Class 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.
    • Constructor Summary

      Constructors 
      Constructor Description
      TreeNode()
      The constructor used by tree leaves.
      TreeNode​(TreeNode left, TreeNode right)
      It constructs a node of the item tree.
    • 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()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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.
    • Constructor Detail

      • 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 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 class java.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.