Package de.mh4j.examples.maxknapsack.model

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


public class SimulatedAnnealingKnapsackSolverTest {

  @Test
  public void testSolveSimpleInstance() {
    int knapsackCapacity = 59;
    List<Item> items = new ArrayList<>(Arrays.asList(new Item("Foo", 100,
        40), new Item("Bar", 80, 30), new Item("Muh", 5, 5), new Item(
        "Awe", 30, 10)));

    SimulatedAnnealingKnapsackSolver solver = new SimulatedAnnealingKnapsackSolver(
        knapsackCapacity, items);
    solver.run();
View Full Code Here


  }

  @Test
  public void testBuggyConfiguration() {
    int knapsackCapacity = 59;
    List<Item> items = new ArrayList<>(Arrays.asList(new Item("Foo", 100,
        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);
View Full Code Here

    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

        }
    }

    private Knapsack createNeighborFromAdd(Knapsack neighbor) {
        if (availableItems.size() > 0) {
            Item randomItem = Util.getRandomEntryFrom(availableItems);
            neighbor.addItem(randomItem);
            availableItems.remove(randomItem);
        }

        log.trace("Created neighbor from ADD : {}", neighbor);
View Full Code Here

        return neighbor;
    }

    private Knapsack createNeighborFromSwap(Knapsack neighbor) {
        int randomIndex = randomizer.nextInt(neighbor.getNumberOfItems());
        Item removedItem = neighbor.removeItem(randomIndex);
        availableItems.add(removedItem);

        log.trace("Created neighbor from SWAP : {}", neighbor);
        return createNeighborFromAdd(neighbor);
    }
View Full Code Here

TOP

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

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.