0

I am modeling people commuting using different transportation methods: walking, biking, and driving. I use nw:path-to to find the shortest path between their home and work and then move them along the path until they reach their goal. This works fine for people walking as they move one link in the path per tick, but cars and bikes should be able to travel faster than pedestrians.

I don't use fd 1 for this because they're not always going in one direction.

I tried to simulate this by repeating the movement procedure twice per tick for bikes and four times per tick for cars, expecting this would make them move twice as fast and four times as fast as pedestrians, but unfortunately, they still move at the same speed.

path-to-goal ;; list of links between the starting node and the goal destination dist-goal ;; the length of the list of links between the starting node and the goal destination mynode ;; min-one-of nodes distance from each person at the start destination ;; the goal location, which is the same for every agent actual-choice ;; what transportation method people choose (either bike, walk, or car) ] 

This is how I set the path for them to follow:

 ask people [ ask mynode [ let shortest-path-to-goal nw:path-to ndestination ask myself [ set path-to-goal shortest-path-to-goal set dist-goal length path-to-goal ] ] end 

This is how I get the people to follow the path:

to move-people ifelse length path-to-goal = 0 [ ;; If the person has reached the destination, stop moving. if distance destination < 1 [ set got_to_destination 1 print "goal reached!" ] ] [ let current item 0 path-to-goal let new-location 0 ;; Determine the next location based on the current road segment ifelse ([end1] of current = mynode) [ set new-location [end2] of current ] [ set new-location [end1] of current ] ;; Move the person to the new location move-to new-location set mynode new-location ;; Remove the current node from the path set path-to-goal remove-item 0 path-to-goal ;; Recalculate the path from the new location to the destination set path-to-goal nw:path-to destination if path-to-goal = false [ set path-to-goal [] ] ] end 

This is my attempt to ask the people to move at different speeds:

to move-to-work ask people [ if actual-choice = "walk" [ move-people ] if actual-choice = "bike" [ set shape "bike" set size 4 repeat 2;;bike_speed [ move-people ] ] if actual-choice = "car" [ set shape "car" set size 4 repeat 4;;car_speed [ move-people ] ] ] end 

2 Answers 2

1

The current approach where your turtles move-to the next node in your network is 'unitless'- the turtles are able to jump from one node to the next with no regard for distance. That can work, depending on your need, but here is an alternative that uses patch distance to allow for speed differences.

extensions [nw] breed [locations location] breed [movers mover] movers-own [ speed-class speed homeplace nodes-to-goal links-to-goal ] to setup ca ask patches with [pxcor mod 5 = 0 and pycor mod 5 = 0] [ sprout-locations 1 [ set shape "circle" set color 65 set size 1.5 ] ] ask locations [ let nearby-locs other locations in-radius 5 create-links-with nearby-locs ] ask n-of 5 locations [ hatch 1 [ set breed movers set color 15 + ( random 10 ) * 10 pd set pen-size 5 set speed-class one-of [ "bike" "walk" ] set shape ifelse-value speed-class = "bike" ["wheel"] ["person"] set speed ifelse-value speed-class = "bike" [4] [1] set size 1 set homeplace one-of other locations ask homeplace [ set label myself set label-color 68] set nodes-to-goal [nw:turtles-on-path-to [homeplace] of myself] of one-of locations-here ] ] ; This is just for visualization to remove the other nodes let non-nodes remove-duplicates reduce sentence [nodes-to-goal] of movers ask locations with [ not member? self non-nodes ] [ die ] reset-ticks end to go if not any? movers with [ length nodes-to-goal > 0 ] [ stop ] ask movers [ ; If there are nodes yet to travel towards if length nodes-to-goal > 0 [ ; If distance is NOT greater than speed, move to the target ; and then potentially move the remainder of speed towards the next target. ; Repeat this as needed until no speed remains let remain-speed speed while [remain-speed > 0 and (length nodes-to-goal) > 0] [ let cur-targ item 0 nodes-to-goal let cur-dist distance cur-targ face cur-targ if-else cur-dist > speed [ fd speed set remain-speed remain-speed - speed ] [ move-to cur-targ set remain-speed remain-speed - cur-dist set nodes-to-goal but-first nodes-to-goal ] ] ] ] tick end 
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, thank you! This is perfect for varying the speed.
0

Newbie here but maybe create different turtles so that they can follow a + 1 or + 2 for how many patches they are allowed to move per tick?

4 Comments

Thanks, but I'm not really sure how to do that? I know that I can change speed by doing fd 1 or fd 2, but I don't know that it works with move-to
one way or another there needs to be a way to differentiate how much the different types of turtles need to move. you could change how often people, bikes, and cars can move by ticks. i.e. cars move every tick, bikes move every other tick, and people move every 4th tick?
I can try that! how do you suggest I code that in?
i dont really know myself but here is a link to an example that might be helpful: stackoverflow.com/questions/19993631/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.