[starlogo-users] Traffic simulation question
Gordon McDonough
Gordo at hubwest.com
Mon Aug 9 20:52:22 EDT 2004
Pablo,
I would try placing a patch (with a slightly different color,
or addressed through its x and y coordinates) where you want the
cars to start and in Observer code, ask-patches [if . . .
[sprout[]]] my cars. If you need to give each car a number, try
creating a global variable that is incremented at each sprout
and then assigned to the sprouted turtle's variable.
I am sure someone else knows a more elegant way, but that is
one of the beauties of StarLogo!
Gordon
"Pablo E. Coll" wrote:
>
> Dear Starlogoers,
> I am new using Star Logo.
> I am trying to simulate a single traffic lane with a
> source of uniform random vehicles in the beginning of
> the lane and a sink of vehicles on the end.
> All attempts to produce such behaviour where unsuccessful.
>
> this is part of my last code
> I create cars with frecuency aproximately 1/3
> and then put them with, this two lines, in the beginning of the lane
> seth-of lastCar 90
> setx-of lastCar -99
> But after short number of cycles something goes wrong and no more cars
> are born, or at least, no more cars cames from the beginning of the lane
>
> to go
> createCars
> ask-turtles[
> moveDemon
> collisionDemon
> radarDemon
> killCars
> ]
> end
>
> to createCars
> if (random 100) < 33 [
> create-turtles 1
> setlastCar lastCar + 1
> setc-of lastCar yellow
> seth-of lastCar 90
> setx-of lastCar -99
> setstepSize-of lastCar 1 + (0.1 * random 16)
> setspeedLimit-of lastCar 3 + random 8
> setdangerDistance-of lastCar 4
> ]
> end
>
> I will be very thankful for any advice on this question.
> If some one wants to see all my code please write me.
> Thanks in advance.
> ++Pablo;
>
> _______________________________________________
> starlogo-users mailing list
> starlogo-users at media.mit.edu
> http://education.mit.edu/mailman/listinfo/starlogo-users
--
Gordon McDonough
Santa Fe, New Mexico, USA
http://users.hubwest.com/gordo
More information about the starlogo-users
mailing list