net.sf.cpsolver.exam.model
Class ExamDistributionConstraint

java.lang.Object
  extended by net.sf.cpsolver.ifs.model.Constraint
      extended by net.sf.cpsolver.exam.model.ExamDistributionConstraint

public class ExamDistributionConstraint
extends Constraint

Distribution binary constraint.

The following binary distribution constraints are implemented



Version:
ExamTT 1.1 (Examination Timetabling)
Copyright (C) 2008 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 int sDistDifferentPeriod
          Different period constraint type
static int sDistDifferentRoom
          Different room constraint type
static int sDistPrecedence
          Precedence constraint type
static int sDistPrecedenceRev
          Precedence constraint type (reverse order)
static int sDistSamePeriod
          Same period constraint type
static int sDistSameRoom
          Same room constraint type
static String[] sDistType
          Distribution type name
 
Fields inherited from class net.sf.cpsolver.ifs.model.Constraint
iAssignedVariables, iConstraintListeners, iId
 
Constructor Summary
ExamDistributionConstraint(long id, int type, boolean hard, int weight)
          Constructor
ExamDistributionConstraint(long id, String type, boolean hard, int weight)
          Constructor
ExamDistributionConstraint(long id, String type, String pref)
          Constructor
 
Method Summary
 void assigned(long iteration, Value value)
          Given value is to be assigned to its varable.
 boolean check(ExamPlacement first, ExamPlacement second)
          Check assignments of the given exams
 void computeConflicts(Value value, Set conflicts)
          Compute conflicts -- there is a conflict if the other variable is assigned and check(ExamPlacement, ExamPlacement) is false
 boolean equals(Object o)
          Compare with other constraint for equality
 int getType()
          Constraint type
 String getTypeString()
          Constraint type name
 int getWeight()
          If not hard, penalty for violation
 boolean inConflict(Value value)
          Check for conflict -- there is a conflict if the other variable is assigned and check(ExamPlacement, ExamPlacement) is false
 boolean isConsistent(Value value1, Value value2)
          Consistency check -- check(ExamPlacement, ExamPlacement) is called
 boolean isHard()
          True if hard (must be satisfied), false for soft (should be satisfied)
 boolean isPeriodRelated()
          True if the constraint is related to periods
 boolean isRoomRelated()
          True if the constraint is related to rooms
 boolean isSatisfied()
          Return true if this is hard constraint or this is a soft constraint without any violation
 boolean isSatisfied(ExamPlacement p)
          Return true if this is hard constraint or this is a soft constraint without any violation
 String toString()
          String representation -- constraint type name (exam 1, exam 2)
 void unassigned(long iteration, Value value)
          Given value is unassigned from its varable.
 
Methods inherited from class net.sf.cpsolver.ifs.model.Constraint
addConstraintListener, addVariable, assignedVariables, constraintListeners, countAssignedVariables, countVariables, getDescription, getId, getModel, getName, hashCode, removeConstraintListener, removeVariable, setModel, variables
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

sDistSameRoom

public static final int sDistSameRoom
Same room constraint type

See Also:
Constant Field Values

sDistDifferentRoom

public static final int sDistDifferentRoom
Different room constraint type

See Also:
Constant Field Values

sDistSamePeriod

public static final int sDistSamePeriod
Same period constraint type

See Also:
Constant Field Values

sDistDifferentPeriod

public static final int sDistDifferentPeriod
Different period constraint type

See Also:
Constant Field Values

sDistPrecedence

public static final int sDistPrecedence
Precedence constraint type

See Also:
Constant Field Values

sDistPrecedenceRev

public static final int sDistPrecedenceRev
Precedence constraint type (reverse order)

See Also:
Constant Field Values

sDistType

public static final String[] sDistType
Distribution type name

Constructor Detail

ExamDistributionConstraint

public ExamDistributionConstraint(long id,
                                  int type,
                                  boolean hard,
                                  int weight)
Constructor

Parameters:
id - constraint unique id
type - constraint type
hard - true if the constraint is hard (cannot be violated)
weight - if not hard, penalty for violation

ExamDistributionConstraint

public ExamDistributionConstraint(long id,
                                  String type,
                                  String pref)
Constructor

Parameters:
id - constraint unique id
type - constraint type (EX_SAME_PREF, EX_SAME_ROOM, or EX_PRECEDENCE)
pref - preference (R/P for required/prohibited, or -2, -1, 0, 1, 2 for preference (from preferred to discouraged))

ExamDistributionConstraint

public ExamDistributionConstraint(long id,
                                  String type,
                                  boolean hard,
                                  int weight)
Constructor

Parameters:
id - constraint unique id
type - constraint type name
Method Detail

isHard

public boolean isHard()
True if hard (must be satisfied), false for soft (should be satisfied)

Overrides:
isHard in class Constraint

getWeight

public int getWeight()
If not hard, penalty for violation


getType

public int getType()
Constraint type


getTypeString

public String getTypeString()
Constraint type name


toString

public String toString()
String representation -- constraint type name (exam 1, exam 2)

Overrides:
toString in class Object

computeConflicts

public void computeConflicts(Value value,
                             Set conflicts)
Compute conflicts -- there is a conflict if the other variable is assigned and check(ExamPlacement, ExamPlacement) is false

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)
Check for conflict -- there is a conflict if the other variable is assigned and check(ExamPlacement, ExamPlacement) is false

Overrides:
inConflict in class Constraint

isConsistent

public boolean isConsistent(Value value1,
                            Value value2)
Consistency check -- check(ExamPlacement, ExamPlacement) is called

Overrides:
isConsistent in class Constraint

check

public boolean check(ExamPlacement first,
                     ExamPlacement second)
Check assignments of the given exams

Parameters:
first - assignment of the first exam
second - assignment of the second exam
Returns:
true, if the constraint is satisfied

equals

public boolean equals(Object o)
Compare with other constraint for equality

Overrides:
equals in class Constraint

isSatisfied

public boolean isSatisfied()
Return true if this is hard constraint or this is a soft constraint without any violation


isSatisfied

public boolean isSatisfied(ExamPlacement p)
Return true if this is hard constraint or this is a soft constraint without any violation

Parameters:
p - exam assignment to be made

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

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

isRoomRelated

public boolean isRoomRelated()
True if the constraint is related to rooms


isPeriodRelated

public boolean isPeriodRelated()
True if the constraint is related to periods