Città 30
Model was written in NetLogo 6.4.0
•
Viewed 27 times
•
Downloaded 3 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
breed [cars car] breed [intersections intersection] globals [ accident-count traffic-flow-rate annual-accidents average-speed congestion-index BASE-ACCIDENTS TOTAL-VEHICLES REFERENCE-SPEED ] cars-own [ speed desired-speed waiting? trip-time ] patches-own [ is-road? ] to setup clear-all set-default-shape cars "car" set BASE-ACCIDENTS 2158 set REFERENCE-SPEED 50 setup-roads setup-intersections setup-cars set accident-count 0 set traffic-flow-rate 0 set average-speed 0 set congestion-index 0 reset-ticks end to setup-roads ask patches [ ifelse (abs pycor mod 4 = 0) or (abs pxcor mod 4 = 0) [ set is-road? true set pcolor gray ] [ set is-road? false set pcolor green ] ] end to setup-intersections ask patches [ if is-road? and any? neighbors4 with [not is-road?] [ sprout-intersections 1 [ set color red set size 1 ] ] ] end to setup-cars create-cars initial-number-of-cars [ move-to one-of patches with [is-road? and not any? cars-here] set color one-of [red blue yellow] set size 1 set speed random-float speed-limit set desired-speed speed-limit * (0.8 + random-float 0.4) set waiting? false set trip-time 0 ifelse abs xcor mod 4 = 0 [ set heading one-of [0 90] ] [ set heading one-of [90 270] ] ] end to go ; Ferma la simulazione se non ci sono più auto if count cars = 0 [ user-message "Simulazione terminata: non ci sono più auto attive." stop ] ask cars [ ifelse safe-to-move? [ move-forward check-for-accidents set trip-time trip-time + 1 ] [ set waiting? true ] ] update-statistics tick end to move-forward set waiting? false let target-speed min (list desired-speed speed-limit) let cars-ahead cars in-cone 3 20 if any? cars-ahead [ set target-speed [speed] of min-one-of cars-ahead [distance myself] ] ifelse speed < target-speed [ set speed speed + 0.1 ] [ set speed speed - 0.1 ] forward speed * 0.1 end to check-for-accidents let nearby-cars other cars in-radius 1 if any? nearby-cars [ let speed-factor (speed / REFERENCE-SPEED) ^ 2 if random-float 1 < 0.01 * speed-factor [ set accident-count accident-count + 1 die ] ] end to update-statistics ifelse count cars > 0 [ set traffic-flow-rate (count cars with [not waiting?] / count cars) * 100 set average-speed mean [speed] of cars set congestion-index 100 - traffic-flow-rate ] [ ; Se non ci sono auto, imposta valori di default set traffic-flow-rate 0 set average-speed 0 set congestion-index 0 ] let time-factor max (list (ticks / (365 * 24 * 60)) 0.0001) ; evita divisione per zero let speed-impact (speed-limit / REFERENCE-SPEED) ^ 2 set annual-accidents accident-count / time-factor end to-report safe-to-move? let next-patch patch-ahead 1 if next-patch = nobody [ report false ] if not [is-road?] of next-patch [ report false ] if any? other cars-on next-patch [ report false ] if any? intersections-on next-patch [ report random 100 < 30 ] report true end to-report get-accident-projection report annual-accidents end to-report get-average-speed report average-speed end to-report get-congestion report congestion-index end
There are 2 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Città 30.png | preview | Preview for 'Città 30' | about 1 month ago, by Sergio Cima | Download |
This model does not have any ancestors.
This model does not have any descendants.