Class 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.9
  • Field Details

    • idNumber

      static AtomicInteger idNumber
    • trace

      protected static final boolean trace
      See Also:
    • traceNarr

      private static final boolean traceNarr
      See Also:
    • currentStore

      Store currentStore
    • minPosition

      private int minPosition
    • stamp

      int stamp
    • durMax

      private List<Integer> durMax
    • variableQueue

      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 Function<Integer,Comparator<IntRectangle>> dimIthMinComparator
  • Constructor Details

    • 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(List<? extends 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(List<? extends 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(List<? extends IntVar> o1, List<? extends IntVar> o2, List<? extends IntVar> l1, 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(List<? extends IntVar> o1, List<? extends IntVar> o2, List<? extends IntVar> l1, 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 Details

    • 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 interface Stateful
      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 class Constraint
      Parameters:
      store - constraint store within which the constraint consistency is being checked.
    • containsChangedVariable

      boolean containsChangedVariable(Rectangle r, Set<IntVar> fdvQueue)
    • findRectangles

      private boolean findRectangles(Rectangle r, List<IntRectangle> UsedRect, List<Rectangle> ProfileCandidates, Set<IntVar> fdvQueue)
    • getDefaultConsistencyPruningEvent

      public int getDefaultConsistencyPruningEvent()
      Specified by:
      getDefaultConsistencyPruningEvent in class Constraint
    • 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, List<IntRectangle> ConsideredRect)
    • narrowIth

      private void narrowIth(int i, Rectangle r, List<IntRectangle> UsedRect, List<Rectangle> ProfileCandidates)
    • computeNewMaxDuration

      private void computeNewMaxDuration(IntVar start, int durMin, int excludeMin, int excludeMax)
    • narrowRectangle

      void narrowRectangle(Rectangle r, List<IntRectangle> UsedRect, List<Rectangle> ProfileCandidates)
    • narrowRectangles

      void narrowRectangles(Set<IntVar> fdvQueue)
    • notFit

      private boolean notFit(int i, Rectangle r, 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, 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 class Constraint
      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 interface SatisfiedPresent
      Returns:
      true if constraint is possible to verify that it is satisfied.
    • toString

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