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

java.lang.Object
  extended by net.sf.cpsolver.ifs.model.Constraint
      extended by net.sf.cpsolver.ifs.example.rpp.ResourceConstraint

public class ResourceConstraint
extends Constraint

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

Version:
IFS 1.1 (Iterative Forward Search)
Copyright (C) 2006 Tomáš Müller
muller@unitime.org
Lazenska 391, 76314 Zlin, Czech Republic

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 2.1 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

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, Value value)
          Notification, when a rectangle is placed.
 void check()
           
 void computeConflicts(Value value, Set conflicts)
          Compute conflicts with the given placement of the rectangle.
 boolean inConflict(Value value)
          Returns true if there is a rectangle which overlaps with the given assignment.
 boolean isConsistent(Value value1, Value value2)
          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, Value value)
          Notification, when a rectangle is unplaced.
 
Methods inherited from class net.sf.cpsolver.ifs.model.Constraint
addConstraintListener, addVariable, assignedVariables, 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(Value value,
                             Set 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
Parameters:
value - value to be assigned to its varaible
conflicts - resultant set of conflicting values

inConflict

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

Overrides:
inConflict in class Constraint

isConsistent

public boolean isConsistent(Value value1,
                            Value value2)
Returns true if the given rectangles (assignments) do not overlap.

Overrides:
isConsistent in class Constraint

assigned

public void assigned(long iteration,
                     Value value)
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

unassigned

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

Overrides:
unassigned in class Constraint

check

public void check()

toString

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

Overrides:
toString in class Object