MATSIM
TransitAgentImpl.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.* *
3  * *
4  * *********************************************************************** *
5  * *
6  * copyright : (C) 2008 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.mobsim.qsim.agents;
20 
21 import java.util.List;
22 
23 import org.apache.logging.log4j.LogManager;
24 import org.apache.logging.log4j.Logger;
25 import org.matsim.api.core.v01.Id;
38 import org.matsim.vehicles.Vehicle;
39 
44 public final class TransitAgentImpl implements PTPassengerAgent {
45 
48 
49  public TransitAgentImpl( BasicPlanAgentImpl basicAgent ) {
50  this( basicAgent, BoardingAcceptance.checkLineAndStop ) ;
51  }
52 
53  public TransitAgentImpl(BasicPlanAgentImpl basicAgent, BoardingAcceptance boardingAcceptance) {
54  this.basicAgentDelegate = basicAgent ;
55  this.boardingAcceptance = boardingAcceptance;
56  }
57 
58  private static final Logger log = LogManager.getLogger(TransitAgentImpl.class);
59 
60  @Override
61  public final boolean getExitAtStop(final TransitStopFacility stop) {
62  TransitPassengerRoute route = (TransitPassengerRoute) basicAgentDelegate.getCurrentLeg().getRoute();
63  return route.getEgressStopId().equals(stop.getId());
64  }
65 
66  @Override
67  public final boolean getEnterTransitRoute(final TransitLine line, final TransitRoute transitRoute, final List<TransitRouteStop> stopsToCome, TransitVehicle transitVehicle) {
68  TransitPassengerRoute route = (TransitPassengerRoute) basicAgentDelegate.getCurrentLeg().getRoute();
69  switch ( boardingAcceptance ) {
70  case checkLineAndStop:
71  return line.getId().equals(route.getLineId()) && containsId(stopsToCome, route.getEgressStopId());
72  case checkStopOnly:
73  return containsId(stopsToCome, route.getEgressStopId());
74  default:
75  throw new RuntimeException("not implemented");
76  }
77  }
78 
79  private final boolean containsId(List<TransitRouteStop> stopsToCome,
80  Id<TransitStopFacility> egressStopId) {
81  for (TransitRouteStop stop : stopsToCome) {
82  if (egressStopId.equals(stop.getStopFacility().getId())) {
83  return true;
84  }
85  }
86  return false;
87  }
88 
89  @Override
90  public final double getWeight() {
91  return 1.0;
92  }
93 
94  @Override
96  Leg leg = basicAgentDelegate.getCurrentLeg();
97  if (!(leg.getRoute() instanceof TransitPassengerRoute)) {
98  log.error("pt-leg has no TransitRoute. Removing agent from simulation. Agent " + getId().toString());
99  log.info("route: "
100  + leg.getRoute().getClass().getCanonicalName()
101  + " "
102  + leg.getRoute().getRouteDescription());
103  return null;
104  } else {
106  Id<TransitStopFacility> accessStopId = route.getAccessStopId();
107  return accessStopId;
108  }
109  }
110 
111  @Override
113  TransitPassengerRoute route = (TransitPassengerRoute) basicAgentDelegate.getCurrentLeg().getRoute();
114  return route.getEgressStopId();
115  }
116  @Override
118  return basicAgentDelegate.getCurrentLinkId() ;
119  }
120  @Override
122  return basicAgentDelegate.getDestinationLinkId() ;
123  }
124  @Override
125  public void setVehicle(MobsimVehicle veh) {
126  basicAgentDelegate.setVehicle( veh );
127  }
128  @Override
130  return basicAgentDelegate.getVehicle() ;
131  }
132  @Override
134  return basicAgentDelegate.getPlannedVehicleId() ;
135  }
136  @Override
137  public Id<Person> getId() {
138  return basicAgentDelegate.getId() ;
139  }
140 
141  @Override
142  public String getMode() {
143  return basicAgentDelegate.getMode() ;
144  }
145 
146 }
final boolean containsId(List< TransitRouteStop > stopsToCome, Id< TransitStopFacility > egressStopId)
final boolean getEnterTransitRoute(final TransitLine line, final TransitRoute transitRoute, final List< TransitRouteStop > stopsToCome, TransitVehicle transitVehicle)
final Id< TransitStopFacility > getDesiredDestinationStopId()
Id< TransitStopFacility > getEgressStopId()
final Id< TransitStopFacility > getDesiredAccessStopId()
final boolean getExitAtStop(final TransitStopFacility stop)
boolean equals(Object obj)
Definition: Id.java:139
Id< TransitStopFacility > getAccessStopId()
TransitAgentImpl(BasicPlanAgentImpl basicAgent, BoardingAcceptance boardingAcceptance)