public class GroupConstraint extends ConstraintWithContext<Lecture,Placement,GroupConstraint.GroupConstraintContext>
| 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. |
| Modifier and Type | Class and Description |
|---|---|
static interface |
GroupConstraint.AssignmentPairCheck
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.
|
static interface |
GroupConstraint.AssignmentParameterPairCheck<P>
Group constraints that can have parameters need to implement this interface instead of
GroupConstraint.AssignmentPairCheck or GroupConstraint.PairCheck. |
static class |
GroupConstraint.ConstraintType
Group constraint type.
|
static interface |
GroupConstraint.ConstraintTypeInterface
Constraint type interface
|
static class |
GroupConstraint.Flag
Group constraint building blocks (individual constraints that need more than
GroupConstraint.PairCheck) |
class |
GroupConstraint.GroupConstraintContext |
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.
|
static class |
GroupConstraint.ParametrizedConstraintType<P>
Constraint type with a parameter
|
iConstraintListeners, iIdsMaxSize| Constructor and Description |
|---|
GroupConstraint() |
GroupConstraint(Long id,
GroupConstraint.ConstraintTypeInterface type,
String preference)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
addVariable(Lecture lecture)
Add a variable to this constraint
|
boolean |
canShareRoom() |
void |
computeConflicts(Assignment<Lecture,Placement> assignment,
Placement value,
Set<Placement> conflicts)
The only method which has to be implemented by any constraint.
|
void |
computeConflicts(Assignment<Lecture,Placement> assignment,
Placement value,
Set<Placement> conflicts,
boolean fwdCheck) |
void |
computeConflictsNoForwardCheck(Assignment<Lecture,Placement> assignment,
Placement value,
Set<Placement> conflicts)
Compute conflicts method that does not do any forward checking.
|
GroupConstraint.GroupConstraintContext |
createAssignmentContext(Assignment<Lecture,Placement> assignment)
Create a new assignment context for the given assignment.
|
boolean |
equals(Object o)
Compare two constraints for equality (
Constraint.getId() is used) |
boolean |
forwardCheck(Assignment<Lecture,Placement> assignment,
Placement value,
Set<GroupConstraint> ignore,
int depth) |
void |
forwardCheck(Assignment<Lecture,Placement> assignment,
Placement value,
Set<Placement> conflicts,
Set<GroupConstraint> ignore,
int depth) |
Long |
getConstraintId()
Constraint id
|
static GroupConstraint.ConstraintTypeInterface |
getConstraintType(String reference)
Constraint type from reference
|
int |
getCurrentPreference(Assignment<Lecture,Placement> assignment)
Current constraint preference (0 if prohibited or required, depends on
current satisfaction of the constraint)
|
int |
getCurrentPreference(Assignment<Lecture,Placement> assignment,
Placement placement)
Current constraint preference change (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 required)
|
String |
getPrologPreference()
Prolog reference: "R" for required, "P" for prohibited", "-2",.."2" for
preference
|
GroupConstraint.ConstraintTypeInterface |
getType()
Return constraint type (e.g,
GroupConstraint.ConstraintType.SAME_TIME) |
boolean |
inConflict(Assignment<Lecture,Placement> assignment,
Placement value)
Returns true if the given assignment is inconsistent with the existing
assignments respecting this constraint.
|
boolean |
isChildrenNotOverlap(Assignment<Lecture,Placement> assignment,
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.
|
protected boolean |
isOnline(Placement p) |
boolean |
isProhibited()
Is constraint prohibited
|
boolean |
isRequired()
Is constraint required
|
boolean |
isSatisfied(Assignment<Lecture,Placement> assignment) |
boolean |
isSatisfiedPair(Assignment<Lecture,Placement> assignment,
Placement plc1,
Placement plc2) |
protected int |
nrSlotsADay(Assignment<Lecture,Placement> assignment,
int dayCode,
BitSet week,
HashMap<Lecture,Placement> assignments,
Set<Placement> conflicts) |
protected int |
nrSlotsADay(Assignment<Lecture,Placement> assignment,
int date,
HashMap<Lecture,Placement> assignments,
Set<Placement> conflicts) |
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)
Set constraint type
|
String |
toString() |
assigned, getAssignmentContextReference, getContext, getContext, setAssignmentContextReference, unassignedaddConstraintListener, assignedVariables, compareTo, constraintListeners, countAssignedVariables, countVariables, getDescription, getModel, hashCode, removeConstraintListener, variablespublic GroupConstraint()
public GroupConstraint(Long id, GroupConstraint.ConstraintTypeInterface type, String preference)
id - constraint idtype - constraString type (e.g, GroupConstraint.ConstraintType.SAME_TIME)preference - time preference ("R" for required, "P" for prohibited, "-2",
"-1", "1", "2" for soft preference)public static GroupConstraint.ConstraintTypeInterface getConstraintType(String reference)
reference - constraint referencepublic void setModel(Model<Lecture,Placement> model)
ConstraintsetModel in class ConstraintWithContext<Lecture,Placement,GroupConstraint.GroupConstraintContext>model - problem modelpublic void addVariable(Lecture lecture)
ConstraintaddVariable in class Constraint<Lecture,Placement>lecture - a variablepublic void removeVariable(Lecture lecture)
ConstraintremoveVariable in class Constraint<Lecture,Placement>lecture - a variablepublic Long getConstraintId()
public long getId()
ConstraintgetId in class Constraint<Lecture,Placement>protected long getGeneratedId()
public GroupConstraint.ConstraintTypeInterface getType()
GroupConstraint.ConstraintType.SAME_TIME)public void setType(GroupConstraint.ConstraintType type)
type - constraint typepublic boolean isRequired()
public boolean isProhibited()
public String getPrologPreference()
public boolean isConsistent(Placement value1, Placement value2)
ConstraintMacPropagation).isConsistent in class Constraint<Lecture,Placement>value1 - a valuevalue2 - a valuepublic void computeConflicts(Assignment<Lecture,Placement> assignment, Placement value, Set<Placement> conflicts)
ConstraintcomputeConflicts in class Constraint<Lecture,Placement>assignment - current assignmentvalue - value to be assigned to its variableconflicts - resultant set of conflicting valuespublic void computeConflictsNoForwardCheck(Assignment<Lecture,Placement> assignment, Placement value, Set<Placement> conflicts)
ConstraintConstraint.computeConflicts(Assignment, Value, Set)
and it is called during assignment (from Constraint.assigned(Assignment, long, Value)) to check for conflicting variables that need to be
unassigned first.computeConflictsNoForwardCheck in class Constraint<Lecture,Placement>assignment - current assignmentvalue - value to be assigned to its variableconflicts - resultant set of conflicting valuespublic void computeConflicts(Assignment<Lecture,Placement> assignment, Placement value, Set<Placement> conflicts, boolean fwdCheck)
public void forwardCheck(Assignment<Lecture,Placement> assignment, Placement value, Set<Placement> conflicts, Set<GroupConstraint> ignore, int depth)
public boolean inConflict(Assignment<Lecture,Placement> assignment, Placement value)
ConstraintMacPropagation).inConflict in class Constraint<Lecture,Placement>assignment - current assignmentvalue - given valuepublic boolean forwardCheck(Assignment<Lecture,Placement> assignment, Placement value, Set<GroupConstraint> ignore, int depth)
public int getPreference()
public int getCurrentPreference(Assignment<Lecture,Placement> assignment)
assignment - current assignmentpublic int getCurrentPreference(Assignment<Lecture,Placement> assignment, Placement placement)
assignment - current assignmentplacement - placement that is being consideredpublic boolean isHard()
ConstraintisHard in class Constraint<Lecture,Placement>public String getName()
ConstraintgetName in class Constraint<Lecture,Placement>public boolean isSatisfied(Assignment<Lecture,Placement> assignment)
public boolean isChildrenNotOverlap(Assignment<Lecture,Placement> assignment, Lecture lec1, Placement plc1, Lecture lec2, Placement plc2)
public boolean isSatisfiedPair(Assignment<Lecture,Placement> assignment, Placement plc1, Placement plc2)
public boolean canShareRoom()
protected int nrSlotsADay(Assignment<Lecture,Placement> assignment, int dayCode, BitSet week, HashMap<Lecture,Placement> assignments, Set<Placement> conflicts)
protected int nrSlotsADay(Assignment<Lecture,Placement> assignment, int date, HashMap<Lecture,Placement> assignments, Set<Placement> conflicts)
public boolean equals(Object o)
ConstraintConstraint.getId() is used)equals in class Constraint<Lecture,Placement>public GroupConstraint.GroupConstraintContext createAssignmentContext(Assignment<Lecture,Placement> assignment)
HasAssignmentContextassignment - an assignment for which there needs to be an assignment context