ExamplesJaCoP
Class KnapsackExample

java.lang.Object
  extended by ExamplesJaCoP.Example
      extended by ExamplesJaCoP.KnapsackExample

public class KnapsackExample
extends Example

It shows the capabilities and usage of Knapsack constraint.

Version:
3.0 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.
Author:
Radoslaw Szymanek

Field Summary
 java.lang.String[] args
          It stores the parameters of the main function to be used by the model functions.
 
Fields inherited from class ExamplesJaCoP.Example
cost, search, store, vars
 
Constructor Summary
KnapsackExample()
           
 
Method Summary
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 ExamplesJaCoP.Example
creditSearch, getSearch, getSearchVariables, getStore, printMatrix, search, searchAllAtOnce, searchAllOptimal, searchLDS, searchMasterSlave, searchMaxRegretOptimal, searchMiddle, searchMostConstrainedStatic, searchOptimal, searchSmallestDomain, searchSmallestMedian, searchSmallestMiddle, searchSmallestMin, searchWeightedDegree, searchWithMaxRegret, searchWithRestarts, shavingSearch
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

args

public java.lang.String[] args
It stores the parameters of the main function to be used by the model functions.

Constructor Detail

KnapsackExample

public KnapsackExample()
Method Detail

model

public void model()
Description copied from class: Example
It specifies a standard way of modeling the problem.

Specified by:
model in class Example

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 -