Rafaela
Rafaela

Reputation: 449

How to create variables with several levels and associate to different turtle profiles in NetLogo?

I'm stuck in a piece of code. Could someone please help me?

The question is: I have 31 turtle profiles (which varies from one turtle to another turtle is where you place the "nest" that can place the nest in any type of ground cover and then there are even more variations. experts who only place the "nest" in a specific habitat type).

But each of these profiles has 2 parameters which are: metabolism (which has 3 levels = 3 values) and reproduction energy (which also has 3 levels = 3 values). That is:

Metabolism: -level 1 -level 2 -level 3

Reproduction energy: -level 1 -level 2 -level 3

So I wanted each of the 31 turtle profiles to have these 2 parameters with these 3 levels. For example:

Profile 1: Metabolism: -level 1 -level 2 -level 3 Reproduction energy: -level 1 -level 2 -level 3

The point is that to create the 2 parameters with these values ​​3 values, I created a code as follows:

turtles-own [ energy-reproduction metabolism ] 

to setup
ask turtles [
    let a2 random-float 1.01
    (
      ifelse
      a2 <= 0.33
      [
        set energy-reproduction 5
      ]
      a2 > 0.33 and a2 <= 0.66
      [
        set energy-reproduction 25
      ]
      a2 > 0.66
      [
        set energy-reproduction 50
      ]
    )
  ]

  ask turtles [
    let a3 random-float 1.01
    (
      ifelse
      a3 <= 0.33 [
        set metabolism 2
      ]
      a3 > 0.33 and a3 <= 0.66
      [
        set metabolism 8
      ]
      a3 > 0.66
      [
        set metabolism 16
      ]
    )
  ]
end

The point is that it could be that for profile 1 the turtle has: 1 colony with metabolism 3 and two colonies with metabolism 2 and none with metabolism 1. And the idea is that all 31 profiles have each of the 3 levels of each of the 2 parameters (which is the energy of reproduction and metabolism). How could I do this?

I would greatly appreciate any help.

Upvotes: 0

Views: 54

Answers (1)

LittleLynx
LittleLynx

Reputation: 1181

If I understand you correctly, you want to have any possible combination of parameter levels in at least one turtle. Here is an example on how to create one turtle for each parameter combination, with var1, var2, var3 input via interface:

to go
  let list1 [green red blue]
  let list2 (list var1 var2 var3)
  foreach list1 [ item1 -> 
    foreach list2 [ item2 -> 
      crt 1 [
        set color item1
        set size item2
        setxy random-xcor random-ycor
      ]
    ]
  ]
end

Upvotes: 1

Related Questions