001package org.cpsolver.ifs.util; 002 003import java.util.HashMap; 004import java.util.Map; 005import java.util.concurrent.locks.ReentrantReadWriteLock; 006 007import org.cpsolver.studentsct.constraint.HardDistanceConflicts; 008 009/** 010 * Common class for computing distances and back-to-back instructor / student conflicts. 011 * 012 * When property Distances.Ellipsoid is set, the distances are computed using the given (e.g., WGS84, see {@link Ellipsoid}). 013 * In the legacy mode (when ellipsoid is not set), distances are computed using Euclidian distance and 1 unit is considered 10 meters. 014 * <br><br> 015 * For student back-to-back conflicts, Distances.Speed (in meters per minute) is considered and compared with the break time 016 * of the earlier class. 017 * <br><br> 018 * For instructors, the preference is computed using the distance in meters and the three constants 019 * Instructor.NoPreferenceLimit (distance <= limit → no preference), Instructor.DiscouragedLimit (distance <= limit → discouraged), 020 * Instructor.ProhibitedLimit (distance <= limit → strongly discouraged), the back-to-back placement is prohibited when the distance is over the last limit. 021 * 022 * @author Tomáš Müller 023 * @version IFS 1.3 (Iterative Forward Search)<br> 024 * Copyright (C) 2006 - 2014 Tomáš Müller<br> 025 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 026 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br> 027 * <br> 028 * This library is free software; you can redistribute it and/or modify 029 * it under the terms of the GNU Lesser General Public License as 030 * published by the Free Software Foundation; either version 3 of the 031 * License, or (at your option) any later version. <br> 032 * <br> 033 * This library is distributed in the hope that it will be useful, but 034 * WITHOUT ANY WARRANTY; without even the implied warranty of 035 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 036 * Lesser General Public License for more details. <br> 037 * <br> 038 * You should have received a copy of the GNU Lesser General Public 039 * License along with this library; if not see 040 * <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>. 041 */ 042public class DistanceMetric { 043 public static enum Ellipsoid { 044 LEGACY ("Euclidean metric (1 unit equals to 10 meters)", "X-Coordinate", "Y-Coordinate", 0, 0, 0), 045 WGS84 ("WGS-84 (GPS)", 6378137, 6356752.3142, 1.0 / 298.257223563), 046 GRS80 ("GRS-80", 6378137, 6356752.3141, 1.0 / 298.257222101), 047 Airy1830 ("Airy (1830)", 6377563.396, 6356256.909, 1.0 / 299.3249646), 048 Intl1924 ("Int'l 1924", 6378388, 6356911.946, 1.0 / 297), 049 Clarke1880 ("Clarke (1880)", 6378249.145, 6356514.86955, 1.0 / 293.465), 050 GRS67 ("GRS-67", 6378160, 6356774.719, 1.0 / 298.25); 051 052 private double iA, iB, iF; 053 private String iName, iFirstCoord, iSecondCoord; 054 055 Ellipsoid(String name, double a, double b) { 056 this(name, "Latitude", "Longitude", a, b, (a - b) / a); 057 } 058 Ellipsoid(String name, double a, double b, double f) { 059 this(name, "Latitude", "Longitude", a, b, f); 060 } 061 Ellipsoid(String name, String xCoord, String yCoord, double a, double b, double f) { 062 iName = name; 063 iFirstCoord = xCoord; iSecondCoord = yCoord; 064 iA = a; iB = b; iF = f; 065 } 066 067 /** Major semiaxe A 068 * @return major semiaxe A 069 **/ 070 public double a() { return iA; } 071 /** Minor semiaxe B 072 * @return major semiaxe B 073 **/ 074 public double b() { return iB; } 075 /** Flattening (A-B) / A 076 * @return Flattening (A-B) / A 077 **/ 078 public double f() { return iF; } 079 080 /** Name of this coordinate system 081 * @return elipsoid name 082 **/ 083 public String getEclipsoindName() { return iName; } 084 /** Name of the fist coordinate (e.g., Latitude) 085 * @return first coordinate's name 086 **/ 087 public String getFirstCoordinateName() { return iFirstCoord; } 088 /** Name of the second coordinate (e.g., Longitude) 089 * @return second coordinate's name 090 **/ 091 public String getSecondCoordinateName() { return iSecondCoord; } 092 } 093 094 /** Elliposid parameters, default to WGS-84 */ 095 private Ellipsoid iModel = Ellipsoid.WGS84; 096 /** Student speed in meters per minute (defaults to 1000 meters in 15 minutes) */ 097 private double iSpeed = 1000.0 / 15; 098 /** Back-to-back classes: maximal distance for no preference */ 099 private double iInstructorNoPreferenceLimit = 0.0; 100 /** Back-to-back classes: maximal distance for discouraged preference */ 101 private double iInstructorDiscouragedLimit = 50.0; 102 /** 103 * Back-to-back classes: maximal distance for strongly discouraged preference 104 * (everything above is prohibited) 105 */ 106 private double iInstructorProhibitedLimit = 200.0; 107 /** 108 * When Distances.ComputeDistanceConflictsBetweenNonBTBClasses is enabled, distance limit (in minutes) 109 * for a long travel. 110 */ 111 private double iInstructorLongTravelInMinutes = 30.0; 112 113 /** Default distance when given coordinates are null. */ 114 private double iNullDistance = 10000.0; 115 /** Maximal travel time in minutes when no coordinates are given. */ 116 private int iMaxTravelTime = 60; 117 /** Travel times overriding the distances computed from coordintaes */ 118 private Map<Long, Map<Long, Integer>> iTravelTimes = new HashMap<Long, Map<Long,Integer>>(); 119 /** Distance cache */ 120 private Map<String, Double> iDistanceCache = new HashMap<String, Double>(); 121 /** True if distances should be considered between classes that are NOT back-to-back */ 122 private boolean iComputeDistanceConflictsBetweenNonBTBClasses = false; 123 /** Reference of the accommodation of students that need short distances */ 124 private String iShortDistanceAccommodationReference = "SD"; 125 /** Allowed distance in minutes (for {@link HardDistanceConflicts}) */ 126 private int iAllowedDistanceInMinutes = 30; 127 /** Hard distance limit in minutes (for {@link HardDistanceConflicts}) */ 128 private int iDistanceHardLimitInMinutes = 60; 129 /** Long distance limit in minutes (for display) */ 130 private int iDistanceLongLimitInMinutes = 60; 131 /** Hard distance conflicts enabled (for {@link HardDistanceConflicts}) */ 132 private boolean iHardDistanceConflicts = false; 133 134 private final ReentrantReadWriteLock iLock = new ReentrantReadWriteLock(); 135 136 /** Default properties */ 137 public DistanceMetric() { 138 } 139 140 public DistanceMetric(DistanceMetric m) { 141 iModel = m.iModel; 142 iSpeed = m.iSpeed; 143 iInstructorNoPreferenceLimit = m.iInstructorNoPreferenceLimit; 144 iInstructorDiscouragedLimit = m.iInstructorDiscouragedLimit; 145 iInstructorProhibitedLimit = m.iInstructorProhibitedLimit; 146 iInstructorLongTravelInMinutes = m.iInstructorLongTravelInMinutes; 147 iNullDistance = m.iNullDistance; 148 iMaxTravelTime = m.iMaxTravelTime; 149 iComputeDistanceConflictsBetweenNonBTBClasses = m.iComputeDistanceConflictsBetweenNonBTBClasses; 150 iShortDistanceAccommodationReference = m.iShortDistanceAccommodationReference; 151 m.iLock.readLock().lock(); 152 try { 153 for (Map.Entry<Long, Map<Long, Integer>> e: m.iTravelTimes.entrySet()) 154 iTravelTimes.put(e.getKey(), new HashMap<Long, Integer>(e.getValue())); 155 } finally { 156 m.iLock.readLock().unlock(); 157 } 158 } 159 160 /** With provided ellipsoid 161 * @param model ellipsoid model 162 **/ 163 public DistanceMetric(Ellipsoid model) { 164 iModel = model; 165 if (iModel == Ellipsoid.LEGACY) { 166 iSpeed = 100.0 / 15; 167 iInstructorDiscouragedLimit = 5.0; 168 iInstructorProhibitedLimit = 20.0; 169 } 170 } 171 172 /** With provided ellipsoid and student speed 173 * @param model ellipsoid model 174 * @param speed student speed in meters per minute 175 **/ 176 public DistanceMetric(Ellipsoid model, double speed) { 177 iModel = model; 178 iSpeed = speed; 179 } 180 181 /** Configured using properties 182 * @param properties solver configuration 183 **/ 184 public DistanceMetric(DataProperties properties) { 185 if (Ellipsoid.LEGACY.name().equals(properties.getProperty("Distances.Ellipsoid",Ellipsoid.LEGACY.name()))) { 186 //LEGACY MODE 187 iModel = Ellipsoid.LEGACY; 188 iSpeed = properties.getPropertyDouble("Student.DistanceLimit", 1000.0 / 15) / 10.0; 189 iInstructorNoPreferenceLimit = properties.getPropertyDouble("Instructor.NoPreferenceLimit", 0.0); 190 iInstructorDiscouragedLimit = properties.getPropertyDouble("Instructor.DiscouragedLimit", 5.0); 191 iInstructorProhibitedLimit = properties.getPropertyDouble("Instructor.ProhibitedLimit", 20.0); 192 iNullDistance = properties.getPropertyDouble("Distances.NullDistance", 1000.0); 193 iMaxTravelTime = properties.getPropertyInt("Distances.MaxTravelDistanceInMinutes", 60); 194 } else { 195 iModel = Ellipsoid.valueOf(properties.getProperty("Distances.Ellipsoid", Ellipsoid.WGS84.name())); 196 if (iModel == null) iModel = Ellipsoid.WGS84; 197 iSpeed = properties.getPropertyDouble("Distances.Speed", properties.getPropertyDouble("Student.DistanceLimit", 1000.0 / 15)); 198 iInstructorNoPreferenceLimit = properties.getPropertyDouble("Instructor.NoPreferenceLimit", iInstructorNoPreferenceLimit); 199 iInstructorDiscouragedLimit = properties.getPropertyDouble("Instructor.DiscouragedLimit", iInstructorDiscouragedLimit); 200 iInstructorProhibitedLimit = properties.getPropertyDouble("Instructor.ProhibitedLimit", iInstructorProhibitedLimit); 201 iNullDistance = properties.getPropertyDouble("Distances.NullDistance", iNullDistance); 202 iMaxTravelTime = properties.getPropertyInt("Distances.MaxTravelDistanceInMinutes", 60); 203 } 204 iComputeDistanceConflictsBetweenNonBTBClasses = properties.getPropertyBoolean( 205 "Distances.ComputeDistanceConflictsBetweenNonBTBClasses", iComputeDistanceConflictsBetweenNonBTBClasses); 206 iShortDistanceAccommodationReference = properties.getProperty( 207 "Distances.ShortDistanceAccommodationReference", iShortDistanceAccommodationReference); 208 iInstructorLongTravelInMinutes = properties.getPropertyDouble("Instructor.InstructorLongTravelInMinutes", 30.0); 209 iAllowedDistanceInMinutes = properties.getPropertyInt("HardDistanceConflict.AllowedDistanceInMinutes", iAllowedDistanceInMinutes); 210 iDistanceHardLimitInMinutes = properties.getPropertyInt("HardDistanceConflict.DistanceHardLimitInMinutes", iDistanceHardLimitInMinutes); 211 iDistanceLongLimitInMinutes = properties.getPropertyInt("HardDistanceConflict.DistanceLongLimitInMinutes", iDistanceLongLimitInMinutes); 212 iHardDistanceConflicts = properties.getPropertyBoolean("Sectioning.HardDistanceConflict", iHardDistanceConflicts); 213 } 214 215 /** Degrees to radians 216 * @param deg degrees 217 * @return radians 218 **/ 219 protected double deg2rad(double deg) { 220 return deg * Math.PI / 180; 221 } 222 223 /** Compute distance between the two given coordinates 224 * @param lat1 first coordinate's latitude 225 * @param lon1 first coordinate's longitude 226 * @param lat2 second coordinate's latitude 227 * @param lon2 second coordinate's longitude 228 * @return distance in meters 229 * @deprecated Use @{link {@link DistanceMetric#getDistanceInMeters(Long, Double, Double, Long, Double, Double)} instead (to include travel time matrix when available). 230 */ 231 @Deprecated 232 public double getDistanceInMeters(Double lat1, Double lon1, Double lat2, Double lon2) { 233 if (lat1 == null || lat2 == null || lon1 == null || lon2 == null) 234 return iNullDistance; 235 236 if (lat1.equals(lat2) && lon1.equals(lon2)) return 0.0; 237 238 // legacy mode -- euclidian distance, 1 unit is 10 meters 239 if (iModel == Ellipsoid.LEGACY) { 240 if (lat1 < 0 || lat2 < 0 || lon1 < 0 || lon2 < 0) return iNullDistance; 241 double dx = lat1 - lat2; 242 double dy = lon1 - lon2; 243 return Math.sqrt(dx * dx + dy * dy); 244 } 245 246 String id = null; 247 if (lat1 < lat2 || (lat1 == lat2 && lon1 <= lon2)) { 248 id = 249 Long.toHexString(Double.doubleToRawLongBits(lat1)) + 250 Long.toHexString(Double.doubleToRawLongBits(lon1)) + 251 Long.toHexString(Double.doubleToRawLongBits(lat2)) + 252 Long.toHexString(Double.doubleToRawLongBits(lon2)); 253 } else { 254 id = 255 Long.toHexString(Double.doubleToRawLongBits(lat1)) + 256 Long.toHexString(Double.doubleToRawLongBits(lon1)) + 257 Long.toHexString(Double.doubleToRawLongBits(lat2)) + 258 Long.toHexString(Double.doubleToRawLongBits(lon2)); 259 } 260 261 iLock.readLock().lock(); 262 try { 263 Double distance = iDistanceCache.get(id); 264 if (distance != null) return distance; 265 } finally { 266 iLock.readLock().unlock(); 267 } 268 269 iLock.writeLock().lock(); 270 try { 271 Double distance = iDistanceCache.get(id); 272 if (distance != null) return distance; 273 274 double a = iModel.a(), b = iModel.b(), f = iModel.f(); // ellipsoid params 275 double L = deg2rad(lon2-lon1); 276 double U1 = Math.atan((1-f) * Math.tan(deg2rad(lat1))); 277 double U2 = Math.atan((1-f) * Math.tan(deg2rad(lat2))); 278 double sinU1 = Math.sin(U1), cosU1 = Math.cos(U1); 279 double sinU2 = Math.sin(U2), cosU2 = Math.cos(U2); 280 281 double lambda = L, lambdaP, iterLimit = 100; 282 double cosSqAlpha, cos2SigmaM, sinSigma, cosSigma, sigma, sinLambda, cosLambda; 283 do { 284 sinLambda = Math.sin(lambda); 285 cosLambda = Math.cos(lambda); 286 sinSigma = Math.sqrt((cosU2*sinLambda) * (cosU2*sinLambda) + 287 (cosU1*sinU2-sinU1*cosU2*cosLambda) * (cosU1*sinU2-sinU1*cosU2*cosLambda)); 288 if (sinSigma==0) return 0; // co-incident points 289 cosSigma = sinU1*sinU2 + cosU1*cosU2*cosLambda; 290 sigma = Math.atan2(sinSigma, cosSigma); 291 double sinAlpha = cosU1 * cosU2 * sinLambda / sinSigma; 292 cosSqAlpha = 1 - sinAlpha*sinAlpha; 293 cos2SigmaM = cosSigma - 2*sinU1*sinU2/cosSqAlpha; 294 if (Double.isNaN(cos2SigmaM)) cos2SigmaM = 0; // equatorial line: cosSqAlpha=0 (�6) 295 double C = f/16*cosSqAlpha*(4+f*(4-3*cosSqAlpha)); 296 lambdaP = lambda; 297 lambda = L + (1-C) * f * sinAlpha * 298 (sigma + C*sinSigma*(cos2SigmaM+C*cosSigma*(-1+2*cos2SigmaM*cos2SigmaM))); 299 } while (Math.abs(lambda-lambdaP) > 1e-12 && --iterLimit>0); 300 if (iterLimit==0) return Double.NaN; // formula failed to converge 301 302 double uSq = cosSqAlpha * (a*a - b*b) / (b*b); 303 double A = 1 + uSq/16384*(4096+uSq*(-768+uSq*(320-175*uSq))); 304 double B = uSq/1024 * (256+uSq*(-128+uSq*(74-47*uSq))); 305 double deltaSigma = B*sinSigma*(cos2SigmaM+B/4*(cosSigma*(-1+2*cos2SigmaM*cos2SigmaM)- 306 B/6*cos2SigmaM*(-3+4*sinSigma*sinSigma)*(-3+4*cos2SigmaM*cos2SigmaM))); 307 308 // initial & final bearings 309 // double fwdAz = Math.atan2(cosU2*sinLambda, cosU1*sinU2-sinU1*cosU2*cosLambda); 310 // double revAz = Math.atan2(cosU1*sinLambda, -sinU1*cosU2+cosU1*sinU2*cosLambda); 311 312 // s = s.toFixed(3); // round to 1mm precision 313 314 distance = b*A*(sigma-deltaSigma); 315 iDistanceCache.put(id, distance); 316 return distance; 317 } finally { 318 iLock.writeLock().unlock(); 319 } 320 } 321 322 /** 323 * Compute distance in minutes. 324 * 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). 325 * @param lat1 first coordinate's latitude 326 * @param lon1 first coordinate's longitude 327 * @param lat2 second coordinate's latitude 328 * @param lon2 second coordinate's longitude 329 * @return distance in minutes 330 * @deprecated Use @{link {@link DistanceMetric#getDistanceInMinutes(Long, Double, Double, Long, Double, Double)} instead (to include travel time matrix when available). 331 */ 332 @Deprecated 333 public int getDistanceInMinutes(double lat1, double lon1, double lat2, double lon2) { 334 return (int) Math.round(getDistanceInMeters(lat1, lon1, lat2, lon2) / iSpeed); 335 } 336 337 /** 338 * Converts minutes to meters. 339 * Property Distances.Speed (in meters per minute) is used, defaults to 1000 meters per 15 minutes. 340 * @param min minutes to travel 341 * @return meters to travel 342 */ 343 public double minutes2meters(int min) { 344 return iSpeed * min; 345 } 346 347 348 /** Back-to-back classes in rooms within this limit have neutral preference 349 * @return limit in meters 350 **/ 351 public double getInstructorNoPreferenceLimit() { 352 return iInstructorNoPreferenceLimit; 353 } 354 355 /** Back-to-back classes in rooms within this limit have discouraged preference 356 * @return limit in meters 357 **/ 358 public double getInstructorDiscouragedLimit() { 359 return iInstructorDiscouragedLimit; 360 } 361 362 /** Back-to-back classes in rooms within this limit have strongly discouraged preference, it is prohibited to exceed this limit. 363 * @return limit in meters 364 **/ 365 public double getInstructorProhibitedLimit() { 366 return iInstructorProhibitedLimit; 367 } 368 369 /** 370 * When Distances.ComputeDistanceConflictsBetweenNonBTBClasses is enabled, distance limit (in minutes) 371 * for a long travel. 372 * @return travel time in minutes 373 */ 374 public double getInstructorLongTravelInMinutes() { 375 return iInstructorLongTravelInMinutes; 376 } 377 378 /** True if legacy mode is used (Euclidian distance where 1 unit is 10 meters) 379 * @return true if the ellipsoid model is the old one 380 **/ 381 public boolean isLegacy() { 382 return iModel == Ellipsoid.LEGACY; 383 } 384 385 /** Maximal travel distance between rooms when no coordinates are given 386 * @return travel time in minutes 387 **/ 388 public int getMaxTravelDistanceInMinutes() { 389 return iMaxTravelTime; 390 } 391 392 /** Set maximal travel distance between rooms when no coordinates are given 393 * @param maxTravelTime max travel time in minutes 394 */ 395 public void setMaxTravelDistanceInMinutes(int maxTravelTime) { 396 iMaxTravelTime = maxTravelTime; 397 } 398 399 /** Add travel time between two locations 400 * @param roomId1 first room's id 401 * @param roomId2 second room's id 402 * @param travelTimeInMinutes travel time in minutes 403 **/ 404 public void addTravelTime(Long roomId1, Long roomId2, Integer travelTimeInMinutes) { 405 iLock.writeLock().lock(); 406 try { 407 if (roomId1 == null || roomId2 == null) return; 408 if (roomId1 < roomId2) { 409 Map<Long, Integer> times = iTravelTimes.get(roomId1); 410 if (times == null) { times = new HashMap<Long, Integer>(); iTravelTimes.put(roomId1, times); } 411 if (travelTimeInMinutes == null) 412 times.remove(roomId2); 413 else 414 times.put(roomId2, travelTimeInMinutes); 415 } else { 416 Map<Long, Integer> times = iTravelTimes.get(roomId2); 417 if (times == null) { times = new HashMap<Long, Integer>(); iTravelTimes.put(roomId2, times); } 418 if (travelTimeInMinutes == null) 419 times.remove(roomId1); 420 else 421 times.put(roomId1, travelTimeInMinutes); 422 } 423 } finally { 424 iLock.writeLock().unlock(); 425 } 426 } 427 428 /** Return travel time between two locations. 429 * @param roomId1 first room's id 430 * @param roomId2 second room's id 431 * @return travel time in minutes 432 **/ 433 public Integer getTravelTimeInMinutes(Long roomId1, Long roomId2) { 434 iLock.readLock().lock(); 435 try { 436 if (roomId1 == null || roomId2 == null) return null; 437 if (roomId1 < roomId2) { 438 Map<Long, Integer> times = iTravelTimes.get(roomId1); 439 return (times == null ? null : times.get(roomId2)); 440 } else { 441 Map<Long, Integer> times = iTravelTimes.get(roomId2); 442 return (times == null ? null : times.get(roomId1)); 443 } 444 } finally { 445 iLock.readLock().unlock(); 446 } 447 } 448 449 /** Return travel time between two locations. Travel times are used when available, use coordinates otherwise. 450 * @param roomId1 first room's id 451 * @param lat1 first room's latitude 452 * @param lon1 first room's longitude 453 * @param roomId2 second room's id 454 * @param lat2 second room's latitude 455 * @param lon2 second room's longitude 456 * @return distance in minutes 457 **/ 458 public Integer getDistanceInMinutes(Long roomId1, Double lat1, Double lon1, Long roomId2, Double lat2, Double lon2) { 459 Integer distance = getTravelTimeInMinutes(roomId1, roomId2); 460 if (distance != null) return distance; 461 462 if (lat1 == null || lat2 == null || lon1 == null || lon2 == null) 463 return getMaxTravelDistanceInMinutes(); 464 else 465 return (int) Math.min(getMaxTravelDistanceInMinutes(), Math.round(getDistanceInMeters(lat1, lon1, lat2, lon2) / iSpeed)); 466 } 467 468 /** Return travel distance between two locations. Travel times are used when available, use coordinates otherwise 469 * @param roomId1 first room's id 470 * @param lat1 first room's latitude 471 * @param lon1 first room's longitude 472 * @param roomId2 second room's id 473 * @param lat2 second room's latitude 474 * @param lon2 second room's longitude 475 * @return distance in meters 476 **/ 477 public double getDistanceInMeters(Long roomId1, Double lat1, Double lon1, Long roomId2, Double lat2, Double lon2) { 478 Integer distance = getTravelTimeInMinutes(roomId1, roomId2); 479 if (distance != null) return minutes2meters(distance); 480 481 return getDistanceInMeters(lat1, lon1, lat2, lon2); 482 } 483 484 /** Return travel times matrix 485 * @return travel times matrix 486 **/ 487 public Map<Long, Map<Long, Integer>> getTravelTimes() { return iTravelTimes; } 488 489 /** 490 * True if distances should be considered between classes that are NOT back-to-back. Distance in minutes is then 491 * 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. 492 * @return true if distances should be considered between classes that are NOT back-to-back 493 **/ 494 public boolean doComputeDistanceConflictsBetweenNonBTBClasses() { 495 return iComputeDistanceConflictsBetweenNonBTBClasses; 496 } 497 498 public void setComputeDistanceConflictsBetweenNonBTBClasses(boolean computeDistanceConflictsBetweenNonBTBClasses) { 499 iComputeDistanceConflictsBetweenNonBTBClasses = computeDistanceConflictsBetweenNonBTBClasses; 500 } 501 502 /** 503 * Reference of the accommodation of students that need short distances 504 */ 505 public String getShortDistanceAccommodationReference() { 506 return iShortDistanceAccommodationReference; 507 } 508 509 /** Allowed distance in minutes (for {@link HardDistanceConflicts}) */ 510 public int getAllowedDistanceInMinutes() { 511 return iAllowedDistanceInMinutes; 512 } 513 /** Hard distance limit in minutes (for {@link HardDistanceConflicts}) */ 514 public int getDistanceHardLimitInMinutes() { 515 return iDistanceHardLimitInMinutes; 516 } 517 /** Long distance limit in minutes (for display) */ 518 public int getDistanceLongLimitInMinutes() { 519 return iDistanceLongLimitInMinutes; 520 } 521 /** Hard distance conflicts enabled (for {@link HardDistanceConflicts}) */ 522 public boolean isHardDistanceConflictsEnabled() { 523 return iHardDistanceConflicts; 524 } 525 526 527 /** Few tests 528 * @param args program arguments 529 **/ 530 public static void main(String[] args) { 531 System.out.println("Distance between Prague and Zlin: " + new DistanceMetric().getDistanceInMeters(50.087661, 14.420535, 49.226736, 17.668856) / 1000.0 + " km"); 532 System.out.println("Distance between ENAD and PMU: " + new DistanceMetric().getDistanceInMeters(40.428323, -86.912785, 40.425078, -86.911474) + " m"); 533 System.out.println("Distance between ENAD and ME: " + new DistanceMetric().getDistanceInMeters(40.428323, -86.912785, 40.429338, -86.91267) + " m"); 534 System.out.println("Distance between Prague and Zlin: " + new DistanceMetric().getDistanceInMinutes(50.087661, 14.420535, 49.226736, 17.668856) / 60 + " hours"); 535 System.out.println("Distance between ENAD and PMU: " + new DistanceMetric().getDistanceInMinutes(40.428323, -86.912785, 40.425078, -86.911474) + " minutes"); 536 System.out.println("Distance between ENAD and ME: " + new DistanceMetric().getDistanceInMinutes(40.428323, -86.912785, 40.429338, -86.91267) + " minutes"); 537 } 538 539}