net.sf.cpsolver.ifs.util
Class DistanceMetric

java.lang.Object
  extended by net.sf.cpsolver.ifs.util.DistanceMetric

public class DistanceMetric
extends Object

Common class for computing distances and back-to-back instructor / student conflicts. When property Distances.Ellipsoid is set, the distances are computed using the given (e.g., WGS84, see DistanceMetric.Ellipsoid). In the legacy mode (when ellipsoid is not set), distances are computed using Euclidian distance and 1 unit is considered 10 meters.

For student back-to-back conflicts, Distances.Speed (in meters per minute) is considered and compared with the break time of the earlier class.

For instructors, the preference is computed using the distance in meters and the three constants Instructor.NoPreferenceLimit (distance <= limit -> no preference), Instructor.DiscouragedLimit (distance <= limit -> discouraged), Instructor.ProhibitedLimit (distance <= limit -> strongly discouraged), the back-to-back placement is prohibited when the distance is over the last limit.

Version:
IFS 1.2 (Iterative Forward Search)
Copyright (C) 2006 - 2010 Tomas Muller
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/.

Nested Class Summary
static class DistanceMetric.Ellipsoid
           
 
Constructor Summary
DistanceMetric()
          Default properties
DistanceMetric(DataProperties properties)
          Configured using properties
DistanceMetric(DistanceMetric.Ellipsoid model)
          With provided ellipsoid
DistanceMetric(DistanceMetric.Ellipsoid model, double speed)
          With provided ellipsoid and student speed
 
Method Summary
 void addTravelTime(Long roomId1, Long roomId2, Integer travelTimeInMinutes)
          Add travel time between two locations
protected  double deg2rad(double deg)
          Degrees to radians
 boolean doComputeDistanceConflictsBetweenNonBTBClasses()
          True if distances should be considered between classes that are NOT back-to-back.
 double getDistanceInMeters(Double lat1, Double lon1, Double lat2, Double lon2)
          Deprecated. Use @{link getDistanceInMeters(Long, Double, Double, Long, Double, Double) instead (to include travel time matrix when available).
 double getDistanceInMeters(Long roomId1, Double lat1, Double lon1, Long roomId2, Double lat2, Double lon2)
          Return travel distance between two locations.
 int getDistanceInMinutes(double lat1, double lon1, double lat2, double lon2)
          Deprecated. Use @{link getDistanceInMinutes(Long, Double, Double, Long, Double, Double) instead (to include travel time matrix when available).
 Integer getDistanceInMinutes(Long roomId1, Double lat1, Double lon1, Long roomId2, Double lat2, Double lon2)
          Return travel time between two locations.
 double getInstructorDiscouragedLimit()
          Back-to-back classes in rooms within this limit have discouraged preference
 double getInstructorLongTravelInMinutes()
          When Distances.ComputeDistanceConflictsBetweenNonBTBClasses is enabled, distance limit (in minutes) for a long travel.
 double getInstructorNoPreferenceLimit()
          Back-to-back classes in rooms within this limit have neutral preference
 double getInstructorProhibitedLimit()
          Back-to-back classes in rooms within this limit have strongly discouraged preference, it is prohibited to exceed this limit.
 int getMaxTravelDistanceInMinutes()
          Maximal travel distance between rooms when no coordinates are given
 Integer getTravelTimeInMinutes(Long roomId1, Long roomId2)
          Return travel time between two locations.
 Map<Long,Map<Long,Integer>> getTravelTimes()
          Return travel times matrix
 boolean isLegacy()
          True if legacy mode is used (Euclidian distance where 1 unit is 10 meters)
static void main(String[] args)
          Few tests
 double minutes2meters(int min)
          Converts minutes to meters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DistanceMetric

public DistanceMetric()
Default properties


DistanceMetric

public DistanceMetric(DistanceMetric.Ellipsoid model)
With provided ellipsoid


DistanceMetric

public DistanceMetric(DistanceMetric.Ellipsoid model,
                      double speed)
With provided ellipsoid and student speed


DistanceMetric

public DistanceMetric(DataProperties properties)
Configured using properties

Method Detail

deg2rad

protected double deg2rad(double deg)
Degrees to radians


getDistanceInMeters

@Deprecated
public double getDistanceInMeters(Double lat1,
                                             Double lon1,
                                             Double lat2,
                                             Double lon2)
Deprecated. Use @{link getDistanceInMeters(Long, Double, Double, Long, Double, Double) instead (to include travel time matrix when available).

Compute distance between the two given coordinates


getDistanceInMinutes

@Deprecated
public int getDistanceInMinutes(double lat1,
                                           double lon1,
                                           double lat2,
                                           double lon2)
Deprecated. Use @{link getDistanceInMinutes(Long, Double, Double, Long, Double, Double) instead (to include travel time matrix when available).

Compute distance in minutes. Property Distances.Speed (in meters per minute) is used to convert meters to minutes, defaults to 1000 meters per 15 minutes (that means 66.67 meters per minute).


minutes2meters

public double minutes2meters(int min)
Converts minutes to meters. Property Distances.Speed (in meters per minute) is used, defaults to 1000 meters per 15 minutes.


getInstructorNoPreferenceLimit

public double getInstructorNoPreferenceLimit()
Back-to-back classes in rooms within this limit have neutral preference


getInstructorDiscouragedLimit

public double getInstructorDiscouragedLimit()
Back-to-back classes in rooms within this limit have discouraged preference


getInstructorProhibitedLimit

public double getInstructorProhibitedLimit()
Back-to-back classes in rooms within this limit have strongly discouraged preference, it is prohibited to exceed this limit.


getInstructorLongTravelInMinutes

public double getInstructorLongTravelInMinutes()
When Distances.ComputeDistanceConflictsBetweenNonBTBClasses is enabled, distance limit (in minutes) for a long travel.


isLegacy

public boolean isLegacy()
True if legacy mode is used (Euclidian distance where 1 unit is 10 meters)


getMaxTravelDistanceInMinutes

public int getMaxTravelDistanceInMinutes()
Maximal travel distance between rooms when no coordinates are given


addTravelTime

public void addTravelTime(Long roomId1,
                          Long roomId2,
                          Integer travelTimeInMinutes)
Add travel time between two locations


getTravelTimeInMinutes

public Integer getTravelTimeInMinutes(Long roomId1,
                                      Long roomId2)
Return travel time between two locations.


getDistanceInMinutes

public Integer getDistanceInMinutes(Long roomId1,
                                    Double lat1,
                                    Double lon1,
                                    Long roomId2,
                                    Double lat2,
                                    Double lon2)
Return travel time between two locations. Travel times are used when available, use coordinates otherwise.


getDistanceInMeters

public double getDistanceInMeters(Long roomId1,
                                  Double lat1,
                                  Double lon1,
                                  Long roomId2,
                                  Double lat2,
                                  Double lon2)
Return travel distance between two locations. Travel times are used when available, use coordinates otherwise.


getTravelTimes

public Map<Long,Map<Long,Integer>> getTravelTimes()
Return travel times matrix


doComputeDistanceConflictsBetweenNonBTBClasses

public boolean doComputeDistanceConflictsBetweenNonBTBClasses()
True if distances should be considered between classes that are NOT back-to-back. Distance in minutes is then to be compared with the difference between end of the last class and start of the second class plus break time of the first class.


main

public static void main(String[] args)
Few tests



Copyright © 2014 UniTime LLC. All Rights Reserved.