NetLogo nw extension: how to save the links reported by `nw:weighted-path-to`?

StackOverflow https://stackoverflow.com/questions/22961785

  •  30-06-2023
  •  | 
  •  

Domanda

I want to save the links of the shortest path between the source and destination , so thagt i can change their color to red ie the links' color. But theres is no primitive to save the links the code is:

          ask nodes with [label = "Source" ]
         [
           show  nw:weighted-path-to  turtle nodenumberdestination "bandwidth"
         ]

can somebody tell me how to save the links reported by the nw primitive used above, so as to change their color to red in the graph?

È stato utile?

Soluzione

I'm not entirely sure what you mean by saving the links, but you can store the list of links in a variable. So, if you have a turtles-own variable path-to-destination, you can just do

ask nodes with [label = "Source" ] [
  set path-to-destination nw:weighted-path-to turtle nodenumberdestination "bandwidth"
]

Alternatively, you can just store the list of links in a local variable if you don't need to do anything with them later:

ask nodes with [label = "Source" ] [
  let path-to-destination nw:weighted-path-to turtle nodenumberdestination "bandwidth"
]

As for turning them red, nw:weighted-path-to returns a list of links, so we can just loop through that list ask each to become red. Extending the previous code, that looks like:

ask nodes with [label = "Source" ] [
  let path-to-destination nw:weighted-path-to turtle nodenumberdestination "bandwidth"
  foreach path-to-destination [ ask ? [ set color red ] ]
]
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top