[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Building objects on the fly
From: |
Jae Chan Oh |
Subject: |
Re: Building objects on the fly |
Date: |
Mon, 10 Mar 1997 19:26:16 -0500 (EST) |
>
>
> joh> Do we need to use "buildObjects" whenever creating a new object?
>
> To this question, I give a resounding "No!" Not only is it
> unecessary to "build" all the objects in a swarm in a special
> "buildObjects" method; but, *I* claim that it can sometimes
> be very artificial to do so. (I have no idea if anybody agrees
> with me on this, so don't take my word as an expert.)
>
Thanks, Glen, that's what I'm doing now. So nice to be able to make sure
that what I'm doing is right. :-)
Still some questions arise though.
>
> [myModelSchedule at: getCurrentTime() +1 createActionTo: self
> message M(giveBirthWithGenome:) : (id)genome];
In my simulation, the Model Swarm does not know -- at least not directly --
about births of individuals.
The simulation is like people running around in the world, if it happen to
bump into a likable person, they mate -- therefore, each person only
knows about birth of its child, much like the real world situation.
Now when a child is created, the genome for the child is also created.
Since I'm using GA lib written by J.J. Merelo -- I have modified/added
some functionality though --, the genome is also an object. So that
I would need to create the genome when creating a Person as well.
Here's how I do it.
-mateWith: (id) person // person is ptr to the person I want to mate with
{
Person * child;
// some stuff deleted
// OK, NOW generate a offspring
child = [self createChild];
[[child getPersonDNA] Mate: [self getPersonDNA] And: [person getPersonDNA]
withMutation: MUTATION_RATE];
return self;
}
*********** Then in my createChild,
-(id) createChild
{
Person * child;
child = [Person createBegin: [self getZone]];
..... setup some stufF
[child setPerson: id]; // create dna, set-up something...
// tell the child where she is
[child setWorld: pplPresent World: world ReaperQ: reaperQueue];
..... setup some stufF
// finish the create phase
child = [child createEnd];
// add the child to the list of people
[pplPresent addLast: child];
return (id) child;
}
And in setPerson
-setPerson: (int) n
{
iD = n;
numOfFriends = 0; // no friends made so far
live = TRUE; // yes, it has just born
// create Chromosomes etc
dna = [BinChromosome createBegin: [self getZone]];
[[dna setLength: (int) (GEN_LENGTH/8)] setRandomInit];
dna = [dna createEnd];
[self setEvalFuncFromModel];
return self;
}
Do you see anything wrong in the above code?
Also one more question about your code below...
What is myParentSwarm? Can I use [self getZone] instead? That's what I'm
doing. Whenever I need an object whether the new object is logically
belongs to another object -- like in the case of Person object and
Genome Object above -- I get a new Zone using [self getZone] message.
Is it OK? I thought about using [dna getZone] but that doesn't seem to work.
>
> Then in the Person class, you might have the method:
>
> -(id) giveBirthWithGenome: (id) genome {
> id newPerson;
>
> [ ... blahblahblah ...]
>
> newPerson = [Person createBegin: myParentSwarm];
^^^^^^^^^^^^^^^^
So why this, instead of [self getZone]?
>
> Now, there should be some message that the modelSwarm can
> accept to tell it to add the new person to the appropriate
> lists and the space and such. But, the creation of the
> individuals should be abstracted from the system you're trying
> to model.
Well, as I said above, I add new persons in Person.m. Do you mean that
I have to let the ModelSwarm know about the adding the new Person explictly
using a method? Since the pointer pplList is known to both ModelSwarm and
Person objects, wouldn't it reflect the changes in pplList from the ModelSwarm's
view if we change the pplList in a Person object?(i.e. adding a new Person)
Thank you very much for your help!
-Jae
- problem with raster, Kevin Crowston, 1997/03/06
- Re: problem with raster, Kevin Crowston, 1997/03/06
- Re: problem with Raster, Sven Thommesen, 1997/03/06
- Re: problem with Raster, mcmullin, 1997/03/10
- Re: problem with Raster, Jae Chan Oh, 1997/03/10
- Building objects on the fly, glen e. p. ropella, 1997/03/10
- Re: Building objects on the fly,
Jae Chan Oh <=
- Re: Building objects on the fly, glen e. p. ropella, 1997/03/11
- Re: Building objects on the fly, Jae Chan Oh, 1997/03/11
- Re: Building objects on the fly, glen e. p. ropella, 1997/03/11
- "zone" or "getZone"? and one additiona question., Jae Chan Oh, 1997/03/13
- Classifier systems, Tony Bigbee, 1997/03/13
- Maintaining a Debian Swarm package, Thor Sigvaldason, 1997/03/14
- Re: Maintaining a Debian Swarm package, Karl Sackett, 1997/03/14
- Re: Classifier systems, Rick Riolo, 1997/03/14
- "zone" or "getZone"? and one additiona question., J.J. Merelo Guervos, 1997/03/14
- Re: "zone" or "getZone"? and one additiona question., Jae Chan Oh, 1997/03/14