Rafaela
Rafaela

Reputation: 449

How to create a variable parameter in NetLogo?

I am new in NetLogo and I have a question, if anyone can help me I would appreciate it :)

I have a 90x90 world. Each patch in the world has a resource value (resource variable that has the smallest value from 10000 to infinity, integers). In the world I have 60 turtles.

I would like every tick to have a parameter that affects the world as a whole. A value drawn from 0 to 1 that will be multiplied in the resource variable

And I would like to compute that:

the resource of the turtles is = the value of the patch * (the parameter that affects the whole world) - its metabolism

But, I'm not able to implement some details above. I tried to remove the file in .txt. But, I don't know how to do that. For example assigning a value to each patch. Sorry...

globals [ edge-size ]
turtles-own [ metabolism resource-turtle ]
patches-own [ resources ]

to setup
 ca
  reset-ticks
  set edge-size 90
  set-patch-size 12
  ask n-of 60 patches  [sprout 1 [ setup-turtles ] ]
  setup-patches
end

to setup-patches
  file-open "resource.txt"
  foreach sort patches [ p ->
    ask p [
      set resources file-read       
    ]
  ]
  file-close
end
 
to setup-turtles
  set metabolism 4
  set resource-turtle [ resources ] of patch-here
end 

to go  
  ask turtles [
    right random 360
    fd 1
    turtle-eat
    reproduction
    if ticks <= 10 [ die ]
  ]
  parameter-world
  
  tick  
end

to turtle-eat   
 set resource-turtle (resources - metabolism )   ;; Here it doesn't do exactly what I want it to do: the resource of the turtles is = the value of the patch * (the parameter that affects the whole world) - its metabolism
end

to reproduction
  if (resource-turtle > 5) [
    hatch 1
  ]
end

to parameter-world ;; And the probability parameter leaves the patch with fractional values... Is this the best way to implement this probability?
  ask patches [
      let prob random-float 2
     set resources resources * prob
   ]
end

Thanks in advance

Upvotes: 0

Views: 319

Answers (1)

LittleLynx
LittleLynx

Reputation: 1181

In order to have the same value for all patches, you must define a global variable, for example resource-availability:

globals [resource-availability]

Each simulation set, the resource-availability will be set to a random value between 0 and 1:

to set-resource-availability
 set resource-availability random-float 1
end

Because you want the turtles to not have fractional values as resource-turtle, you must round resources * resource-availability in someway, using ceiling, floor or round.

In the following example, I used ceiling:

globals [resource-availability]
turtles-own [ metabolism resource-turtle ]
patches-own [ resources ]

to setup
 ca
  reset-ticks
  ask n-of 2 patches  [sprout 1 [ setup-turtles ] ]
  setup-patches
end

to setup-patches
  ask patches 
  [ 
    set resources random 50 + 50
  ]
end

to setup-turtles
  set metabolism 4
  set resource-turtle [ resources ] of patch-here
end

to go
  set-resource-availability
  ask turtles 
  [
    turtle-eat
  ]
  tick
end

to turtle-eat
 set resource-turtle (ceiling(resources * resource-availability) - metabolism )
end

to set-resource-availability
 set resource-availability random-float 1
end

Upvotes: 2

Related Questions