Package org.jacop.constraints.knapsack
Class TreeNode
java.lang.Object
org.jacop.constraints.knapsack.TreeNode
- Direct Known Subclasses:
TreeLeaf
It contains information required by an internal node of the item tree.
- Version:
- 4.9
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal TreeNode
It specifies the left child.It specifies the left neighbor.It specifies the parent of this node.private int
It specifies the sum of the profit of all items in the subtree rooted at this node.final TreeNode
It specifies the right child.It specifies the right neighbor.private int
It specifies the maximal weight of an item in the subtree rooted at this node.private int
It specifies the sum of the weight of all items in the subtree rooted at this node. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
getPSum()
It does not recompute sum of profits.int
getWMax()
It does not recompute the maximum of weights.int
getWSum()
It does not recompute sum of weights.boolean
isLeaf()
It generates description of the node only.void
recomputeDown
(Tree tree) This function recomputes the attributes of this node after recomputing the left and right subtree.void
recomputeUp
(Tree tree) This function is used to recompute the attributes of all nodes on the way to root from this node.void
setLeftNeighbor
(TreeNode leftNeighbor) It sets the left neighbor of this tree node.void
setRightNeighbor
(TreeNode rightNeighbor) It sets the right neighbor of this tree node.toString()
-
Field Details
-
wMax
private int wMaxIt specifies the maximal weight of an item in the subtree rooted at this node. The consistency algorithm will know that it can skip the entire subtree if the weight is not sufficiently large. -
wSum
private int wSumIt specifies the sum of the weight of all items in the subtree rooted at this node. -
pSum
private int pSumIt specifies the sum of the profit of all items in the subtree rooted at this node. -
parent
It specifies the parent of this node. If it is equal to null then this node is the root of the whole item tree. -
left
It specifies the left child. It can not be equal to null. -
right
It specifies the right child. It can not be equal to null. -
leftNeighbor
It specifies the left neighbor. -
rightNeighbor
It specifies the right neighbor.
-
-
Constructor Details
-
TreeNode
public TreeNode()The constructor used by tree leaves. -
TreeNode
It constructs a node of the item tree.- Parameters:
left
- left childright
- right child
-
-
Method Details
-
setLeftNeighbor
It sets the left neighbor of this tree node.- Parameters:
leftNeighbor
- left neighbor of this node.
-
setRightNeighbor
It sets the right neighbor of this tree node.- Parameters:
rightNeighbor
- right neighbor of this node.
-
isLeaf
public boolean isLeaf()- Returns:
- true if the node is a leaf, false otherwise.
-
getWMax
public int getWMax()It does not recompute the maximum of weights.- Returns:
- The previously computed maximum weight of its children
-
getWSum
public int getWSum()It does not recompute sum of weights.- Returns:
- The previously computed sum of weights of its children
-
getPSum
public int getPSum()It does not recompute sum of profits.- Returns:
- The previously computed sum of profits of its children
-
toString
-
recomputeUp
This function is used to recompute the attributes of all nodes on the way to root from this node. It assumes that left and right subtree have a correct values for their attributes.- Parameters:
tree
- only added to be in agreement with the function template for leaf which need information about tree it belongs to.
-
recomputeDown
This function recomputes the attributes of this node after recomputing the left and right subtree.- Parameters:
tree
- It is required by leaves so tree atributes like alreadyUsedCapacity are properly updated.
-
nodeToString
It generates description of the node only.- Returns:
- the description containing values of all node internal attributes.
-