Package de.mh4j.examples

Examples of de.mh4j.examples.Sorting


    public void testCreateRandomNeighbor() {
        LocalSearchSorter sorter = new LocalSearchSorter(10);
        // invoke step to initialize the solver
        sorter.step();

        Sorting initialSorting = sorter.getCurrentSolution();
        Sorting neighbor = sorter.createRandomNeighbor();

        assert initialSorting.equals(neighbor) == false;
    }
View Full Code Here


     * Hopefully one of the swapped numbers will be nearer to its optimal
     * position in the sorting and decrease the cost of the whole new sorting.
     */
    @Override
    protected Sorting createRandomNeighbor() {
        Sorting neighbor = new Sorting(currentSolution);

        int randomIndex1 = randomizer.nextInt(currentSolution.getAmountOfNumbers());
        int randomIndex2 = randomizer.nextInt(currentSolution.getAmountOfNumbers() - 1);

        if (randomIndex1 <= randomIndex2) {
            randomIndex2++;
        }

        neighbor.swapIndices(randomIndex1, randomIndex2);
        return neighbor;
    }
View Full Code Here

     * Hopefully one of the swapped numbers will be nearer to its optimal
     * position in the sorting and decrease the cost of the whole new sorting.
     */
    @Override
    protected Sorting createRandomNeighbor() {
        Sorting neighbor = new Sorting(currentSolution);

        int randomIndex1 = randomizer.nextInt(currentSolution.getAmountOfNumbers());
        int randomIndex2 = randomizer.nextInt(currentSolution.getAmountOfNumbers());

        neighbor.swapIndices(randomIndex1, randomIndex2);
        return neighbor;
    }
View Full Code Here

TOP

Related Classes of de.mh4j.examples.Sorting

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.