Class CreditCalculator<T extends Var>

    • Field Detail

      • timeOut

        boolean timeOut
      • backtracks

        int backtracks
      • currentLevel

        int currentLevel
      • currentBacktracks

        int currentBacktracks
      • creditsLeft

        int[] creditsLeft
      • creditsRight

        int[] creditsRight
      • leftChild

        boolean leftChild
    • Constructor Detail

      • CreditCalculator

        public CreditCalculator​(int credit,
                                int backtracks,
                                int maxDepth)
        The constructor allows to specify number of credits. Credits of the parent are divided equally among children. As soon a node has only one credit, there is a restriction how many backtracks can be performed in search in the left and right child altogether. If nodes are at maxDepth then the credits are not splitted among children but sent back to the parent for use in other parts of the tree. In a nutshell, there are maximally credit number of search subtrees attached at depth no lower than max depth with a maximumally number of backtracks performed in those subtrees. This approach allows to limit detrimental effect of early mistake which can not be proven easily by a backtrack search.
        Parameters:
        credit - the number of credits given to a search.
        backtracks - the maximum number of allowed backtracks from the node which has no remaining credits.
        maxDepth - the maximum depth at which it is still alowed to distribute credits.
      • CreditCalculator

        public CreditCalculator​(int credit,
                                int backtracks)
        The constructor allows to specify number of credits. Credits of the parent are divided equally among children. As soon a node has only one credit, there is a restriction how many backtracks can be performed in search in the left and right child altogether. This approach allows to limit detrimental effect of early mistake which can not be proven easily by a backtrack search.
        Parameters:
        credit - the number of credits given to a search.
        backtracks - the maximum number of allowed backtracks from the node which has no remaining credits.
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • executeAfterConsistency

        public boolean executeAfterConsistency​(boolean consistent)
        It is executed right after consistency of the current search node. The return code specifies if the search should continue with or exit the current search node.
        Specified by:
        executeAfterConsistency in interface ConsistencyListener
        Parameters:
        consistent - specifies if the consistency call returned true or false.
        Returns:
        true if the search should continue, false if the search should act as the consistency returned false.
      • executedAtTimeOut

        public void executedAtTimeOut​(int noSolutions)
        It is executed right after time out is determined.
        Specified by:
        executedAtTimeOut in interface TimeOutListener
        Parameters:
        noSolutions - number of solutions found before the timeout occurred.
      • leftChild

        public boolean leftChild​(T var,
                                 int value,
                                 boolean status)
        It is executed after exiting the left child. The parameters specify the variable and value used in the choice point. The parameter status specifies the return code from the child. The return parameter of this function specifies if the search should continue undisturbed or exit the current search node with false.
        Specified by:
        leftChild in interface ExitChildListener<T extends Var>
        Parameters:
        var - variable used in the choice point.
        value - value used in the choice point.
        status - true if the solution was found in the child subtree, false otherwise.
        Returns:
        true if the search should continue undisturbed, false if it should exit the current node with false
      • leftChild

        public boolean leftChild​(PrimitiveConstraint choice,
                                 boolean status)
        It is executed after exiting the left child. The parameters specify the choice point. The parameter status specifies the return code from the child. The return parameter of this function specifies if the search should continue undisturbed or exit the current search node. If the left child has exhausted backtracks allowance then this function will return false so the right child will not be explored.
        Specified by:
        leftChild in interface ExitChildListener<T extends Var>
        Parameters:
        choice - primitive constraint used as the base of the choice point.
        status - true if the solution was found in the child subtree, false otherwise.
        Returns:
        true if the search should continue undisturbed to the right node, false if it should exit the current node with false
      • rightChild

        public void rightChild​(T var,
                               int value,
                               boolean status)
        Exiting the right children if no credits have been distributed to a right child involves increasing the number of backtracks occurred.
        Specified by:
        rightChild in interface ExitChildListener<T extends Var>
        Parameters:
        var - variable used in the choice point.
        value - value used in the choice point.
        status - true if the solution was found in the child subtree, false otherwise. exit the current node with false
      • rightChild

        public void rightChild​(PrimitiveConstraint choice,
                               boolean status)
        Description copied from interface: ExitChildListener
        It is executed after exiting the right child.
        Specified by:
        rightChild in interface ExitChildListener<T extends Var>
        Parameters:
        choice - primitive constraint used as the base of the choice point.
        status - true if the solution was found in the child subtree, false otherwise. exit the current node with false
      • setChildrenListeners

        public void setChildrenListeners​(ConsistencyListener[] children)
        Description copied from interface: ConsistencyListener
        Each of the child listeners will be called and the return code from them will be combined (taken into account) by a parent).
        Specified by:
        setChildrenListeners in interface ConsistencyListener
        Parameters:
        children - the children listeners attached to this listener.