Class TreeLeaf

java.lang.Object
org.jacop.constraints.knapsack.TreeNode
org.jacop.constraints.knapsack.TreeLeaf

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

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

    Fields inherited from class org.jacop.constraints.knapsack.TreeNode

    left, leftNeighbor, parent, right, rightNeighbor
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    final double
    It returns computed beforehand the efficiency of the item stored in this tree leaf.
    int
     
    final int
    It does not recompute sum of profits.
    final IntVar
     
    int
     
    final int
    It does not recompute the maximum of weights.
    final int
    It does not recompute sum of weights.
    final boolean
    Used to know the changes that occurred
    final boolean
    Used to know the changes that occurred
    final boolean
     
    final int
    Used to know the changes that occurred
    final int
    max()
     
    final int
    min()
     
    final String
    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.
    final String
     
    void
    Only used in removeLevelLate(), update the internal value like previous and slice.

    Methods inherited from class org.jacop.constraints.knapsack.TreeNode

    setLeftNeighbor, setRightNeighbor

    Methods inherited from class java.lang.Object

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

    • 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 Details

    • 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 Details

    • 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 String toString()
      Overrides:
      toString in class TreeNode
    • nodeToString

      public final 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.