Package org.jacop.constraints.knapsack
Class Tree
java.lang.Object
org.jacop.constraints.knapsack.Tree
This tree is a main data structure used and required by Knapsack constraint.
- Version:
- 4.9
-
Field Summary
FieldsModifier and TypeFieldDescriptionint
It specifies the already obtained profit due to the items which are already included in the solution.int
It specifies the already used capacity due to the items which are already included in the solution.int
It specifies the fraction of the critical item which has been not included in the optimal non-integral solution.It specifies the leaf containing the critical item.int
It specifies the leaf containing the left most item which is being used during computeForbidden().int
It specifies the leaf containing the last right item which is being used during computeMandatory().(package private) TreeNode
It specifies the current right item of the tree which have been yet included in computation of replaceable weight.(package private) int
It specifies the current profit obtained by all already traversed right items.(package private) int
It specifies the currentWeight from which searching for next mandatory item starts from.boolean
It specifies that computeForbidden part of the consistency function has run out of left mandatory items.boolean
It specifies if the mandatory check has run out of right items to complement mandatory items.It specifies the first (counting from left to right), the most efficient item in the tree.It specifies the last (counting from left to right), the least efficient item in the tree.double
It specifies the optimalProfit of possibly non-integral solution generated by LP relaxation.(package private) double
It specifies the profit obtained from the remaining part of the critical item.(package private) double
It specifies the profit obtained from the remaining part of the critical item.final TreeNode
It specifies the root of the tree.int
It specifies how much weight is used by an optimal non-fractional solution. -
Constructor Summary
ConstructorsConstructorDescriptionIt constructs a tree out of the list of items and creates proper supporting structures.It creates a tree by making a shallow copy.Create a single node tree. -
Method Summary
Modifier and TypeMethodDescriptionint
computeIntrusionWeight
(int weightOfItemChecked, int maxNoOfItems, int profitOfItemChecked, double efficiencyOfItemChecked, double profitSlack) It returns the amount of weight of a given item being checked which can be replaced by Right items given the amount of profitSlack.int
computeMinProfit
(int minWeight) It computes the minimum of capacity variable for knapsack constraint given the minimum requirement for profit.int
computeMinWeight
(int minProfit) It computes the minimum of capacity variable for knapsack constraint given the minimum requirement for profit.int
computeReplacableWeight
(int weightOfItemChecked, int maxNoOfItems, int profitOfItemChecked, double efficiencyOfItemChecked, double profitSlack) It returns the amount of weight of a given item being checked which can be replaced by Right items given the amount of profitSlack.findNextLeafAtLeastOfWeight
(TreeLeaf leaf, int weight) It finds next leaf of a maximum weight of at least weight, so it can have some parts of it mandatory.findPreviousLeafAtLeastOfWeight
(TreeLeaf leaf, int weight) It finds previous leaf of a maximum weight of at least weight, so it can have some parts of it forbidden.int
getCriticalPosition
(int capacity) It finds a leaf which reaches the limit of the given capacity.getFirst()
Used to search for mandatorygetLast()
It returns the last (the least efficient) item in the tree.void
It initializes the private variables required by computation of how much weight we can replace for any Left item.void
It initializes the private variables required by computation of how much weight we can replace for any Left item.A merge method for trees, it added a new root from the ancientsvoid
It recomputes all the attributes of the internal nodes of the knapsack tree.toString()
void
updateCritical
(int capacity) It updates information about the critical item, as well as information about fraction of critical item which is not taken.void
updateFromList
(List<TreeLeaf> list, int startingPosition) Used for updating the tree using a list of nodes that have changed.
-
Field Details
-
root
It specifies the root of the tree. -
criticalLeaf
It specifies the leaf containing the critical item. The critical item is the one used partially by Linear Programming approach. -
criticalRightLeaf
public int criticalRightLeafIt specifies the leaf containing the last right item which is being used during computeMandatory(). if max() of the right item after criticalRight is changed then it can be safely ignored. -
criticalLeftLeaf
public int criticalLeftLeafIt specifies the leaf containing the left most item which is being used during computeForbidden(). if min() of the left item before criticalLeft is changed then it can be safely ignored. -
first
It specifies the first (counting from left to right), the most efficient item in the tree. -
last
It specifies the last (counting from left to right), the least efficient item in the tree. -
optimalProfit
public double optimalProfitIt specifies the optimalProfit of possibly non-integral solution generated by LP relaxation. -
availableWeightOfCriticalItem
public int availableWeightOfCriticalItemIt specifies the fraction of the critical item which has been not included in the optimal non-integral solution. -
takenWeightOfCriticalItem
public int takenWeightOfCriticalItemIt specifies how much weight is used by an optimal non-fractional solution. -
alreadyObtainedProfit
public int alreadyObtainedProfitIt specifies the already obtained profit due to the items which are already included in the solution. -
alreadyUsedCapacity
public int alreadyUsedCapacityIt specifies the already used capacity due to the items which are already included in the solution. -
currentNode
TreeNode currentNodeIt specifies the current right item of the tree which have been yet included in computation of replaceable weight. -
currentWeight
int currentWeightIt specifies the currentWeight from which searching for next mandatory item starts from. Only items with weight greater or equal to currentWeight can be (partially) mandatory. -
currentProfit
int currentProfitIt specifies the current profit obtained by all already traversed right items. -
profitFromCriticalLeft
double profitFromCriticalLeftIt specifies the profit obtained from the remaining part of the critical item. -
profitFromCriticalTaken
double profitFromCriticalTakenIt specifies the profit obtained from the remaining part of the critical item. -
exhaustedRightItems
public boolean exhaustedRightItemsIt specifies if the mandatory check has run out of right items to complement mandatory items. -
exhaustedLeftItems
public boolean exhaustedLeftItemsIt specifies that computeForbidden part of the consistency function has run out of left mandatory items.
-
-
Constructor Details
-
Tree
Create a single node tree.- Parameters:
node
- a root of this one-node tree.
-
Tree
It creates a tree by making a shallow copy.- Parameters:
tree
- tree to be constructed
-
Tree
public Tree(KnapsackItem[] items, Map<IntVar, TreeLeaf> varPositionMaping, TreeLeaf[] leaves, IntVar zero) It constructs a tree out of the list of items and creates proper supporting structures. It assumes the list of items is greater than 1.- Parameters:
items
- knapsack items used to create the tree.varPositionMaping
- mapping of variables into positions within the tree.leaves
- array of leaves of the created tree.zero
- it specifies a variable equal to value 0.
-
-
Method Details
-
merge
A merge method for trees, it added a new root from the ancients- Parameters:
that
- A tree that is being merged with this tree.- Returns:
- The tree resulting of the merge of this and that
-
updateCritical
public void updateCritical(int capacity) It updates information about the critical item, as well as information about fraction of critical item which is not taken.- Parameters:
capacity
- available capacity to be used by knapsack.
-
getCriticalPosition
public int getCriticalPosition(int capacity) It finds a leaf which reaches the limit of the given capacity. Items weight is added from the most efficient to the least efficient.- Parameters:
capacity
- available capacity to be used by knapsack.- Returns:
- the position of the item.
-
getFirst
Used to search for mandatory- Returns:
- The first item
-
getLast
It returns the last (the least efficient) item in the tree. It is a starting leaf for computeForbidden() part.- Returns:
- The last item
-
toString
-
updateFromList
Used for updating the tree using a list of nodes that have changed.- Parameters:
list
- list of leaves that needs to be updated.startingPosition
- it specifies the first leaf in the array which has not been updated before.
-
recompute
public void recompute()It recomputes all the attributes of the internal nodes of the knapsack tree. -
initializeComputeMandatory
public void initializeComputeMandatory()It initializes the private variables required by computation of how much weight we can replace for any Left item. -
computeReplacableWeight
public int computeReplacableWeight(int weightOfItemChecked, int maxNoOfItems, int profitOfItemChecked, double efficiencyOfItemChecked, double profitSlack) It returns the amount of weight of a given item being checked which can be replaced by Right items given the amount of profitSlack.- Parameters:
weightOfItemChecked
- the weight of item being checked.maxNoOfItems
- the maximum number which can be taken of checked items.profitOfItemChecked
- the profit of the item being checked.efficiencyOfItemChecked
- the efficiency of the item being checked.profitSlack
- the amount of reserve profit which can be sacrificed before violating the constraint.- Returns:
- the amount of weight of a given item that can be replaced by Right items without violating the constraint.
-
findNextLeafAtLeastOfWeight
It finds next leaf of a maximum weight of at least weight, so it can have some parts of it mandatory.- Parameters:
leaf
- starting leaf, the result must be to the right of this leaf.weight
- weight condition which must be satisfied by the found leaf.- Returns:
- tree leaf on the right to the supplied leaf with at least specified weight.
-
initializeComputeForbidden
public void initializeComputeForbidden()It initializes the private variables required by computation of how much weight we can replace for any Left item. -
computeIntrusionWeight
public int computeIntrusionWeight(int weightOfItemChecked, int maxNoOfItems, int profitOfItemChecked, double efficiencyOfItemChecked, double profitSlack) It returns the amount of weight of a given item being checked which can be replaced by Right items given the amount of profitSlack.- Parameters:
weightOfItemChecked
- the weight of item being checked.maxNoOfItems
- the maximum number which can be taken of checked items.profitOfItemChecked
- the profit of the item being checked.efficiencyOfItemChecked
- the efficiency of the item being checked.profitSlack
- the amount of reserve profit which can be sacrificed before violating the constraint.- Returns:
- the amount of weight of a given item that can be replaced by Right items without violating the constraint.
-
findPreviousLeafAtLeastOfWeight
It finds previous leaf of a maximum weight of at least weight, so it can have some parts of it forbidden.- Parameters:
leaf
- starting leaf, the result must be to the left of this leaf.weight
- weight condition which must be satisfied by the found leaf.- Returns:
- tree leaf on the left to the supplied leaf with at least specified weight.
-
computeMinWeight
public int computeMinWeight(int minProfit) It computes the minimum of capacity variable for knapsack constraint given the minimum requirement for profit.- Parameters:
minProfit
- minimum profit obtained by the knapsack.- Returns:
- it returns the minimum required weight to satisfy min profit requirements.
-
computeMinProfit
public int computeMinProfit(int minWeight) It computes the minimum of capacity variable for knapsack constraint given the minimum requirement for profit.- Parameters:
minWeight
- - the minimum of weight within a knapsack.- Returns:
- it returns the minimum required weight to satisfy min profit requirements.
-