Package org.ddolib.examples.knapsack
Class KSAlgo
java.lang.Object
org.ddolib.examples.knapsack.KSAlgo
Utility class providing algorithms to solve the Knapsack Problem.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
KSAlgo
public KSAlgo()
-
-
Method Details
-
greedyKS
Provides a greedy approximation for the Knapsack Problem.The algorithm sorts items in descending order of their profit-to-weight ratio (
profit / weight) and selects items sequentially as long as they fit within the remaining capacity.- Parameters:
problem- the Knapsack Problem instance to solve- Returns:
- the total profit of the selected items, providing a primal bound (lower bound) on the optimal solution
-