net.sf.cpsolver.coursett.constraint
Class GroupConstraint

java.lang.Object
  extended by net.sf.cpsolver.ifs.model.Constraint
      extended by net.sf.cpsolver.coursett.constraint.GroupConstraint

public class GroupConstraint
extends Constraint

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:

ConstraintComment
SAME_TIMESame 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_DAYSSame 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.
BTBBack-to-back constraint: given classes have to be taught in the same room and they have to follow one strictly after another.
BTB_TIMEBack-to-back constraint: given classes have to follow one strictly after another, but they can be taught in different rooms.
DIFF_TIMEDifferent 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_STARTSame starting hour: given classes have to start in the same hour.
SAME_ROOMSame 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.1 (University Course Timetabling)
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
static String TYPE_BTB
          Back-to-back constraint: given classes have to be taught in the same room and they have to follow one strictly after another.
static String TYPE_BTB_DAY
           
static String TYPE_BTB_TIME
          Back-to-back constraint: given classes have to follow one strictly after another, but they can be taught in different rooms.
static String TYPE_CAN_SHARE_ROOM
           
static String TYPE_CH_NOTOVERLAP
           
static String TYPE_DIFF_TIME
          Different time: given classes cannot overlap in time.
static String TYPE_EVERY_OTHER_DAY
           
static String TYPE_FOLLOWING_DAY
           
static String TYPE_MEET_WITH
           
static String TYPE_NDB_GT_1
           
static String TYPE_NHB_1
          One hour between: between the given classes, the exact number of hours have to be kept.
static String TYPE_NHB_1_5
          One and half hour between: between the given classes, the exact number of hours have to be kept.
static String TYPE_NHB_2
          Two hours between: between the given classes, the exact number of hours have to be kept.
static String TYPE_NHB_3
          Three hours between: between the given classes, the exact number of hours have to be kept.
static String TYPE_NHB_4
          Four hours between: between the given classes, the exact number of hours have to be kept.
static String TYPE_NHB_4_5
          Four and half hours between: between the given classes, the exact number of hours have to be kept.
static String TYPE_NHB_5
          Five hours between: between the given classes, the exact number of hours have to be kept.
static String TYPE_NHB_6
          Six hours between: between the given classes, the exact number of hours have to be kept.
static String TYPE_NHB_7
          Seven hours between: between the given classes, the exact number of hours have to be kept.
static String TYPE_NHB_8
          Eight hours between: between the given classes, the exact number of hours have to be kept.
static String TYPE_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.
static String TYPE_NHB_LT_6
          Less than 6 hours between: between the given classes, the number of hours have to be less than six.
static String TYPE_PRECEDENCE
           
static String TYPE_SAME_DAYS
          Same days: given classes have to be taught in the same day.
static String TYPE_SAME_INSTR
           
static String TYPE_SAME_ROOM
          Same room: given classes have to placed in the same room.
static String TYPE_SAME_START
          Same room: given classes have to placed in the same room.
static String TYPE_SAME_STUDENTS
           
static String TYPE_SAME_TIME
          Same time: given classes have to be taught in the same hours.
 
Fields inherited from class net.sf.cpsolver.ifs.model.Constraint
iAssignedVariables, iConstraintListeners
 
Constructor Summary
GroupConstraint()
           
GroupConstraint(Long id, String type, String preference)
          Constructor
 
Method Summary
 void addVariable(Variable variable)
          Add a variable to this constraint
 void assigned(long iteration, Value value)
          Given value is to be assigned to its varable.
static boolean canShareRooms(String type)
           
 void computeConflicts(Value value, Set conflicts)
          The only method which has to be implemented by any constraint.
 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)
 long getId()
          Unique id
 String getName()
          Constraint's name -- for printing purposes
static String getName(String type)
           
 int getPreference()
          Constraint preference (0 if prohibited or reqired)
 String getPrologPreference()
          Prolog reference: "R" for required, "P" for prohibited", "-2",.."2" for preference
 String getType()
          ConstraString type (e.g, TYPE_SAME_TIME
 boolean inConflict(Value 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(Value value1, Value 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()
           
 void removeVariable(Variable variable)
          Remove a variable from this constraint
 void setType(String type)
           
 String toString()
           
 void unassigned(long iteration, Value value)
          Given value is unassigned from its varable.
 
Methods inherited from class net.sf.cpsolver.ifs.model.Constraint
addConstraintListener, assignedVariables, constraintListeners, countAssignedVariables, countVariables, equals, getDescription, getModel, hashCode, removeConstraintListener, setModel, variables
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE_SAME_TIME

public static String TYPE_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.


TYPE_SAME_DAYS

public static String TYPE_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.


TYPE_BTB

public static String TYPE_BTB
Back-to-back constraint: given classes have to be taught in the same room and they have to follow one strictly after another.


TYPE_BTB_TIME

public static String TYPE_BTB_TIME
Back-to-back constraint: given classes have to follow one strictly after another, but they can be taught in different rooms.


TYPE_DIFF_TIME

public static String TYPE_DIFF_TIME
Different time: given classes cannot overlap in time.


TYPE_NHB_1

public static String TYPE_NHB_1
One hour between: between the given classes, the exact number of hours have to be kept.


TYPE_NHB_2

public static String TYPE_NHB_2
Two hours between: between the given classes, the exact number of hours have to be kept.


TYPE_NHB_3

public static String TYPE_NHB_3
Three hours between: between the given classes, the exact number of hours have to be kept.


TYPE_NHB_4

public static String TYPE_NHB_4
Four hours between: between the given classes, the exact number of hours have to be kept.


TYPE_NHB_5

public static String TYPE_NHB_5
Five hours between: between the given classes, the exact number of hours have to be kept.


TYPE_NHB_6

public static String TYPE_NHB_6
Six hours between: between the given classes, the exact number of hours have to be kept.


TYPE_NHB_7

public static String TYPE_NHB_7
Seven hours between: between the given classes, the exact number of hours have to be kept.


TYPE_NHB_8

public static String TYPE_NHB_8
Eight hours between: between the given classes, the exact number of hours have to be kept.


TYPE_SAME_START

public static String TYPE_SAME_START
Same room: given classes have to placed in the same room.


TYPE_SAME_ROOM

public static String TYPE_SAME_ROOM
Same room: given classes have to placed in the same room.


TYPE_NHB_GTE_1

public static String TYPE_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.


TYPE_NHB_LT_6

public static String TYPE_NHB_LT_6
Less than 6 hours between: between the given classes, the number of hours have to be less than six.


TYPE_NHB_1_5

public static String TYPE_NHB_1_5
One and half hour between: between the given classes, the exact number of hours have to be kept.


TYPE_NHB_4_5

public static String TYPE_NHB_4_5
Four and half hours between: between the given classes, the exact number of hours have to be kept.


TYPE_SAME_STUDENTS

public static String TYPE_SAME_STUDENTS

TYPE_SAME_INSTR

public static String TYPE_SAME_INSTR

TYPE_CAN_SHARE_ROOM

public static String TYPE_CAN_SHARE_ROOM

TYPE_PRECEDENCE

public static String TYPE_PRECEDENCE

TYPE_BTB_DAY

public static String TYPE_BTB_DAY

TYPE_MEET_WITH

public static String TYPE_MEET_WITH

TYPE_NDB_GT_1

public static String TYPE_NDB_GT_1

TYPE_CH_NOTOVERLAP

public static String TYPE_CH_NOTOVERLAP

TYPE_FOLLOWING_DAY

public static String TYPE_FOLLOWING_DAY

TYPE_EVERY_OTHER_DAY

public static String TYPE_EVERY_OTHER_DAY
Constructor Detail

GroupConstraint

public GroupConstraint()

GroupConstraint

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

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

addVariable

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

Overrides:
addVariable in class Constraint

removeVariable

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

Overrides:
removeVariable in class Constraint

getConstraintId

public Long getConstraintId()
Constraint id


getId

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

Overrides:
getId in class Constraint

getType

public String getType()
ConstraString type (e.g, TYPE_SAME_TIME


setType

public void setType(String 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(Value value1,
                            Value 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

computeConflicts

public void computeConflicts(Value value,
                             Set 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
Parameters:
value - value to be assigned to its varaible
conflicts - resultant set of conflicting values

inConflict

public boolean inConflict(Value 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

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,
                       Value value)
Description copied from class: Constraint
Given value is unassigned from its varable.

Overrides:
unassigned in class Constraint

assigned

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

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

getName

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

Overrides:
getName in class Constraint

getName

public static String getName(String type)

canShareRooms

public static boolean canShareRooms(String type)

isSatisfied

public boolean isSatisfied()

isChildrenNotOverlap

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