Messages from list : cormas@cirad.fr

Choose a topic among the following archives :

Re: How to restrict initAgents?

New Message Reply Date view Thread view Subject view Author view

Subject: Re: How to restrict initAgents?
From: Pierre Bommel (bommel@cirad.fr)
Date: Mon Mar 06 2006 - 16:28:34 CET

Dear Mira,

To create and put your agents on restricted cells, you should write a
method. For example :

setRandomlyLocatedAgents: aClass n: aNumber constrainedBy: aBlock
    " The new agents are randomly located on the cells verifying the
constraint "
        | a targetCell |
        aNumber timesRepeat:
                        [targetCell := Cormas selectRandomlyFrom: (self theESE select: [:c |
aBlock value: c]).
                        targetCell isNil
                                ifTrue:
                                        [Dialog warn: 'No available cell for the constraint. The
simulation will stop'.
                                        self halt].
                        a := self newEntity: aClass.
                        a perform: aSymbol withArguments: aCollec.
                        a moveTo: targetCell]

Then in your init, you can add :
    super initAgents.
    self setRandomlyLocatedAgents: Tourist n:100 constrainedBy: [:cell |
cell state=#land or:[cell state=#street]].

By adding the 2 joined .ST files, it is not necessary to create the
"setRandomlyLocatedAgents:n:constrainedBy:" method.

Remark: These methods will be in the next Cormas release (+
randomCellConstrainedBy: aBlock)

        Pierre

Le 6 mars 06, à 10:55, Miao Wang a écrit :

> Hi all!
>
> I have imported a map into Cormas and I'm trying to simulate crowds
> walking in the streets.Now I have some problems:
>
> according to the tutorial, after I identified the intAgents in
> instance-creation like this
>
> initAgents
> super initAgents.
> self setRandomlyLocatedAgents: Tourist n:100
>
> The 100 agents are ramdomly standing all over the visualisation space
> window ,no matter which attibute the cell has(river or building or
> even out of the map(no value area)).But what I want is just to let the
> 100 agents been restricted in cells with attributes of 'lands' or
> 'streets'.
>
> I thought a conditonal test is needed. so I add:
>
> super initAgents.
> self patch state=#Lands ifTrue:[self setRandomlyLocatedAgents:
> Tourist n:100].
>
> But Cormas show:
>
> "Unhandled exception:message not understood:#patch."
patch is a method of AgentLocation (it returns the cell on which is
located the agent). It is not a method of CormasModel.

>
> Is there anyone who can give me some idea about it?
>
> Thank you very much!
>
> Mira
>
>
>
>
        Pierre Bommel - CIRAD - UR Green
        Universidade de Brasilia - CDS
        SHIS QI 26, Conjunto 15, Casa 18
        71670-150
        Brasilia DF
        tel: (00 55 61) 3367 3405
        http://www.cirad.fr/ur/green

New Message Reply Date view Thread view Subject view Author view
 

Back to home