NetLogo max number of turtles on patches

classic Classic list List threaded Threaded
3 messages Options
xc
Reply | Threaded
Open this post in threaded view
|

NetLogo max number of turtles on patches

xc
Hi, i'm creating a model of densification of city.

my agent must reach the most attractive patches but there is a constrain, a limit of densification. if the limit of densification is exceede they must reach another patch. the ones who find the right place they schould stay

so i don't know how to implement this on NetLogo. Here my code

to go

 ask turtles [

    set new-densite pop_dens + count turtles-here
    let free-patches patches with [new-densite <= limite-densite ]
   
    ifelse (new-densite >= limite-densite) [move-to one-of free-patches]
      [find-new-spot]
  ]

  tick

end

to find-new-spot

let free-patches patches with [new-densite <= limite-densite and lac <= 0]
move-to max-one-of free-patches [attractivity]


end
Reply | Threaded
Open this post in threaded view
|

Re: NetLogo max number of turtles on patches

NetLogo-Users mailing list
On 8/7/2017 8:05 AM, xc [hidden email] [netlogo-users] wrote:

>
> Hi, i'm creating a model of densification of city.
>
> my agent must reach the most attractive patches but there is a
> constrain, a
> limit of densification. if the limit of densification is exceede they must
> reach another patch. the ones who find the right place they schould stay
>
> so i don't know how to implement this on NetLogo. Here my code
>
> to go
>
> ask turtles [
>
> set new-densite pop_dens + count turtles-here
> let free-patches patches with [new-densite <= limite-densite ]
>
> ifelse (new-densite >= limite-densite) [move-to one-of free-patches]
> [find-new-spot]
> ]
>
> tick
>
> end
>
> to find-new-spot
>
> let free-patches patches with [new-densite <= limite-densite and lac <= 0]
> move-to max-one-of free-patches [attractivity]
>
> end
>
Hello,


     You should look in the Models Library under the code examples
section for the "One Turtle Per Patch" Example which shows how to use
the code which I have highlighted in *bold* below


  let move-candidates (patch-set patch-here (patches at-points
vision-points) with [*not any? turtles-here*])
   let possible-winners move-candidates *with-max [psugar]*
   if any? possible-winners [
     ;; if there are any such patches move to one of the patches that is
closest
*move-to min-one-of possible-winners [distance myself]


*Also look up in the Netlogo dictionary***with-min* and *with-max*
Reply | Threaded
Open this post in threaded view
|

Re: NetLogo max number of turtles on patches

NetLogo-Users mailing list
On 8/9/2017 11:18 AM, Carl Payne [hidden email]
[netlogo-users] wrote:

>
> On 8/7/2017 8:05 AM, xc [hidden email] [netlogo-users] wrote:
>>
>> Hi, i'm creating a model of densification of city.
>>
>> my agent must reach the most attractive patches but there is a
>> constrain, a
>> limit of densification. if the limit of densification is exceede they
>> must
>> reach another patch. the ones who find the right place they schould stay
>>
>> so i don't know how to implement this on NetLogo. Here my code
>>
>> to go
>>
>> ask turtles [
>>
>> set new-densite pop_dens + count turtles-here
>> let free-patches patches with [new-densite <= limite-densite ]
>>
>> ifelse (new-densite >= limite-densite) [move-to one-of free-patches]
>> [find-new-spot]
>> ]
>>
>> tick
>>
>> end
>>
>> to find-new-spot
>>
>> let free-patches patches with [new-densite <= limite-densite and lac
>> <= 0]
>> move-to max-one-of free-patches [attractivity]
>>
>> end
>>




Hello,


     You might try modifying your code "ifelse (new-densite >=
limite-densite) [move-to one-of free-patches] [find-new-spot] " to read
like this
"foreach sort free-patches *[* X -> ifelse*(* [new-densite] of X >=
limite-densit *)* [move-to one-of free-patches] [find-new-spot]*]*"  .


     The "foreach" command takes each and every object from a /list/ or
from /many lists/ and then runs a command which uses those objects as
inputs to produce some output.  The format for this "foreach" command is
as follows: "foreach /list/ /command" . /In the code that I wrote above,
"foreach /sort free-patches/ *[* X -> ifelse*(* [new-densite] of X >=
limite-densit *)* [move-to one-of free-patches] [find-new-spot]*]*"  , I
used the "/sort"/ command on "/free-patches" /to create a list of free
patches so the /"foreach"/ command could act on it.  The command in the
brackets is called an "anonymous procedure" because it uses the "->"
command in it.   I used it because it does not need a formally defined
"to insert-name-here ...   ... end" procedure, but rather can be defined
inside those brackets with the "->" symbol.  It should take each and
every item in the sorted list of patches given by "sort free-patches"
and represent each one with the "X" symbol and then apply the
"[new-densite] of X  >= limite-densit" reporter of the "ifelse**(
[new-densite] of X >= limite-densit )" statement to it.  The reporter
"[new-densite] of X" should report a /number/ so /"limite-densit"/ must
also be a number if the "ifelse**(**[new-densite] of X >= limite-densit
)" is to work.


     Also if you need each patch to have only one turtle on it, then you
can use the command "with [not any? turtles-here])"  from this line of
code from the Sugarscape 2 - Constant Growback model  "let
_move-candidates (patch-set patch-here (patches at-points
vision-points)_ /with//[not any? turtles-here]/".  The underlined
segment of code can be replaced with anything as long as it is an
agent-set.


I hope this helps.