JaCoP.constraints.regular
Class Regular

java.lang.Object
  extended by JaCoP.constraints.DecomposedConstraint
      extended by JaCoP.constraints.Constraint
          extended by JaCoP.constraints.regular.Regular

public class Regular
extends Constraint

Regular constraint accepts only the assignment to variables which is accepted by an automaton. This constraint implements a polynomial algorithm to establish GAC. There are number of improvements (iterative execution, optimization of computational load upon backtracking) to improve the constraint further.

Version:
3.1
Author:
Polina Makeeva and Radoslaw Szymanek

Field Summary
static boolean debugAll
          It specifies if debugging information should be printed out.
 java.util.HashMap<java.lang.Integer,java.lang.String> dNames
          dNames contain a "name" for each value from the union of all variabl's domains.
 FSM fsm
          It specifies finite state machine used by this regular.
 java.lang.String latexFile
          Name of the file to store the latex output after consistency call The output will be : file_name + "call number" + ".tex"
 IntVar[] list
          Array of the variables of the graph levels
 boolean listRepresentation
          It specifies if the edges should have a list of values associated with them.
 boolean oneSupport
          It specifies if the support functionality should be used.
 boolean optimizedMDD
          It specifies if the translation of FSM into optimized MDD should take place so minimal layered graph can be obtained.
static boolean saveAllToLatex
          It specifies if constraint description should be saved to latex for later viewing.
 java.util.HashMap<java.lang.Integer,RegEdge>[] supports
          It keeps for each variable value pair a current support.
static java.lang.String[] xmlAttributes
          It specifies the arguments required to be saved by an XML format as well as the constructor being called to recreate an object from an XML format.
 
Fields inherited from class JaCoP.constraints.Constraint
atomicExecution, consistencyPruningEvents, earlyTerminationOK, id, increaseWeight, numberArgs, numberId
 
Fields inherited from class JaCoP.constraints.DecomposedConstraint
queueIndex
 
Constructor Summary
Regular(FSM fsm, IntVar[] list)
          Constructor need Store to initialize the time-stamps
 
Method Summary
 java.util.ArrayList<Var> arguments()
          It returns the variables in a scope of the constraint.
 void consistency(Store store)
          It is a (most probably incomplete) consistency function which removes the values from variables domains.
 java.util.ArrayList<Constraint> decompose(Store store)
          It returns an array list of constraint which are used to decompose this constraint.
 void disableState(int level, int pos)
          It marks state as being not active.
 int getConsistencyPruningEvent(Var var)
          It retrieves the pruning event which causes reevaluation of the constraint.
 RegState getState(int level, int id)
          Find the state with the corresponding id.
 java.lang.String id()
          It gives the id string of a constraint.
 void impose(Store store)
          It imposes the constraint in a given store.
 void imposeDecomposition(Store store)
          It imposes the decomposition of the given constraint in a given store.
 void increaseWeight()
          It increases the weight of the variables in the constraint scope.
 void pruneArc(int varIndex)
          Collects the damaged states, after pruning the domain of variable "var", and put these states in two separated sets.
 void queueVariable(int level, Var var)
          This is a function called to indicate which variable in a scope of constraint has changed.
 void removeConstraint()
          It removes the constraint by removing this constraint from all variables.
 void removeLevel(int level)
          This function is called in case of the backtrack, so a constraint can clear the queue of changed variables which is no longer valid.
 void removeLevelLate(int level)
          Sweep the graph upon backtracking.
 boolean satisfied()
          It checks if the constraint is satisfied.
 void saveLatexToFile(java.lang.String desc)
          It saves the constraint latex description into file.
 void setLatexBaseFileName(java.lang.String filename)
          It sets the filename for the file which is used to save latex descriptions.
 java.lang.String toLatex(java.lang.String addDescription)
          It creates a latex description of the constraint state.
 java.lang.String toString()
          It produces a string representation of a constraint state.
 int unreachBackwardLoop(int sucPrevLimit, int level)
          It does backward check to remove inactive edges and states.
 void unreachForwardLoop(int end, int level)
          Forward part deletes the outgoing edges of the damaged state and watch whether the successors are still active (in-degree > 0 ), otherwise we collect it and continue the loop.
 void uppendToLatexFile(java.lang.String desc, java.lang.String fileName)
          It appends latex description of the constraint current state to the specified filename.
 
Methods inherited from class JaCoP.constraints.Constraint
cleanAfterFailure, getGuideConstraint, getGuideValue, getGuideVariable, impose, numberArgs, requiresMonotonicity, setConsistencyPruningEvent, supplyGuideFeedback
 
Methods inherited from class JaCoP.constraints.DecomposedConstraint
auxiliaryVariables, imposeDecomposition
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

debugAll

public static final boolean debugAll
It specifies if debugging information should be printed out.

See Also:
Constant Field Values

saveAllToLatex

public static final boolean saveAllToLatex
It specifies if constraint description should be saved to latex for later viewing.

See Also:
Constant Field Values

optimizedMDD

public final boolean optimizedMDD
It specifies if the translation of FSM into optimized MDD should take place so minimal layered graph can be obtained. This option most of the time causes out of memory exception as it requires finding and storing all solutions in mtrie before translation to an optimized MDD can take place. FSM also has to be a deterministic one.

See Also:
Constant Field Values

latexFile

public java.lang.String latexFile
Name of the file to store the latex output after consistency call The output will be : file_name + "call number" + ".tex"


dNames

public java.util.HashMap<java.lang.Integer,java.lang.String> dNames
dNames contain a "name" for each value from the union of all variabl's domains. If Hashmap - dNames - is not null then upon saving the latex graph the values on the edges will be replaced with their "names".


supports

public java.util.HashMap<java.lang.Integer,RegEdge>[] supports
It keeps for each variable value pair a current support.


listRepresentation

public boolean listRepresentation
It specifies if the edges should have a list of values associated with them.


oneSupport

public boolean oneSupport
It specifies if the support functionality should be used.


fsm

public FSM fsm
It specifies finite state machine used by this regular.


list

public IntVar[] list
Array of the variables of the graph levels


xmlAttributes

public static java.lang.String[] xmlAttributes
It specifies the arguments required to be saved by an XML format as well as the constructor being called to recreate an object from an XML format.

Constructor Detail

Regular

public Regular(FSM fsm,
               IntVar[] list)
Constructor need Store to initialize the time-stamps

Parameters:
fsm - (deterministic) finite automaton
list - variables which values have to be accepted by the automaton.
Method Detail

getState

public RegState getState(int level,
                         int id)
Find the state with the corresponding id.

Parameters:
level - specifies the variable for which the state is seeked for.
id - specifies the id of the state.
Returns:
the state at given level with a given id.

pruneArc

public void pruneArc(int varIndex)
Collects the damaged states, after pruning the domain of variable "var", and put these states in two separated sets. One with the states with zero incoming degree - these are the candidates for the forward part. The other set consists of states with zero out-coming degree - these are the candidates for backward part.

Parameters:
varIndex - the index of the variable which have changed.

unreachBackwardLoop

public int unreachBackwardLoop(int sucPrevLimit,
                               int level)
It does backward check to remove inactive edges and states.

Parameters:
sucPrevLimit - previous number of states at a given level.
level - level for which the backward sweep is computed.
Returns:
level at which the sweep has ended. TODO return value is not used.

unreachForwardLoop

public void unreachForwardLoop(int end,
                               int level)
Forward part deletes the outgoing edges of the damaged state and watch whether the successors are still active (in-degree > 0 ), otherwise we collect it and continue the loop. TODO return value is not used.

Parameters:
end - the position of the last active state at a given level.
level - level being examined.

disableState

public void disableState(int level,
                         int pos)
It marks state as being not active.

Parameters:
level - level at which the state is residing.
pos - position of the state in the array of states.

arguments

public java.util.ArrayList<Var> arguments()
Description copied from class: Constraint
It returns the variables in a scope of the constraint.

Specified by:
arguments in class Constraint
Returns:
variables in a scope of the constraint.

removeLevel

public void removeLevel(int level)
Description copied from class: Constraint
This function is called in case of the backtrack, so a constraint can clear the queue of changed variables which is no longer valid. This function is called *before* all timestamps, variables, mutablevariables have reverted to their previous value.

Overrides:
removeLevel in class Constraint
Parameters:
level - the level which is being removed.

removeLevelLate

public void removeLevelLate(int level)
Sweep the graph upon backtracking.

Overrides:
removeLevelLate in class Constraint
Parameters:
level - the level which is being removed.

queueVariable

public void queueVariable(int level,
                          Var var)
Description copied from class: Constraint
This is a function called to indicate which variable in a scope of constraint has changed. It also indicates a store level at which the change has occurred.

Overrides:
queueVariable in class Constraint
Parameters:
level - the level of the store at which the change has occurred.
var - variable which has changed.

consistency

public void consistency(Store store)
Description copied from class: Constraint
It is a (most probably incomplete) consistency function which removes the values from variables domains. Only values which do not have any support in a solution space are removed.

Specified by:
consistency in class Constraint
Parameters:
store - constraint store within which the constraint consistency is being checked.

impose

public void impose(Store store)
Description copied from class: Constraint
It imposes the constraint in a given store.

Specified by:
impose in class Constraint
Parameters:
store - the constraint store to which the constraint is imposed to.

satisfied

public boolean satisfied()
Description copied from class: Constraint
It checks if the constraint is satisfied. If this function is incorrectly implemented a constraint may not be satisfied in a solution.

Specified by:
satisfied in class Constraint
Returns:
true if the constraint is for certain satisfied, false otherwise.

getConsistencyPruningEvent

public int getConsistencyPruningEvent(Var var)
Description copied from class: Constraint
It retrieves the pruning event which causes reevaluation of the constraint.

Specified by:
getConsistencyPruningEvent in class Constraint
Parameters:
var - variable for which pruning event is retrieved
Returns:
it returns the int code of the pruning event (GROUND, BOUND, ANY, NONE)

id

public java.lang.String id()
Description copied from class: Constraint
It gives the id string of a constraint.

Specified by:
id in class Constraint
Returns:
string id of the constraint.

removeConstraint

public void removeConstraint()
Description copied from class: Constraint
It removes the constraint by removing this constraint from all variables.

Specified by:
removeConstraint in class Constraint

toString

public java.lang.String toString()
Description copied from class: Constraint
It produces a string representation of a constraint state.

Specified by:
toString in class Constraint

imposeDecomposition

public void imposeDecomposition(Store store)
Description copied from class: Constraint
It imposes the decomposition of the given constraint in a given store.

Overrides:
imposeDecomposition in class Constraint
Parameters:
store - the constraint store to which the constraint is imposed to.

decompose

public java.util.ArrayList<Constraint> decompose(Store store)
Description copied from class: Constraint
It returns an array list of constraint which are used to decompose this constraint. It actually creates a decomposition (possibly also creating variables), but it does not impose the constraint.

Overrides:
decompose in class Constraint
Parameters:
store - the constraint store in which context the decomposition takes place.
Returns:
an array list of constraints used to decompose this constraint.

toLatex

public java.lang.String toLatex(java.lang.String addDescription)
It creates a latex description of the constraint state.

Parameters:
addDescription - added description.
Returns:
description of the constraint state.

saveLatexToFile

public void saveLatexToFile(java.lang.String desc)
It saves the constraint latex description into file.

Parameters:
desc -

setLatexBaseFileName

public void setLatexBaseFileName(java.lang.String filename)
It sets the filename for the file which is used to save latex descriptions.

Parameters:
filename -

uppendToLatexFile

public void uppendToLatexFile(java.lang.String desc,
                              java.lang.String fileName)
It appends latex description of the constraint current state to the specified filename.

Parameters:
desc - appended description.
fileName - filename where the description is appended.

increaseWeight

public void increaseWeight()
Description copied from class: Constraint
It increases the weight of the variables in the constraint scope.

Specified by:
increaseWeight in class Constraint