Extending NW - Multiple Plots with nw: generate?

I want to create multiple random subgraphs in the same world. Since, as a rule, the number of subgraphs is not fixed, I do not want to use a different breed for each subgraph. So far, I have been using a rather crude approach (see below) with "handcrafted random nets" by defining a "my group" variable for the turtles. I'm new to the NW extension and I'm wondering if it is possible to create multiple subgraphs using the nw: generate-random module without using rocks for each subgraph. Do you have any suggestions? Thanks Hannah

to create-subgroups
  crt network_size [ setxy random-xcor random-ycor ]
  let group-n 0
  repeat network_size / group_size [ ;; group_size is always a factor of network_size
    ask turtles with [who >= (group-n * group_size) and who < ((group-n + 1) * group_size)] [
      set my-group group-n           ;; get group number
      repeat (random 4) + 1 [        ;; create links
        let target one-of other turtles with [who >= (group-n * group_size) and who < ((group-n + 1) * group_size)]
        if target != nobody [
          create-group-link-with target ] ] ]
    set group-n group-n + 1 ]
end

      

+3


source to share


1 answer


Good question! This should be a more convenient way to create the same graphs you are currently generating:

to create-subgroups
  repeat network_size / group_size [
    let group (turtle-set)
    crt group_size [ set group (turtle-set group self) ]
    ask group [
      create-group-links-with n-of (1 + random 4) other group
    ]
  ]
end

      

This assumes the group_size is greater than 4 (otherwise, there might not be enough turtles in the group that needs the link).

The idea here is that instead of keeping track of who is in the numbered group who

, you can use a set of turtles. Besides cleaning, it allows you to save groups in a list for later use. So if you have a global groups

that you set to a list, you can add groups to it like this:

to create-subgroups
  repeat network_size / group_size [
    let group (turtle-set)
    crt group_size [ set group (turtle-set group self) ]
    ask group [
      create-group-links-with n-of (1 + random 4) other group
    ]
    set groups (lput group groups)
  ]
end

      

Update:



You can use a similar method with nw:generate-random

. nw:generate-random

creates a subgraph, it won't use your entire network. Turtles and links will be whatever breed you specify, but they will only connect to other turtles in the breeds that are currently being created nw:generate-random

. So this should work:

to create-subgroups
  repeat network_size / group_size [
    nw:generate-random turtles links group_size connection-probability
  ]
end

      

where connection-probability

is the probability that any two turtles in the newly created subgraph will be connected. You can still intercept references to newly created turtles for storage in a list similar to above:

to create-subgroups
  let group (turtle-set)
  repeat network_size / group_size [
    nw:generate-random turtles links group_size connection-probability [
      set group (turtle-set group self)
    ]
  ]
  set groups (lput group groups)
end

      

So you have a set of turtles for each of the components, the number of components is completely variable and changeable in the run run, and the components are completely disconnected from each other.

+3


source







All Articles