@Override public Double getExpectedTravelTime() { return route.getTravelTime(); }
@Override public void startRoute(final Route route, final BufferedWriter out) throws IOException { out.write("\t\t\t\t<route"); if (!Double.isNaN(route.getDistance())) { out.write(" dist=\""); out.write(Double.toString(route.getDistance())); out.write("\""); } if (route.getTravelTime() != Time.UNDEFINED_TIME) { out.write(" trav_time=\""); out.write(Time.writeTime(route.getTravelTime())); out.write("\""); } out.write(">\n"); out.write("\t\t\t\t\t"); if (route instanceof NetworkRoute) { for (Node n : RouteUtils.getNodes((NetworkRoute) route, this.network)) { out.write(n.getId().toString()); out.write(" "); } } else { String rd = route.getRouteDescription(); if (rd != null) { out.write(rd); out.write(" "); // this is at the moment only to maintain binary compatibility } } out.write("\n"); }
public GenericRouteSerializable(Route route) { distance = route.getDistance(); endLinkIdString = route.getEndLinkId().toString(); routeDescription = route.getRouteDescription(); startLinkIdString = route.getStartLinkId().toString(); travelTime = route.getTravelTime(); }
out.write("\""); out.write(" trav_time=\""); out.write(Time.writeTime(route.getTravelTime())); out.write("\""); out.write(" distance=\"");
out.write("\""); out.write(" trav_time=\""); out.write(Time.writeTime(route.getTravelTime())); out.write("\""); out.write(" distance=\"");
public static double decideOnTravelTimeForLeg( Leg leg ) { if ( leg.getRoute()!=null ) { return leg.getRoute().getTravelTime() ; } else { return leg.getTravelTime() ; } } public static void sampleDown( Population pop, double sample ) {
final Route route = leg.getRoute(); final double legDur = route != null && route.getTravelTime() != Time.UNDEFINED_TIME ? route.getTravelTime() : leg.getTravelTime();
@Override public final Double getExpectedTravelTime() { PlanElement currentPlanElement = this.getCurrentPlanElement(); if (!(currentPlanElement instanceof Leg)) { return null; } final double travelTimeFromRoute = ((Leg) currentPlanElement).getRoute().getTravelTime(); if ( travelTimeFromRoute != Time.UNDEFINED_TIME ) { return travelTimeFromRoute ; } else if ( ((Leg) currentPlanElement).getTravelTime() != Time.UNDEFINED_TIME ) { return ((Leg) currentPlanElement).getTravelTime() ; } else { return null ; } }
private static double calcArrivalTime(final Trip trip) { double now = trip.getOriginActivity().getEndTime(); for ( final PlanElement pe : trip.getTripElements() ) { if ( pe instanceof Activity ) { final double end = ((Activity) pe).getEndTime(); now = end != Time.UNDEFINED_TIME ? end : now + ((Activity) pe).getMaximumDuration(); // TODO: do not fail *that* badly, but just revert to random alloc if ( now == Time.UNDEFINED_TIME ) throw new RuntimeException( "could not get time from "+pe ); } else if ( pe instanceof Leg ) { final Route r = ((Leg) pe).getRoute(); if ( r != null && r.getTravelTime() != Time.UNDEFINED_TIME ) { now += r.getTravelTime(); } else { now += ((Leg) pe).getTravelTime() != Time.UNDEFINED_TIME ? ((Leg) pe).getTravelTime() : 0; // no info: just assume instantaneous. This will give poor results! } } } return now; } }
final Route route = leg.getRoute(); final double legDur = route != null && route.getTravelTime() != Time.UNDEFINED_TIME ? route.getTravelTime() : leg.getTravelTime();
final Leg l = PopulationUtils.createLeg(mode); l.setRoute( pathCosts.getRoute() ); l.setTravelTime( pathCosts.getRoute().getTravelTime() ); l.setDepartureTime( fromAct.getEndTime() ); return Collections.singletonList( l );
@Deprecated // use TripRouter instead. kai, dec'13 public static double handleLeg(TripRouter tripRouter, final Person person, final Leg leg, final Activity fromAct, final Activity toAct, final double depTime) { List<? extends PlanElement> trip = tripRouter.calcRoute( leg.getMode(), new ActivityWrapperFacility( fromAct ), new ActivityWrapperFacility( toAct ), depTime, person); if ( trip.size() != 1 ) { throw new IllegalStateException( "This method can only be used with "+ "routing modules returning single legs. Got the following trip "+ "for mode "+leg.getMode()+": "+trip ); } Leg tripLeg = (Leg) trip.get( 0 ); leg.setRoute( tripLeg.getRoute() ); leg.setTravelTime( tripLeg.getTravelTime() ); leg.setDepartureTime( tripLeg.getDepartureTime() ); return tripLeg.getRoute() != null && tripLeg.getRoute().getTravelTime() != Time.UNDEFINED_TIME ? tripLeg.getRoute().getTravelTime() : tripLeg.getTravelTime(); }
private static void fillInLegTravelTimes( final double departureTime, final List<? extends PlanElement> trip ) { double time = departureTime; for ( PlanElement pe : trip ) { if ( !(pe instanceof Leg) ) continue; final Leg leg = (Leg) pe; if ( leg.getDepartureTime() == Time.UNDEFINED_TIME ) { leg.setDepartureTime( time ); } if ( leg.getTravelTime() == Time.UNDEFINED_TIME ) { leg.setTravelTime( leg.getRoute().getTravelTime() ); } time += leg.getTravelTime(); } }
@Override public double computeContributionOfOpportunity(ActivityFacility origin, final AggregationObject destination, Double departureTime) { Person person = null ; // I think that this is ok ActivityFacilitiesFactory activityFacilitiesFactory = new ActivityFacilitiesFactoryImpl(); ActivityFacility destinationFacility = activityFacilitiesFactory.createActivityFacility(null, destination.getNearestNode().getCoord()); Gbl.assertNotNull(tripRouter); List<? extends PlanElement> plan = tripRouter.calcRoute(mode, origin, destinationFacility, departureTime, person); // Vehicle vehicle = null ; // I think that this is ok double utility = 0.; List<Leg> legs = TripStructureUtils.getLegs(plan); // TODO Doing it like this, the pt interaction (e.g. waiting) times will be omitted! Gbl.assertIf(!legs.isEmpty()); for (Leg leg : legs) { // Add up all utility components of leg utility += leg.getRoute().getDistance() * this.planCalcScoreConfigGroup.getModes().get(leg.getMode()).getMarginalUtilityOfDistance(); utility += leg.getRoute().getTravelTime() * this.planCalcScoreConfigGroup.getModes().get(leg.getMode()).getMarginalUtilityOfTraveling() / 3600.; utility += -leg.getRoute().getTravelTime() * this.planCalcScoreConfigGroup.getPerforming_utils_hr() / 3600.; } // Utility based on opportunities that are attached to destination node double sumExpVjkWalk = destination.getSum(); // exp(beta * a) * exp(beta * b) = exp(beta * (a+b)) return Math.exp(this.planCalcScoreConfigGroup.getBrainExpBeta() * utility) * sumExpVjkWalk; } }
if (this.currRoute.getTravelTime() == Time.UNDEFINED_TIME) { this.currRoute.setTravelTime(this.currleg.getTravelTime());
public void testWriteGenericRoute() { MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(super.loadConfig(null)); Network network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).readFile("test/scenarios/equil/network.xml"); Link link1 = network.getLinks().get(Id.create(1, Link.class)); Link link2 = network.getLinks().get(Id.create(2, Link.class)); Scenario tmpScenario = new ScenarioBuilder(ConfigUtils.createConfig()).setNetwork(network).build() ; Population pop = tmpScenario.getPopulation(); PopulationFactory pb = pop.getFactory(); Person person = pb.createPerson(Id.create(1, Person.class)); Plan plan = (Plan) pb.createPlan(); plan.setPerson(person); plan.addActivity(pb.createActivityFromLinkId("h", link1.getId())); Leg leg = pb.createLeg("undefined"); Route route = RouteUtils.createGenericRouteImpl(link1.getId(), link2.getId()); route.setTravelTime(123); leg.setRoute(route); plan.addLeg(leg); plan.addActivity(pb.createActivityFromLinkId("h", Id.create(1, Link.class))); person.addPlan(plan); pop.addPerson(person); String filename = getOutputDirectory() + "population.xml"; new PopulationWriter(pop, network).writeV4(filename); Population pop2 = scenario.getPopulation(); new PopulationReader(scenario).readFile(filename); Person person2 = pop2.getPersons().get(Id.create(1, Person.class)); Leg leg2 = (Leg) person2.getPlans().get(0).getPlanElements().get(1); Route route2 = leg2.getRoute(); assertEquals(123, route2.getTravelTime(), EPSILON); // if this succeeds, we know that writing/reading the data works }
Assert.assertEquals("wrong travel time", travTime, route2.getTravelTime(), 1e-9); Assert.assertEquals("wrong distance", dist, route2.getDistance(), 1e-9);
Route route2 = ((Leg) plan.getPlanElements().get(1)).getRoute(); assertEquals(98.76, route2.getTravelTime(), 1e-8);
@Test public void testCopyPlan_NetworkRoute() { Network network = NetworkUtils.createNetwork(); Node node1 = NetworkUtils.createAndAddNode(network, Id.create(1, Node.class), new Coord(0, 0)); Node node2 = NetworkUtils.createAndAddNode(network, Id.create(2, Node.class), new Coord(1000, 0)); Node node3 = NetworkUtils.createAndAddNode(network, Id.create(3, Node.class), new Coord(2000, 0)); final Node fromNode = node1; final Node toNode = node2; Link link1 = NetworkUtils.createAndAddLink(network,Id.create(1, Link.class), fromNode, toNode, 1000.0, 100.0, 3600.0, 1.0 ); final Node fromNode1 = node2; final Node toNode1 = node3; Link link2 = NetworkUtils.createAndAddLink(network,Id.create(2, Link.class), fromNode1, toNode1, 1000.0, 100.0, 3600.0, 1.0 ); Plan plan = PopulationUtils.createPlan(PopulationUtils.getFactory().createPerson(Id.create(1, Person.class))); PopulationUtils.createAndAddActivityFromCoord(plan, "h", new Coord(0, 0)); Leg leg = PopulationUtils.createAndAddLeg( plan, TransportMode.car ); PopulationUtils.createAndAddActivityFromCoord(plan, "w", new Coord(100, 200)); Route route = RouteUtils.createLinkNetworkRouteImpl(link1.getId(), link2.getId()); route.setTravelTime(98.76); leg.setRoute(route); Plan plan2 = PopulationUtils.createPlan(PopulationUtils.getFactory().createPerson(Id.create(2, Person.class))); PopulationUtils.copyFromTo(plan, plan2); assertEquals("person must not be copied.", Id.create(2, Person.class), plan2.getPerson().getId()); assertEquals("wrong number of plan elements.", plan.getPlanElements().size(), plan2.getPlanElements().size()); Route route2 = ((Leg) plan.getPlanElements().get(1)).getRoute(); assertTrue(route2 instanceof NetworkRoute); assertEquals(98.76, route2.getTravelTime(), 1e-8); }
@Test public void testCreatesLegWithRoute() { Scenario scenario = createTriangularNetwork(); EventsToLegs eventsToLegs = new EventsToLegs(scenario); RememberingLegHandler lh = new RememberingLegHandler(); eventsToLegs.addLegHandler(lh); Id<Person> agentId = Id.create("1", Person.class); Id<Vehicle> vehId = Id.create("veh1", Vehicle.class); eventsToLegs.handleEvent(new PersonDepartureEvent(10.0, agentId, Id.createLinkId("l1"), "car")); eventsToLegs.handleEvent(new PersonEntersVehicleEvent(10.0, agentId, vehId)); eventsToLegs.handleEvent(new VehicleEntersTrafficEvent(10.0, agentId, Id.createLinkId("l1"), vehId, "car", 1.0)); eventsToLegs.handleEvent(new LinkLeaveEvent(10.0, vehId, Id.createLinkId("l1"))); eventsToLegs.handleEvent(new LinkEnterEvent(11.0, vehId, Id.createLinkId("l2"))); eventsToLegs.handleEvent(new LinkLeaveEvent(15.0, vehId, Id.createLinkId("l2"))); eventsToLegs.handleEvent(new LinkEnterEvent(16.0, vehId, Id.createLinkId("l3"))); eventsToLegs.handleEvent(new VehicleLeavesTrafficEvent(30.0, agentId, Id.createLinkId("l3"), vehId, "car", 1.0)); eventsToLegs.handleEvent(new PersonArrivalEvent(30.0, agentId, Id.createLinkId("l3"), "car")); Assert.assertNotNull(lh.handledLeg); Assert.assertEquals(10.0,lh.handledLeg.getLeg().getDepartureTime(), 1e-9); Assert.assertEquals(20.0,lh.handledLeg.getLeg().getTravelTime(), 1e-9); Assert.assertEquals(20.0,lh.handledLeg.getLeg().getRoute().getTravelTime(), 1e-9); Assert.assertEquals(550.0,lh.handledLeg.getLeg().getRoute().getDistance(), 1e-9); }