Class Knapsack01

java.lang.Object
topics.greedy.Knapsack01

public class Knapsack01 extends Object
GREEDY ALGORITHM PROBLEM: THE KNAPSACK PROBLEM (0/1). ELEMENTS CANNOT BE BROKEN It has not an optimal solution in some cases
Author:
vicegd
  • Constructor Details

    • Knapsack01

      public Knapsack01(int[] weights, int[] values, float[] solution)
      Constructor for Knapsack01 objects
      Parameters:
      weights - Weights that can be used
      values - Values of the objects
      solution - Array to save the amount of each object taken as a solution
  • Method Details

    • findObjects

      public void findObjects(int maxWeight)
      This algorithm can have a complexity from O(n*logn) to O(n^2). It depends on the heuristic method since the main loop is repeated at most n times
      Parameters:
      maxWeight - Max weight that we can take from objects