MATSIM
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap Class Reference
Inheritance diagram for org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap:
Inheritance graph
[legend]

Public Member Functions

 ActivityReplanningMap (MobsimDataProvider mobsimDataProvider, EventsManager eventsManager)
 
void notifyMobsimInitialized (MobsimInitializedEvent e)
 
void notifyMobsimAfterSimStep (MobsimAfterSimStepEvent e)
 
void handleEvent (ActivityStartEvent event)
 
void handleEvent (ActivityEndEvent event)
 
void handleEvent (PersonStuckEvent event)
 
void handleEvent (ReplanningEvent event)
 
Set< Id< Person > > getActivityPerformingAgents ()
 
Collection< MobsimAgentgetActivityEndingAgents (double time)
 
void reset (int iteration)
 

Private Member Functions

Map< Id< Person >, MobsimAgentgetMapForTimeBin (int bin)
 

Private Attributes

final MobsimDataProvider mobsimDataProvider
 
final Map< Id< Person >, MobsimAgentstartingAgents
 
final Map< Id< Person >, Double > activityEndTimes
 
final Map< Integer, Map< Id< Person >, MobsimAgent > > activityPerformingAgents
 

Static Private Attributes

static final Logger log = LogManager.getLogger(ActivityReplanningMap.class)
 

Detailed Description

This class tracks agents and their activity end times. It can be used to identify those agents which are going to end their activities in the current time step. Doing so allows one to e.g. extend their activities. Moreover, it can return a set containing all agents currently performing activites.

Definition at line 60 of file ActivityReplanningMap.java.

Constructor & Destructor Documentation

◆ ActivityReplanningMap()

org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap.ActivityReplanningMap ( MobsimDataProvider  mobsimDataProvider,
EventsManager  eventsManager 
)

Definition at line 97 of file ActivityReplanningMap.java.

References org.matsim.core.api.experimental.events.EventsManager.addHandler(), and org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap.mobsimDataProvider.

97  {
98  eventsManager.addHandler(this);
99  log.info("Note that the ActivityReplanningMap has to be registered as an EventHandler and a SimulationListener!");
100 
102 
103  this.startingAgents = new HashMap<>();
104  this.activityEndTimes = new HashMap<>();
105 
106  this.activityPerformingAgents = new ConcurrentHashMap<>();
107  }
final Map< Integer, Map< Id< Person >, MobsimAgent > > activityPerformingAgents
Here is the call graph for this function:

Member Function Documentation

◆ notifyMobsimInitialized()

void org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap.notifyMobsimInitialized ( MobsimInitializedEvent  e)

Implements org.matsim.core.mobsim.framework.listeners.MobsimInitializedListener.

Definition at line 114 of file ActivityReplanningMap.java.

References org.matsim.withinday.mobsim.MobsimDataProvider.getAgents(), org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap.getMapForTimeBin(), org.matsim.core.mobsim.framework.MobsimTimer.getSimStartTime(), and org.matsim.core.mobsim.framework.MobsimTimer.getSimTimestepSize().

114  {
115 
116  MobsimTimer mobsimTimer = ((QSim) e.getQueueSimulation()).getSimTimer();
117  this.simStartTime = mobsimTimer.getSimStartTime();
118  this.timeStepSize = mobsimTimer.getSimTimestepSize();
119 
120  this.activityPerformingAgents.clear();
121 
122  for (MobsimAgent mobsimAgent : this.mobsimDataProvider.getAgents().values()) {
123 
124  // get the agent's activity end time and mark it as currently performing an Activity
125  double activityEndTime = mobsimAgent.getActivityEndTime();
126 
127  // add the agent to the collections
128  this.activityEndTimes.put(mobsimAgent.getId(), activityEndTime);
129 
130  int bin = this.getTimeBin(activityEndTime);
131  Map<Id<Person>, MobsimAgent> map = getMapForTimeBin(bin);
132  map.put(mobsimAgent.getId(), mobsimAgent);
133  }
134 
135  }
final Map< Id< Person >, MobsimAgent > getAgents()
final Map< Integer, Map< Id< Person >, MobsimAgent > > activityPerformingAgents
Here is the call graph for this function:

◆ notifyMobsimAfterSimStep()

void org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap.notifyMobsimAfterSimStep ( MobsimAfterSimStepEvent  e)

Implements org.matsim.core.mobsim.framework.listeners.MobsimAfterSimStepListener.

Definition at line 144 of file ActivityReplanningMap.java.

References org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap.getMapForTimeBin(), and org.matsim.core.mobsim.framework.events.MobsimAfterSimStepEvent< T extends Mobsim >.getSimulationTime().

144  {
145 
146  double now = e.getSimulationTime();
147  for (MobsimAgent mobsimAgent : startingAgents.values()) {
148 
149  double departureTime = mobsimAgent.getActivityEndTime();
150 
151  /*
152  * If it is the last scheduled Activity the departureTime is -infinity.
153  * Otherwise we select the agent for a replanning.
154  */
155  if (departureTime >= now) {
156  this.activityEndTimes.put(mobsimAgent.getId(), departureTime);
157  int bin = this.getTimeBin(mobsimAgent.getActivityEndTime());
158  Map<Id<Person>, MobsimAgent> map = getMapForTimeBin(bin);
159  map.put(mobsimAgent.getId(), mobsimAgent);
160  } else {
161  log.warn("Departure time is in the past - ignoring activity!");
162  }
163  }
164  this.startingAgents.clear();
165 
166  /*
167  * Remove current time bin from activityPerformingAgents map. They have been handled
168  * in the current time step.
169  */
170  this.activityPerformingAgents.remove(this.getTimeBin(now));
171  }
final Map< Integer, Map< Id< Person >, MobsimAgent > > activityPerformingAgents
Here is the call graph for this function:

◆ getMapForTimeBin()

Map<Id<Person>, MobsimAgent> org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap.getMapForTimeBin ( int  bin)
private

◆ handleEvent() [1/4]

void org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap.handleEvent ( ActivityStartEvent  event)

Implements org.matsim.api.core.v01.events.handler.ActivityStartEventHandler.

Definition at line 214 of file ActivityReplanningMap.java.

References org.matsim.withinday.mobsim.MobsimDataProvider.getAgent().

214  {
215  Id<Person> agentId = event.getPersonId();
216  this.startingAgents.put(agentId, this.mobsimDataProvider.getAgent(agentId));
217  }
final MobsimAgent getAgent(Id< Person > agentId)
Here is the call graph for this function:

◆ handleEvent() [2/4]

void org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap.handleEvent ( ActivityEndEvent  event)

Implements org.matsim.api.core.v01.events.handler.ActivityEndEventHandler.

Definition at line 224 of file ActivityReplanningMap.java.

References org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap.getMapForTimeBin().

224  {
225  Id<Person> agentId = event.getPersonId();
226  this.startingAgents.remove(agentId);
227 
228  Double activityEndTime = this.activityEndTimes.remove(agentId);
229  if (activityEndTime != null) {
230  Map<Id<Person>, MobsimAgent> map;
231  // remove
232  map = this.getMapForTimeBin(this.getTimeBin(activityEndTime));
233  map.remove(agentId);
234  }
235  }
Here is the call graph for this function:

◆ handleEvent() [3/4]

void org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap.handleEvent ( PersonStuckEvent  event)

◆ handleEvent() [4/4]

void org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap.handleEvent ( ReplanningEvent  event)

Implements org.matsim.withinday.events.handler.ReplanningEventHandler.

Definition at line 246 of file ActivityReplanningMap.java.

References org.matsim.core.mobsim.framework.MobsimAgent.getActivityEndTime(), org.matsim.withinday.mobsim.MobsimDataProvider.getAgent(), org.matsim.api.core.v01.Identifiable< T >.getId(), org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap.getMapForTimeBin(), and org.matsim.withinday.events.ReplanningEvent.getPersonId().

246  {
247 
248  // check whether the agent is performing an activity
249  Double activityEndTime = this.activityEndTimes.get(event.getPersonId());
250  if (activityEndTime != null) {
251 
252  // check whether the agent has changed its planned departure time
253  MobsimAgent agent = this.mobsimDataProvider.getAgent(event.getPersonId());
254  if (activityEndTime != agent.getActivityEndTime()) {
255  // Update the agent's activity end time.
256  this.activityEndTimes.put(agent.getId(), agent.getActivityEndTime());
257 
258  // Update the activity performing agents map. To do so, remove old entry and add new one.
259  Map<Id<Person>, MobsimAgent> map;
260  // remove
261  map = this.getMapForTimeBin(this.getTimeBin(activityEndTime));
262  map.remove(agent.getId());
263 
264  // add
265  map = this.getMapForTimeBin(this.getTimeBin(agent.getActivityEndTime()));
266  map.put(agent.getId(), agent);
267  }
268  }
269  }
final MobsimAgent getAgent(Id< Person > agentId)
Here is the call graph for this function:

◆ getActivityPerformingAgents()

Set<Id<Person> > org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap.getActivityPerformingAgents ( )

Returns a set containing the Ids of all agents that are currently performing an activity.

Definition at line 274 of file ActivityReplanningMap.java.

Referenced by org.matsim.withinday.replanning.identifiers.ActivityPerformingIdentifier.getAgentsToReplan().

274  {
275  return Collections.unmodifiableSet(this.activityEndTimes.keySet());
276  }

◆ getActivityEndingAgents()

Collection<MobsimAgent> org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap.getActivityEndingAgents ( double  time)

Returns a Collection containing all agents that are going to end their activity in the time step belongs to the given time. Typically, this is the current simulation time. For times in the past an empty set is returned. Since in data structure in the background the MobsimAgents are available, we return them instead of only their Ids as the getActivityPerformingAgents() method does.

Definition at line 285 of file ActivityReplanningMap.java.

References org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap.getMapForTimeBin().

Referenced by org.matsim.withinday.replanning.identifiers.ActivityEndIdentifier.getAgentsToReplan().

285  {
286  return Collections.unmodifiableCollection(this.getMapForTimeBin(this.getTimeBin(time)).values());
287  }
Here is the call graph for this function:

◆ reset()

void org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap.reset ( int  iteration)

Gives the event handler the possibility to clean up its internal state. Within a Controler-Simulation, this is called before the mobsim starts.

Parameters
iterationthe up-coming iteration from which up-coming events will be from.

Implements org.matsim.core.events.handler.EventHandler.

Definition at line 290 of file ActivityReplanningMap.java.

290  {
291  this.startingAgents.clear();
292  this.activityEndTimes.clear();
293  }

Member Data Documentation

◆ log

final Logger org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap.log = LogManager.getLogger(ActivityReplanningMap.class)
staticprivate

Definition at line 64 of file ActivityReplanningMap.java.

◆ mobsimDataProvider

final MobsimDataProvider org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap.mobsimDataProvider
private

◆ startingAgents

final Map<Id<Person>, MobsimAgent> org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap.startingAgents
private

Definition at line 76 of file ActivityReplanningMap.java.

◆ activityEndTimes

final Map<Id<Person>, Double> org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap.activityEndTimes
private

Definition at line 84 of file ActivityReplanningMap.java.

◆ activityPerformingAgents

final Map<Integer, Map<Id<Person>, MobsimAgent> > org.matsim.withinday.replanning.identifiers.tools.ActivityReplanningMap.activityPerformingAgents
private

Definition at line 90 of file ActivityReplanningMap.java.


The documentation for this class was generated from the following file: