Transportation

No preview image

5 collaborators

Uri_dolphin3 Uri Wilensky (Author)
Default-person Matthew Berland (Author)
Josh3 Josh Unterman (Author)
Image001 Sharona T Levy (Author)
Dor Abrahamson (Author)

Tags

cars 

Tagged by Reuven M. Lerner about 6 years ago

hubnet 

Tagged by Reuven M. Lerner about 6 years ago

trains 

Tagged by Reuven M. Lerner about 6 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 4.0pre8 • Viewed 987 times • Downloaded 65 times • Run 1 time
Download the 'Transportation' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


VERSION

$Id: Transportation.nlogo 37529 2008-01-03 20:38:02Z craig $

WHAT IS IT?

This is a model for Computer HubNet, which simulates traffic and the public policy decisions (and the ramifications of those decisions) that can result from trying to regulate that traffic.

Each participant is a citizen in a small city with one single-lane highway

(taken from the "traffic basic" model) and a train. The train runs at constant speed, set with the TRAIN-SPEED slider. The cars travel as quickly as they can, but will slow down to avoid collisions with cars in front of them. As more cars get onto the highway, the traffic jams become increasingly large and frustrating.

City residents can try to remedy the situation by charging different amounts of money for drivers and rail passengers. How much must they charge in order to reduce traffic to a normal flow, such that driving is faster than taking the train? When this happens, will the city earn more revenue from the train, or from the cars? And how will all of this affect the city's residents, who may not be able to afford driving or the train?

HOW TO USE IT

When the model loads, it will ask you to enter the name by which the model will be known on the network. Enter your name (as it suggests), or perhaps something more descriptive, such as "transportation." Once you have done this, click on the "setup" button. Each participant should then run the "HubNet client" program on their own computer, connecting to the server that you named.

Warning: Clicking on "setup" removes the participants from the system, and forces them to re-connect.

THINGS TO NOTICE

- What is the capacity of the road vs. the train?

- What is the correlation (if any) between the city's income and traffic on the roads?

- Is the city's interest always the same as the individual's interest? Where are they the same? Where are they different? How do the citizens react when faced with such dilemmas?

THINGS TO TRY

- Does the city make more money from cars, or from the train? What settings for car and rail fare will maximize the city's income?

- Make the robots switch modes of transportation based on an algorithm

EXTENDING THE MODEL

- Add a "welfare" option; when someone cannot afford to take the train or drive, they should receive a subsidy from the collected taxes.

- The current model assigns a salary to each individual. But there's no way for people's salaries to rise or fall. Allow individuals to invest some of their money for a potential payoff. Perhaps there could be two kinds of investments, education (where you spend a lot over a long time, and see an increase in your salary) and stocks (where you invest any amount of money over any amount of time, and see a random return in your holdings, but not your salary.

- Add a second highway with a separate (and different) cost. How does this affect traffic? How does this affect the city's income?

- Make the robots intelligent, allowing them to move between driving and the train (like people do). What rules should the robots follow? When should they take the train? When should they drive?

NETLOGO FEATURES

Lots of Computer HubNet stuff

RELATED MODELS

"Traffic basic" (which comes with NetLogo)

CREDITS AND REFERENCES

??? What should I put here ???

Thanks to the following people for help and support: Uri Wilensky, Matthew Berland, Josh Unterman, Sharona Halevy, Dor Abrahamson. (The order of the preceding list of names has nothing whatsoever to do with

TO DO

- Don't use maps as an example in the curriculum

- Make the train stops (and wait-per-stop) adjustable

- Add a more useful info tab

- Can we reduce the information load further?

- Different background color for bankruptcies?

- ptext and ptextcolor for labeling the highway and railway?

- Ask kids to interview their parents about why they travel in a

certain way

- Reduce the information load on the graphs

- Stack the graphs vertically, so that they line up

- Make the clear/setup buttons closer to the HubNet standard, with a

warning if you try to setup with people attached.

- Background colors for the road

- Make train-speed an integer in the slider

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

globals [ road-row rails-row bankrupt-row-max bankrupt-row-min shape-names colors used-shape-colors max-possible-codes
          road-money-collected rail-money-collected driver-speed-up driver-slow-down road-color rails-color]
breed [ drivers driver ]
breed [ rail-passengers rail-passenger ]
breed [ bankruptcies bankruptcy ]
turtles-own [ speed speed-limit speed-min user-id money salary color-name]

; ------------------------------------------------------
; Overall setup
; ------------------------------------------------------

to startup
  hubnet-set-client-interface "COMPUTER" []
  hubnet-reset
end 

to setup
  set road-row 0
  set rails-row -5
  set bankrupt-row-min 5
  set bankrupt-row-max 6
  set road-color violet
  set rails-color red
  ;; The following two variables are taken from the traffic-basic model,
  ;; where they are sliders available for user modification.  Since traffic
  ;; in this model is affected much more dramatically by cars entering
  ;; the highway, I removed these from the GUI in the interest of cleaning
  ;; things up.
  set driver-speed-up 100
  set driver-slow-down 100
  set used-shape-colors []
  set shape-names ["wide wedge" "square" "car" "big boat" "pickup truck"
                   "nu" "uu" "circle" "butterfly" "sheep" "lobster" "monster"
                   "moose" "bear" "teddy bear"]
  set colors      [ gray   brown   green   lime   turquoise
                    cyan   sky   blue   violet ]
  set colors remove road-color colors
  set colors remove rails-color colors
  set max-possible-codes (length colors * length shape-names)
  ask patches [ setup-road ]
  setup-car-robots
  ask patches [ setup-rails ]
  setup-rail-robots
  ; Get rid of bankrupt robots
  ask bankruptcies with [user-id = 0] [die]
  ; Bankrupt users some money again
  ask bankruptcies with [user-id != 0] [ driver-to-onramp ]
  ask turtles [
       set money int random-normal initial-money-mean initial-money-sd
       set salary int random-normal individual-salary-mean individual-salary-sd
       if salary < 0 [ set salary 0 ]
      ]
  set-current-plot "Wealth distribution"
  histogram [ money ] of turtles
end 

to setup-road
  if ( pycor = road-row ) [ set pcolor road-color ]
end 

to setup-rails
  if ( pycor = rails-row ) [ set pcolor rails-color ]
end 
;; pick a shape and color for the turtle

to set-unique-shape-and-color
  let code 0

  set code random max-possible-codes
  while [member? code used-shape-colors and ((count drivers + count rail-passengers) < max-possible-codes)]
  [
    set code random max-possible-codes
  ]
  set used-shape-colors (lput code used-shape-colors)
  set shape item (code mod length shape-names) shape-names
  set color item (code / length shape-names) colors
  if color = gray [set color-name "gray"]
  if color = brown [set color-name "brown"]
  if color = yellow [set color-name "yellow"]
  if color = green [set color-name "green"]
  if color = lime [set color-name "lime"]
  if color = turquoise [set color-name "turquoise"]
  if color = cyan [set color-name "cyan"]
  if color = sky [set color-name "sky"]
  if color = blue [set color-name "blue"]
  if color = violet [set color-name "violet"]
end 
; ------------------------------------------------------
; Set up drivers (cars)
; ------------------------------------------------------

to setup-car-robots
  if ( initial-car-robots > world-width )
  [
    user-message (word "There are too many drivers for the amount of road.  Please decrease the INITIAL-CAR-ROBOTS slider to below " (world-width + 1) " and press the SETUP button again.  The setup has stopped.")
    stop
  ]
  ; Get rid of existing car-robots
  ask drivers with [user-id = 0] [die]
  create-drivers initial-car-robots [
    setup-generic-robot
    set ycor road-row
    separate-drivers
  ]
end 
; this function is needed so when we click "Setup" we
; don't end up with any two drivers on the same patch

to separate-drivers  ; turtle procedure
  if any? other drivers-here
    [ fd 1
      separate-drivers ]
end 

; this function is needed so when we click "Setup" we
; don't end up with any two drivers on the same patch

to separate-bankruptcies  ; turtle procedure
  if any? other bankruptcies-here
    [ set heading 90
      fd random 5
      separate-bankruptcies
    ]
end 

to setup-generic-robot
    set xcor random-float world-width
    set heading 90
    set speed  0.1 + random 9.9
    set speed-limit  1
    set speed-min  0
    set salary int random-normal individual-salary-mean individual-salary-sd
    if salary < 0 [ set salary 0 ]
end 

; ------------------------------------------------------
; Go!
; ------------------------------------------------------

to go
  let old-shape 0
  move-cars
  move-train
  ;; ---------------------------------------
  ;; Check for bankruptcies
  ask turtles with [ money <= 0 and (ycor = road-row or ycor = rails-row) ]
   [
     set old-shape shape
     set breed bankruptcies
     set shape old-shape
     set ycor bankrupt-row-min + random (bankrupt-row-max - bankrupt-row-min + 1)
     set speed 0
     set money 0
     separate-bankruptcies ]
  ;; Pay a salary to everyone on the right side of the screen
  ask turtles with [ xcor + speed > (max-pxcor + 0.5) ]
   [ set money money + salary ]
  set-current-plot "Wealth distribution"
  histogram [ money ] of turtles
  ;; ---------------------------------------------
  while [hubnet-message-waiting?]
  [
    hubnet-fetch-message
    ifelse hubnet-enter-message?
    [ create-entering-driver ]
    [
      ifelse hubnet-exit-message?
      [
        ask turtles with [user-id = hubnet-message-source] [ die ]
      ]
      [
        if hubnet-message-tag = "method-of-transportation"
        [
          if hubnet-message = "Drive"
          [ rail-passenger-becomes-driver hubnet-message-source]
          if hubnet-message = "Take the train"
          [ driver-becomes-rail-passenger hubnet-message-source]
        ]
      ]
    ]
  ]
  tick
  ;; Send info to the client window
  hubnet-broadcast "View" "View"
  hubnet-broadcast "Cost to drive" driver-cost
  hubnet-broadcast "Cost of train" train-cost
  ask turtles with [ user-id != 0 ]
   [
    hubnet-send user-id "Your savings" money
    hubnet-send user-id "Your salary" salary
    ifelse breed = bankruptcies
      [ hubnet-send user-id "You are a" (word "bankrupt " color-name " " shape) ]
      [ hubnet-send user-id "You are a" (word color-name " " shape) ]
   ]
  if ticks mod plot-frequency = 0 and any? drivers
  [ set-current-plot "Commuters"
    set-current-plot-pen "Bankruptcies"
    plot count bankruptcies
  ]
end 

;; Client Message Processing Procedures

to listen-clients
end 

to create-entering-driver
    create-drivers 1 [driver-to-onramp
                             set user-id hubnet-message-source
                             set-unique-shape-and-color
                             set money int random-normal initial-money-mean initial-money-sd
                             set salary int random-normal individual-salary-mean individual-salary-sd
                             if salary < 0 [ set salary 0 ]
                             ]
end 

to move-cars
  ;; Drivers have two possible headings, 90 (on the road) and 180 (waiting to get
  ;; on the road).  If you're on the road, then try to move forward.  If you're
  ;; waiting to get on the road, then you have to wait for an opening.
  ask drivers [
    ifelse (heading = 90)
     ;; If heading is 90, then we are driving.  Set the car's
     ;; speed according to the car ahead of it, speeding up if no
     ;; one is there (and slowing down to match the car's speed
     ;; if someone is there).
     [ifelse any? drivers-at 1 0
       [ set speed ([speed] of one-of drivers-at 1 0)
         slow-down-driver ]
       [ speed-up-driver ]
       if speed < speed-min  [ set speed speed-min ]
       if speed > speed-limit   [ set speed speed-limit ]
       fd speed
       ;; Charge everyone at the right side of the screen
       if xcor + speed > (max-pxcor + 0.5)
         [ set money money - driver-cost
           set road-money-collected road-money-collected + driver-cost
           ]
       ]
     ;; If heading is not 90, then it is presumably
     ;; 180, which means that it is waiting to enter the road.
     ;; If there are no cars at the entry point, then
     ;; everyone moves forward, and the bottommost turtle
     ;; turns to have a heading of 90, like other cars on the road
     [if (not any? drivers-at 0 -1)
      [fd 1
       lt 90]
      ]
     ]
  plot-drivers
end 

to move-train
  ask rail-passengers
  [ set speed (train-speed / 10)
    fd speed
    ;; Charge everyone at the right side of the screen
    if xcor + speed > (max-pxcor + 0.5)
     [ set money money - train-cost
       set rail-money-collected rail-money-collected + train-cost ]
   ]
  plot-rail-passengers
end 

to slow-down-driver
  set speed speed - ( driver-slow-down / 1000 )
end 

to speed-up-driver
  set speed ( speed + ( driver-speed-up / 10000 ) )
end 

to plot-drivers
  if ticks mod plot-frequency = 0 and any? drivers
    [
      set-current-plot "Commuter Speed"
      set-current-plot-pen "Max Driver Speed"
      plot (10 * (max [speed] of drivers))
      set-current-plot-pen "Average Driver Speed"
      plot (10 * (mean [speed] of drivers))
      set-current-plot "Commuters"
      set-current-plot-pen "Drivers"
      plot count drivers
      set-current-plot "Money collected"
      set-current-plot-pen "Cars"
      plot road-money-collected
  ]
end 

to add-car-robot
  ifelse (count drivers >= ( 2 * world-width))
    [ user-message "You have reached the max number of drivers"]
    [ create-drivers 1 [
        set money int random-normal initial-money-mean initial-money-sd
        set salary int random-normal individual-salary-mean individual-salary-sd
        if salary < 0 [set salary 0]
        driver-to-onramp
        ]
  ]
end 

to driver-to-onramp  ;; turtle procedure
  let old-shape 0
  set old-shape shape
  set breed drivers
  set shape old-shape
  set heading 90
  set xcor (min-pxcor)
  set ycor 1
  set speed 0
  set speed-limit 1
  set speed-min 0
  separate-drivers
  rt 90
end 
; ------------------------------------------------------
; Set up the rail-passengers
; ------------------------------------------------------

to setup-rail-robots
  if ( initial-rail-robots > world-width )
  [
    user-message (word "There are too many rail-passengers for the amount of road.  Please decrease the INITIAL-RAIL-ROBOTS slider to below " (world-width + 1) " and press the SETUP button again.  The setup has stopped.")
    stop
  ]
  ; Get rid of existing rail-robots
  ask rail-passengers with [user-id = 0] [die]
  create-rail-passengers initial-rail-robots [
    setup-generic-robot
    set ycor rails-row
    separate-rail-passengers
  ]
end 
; this function is needed so when we click "Setup" we
; don't end up with any two drivers on the same patch

to separate-rail-passengers  ; turtle procedure
  if any? other rail-passengers-here
    [ fd 1
      separate-rail-passengers ]
end 

to add-rail-robot
  ifelse (count rail-passengers >= world-width)
  [ user-message "You have reached the max number of rail-passengers"]
  [ create-rail-passengers 1 [
     set xcor (min-pxcor)
     set ycor rails-row
     set heading 90
     ;; We don't really care about these variables
     set speed 0
     set speed-limit  1
     set speed-min  0
     separate-rail-passengers
   ]
   ]
end 

to plot-rail-passengers
  if ticks mod plot-frequency = 0 and any? rail-passengers
  [ set-current-plot "Commuter Speed"
    set-current-plot-pen "Train Speed"
    plot train-speed
    set-current-plot "Commuters"
    set-current-plot-pen "Rail Passengers"
    plot count rail-passengers
    set-current-plot "Money collected"
    set-current-plot-pen "Train"
    plot rail-money-collected
   ]
end 
; ------------------------------------------------------
; Get rid of a robot driver
; ------------------------------------------------------

to remove-one-car-robot
  let car-robots 0
  set car-robots drivers with [user-id = 0]
  if (any? car-robots)
    [ ask one-of car-robots [ die ] ]
end 

to remove-one-rail-robot
  let rail-robots 0
  set rail-robots rail-passengers with [user-id = 0]
  if (any? rail-robots)
    [ ask one-of rail-robots [ die ] ]
end 
; ------------------------------------------------------
; Allow people to switch
; ------------------------------------------------------

to driver-becomes-rail-passenger [target-user-id]
     let old-shape 0
     ask drivers
     [ if user-id = target-user-id
      [ set old-shape shape
        set breed rail-passengers
        set shape old-shape
        set ycor rails-row
        set heading 90
        separate-rail-passengers
       ]
     ]
end 

to car-robot-to-rail-robot
  let car-robots 0
  let old-shape 0

  set car-robots drivers with [user-id = 0]
  ; Choose a random driver
  if (any? car-robots)
    [ ask one-of car-robots
     [
       set old-shape shape
       set breed rail-passengers
       set shape old-shape
       set ycor rails-row
       set heading 90
       separate-rail-passengers
     ]
    ]
end 

to rail-passenger-becomes-driver [target-user-id]
    ask rail-passengers
      [ if user-id = target-user-id [ driver-to-onramp ] ]
end 

to rail-robot-to-car-robot
  let rail-robots 0
  set rail-robots rail-passengers with [user-id = 0]
  ; Choose a random rail-robot
  if (any? rail-robots)
    [ ask one-of rail-robots
     [ driver-to-onramp]
    ]
end 

There are 2 versions of this model.

Uploaded by When Description Download
Uri Wilensky almost 9 years ago Transportation Download this version
Uri Wilensky almost 9 years ago Transportation Download this version

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.