Traffic and Alcohol

Traffic and Alcohol preview image

1 collaborator



Tagged by Diego Díaz Córdova 2 months ago


Tagged by Diego Díaz Córdova 2 months ago

Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.4.0 • Viewed 77 times • Downloaded 1 time • Run 0 times
Download the 'Traffic and Alcohol' modelDownload this modelEmbed this model

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

Info tab cannot be displayed because of an encoding error

Comments and Questions

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

Click to Run Model

globals [
  choques ; acumula cantidad de choques
;; 0.026 descaceleration
;; 0.0045 aceleration
turtles-own [
  alcohol? ;variable booleana que indica si la tortuga consumió alcohol o no

to setup
  set speed-limit 1
  set speed-min 0
  ask patches [ setup-road ]

to setup-road ;; patch procedure
  if pycor < 2 and pycor > -2 [ set pcolor white ]

to setup-cars
  if number-of-cars > world-width [
    user-message (word
      "There are too many cars for the amount of road. "
      "Please decrease the NUMBER-OF-CARS slider to below "
      (world-width + 1) " and press the SETUP button again. "
      "The setup has stopped.")

  if tortugasalcoholizadas > number-of-cars [
    user-message (word
      "Hay más autos alcoholizados que autos en el tablero. Baje la cantidad de autos alcoholizados a menor o igual que la cantidad de autos totales"

  set-default-shape turtles "car"
  create-turtles number-of-cars [
    set color blue
    set xcor random-xcor
    set heading 90
    ;; set initial speed to be in range 0.1 to 1.0
    set speed 0.01 ;;+ random-float 0.9
    set label-color red

  let posiblesalcoholizadas n-of tortugasalcoholizadas turtles
  if count posiblesalcoholizadas > 0
  ask turtles [
     if member? self posiblesalcoholizadas
       [ set alcohol? true
         set color yellow

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

to separate-cars ;; turtle procedure
  if any? other turtles-here [
    fd 1

to go
  ;; if there is a car right ahead of you, match its speed then slow down
  ask turtles
    let car-ahead one-of turtles-on patch-ahead 1
    ifelse car-ahead != nobody
        ifelse alcohol? = 0
          [set speed 0]
          [slow-down-car car-ahead]
      [ speed-up-car ] ;; otherwise, speed up
    ;; don't slow down below speed minimum or speed up beyond speed limit
    ;;si hay un auto delante y no tomó alcohol entonces frena
    ;; que pasa si hay un auto alcoholizado
    ;; si el auto está alcoholizado entonces no respeta ni la velocidad máxima ni la mínima
   if alcohol? = 0
      if speed < speed-min [ set speed speed-min ]
      if speed > speed-limit [ set speed speed-limit ]
    if speed < 0 [set speed 0]

    if (count turtles-here > 1)
      [set choques (choques + 1)
       set speed 0
       back 1

    fd speed



to slow-down-car [ car-ahead ] ;; turtle procedure
  ;; slow down so you are driving more slowly than the car ahead of you
  ;; if it is drunk it tries to drive so slowly asn the car ahead of him
  set speed [ speed ] of car-ahead - deceleration

to speed-up-car ;; turtle procedure
  ;; if it is drunk then it speed up at much more acceleration
  ifelse alcohol? = true
  [set speed speed + (acceleration * 2)]
  [set speed speed + acceleration]

; Modifed 2024 Diaz Cordova et alumni UBA
; Copyright 1997 Uri Wilensky.
; See Info tab for full copyright and license.

There is only one version of this model, created 2 months ago by Diego Díaz Córdova.

Attached files

File Type Description Last updated
Traffic and Alcohol.png preview Preview for 'Traffic and Alcohol' 2 months ago, by Diego Díaz Córdova Download

This model does not have any ancestors.

This model does not have any descendants.