Reputation: 2525
I have a model built on the Road Transport Library and I have cars on the highway that take an exit. Since the speed on the actual highway is 70mph and on the exit road is 40mph, I want to reduce the speed of the cars on the the exit from 70mph to 40mph.
Setup
I have a cars
population that is built on a custom agent Car
.
The carSource
has an initialSpeed
and preferredSpeed
of 70mph. The carSource
is paired with a binary selectOutput
with a probability of 40% taking the exit followed by two moveTo
nodes, one for the exit and the other to go on straight the highway.
I assumed that we can change the speed of the car agent in the moveTo
node (to the exit) by specifying the onEnter
action as car.setPreferredSpeed(18);
(because 40mph is 18 meters per second). However, this doesn't seem to effect the speed of the cars on the exit (when I eyeball it in the simulation). Also, the amount of time spent in the model also doesn't change.
Any suggestions on how to change the speed of agent that moveTo
the exit road?
Upvotes: 0
Views: 729
Reputation: 224
You've developed your model correctly. But using Road traffic library, you should consider some points:
In road traffic library, speed of cars change gradually and based on car's current speed, preferred speed, max and min acceleration and also road configuration and traffic condition. So when you set car's preferred speed as 40 MPH, based on its deceleration rate (by default 4.2 mps2) and its current speed (probably 70 MPH) it takes some time to reduce the speed, and it doesn't happen rapidly. In order to sense reduced speed of cars, you can do one of the followings: a) increase length of the road on which cars appear in carSorce
such that cars have more time to reduce their speed before reaching the exit. b) increase car's deceleration.
You can use setPreferredSpeed(40, SpeedUnits.MPH)
without changing speed unit to MPS
P.S.: In order to make sure that there is no problem in your modeling, as a test, set car's preferred speed to 0 in onEnter
section of moveTo
, and check whether or not they stop after a while.
Upvotes: 2