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