Define home area-turtles?

别说谁变了你拦得住时间么 提交于 2019-12-02 02:34:55

You can find a similar problem here which has examples too :

Spacing agents in NetLogo based on territory size

There are several ways that you can assign a territory zone to each horse, but all methods that I know have two steps, first step is in order to make sure initial home area of horses are separated from each other , So we need to create horses only in patches which has a certain distance from another patch which has a horse on it,I did not follow your method that asked patches to sprout horses and instead I created them without asking patches.

I was not sure how you defined grass? Variable for each patch but I have assigned a number of patches with grass? = true and others false. Second step is to set home-area property of each horse. If initially you moved them far away from each other they will have separate territories.

I have included a few examples here : First to use in-radius for both steps:

Breed [Horses horse]
Horses-own [home-area]
patches-own [grass?]
globals [Zone-Radius]
to setup
  clear-all
  reset-ticks
  set Zone-Radius 2
  ask patches 
  [ 
    ifelse pxcor mod 5 = 3  
    [  set Grass? true  ]
    [  set Grass? false  ]
  ]
  create-horses Number-horses  
  [ Move-to one-of patches with [Grass? and not any? other horses in-radius (Zone-Radius + 1)]
    set home-area patches in-radius Zone-Radius
    set color 25  
  ]
end 

to go

  ask horses [
    ifelse member? patch-ahead 1 home-area 
    [rt random 10 fd 1 ] ; move if next patch is in their zone
    [rt random 180]
  ]
  tick
end

In this example horses only move in the patches in their radius 2. But you can change that base on your model requirements.

In the second method you can use distance for the first step (finding empty patches with enough distance to current patch) and radius for second one (assigning home-area to each horse).

Move-to one-of patches with [Grass? and not any? other horses with [distance myself < (Zone-Radius + 1)]]
    set home-area patches in-radius Zone-Radius

If you use higher distance for finding empty patches you will have completely seprated zones. Finally , you can use distance for both steps:

Move-to one-of patches with [Grass? and not any? other horses with [distance myself < (Zone-Radius + 1)]]

    set home-area patches with [distance myself < Zone-Radius] 

I just did it another way:

Breed [Horses horse]
Horses-own [home-area]
patches-own [  concession? forest? parks?]
globals [Zone-Radius]
to setup
  clear-all
  reset-ticks
  set Zone-Radius 2

  ask n-of 500 patches [ set concession? "No" ]
  ask n-of 500 patches[ set forest? "Yes" ]
  ask n-of 500 patches[ set parks? "Yes"]



  let i 0
   while [i < Number-horses] 
   [ 
   ask one-of patches with [(concession? = "No" or forest? = "YES" or parks? = "YES" ) and (not any? horses in-radius (Zone-Radius + 2) )]
     [
       sprout-horses 1 [
       set home-area patches with [distance myself < Zone-Radius]
       let w who
       ask home-area [set pcolor red]
       set color 25  ]
     ]
     set i (i + 1)
     ]
end 

to go

  ask horses [
    ifelse member? patch-ahead 1 home-area [rt random 10 fd 1 ] [rt random 180]
  ]
  tick
end

As you can see I used while and a condition to ask patches one by one, I might be mistaken but when I ask all the n-of Number-of-horses patches with [YourCondition][...] I get the wrong results and distance between horses is not effective, maybe they are created all at the same time and therefore upon creating a horse there was no horse nearby!? I am new to these concepts and might be wrong.

This is the code and view for the one which asks patches to create horses at once here :

Breed [Horses horse]
Horses-own [home-area]
patches-own [  concession? forest? parks?]
globals [Zone-Radius]
to setup
  clear-all
  reset-ticks
  set Zone-Radius 2

  ask n-of 500 patches [ set concession? "No" ]
  ask n-of 500 patches[ set forest? "Yes" ]
  ask n-of 500 patches[ set parks? "Yes"]





   ask n-of number-horses patches with [(concession? = "No" or forest? = "YES" or parks? = "YES" ) and (not any? horses in-radius (Zone-Radius + 2) )]
     [
       sprout-horses 1 [
       set home-area patches with [distance myself < Zone-Radius]
       let w who
       ask home-area [set pcolor red]
       set color 25  ]
     ]


end 

to go

  ask horses [
    ifelse member? patch-ahead 1 home-area [rt random 10 fd 1 ] [rt random 180]
  ]
  tick
end

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!