Skip to content

faq 30998530

Billy Charlton edited this page Sep 5, 2018 · 2 revisions

How otfvis detect the waiting or delayed agents? There is a way to compute the stops and how long it takes?

by Kai Nagel on 2015-07-08 06:44:10


On 08 Jul 2015, at 05:29, Rolando Armas <rolandoarmas@gmail.com> wrote:
Hi matsim users!

I am working with scenarios to test different traffic lights settings.
I would like to know, if it is possible, the number of stops per agent and how long it takes on each stop when agent is waiting in an specific intersection.

Otfvis can detect when agent is waiting or is delayed by traffic turning the agent to red. 
My questions are:

How otfvis detect the waiting or delayed agents? 
There is a way to compute the stops and how long it takes?

Please if you could help me with this questions I will appreciate.

Thanks !


Roland.

Comments: 1


Re: How otfvis detect the waiting or delayed agents? There is a way to compute the stops and how long it takes?

by Kai Nagel on 2015-07-08 06:48:46

Dear Roland,

Nothing "official".  otfvis uses 

 

public double calcSpeedValueBetweenZeroAndOne(QVehicle veh, double inverseSimulatedFlowCapacity, double now, double freespeed){
 		int cmp = (int) (veh.getEarliestLinkExitTime() + inverseSimulatedFlowCapacity + 2.0);
 		// "inverseSimulatedFlowCapacity" is there to keep vehicles green that only wait for capacity (i.e. have no vehicle
 		// ahead). Especially important with small samples sizes.  This is debatable :-).  kai, jan'11
		

 		double speed = (now > cmp ? 0.0 : 1.0);
 		return speed;
 	}

 

in AbstractAgentSnapshotInfoBuilderI just made that function static so it can be used without even instantiating the class but you will need the svn HEAD or the next nightly build.
However, under normal circumstances you will not have access to the "veh", and even if you get such access, it will not be officially supported and thus possibly break with future releases.  In consequence, I would recommend to re-write the above functionality based on events.  Something like

 

public class CongestionDetectionEventHandler implements LinkEnterEventHandler,
     LinkLeaveEventHandler, PersonDepartureEventHandler{
 	private Map<Id<Vehicle>,Double> earliestLinkExitTime = new HashMap<>() ;
 	private Network network;
 	public CongestionDetectionEventHandler( Network network ) {
 		this.network = network ;
 	}
 	@Override
 	public void reset(int iteration) {
 		this.earliestLinkExitTime.clear(); 
 	}
 	@Override
 	public void handleEvent(LinkEnterEvent event) {
 		Link link = network.getLinks().get( event.getLinkId() ) ;
 		double linkTravelTime = link.getFreespeed( event.getTime() ) / link.getLength() ; 
 		this.earliestLinkExitTime.put( event.getVehicleId(), event.getTime() + linkTravelTime ) ;
 	}
 	@Override
 	public void handleEvent(LinkLeaveEvent event) {
 		double excessTravelTime = event.getTime() - this.earliestLinkExitTime.get( event.getVehicleId() ) ; 
 		System.out.println( "excess travel time: " + excessTravelTime ) ;
 	}
 	@Override
 	public void handleEvent(PersonDepartureEvent event) {
 		Id<Vehicle> vehId = Id.create( event.getPersonId(), Vehicle.class ) ; // unfortunately necessary since vehicle departures are not uniformly registered
 		this.earliestLinkExitTime.put( vehId, event.getTime() ) ;
 	}
 }


 

(see http://matsim.org/javadoc → main distribution → RunEventsHandlingWithControlerExample for reference to a compiling version of the above; available after next automatic build).

Clone this wiki locally