MATSIM
TripsToLegsAlgorithm.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * TripsToLegAlgorithm.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2012 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 package org.matsim.core.population.algorithms;
21 
22 import java.util.List;
23 
32 
40 public final class TripsToLegsAlgorithm implements PlanAlgorithm {
42 
43  public TripsToLegsAlgorithm(final TripRouter router) {
45  }
46 
47 
49  final MainModeIdentifier mainModeIdentifier) {
50  this.mainModeIdentifier = mainModeIdentifier;
51  }
52 
53  @Override
54  public void run(final Plan plan) {
55  final List<PlanElement> planElements = plan.getPlanElements();
56  final List<Trip> trips = TripStructureUtils.getTrips( plan );
57 
58  for ( Trip trip : trips ) {
59  final List<PlanElement> fullTrip =
60  planElements.subList(
61  planElements.indexOf( trip.getOriginActivity() ) + 1,
62  planElements.indexOf( trip.getDestinationActivity() ));
63  final String mode = mainModeIdentifier.identifyMainMode( fullTrip );
64  fullTrip.clear();
65  Leg leg = PopulationUtils.createLeg(mode);
67  fullTrip.add( leg );
68  if ( fullTrip.size() != 1 ) throw new RuntimeException( fullTrip.toString() );
69  }
70  }
71 }
72 
String identifyMainMode(List<? extends PlanElement > tripElements)
static MainModeIdentifier getRoutingModeIdentifier()
static void setRoutingMode(Leg leg, String mode)
TripsToLegsAlgorithm(final MainModeIdentifier mainModeIdentifier)
static Leg createLeg(String transportMode)
static List< Trip > getTrips(final Plan plan)
List< PlanElement > getPlanElements()