如何在 NetLogo 中创建可变参数?

How to create a variable parameter in NetLogo?

我是 NetLogo 的新手,我有一个问题,如果有人能帮助我,我将不胜感激:)

我有一个 90x90 的世界。世界上的每一个补丁都有一个资源值(从10000到无穷大的最小值的资源变量,整数)。世界上我有60只乌龟。

我希望每个滴答声都有一个影响整个世界的参数。从 0 到 1 的值将在资源变量中相乘

我想计算一下:

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

但是,我无法实现上面的一些细节。 我试图删除 .txt 中的文件。但是,我不知道该怎么做。例如,为每个补丁分配一个值。抱歉...

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

提前致谢

为了让所有补丁都具有相同的值,您必须定义一个全局变量,例如resource-availability:

globals [resource-availability]

每个模拟集,resource-availability会被设置为0到1之间的随机值:

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

因为您希望海龟没有 resource-turtle 那样的分数值,您必须以某种方式舍入 resources * resource-availability,使用 ceilingfloorround.

在下面的例子中,我使用了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