Package com.barrybecker4.puzzle.tantrix.solver.path.permuting

Examples of com.barrybecker4.puzzle.tantrix.solver.path.permuting.PathPivotPermuter


        ParameterArray solution =
            optimizer.doOptimization(strategy, initialGuess, SOLVED_THRESH);

        solution_ =
            new TantrixBoard(((TantrixPath)solution).getTilePlacements(), board.getPrimaryColor());

        TilePlacementList moves;
        if (evaluateFitness(solution) >= SOLVED_THRESH) {
            moves = ((TantrixPath)solution).getTilePlacements();
        } else {
View Full Code Here


     * @param params
     */
    public void optimizerChanged(ParameterArray params) {
        // update our current best guess at the solution.
        TantrixPath path = (TantrixPath)params;
        solution_ = new TantrixBoard(path.getTilePlacements(), path.getPrimaryPathColor());
        puzzlePanel_.refresh(solution_, numTries_++);
    }
View Full Code Here

        drawGrid(g2, board);

        Location topLeftCorner = board.getBoundingBox().getTopLeftCorner();

        for (Location loc : board.getTantrixLocations()) {
            TilePlacement placement = board.getTilePlacement(loc);
            tileRenderer.render(g2, placement, topLeftCorner, hexRadius);
        }
    }
View Full Code Here

            optimizer.doOptimization(strategy, initialGuess, SOLVED_THRESH);

        solution_ =
            new TantrixBoard(((TantrixPath)solution).getTilePlacements(), board.getPrimaryColor());

        TilePlacementList moves;
        if (evaluateFitness(solution) >= SOLVED_THRESH) {
            moves = ((TantrixPath)solution).getTilePlacements();
        } else {
            moves = null;
        }
View Full Code Here

        int numTiles = path.size();
        double distance = path.getEndPointDistance();
        boolean isLoop = distance == 0 && path.isLoop();

        ConsistencyChecker checker = new ConsistencyChecker(path.getTilePlacements(), path.getPrimaryPathColor());
        int numFits = checker.numFittingTiles();
        boolean allFit = numFits == numTiles;
        boolean consistentLoop = isLoop && allFit;
        boolean perfectLoop = false;
        double compactness = determineCompactness(path);
View Full Code Here

        boolean perfectLoop = false;
        double compactness = determineCompactness(path);

        if (consistentLoop) {
            Tantrix tantrix = new Tantrix(path.getTilePlacements());
            InnerSpaceDetector innerDetector = new InnerSpaceDetector(tantrix);
            perfectLoop = !innerDetector.hasInnerSpaces();
            //System.out.println("perfect loop");
        }

        double fitness =
                LOOP_PROXIMITY_WEIGHT * (numTiles - distance) / (0.1 + numTiles)
View Full Code Here

                               boolean useConcurrency) {
        super(board);
        puzzlePanel_ = puzzlePanel;
        strategy = useConcurrency ? OptimizationStrategyType.CONCURRENT_GENETIC_SEARCH :
                                    OptimizationStrategyType.GENETIC_SEARCH;
        evaluator = new PathEvaluator();
    }
View Full Code Here

     * @return list of moves to a solution.
     */
    @Override
    public TilePlacementList solve()  {

        ParameterArray initialGuess = new TantrixPath(board);
        assert(initialGuess.size() > 0) : "The random path should have some tiles!";
        long startTime = System.currentTimeMillis();

        Optimizer optimizer = new Optimizer(this);
        optimizer.setListener(this);

View Full Code Here

     * We show the current status.
     * @param params
     */
    public void optimizerChanged(ParameterArray params) {
        // update our current best guess at the solution.
        TantrixPath path = (TantrixPath)params;
        solution_ = new TantrixBoard(path.getTilePlacements(), path.getPrimaryPathColor());
        puzzlePanel_.refresh(solution_, numTries_++);
    }
View Full Code Here

     * @return 7 permuted path cases.
     */
    private List<TantrixPath> findPermutedPaths(double radius) {

        List<TantrixPath> permutedPaths = new ArrayList<TantrixPath>();
        PathPivotPermuter permuter = new PathPivotPermuter(path);
        TilePlacementList tiles = path.getTilePlacements();
        int numTiles = path.size();

        if (radius >= 0.4) {
            for (int i = 1; i < numTiles - 1; i++) {
                addAllPermutedPaths(permuter.findPermutedPaths(i, i), permutedPaths);
            }
        }
        else if (radius >= 0.1) {
            // to avoid trying too many paths, increment by something more than one if many tiles.
            int inc = 1 + path.size()/4;
            // n^2 * 7 permuted paths will be added.
            for (int pivot1 = 1; pivot1 < numTiles-1; pivot1+=rand(inc)) {
                for (int pivot2 = pivot1; pivot2 < numTiles-1; pivot2+=rand(inc)) {
                    addAllPermutedPaths(permuter.findPermutedPaths(pivot1, pivot2), permutedPaths);
                }
            }
        }
        else if (permutedPaths.isEmpty()) {
            List<PathType> types = Arrays.asList(PathType.values());
            Collections.shuffle(types, MathUtil.RANDOM);
            Iterator<PathType> typeIter = types.iterator();

            do {
                SameTypeTileMixer mixer = new SameTypeTileMixer(typeIter.next(), path);
                addAllPermutedPaths(mixer.findPermutedPaths(), permutedPaths);
            } while (typeIter.hasNext());
        }

        // as a last resort use this without checking for it in the cache.
        if (permutedPaths.isEmpty()) {

            List<TantrixPath> paths;
            do {
                int pivotIndex1 = 1 + MathUtil.RANDOM.nextInt(tiles.size()-2);
                int pivotIndex2 = 1 + MathUtil.RANDOM.nextInt(tiles.size()-2);
                paths = permuter.findPermutedPaths(pivotIndex1, pivotIndex2);
                System.out.println("paths unexpectedly empty! when p1="+pivotIndex1 + " p2="+ pivotIndex2);
            } while (paths.isEmpty());
            return paths;
        }

View Full Code Here

TOP

Related Classes of com.barrybecker4.puzzle.tantrix.solver.path.permuting.PathPivotPermuter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.