Class InArea

java.lang.Object
org.jacop.constraints.geost.InArea
All Implemented Interfaces:
ExternalConstraint

public class InArea extends Object implements ExternalConstraint
Version:
4.10

InArea constraint allows on to define an area within which objects should be contained, as well as a collection of "holes" within the area

TODO implement the use of a subset of objects only. In some applications, classes of objects may need to be placed in different portions of the space. Possibly, create class InAreaSetOfObjects extending from InArea to allow specification of the objects in the focus of the constraint.

  • Field Details

    • allowedArea

      public DBox allowedArea
      It specifies the allowed area in which the objects can reside.
    • holes

      public Collection<DBox> holes
      It specifies the holes within the allowed area in which the objects can not be placed.
    • constraints

      public Set<InternalConstraint> constraints
      It holds all the constraints which have been generated from this external constraints.
  • Constructor Details

    • InArea

      public InArea(DBox area, Collection<DBox> holes)
      It constructs an external constraint to enforce that all objects within Geost constraint are placed within a specified area with holes in that area specfied as well.
      Parameters:
      area - the specification of the area within which the objects have to be placed.
      holes - the holes in which the objects can not be placed.
  • Method Details

    • checkInvariants

      public String checkInvariants()
      It checks whether the InArea is consistent.
      Returns:
      It returns the string description of the problem, or null if no problem with data structure consistency encountered.
    • genInternalConstraints

      public Collection<InternalConstraint> genInternalConstraints(Geost geost)
      Description copied from interface: ExternalConstraint
      It generates internal constraints which will be used by Geost's sweeping algorithm.

      The generation of internal constraints is done only once per search, implying that it is possible to do costly operations in order to generate internal constraints. However, another implication of this one-time use is that the internal constraints generated have to remain valid during the whole search.

      Specified by:
      genInternalConstraints in interface ExternalConstraint
      Parameters:
      geost - the geost kernel that will use the generated constraint
      Returns:
      the collection of internal constraints which correspond to this external constraint
    • addPrunableObjects

      public boolean addPrunableObjects(GeostObject o, SimpleHashSet<GeostObject> accumulator)
      Description copied from interface: ExternalConstraint
      It adds to the accumulator collection the objects that are likely to be pruned if the given object changes. For instance, in the case of the non-overlapping constraint, these would be the objects that are close to the given object.

      TODO, optimize all the code around this functionality, avoid situation when accumulator has all objects anyway and external constraints are continuously queried to add objects and keep adding objects which are already in the set.

      Specified by:
      addPrunableObjects in interface ExternalConstraint
      Parameters:
      o - the object that was pruned
      accumulator - the set of objects to add the object to
      Returns:
      true if a value was added, false otherwise
    • onObjectUpdate

      public void onObjectUpdate(GeostObject o)
      Description copied from interface: ExternalConstraint
      Handler method called by the Geost kernel when the domain of the object changes. Use this method to make changes to the state of the constraint (and of its relative internal constraints) if needed.
      Specified by:
      onObjectUpdate in interface ExternalConstraint
      Parameters:
      o - the object
    • getObjectConstraints

      public Collection<? extends InternalConstraint> getObjectConstraints(GeostObject o)
      Description copied from interface: ExternalConstraint
      It provides the collection of internal constraints that the given object has to satisfy. For instance, for the non overlapping constraint, the result would contain all the constraints corresponding to the objects in the non overlapping group.

      This method is used by the kernel only once per object, at the beginning of the search, to collect the set of constraints to use for each object.

      Specified by:
      getObjectConstraints in interface ExternalConstraint
      Parameters:
      o - the geost object that needs to be constrained
      Returns:
      the collection of internal constraints acting on the given object
    • isInternalConstraintApplicableTo

      public boolean isInternalConstraintApplicableTo(InternalConstraint ic, GeostObject o)
      Description copied from interface: ExternalConstraint
      Returns true if the external constraint generated the supplied internal constraint ic, and that ic applies to object o.
      Specified by:
      isInternalConstraintApplicableTo in interface ExternalConstraint
      Parameters:
      ic - internal constraint being checked
      o - object to which internal constrain should apply to
      Returns:
      true if the constraint was generated by this external constraint for the object o.
    • getObjectScope

      public GeostObject[] getObjectScope()
      Description copied from interface: ExternalConstraint
      Provides the collection of objects that this constraint applies to
      Specified by:
      getObjectScope in interface ExternalConstraint
      Returns:
      the collection of objects, or null if the constraint applies to all objects
    • toString

      public String toString()
      Overrides:
      toString in class Object