Sender: |
|
Date: |
Tue, 28 Nov 2006 14:15:44 -0500 |
MIME-version: |
1.0 (Apple Message framework v750) |
Reply-To: |
|
Content-type: |
text/plain; charset=US-ASCII; delsp=yes; format=flowed |
Subject: |
|
From: |
|
In-Reply-To: |
|
Content-transfer-encoding: |
7bit |
Comments: |
|
Parts/Attachments: |
|
|
Sure, there are lots of ways. The easiest and perhaps best:
If you're using tournament selection, then it's a piece of cake.
Just subclass your Fitness function to (a) store both fitness
elements inside it and (b) override the equivalentTo and betterThan
methods to do a lexicographic ordering between the two fitness elements.
Sean
On Nov 28, 2006, at 12:50 PM, John Woodward wrote:
> Hi,
>
> I am working on a problem where I would like to compare two
> individuals according to one fitness function (if one beats the other
> then it is promoted to the next generation).
> However, it is possible that two individuals have the same fitness, so
> to differentiate them I call on a second fitness function.
>
> Something like this
>
> ind choice(ind ind1, ind ind2) {
> if(ind1.fitness == ind2.fitness)//if they are equal
> return choice2(ind1, ind2)//call on the second fitness function
> else
> if(ind1.fitness < ind2.fitness)
> return ind1
> else
> return ind2
> }
>
> ind choice2(ind ind1, ind ind2) {
> if(ind1.fitness2 < ind2.fitness2)
> //fitness2 is the fitness according to the second
> fitness function
> return ind1
> else
> return ind2
> }
>
>
> --
> Thanks,
> John Woodward.
|
|
|