[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Swarm-Support] Re: Opinions among swarm agents
From: |
gepr |
Subject: |
Re: [Swarm-Support] Re: Opinions among swarm agents |
Date: |
Fri, 4 Apr 2003 08:25:14 -0800 |
Kanagaraj Krishna writes:
> Thanks. What if each agent has to store not only one info on a
> particular agent but all the other agents that it meets in the
> society. That would be multiple agent infos. Would any array or
> list that keeps this objects be helpful?
>
> What would be the best way to do this and the one that doesn't take
> a lot of resources.
I think Steve's suggestion of a class or data structure that is
specifically formatted to contain the profile of a "contact" is the
right way to do it. At least, it's the object-oriented way to do it.
So, create a class like
@interface Contact
{
@public
id <String> address;
id <String> given_name;
id <String> surname;
id <String> phone_number;
id <String> type_of_dog_they_have;
}
@end
Then use a collection to keep track of each Contact by keying off one
of those fields. If you use a Map, you can use any one of the fields
(or anything else, actually) as the key. If you use an Array, you can
just write your own lookup function by walking the array querying the
particular field, etc. Whether or not you use an Array or a Map
depends on how you will access and edit the data structure. If you
intend to always walk the list of contacts in a linear order, use an
Array. If you will always be pulling 1 contact out at a time and will
always do that via the key, then use a Map.
So, a Map might look like:
bob -> 1120 Timor St.; Santiago; Chile
Robert
Jackson
123-456-7890
snauzer
sally -> 450 Gila Dr.; Las Cruces, NM; USA
Sally
Struthers
098-765-4321
irish setter
...
You'd access the values by saying something like:
contact = java.util.Map.get(bob);
System.out.println("Bob has a " + bob.type_of_dog_they_have + ".");
Also, don't forget about the ability to set the predicates for
searching and manipulating the data structure. Whatever collection
you use, there should be a way to override the default compare function or
install new ways to subset the data.
You might also consider hooking the model up to a relational database.
If you have alot of data and you will be doing alot of mixing and
matching of that data to come up with "report-like" things, then
a relational database might be the way to go instead of these OO
data structures.
--
glen e. p. ropella =><= Hail Eris!
H: 503.630.4505 http://www.ropella.net/~gepr
M: 831.247.7901 http://www.tempusdictum.com