做出不同动作的子样本中的海龟

Turtles in sub-samples which make different actions

我需要让我的 agents/turtles 进行一些操作。具体来说,我想 select,比方说,40 只乌龟,让它们随机做出一些动作,例如:

25, 15应该随机选择。 我写了以下内容

ask up-to-n-of num_of_turtles_per_tick turtles with [breed = M] [
         ifelse random-float 1 < prob
           [
           action1]
           [action2]
      ]

prob 设置为 0.5。我认为我的代码让 40 只海龟执行 action1 或 action2,无法区分海龟的两个子样本(示例中为 25,15,或 20,20,或 12 和 18 ...)。 我可能应该添加一个新参数来确定这个随机数并让它们分别进行操作。

你能给我一些建议吗? 谢谢

您希望子集互斥,因此您需要一些具有 if-else 类型逻辑的结构。但是你可以作为一个小组或单独进行。

单独的更容易理解,所以让我们从这里开始(没有测试所以可能有语法错误)。基本上你抽取一个随机数,如果它低则执行一个操作,如果它高则执行另一个操作。

to testme
  clear-all
  create-turtles 40 [setxy random-xcor random-ycor]
  ask turtles
  [ ifelse random-float 1 < 15 / 40
    [ set color blue ]
    [ set color red ]
  ]
end

对于组方法,您需要一些方法来记住执行第一个操作的组,以便您可以识别所有其他人在执行第二个操作的组中。 member? 报告器检查海龟是否是指定海龟集的成员。

to testme
  clear-all
  create-turtles 40 [setxy random-xcor random-ycor]
  let type1 n-of 15 turtles        ; assigns some to a temporary agentset
  ask type1 [ set color blue ]
  ask turtles with not member? self type1 [ set color red ]   ; gets the others
end