net.sf.cpsolver.coursett.constraint
Class GroupConstraint

java.lang.Object
  extended by net.sf.cpsolver.ifs.model.Constraint<Lecture,Placement>
      extended by net.sf.cpsolver.coursett.constraint.GroupConstraint
All Implemented Interfaces:
Comparable<Constraint<Lecture,Placement>>

public class GroupConstraint
extends Constraint<Lecture,Placement>

Group constraint.
This constraint expresses relations between several classes, e.g., that two sections of the same lecture can not be taught at the same time, or that some classes have to be taught one immediately after another. It can be either hard or soft.

Following constraints are now supported:

Constraint Comment
SAME_TIME Same time: given classes have to be taught in the same hours. If the classes are of different length, the smaller one cannot start before the longer one and it cannot end after the longer one.
SAME_DAYS Same days: given classes have to be taught in the same day. If the classes are of different time patterns, the days of one class have to form a subset of the days of the other class.
BTB Back-to-back constraint: given classes have to be taught in the same room and they have to follow one strictly after another.
BTB_TIME Back-to-back constraint: given classes have to follow one strictly after another, but they can be taught in different rooms.
DIFF_TIME Different time: given classes cannot overlap in time.
NHB(1), NHB(1.5), NHB(2), ... NHB(8) Number of hours between: between the given classes, the exact number of hours have to be kept.
SAME_START Same starting hour: given classes have to start in the same hour.
SAME_ROOM Same room: given classes have to be placed in the same room.
NHB_GTE(1) Greater than or equal to 1 hour between: between the given classes, the number of hours have to be one or more.
NHB_LT(6) Less than 6 hours between: between the given classes, the number of hours have to be less than six.

Version:
CourseTT 1.2 (University Course Timetabling)
Copyright (C) 2006 - 2010 Tomas Muller
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
static class GroupConstraint.ConstraintType
          Group constraint type.
static class GroupConstraint.Flag
          Group constraint building blocks (individual constraints that need more than GroupConstraint.PairCheck)
static interface GroupConstraint.PairCheck
          Group constraints that can be checked on pairs of classes (e.g., same room means any two classes are in the same room), only need to implement this interface.
 
Field Summary
 
Fields inherited from class net.sf.cpsolver.ifs.model.Constraint
iAssignedVariables, iConstraintListeners, iId
 
Constructor Summary
GroupConstraint()
           
GroupConstraint(Long id, GroupConstraint.ConstraintType type, String preference)
          Constructor
 
Method Summary
 void addVariable(Lecture lecture)
          Add a variable to this constraint
 void assigned(long iteration, Placement value)
          Given value is to be assigned to its varable.
 boolean canShareRoom()
           
 void computeConflicts(Placement value, Set<Placement> conflicts)
          The only method which has to be implemented by any constraint.
 boolean equals(Object o)
          Compare two constraints for equality (Constraint.getId() is used)
 void forwardCheck(Placement value, Set<Placement> conflicts, Set<GroupConstraint> ignore)
           
 Long getConstraintId()
          Constraint id
 int getCurrentPreference()
          Current constraint preference (0 if prohibited or reqired, depends on current satisfaction of the constraint)
 int getCurrentPreference(Placement placement)
          Current constraint preference (if given placement is assigned)
protected  long getGeneratedId()
          Generated unique id
 long getId()
          Unique id
 String getName()
          Constraint's name -- for printing purposes
 int getPreference()
          Constraint preference (0 if prohibited or reqired)
 String getPrologPreference()
          Prolog reference: "R" for required, "P" for prohibited", "-2",.."2" for preference
 GroupConstraint.ConstraintType getType()
          ConstraString type (e.g, GroupConstraint.ConstraintType.SAME_TIME)
 boolean inConflict(Placement value)
          Returns true if the given assignment is inconsistent with the existing assignments respecting this constraint.
 boolean isChildrenNotOverlap(Lecture lec1, Placement plc1, Lecture lec2, Placement plc2)
           
 boolean isConsistent(Placement value1, Placement value2)
          Returns true if the given assignments are consistent respecting this constraint.
 boolean isHard()
          Returns true if the constraint is hard.
 boolean isProhibited()
          Is constraint prohibited
 boolean isRequired()
          Is constraint required
 boolean isSatisfied()
           
 boolean isSatisfiedPair(Placement plc1, Placement plc2)
           
 void removeVariable(Lecture lecture)
          Remove a variable from this constraint
 void setModel(Model<Lecture,Placement> model)
          Sets the model which the constraint belongs to
 void setType(GroupConstraint.ConstraintType type)
           
 String toString()
           
 void unassigned(long iteration, Placement value)
          Given value is unassigned from its variable.
 
Methods inherited from class net.sf.cpsolver.ifs.model.Constraint
addConstraintListener, assignedVariables, compareTo, constraintListeners, countAssignedVariables, countVariables, getDescription, getModel, hashCode, removeConstraintListener, variables
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GroupConstraint

public GroupConstraint()

GroupConstraint

public GroupConstraint(Long id,
                       GroupConstraint.ConstraintType type,
                       String preference)
Constructor

Parameters:
id - constraint id
type - constraString type (e.g, GroupConstraint.ConstraintType.SAME_TIME)
preference - time preference ("R" for required, "P" for prohibited, "-2", "-1", "1", "2" for soft preference)
Method Detail

setModel

public void setModel(Model<Lecture,Placement> model)
Description copied from class: Constraint
Sets the model which the constraint belongs to

Overrides:
setModel in class Constraint<Lecture,Placement>

addVariable

public void addVariable(Lecture lecture)
Description copied from class: Constraint
Add a variable to this constraint

Overrides:
addVariable in class Constraint<Lecture,Placement>

removeVariable

public void removeVariable(Lecture lecture)
Description copied from class: Constraint
Remove a variable from this constraint

Overrides:
removeVariable in class Constraint<Lecture,Placement>

getConstraintId

public Long getConstraintId()
Constraint id


getId

public long getId()
Description copied from class: Constraint
Unique id

Overrides:
getId in class Constraint<Lecture,Placement>

getGeneratedId

protected long getGeneratedId()
Generated unique id


getType

public GroupConstraint.ConstraintType getType()
ConstraString type (e.g, GroupConstraint.ConstraintType.SAME_TIME)


setType

public void setType(GroupConstraint.ConstraintType type)

isRequired

public boolean isRequired()
Is constraint required


isProhibited

public boolean isProhibited()
Is constraint prohibited


getPrologPreference

public String getPrologPreference()
Prolog reference: "R" for required, "P" for prohibited", "-2",.."2" for preference


isConsistent

public boolean isConsistent(Placement value1,
                            Placement value2)
Description copied from class: Constraint
Returns true if the given assignments are consistent respecting this constraint. This method is used by MAC (see MacPropagation).

Overrides:
isConsistent in class Constraint<Lecture,Placement>

computeConflicts

public void computeConflicts(Placement value,
                             Set<Placement> conflicts)
Description copied from class: Constraint
The only method which has to be implemented by any constraint. It returns the values which needs to be unassigned in order to make this constraint consistent with the given value if it is assigned to its variable. The computed list of conflicting values is added to the given set of conflicts.

Specified by:
computeConflicts in class Constraint<Lecture,Placement>
Parameters:
value - value to be assigned to its varaible
conflicts - resultant set of conflicting values

forwardCheck

public void forwardCheck(Placement value,
                         Set<Placement> conflicts,
                         Set<GroupConstraint> ignore)

inConflict

public boolean inConflict(Placement value)
Description copied from class: Constraint
Returns true if the given assignment is inconsistent with the existing assignments respecting this constraint. This method is used by MAC (see MacPropagation).

Overrides:
inConflict in class Constraint<Lecture,Placement>

getPreference

public int getPreference()
Constraint preference (0 if prohibited or reqired)


getCurrentPreference

public int getCurrentPreference()
Current constraint preference (0 if prohibited or reqired, depends on current satisfaction of the constraint)


getCurrentPreference

public int getCurrentPreference(Placement placement)
Current constraint preference (if given placement is assigned)


unassigned

public void unassigned(long iteration,
                       Placement value)
Description copied from class: Constraint
Given value is unassigned from its variable.

Overrides:
unassigned in class Constraint<Lecture,Placement>

assigned

public void assigned(long iteration,
                     Placement value)
Description copied from class: Constraint
Given value is to be assigned to its varable. In this method, the constraint should unassigns all varaibles which are in conflict with the given assignment because of this constraint.

Overrides:
assigned in class Constraint<Lecture,Placement>

toString

public String toString()
Overrides:
toString in class Object

isHard

public boolean isHard()
Description copied from class: Constraint
Returns true if the constraint is hard. Only hard constraints are allowed to unassign a variable when there is a conflict with a value that is being assigned

Overrides:
isHard in class Constraint<Lecture,Placement>

getName

public String getName()
Description copied from class: Constraint
Constraint's name -- for printing purposes

Overrides:
getName in class Constraint<Lecture,Placement>

isSatisfied

public boolean isSatisfied()

isChildrenNotOverlap

public boolean isChildrenNotOverlap(Lecture lec1,
                                    Placement plc1,
                                    Lecture lec2,
                                    Placement plc2)

isSatisfiedPair

public boolean isSatisfiedPair(Placement plc1,
                               Placement plc2)

canShareRoom

public boolean canShareRoom()

equals

public boolean equals(Object o)
Description copied from class: Constraint
Compare two constraints for equality (Constraint.getId() is used)

Overrides:
equals in class Constraint<Lecture,Placement>


Copyright © 2014 UniTime LLC. All Rights Reserved.