net.sf.cpsolver.studentsct.extension
Class DistanceConflict

java.lang.Object
  extended by net.sf.cpsolver.ifs.extension.Extension
      extended by net.sf.cpsolver.studentsct.extension.DistanceConflict
All Implemented Interfaces:
ModelListener

public class DistanceConflict
extends Extension
implements ModelListener

This extension computes student distant conflicts. Two sections that are attended by the same student are considered in a distance conflict if they are back-to-back taught in locations that are two far away. The allowed distance is provided by method getAllowedDistance(TimeLocation).

Version:
StudentSct 1.1 (Student Sectioning)
Copyright (C) 2007 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
See Also:
TimeLocation,


Nested Class Summary
 class DistanceConflict.Conflict
          A representation of a distance conflict
 
Field Summary
static boolean sDebug
          Debug flag
 
Constructor Summary
DistanceConflict(Solver solver, DataProperties properties)
          Constructor.
 
Method Summary
 void afterAssigned(long iteration, Value value)
          Called after a value is assigned to a variable.
 void afterUnassigned(long iteration, Value value)
          Called after a value is unassigned from a variable.
 HashSet allConflicts(Enrollment enrollment)
          The set of all conflicts (DistanceConflict.Conflict objects) of the given enrollment and other enrollments that are assignmed to the same student.
 void assigned(long iteration, Value value)
          Called when a value is assigned to a variable.
 double avg(double w1, double w2)
          Quadratic average of two weights.
 void beforeAssigned(long iteration, Value value)
          Called before a value is assigned to a variable.
 HashSet computeAllConflicts()
          Compute a set of all distance conflicts (DistanceConflict.Conflict objects).
 HashSet conflicts(Enrollment e1)
          Return a set of distance conflicts (DistanceConflict.Conflict objects) of a (course) enrollment.
 HashSet conflicts(Enrollment e1, Enrollment e2)
          Return a set of distance conflicts (DistanceConflict.Conflict objects) between given (course) enrollments.
 double countTotalNrConflicts()
          Compute the actual number of all distance conflicts.
 double getAllowedDistance(TimeLocation time)
          Allowed distance for the course that follows the given time assignment.
 double getTotalNrConflicts()
          Actual number of all distance conflicts
 boolean inConflict(Section s1, Section s2)
          Return true if the given two sections are in distance conflict.
 boolean init(Solver solver)
          Initialize extension
 double nrAllConflicts(Enrollment enrollment)
          Total sum of all conflict of the given enrollment and other enrollments that are assignmed to the same student.
 double nrConflicts(Enrollment e1)
          Return number of distance conflict of a (course) enrollment.
 double nrConflicts(Enrollment e1, Enrollment e2)
          Return number of distance conflicts that are between two enrollments.
 String toString()
           
 void unassigned(long iteration, Value value)
          Called when a value is unassigned from a variable.
 
Methods inherited from class net.sf.cpsolver.ifs.extension.Extension
beforeUnassigned, constraintAdded, constraintRemoved, getModel, getProperties, getSolver, isRegistered, register, unregister, useValueExtra, useVariableExtra, variableAdded, variableRemoved
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.cpsolver.ifs.model.ModelListener
beforeUnassigned, constraintAdded, constraintRemoved, variableAdded, variableRemoved
 

Field Detail

sDebug

public static boolean sDebug
Debug flag

Constructor Detail

DistanceConflict

public DistanceConflict(Solver solver,
                        DataProperties properties)
Constructor. Beside of other thigs, this constructor also uses StudentSectioningModel.setDistanceConflict(DistanceConflict) to set the this instance to the model.

Parameters:
solver - constraint solver
properties - configuration
Method Detail

init

public boolean init(Solver solver)
Initialize extension

Specified by:
init in interface ModelListener
Overrides:
init in class Extension
Parameters:
solver - IFS solver

toString

public String toString()
Overrides:
toString in class Object

inConflict

public boolean inConflict(Section s1,
                          Section s2)
Return true if the given two sections are in distance conflict. This means that the sections are back-to-back and that they are placed in locations that are two far.

Parameters:
s1 - a section
s2 - a section
Returns:
true, if the given sections are in a distance conflict

nrConflicts

public double nrConflicts(Enrollment e1)
Return number of distance conflict of a (course) enrollment. It is the number of pairs of assignments of the enrollment that are in a distance conflict, weighted by the request's weight (see Request.getWeight()).

Parameters:
e1 - an enrollment
Returns:
number of distance conflicts

nrConflicts

public double nrConflicts(Enrollment e1,
                          Enrollment e2)
Return number of distance conflicts that are between two enrollments. It is the number of pairs of assignments of these enrollments that are in a distance conflict, weighted by the average (see avg(double, double)) of the requests' weight (see Request.getWeight()).

Parameters:
e1 - an enrollment
e2 - an enrollment
Returns:
number of distance conflict between given enrollments

conflicts

public HashSet conflicts(Enrollment e1)
Return a set of distance conflicts (DistanceConflict.Conflict objects) of a (course) enrollment.

Parameters:
e1 - an enrollment
Returns:
list of distance conflicts that are between assignment of the given enrollment

conflicts

public HashSet conflicts(Enrollment e1,
                         Enrollment e2)
Return a set of distance conflicts (DistanceConflict.Conflict objects) between given (course) enrollments.

Parameters:
e1 - an enrollment
e2 - an enrollment
Returns:
list of distance conflicts that are between assignment of the given enrollments

getAllowedDistance

public double getAllowedDistance(TimeLocation time)
Allowed distance for the course that follows the given time assignment.

Parameters:
time - a time assignment of the first of two sections that are back-to-back
Returns:
the maximal allowed distance

nrAllConflicts

public double nrAllConflicts(Enrollment enrollment)
Total sum of all conflict of the given enrollment and other enrollments that are assignmed to the same student.


allConflicts

public HashSet allConflicts(Enrollment enrollment)
The set of all conflicts (DistanceConflict.Conflict objects) of the given enrollment and other enrollments that are assignmed to the same student.


assigned

public void assigned(long iteration,
                     Value value)
Called when a value is assigned to a variable. Internal number of distance conflicts is updated, see getTotalNrConflicts().


unassigned

public void unassigned(long iteration,
                       Value value)
Called when a value is unassigned from a variable. Internal number of distance conflicts is updated, see getTotalNrConflicts().


getTotalNrConflicts

public double getTotalNrConflicts()
Actual number of all distance conflicts


countTotalNrConflicts

public double countTotalNrConflicts()
Compute the actual number of all distance conflicts. Should be equal to getTotalNrConflicts().


computeAllConflicts

public HashSet computeAllConflicts()
Compute a set of all distance conflicts (DistanceConflict.Conflict objects).


avg

public double avg(double w1,
                  double w2)
Quadratic average of two weights.


beforeAssigned

public void beforeAssigned(long iteration,
                           Value value)
Called before a value is assigned to a variable.

Specified by:
beforeAssigned in interface ModelListener
Overrides:
beforeAssigned in class Extension
Parameters:
iteration - current iteration
value - value to be assigned

afterAssigned

public void afterAssigned(long iteration,
                          Value value)
Called after a value is assigned to a variable.

Specified by:
afterAssigned in interface ModelListener
Overrides:
afterAssigned in class Extension
Parameters:
iteration - current iteration
value - value to be assigned

afterUnassigned

public void afterUnassigned(long iteration,
                            Value value)
Called after a value is unassigned from a variable.

Specified by:
afterUnassigned in interface ModelListener
Overrides:
afterUnassigned in class Extension
Parameters:
iteration - current iteration
value - value to be unassigned