Koul_Dhruv_FinalProject
No preview image
Model was written in NetLogo 5.0.4
•
Viewed 506 times
•
Downloaded 101 times
•
Run 0 times
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
;; Dhruv Koul ;; EECS 372 - Spring 2013 ;; Final Project ;; breeds used in model breed [tornadoes tornado] breed [trees tree] breed [houses house] ;; for small and medium cities breed [buildings building] ;; for medium and large cities (and a few in small cities) breed [cars car] globals [total-life initial-city-value initial-buildings-value initial-houses-value final-city-value final-buildings-value final-houses-value total-damage initial-car-count car-casualty-tornado car-casualty-accident final-car-casualty-count] tornadoes-own [lifetime t-speed] buildings-own [initial-bvalue b-damage b-time-with-tornado] ;; value is average value for buildings in specified city size houses-own [initial-hvalue h-damage h-time-with-tornado] ;; value is average value for homes in specified city size cars-own [speed] ;; setting default shapes aids in simplifying the setup process to set-default-shapes set-default-shape trees "tree" set-default-shape tornadoes "target" set-default-shape houses "house" set-default-shape buildings "box" set-default-shape cars "car" end ;; tornado procedure ;; sets lifetime of each tornado (taken from average tornado lifetimes and adjusts it for time (explained in report) to set-total-life set total-life (tornado-lifetime / 10 * 60 * 50) end ;; initialize global variables and call this in the setup functions to set-initial-values set initial-buildings-value (sum [initial-bvalue] of buildings) set initial-houses-value (sum [initial-hvalue] of houses) set initial-city-value (initial-buildings-value + initial-houses-value) set total-damage 0 set car-casualty-tornado 0 set car-casualty-accident 0 end ;; tornado procedure ;; creates tornadoes (function since tornadoes are same across cities - reusable code) to make-tornadoes-appear create-tornadoes 1 [ set color gray ;; will focus less on the actual physics of the tornado as that will be difficult to set lifetime 0 set size (tornado-strength / 2 + 1) ;; model accurately - instead will focus on the movement of tornadoes, the probability set t-speed (movement-speed / 100) move-to one-of patches with [count turtles-here = 0] ;; of them jumping from place to place, and the actual damage they cause based on a reference ] ;; pattern from previous tornadoes in similar-sized areas end ;; cars procedure ;; creates cars (cars same across cities and # defined by user - reusable code) to make-cars-appear create-cars number-of-cars [ set initial-car-count number-of-cars set color red set speed (car-speed / 100) ;; car speed is normalized to move at a "see-able" pace (just like tornado mph) move-to one-of patches with [count turtles-here = 0] ] end ;; SETUP OF CITIES - three types of cities are being set up - large cities, medium-sized cities ;; and small town/rural areas. These setups are going to be pre-defined and captured in three different ;; setup buttons. The user can choose which type of city they want to use and pair with a certain ;; strength of tornado to assess damage done. The rationale for the setups will be scattered in comments ;; throughout the code as well as detailed in the report's final analysis. The values given to the buildings and ;; houses in each of the type of cities is the average property value for such types in examples of cities that are ;; the same size as the ones I've chosen for this model (explained in the report). to setup-large-city clear-all set-default-shapes set-total-life ask patches [ set pcolor green - 2.5 ;; chose green to be the "landscape" of the cities - same for medium and small cities ] create-trees 50 [ set color green move-to one-of patches with [ count turtles-here = 0 and pxcor > 24 ] ] ;; downtown setting create-buildings 40 [ set size 3 + random 3 ;; for large city - at least a size of 3 set color blue set initial-bvalue 500000000 set b-time-with-tornado 0 set b-damage 0 move-to one-of patches with [ count turtles-here = 0 and not any? turtles in-radius 2 and pxcor < 11 and pycor > 0 ] ] ;; less densely-populated, non-downtown area create-buildings 15 [ set size 1.5 + random 2 ;; for large city - at least a size of 3 set color gray + 1 set initial-bvalue 250000000 ;; in lesser downtown - property is slightly cheaper set b-time-with-tornado 0 set b-damage 0 move-to one-of patches with [ count turtles-here = 0 and not any? turtles in-radius 2 and pxcor < 11 and pycor < -5 ] ] make-tornadoes-appear make-cars-appear set-initial-values setup-damage-plot reset-ticks end to setup-medium-city clear-all set-default-shapes set-total-life ask patches [ set pcolor green - 2.5 ] create-trees 40 [ set color green move-to one-of patches with [ count turtles-here = 0 and pxcor > 1 ] ] ;; on one side of the trees will exist houses ;; the other side of the trees will be the "downtown" area create-houses 40 [ set size 1.25 set color yellow set initial-hvalue 200000 set h-time-with-tornado 0 set h-damage 0 move-to one-of patches with [ count turtles-here = 0 and not any? turtles in-radius 2 and pxcor > 3 ] ] ;; medium city downtown area create-buildings 25 [ set size 1 + random 3 set color gray + 1 set initial-bvalue 100000000 set b-time-with-tornado 0 set b-damage 0 move-to one-of patches with [ count turtles-here = 0 and not any? turtles in-radius 2 and pxcor < 1 and pycor > 0 ] ] ;; smaller buildings in non-downtown area create-buildings 10 [ set size 1 + random 2 set color gray + 1 set initial-bvalue 50000000 ;; worth a little less than the downtown buildings set b-time-with-tornado 0 set b-damage 0 move-to one-of patches with [ count turtles-here = 0 and not any? turtles in-radius 2 and pxcor < 1 and pycor < -8 ] ] make-tornadoes-appear make-cars-appear set-initial-values setup-damage-plot reset-ticks end ;; SMALL CITY to setup-small-city clear-all set-default-shapes set-total-life ask patches [ set pcolor green - 2.5 ] create-trees 80 [ set color green move-to one-of patches with [ count houses = 0 and count buildings = 0 ] ] ;; houses around the city except near shopping district create-houses 50 [ set size 1.25 set color yellow set initial-hvalue 125000 set h-time-with-tornado 0 set h-damage 0 move-to one-of patches with [ count turtles-here = 0 and pxcor < 4 or (pxcor > 4 and pycor < 0) ] ] ;; tight little "shopping district" create-buildings 10 [ set size 1.5 set color gray + 1 set initial-bvalue 20000000 set b-time-with-tornado 0 set b-damage 0 move-to one-of patches with [ count turtles-here = 0 and pxcor > 6 and pycor > 6 ] ] make-tornadoes-appear make-cars-appear set-initial-values setup-damage-plot reset-ticks end ;; GO CODE to go if not any? tornadoes [ calculate-total-damage set-final-values stop ] move-tornadoes move-cars throw-cars throw-trees tornado-damage-to-buildings tornado-damage-to-houses increment-tornado-life check-tornado-death tick end ;; tornadoes procedure ;; tornadoes will move based on a probability which user assigns - a probabilistic movement ;; is consistent with the average tornado. Though tendecies for tornadoes are to move from SW - NE, ;; I've decided to allow the user to assign a probability to make the model exhibit "emergent" behavior ;; I'm also bouncing off world boundaries to avoid the tornado getting caught - just for action purposes to move-tornadoes ask tornadoes [ if patch-ahead 0.1 != nobody and abs [pxcor] of patch-ahead 0.1 = max-pxcor [ set heading (- heading) ] if patch-ahead 0.1 != nobody and abs [pycor] of patch-ahead 0.1 = max-pycor [ set heading (180 - heading) ] ;; according to probability - this is just so it ] ;; doesn't get stuck (I've unchecked wrapping) if random 100 < movement-probability [ ask tornadoes [ wiggle fd t-speed check-reproduction ] ] end ;; cars procedure ;; cars will try and move away from tornadoes and buildings and houses (avoid massive collisions ;; also checking that the cars try and bounce away from the ends of the world to avoid getting fully stuck there to move-cars ask cars [ if patch-ahead 0.1 != nobody and abs [pxcor] of patch-ahead 0.1 = max-pxcor [ set heading (- heading) ] if patch-ahead 0.1 != nobody and abs [pycor] of patch-ahead 0.1 = max-pycor [ set heading (180 - heading) ] avoid-tornadoes ;; only move when a tornado is approaching check-for-car-accidents ;; after moving, check for car accidents ] end ;; cars procedure ;; checks for tornadoes and tries to escape them to avoid-tornadoes if any? tornadoes in-radius 4 [ face one-of tornadoes in-radius 4 rt 180 wiggle fd speed ] end ;; cars procedure ;; checks for nearby cars and trees to avoid collisions to avoid-cars-and-trees if any? trees in-radius 1 or any? cars in-radius 1 [ wiggle fd speed avoid-cars-and-trees ;; when avoiding tornadoes, it's also important to watch out for other avoid-houses-and-buildings ;; obstacles, like other cars, houses, trees and buildings ] end ;; cars procedure ;; checks for nearby buildings and houses to avoid collisions to avoid-houses-and-buildings if any? houses in-radius 1 or any? buildings in-radius 1 [ wiggle fd speed ] end ;; cars procedure ;; check for collisions with houses, buildings, trees, or other cars ;; account for those collisions in casualty-by-accident count to check-for-car-accidents ask cars with [color != black] [ if any? buildings-here or any? houses-here or any? trees-here or any? other cars-here [ set speed 0 set color black set car-casualty-accident car-casualty-accident + 1 ] ] end ;; turtles procedure ;; allow users to choose the speed at which the tornado actually travels ;; research shows that speed is generally between 30 - 70 mph (hence the limits) to wiggle rt random 30 lt 15 end ;; tornado procedure ;; if the user allows tornado reproduction, then there is a .1% chance that a tornado will ;; reproduce - tornado "families" are rare, so that's why the percentage chance is so low to check-reproduction if allow-reproduction? and random 1000 = 0 [ ask one-of tornadoes [ hatch 1 [set lifetime 0] ] ] end ;; tornado procedure ;; if the tornado encounters a car, it treats the car just like a tree (throwing it) - with the ;; car becoming damaged and added to the car casualty percentage to throw-cars ask tornadoes [ if any? cars in-radius (tornado-strength / 2) [ ask cars in-radius (tornado-strength / 2) [ move-to one-of patches in-radius (sqrt ((tornado-strength ^ 2) + ((0.05 * (movement-speed)) ^ 2))) ask cars in-radius (tornado-strength / 2) with [color != black] [ set speed 0 set color black set car-casualty-tornado car-casualty-tornado + 1 ] check-if-hit-something ] ] ] end ;; tornado procedure ;; if it encounters a tree in its path, throw it to another patch based on tornado strength and movement speed ;; this is a little arbitrary but it's a sort of vector math, using movement-speed as a vector ;; proceed to check if the thrown tree has hit a building or a home to throw-trees ask tornadoes [ if any? trees in-radius (tornado-strength / 2) [ ask trees in-radius (tornado-strength / 2) [ move-to one-of patches in-radius (sqrt ((tornado-strength ^ 2) + ((0.05 * (movement-speed)) ^ 2))) check-if-hit-something ] ] ] end ;; turtles procedure ;; if the tree was thrown to a spot where there are any buildings or houses here ;; then inflict damage to them (assuming houses are hurt more than buildings) to check-if-hit-something ask buildings-here [ set b-damage b-damage + 3000 ] ask houses-here [ set h-damage h-damage + 10000 ] end ;; tornado procedure ;; calculate damage done by tornadoes - the targets are going to be in a certain ;; radius size depending on strength of tornado because the tornado can cause damage ;; with its winds in similar settings to tornado-damage-to-houses ask tornadoes [ if any? houses in-radius (tornado-strength / 2) [ ask houses in-radius (tornado-strength / 2) [ set h-time-with-tornado h-time-with-tornado + 1 calculate-house-damage show-house-damage-visually ] ] ] end ;; tornado procedure ;; calculate damage done by tornadoes - the targets are going to be in a certain ;; radius size depending on strength of tornado because the tornado can cause damage ;; with its winds in similar settings to tornado-damage-to-buildings ask tornadoes [ if any? buildings in-radius (tornado-strength / 2) [ ask buildings in-radius (tornado-strength / 2) [ set b-time-with-tornado b-time-with-tornado + 1 calculate-building-damage show-building-damage-visually ] ] ] end ;; otherwise set damage according to this model (mathematical model I've chosen that ;; works out to reflect some average reference pattern statistics - and it takes into ;; account some relevant factors of the tornado) to calculate-house-damage ifelse (h-damage >= initial-hvalue) [set h-damage initial-hvalue] [set h-damage ((tornado-strength ^ 3) * (e ^ (h-time-with-tornado / 50)) * 100000)] end to calculate-building-damage ifelse (b-damage >= initial-bvalue) [set b-damage initial-bvalue] [set b-damage ((tornado-strength ^ 3) * (e ^ (b-time-with-tornado / 50)) * 100000)] end ;; buildings procedure ;; changes the color/shape of a building depending on amount of damage done to it percentage-wise to show-building-damage-visually if (b-damage / initial-bvalue) >= 0.333 [ set color brown ] if (b-damage / initial-bvalue) >= 0.667 [ set color brown - 2 ] if (b-damage / initial-bvalue) >= 1 [ set color black set shape "circle" ;; indicates a sort of 2D "heap" of building material ] end ;; houses procedure ;; changes the color/shape of a house depending on amount of damage done to it percentage-wise to show-house-damage-visually if (h-damage / initial-hvalue) >= 0.333 [ set color brown ] if (h-damage / initial-hvalue) >= 0.667 [ set color brown - 2 ] if (h-damage / initial-hvalue) >= 1 [ set color black set shape "circle" ;; indicates a sort of 2D "heap" of building material ] end ;; tornadoes procedure ;; make the tornado creep closer to dissipation to increment-tornado-life ask tornadoes [ set lifetime lifetime + 1 ] end ;; tornadoes procedure ;; if the tornado has outlived its allotted lifetime, it dies to check-tornado-death ask tornadoes with [lifetime >= total-life] [die] end ;; total damage to the entire city (sum of individual damages of houses and buildings) to calculate-total-damage set total-damage ((sum [h-damage] of houses) + (sum [b-damage] of buildings)) end ;; calculate final values - again all global variables and called in go function to set-final-values set final-buildings-value (initial-buildings-value - (sum [b-damage] of buildings)) set final-houses-value (initial-houses-value - (sum [h-damage] of houses)) set final-city-value (final-buildings-value + final-houses-value) set final-car-casualty-count (count cars with [color = black]) end ;; set up the initial values for the plots (setup in each setup function) to setup-damage-plot set-current-plot "Building Damage vs. Total" set-plot-x-range 0 100 set-plot-y-range 0 1000000 set-current-plot "House Damage vs. Total" set-plot-x-range 0 100 set-plot-y-range 0 1000000 end
There are 18 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
DhruvKoul_June3.pdf | Progress report - June 3 | over 11 years ago, by Dhruv Koul | Download | |
DhruvKoul_May13.pdf | Progress report - May 13 | over 11 years ago, by Dhruv Koul | Download | |
DhruvKoul_May20.pdf | Progress report - May 20 | over 11 years ago, by Dhruv Koul | Download | |
DhruvKoul_May27.pdf | Progress report - May 27 | over 11 years ago, by Dhruv Koul | Download | |
Koul_Dhruv_Final Report.pdf | Final Project Report | over 11 years ago, by Dhruv Koul | Download | |
Koul_Dhruv_Poster Presentation.pdf | Poster Presentation "Digital Version" | over 11 years ago, by Dhruv Koul | Download | |
Koul_Dhruv_Project Proposal.pdf | Original Project Proposal | over 11 years ago, by Dhruv Koul | Download | |
Koul_Dhruv_Slam.ppt | powerpoint | Poster "Slam" Slides | over 11 years ago, by Dhruv Koul | Download |
This model does not have any ancestors.
This model does not have any descendants.