How to group agents in NetLogo and ask them to sta

2019-07-31 07:04发布

I have slightly problem in keeping a group of agents moving together in NetLogo world

Here is what I want to do. I want them to stay in group while moving, the rules to keep them in groups are BOIDS, which I'm gonna apply "separate,cohere and align" codes within groups.

Here is my code. This is global code

globals[                  ;;;;;;;;;;;;;;;;global variables;;;;;;;;;;;;;;;;;;;;;;
  t-bp                        ;;time taken in ticks
  t-time                      ;;time taken in seconds
  groups
]

Here is what the turtles has

  turtles-own[               
  food-found         
  on-food            
  see-food           
  my-group
]

this is setup code

   to setup
  clear-all
  set-default-shape turtles "arrow"

   ask turtles                          ;;;;;agents setup;;;;;;;;
  [ set size 2.0
    set color blue
    set count-down 30
    set happy? set?
    set on-food 0
    set see-food 0
  ]
 let number-of-groups 5
  let turtles-per-group 4  
  create-turtles turtles-per-group * number-of-groups 

  set groups [] ; empty list
  repeat number-of-groups [
    let new-group n-of turtles-per-group turtles with [
      not is-agentset? my-group
    ]
    ask new-group [ set my-group new-group ]
    set groups lput new-group groups
  ]

  print (word "First group:  " sort first groups)
  print (word "Second group: " sort last groups)
  ask turtles [ show sort other my-group ]
end

after they found their group, they need to follow their group around. here is to go code

to go  
                                      ;;;;;;;;;;;;;;;;;agents procedure;;;;;;;;;;;;;;
  ask turtles 

 [  call-eat                                     ;;;;;;;turtle movement;;;;;;;;;;;;;;;
   ifelse food > 0
   [stay]          ;;eat food;;
   [continue            ;;walk to other places to find food;;
    turn-towards]

   ;;;;setup for agents foraging styles;
    if (Forage-style = "Eat,Inspect and Stop") [set Scale -30]
    if (Forage-style = "Eat and Walk") [set Scale 0]
    if (Forage-style = "Stop and Eat") [set Scale -15]

ask turtle 1
[if not any? patches with [food > 0]
  [
    show ticks stop]
  ]
end

this is how I code them to walk throughout world

to walk                                                                                    
if any? patches in-cone vision-distance 40 with [food > 0]  [set see-food 1
    face min-one-of patches in-cone vision-distance 40 with [food > 0][distance myself]
      fd distance min-one-of patches in-cone vision-distance 40 with [food > 0][distance myself] * 0.002]
end 

The problem is, I don't know how to move them in group and where to apply BOIDS.

And if I want agents to check patches without food, is this the right way?

ask turtle 1
[if not any? patches with [food > 0]
  [
    show ticks stop]
  ]
end

Ways to group agents within group is answered in this post How to send parameters using NetLogo?

Thank you.

0条回答
登录 后发表回答