Package org.jacop.examples.fd
Class KnapsackExample
- java.lang.Object
-
- org.jacop.examples.fd.ExampleFD
-
- org.jacop.examples.fd.KnapsackExample
-
public class KnapsackExample extends ExampleFD
It shows the capabilities and usage of Knapsack constraint.- Version:
- 4.7
It models and solves a simple knapsack problem. There are two different models. The first one uses quantity from 0 to n, where the second model is allowed to use only binary variables.
Each item is specified by its weight and profit. Find what objects should be put in the knapsack to maximize the profit without exceeding the knapsack capacity.
-
-
Constructor Summary
Constructors Constructor Description KnapsackExample()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
main(java.lang.String[] args)
It executes the two different models to find a solution to a knapsack problem.void
model()
It specifies a standard way of modeling the problem.void
modelBasic()
It creates a model where quantity variable is allowed only to be between 0 and 1, so if the original description allows n items n copies of that items must be created.void
modelBoth()
It does not use Knapsack constraint only SumWeight constraints.void
modelNoKnapsackConstraint()
It does not use Knapsack constraint only SumWeight constraints.-
Methods inherited from class org.jacop.examples.fd.ExampleFD
creditSearch, getSearch, getSearchVariables, getStore, printMatrix, search, searchAllAtOnce, searchAllOptimal, searchLDS, searchMasterSlave, searchMaxRegretOptimal, searchMiddle, searchMostConstrainedStatic, searchOptimal, searchSmallestDomain, searchSmallestMedian, searchSmallestMiddle, searchSmallestMin, searchWeightedDegree, searchWithMaxRegret, searchWithRestarts, shavingSearch
-
-
-
-
Method Detail
-
model
public void model()
Description copied from class:ExampleFD
It specifies a standard way of modeling the problem.
-
modelNoKnapsackConstraint
public void modelNoKnapsackConstraint()
It does not use Knapsack constraint only SumWeight constraints.
-
modelBoth
public void modelBoth()
It does not use Knapsack constraint only SumWeight constraints.
-
modelBasic
public void modelBasic()
It creates a model where quantity variable is allowed only to be between 0 and 1, so if the original description allows n items n copies of that items must be created.
-
main
public static void main(java.lang.String[] args)
It executes the two different models to find a solution to a knapsack problem. It is possible to supply the knapsack problem through the parameters. The parameters are order as follows : string denoting the capacity of the knapsack 4 strings denoting the item (weight, profit, maximumQuantity, name) the number of strings total must be equal to 1+4*noOfItems.If no arguments is provided or improper number of them the program will use internal instance of the knapsack problem.
- Parameters:
args
- the capacity of the knapsack, 4 strings denoting the item (weight, profit, maximumQuantity, name), the number of strings total must be equal to 1+4*noOfItems.
-
-