How to link actions of agents?

2019-07-20 20:00发布

I am trying to program the simulation with 3 sets of agents - A,B,C. The point is that the agents from the set A can choose to DO the action or NOT. If they decide to NOT do the action, the simulation stops. When they decide to DO the action, simulation continues to the next step, where the agents from the set B can also decide to DO the action or not. The same is here. And the agents from the set C, can also decide to DO the action or NOT, but here, the simulation in both cases stops. Here is my code:

ask turttles [
if breed = set A [ ifeslse do?= false [ set lazy]
                                        stop]
[ if breed = set B [ ifelse do1?= false [ set lazy]
                                         stop]
[ask other turtles [ if breed = set C [ ifelse do 2? = false [ set lazy
                                                               stop] ] 
                                       [set done
                                        stop] ]
                                        ]
                                      ]
                                    ]

The code does not work very good,I need somehing to link these three step, because when I export-world, I got data only from the first step

标签: netlogo
1条回答
冷血范
2楼-- · 2019-07-20 20:34

If you do stop inside of an ask, it won't cause the whole simulation to stop. It will only stop the current turtle from executing the rest of the ask.

I think you want something more like:

globals [done?]

to setup
  ...
  set done? false
  ...
end

to go
  if done? [ stop ]
  ifelse ...
    [ ask A [ do-action ] ]
    [ set done? true ]
  ifelse ...
    [ ask B [ do-action ] ]
    [ set done? true ]
  ifelse ...
    [ ask C [ do-action ] ]
    [ set done? true ]
  ...
end

But I'm guessing somewhat, since it's difficult to tell from your description what your actual intentions are. (Especially since you haven't included your real code — the coede in your question wouldn't get past the compiler.)

查看更多
登录 后发表回答