public class Knapsack extends Constraint
Modifier and Type | Field and Description |
---|---|
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.
|
HashMap<IntVar,TreeLeaf> |
variableLeafMapping
It specifies mapping from variables into the leaf of the knapsack tree.
|
static 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.
|
atomicExecution, consistencyPruningEvents, earlyTerminationOK, id, increaseWeight, numberArgs, numberId, trace
queueIndex
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
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.
|
String |
toString()
It produces a string representation of a constraint state.
|
decompose, getGuideConstraint, getGuideValue, getGuideVariable, impose, imposeDecomposition, requiresMonotonicity, setConsistencyPruningEvent, supplyGuideFeedback
auxiliaryVariables, derivative, imposeDecomposition
public static final boolean debugAll
public 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 String[] xmlAttributes
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
- public void removeLevel(int level)
Constraint
removeLevel
in class Constraint
level
- the level which is being removed.public void cleanAfterFailure()
Constraint
cleanAfterFailure
in class Constraint
public void removeLevelLate(int level)
Constraint
removeLevelLate
in class Constraint
level
- the level which is being removed.public void consistency(Store store)
Constraint
consistency
in class Constraint
store
- 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 Constraint
store
- the constraint store to which the constraint is imposed to.public void queueVariable(int level, Var v)
Constraint
queueVariable
in class Constraint
level
- the level of the store at which the change has occurred.v
- variable which has changed.public int numberArgs()
Constraint
numberArgs
in class Constraint
public int getConsistencyPruningEvent(Var var)
Constraint
getConsistencyPruningEvent
in class Constraint
var
- variable for which pruning event is retrievedpublic String id()
Constraint
id
in class Constraint
public void removeConstraint()
Constraint
removeConstraint
in class Constraint
public void increaseWeight()
Constraint
increaseWeight
in class Constraint
public ArrayList<Var> arguments()
Constraint
arguments
in class Constraint
public boolean satisfied()
Constraint
satisfied
in class Constraint
public String toString()
Constraint
toString
in class Constraint
Copyright © 2015. All rights reserved.