如何更改代理角色

时间:2014-03-19 13:06:02

标签: netlogo

我是netlogo的新手,我真的需要一些帮助。我的问题是:我正在尝试使用3套代理进行模拟:公司,官员和公民。事情是:我一起有10个人/海龟,我需要将它们分成3组,但我还需要,在开始时,每只乌龟可以选择他想要属于哪一组代理人...... .......所以每次我点击设置底部,代理商都可以改变他们的角色。 谢谢你的帮助。埃里卡 我的代码是:

breed [firms firm]
breed [ officers officer]
breed [ citizens citizen]

to setup
  clear-all
  create-turtles num-of-firms[  
    set color blue
    set xcor random-xcor
    set ycor random-ycor
    ]
  create-turtles num-of-officers [ 
   set color green
   set xcor random-xcor
   set ycor random-ycor
   ]
  create-turtles num-of-citizens [ 
   set color white
   set xcor random-xcor
   set ycor random-ycor
  ] 
 set-default-shape turtles "person" 
 reset ticks

1 个答案:

答案 0 :(得分:3)

每个NetLogo乌龟都有一个内置的breed variable,您可以用它来动态改变乌龟的品种。

如果你想创建一些代理商总数(例如100)并让每个代理商随机选择它所属的品种,你可以这样做:

breed [ firms firm]
breed [ officers officer]
breed [ citizens citizen]

to setup
  clear-all
  set-default-shape turtles "person" 
  create-turtles 100 [  
    set xcor random-xcor
    set ycor random-ycor
  ]
  ask turtles [ 
    set breed one-of (list firms officers citizens)
  ]
  ask firms [ set color blue ]
  ask officers [ set color green ]
  ask citizens [ set color white ]
  reset-ticks
end