Custom genes?

View: New views
5 Messages — Rating Filter:   Alert me  

Custom genes?

by Ary Junior-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi, in my application, each individual have 6 genes, see below:

...
Gene[] genotype = new Gene[6];
genotype[0] = new DoubleGene(conf, 0.5, 1.5);
genotype[1] = new DoubleGene(conf, 0.5, 1.5);
genotype[2] = new DoubleGene(conf, 0.5, 1.5);
genotype[3] = new DoubleGene(conf, 0.00, 360.00);
genotype[4] = new DoubleGene(conf, -90.00, 90.00);
genotype[5] = new DoubleGene(conf, -90.00, 90.00);
...

Now, I want to restrict the crossover operation. When two solutions are mating, the genes 0, 1 and 2 must be swaped together. The same for genes 3, 4 and 5. To solve my problem I need define my own custom genes?

Thanks very much!!!

Ary Junior

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
jgap-users mailing list
jgap-users@...
https://lists.sourceforge.net/lists/listinfo/jgap-users

Re: Custom genes?

by Klaus Meffert-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ary,
 
please also consider implementing a custom crossover operater. See SwappingMutationOperator for an example, which may be helpful (although it targets at mutation).
 
Best
 


From: jgap-users-bounces@... [mailto:jgap-users-bounces@...] On Behalf Of Ary Junior
Sent: Thursday, May 22, 2008 5:40 PM
To: jgap-users@...
Subject: [jgap-users] Custom genes?

Hi, in my application, each individual have 6 genes, see below:

...
Gene[] genotype = new Gene[6];
genotype[0] = new DoubleGene(conf, 0.5, 1.5);
genotype[1] = new DoubleGene(conf, 0.5, 1.5);
genotype[2] = new DoubleGene(conf, 0.5, 1.5);
genotype[3] = new DoubleGene(conf, 0.00, 360.00);
genotype[4] = new DoubleGene(conf, -90.00, 90.00);
genotype[5] = new DoubleGene(conf, -90.00, 90.00);
...

Now, I want to restrict the crossover operation. When two solutions are mating, the genes 0, 1 and 2 must be swaped together. The same for genes 3, 4 and 5. To solve my problem I need define my own custom genes?

Thanks very much!!!

Ary Junior

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
jgap-users mailing list
jgap-users@...
https://lists.sourceforge.net/lists/listinfo/jgap-users

Re: Custom genes?

by socratesone :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Having a custom crossover function seems to me the better approach, however that doesn't necessarily mean that creating custom genes is a bad idea. You might want to go with both.

For instance:
Gene[] genotype1 = new Gene[6];
Gene[] genotype2 = new Gene[6];

genotype1[0] = new DoubleGene(conf, 0.5, 1.5); // same goes for 1 and 2 in the array
genotype1[3] = new CustomGene(conf, 0.00, 360.00); // same goes for 4 and 6 in the array

genotype2[0] = new DoubleGene(conf, 0.5, 1.5);
genotype2[3] = new CustomGene(conf, 0.00, 360.00);

Gene[] newGenotype = CustomCrossover(genotype1, genotype2);

Creating a custom crossover would allow you to alter whatever genes you wanted, either by array index or, if you decide to go with custom genes, by the gene subclass.

Creating a custom gene would allow greater flexibility when making changes, clearly identify it in the code as a different kind of Gene (which it is) and would give more information to the custom crossover function. Determining the gene based on subclass rather than array index may also allow you to incorporate additional genes into individuals through mutation, letting a "smart" custom crossover function adapt to more (or less) than 6 genes, if you ever decided to change the genotype class or create a sub-class that can handle a dynamic array length.

Ary Junior-3 wrote:
Hi, in my application, each individual have 6 genes, see below:

...
Gene[] genotype = new Gene[6];
genotype[0] = new DoubleGene(conf, 0.5, 1.5);
genotype[1] = new DoubleGene(conf, 0.5, 1.5);
genotype[2] = new DoubleGene(conf, 0.5, 1.5);
genotype[3] = new DoubleGene(conf, 0.00, 360.00);
genotype[4] = new DoubleGene(conf, -90.00, 90.00);
genotype[5] = new DoubleGene(conf, -90.00, 90.00);
...

Now, I want to restrict the crossover operation. When two solutions are
mating, the genes 0, 1 and 2 must be swaped together. The same for genes 3,
4 and 5. To solve my problem I need define my own custom genes?

Thanks very much!!!

Ary Junior

Parent Message unknown Re: Custom genes?

by Ary Junior-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Well, if the private method org.jgap.impl.CrossOverOperator.doCrossover(...) were public, it would be easier... I just need to extends the CrossOver operator and override this method to personalize only the crossover logic... right?

On Thu, Jun 5, 2008 at 10:08 AM, Ary Junior <aryjunior@...> wrote:
Hi, thanks for your reply... I'm thinking about create my own CrossoverOperator based on source code:

http://jgap.cvs.sourceforge.net/jgap/jgap/src/org/jgap/impl/CrossoverOperator.java?view=log

My genotype is ever an DoubleGene[] array with n*6 elements. What do you think?


On Wed, Jun 4, 2008 at 9:18 PM, socratesone <socratesone@...> wrote:

Having a custom crossover function seems to me the better approach, however
that doesn't necessarily mean that creating custom genes is a bad idea. You
might want to go with both.

For instance:
Gene[] genotype1 = new Gene[6];
Gene[] genotype2 = new Gene[6];

genotype1[0] = new DoubleGene(conf, 0.5, 1.5); // same goes for 1 and 2 in
the array
genotype1[3] = new CustomGene(conf, 0.00, 360.00); // same goes for 4 and 6
in the array

genotype2[0] = new DoubleGene(conf, 0.5, 1.5);
genotype2[3] = new CustomGene(conf, 0.00, 360.00);

Gene[] newGenotype = CustomCrossover(genotype1, genotype2);

Creating a custom crossover would allow you to alter whatever genes you
wanted, either by array index or, if you decide to go with custom genes, by
the gene subclass.

Creating a custom gene would allow greater flexibility when making changes,
clearly identify it in the code as a different kind of Gene (which it is)
and would give more information to the custom crossover function.
Determining the gene based on subclass rather than array index may also
allow you to incorporate additional genes into individuals through mutation,
letting a "smart" custom crossover function adapt to more (or less) than 6
genes, if you ever decided to change the genotype class or create a
sub-class that can handle a dynamic array length.


Ary Junior-3 wrote:
>
> Hi, in my application, each individual have 6 genes, see below:
>
> ...
> Gene[] genotype = new Gene[6];
> genotype[0] = new DoubleGene(conf, 0.5, 1.5);
> genotype[1] = new DoubleGene(conf, 0.5, 1.5);
> genotype[2] = new DoubleGene(conf, 0.5, 1.5);
> genotype[3] = new DoubleGene(conf, 0.00, 360.00);
> genotype[4] = new DoubleGene(conf, -90.00, 90.00);
> genotype[5] = new DoubleGene(conf, -90.00, 90.00);
> ...
>
> Now, I want to restrict the crossover operation. When two solutions are
> mating, the genes 0, 1 and 2 must be swaped together. The same for genes
> 3,
> 4 and 5. To solve my problem I need define my own custom genes?
>
> Thanks very much!!!
>
> Ary Junior
>
>

--
View this message in context: http://www.nabble.com/Custom-genes--tp17410129p17659515.html
Sent from the jgap-users mailing list archive at Nabble.com.


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
jgap-users mailing list
https://lists.sourceforge.net/lists/listinfo/jgap-users



-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
jgap-users mailing list
jgap-users@...
https://lists.sourceforge.net/lists/listinfo/jgap-users

Re: Custom genes?

by socratesone :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sounds right to me. I didn't realize that crossover function was
private. That does make it more difficult. I think you're right,
though, and creating a subclass of CrossoverOpperator and overriding
CrossoverOperator() or even operate() should do the trick.

As far as making the custom genes goes, you're probably right. You
could be just end up giving yourself more work, which would be
unnecessary if you are committed to the 6-gene genotype.

On Thu, Jun 5, 2008 at 9:19 AM, Ary Junior <aryjunior@...> wrote:

> Well, if the private method org.jgap.impl.CrossOverOperator.doCrossover(...)
> were public, it would be easier... I just need to extends the CrossOver
> operator and override this method to personalize only the crossover logic...
> right?
>
> On Thu, Jun 5, 2008 at 10:08 AM, Ary Junior <aryjunior@...> wrote:
>>
>> Hi, thanks for your reply... I'm thinking about create my own
>> CrossoverOperator based on source code:
>>
>>
>> http://jgap.cvs.sourceforge.net/jgap/jgap/src/org/jgap/impl/CrossoverOperator.java?view=log
>>
>> My genotype is ever an DoubleGene[] array with n*6 elements. What do you
>> think?
>>
>> On Wed, Jun 4, 2008 at 9:18 PM, socratesone <socratesone@...> wrote:
>>>
>>> Having a custom crossover function seems to me the better approach,
>>> however
>>> that doesn't necessarily mean that creating custom genes is a bad idea.
>>> You
>>> might want to go with both.
>>>
>>> For instance:
>>> Gene[] genotype1 = new Gene[6];
>>> Gene[] genotype2 = new Gene[6];
>>>
>>> genotype1[0] = new DoubleGene(conf, 0.5, 1.5); // same goes for 1 and 2
>>> in
>>> the array
>>> genotype1[3] = new CustomGene(conf, 0.00, 360.00); // same goes for 4 and
>>> 6
>>> in the array
>>>
>>> genotype2[0] = new DoubleGene(conf, 0.5, 1.5);
>>> genotype2[3] = new CustomGene(conf, 0.00, 360.00);
>>>
>>> Gene[] newGenotype = CustomCrossover(genotype1, genotype2);
>>>
>>> Creating a custom crossover would allow you to alter whatever genes you
>>> wanted, either by array index or, if you decide to go with custom genes,
>>> by
>>> the gene subclass.
>>>
>>> Creating a custom gene would allow greater flexibility when making
>>> changes,
>>> clearly identify it in the code as a different kind of Gene (which it is)
>>> and would give more information to the custom crossover function.
>>> Determining the gene based on subclass rather than array index may also
>>> allow you to incorporate additional genes into individuals through
>>> mutation,
>>> letting a "smart" custom crossover function adapt to more (or less) than
>>> 6
>>> genes, if you ever decided to change the genotype class or create a
>>> sub-class that can handle a dynamic array length.
>>>
>>>
>>> Ary Junior-3 wrote:
>>> >
>>> > Hi, in my application, each individual have 6 genes, see below:
>>> >
>>> > ...
>>> > Gene[] genotype = new Gene[6];
>>> > genotype[0] = new DoubleGene(conf, 0.5, 1.5);
>>> > genotype[1] = new DoubleGene(conf, 0.5, 1.5);
>>> > genotype[2] = new DoubleGene(conf, 0.5, 1.5);
>>> > genotype[3] = new DoubleGene(conf, 0.00, 360.00);
>>> > genotype[4] = new DoubleGene(conf, -90.00, 90.00);
>>> > genotype[5] = new DoubleGene(conf, -90.00, 90.00);
>>> > ...
>>> >
>>> > Now, I want to restrict the crossover operation. When two solutions are
>>> > mating, the genes 0, 1 and 2 must be swaped together. The same for
>>> > genes
>>> > 3,
>>> > 4 and 5. To solve my problem I need define my own custom genes?
>>> >
>>> > Thanks very much!!!
>>> >
>>> > Ary Junior
>>> >
>>> >
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Custom-genes--tp17410129p17659515.html
>>> Sent from the jgap-users mailing list archive at Nabble.com.
>>>
>>>
>>> -------------------------------------------------------------------------
>>> Check out the new SourceForge.net Marketplace.
>>> It's the best place to buy or sell services for
>>> just about anything Open Source.
>>> http://sourceforge.net/services/buy/index.php
>>> _______________________________________________
>>> jgap-users mailing list
>>> jgap-users@...
>>> https://lists.sourceforge.net/lists/listinfo/jgap-users
>>
>
>

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
jgap-users mailing list
jgap-users@...
https://lists.sourceforge.net/lists/listinfo/jgap-users
LightInTheBox - Buy quality products at wholesale price