net.sf.cpsolver.studentsct.extension
Class DistanceConflict

java.lang.Object
  extended by net.sf.cpsolver.ifs.extension.Extension<Request,Enrollment>
      extended by net.sf.cpsolver.studentsct.extension.DistanceConflict
All Implemented Interfaces:
ModelListener<Request,Enrollment>

public class DistanceConflict
extends Extension<Request,Enrollment>
implements ModelListener<Request,Enrollment>

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. This means that the (walking) distance in minutes between the two classes are longer than the break time of the earlier class. See DistanceMetric for more details.

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


Nested Class Summary
static class DistanceConflict.Conflict
          A representation of a distance conflict
 
Field Summary
static boolean sDebug
          Debug flag
 
Constructor Summary
DistanceConflict(DistanceMetric metrics, DataProperties properties)
          Alternative constructor (for online student sectioning)
DistanceConflict(Solver<Request,Enrollment> solver, DataProperties properties)
          Constructor.
 
Method Summary
 void afterAssigned(long iteration, Enrollment value)
          Called after a value is assigned to a variable.
 void afterUnassigned(long iteration, Enrollment value)
          Called after a value is unassigned from a variable.
 Set<DistanceConflict.Conflict> 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, Enrollment value)
          Called when a value is assigned to a variable.
 void beforeAssigned(long iteration, Enrollment value)
          Called before a value is assigned to a variable.
 void checkAllConflicts()
          Checks the counter counting all conflicts
 Set<DistanceConflict.Conflict> computeAllConflicts()
          Compute a set of all distance conflicts (DistanceConflict.Conflict objects).
 Set<DistanceConflict.Conflict> conflicts(Enrollment e1)
          Return a set of distance conflicts (DistanceConflict.Conflict objects) of a (course) enrollment.
 Set<DistanceConflict.Conflict> conflicts(Enrollment e1, Enrollment e2)
          Return a set of distance conflicts (DistanceConflict.Conflict objects) between given (course) enrollments.
 int countTotalNrConflicts()
          Compute the actual number of all distance conflicts.
 Set<DistanceConflict.Conflict> getAllConflicts()
          Return a set of all distance conflicts (DistanceConflict.Conflict objects).
protected  int getDistanceInMinutes(Placement p1, Placement p2)
           
protected  int getDistanceInMinutes(RoomLocation r1, RoomLocation r2)
           
 DistanceMetric getDistanceMetric()
           
 int 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<Request,Enrollment> solver)
          Initialize extension
 int nrAllConflicts(Enrollment enrollment)
          Total sum of all conflict of the given enrollment and other enrollments that are assignmed to the same student.
 int nrConflicts(Enrollment e1)
          Return number of distance conflict of a (course) enrollment.
 int nrConflicts(Enrollment e1, Enrollment e2)
          Return number of distance conflicts that are between two enrollments.
 String toString()
           
 void unassigned(long iteration, Enrollment 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<Request,Enrollment> 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

DistanceConflict

public DistanceConflict(DistanceMetric metrics,
                        DataProperties properties)
Alternative constructor (for online student sectioning)

Parameters:
metrics - distance metrics
properties - configuration
Method Detail

init

public boolean init(Solver<Request,Enrollment> solver)
Initialize extension

Specified by:
init in interface ModelListener<Request,Enrollment>
Overrides:
init in class Extension<Request,Enrollment>
Parameters:
solver - IFS solver

toString

public String toString()
Overrides:
toString in class Object

getDistanceMetric

public DistanceMetric getDistanceMetric()

getDistanceInMinutes

protected int getDistanceInMinutes(RoomLocation r1,
                                   RoomLocation r2)

getDistanceInMinutes

protected int getDistanceInMinutes(Placement p1,
                                   Placement p2)

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 int 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.

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

nrConflicts

public int 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.

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

conflicts

public Set<DistanceConflict.Conflict> 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 Set<DistanceConflict.Conflict> 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

nrAllConflicts

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


allConflicts

public Set<DistanceConflict.Conflict> 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,
                     Enrollment 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,
                       Enrollment value)
Called when a value is unassigned from a variable. Internal number of distance conflicts is updated, see getTotalNrConflicts().


checkAllConflicts

public void checkAllConflicts()
Checks the counter counting all conflicts


getTotalNrConflicts

public int getTotalNrConflicts()
Actual number of all distance conflicts


countTotalNrConflicts

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


computeAllConflicts

public Set<DistanceConflict.Conflict> computeAllConflicts()
Compute a set of all distance conflicts (DistanceConflict.Conflict objects).


getAllConflicts

public Set<DistanceConflict.Conflict> getAllConflicts()
Return a set of all distance conflicts (DistanceConflict.Conflict objects).


beforeAssigned

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

Specified by:
beforeAssigned in interface ModelListener<Request,Enrollment>
Overrides:
beforeAssigned in class Extension<Request,Enrollment>
Parameters:
iteration - current iteration
value - value to be assigned

afterAssigned

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

Specified by:
afterAssigned in interface ModelListener<Request,Enrollment>
Overrides:
afterAssigned in class Extension<Request,Enrollment>
Parameters:
iteration - current iteration
value - value to be assigned

afterUnassigned

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

Specified by:
afterUnassigned in interface ModelListener<Request,Enrollment>
Overrides:
afterUnassigned in class Extension<Request,Enrollment>
Parameters:
iteration - current iteration
value - value to be unassigned