Search code examples
netlogoagent-based-modeling

How to create links between turtles and patches?


I have the following code, which gives turtles property over patches. Does anyone know how to either create links between the turtle and its owned patches?

Or, even better, to create a line that surrounds the patches that belong to the turtle?

I tried the following code but it gives an error because CREATE-LINKS-WITH expected input to be a turtle agentset but got the agentset (agentset, 25 patches) instead. It seems that links with patches are not allowed. Any thoughts?

patches-own [
  state 
  patch-owner  
]

turtles-own [
 property 
]

to setup
  clear-all
  create-turtles 10 [
    move-to one-of patches with [not any? turtles-here]
  ]
  setup-patches
  set-ownership
end

to setup-patches
  ask patches [
    let closest-turtle min-one-of turtles [distance myself]
    set patch-owner closest-turtle
  ]
end

to set-ownership
  ask turtles [
    let my-patches patches with [patch-owner = myself]
     create-links-with my-patches
    ]
  ]
end

Solution

  • You are correct that one can not create a link from turtle to patch or patch to patch. However, the typical way of doing the same thing is to place a turtle on the patch and to link to that turtle. To avoid confusion, it's best to make those "patch turtles" a different breed. So, you might do something like

    breed [locations location]
    
        to set-ownership
          ask turtles [
            let my-patches patches with [patch-owner = myself]
            ask my-patches [
              sprout-locations 1
            ]
            create-links-with locations with [member patch-here my-patches]
            ]
          ]
    

    If you want you can make the location turtles invisible, or a certain shape or color.

    Outlining patches is not trivial - see here: outline for patches in NetLogo Would simply coloring the patches help?