Electrical network
Model was written in NetLogo 5.0
•
Viewed 616 times
•
Downloaded 37 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
extensions [ gis ] globals [ cities-dataset countries-dataset arr_e] breed [cities city] patches-own [population country-name] cities-own [key name pop elec?] links-own [energ?] to setup ca set arr_e [] ; Load all of our datasets set cities-dataset gis:load-dataset "USCAN/cities.shp" set countries-dataset gis:load-dataset "USCAN/countries.shp" gis:set-world-envelope (gis:envelope-union-of (gis:envelope-of cities-dataset) (gis:envelope-of countries-dataset)) display-countries create-towns end to create-towns foreach gis:feature-list-of cities-dataset [ let location gis:location-of (first (first (gis:vertex-lists-of ?))) if not empty? location [ create-cities 1 [ set xcor item 0 location set ycor item 1 location set size 2 set shape "pentagon" set color black if label-cities [set label gis:property-value ? "NAME"] set key gis:property-value ? "KEY" set name gis:property-value ? "NAME" set pop gis:property-value ? "POPULATION" ] ] ] end to create-electric-network ask turtles [ set size 2 set color black create-links-with other turtles] set arr_e [] ask links [set hidden? true] let l [] foreach [self] of links [ set l lput ([link-length] of ?) l] set l sort l ;first pair ask first([self] of links with [link-length = first(l)]) [set color 25 set hidden? false set thickness 0.3 let e1 [who] of end1 let e2 [who] of end2 let tempar [] set tempar lput e1 tempar set tempar lput e2 tempar set arr_e lput tempar arr_e] set l remove-item 0 l while [length(l) > 0] [ let li first([self] of links with [link-length = first(l)]) let e1 [who] of [end1] of li let e2 [who] of [end2] of li let i 0 let flag 0 let p1 -1 let p2 -1 while [i < length(arr_e)] [ if (member? e1 item i arr_e) [set p1 i] if (member? e2 item i arr_e) [set p2 i] set i i + 1] let case 0 while [flag = 0] [ let tempar [] if p1 != -1 and p1 = p2 [ ;Case1: Both belong to the same array set case 1 set flag 2] if p1 = -1 and p1 = p2 [ ;Case2: Nobody belongs set tempar lput e1 tempar set tempar lput e2 tempar set arr_e lput tempar arr_e set case 2 set flag 1] if p1 != -1 and p2 = -1 [ ;Case 3: Only e1 exists in one group set tempar item p1 arr_e set arr_e remove tempar arr_e set tempar lput e2 tempar set arr_e lput tempar arr_e set case 3 set flag 1] if p1 = -1 and p2 != -1 [ ;Case 4: Only e2 exists in one group set tempar item p2 arr_e set arr_e remove tempar arr_e set tempar lput e1 tempar set arr_e lput tempar arr_e set case 4 set flag 1] if p1 != -1 and p2 != -1 and flag = 0 [ ;Case 5: Both already belong to different groups let g1 item p1 arr_e let g2 item p2 arr_e set tempar sentence g1 g2 set arr_e remove g1 arr_e set arr_e remove g2 arr_e set arr_e lput tempar arr_e set case 5 set flag 1] ] if flag = 1 [ask li [ set color 25 set hidden? false set thickness 0.6 ] ] set l remove-item 0 l ] set arr_e remove-duplicates arr_e ask links with [hidden? = true] [die] end ; Drawing polygon data from a shapefile, and optionally loading some ; of the data into turtles, if label-countries is true to display-countries gis:set-drawing-color white gis:draw countries-dataset 1 gis:apply-coverage countries-dataset "CNTRY_NAME" country-name ask patches [ ifelse country-name = "United States" [set pcolor 122] [ifelse country-name = "Canada" [set pcolor 73] [set pcolor 94]] ] end to turn-lights-on ask turtles with [key = Electric_Source] [set elec? True set color 24 set size 3 ask my-links [set energ? True]] elec-city elec-links end to elec-city ask cities [foreach [self] of my-links [if [color] of ? = Yellow [set elec? True]] if elec? = True [set color Yellow ask my-links [set energ? True]]] end to elec-links ask links [if energ? = True [set color Yellow]] end to damage let l one-of links let c1 [end1] of l let c2 [end2] of l watch l ask l [die] user-message(word "There's a problem in the electric connection between cities " [Name] of c1 " and " [Name] of c2) ask cities [set elec? False set color black] ask links [set energ? False set color grey] reset-perspective turn-lights-on end
There is only one version of this model, created over 10 years ago by Alvaro Gil.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Electrical network.png | preview | Preview for 'Electrical network' | over 10 years ago, by Alvaro Gil | Download |
Mod5-6-GIS.zip | extension | Model, extensions and data | over 10 years ago, by Alvaro Gil | Download |
This model does not have any ancestors.
This model does not have any descendants.