|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.ObjectJaCoP.constraints.DecomposedConstraint
JaCoP.constraints.Constraint
JaCoP.constraints.knapsack.Knapsack
public class Knapsack
It specifies a knapsack constraint. This implementation was inspired by the paper by Irit Katriel, Meinolf Sellmann, Eli Upfal, Pascal Van Hentenryck: "Propagating Knapsack Constraints in Sublinear Time", AAAI 2007: pp. 231-236. Tha major extensions of that paper are the following. The quantity variables do not have to be binary. The profit and capacity of the knapsacks do not have to be integers. In both cases, the constraint accepts any finite domain variable. This implementation is based on the implementation obtained by Wadeck Follonier during his work on a student semester project. We would like to thank Meinolf Sellmann for his appreciation of our work and useful comments.
| Field Summary | |
|---|---|
int |
CONSISTENCY_INFO_FROM
It specifies how many consistency functions must be executed before the information about the constraint is being printed out. |
int |
countConsistency
It counts the number of time the consistency function has been executed. |
int |
countQueueVariable
It counts the number of times the queueVariable function has been executed. |
int |
countRemoveLevel
It counts the number of time the removeLevel function has been executed. |
int |
currentLevel
It specifies the current level of the constraint store at which the consistency function of this constraint is being executed. |
static boolean |
debugAll
It specifies if any debugging information should be printed. |
boolean |
impositionFailure
It specifies if the constraint has already discovered to be unsatisfied during the imposition stage. |
boolean |
inConsistency
It specifies if the constraint is executing the consistency function. |
KnapsackItem[] |
items
The array of items present in the knapsack constraint. |
IntVar |
knapsackCapacity
This is a finite domain variable to specify the knapsack capacity. |
IntVar |
knapsackProfit
This is a finite domain variable to specify the knapsack profit. |
TreeLeaf[] |
leaves
It stores all the leaves of the knapsack tree in one array. |
boolean |
needConsistency
It specifies if the consistency function should execute. |
boolean |
needCriticalUpdate
It specifies if the recomputation of the critical item should take place. |
boolean |
needForbidden
It specifies if the forbidden part of the consistency algortihm should be executed. |
boolean |
needMandatory
It specifies if the mandatory part of the consistency algorithm should be executed. |
boolean |
needUpdate
It specifies if the knapsack tree requires an update. |
int |
positionOfAlreadyUpdated
It specifies the position of the last changed item which has been already been recomputed. |
int |
QUEUE_INFO_FROM
It specifies how many queueVariable functions must be executed before the information about the constraint is being printed out. |
int |
REMOVE_INFO_FROM
It specifies how many removeLevel functions must be executed before the information about the constraint is being printed out. |
Tree |
tree
The tree for the storing information about the maximalWeight, sum of weights and sum of profits. |
int |
updateLimit
It specifies the limit after which the changed leaves are not store and the remove level will simply recompute attributes of all nodes in the knapsack tree. |
java.util.HashMap<IntVar,TreeLeaf> |
variableLeafMapping
It specifies mapping from variables into the leaf of the knapsack tree. |
static java.lang.String[] |
xmlAttributes
It specifies the arguments required to be saved by an XML format as well as the constructor being called to recreate an object from an XML format. |
| Fields inherited from class JaCoP.constraints.Constraint |
|---|
atomicExecution, consistencyPruningEvents, earlyTerminationOK, id, increaseWeight, numberArgs, numberId |
| Fields inherited from class JaCoP.constraints.DecomposedConstraint |
|---|
queueIndex |
| Constructor Summary | |
|---|---|
Knapsack(int[] profits,
int[] weights,
IntVar[] quantity,
IntVar knapsackCapacity,
IntVar knapsackProfit)
It constructs the knapsack constraint. |
|
Knapsack(KnapsackItem[] items,
IntVar knapsackCapacity,
IntVar knapsackProfit)
It constructs an knapsack constraint. |
|
| Method Summary | |
|---|---|
java.util.ArrayList<Var> |
arguments()
It returns the variables in a scope of the constraint. |
void |
cleanAfterFailure()
It is executed after the constraint has failed. |
void |
computeForbidden()
It searches through a subset of right items to find the ones which can not be fully included without violating the profit requirement in the knapsack constraint. |
void |
computeMandatory()
It computes the mandatory part of the knapsack pruning. |
void |
consistency(Store store)
It is a (most probably incomplete) consistency function which removes the values from variables domains. |
int |
getConsistencyPruningEvent(Var var)
It retrieves the pruning event which causes reevaluation of the constraint. |
java.lang.String |
id()
It gives the id string of a constraint. |
void |
impose(Store store)
It imposes the constraint in a given store. |
void |
increaseWeight()
It increases the weight of the variables in the constraint scope. |
int |
numberArgs()
It returns the number of variables within a constraint scope. |
void |
queueVariable(int level,
Var v)
This is a function called to indicate which variable in a scope of constraint has changed. |
void |
removeConstraint()
It removes the constraint by removing this constraint from all variables. |
void |
removeLevel(int level)
This function is called in case of the backtrack, so a constraint can clear the queue of changed variables which is no longer valid. |
void |
removeLevelLate(int level)
This function is called in case of the backtrack. |
boolean |
satisfied()
It checks if the constraint is satisfied. |
java.lang.String |
toString()
It produces a string representation of a constraint state. |
| Methods inherited from class JaCoP.constraints.Constraint |
|---|
decompose, getGuideConstraint, getGuideValue, getGuideVariable, impose, imposeDecomposition, requiresMonotonicity, setConsistencyPruningEvent, supplyGuideFeedback |
| Methods inherited from class JaCoP.constraints.DecomposedConstraint |
|---|
auxiliaryVariables, imposeDecomposition |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final boolean debugAll
public java.util.HashMap<IntVar,TreeLeaf> variableLeafMapping
public TreeLeaf[] leaves
public final int updateLimit
public boolean impositionFailure
public final IntVar knapsackCapacity
public final IntVar knapsackProfit
public int currentLevel
public int positionOfAlreadyUpdated
public boolean needUpdate
public boolean needConsistency
public boolean needMandatory
public boolean needForbidden
public boolean needCriticalUpdate
public boolean inConsistency
public Tree tree
public KnapsackItem[] items
public int countConsistency
public int countQueueVariable
public int countRemoveLevel
public int REMOVE_INFO_FROM
public int QUEUE_INFO_FROM
public int CONSISTENCY_INFO_FROM
public static java.lang.String[] xmlAttributes
| Constructor Detail |
|---|
public Knapsack(KnapsackItem[] items,
IntVar knapsackCapacity,
IntVar knapsackProfit)
items - list of items in knapsack with its weight, profit and quantity variable.knapsackCapacity - overall knapsack capacity.knapsackProfit - overall profit obtained by the items in the knapsack.
public Knapsack(int[] profits,
int[] weights,
IntVar[] quantity,
IntVar knapsackCapacity,
IntVar knapsackProfit)
profits - the list of profits, each for the corresponding item no.weights - the list of weights, each for the corresponding item no.quantity - finite domain variable specifying allowed values for the vars.knapsackCapacity - finite domain variable specifying the capacity limit of the knapsack.knapsackProfit - | Method Detail |
|---|
public void removeLevel(int level)
Constraint
removeLevel in class Constraintlevel - the level which is being removed.public void cleanAfterFailure()
Constraint
cleanAfterFailure in class Constraintpublic void removeLevelLate(int level)
Constraint
removeLevelLate in class Constraintlevel - the level which is being removed.public void consistency(Store store)
Constraint
consistency in class Constraintstore - constraint store within which the constraint consistency is being checked.public void computeForbidden()
public void computeMandatory()
public void impose(Store store)
Constraint
impose in class Constraintstore - the constraint store to which the constraint is imposed to.
public void queueVariable(int level,
Var v)
Constraint
queueVariable in class Constraintlevel - the level of the store at which the change has occurred.v - variable which has changed.public int numberArgs()
Constraint
numberArgs in class Constraintpublic int getConsistencyPruningEvent(Var var)
Constraint
getConsistencyPruningEvent in class Constraintvar - variable for which pruning event is retrieved
public java.lang.String id()
Constraint
id in class Constraintpublic void removeConstraint()
Constraint
removeConstraint in class Constraintpublic void increaseWeight()
Constraint
increaseWeight in class Constraintpublic java.util.ArrayList<Var> arguments()
Constraint
arguments in class Constraintpublic boolean satisfied()
Constraint
satisfied in class Constraintpublic java.lang.String toString()
Constraint
toString in class Constraint
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||