Class TreeNode

java.lang.Object
org.jacop.constraints.knapsack.TreeNode
Direct Known Subclasses:
TreeLeaf

public class TreeNode extends Object
It contains information required by an internal node of the item tree.
Version:
4.10
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final 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
    Constructor
    Description
    The constructor used by tree leaves.
    TreeNode(TreeNode left, TreeNode right)
    It constructs a node of the item tree.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    It does not recompute sum of profits.
    int
    It does not recompute the maximum of weights.
    int
    It does not recompute sum of weights.
    boolean
     
    It generates description of the node only.
    void
    This function recomputes the attributes of this node after recomputing the left and right subtree.
    void
    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.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • 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.
    • leftNeighbor

      public TreeNode leftNeighbor
      It specifies the left neighbor.
    • rightNeighbor

      public TreeNode rightNeighbor
      It specifies the right neighbor.
  • Constructor Details

    • TreeNode

      public TreeNode()
      The constructor used by tree leaves.
    • TreeNode

      public TreeNode(TreeNode left, TreeNode right)
      It constructs a node of the item tree.
      Parameters:
      left - left child
      right - right child
  • Method Details

    • 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 String toString()
      Overrides:
      toString in class 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 String nodeToString()
      It generates description of the node only.
      Returns:
      the description containing values of all node internal attributes.