JaCoP.constraints.geost
Class Geost

java.lang.Object
  extended by JaCoP.constraints.DecomposedConstraint
      extended by JaCoP.constraints.Constraint
          extended by JaCoP.constraints.geost.Geost

public class Geost
extends Constraint

Author:
Marc-Olivier Fleury and Radoslaw Szymanek 1) DONE. FlushAndQueue function should be changed and some functionality moved to firstConsistencyCheck. 2) DONE. No propagation inside queueVariable function. 3) DONE. How to incorporate GUI code within Geost constraint. 4) DONE. Move part of the functionality of onObjectUpdate to consistency function. 5) Refactor use of TimeBoundConstraint 5b) DONE. remove runTimeConstraint boolean variable. 6) DONE. asserts for Shape register 6b) asserts about possible values of MaxInt and MinInt. 7) DONE. Use simpleHashSet instead of LinkedHashSet for objectQueue. 8) DONE. Discuss pruning events, do we really need ANY for all variables? For example, maybe time variables always BOUND pruning event. 9) DONE. Simplify queueObject by removing if statements and make sure that this function is being called properly (avoid non-asserts checks inside it). 10) DONE. Discuss the possible implementation of satisfied function. 11) Introduce time switch so geost can work without time dimension. 12) Lessen the feature of geost that it does not work with variables used multiple times within different objects 12b) DONE. (at least for singleton variables). 13) DONE. Verify fix to address bug in case of multiple level removals, or level removals for which no consistency function has been called. Functionality around variable currentLevel. It is still needed. 14. DONE. Fixing a bug connected with timestamps and multiple remove levels calls. 14b Check lastLevelVar (possibly needs to be done similarly as setStart). Future Work : 1. InArea should support subset of objects and dimensions. 2. Reuse previously generated outboxes. Create a function to create a hashkey from points coordinates for which an outbox is required. Later, for each new point we check if we have proper outbox for a given hash-key generated from this outbox. 3. Not always finishing at consistency fixpoint, speculative fixpoint. 4. consider polymorphism due to rotations only, and see if better performance can be reached under this assumption. 5. If objects have the same shape, and they are indistingushable then symmetry breaking can be employed.

Nested Class Summary
static class Geost.SweepDirection
           
 
Field Summary
 boolean alwaysUseFrames
          It defines whether outbox generation should always rely on overlapping frames.
 boolean backtracking
          It is a flag set to true during remove level late function execution so objects which are being updated upon backtracking can be handled properly.
 boolean enforceNoSkip
          if set to true, a variable will never be skipped, even if grounded and not in queue
 ExternalConstraint[] externalConstraints
          It stores the reference to the collection of external constraints which must be satisfied within this constraint.
 boolean filterUseless
          It specifies that filtering of useless internal constraint takes place before an object is being pruned.
 java.util.Collection<InternalConstraint> internalConstraints
          It stores all generated internal constraints for all objects/constraints.
 GeostObject[] objects
          It stores the reference to the collection of objects provided to the constructor.
 LexicographicalOrder order
          It specifies the order between dimensions which is used by the pruning algorithm.
 boolean partialShapeSweep
          set to false to disable relaxed shape pruning
 Shape[] shapeRegister
          It stores information about shapes used by objects within this geost constraint.
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
Geost(java.util.Collection<GeostObject> objects, java.util.Collection<ExternalConstraint> constraints, java.util.Collection<Shape> shapes)
           
Geost(GeostObject[] objects, ExternalConstraint[] constraints, Shape[] shapes)
          It creates a geost constraint from provided objects, external constraints, as well as shapes.
 
Method Summary
 java.util.ArrayList<Var> arguments()
          It returns the variables in a scope of the constraint.
 java.lang.String checkInvariants()
          It checks that this constraint has consistent data structures.
 void consistency(Store store)
          It is a (most probably incomplete) consistency function which removes the values from variables domains.
 int getConsistencyPruningEvent(Var var)
          It retrieves the pruning event which causes reevaluation of the constraint.
 Shape getShape(int id)
          It returns the shape with a given id if such exists.
 java.util.List<java.lang.Long> getStatistics()
          It returns all the statistics gathered by geost constraint during the search.
 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 increaseWeight()
          It increases the weight of the variables in the constraint scope.
 void queueObject(GeostObject o)
          It puts the object into the queue if it can be still pruned or cause failure.
 void queueVariable(int level, Var v)
          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)
          This function is called in case of the backtrack.
 boolean satisfied()
          Geost is satisfied if all of its external constraints are satisfied.
 java.lang.String toString()
          It produces a string representation of a constraint state.
 
Methods inherited from class JaCoP.constraints.Constraint
cleanAfterFailure, decompose, getGuideConstraint, getGuideValue, getGuideVariable, impose, imposeDecomposition, 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

enforceNoSkip

public boolean enforceNoSkip
if set to true, a variable will never be skipped, even if grounded and not in queue


partialShapeSweep

public boolean partialShapeSweep
set to false to disable relaxed shape pruning


internalConstraints

public java.util.Collection<InternalConstraint> internalConstraints
It stores all generated internal constraints for all objects/constraints. It is used to speed up some visualization functions. If not for that reason it could have been a local variable within a function generating internal constraints.


order

public final LexicographicalOrder order
It specifies the order between dimensions which is used by the pruning algorithm. The order may have influence on the algorithm efficiency. The geost constraint chooses the order based on average length of objects in the particular dimension. The dimension with higher average length in this dimension will have the preference.


filterUseless

public final boolean filterUseless
It specifies that filtering of useless internal constraint takes place before an object is being pruned. It may be costly for small instances.

See Also:
Constant Field Values

alwaysUseFrames

public boolean alwaysUseFrames
It defines whether outbox generation should always rely on overlapping frames. For problems that contain objects that have small domains compared to their size, then using only frames may provide a better performance (up to 50% faster). It can only be changed before impose() function, changing it afterwards will lead to improper behavior.


backtracking

public boolean backtracking
It is a flag set to true during remove level late function execution so objects which are being updated upon backtracking can be handled properly.


objects

public final GeostObject[] objects
It stores the reference to the collection of objects provided to the constructor. It does not perform cloning so the collection can not change after geost constraint was imposed.


externalConstraints

public final ExternalConstraint[] externalConstraints
It stores the reference to the collection of external constraints which must be satisfied within this constraint. This is a reference to the collection provided within the constructor. No copying is employed therefore the collection can not change even after the constraint is imposed.


shapeRegister

public final Shape[] shapeRegister
It stores information about shapes used by objects within this geost constraint. It is based on shapes information provided in the constructor.


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

Geost

public Geost(java.util.Collection<GeostObject> objects,
             java.util.Collection<ExternalConstraint> constraints,
             java.util.Collection<Shape> shapes)

Geost

public Geost(GeostObject[] objects,
             ExternalConstraint[] constraints,
             Shape[] shapes)
It creates a geost constraint from provided objects, external constraints, as well as shapes. The construct parameters are not cloned so do not reuse them in creation in other constraints if changes are necessary. Make sure that the largest object id is as small as possible to avoid unnecessary memory cost.

Parameters:
objects - objects in the scope of the geost constraint.
constraints - the collection of external constraints enforced by geost.
shapes - the list of different shapes used by the objects in scope of the geost.
Method Detail

checkInvariants

public java.lang.String checkInvariants()
It checks that this constraint has consistent data structures.

Returns:
a string describing the consistency problem with data structures, null if no problem encountered.

getShape

public final Shape getShape(int id)
It returns the shape with a given id if such exists.

Parameters:
id - the unique id of the shape we are looking for.
Returns:
the shape of a given id previously provided.

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.

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.

queueObject

public final void queueObject(GeostObject o)
It puts the object into the queue if it can be still pruned or cause failure.

Parameters:
o - the object which is possibly put into the queue.

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.

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.

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

queueVariable

public void queueVariable(int level,
                          Var v)
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.
v - variable which has changed.

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

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)
Description copied from class: Constraint
This function is called in case of the backtrack. It is called after all timestamps, variables, mutablevariables have reverted to their values *after* removing the level.

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

satisfied

public boolean satisfied()
Geost is satisfied if all of its external constraints are satisfied.

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

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

getStatistics

public java.util.List<java.lang.Long> getStatistics()
It returns all the statistics gathered by geost constraint during the search.

Returns:
an array list consisting of different statistics collected during search.