org.cpsolver.ifs.example.rpp

## Class ResourceConstraint

- java.lang.Object
- - org.cpsolver.ifs.model.Constraint<V,T>
  - - org.cpsolver.ifs.assignment.context.ConstraintWithContext<Rectangle,Location,ResourceConstraint.Context>
    - - org.cpsolver.ifs.example.rpp.ResourceConstraint

- All Implemented Interfaces:
    Comparable<Constraint<Rectangle,Location>>, CanHoldContext, HasAssignmentContext<Rectangle,Location,ResourceConstraint.Context>

      public class ResourceConstraint
      extends ConstraintWithContext<Rectangle,Location,ResourceConstraint.Context>

  Resource constraint (rectangular area where the rectangles are to be placed). It prohibits overlapping of the placed rectangles.
  Version:
    IFS 1.3 (Iterative Forward Search)
    Copyright (C) 2006 - 2014 Tomáš Müller
    muller@unitime.org
    http://muller.unitime.org
    This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
    This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    You should have received a copy of the GNU Lesser General Public License along with this library; if not see http://www.gnu.org/licenses/.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `ResourceConstraint.Context` Assignment context

  - ### Field Summary

    - ### Fields inherited from class org.cpsolver.ifs.model.Constraint

      `iConstraintListeners, iId`

    - ### Fields inherited from interface org.cpsolver.ifs.assignment.context.CanHoldContext

      `sMaxSize`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ResourceConstraint(int width, int height)` Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `computeConflicts(Assignment<Rectangle,Location> assignment, Location placement, Set<Location> conflicts)` Compute conflicts with the given placement of the rectangle.
    `ResourceConstraint.Context` | `createAssignmentContext(Assignment<Rectangle,Location> assignment)` Create a new assignment context for the given assignment.
    `void` | `check(Assignment<Rectangle,Location> assignment)`
    `boolean` | `inConflict(Assignment<Rectangle,Location> assignment, Location placement)` Returns true if there is a rectangle which overlaps with the given assignment.
    `boolean` | `isConsistent(Location p1, Location p2)` Returns true if the given rectangles (assignments) do not overlap.
    `String` | `toString()` String representation of the constraint (for debugging and printing purposes).

    - ### Methods inherited from class org.cpsolver.ifs.assignment.context.ConstraintWithContext

      `assigned, getAssignmentContextReference, getContext, getContext, setAssignmentContextReference, setModel, unassigned`

    - ### Methods inherited from class org.cpsolver.ifs.model.Constraint

      `addConstraintListener, addVariable, assignedVariables, compareTo, computeConflictsNoForwardCheck, constraintListeners, countAssignedVariables, countVariables, equals, getDescription, getId, getModel, getName, hashCode, isHard, removeConstraintListener, removeVariable, variables`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### ResourceConstraint

          public ResourceConstraint(int width,
                                    int height)

      Constructor.
      Parameters:
        `width` - area width
        `height` - area height

  - ### Method Detail

    - #### computeConflicts

          public void computeConflicts(Assignment<Rectangle,Location> assignment,
                                       Location placement,
                                       Set<Location> conflicts)

      Compute conflicts with the given placement of the rectangle. This means the rectangles which are already placed and which are overlapping with the given assignment.
      Specified by:
        `computeConflicts` in class `Constraint<Rectangle,Location>`
      Parameters:
        `assignment` - current assignment
        `placement` - value to be assigned to its variable
        `conflicts` - resultant set of conflicting values

    - #### inConflict

          public boolean inConflict(Assignment<Rectangle,Location> assignment,
                                    Location placement)

      Returns true if there is a rectangle which overlaps with the given assignment.
      Overrides:
        `inConflict` in class `Constraint<Rectangle,Location>`
      Parameters:
        `assignment` - current assignment
        `placement` - given value
      Returns:
        true if there is a conflict with other assigned variables of the constraint

    - #### isConsistent

          public boolean isConsistent(Location p1,
                                      Location p2)

      Returns true if the given rectangles (assignments) do not overlap.
      Overrides:
        `isConsistent` in class `Constraint<Rectangle,Location>`
      Parameters:
        `p1` - a value
        `p2` - a value
      Returns:
        true if the constraint is ok with the assignment

    - #### check

          public void check(Assignment<Rectangle,Location> assignment)

    - #### toString

          public String toString()

      String representation of the constraint (for debugging and printing purposes).
      Overrides:
        `toString` in class `Object`

    - #### createAssignmentContext

          public ResourceConstraint.Context createAssignmentContext(Assignment<Rectangle,Location> assignment)

      Description copied from interface: `HasAssignmentContext`
      Create a new assignment context for the given assignment. If there are already some variables assigned in the value, the method should make sure that the context is appropriately initialized.
      Parameters:
        `assignment` - an assignment for which there needs to be an assignment context
      Returns:
        a new instance of the assignment context, filled according to the given assignment