Messages from list : cormas@cirad.fr

Choose a topic among the following archives :

RE : Can instance variable be a sortedcollection?

New Message Reply Date view Thread view Subject view Author view

Subject: RE : Can instance variable be a sortedcollection?
From: Christophe Le Page (christophe.l@chula.ac.th)
Date: Tue May 09 2006 - 05:23:23 CEST

 

Hello Miao,

 

Instance variables can be any kind of objects, so no problem for having an
instance variable being a kind of collection.

 

If the targets don't have to be visited in a specific sequence (T1 before T2
before T3 ...), then you'd probably better to use a Dictionary where keys
would be targets and values the time-step where an agent will have visited
each of them (0 for not yet visited). This way you will record the sequence
and even the delays between visits to targets (this way you will be able to
compute statistics about target reaching efficiency).

 

For each agent, is "targets" already an instance variable?

It should probably be a kind of Set.

Assuming "targets" is known, you can prepare "records" like this:

 

initRecords

  self records: Dictionary new.

  self targets do: [:aTarget | self records at: aTarget put: 0].

 

In the main method of your Agent, you need to pass the time-step “t” as an
argument.

Then you could have something like:

 

step: t

  …

  self move. “to be defined”

 ((self targets includes: self patch) and: [(self records at: self patch)
isZero])

     ifTrue: [self records at: self patch put: t]

 

An accessing method to get the unvisited targets

unvisitedTargets

  ^self targets select: [:aTarget | (self records at: aTarget) isZero]

 

 Hope this will help you!

Best,

Clp

 

> -----Message d'origine-----

> De : owner-cormas@cirad.cirad.fr [mailto:owner-cormas@cirad.cirad.fr] De

> la part de Miao Wang

> Envoyé : mardi 9 mai 2006 06:42

> À : cormas@cirad.fr

> Objet : Can instance variable be a sortedcollection?

>

> Hi!

>

> I want to let my agents to visit several targets. I want to set a

> instance variable of agent to make a record of whether a agent has been to

> the targes.

>

> For example there are 5 targets(T1,T2,...T5) for each agent to go. Then

> the instance variable named 'Record' should be a

> sortedcollection(R1,R2,...R5), the initial value of R are all 0, then if

> the agent has been to target T1, then R1=1, if he has been to target T2,

> then R2=1, In this way the agent can have a memory and not to go to a

> target more than one time.( Target in my model is a kind of attribute of

> spatial entity-Cell, I don't want to change it's target attribute)

>

> Can instance variable be a sortedcollection? if it is possible, how can I

> connected sortedcollection T(T1,T2,...Tn) with sortedcollection

> R(R1,R2,...Rn)?

>

> It would be very appriciated if anyone can help me. Great thanks!!

>

> Forgive me for lacking knowledge of smalltalk!

>

>

> Mira

>

> Miao Wang at Geomatics

> School of Civil Engineering and Geosciences

> G.19, Cassie Building,

> University of Newcastle Upon Tyne, NE1 7RU

> England

> Email: miao.wang1@ncl.ac.uk

>

>

 

New Message Reply Date view Thread view Subject view Author view
 

Back to home