Subject: Re: setRandomlyLocatedObjects
From: Pierre Bommel (bommel@cirad.fr)
Date: Wed May 12 2004 - 20:01:52 CEST
Hello Mathias,
Mathias Rouan a écrit :
> Hello cormas forum !
>
> I just want to know what means the argument "initMethod:" in this method :
>
> setRandomlyLocatedObjects: className n: aNumber initMethod: aSymbol
> arguments: aCollec
>
> In fact, i want to randomly set my located objects in a particular
> collection of cells, but i don't understand what i have to put in the
> initMethod argument.
If you just need to put your agents randomly on the grid, you should use
"setRandomlyLocatedObjects: className n: aNumber"
It will create aNumber instances of objects. For each instance, it will call
the
#init method of this object, then it will place it on a random cell.
When creating the new instance, you can also call a particular init method.
Then you should use :
"setRandomlyLocatedObjects: className n: aNumber initMethod: aSymbol"
ex: self setRandomlyLocatedObjects: LandCover n: 10 initMethod: #initAge
The result is the same than previously except that the #initAge method is
called for each landCover.
Finally, if you need to call a specific init method that need an input
variable, you
can use :
"setRandomlyLocatedObjects: className n: aNumber initMethod: aSymbol
arguments: aCollec"
ex : self setRandomlyLocatedObjects: LandCover n: 10 initMethod: #initA:B:C:
arguments: #(1 2 3)
For the last 2 methods, an alternative could be :
self setRandomlyLocatedObjects: LandCover n: 10.
self theLandCovers do:[: lc| lc initAge]. or
self theLandCovers do:[: lc| lc initA: 1 B: 2 C: 3].
At the begining of your initialisation method, do not forget to write: self
initObjects to release the
objects of the previous simulation.
Cheers,
Pierre
***********************************
Pierre Bommel
CIRAD TA 60/15
73, rue Jean-François Breton
34398 Montpellier cedex 5 France
Phone: +33 (0)4 67 59 38 53
Fax: +33 (0)4 67 59 38 27
http://cormas.cirad.fr
***********************************