Class Knapsack01
java.lang.Object
topics.greedy.Knapsack01
GREEDY ALGORITHM PROBLEM: THE KNAPSACK PROBLEM (0/1). ELEMENTS CANNOT BE BROKEN
It has not an optimal solution in some cases
- Author:
- vicegd
-
Constructor Summary
ConstructorsConstructorDescriptionKnapsack01(int[] weights, int[] values, float[] solution) Constructor for Knapsack01 objects -
Method Summary
Modifier and TypeMethodDescriptionvoidfindObjects(int maxWeight) This algorithm can have a complexity from O(n*logn) to O(n^2).
-
Constructor Details
-
Knapsack01
public Knapsack01(int[] weights, int[] values, float[] solution) Constructor for Knapsack01 objects- Parameters:
weights- Weights that can be usedvalues- Values of the objectssolution- 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
-