Package org.jacop.constraints
Class Diff
- java.lang.Object
-
- org.jacop.constraints.DecomposedConstraint<Constraint>
-
- org.jacop.constraints.Constraint
-
- org.jacop.constraints.Diff
-
- All Implemented Interfaces:
SatisfiedPresent
,Stateful
,UsesQueueVariable
- Direct Known Subclasses:
Diff2
,Disjoint
,DisjointConditional
public class Diff extends Constraint implements UsesQueueVariable, Stateful, SatisfiedPresent
Diff constraint assures that any two rectangles from a vector of rectangles does not overlap in at least one direction. It is a simple implementation which does not use sophisticated techniques for efficient backtracking.- Version:
- 4.8
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
Diff.Pair
-
Field Summary
Fields Modifier and Type Field Description (package private) Store
currentStore
protected java.util.function.Function<java.lang.Integer,java.util.Comparator<IntRectangle>>
dimIthMinComparator
(package private) boolean
doProfile
It specifies if the constraint should compute and use the profile.private java.util.List<java.lang.Integer>
durMax
(package private) static java.util.concurrent.atomic.AtomicInteger
idNumber
private int
minPosition
Rectangle[]
rectangles
It specifies the list of rectangles which are of interest for this diff constraint.(package private) int
stamp
protected static boolean
trace
private static boolean
traceNarr
(package private) java.util.Set<IntVar>
variableQueue
-
Fields inherited from class org.jacop.constraints.Constraint
afcWeight, atomicExecution, consistencyPruningEvents, constraintScope, earlyTerminationOK, increaseWeight, numberId, scope, watchedVariableGrounded
-
Fields inherited from class org.jacop.constraints.DecomposedConstraint
queueIndex
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Diff()
Diff(java.util.List<? extends java.util.List<? extends IntVar>> rectangles)
It specifies a diffn constraint.Diff(java.util.List<? extends java.util.List<? extends IntVar>> rectangles, boolean profile)
It specifies a diff constraint.Diff(java.util.List<? extends IntVar> o1, java.util.List<? extends IntVar> o2, java.util.List<? extends IntVar> l1, java.util.List<? extends IntVar> l2)
It constructs a diff constraint.Diff(java.util.List<? extends IntVar> o1, java.util.List<? extends IntVar> o2, java.util.List<? extends IntVar> l1, java.util.List<? extends IntVar> l2, boolean profile)
It constructs a diff constraint.Diff(Rectangle[] rectangles, boolean doProfile)
It specifies a diff constraint.Diff(IntVar[][] rectangles)
It specifies a diff constraint.Diff(IntVar[][] rectangles, boolean profile)
It specifies a diff constraint.Diff(IntVar[] origin1, IntVar[] origin2, IntVar[] length1, IntVar[] length2)
It constructs a diff constraint.Diff(IntVar[] o1, IntVar[] o2, IntVar[] l1, IntVar[] l2, boolean profile)
It constructs a diff constraint.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
computeNewMaxDuration(IntVar start, int durMin, int excludeMin, int excludeMax)
void
consistency(Store store)
It is a (most probably incomplete) consistency function which removes the values from variables domains.(package private) boolean
containsChangedVariable(Rectangle r, java.util.Set<IntVar> fdvQueue)
private boolean
findRectangles(Rectangle r, java.util.List<IntRectangle> UsedRect, java.util.List<Rectangle> ProfileCandidates, java.util.Set<IntVar> fdvQueue)
int
getDefaultConsistencyPruningEvent()
(package private) Rectangle[]
getRectangles()
(package private) boolean
intervalOverlap(int min1, int max1, int min2, int max2)
private Diff.Pair
minForbiddenInterval(int start, int i, Rectangle r, java.util.List<IntRectangle> ConsideredRect)
private void
narrowIth(int i, Rectangle r, java.util.List<IntRectangle> UsedRect, java.util.List<Rectangle> ProfileCandidates)
(package private) void
narrowRectangle(Rectangle r, java.util.List<IntRectangle> UsedRect, java.util.List<Rectangle> ProfileCandidates)
(package private) void
narrowRectangles(java.util.Set<IntVar> fdvQueue)
private boolean
notFit(int i, Rectangle r, java.util.List<IntRectangle> ConsideredRect, int barierPosition)
private void
profileCheckInterval(Store store, DiffnProfile Profile, int limit, IntVar Start, IntVar Duration, int iMin, int i_max, IntVar Resources)
(package private) void
profileCheckRectangle(DiffnProfile Profile, Rectangle r, int i, int j)
(package private) void
profileNarrowing(int i, Rectangle r, java.util.List<Rectangle> ProfileCandidates)
void
queueVariable(int level, Var V)
This is a function called to indicate which variable in a scope of constraint has changed.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.boolean
satisfied()
It checks if the constraint is satisfied.java.lang.String
toString()
It produces a string representation of a constraint state.-
Methods inherited from class org.jacop.constraints.Constraint
afc, arguments, cleanAfterFailure, decompose, getConsistencyPruningEvent, getGuideConstraint, getGuideValue, getGuideVariable, grounded, grounded, id, impose, impose, imposeDecomposition, increaseWeight, intArrayToString, long2int, numberArgs, removeConstraint, requiresMonotonicity, setConsistencyPruningEvent, setConstraintScope, setScope, setScope, setScope, setScope, setScope, setWatchedVariableGrounded, supplyGuideFeedback, toInt, toInt, updateAFC, watchedVariableGrounded
-
Methods inherited from class org.jacop.constraints.DecomposedConstraint
auxiliaryVariables, checkInput, checkInput, checkInputForDuplication, checkInputForDuplicationSkipSingletons, checkInputForNullness, checkInputForNullness, checkInputForNullness, derivative, getDubletonsSkipSingletons, imposeDecomposition
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jacop.api.Stateful
isStateful
-
-
-
-
Field Detail
-
idNumber
static java.util.concurrent.atomic.AtomicInteger idNumber
-
trace
protected static final boolean trace
- See Also:
- Constant Field Values
-
traceNarr
private static final boolean traceNarr
- See Also:
- Constant Field Values
-
currentStore
Store currentStore
-
minPosition
private int minPosition
-
stamp
int stamp
-
durMax
private java.util.List<java.lang.Integer> durMax
-
variableQueue
java.util.Set<IntVar> variableQueue
-
rectangles
public Rectangle[] rectangles
It specifies the list of rectangles which are of interest for this diff constraint.
-
doProfile
boolean doProfile
It specifies if the constraint should compute and use the profile.
-
dimIthMinComparator
protected java.util.function.Function<java.lang.Integer,java.util.Comparator<IntRectangle>> dimIthMinComparator
-
-
Constructor Detail
-
Diff
protected Diff()
-
Diff
public Diff(Rectangle[] rectangles, boolean doProfile)
It specifies a diff constraint.- Parameters:
rectangles
- list of rectangles which can not overlap in at least one dimension.doProfile
- should the constraint compute and use the profile functionality.
-
Diff
public Diff(IntVar[][] rectangles)
It specifies a diff constraint.- Parameters:
rectangles
- list of rectangles which can not overlap in at least one dimension.
-
Diff
public Diff(IntVar[] o1, IntVar[] o2, IntVar[] l1, IntVar[] l2, boolean profile)
It constructs a diff constraint.- Parameters:
o1
- list of variables denoting origin of the rectangle in the first dimension.o2
- list of variables denoting origin of the rectangle in the second dimension.l1
- list of variables denoting length of the rectangle in the first dimension.l2
- list of variables denoting length of the rectangle in the second dimension.profile
- it specifies if the profile should be computed and used.
-
Diff
public Diff(IntVar[] origin1, IntVar[] origin2, IntVar[] length1, IntVar[] length2)
It constructs a diff constraint.- Parameters:
origin1
- list of variables denoting origin of the rectangle in the first dimension.origin2
- list of variables denoting origin of the rectangle in the second dimension.length1
- list of variables denoting length of the rectangle in the first dimension.length2
- list of variables denoting length of the rectangle in the second dimension.
-
Diff
public Diff(java.util.List<? extends java.util.List<? extends IntVar>> rectangles)
It specifies a diffn constraint.- Parameters:
rectangles
- list of rectangles which can not overlap in at least one dimension.
-
Diff
public Diff(java.util.List<? extends java.util.List<? extends IntVar>> rectangles, boolean profile)
It specifies a diff constraint.- Parameters:
profile
- specifies is the profiles are used.rectangles
- list of rectangles which can not overlap in at least one dimension.
-
Diff
public Diff(java.util.List<? extends IntVar> o1, java.util.List<? extends IntVar> o2, java.util.List<? extends IntVar> l1, java.util.List<? extends IntVar> l2)
It constructs a diff constraint.- Parameters:
o1
- list of variables denoting origin of the rectangle in the first dimension.o2
- list of variables denoting origin of the rectangle in the second dimension.l1
- list of variables denoting length of the rectangle in the first dimension.l2
- list of variables denoting length of the rectangle in the second dimension.
-
Diff
public Diff(java.util.List<? extends IntVar> o1, java.util.List<? extends IntVar> o2, java.util.List<? extends IntVar> l1, java.util.List<? extends IntVar> l2, boolean profile)
It constructs a diff constraint.- Parameters:
o1
- list of variables denoting origin of the rectangle in the first dimension.o2
- list of variables denoting origin of the rectangle in the second dimension.l1
- list of variables denoting length of the rectangle in the first dimension.l2
- list of variables denoting length of the rectangle in the second dimension.profile
- it specifies if the profile should be computed and used.
-
Diff
public Diff(IntVar[][] rectangles, boolean profile)
It specifies a diff constraint.- Parameters:
profile
- specifies is the profiles are used.rectangles
- list of rectangles which can not overlap in at least one dimension.
-
-
Method Detail
-
removeLevel
public void removeLevel(int level)
Description copied from interface:Stateful
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.- Specified by:
removeLevel
in interfaceStateful
- Parameters:
level
- the level which is being removed.
-
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 classConstraint
- Parameters:
store
- constraint store within which the constraint consistency is being checked.
-
containsChangedVariable
boolean containsChangedVariable(Rectangle r, java.util.Set<IntVar> fdvQueue)
-
findRectangles
private boolean findRectangles(Rectangle r, java.util.List<IntRectangle> UsedRect, java.util.List<Rectangle> ProfileCandidates, java.util.Set<IntVar> fdvQueue)
-
getDefaultConsistencyPruningEvent
public int getDefaultConsistencyPruningEvent()
- Specified by:
getDefaultConsistencyPruningEvent
in classConstraint
-
getRectangles
Rectangle[] getRectangles()
-
intervalOverlap
boolean intervalOverlap(int min1, int max1, int min2, int max2)
-
minForbiddenInterval
private Diff.Pair minForbiddenInterval(int start, int i, Rectangle r, java.util.List<IntRectangle> ConsideredRect)
-
narrowIth
private void narrowIth(int i, Rectangle r, java.util.List<IntRectangle> UsedRect, java.util.List<Rectangle> ProfileCandidates)
-
computeNewMaxDuration
private void computeNewMaxDuration(IntVar start, int durMin, int excludeMin, int excludeMax)
-
narrowRectangle
void narrowRectangle(Rectangle r, java.util.List<IntRectangle> UsedRect, java.util.List<Rectangle> ProfileCandidates)
-
narrowRectangles
void narrowRectangles(java.util.Set<IntVar> fdvQueue)
-
notFit
private boolean notFit(int i, Rectangle r, java.util.List<IntRectangle> ConsideredRect, int barierPosition)
-
profileCheckInterval
private void profileCheckInterval(Store store, DiffnProfile Profile, int limit, IntVar Start, IntVar Duration, int iMin, int i_max, IntVar Resources)
-
profileCheckRectangle
void profileCheckRectangle(DiffnProfile Profile, Rectangle r, int i, int j)
-
profileNarrowing
void profileNarrowing(int i, Rectangle r, java.util.List<Rectangle> ProfileCandidates)
-
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 classConstraint
- Parameters:
level
- the level of the store at which the change has occurred.V
- variable which has changed.
-
satisfied
public boolean satisfied()
Description copied from interface:SatisfiedPresent
It checks if the constraint is satisfied. It can return false even if constraint is satisfied but not all variables in its scope are grounded. It needs to return true if all variables in its scope are grounded and constraint is satisfied.Implementations of this interface for constraints that are not PrimitiveConstraint may require constraint imposition and consistency check as a requirement to work correctly.
- Specified by:
satisfied
in interfaceSatisfiedPresent
- Returns:
- true if constraint is possible to verify that it is satisfied.
-
toString
public java.lang.String toString()
Description copied from class:Constraint
It produces a string representation of a constraint state.- Overrides:
toString
in classConstraint
-
-