Class TreeLeaf


  • public final class TreeLeaf
    extends TreeNode
    It contains information required by the leaf node of the item tree.
    Version:
    4.8
    • Field Summary

      Fields 
      Modifier and Type Field Description
      double efficiency
      It specifies the efficiency of the item in the leaf.
      int positionInTheTree
      It specifies the position in the tree.
      int previousMaxQ
      It specifies the maximal value of quantity variable after the last consistency check.
      int previousMinQ
      It specifies the minimal value of quantity variable after the last consistency check.
      int profitOfOne
      It store the profit of one instance of the item stored in this leaf.
      IntVar quantity
      It specifies the finite domain variable denoting the allowed quantity of the item,
      int slice
      It represents the offset from the minimal value.
      int weightOfOne
      It stores the weight of one instance of the item stored in this leaf.
    • Constructor Summary

      Constructors 
      Constructor Description
      TreeLeaf​(IntVar quantity, int weight, int profit, int positionInTheTree)
      It creates a leaf in the tree of items.
    • Field Detail

      • quantity

        public final IntVar quantity
        It specifies the finite domain variable denoting the allowed quantity of the item,
      • efficiency

        public final double efficiency
        It specifies the efficiency of the item in the leaf.
      • previousMaxQ

        public int previousMaxQ
        It specifies the maximal value of quantity variable after the last consistency check. It is used to determine if the maximal value of the quantity variable has changed since the last execution of the consistency function.
      • previousMinQ

        public int previousMinQ
        It specifies the minimal value of quantity variable after the last consistency check. It is used to determine if the minimal value of the quantity variable has changed since the last execution of the consistency function.
      • weightOfOne

        public final int weightOfOne
        It stores the weight of one instance of the item stored in this leaf.
      • profitOfOne

        public final int profitOfOne
        It store the profit of one instance of the item stored in this leaf.
      • slice

        public int slice
        It represents the offset from the minimal value. Slice of value 1 means that 1 item has been already counted in capacity and profit of the knapsack and quantity variable should be offset by one. Both min and max values will be reduced by one.
      • positionInTheTree

        public int positionInTheTree
        It specifies the position in the tree.
    • Constructor Detail

      • TreeLeaf

        public TreeLeaf​(IntVar quantity,
                        int weight,
                        int profit,
                        int positionInTheTree)
        It creates a leaf in the tree of items.
        Parameters:
        quantity - finite domain variable specifying the quantity.
        weight - it specifies the weight of one instance of the item.
        profit - it specifies the profit of one instance of the item.
        positionInTheTree - it specifies the position in the tree.
    • Method Detail

      • getVariable

        public final IntVar getVariable()
        Returns:
        The variable stored in this leaf
      • getProfitOfOne

        public int getProfitOfOne()
        Returns:
        The profit of one unit of the variable
      • getWeightOfOne

        public int getWeightOfOne()
        Returns:
        The weight of one unit of the variable
      • hasMinChanged

        public final boolean hasMinChanged()
        Used to know the changes that occurred
        Returns:
        If the minimum has changed
      • lastIncreasedOfMin

        public final int lastIncreasedOfMin()
        Used to know the changes that occurred
        Returns:
        The last change of the minimum
      • hasMaxChanged

        public final boolean hasMaxChanged()
        Used to know the changes that occurred
        Returns:
        If the maximum has changed
      • getWMax

        public final int getWMax()
        Description copied from class: TreeNode
        It does not recompute the maximum of weights.
        Overrides:
        getWMax in class TreeNode
        Returns:
        The previously computed maximum weight of its children
      • getWSum

        public final int getWSum()
        Description copied from class: TreeNode
        It does not recompute sum of weights.
        Overrides:
        getWSum in class TreeNode
        Returns:
        The previously computed sum of weights of its children
      • getPSum

        public final int getPSum()
        Description copied from class: TreeNode
        It does not recompute sum of profits.
        Overrides:
        getPSum in class TreeNode
        Returns:
        The previously computed sum of profits of its children
      • isLeaf

        public final boolean isLeaf()
        Overrides:
        isLeaf in class TreeNode
        Returns:
        true if the node is a leaf, false otherwise.
      • getEfficiency

        public final double getEfficiency()
        It returns computed beforehand the efficiency of the item stored in this tree leaf.
        Returns:
        the efficiency of the item stored at this computer.
      • toString

        public final java.lang.String toString()
        Overrides:
        toString in class TreeNode
      • nodeToString

        public final java.lang.String nodeToString()
        Description copied from class: TreeNode
        It generates description of the node only.
        Overrides:
        nodeToString in class TreeNode
        Returns:
        the description containing values of all node internal attributes.
      • updateInternalValues

        public void updateInternalValues​(Tree tree)
        Only used in removeLevelLate(), update the internal value like previous and slice. It does not updates anything else in the tree.
        Parameters:
        tree - it specifies the tree to which this leaf belongs too.
      • min

        public final int min()
        Returns:
        The minimum value of the variable after slicing.
      • max

        public final int max()
        Returns:
        The maximum value of the variable after slicing
      • recomputeDown

        public void recomputeDown​(Tree tree)
        Description copied from class: TreeNode
        This function recomputes the attributes of this node after recomputing the left and right subtree.
        Overrides:
        recomputeDown in class TreeNode
        Parameters:
        tree - It is required by leaves so tree atributes like alreadyUsedCapacity are properly updated.
      • recomputeUp

        public void recomputeUp​(Tree tree)
        Description copied from class: TreeNode
        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.
        Overrides:
        recomputeUp in class TreeNode
        Parameters:
        tree - only added to be in agreement with the function template for leaf which need information about tree it belongs to.