Dilshani N Ranawaka
Dilshani N Ranawaka

Reputation: 25

How to link turtles of different agentsets in Netlogo

Hi I'm new to NetLogo and would appreciate your assistance in creating links between agents.

I've already written this code and it doesn't create links for some reason but does not indicate an error either.

I want to randomly assign links between turtles.

`

turtles-own [wealth]

breed [consumers consumer]
breed [investors investor]


to setup
  clear-all
  setup-people
  if variant = "network" [ make-network ]
  reset-ticks
end

to setup-people
set-default-shape turtles "person"
  create-turtles initial-persons [
  setxy random-xcor random-ycor
    let breed-rand random-float 200 ;;change this into odd and even numbers later
    set wealth 1000
    ifelse breed-rand > 100 [
    set breed consumers
      set color red
    ] [
    set breed investors
    set color sky
    ]
  ]
end

to make-network
    ask turtles [
      create-links-with other turtles 
      show my-links
    ]
end

to go
  ask turtles [
  economic-activity
  ]
  tick
end

to economic-activity
  ifelse breed = consumers [
  consume
  ] [
  if breed = investors
    [invest]
  ]
end

to consume ;; turtle procedure
if breed = consumers [
    fd 5
    set wealth wealth - 1
  ]
end

to invest
  if breed = investors [
    fd 5
  set wealth wealth + 1
  ]
end`

Thanks in advance!

Best, D

Upvotes: 1

Views: 346

Answers (1)

TurtleZero
TurtleZero

Reputation: 1064

I don’t see a reason in the code that no links are created.

I am assuming that the control “variant” exists and is actually set to “network” and you didn’t misspell “network.”

To randomly link a turtle with one other turtle, you need to use “with [ not any? Link-neighbors ]” to avoid turtles that already have links and “one-of” to pick just one of those. Parentheses for emphasis of the order of evaluation. They are not required.

One-of ( ( other turtles ) with [ not any? Link-neighbors ] ) ) 

You may need additional code to handle the situation where all turtles are linked and this turtle has no available partners.

To randomly link with more than one turtle you need to decide how many links you want, or what rules determine linking.

  • by nearness?
  • a specific number of links per turtle?
  • a random number of links?
  • if random, what’s the method for determining the number?
    • (we often see this question as “what kind of distribution function?)

You will likely use the “n-of” reporter. Like

Let eligible-link-partners other turtles with [ <selection-reporter> ]
Let link-quantity <number-or-a-number-reporter>
Make-links-with n-of link-quantity Eligible-link-partners

Upvotes: 1

Related Questions