Package de.mh4j.examples.maxknapsack.model

Examples of de.mh4j.examples.maxknapsack.model.Knapsack


        40), new Item("Bar", 80, 30), new Item("Muh", 5, 5), new Item(
        "Awe", 30, 10)));

    SimulatedAnnealingKnapsackSolver solver = new SimulatedAnnealingKnapsackSolver(
        knapsackCapacity, items);
    Knapsack currentSolution = new Knapsack(knapsackCapacity);
    currentSolution.addItem(items.get(3));
    currentSolution.addItem(items.get(2));
    currentSolution.addItem(items.get(1));

    solver.setInitialSolution(currentSolution);
    solver.setLogLevel(Level.TRACE);

    boolean hasChanged = false;
View Full Code Here


        addTerminationCondition(new StagnationTermination(this, 5));
    }

    @Override
    protected Knapsack createInitialSolution() {
        Knapsack knapsack = new Knapsack(knapsackCapacity);

        boolean itemHasBeenAdded;
        do {
            Item randomItem = Util.getRandomEntryFrom(availableItems);
            itemHasBeenAdded = knapsack.addItem(randomItem);
            availableItems.remove(randomItem);
        } while (itemHasBeenAdded && (availableItems.size() > 0));

        return knapsack;
    }
View Full Code Here

        return knapsack;
    }

    @Override
    protected Knapsack createRandomNeighbor() {
        Knapsack neighbor = new Knapsack(currentSolution);
        switch (NeighborFunction.getFromId(randomizer.nextInt(2))) {
            default:
            case ADD:
                return createNeighborFromAdd(neighbor);
            case SWAP:
View Full Code Here

TOP

Related Classes of de.mh4j.examples.maxknapsack.model.Knapsack

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.