net.sf.cpsolver.ifs.example.rpp
Class ResourceConstraint

java.lang.Object
  extended by net.sf.cpsolver.ifs.model.Constraint<Rectangle,Location>
      extended by net.sf.cpsolver.ifs.example.rpp.ResourceConstraint
All Implemented Interfaces:
Comparable<Constraint<Rectangle,Location>>

public class ResourceConstraint
extends Constraint<Rectangle,Location>

Resource constraint (rectangular area where the rectangles are to be placed). It prohibits overlapping of the placed rectangles.

Version:
IFS 1.2 (Iterative Forward Search)
Copyright (C) 2006 - 2010 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/.

Field Summary
 
Fields inherited from class net.sf.cpsolver.ifs.model.Constraint
iAssignedVariables, iConstraintListeners, iId
 
Constructor Summary
ResourceConstraint(int width, int height)
          Constructor.
 
Method Summary
 void assigned(long iteration, Location placement)
          Notification, when a rectangle is placed.
 void check()
           
 void computeConflicts(Location placement, Set<Location> conflicts)
          Compute conflicts with the given placement of the rectangle.
 boolean inConflict(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).
 void unassigned(long iteration, Location placement)
          Notification, when a rectangle is unplaced.
 
Methods inherited from class net.sf.cpsolver.ifs.model.Constraint
addConstraintListener, addVariable, assignedVariables, compareTo, constraintListeners, countAssignedVariables, countVariables, equals, getDescription, getId, getModel, getName, hashCode, isHard, removeConstraintListener, removeVariable, setModel, 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(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:
placement - value to be assigned to its varaible
conflicts - resultant set of conflicting values

inConflict

public boolean inConflict(Location placement)
Returns true if there is a rectangle which overlaps with the given assignment.

Overrides:
inConflict in class Constraint<Rectangle,Location>

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>

assigned

public void assigned(long iteration,
                     Location placement)
Notification, when a rectangle is placed. It memorizes the rectangle's new position in 2D ([0..width][0..height]) array. It is used for faster lookup when computing conflicts.

Overrides:
assigned in class Constraint<Rectangle,Location>

unassigned

public void unassigned(long iteration,
                       Location placement)
Notification, when a rectangle is unplaced. It removes the rectangle from the 2D ([0..width][0..height]) array.

Overrides:
unassigned in class Constraint<Rectangle,Location>

check

public void check()

toString

public String toString()
String representation of the constraint (for debugging and printing purposes).

Overrides:
toString in class Object