5 boxes

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

5 boxes

t.s.wonder
Hello Netlogo users,
 

 How to write a code to send a fifth of turtles to each of five boxes?
  Thank you in advance
 

 

Reply | Threaded
Open this post in threaded view
|

Re: 5 boxes

t.s.wonder
I mean,
 

---In [hidden email], <t.s.wonder@...> wrote :

 Hello Netlogo users,
 

 How to write a code to send a fifth of turtles to each of five boxes?
  Thank you in advance
 

 I mean
 let fifth n-of (count turtles / 5) turtles
    ask fifth [move-to one-of box1]
    ask fifth [move-to one-of box2]
    ask fifth [move-to one-of box3]
    ask fifth [move-to one-of box4]
    ask fifth [move-to one-of box5]
 The result is
 Box1, Box2, Box3 and Box4 have 0 turtles
 and Box5 has all turtles


 



Reply | Threaded
Open this post in threaded view
|

Re: 5 boxes

guerrin
>The result is Box1, Box2,  Box3 and Box4 have 0 turtles and Box5 has all turtles


Of course, you obtain this result because you determine at each
time-step a turtle-set which passes from one box to the other until the
last where they stay (the same turtles pass through all of the 5 boxes
and remaain in the last).


If you want get rid of this you need first to distinguish the boxes from
outside of the boxes (for example giving them a specific color) and
second to iterate successively the assignment of 1/5^th of the total
turtle number to each box.


patches-own [box-nb] ; patches may have a number as an attribute




to Init


clear-all


reset-ticks
create-boxes ; make some patches as boxes


crt n-turtles ; create any number of turtles


ask turtles [move-to one-of patches with [pcolor != red]] ; turtles are
spread over the world but on patches that are not boxes


end




to create-boxes ; create patches as boxes


foreach [1 2 3 4 5]


[? -> ask one-of patches [set box-nb ? set pcolor red] ] ; assign
successively both a number (1, 2, 3, 4 and 5) and the color red to each
of 5 patches


end




to go


let fifth int (count turtles with [pcolor != red] / 5) ; determine
“fifth” as the number of 1/5^th of turtles not located in a box. int is
to avoid part of turtles...


foreach [1 2 3 4 5] ; anonymous variable ? = 1, 2, 3, 4, 5 iteratively
selected


[? ->


let turtles-fifth n-of fifth turtles with [pcolor != red] ; determine a
turtle-set of “fifth” turtles


ask turtles-fifth[move-to one-of patches with [box-nb = ?]] ; ask these
turtles to move to a box with number “?”


]


end




Le 25/01/2018 à 09:30, [hidden email] [netlogo-users] a écrit :

>
> I mean,
>
>
>
> ---In netlogo-users@yahoogroups...com, <t.s.wonder@...> wrote :
>
> Hello Netlogo users,
>
>
> How to write a code to send a fifth of turtles to each of five boxes?
>  Thank you in advance
>
> I mean
> let fifth n-of (count turtles / 5) turtles
>     ask fifth [move-to one-of box1]
>     ask fifth [move-to one-of box2]
>     ask fifth [move-to one-of box3]

>     ask fifth [move-to one-of box4]
>     ask fifth [move-to one-of box5]
> The result is
> Box1, Box2, Box3 and Box4 have 0 turtles
> and Box5 has all turtles
>
>
>


--

SignatureMail-FG.png (33K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: 5 boxes

t.s.wonder
thank you Francois for your inspiring code!