MATSIM
TeleportationRoutingModule.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * *
4  * *********************************************************************** *
5  * *
6  * copyright : (C) 2015 by the members listed in the COPYING, *
7  * LICENSE and WARRANTY file. *
8  * email : info at matsim dot org *
9  * *
10  * *********************************************************************** *
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * See also COPYING, LICENSE and WARRANTY file *
17  * *
18  * *********************************************************************** */
19 package org.matsim.core.router;
20 
21 import java.util.Arrays;
22 import java.util.List;
23 
24 import org.matsim.api.core.v01.Coord;
25 import org.matsim.api.core.v01.Id;
26 import org.matsim.api.core.v01.Scenario;
32 import org.matsim.core.gbl.Gbl;
36 
37 
38 
42 public class TeleportationRoutingModule implements RoutingModule {
43 
44  private final String mode;
45 
46  private final double beelineDistanceFactor;
47  private final double networkTravelSpeed;
48  private final Scenario scenario;
49 
51  final String mode,
52  final Scenario scenario,
53  final double networkTravelSpeed,
54  final double beelineDistanceFactor) {
55  this.networkTravelSpeed = networkTravelSpeed;
56  this.beelineDistanceFactor = beelineDistanceFactor;
57  this.mode = mode;
58  this.scenario = scenario ;
59  }
60 
61  @Override
62  public List<? extends PlanElement> calcRoute(RoutingRequest request) {
63  final Facility fromFacility = request.getFromFacility();
64  final Facility toFacility = request.getToFacility();
65  final double departureTime = request.getDepartureTime();
66  final Person person = request.getPerson();
67 
68  Leg newLeg = this.scenario.getPopulation().getFactory().createLeg( this.mode );
69  newLeg.setDepartureTime( departureTime );
70 
71  double travTime = routeLeg(
72  person,
73  newLeg,
74  fromFacility,
75  toFacility,
76  departureTime);
77 
78  // otherwise, information may be lost
79  newLeg.setTravelTime( travTime );
80 
81  return Arrays.asList(newLeg);
82  }
83 
84  @Override
85  public String toString() {
86  return "[TeleportationRoutingModule: mode="+this.mode+"]";
87  }
88 
89 
90  /* package */ double routeLeg( Person person, Leg leg, Facility fromFacility, Facility toFacility, double depTime ) {
91  // yyyy there is a test that uses the above; todo: make that test use the official RoutingModule interface. kai, nov'19
92 
93  // make simple assumption about distance and walking speed
94 
95  final Coord fromActCoord = FacilitiesUtils.decideOnCoord( fromFacility, scenario.getNetwork(), scenario.getConfig() ) ;
96  Gbl.assertNotNull( fromActCoord );
97  final Coord toActCoord = FacilitiesUtils.decideOnCoord( toFacility, scenario.getNetwork(), scenario.getConfig() ) ;
98  Gbl.assertNotNull( toActCoord );
99  double dist = CoordUtils.calcEuclideanDistance( fromActCoord, toActCoord );
100  // create an empty route, but with realistic travel time
101 
102  Id<Link> fromFacilityLinkId = fromFacility.getLinkId();
103  if ( fromFacilityLinkId==null ) {
104  // (yyyy there is a test that does not have a context, and thus the call below fails. todo: adapt test. kai, nov'19)
105  fromFacilityLinkId = FacilitiesUtils.decideOnLink( fromFacility, scenario.getNetwork() ).getId() ;
106  }
107 
108  Id<Link> toFacilityLinkId = toFacility.getLinkId();
109  if ( toFacilityLinkId==null ) {
110  // (yyyy: same as above)
111  toFacilityLinkId = FacilitiesUtils.decideOnLink( toFacility, scenario.getNetwork() ).getId() ;
112  }
113 
114  Route route = this.scenario.getPopulation().getFactory().getRouteFactories().createRoute(Route.class, fromFacilityLinkId, toFacilityLinkId );
115  double estimatedNetworkDistance = dist * this.beelineDistanceFactor;
116  int travTime = (int) (estimatedNetworkDistance / this.networkTravelSpeed);
117  route.setTravelTime(travTime);
118  route.setDistance(estimatedNetworkDistance);
119  leg.setRoute(route);
120  leg.setDepartureTime(depTime);
121  leg.setTravelTime(travTime);
122  Leg r = (leg);
123  r.setTravelTime( depTime + travTime - r.getDepartureTime().seconds()); // yy something needs to be done once there are alternative implementations of the interface. kai, apr'10
124  return travTime;
125  }
126 
127 }
void setDistance(final double distance)
static double calcEuclideanDistance(Coord coord, Coord other)
void setDepartureTime(final double seconds)
List<? extends PlanElement > calcRoute(RoutingRequest request)
static Link decideOnLink(final Facility facility, final Network network)
static void assertNotNull(Object obj)
Definition: Gbl.java:212
TeleportationRoutingModule(final String mode, final Scenario scenario, final double networkTravelSpeed, final double beelineDistanceFactor)
void setTravelTime(final double seconds)
static Coord decideOnCoord(final Facility facility, final Network network, final Config config)
void setTravelTime(final double travelTime)