Package org.jacop.constraints.knapsack
Class TreeNode
- java.lang.Object
-
- org.jacop.constraints.knapsack.TreeNode
-
- Direct Known Subclasses:
TreeLeaf
public class TreeNode extends java.lang.Object
It contains information required by an internal node of the item tree.- Version:
- 4.7
-
-
Field Summary
Fields Modifier and Type Field Description TreeNode
left
It specifies the left child.TreeNode
leftNeighbor
It specifies the left neighbor.TreeNode
parent
It specifies the parent of this node.private int
pSum
It specifies the sum of the profit of all items in the subtree rooted at this node.TreeNode
right
It specifies the right child.TreeNode
rightNeighbor
It specifies the right neighbor.private int
wMax
It specifies the maximal weight of an item in the subtree rooted at this node.private int
wSum
It specifies the sum of the weight of all items in the subtree rooted at this node.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
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()
java.lang.String
nodeToString()
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.java.lang.String
toString()
-
-
-
Field Detail
-
wMax
private int wMax
It 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 wSum
It specifies the sum of the weight of all items in the subtree rooted at this node.
-
pSum
private int pSum
It specifies the sum of the profit of all items in the subtree rooted at this node.
-
parent
public TreeNode 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
public final TreeNode left
It specifies the left child. It can not be equal to null.
-
right
public final TreeNode right
It specifies the right child. It can not be equal to null.
-
leftNeighbor
public TreeNode leftNeighbor
It specifies the left neighbor.
-
rightNeighbor
public TreeNode rightNeighbor
It specifies the right neighbor.
-
-
Method Detail
-
setLeftNeighbor
public void setLeftNeighbor(TreeNode leftNeighbor)
It sets the left neighbor of this tree node.- Parameters:
leftNeighbor
- left neighbor of this node.
-
setRightNeighbor
public void setRightNeighbor(TreeNode rightNeighbor)
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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
recomputeUp
public void recomputeUp(Tree tree)
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
public void recomputeDown(Tree tree)
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
public java.lang.String nodeToString()
It generates description of the node only.- Returns:
- the description containing values of all node internal attributes.
-
-