Package org.jacop.examples.fd
Class KnapsackExample
java.lang.Object
org.jacop.examples.fd.ExampleFD
org.jacop.examples.fd.KnapsackExample
It shows the capabilities and usage of Knapsack constraint.
- Version:
- 4.8
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionString[]
It stores the parameters of the main function to be used by the model functions. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
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
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
It does not use Knapsack constraint only SumWeight constraints.void
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
-
Field Details
-
args
It stores the parameters of the main function to be used by the model functions.
-
-
Constructor Details
-
KnapsackExample
public KnapsackExample()
-
-
Method Details
-
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
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.
-