001/* *********************************************************************** * 002 * project: org.matsim.* 003 * ActivityStartingFilter.java 004 * * 005 * *********************************************************************** * 006 * * 007 * copyright : (C) 2013 by the members listed in the COPYING, * 008 * LICENSE and WARRANTY file. * 009 * email : info at matsim dot org * 010 * * 011 * *********************************************************************** * 012 * * 013 * This program is free software; you can redistribute it and/or modify * 014 * it under the terms of the GNU General Public License as published by * 015 * the Free Software Foundation; either version 2 of the License, or * 016 * (at your option) any later version. * 017 * See also COPYING, LICENSE and WARRANTY file * 018 * * 019 * *********************************************************************** */ 020 021package org.matsim.withinday.replanning.identifiers.filter; 022 023import java.util.Iterator; 024import java.util.Map; 025import java.util.Set; 026 027import org.matsim.api.core.v01.Id; 028import org.matsim.api.core.v01.network.Link; 029import org.matsim.api.core.v01.population.Person; 030import org.matsim.core.mobsim.framework.DriverAgent; 031import org.matsim.core.mobsim.framework.MobsimAgent; 032import org.matsim.withinday.replanning.identifiers.interfaces.AgentFilter; 033 034/** 035 * Remove all agents from the set that are going to start an activity on 036 * their current link. 037 * 038 * @author cdobler 039 */ 040public class ActivityStartingFilter implements AgentFilter { 041 042 private final Map<Id<Person>, MobsimAgent> agents; 043 044 // use the factory 045 /*package*/ ActivityStartingFilter(Map<Id<Person>, MobsimAgent> agents) { 046 this.agents = agents; 047 } 048 049 @Override 050 public void applyAgentFilter(Set<Id<Person>> set, double time) { 051 Iterator<Id<Person>> iter = set.iterator(); 052 053 while (iter.hasNext()) { 054 Id<Person> id = iter.next(); 055 056 if (!this.applyAgentFilter(id, time)) iter.remove(); 057 } 058 } 059 060 @Override 061 public boolean applyAgentFilter(Id<Person> id, double time) { 062 MobsimAgent agent = this.agents.get(id); 063 // check whether the agent is performing a leg 064 if (!(agent.getState() == MobsimAgent.State.LEG)) return false; 065 066 /* 067 * Check whether the agent ends its leg on the current link. If 068 * yes, remove the agent from the set. 069 */ 070 DriverAgent driver = (DriverAgent) agent; 071// Id<Link> nextLinkId = driver.chooseNextLinkId(); 072// if (nextLinkId == null) return false; 073 if ( driver.isWantingToArriveOnCurrentLink() ) return false ; 074 075 return true; 076 } 077 078}