net.sf.cpsolver.exam.model
Class ExamDistributionConstraint

java.lang.Object
  extended by net.sf.cpsolver.ifs.model.Constraint<Exam,ExamPlacement>
      extended by net.sf.cpsolver.exam.model.ExamDistributionConstraint
All Implemented Interfaces:
Comparable<Constraint<Exam,ExamPlacement>>

public class ExamDistributionConstraint
extends Constraint<Exam,ExamPlacement>

Distribution binary constraint.

The following binary distribution constraints are implemented



Version:
ExamTT 1.2 (Examination Timetabling)
Copyright (C) 2008 - 2010 Tomáš Müller
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/.

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, ExamPlacement value)
          Given value is to be assigned to its varable.
 boolean check(ExamPlacement first, ExamPlacement second)
          Check assignments of the given exams
 void computeConflicts(ExamPlacement givenPlacement, Set<ExamPlacement> 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(ExamPlacement givenPlacement)
          Check for conflict -- there is a conflict if the other variable is assigned and check(ExamPlacement, ExamPlacement) is false
 boolean isConsistent(ExamPlacement first, ExamPlacement second)
          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, ExamPlacement value)
          Given value is unassigned from its variable.
 
Methods inherited from class net.sf.cpsolver.ifs.model.Constraint
addConstraintListener, addVariable, assignedVariables, compareTo, 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<Exam,ExamPlacement>

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(ExamPlacement givenPlacement,
                             Set<ExamPlacement> 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<Exam,ExamPlacement>
Parameters:
givenPlacement - value to be assigned to its varaible
conflicts - resultant set of conflicting values

inConflict

public boolean inConflict(ExamPlacement givenPlacement)
Check for conflict -- there is a conflict if the other variable is assigned and check(ExamPlacement, ExamPlacement) is false

Overrides:
inConflict in class Constraint<Exam,ExamPlacement>

isConsistent

public boolean isConsistent(ExamPlacement first,
                            ExamPlacement second)
Consistency check -- check(ExamPlacement, ExamPlacement) is called

Overrides:
isConsistent in class Constraint<Exam,ExamPlacement>

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<Exam,ExamPlacement>

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,
                     ExamPlacement 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<Exam,ExamPlacement>

unassigned

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

Overrides:
unassigned in class Constraint<Exam,ExamPlacement>

isRoomRelated

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


isPeriodRelated

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