-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: A more advanced standalone mode choice (#195)
* feat: RunStandaloneModeChoice * feat: PublicTransportLegReaderFromPopulation * fix: input csv file names --------- Co-authored-by: Tarek Chouaki <tarek.chouaki@irt-systemx.fr>
- Loading branch information
Showing
8 changed files
with
691 additions
and
220 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
core/src/main/java/org/eqasim/core/analysis/pt/PublicTransportLegReaderFromPopulation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package org.eqasim.core.analysis.pt; | ||
|
||
import org.eqasim.core.analysis.PersonAnalysisFilter; | ||
import org.matsim.api.core.v01.Id; | ||
import org.matsim.api.core.v01.Scenario; | ||
import org.matsim.api.core.v01.TransportMode; | ||
import org.matsim.api.core.v01.population.*; | ||
import org.matsim.core.config.Config; | ||
import org.matsim.core.config.ConfigUtils; | ||
import org.matsim.core.population.io.PopulationReader; | ||
import org.matsim.core.router.TripStructureUtils; | ||
import org.matsim.core.scenario.ScenarioUtils; | ||
import org.matsim.pt.routes.DefaultTransitPassengerRoute; | ||
import org.matsim.pt.transitSchedule.api.TransitSchedule; | ||
import org.matsim.pt.transitSchedule.api.TransitStopArea; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class PublicTransportLegReaderFromPopulation { | ||
|
||
final private PersonAnalysisFilter personAnalysisFilter; | ||
final private TransitSchedule transitSchedule; | ||
|
||
public PublicTransportLegReaderFromPopulation(TransitSchedule transitSchedule, PersonAnalysisFilter personAnalysisFilter) { | ||
this.personAnalysisFilter = personAnalysisFilter; | ||
this.transitSchedule = transitSchedule; | ||
|
||
} | ||
|
||
public Collection<PublicTransportLegItem> readPublicTransportLegs(String populationFilePath) { | ||
Config config = ConfigUtils.createConfig(); | ||
Scenario scenario = ScenarioUtils.createScenario(config); | ||
new PopulationReader(scenario).readFile(populationFilePath); | ||
return this.readPublicTransportLegs(scenario.getPopulation()); | ||
} | ||
|
||
public Collection<PublicTransportLegItem> readPublicTransportLegs(Population population) { | ||
return population.getPersons().values().stream().flatMap(person -> getPublicTransportLegs(person).stream()).collect(Collectors.toList()); | ||
} | ||
|
||
public Collection<PublicTransportLegItem> getPublicTransportLegs(Person person) { | ||
List<PublicTransportLegItem> legItems = new ArrayList<>(); | ||
Plan plan = person.getSelectedPlan(); | ||
int tripIndex = -1; | ||
int legIndex = -1; | ||
for(PlanElement planElement: plan.getPlanElements()) { | ||
if(planElement instanceof Activity) { | ||
Activity activity = (Activity) planElement; | ||
if(!TripStructureUtils.isStageActivityType(activity.getType())) { | ||
tripIndex +=1; | ||
} | ||
continue; | ||
} | ||
Leg leg = (Leg) planElement; | ||
legIndex=+1; | ||
if(!leg.getMode().equals(TransportMode.pt)) { | ||
continue; | ||
} | ||
if(! (leg.getRoute() instanceof DefaultTransitPassengerRoute)) { | ||
throw new IllegalStateException("PT leg has invalid route type"); | ||
} | ||
DefaultTransitPassengerRoute transitPassengerRoute = (DefaultTransitPassengerRoute) leg.getRoute(); | ||
|
||
Id<TransitStopArea> accessStopAreaId = this.transitSchedule.getFacilities().get(transitPassengerRoute.getAccessStopId()).getStopAreaId(); | ||
Id<TransitStopArea> egressStopAreaId = this.transitSchedule.getFacilities().get(transitPassengerRoute.getEgressStopId()).getStopAreaId(); | ||
String mode = this.transitSchedule.getTransitLines().get(transitPassengerRoute.getLineId()).getRoutes().get(transitPassengerRoute.getRouteId()).getTransportMode(); | ||
|
||
PublicTransportLegItem item = new PublicTransportLegItem(person.getId(), tripIndex, legIndex, transitPassengerRoute.getAccessStopId(), transitPassengerRoute.getEgressStopId(), transitPassengerRoute.getLineId(), transitPassengerRoute.getRouteId(), accessStopAreaId, egressStopAreaId, mode); | ||
legItems.add(item); | ||
} | ||
return legItems; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
218 changes: 0 additions & 218 deletions
218
ile_de_france/src/main/java/org/eqasim/ile_de_france/RunModeChoice.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.