Class KSAlgo
java.lang.Object
org.ddolib.examples.layered.knapsack.KSAlgo
Utility class providing algorithms to solve the Knapsack Problem.
-
Method Summary
-
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 selected items (
1if itemiis taken,0otherwise). As the problem is modeled as a minimization, its value is minus the total profit and provides an upper bound on the optimal value.
-