1

I am creating an urban environment that is robust from interruption for my university project.

The problem I am facing is that I am not sure how to make each turtle follow a specific network line. The black line represents the electricity cable and the blue line represent the underground water pipe. I am not sure how to create a turtle to follow the network line to be consumed by the house or the big buildings. Also, please bear in mind that I only just started learning Netlogo so any improvements in the coding itself are much appreciated.

This is the current code for the urban environment model. Also, is it even possible for a turtle to follow a specific line?

breed [ houses house ]
breed [ big-buildings big-building ]
breed [ commercial-buildings commercial-building ]

breed [ water-pumping-stations water-pumping-station ]
breed [ sewage-plant-stations sewage-plant-station ]

breed [ electricity-power-stations electricity-power-station ]
breed [ overhead-cable-stations overhead-cable-station ]

to setup
  clear-all
  reset-ticks
  setup-landscape
  setup-network

  if (show-grid = true ) [
    draw-grid ;for the switch to hide or show the gride
  ]

  if (show-eletricity = true) [
    draw-electricity ; for the swtich to hide or show the gride
  ]

  if (show-sewage = true) [
    draw-sewage ; for the swtich to hide or show the gride
  ]

  if (show-water = true) [
    draw-water ; for the swtich to hide or show the gride
  ]
end


to setup-network
    draw-networks ; designing lines and colour coordinate them to show what each network are.
end

to draw-networks ; list of networks that has been drawn.
  draw-electricity
  draw-sewage
  draw-water
end

to draw-water
  create-turtles 1 [ ;FOR THE HOUSE AND BIG BUILDINGS
    setxy 37 -18
    set heading 90
    set color blue
    set pen-size 2.5
    pen-down
    left 180
    fd 10
    right 90
    fd 9
    right 90
    fd 3
    right 90
    fd 3
    back 6
    fd 3
    right 90
    fd 7
    right 90
    fd 3
    back 6
    fd 3
    left 90
    fd 7
    right 90
    fd 3
    back 6
    fd 3
    left 90
    fd 3
    right 90
    fd 19
    right 90
    fd 3
    right 90
    fd 4
    back 9
    fd 5
    left 90
    fd 4
    right 90
    fd 8
    back 8
    left 90
    fd 3
    right 90
    fd 4
    back 9
    fd 5
    left 90
    fd 4
    right 90
    fd 8
    back 8
    left 90
    fd 3
    right 90
    fd 4
    back 9
    die
  ]

  create-turtles 1 [ ;FOR THE COMMERICAL BUILDING
    setxy -37 -18
    set heading 90
    set color blue
    set pen-size 2.5
    pen-down
    left 90
    fd 14
    right 90
    fd 12
    right 90
    fd 3
    back 6
    fd 3
    left 90
    fd 10
    left 90
    fd 3
    back 6
    fd 3
    right 90
    fd 10
    right 90
    fd 3
    back 6
    fd 3
    die
  ]
end

to draw-sewage
  create-turtles 1 [ ;FOR HOUSE AND BIG BUILDINGS
    setxy 38 -1
    set heading 90
    set color green
    set pen-size 2.5
    pen-down
    right 90
    fd 8
    right 90
    fd 8
    right 90
    fd 3
    back 6
    fd 3
    left 90
    fd 7
    right 90
    fd 3
    back 6
    fd 3
    left 90
    fd 7
    right 90
    fd 3
    back 6
    fd 3
    left 90
    fd 3
    right 90
    fd 19
    right 90
    fd 3
    right 90
    fd 4
    back 9
    fd 5
    left 90
    fd 4
    right 90
    fd 8
    back 8
    left 90
    fd 3
    right 90
    fd 4
    back 9
    fd 5
    left 90
    fd 4
    right 90
    fd 8
    back 8
    left 90
    fd 3
    right 90
    fd 4
    back 9
    die
  ]

  create-turtles 1 [ ;FOR COMMERICAL BUILDING
    setxy -18 -18
    set heading 90
    set color green
    set pen-size 2.5
    pen-down
    right 180
    back 7
    right 90
    fd 7
    right 90
    fd 9
    left 90
    fd 7
    left 90
    fd 3
    right 90
    fd 3
    back 6
    fd 3
    left 90
    fd 10
    right 90
    fd 3
    back 6
    fd 3
    left 90
    fd 10
    right 90
    fd 3
    back 6
    fd 3
    die
  ]
end

to draw-electricity
  ;HOUSE
  create-turtles 1 [ ;house 1
    setxy -38 18
    set heading 90
    set color black
    set pen-size 2.5
    pen-down
    fd 54
    right 90
    fd 3
    die
  ]

  create-turtles 1 [ ;house 2
    setxy -38 18
    set heading 90
    set color black
    set pen-size 2.5
    pen-down
    forward 61
    right 90
    fd 3
    die
  ]

  create-turtles 1 [ ; house 3
    setxy -38 18
    set heading 90
    set color black
    set pen-size 2.5
    pen-down
    forward 68
    right 90
    fd 3
    die
  ]

  create-turtles 1 [ ; house 4
    setxy -38 18
    set heading 90
    set color black
    set pen-size 2.5
    pen-down
    forward 70
    right 90
    fd 8
    right 90
    fd 2
    left -90
    back 4
    die
  ]

  create-turtles 1 [ ; house 5
    setxy -38 18
    set heading 90
    set color black
    set pen-size 2.5
    pen-down
    forward 70
    right 90
    fd 8
    right 90
    fd 9
    left -90
    back 4
    die
  ]

  create-turtles 1 [ ; house 6
    setxy -38 18
    set heading 90
    set color black
    set pen-size 2.5
    pen-down
    forward 70
    right 90
    fd 8
    right 90
    fd 16
    left -90
    back 4
    die
  ]

  create-turtles 1 [ ; house 7
    setxy -38 18
    set heading 90
    set color black
    set pen-size 2.5
    pen-down
    forward 70
    right 90
    fd 18
    left 90
    back 5
    right 90
    back 2
    die
  ]

  create-turtles 1 [ ; house 8
    setxy -38 18
    set heading 90
    set color black
    set pen-size 2.5
    pen-down
    forward 70
    right 90
    fd 18
    left 90
    back 12
    right 90
    back 2
    die
  ]

  ; BIG BUILDINGS ROW
  create-turtles 1 [ ; building 1
    setxy -38 18
    set heading 90
    set color black
    set pen-size 2.5
    pen-down
    forward 70
    right 90
    fd 8
    right 90
    fd 19
    left -90
    back 19
    right 90
    fd 3
    right 90
    back 3
    die
  ]

  create-turtles 1 [ ; building 2
    setxy -38 18
    set heading 90
    set color black
    set pen-size 2.5
    pen-down
    forward 70
    right 90
    fd 8
    right 90
    fd 19
    left -90
    back 19
    right 90
    fd 10
    right 90
    back 3
    die
  ]

  create-turtles 1 [ ; building 3
    setxy -38 18
    set heading 90
    set color black
    set pen-size 2.5
    pen-down
    forward 70
    right 90
    fd 8
    right 90
    fd 19
    left -90
    back 19
    right 90
    fd 17
    right 90
    back 3
    die
  ]

   create-turtles 1 [ ; building 4
    setxy -38 18
    set heading 90
    set color black
    set pen-size 2.5
    pen-down
    forward 70
    right 90
    fd 8
    right 90
    fd 19
    left -90
    back 19
    right 90
    fd 3
    right 90
    fd 3
    die
  ]

  create-turtles 1 [ ; building 5
    setxy -38 18
    set heading 90
    set color black
    set pen-size 2.5
    pen-down
    forward 70
    right 90
    fd 8
    right 90
    fd 19
    left -90
    back 19
    right 90
    fd 10
    right 90
    fd 3
    die
  ]

  create-turtles 1 [ ; building 6
    setxy -38 18
    set heading 90
    set color black
    set pen-size 2.5
    pen-down
    forward 70
    right 90
    fd 8
    right 90
    fd 19
    left -90
    back 19
    right 90
    fd 17
    right 90
    fd 3
    die
  ]

  ;COMMERICAL BUILDINGS
   create-turtles 1 [ ;COMMERICAL BUILDINGS 1
    setxy -38 18
    set heading 90
    set color black
    set pen-size 2.5
    pen-down
    right 90
    fd 22
    left 90
    fd 33
    die
  ]

   create-turtles 1 [ ;COMMERICAL BUILDINGS 2
    setxy -25 -4
    set heading 90
    set color black
    set pen-size 2.5
    pen-down
    right 90
    fd 2
    die
  ]

  create-turtles 1 [ ;COMMERICAL BUILDINGS 3
    setxy -25 -4
    set heading 90
    set color black
    set pen-size 2.5
    pen-down
    right 90
    back 3
    die
  ]

  create-turtles 1 [ ;COMMERICAL BUILDINGS 4
    setxy -15 -4
    set heading 90
    set color black
    set pen-size 2.5
    pen-down
    right 90
    fd 2
    die
  ]

  create-turtles 1 [ ;COMMERICAL BUILDINGS 5
    setxy -15 -4
    set heading 90
    set color black
    set pen-size 2.5
    pen-down
    right 90
    back 3
    die
  ]

  create-turtles 1 [ ;COMMERICAL BUILDINGS 6
    setxy -5 -4
    set heading 90
    set color black
    set pen-size 2.5
    pen-down
    right 90
    fd 2
    die
  ]

  create-turtles 1 [ ;COMMERICAL BUILDINGS 7
    setxy -5 -4
    set heading 90
    set color black
    set pen-size 2.5
    pen-down
    right 90
    back 3
    die
  ]

  create-turtles 1 [ ;COMMERICAL BUILDINGS 8
    setxy -25 -4
    set heading 90
    set color black
    set pen-size 2.5
    pen-down
    right 90
    fd 2
    die
  ]
end


to setup-landscape
  ask patches [
    set pcolor pink
  ]

  draw-entities

end

to draw-entities
  draw-houses
  draw-big-buildings
  draw-water-pumping-stations
  draw-sewage-plant-stations
  draw-electricity-power-stations
  draw-commercial-buildings
end

to draw-houses ; setting house as stationary not going to move at all
  ask patch 30 15 [ sprout-houses 1 ]
  ask patch 23 15 [ sprout-houses 1 ]
  ask patch 16 15 [ sprout-houses 1 ]
  ask patch 30 6  [ sprout-houses 1 ]
  ask patch 23 6  [ sprout-houses 1 ]
  ask patch 16 6  [ sprout-houses 1 ]
  ask patch 20 2  [ sprout-houses 1 ]
  ask patch 27 2  [ sprout-houses 1 ]

  ask houses [
    set size 1.5
    set shape "house"
    set color red
  ]
end

to draw-big-buildings ; setting big buildings as stationary not going to move at all
  ask patch 30 -6  [ sprout-big-buildings 2 ]
  ask patch 23 -6  [ sprout-big-buildings 2 ]
  ask patch 16 -6  [ sprout-big-buildings 2 ]
  ask patch 30 -12 [ sprout-big-buildings 3 ]
  ask patch 23 -12 [ sprout-big-buildings 3 ]
  ask patch 16 -12 [ sprout-big-buildings 3 ]

  ask big-buildings [
    set size 2
    set shape "bigbuildings"
    set color white
  ]
end

to draw-water-pumping-stations ; setting water pumping statoins as stationary not going to move at all
  ask patch 37 -18 [ sprout-water-pumping-stations 3 ]
  ask patch -37 -18 [ sprout-water-pumping-stations 3 ] ;FOR THE COMMERICAL BUILDINGS

  ask water-pumping-stations [
    set size 2
    set shape "producewater"
    set color blue
  ]
end

to draw-sewage-plant-stations ; setting sewage plant station as stationary not going to move at all
  ask patch 38 -1 [ sprout-sewage-plant-stations 4 ]
  ask patch -18 -18 [sprout-sewage-plant-stations 4] ;FOR THE COMMERICAL BUILDING

  ask sewage-plant-stations [
    set size 2
    set shape "sewage"
    set color green
  ]
end

to draw-electricity-power-stations ; setting eletricity power station as stationary not going to move at all
  ask patch -38 18 [ sprout-electricity-power-stations 5]

  ask electricity-power-stations [
    set size 2
    set shape "electrcitystation"
    set color 44
  ]
end

to draw-commercial-buildings ; setting commerical buildings as stationary not going to move at all
  ask patch -5 -1 [ sprout-commercial-buildings 7 ]
  ask patch -5 -6 [ sprout-commercial-buildings 7 ]
  ask patch -15 -6 [ sprout-commercial-buildings 7 ]
  ask patch -15 -1 [ sprout-commercial-buildings 7 ]
  ask patch -25 -1 [ sprout-commercial-buildings 7 ]
  ask patch -25 -6 [ sprout-commercial-buildings 7 ]

  ask commercial-buildings [
    set size 2
    set shape "commercialbuilding"
    set color orange
  ]
end

to draw-grid ; allows me to pinpoint where each turtle is properly ( helps me to debug the code)
  ask patches [
    sprout 1 [
      set heading 0
      set color black
      set pen-size 1
      forward 3
      right 90
      pen-down
      repeat 8 [
        forward 3 right 90 fd 3
      ]
      die
    ]
  ]
end

to go
end

This is the image of what my model currently looks like and NetLogo whole image is what I imagine how my model will work as I haven't started doing the go procedure.

model image

netlogo whole image

The model can be found in the following GitHub repo:

https://github.com/omoaka1738/Netlogo-help.git

Nimesh Neema
  • 1,528
  • 2
  • 17
  • 44
BigM
  • 11
  • 3
  • Short answer: turtles and patches can not “see” the drawing layer where PD makes its marks. A different method is needed to encode the network. See next comment. – TurtleZero Mar 04 '22 at 22:12
  • The first thing to consider is that the electrical and water networks can be modeled very abstractly as nodes (the start, end, joints, and access points along the way) and edges (the spans of wires or pipes). Some of your modeling tasks and data and questions may be easier with the networks abstracted like that. – TurtleZero Mar 04 '22 at 22:15
  • I understand what your saying. Can you elaborate a bit more on what you mean using nodes. Is there any examples I can look at since it will be easier if I make it like that. – BigM Mar 05 '22 at 00:10
  • I’m writing up a long answer for you. Probably post it later tonight or on Saturday. – TurtleZero Mar 05 '22 at 00:12

1 Answers1

1

So, my comment above aside, drawing the network so it can be traversed is a whole other thing. You don't want to get bogged down in having to make a path-seeking model, on top of what you are already trying to do. So it's important to not just draw the lines, but give them information to make using them easier. This is why you've really got to think about your model, all its parts, how they interact (not in terms of netlogo, but just like, in terms of if it was a game, what are the rules?)

First question:

Do we really need to model the “physical” location of the wire/pipe or do we just need to know what connects to what?

Maybe we are modeling the effect of breaks in the physical lines/pipes, so we do ned to model the pipes and lines.

Next: do we really need to model each step that the water/elec takes in the pipe? That’s not how electricity works. It’s only sort of how water works. That’s mostly about pressure.

Instead, we can “cook” or “preload” the wires and pipes with information about where the stuff is coming from, and where it goes. This lets the model know what it needs to know without us doing extra work while the model is running.

So:

First: instead of PD and FD etc, we can use turtles to be the pipes and wires, or possibly, just the terminals, access points and joints. If we need to, the pipes too.

Each member will know:

  • what services it provides, like water or electric
  • Whether it is a terminal, in-line access point, joint, or pipe (if we need to model pipes)
  • An indicator of which connection leads to the source, created while we create the network.
  • Note that we can also "pre-calculate" the path from the source to any destination by recording the steps to trace backwards from the destination to the source, then reversing the steps. Store this map in the destination.

The more I think about it, the more this looks like a job for linked turtles. Then you don't need to mark or create turtles for the "pipes" just for the terminals, bends, joints, and access points.

So consider:

  • a breed of turtle, maybe called [nodes node].
  • This is common jargon for networks (aka graphs), they have nodes and edges.
  • add a breed of directed links called [ edges edge](common jargon again)
  • nodes will own:
  • service -- will be "w" or "e" (for exampleor watever you want)
  • Source — contains the turtle that is at the source
  • Input-direction (or something) l—-contains the node that is in the direction towards the source
  • maybe some other stuff.

We can reuse some of your line-drawing code, and maybe make it more consider and easier to copy and change.

POSTING THIS ANSWER FOR NOW

will com back and add on letter

Add some comments to this answer to give more info about what the model is doing.

TurtleZero
  • 1,013
  • 7
  • 15
  • that is fine by me thank you for your response. the model shows, multiple stations such as water, electricity and sewage stations that are structured in a way to is robust. If one of the stations break down another station will do double the work so all the buildings and houses will get what they need or if the circuits/pipeline gets destroyed, the water or electricity will be able to find an alternative route to reach its destination, Interruption like this will happen randomly. – BigM Mar 05 '22 at 02:02
  • When all stations get destroyed and don't cool down all the residential and commercial buildings will stop collecting energy and water. Each house and building will the same amount of income. If it uses more than the income that was given it will show a minus since indicating the houses are in debt/overdraft if it’s not on minus it will be normal. In this variation, the house will be able to generate income to lose some of the debt that they owe but won’t happen rapidly. – BigM Mar 05 '22 at 02:08
  • The city will be running on a weekly basis, and you will be to see how much energy and water is being consumed and produced depending on the time of day (Morning, afternoon, evening, and night). Feel free to let me know if you don't understand what i am saying as i am a bit bad of explaining things. – BigM Mar 05 '22 at 02:09
  • Yeah, so From this description your network can be much simpler- just a network made of “linked” turtles, where each building has a link to each utilty that services that location. It won’t look like a pretty map of a town, at first, but that prettiness can be added later. But, using links, it will be much easier to manage the simulation. For example, when a utility is damaged, it is easy for the linked building to learn that. Likewise, a link itself may be “damaged”, affecting the building(s) it serves. – TurtleZero Mar 05 '22 at 06:43
  • If needed, you can also have what your drawing seems to suggest and I mentioned here, the idea of sources linked to joints or hubs or whatever, that are then liked to building it to other hubs. – TurtleZero Mar 05 '22 at 06:45
  • You have two distinct questions to consider: how will I model the networks and how will I display the networks. Many modelers go for the easier abstract display, everything in a circle, or in a self-organizing ball-and-spring thing based directly on the model. But you can separate the model from the display. Your current network drawing code can be leverages to also create the abstract network model. We will talk about that tomorrow. – TurtleZero Mar 05 '22 at 07:12
  • Oh I see and okay – BigM Mar 05 '22 at 17:42
  • Is it possible you can show me an example of a node model – BigM Mar 09 '22 at 17:30
  • Sorry, BigM, life happened and I didn’t get back to you. Do you still need the info? – TurtleZero Apr 20 '22 at 00:58