MATSIM
ActivityStartingFilter.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * ActivityStartingFilter.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2013 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 
21 package org.matsim.withinday.replanning.identifiers.filter;
22 
23 import java.util.Iterator;
24 import java.util.Map;
25 import java.util.Set;
26 
27 import org.matsim.api.core.v01.Id;
32 
39 public class ActivityStartingFilter implements AgentFilter {
40 
41  private final Map<Id<Person>, MobsimAgent> agents;
42 
43  // use the factory
44  /*package*/ ActivityStartingFilter(Map<Id<Person>, MobsimAgent> agents) {
45  this.agents = agents;
46  }
47 
48  @Override
49  public void applyAgentFilter(Set<Id<Person>> set, double time) {
50  Iterator<Id<Person>> iter = set.iterator();
51 
52  while (iter.hasNext()) {
53  Id<Person> id = iter.next();
54 
55  if (!this.applyAgentFilter(id, time)) iter.remove();
56  }
57  }
58 
59  @Override
60  public boolean applyAgentFilter(Id<Person> id, double time) {
61  MobsimAgent agent = this.agents.get(id);
62  // check whether the agent is performing a leg
63  if (!(agent.getState() == MobsimAgent.State.LEG)) return false;
64 
65  /*
66  * Check whether the agent ends its leg on the current link. If
67  * yes, remove the agent from the set.
68  */
69  DriverAgent driver = (DriverAgent) agent;
70 // Id<Link> nextLinkId = driver.chooseNextLinkId();
71 // if (nextLinkId == null) return false;
72  if ( driver.isWantingToArriveOnCurrentLink() ) return false ;
73 
74  return true;
75  }
76 
77 }