Examples of Knapsack


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

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

        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

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

        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

Examples of samples.integer.Knapsack

*/
public class KnapsackTest {
    private final static TFloatArrayList times = new TFloatArrayList();

    public Solver modelIt(String data, int n) throws IOException {
        Knapsack pb = new Knapsack();
        pb.readArgs("-d", data, "-n", "" + n);
        pb.createSolver();
        pb.buildModel();
//    pb.configureSearch();

        for (IntVar v : pb.objects) {
            if (v == null) {
                throw new UnsupportedOperationException();
            }
        }
        return pb.getSolver();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.