Define home area-turtles?

2019-02-26 07:44发布

I am very new to netlogo. I have searched every question here before I posted this.

I have the following code which sprouts a given number of horses:

ask n-of Number-horses patches with [grass? = "Yes"] [sprout-horses 1 [set color 25 ]]

The person can change the number of horses using the slider but I would like each horse to have its own area/range/radius.

They can only move within this radius/area and they cannot meet each other.

From what I've read it's got something to do with the distance function?

3条回答
一夜七次
2楼-- · 2019-02-26 08:02

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

enter image description here

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

enter image description here

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] 

enter image description here

查看更多
smile是对你的礼貌
3楼-- · 2019-02-26 08:09

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

enter image description here

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

enter image description here

查看更多
看我几分像从前
4楼-- · 2019-02-26 08:13

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

Spacing agents in NetLogo based on territory size

查看更多
登录 后发表回答