How to use MapGene?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to use MapGene?

Milan Jedlicka
Hello,

I found JGAP recently and it seems like project that I was looking  
for. But also I found one problem that I'm unable to solve. I need  
IntegerGene, BooleanGen and I really need Gene which take one value  
of set like {1, 3, 5} or {"low"->10, "medium"->,50 "high"->100} for  
Chromosome.  MapGene looks great but... When I try to use this type  
of Gene in simple coin example (or others) then exception ocurrs.

I tried to fill MapGene only with int values, but problem occurs on line

--> population = Genotype.randomInitialGenotype(conf);

and I get

Exception in thread "main" java.lang.IllegalArgumentException: Allele  
value being set is not an element of the set of permitted values.
     at org.jgap.impl.MapGene.setAllele(MapGene.java:290)
     at org.jgap.Configuration.verifyStateIsValid(Configuration.java:
893)
     at org.jgap.Configuration.lockSettings(Configuration.java:800)
     at org.jgap.Genotype.randomInitialGenotype(Genotype.java:407)
     at org.jgap.Genotype.randomInitialGenotype(Genotype.java:370)
     at examples.MinimizingMakeChange.makeChangeForAmount
(MinimizingMakeChange.java:138)
     at examples.MinimizingMakeChange.main(MinimizingMakeChange.java:
268)

It seems like HashSet which holds all possibilities for MapGene is  
empty, but I don't know why.

I'm JGAP newbie, please help me, show me simple example of how to use  
MapGene and I will be the happiest JGAP user ever ;-) (i have spent a  
few days on this)

Thanks

Milca

P.S.: There are a few lines of code that may help... maybe there  
could be a problem in initialization part, but I checked it :o(
---
     Configuration conf = new DefaultConfiguration();
     conf.setPreservFittestIndividual(true);
     conf.setKeepPopulationSizeConstant(false);

     FitnessFunction myFunc =
         new MinimizingMakeChangeFitnessFunction(a_targetChangeAmount);

     conf.setBulkFitnessFunction(new BulkFitnessOffsetRemover(myFunc));

     Gene[] sampleGenes = new Gene[4];
     sampleGenes[0] = new IntegerGene(0, 3 * 10); // Quarters
     sampleGenes[1] = new IntegerGene(0, 2 * 10); // Dimes
     sampleGenes[2] = new IntegerGene(0, 1 * 10); // Nickels
     MapGene mapgene = new MapGene();
     mapgene.addAllele(1);
     mapgene.addAllele(3);
     mapgene.addAllele(5);
     sampleGenes[3] = mapgene; // Pennies
     Chromosome sampleChromosome = new Chromosome(sampleGenes);
     conf.setSampleChromosome(sampleChromosome);

     conf.setPopulationSize(POPULATION_SIZE);
     Genotype population;

     population = Genotype.randomInitialGenotype(conf);



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
jgap-devl mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgap-devl
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: How to use MapGene?

Bonhomme

Hi Milca -

I originally wrote MapGene for my own particular uses and then gave it to
Klaus, so I'm not surprised that there might be a mismatch in generating
things randomly through the main interface.

The way I originally designed things, you could write something like

  mg.addAllele(new Integer(1), new Integer(25));           // 1 = 25
  mg.addAllele(new Integer(3), new Integer(10));           // 3 = 10
  mg.addAllele(new Integer(5), new Integer(5));            // 5 = 5

and that would fill up the HashSet (That's the addAllele(Object a_key,
Object a_value) method).  I think I also had a getAllele(Object o) method
that retrieved the value from the set according to the key provided - e.g.
getAllele(3) would return 10, but it looks like this may have been removed.

The purpose was both to provide a label and allow for discontinuities (For
just addressing discontinuities you might be able to use SetGene? - not sure
if that would help though).

Looking at the code, it looks like right now Klaus has put in a convenience
function where if you add a single value you'd get

  mg.addAllele(1)  // 1 = 1
  mg.addAllele(3)  // 3 = 3
  mg.addAllele(5)  // 5 = 5

That's (the first) half of the story, Klaus will have to tell the second
half - particularly how the classes were incorporated into the larger scheme
of things, but I thought I could at least provide some input into how things
were originally designed. My apologies if that's not particularly helpful -
I'll keep trying to figure things out from this end as well...

JK




-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
jgap-devl mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgap-devl
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: How to use MapGene?

Klaus Meffert
Hello Milan,

in the sourcecode to the Mapgene class originally provided by JK, you find a
text beginning with "attention:". The MapGene implementation currently
provided is preliminary. It needs to be figured out how to adapt MapGene to
fit into the general scheme of JGAP, as JK also mentioned in his reply to
your question. The convenient method addAlelel with only one param behaves
as JK described. Maybe your problem is resolved by using the addAlelele
method with two parameters. Then, do you still have a problem? If yes, don't
hesitate to tell us!

If you'd like, you could send me your additions to the MapGene class (if
any) and I'll try to add them to the current MapGene implementation.

Best

Klaus

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> Johnathan Kool
> Sent: Wednesday, September 28, 2005 8:02 PM
> To: 'Milan Jedlicka'
> Cc: [hidden email]
> Subject: RE: [jgap-devl] How to use MapGene?
>
>
> Hi Milca -
>
> I originally wrote MapGene for my own particular uses and
> then gave it to Klaus, so I'm not surprised that there might
> be a mismatch in generating things randomly through the main
> interface.
>
> The way I originally designed things, you could write something like
>
>   mg.addAllele(new Integer(1), new Integer(25));           // 1 = 25
>   mg.addAllele(new Integer(3), new Integer(10));           // 3 = 10
>   mg.addAllele(new Integer(5), new Integer(5));            // 5 = 5
>
> and that would fill up the HashSet (That's the
> addAllele(Object a_key, Object a_value) method).  I think I
> also had a getAllele(Object o) method that retrieved the
> value from the set according to the key provided - e.g.
> getAllele(3) would return 10, but it looks like this may have
> been removed.
>
> The purpose was both to provide a label and allow for
> discontinuities (For just addressing discontinuities you
> might be able to use SetGene? - not sure if that would help though).
>
> Looking at the code, it looks like right now Klaus has put in
> a convenience function where if you add a single value you'd get
>
>   mg.addAllele(1)  // 1 = 1
>   mg.addAllele(3)  // 3 = 3
>   mg.addAllele(5)  // 5 = 5
>
> That's (the first) half of the story, Klaus will have to tell
> the second half - particularly how the classes were
> incorporated into the larger scheme of things, but I thought
> I could at least provide some input into how things were
> originally designed. My apologies if that's not particularly
> helpful - I'll keep trying to figure things out from this end
> as well...
>
> JK




-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
jgap-devl mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgap-devl
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: How to use MapGene?

Klaus Meffert
In reply to this post by Milan Jedlicka
Addition to my previous answer:
The problem you encountered is the following:
In Genotype.randomInitialGenotype the sampleChromosome set in the
configuration by you comes in play. In Configuration.verifyStateIsValid,
MapGene.newGene is called to produce a copy of the sample genes of the
provided implicitely with your sampleChromosome. But as newGene() only
produces a MapGene with an empty map (representing allowed alleles ton be
set with setAllele later called in Configuration.verifyStateIsValid) the
error arises. Therefor we would need to modify MapGene.setAllele: If
geneMap.keySet() is empty, any value to be set is allowed. I will fix the
code and check it in soon. Please check the CVS in some minutes.

Best

Klaus

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> Milan Jedlicka
> Sent: Monday, September 26, 2005 10:31 PM
> To: [hidden email]
> Subject: [jgap-devl] How to use MapGene?
>
> Hello,
>
> I found JGAP recently and it seems like project that I was
> looking for. But also I found one problem that I'm unable to
> solve. I need IntegerGene, BooleanGen and I really need Gene
> which take one value of set like {1, 3, 5} or {"low"->10,
> "medium"->,50 "high"->100} for Chromosome.  MapGene looks
> great but... When I try to use this type of Gene in simple
> coin example (or others) then exception ocurrs.
>
> I tried to fill MapGene only with int values, but problem
> occurs on line
>
> --> population = Genotype.randomInitialGenotype(conf);
>
> and I get
>
> Exception in thread "main"
> java.lang.IllegalArgumentException: Allele value being set is
> not an element of the set of permitted values.
>      at org.jgap.impl.MapGene.setAllele(MapGene.java:290)
>      at org.jgap.Configuration.verifyStateIsValid(Configuration.java:
> 893)
>      at org.jgap.Configuration.lockSettings(Configuration.java:800)
>      at org.jgap.Genotype.randomInitialGenotype(Genotype.java:407)
>      at org.jgap.Genotype.randomInitialGenotype(Genotype.java:370)
>      at examples.MinimizingMakeChange.makeChangeForAmount
> (MinimizingMakeChange.java:138)
>      at examples.MinimizingMakeChange.main(MinimizingMakeChange.java:
> 268)
>
> It seems like HashSet which holds all possibilities for
> MapGene is empty, but I don't know why.
>
> I'm JGAP newbie, please help me, show me simple example of
> how to use MapGene and I will be the happiest JGAP user ever
> ;-) (i have spent a few days on this)
>
> Thanks
>
> Milca
>
> P.S.: There are a few lines of code that may help... maybe
> there could be a problem in initialization part, but I checked it :o(
> ---
>      Configuration conf = new DefaultConfiguration();
>      conf.setPreservFittestIndividual(true);
>      conf.setKeepPopulationSizeConstant(false);
>
>      FitnessFunction myFunc =
>          new
> MinimizingMakeChangeFitnessFunction(a_targetChangeAmount);
>
>      conf.setBulkFitnessFunction(new
> BulkFitnessOffsetRemover(myFunc));
>
>      Gene[] sampleGenes = new Gene[4];
>      sampleGenes[0] = new IntegerGene(0, 3 * 10); // Quarters
>      sampleGenes[1] = new IntegerGene(0, 2 * 10); // Dimes
>      sampleGenes[2] = new IntegerGene(0, 1 * 10); // Nickels
>      MapGene mapgene = new MapGene();
>      mapgene.addAllele(1);
>      mapgene.addAllele(3);
>      mapgene.addAllele(5);
>      sampleGenes[3] = mapgene; // Pennies
>      Chromosome sampleChromosome = new Chromosome(sampleGenes);
>      conf.setSampleChromosome(sampleChromosome);
>
>      conf.setPopulationSize(POPULATION_SIZE);
>      Genotype population;
>
>      population = Genotype.randomInitialGenotype(conf);
>
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by:
> Tame your development challenges with Apache's Geronimo App
> Server. Download it for free - -and be entered to win a 42"
> plasma tv or your very own Sony(tm)PSP.  Click here to play:
> http://sourceforge.net/geronimo.php
> _______________________________________________
> jgap-devl mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jgap-devl




-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
jgap-devl mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgap-devl
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to use MapGene?

Milan Jedlicka
In reply to this post by Klaus Meffert
Hi Klaus,

I tried to make my own Gene class and experimented a bit with it. I  
think that I have solved problems with MapGene and also with SetGen.

I found and solved these problems:

1. Exception in thread "main" java.lang.IllegalArgumentException:  
Allele value being set is not an element of the set of permitted  
values. (MapGene and SetGene problem)

You get this exception because newGene() method only creates new  
SetGene but doesn't fill HashSet with values. When then setAllele()  
method is called it throws exception, 'cause geneSet is empty.

2. setToRandomValue() problem
m_value = ( (List) geneSet).get(a_numberGenerator.nextInt(geneSet.size
()));

This line throws also exception, cause Java can't change type from  
Set to List. When I moved values from geneSet to array, GeneSet works.

3. getInternalValue() problem
On initialization m_value is null and JGAP throws exception. I solved  
this with line that fills m_value with random value from geneSet.

Now these classes works in my applications properly. I hope that this  
info helps you to fix problems with GeneSet and MapSet. I think that  
these classes should be very usable for users.

Best Regards

Milca

P.S.: I don't know if my solution is the best, because I don't see  
many things in JGAP, but it works.

On Sep 30, 2005, at 11:27 AM, Klaus Meffert wrote:

> Hello Milan,
>
> in the sourcecode to the Mapgene class originally provided by JK,  
> you find a
> text beginning with "attention:". The MapGene implementation currently
> provided is preliminary. It needs to be figured out how to adapt  
> MapGene to
> fit into the general scheme of JGAP, as JK also mentioned in his  
> reply to
> your question. The convenient method addAlelel with only one param  
> behaves
> as JK described. Maybe your problem is resolved by using the  
> addAlelele
> method with two parameters. Then, do you still have a problem? If  
> yes, don't
> hesitate to tell us!
>
> If you'd like, you could send me your additions to the MapGene  
> class (if
> any) and I'll try to add them to the current MapGene implementation.
>
> Best
>
> Klaus
>
>
>> -----Original Message-----
>> From: [hidden email]
>> [mailto:[hidden email]] On Behalf Of
>> Johnathan Kool
>> Sent: Wednesday, September 28, 2005 8:02 PM
>> To: 'Milan Jedlicka'
>> Cc: [hidden email]
>> Subject: RE: [jgap-devl] How to use MapGene?
>>
>>
>> Hi Milca -
>>
>> I originally wrote MapGene for my own particular uses and
>> then gave it to Klaus, so I'm not surprised that there might
>> be a mismatch in generating things randomly through the main
>> interface.
>>
>> The way I originally designed things, you could write something like
>>
>>   mg.addAllele(new Integer(1), new Integer(25));           // 1 = 25
>>   mg.addAllele(new Integer(3), new Integer(10));           // 3 = 10
>>   mg.addAllele(new Integer(5), new Integer(5));            // 5 = 5
>>
>> and that would fill up the HashSet (That's the
>> addAllele(Object a_key, Object a_value) method).  I think I
>> also had a getAllele(Object o) method that retrieved the
>> value from the set according to the key provided - e.g.
>> getAllele(3) would return 10, but it looks like this may have
>> been removed.
>>
>> The purpose was both to provide a label and allow for
>> discontinuities (For just addressing discontinuities you
>> might be able to use SetGene? - not sure if that would help though).
>>
>> Looking at the code, it looks like right now Klaus has put in
>> a convenience function where if you add a single value you'd get
>>
>>   mg.addAllele(1)  // 1 = 1
>>   mg.addAllele(3)  // 3 = 3
>>   mg.addAllele(5)  // 5 = 5
>>
>> That's (the first) half of the story, Klaus will have to tell
>> the second half - particularly how the classes were
>> incorporated into the larger scheme of things, but I thought
>> I could at least provide some input into how things were
>> originally designed. My apologies if that's not particularly
>> helpful - I'll keep trying to figure things out from this end
>> as well...
>>
>> JK
>>
>
>
>



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
jgap-devl mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgap-devl
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: How to use MapGene?

Klaus Meffert
Hello Milan,

Great work!
Of course we would be interested in your implementation. If you like, you
could send the relevant classes to me. Then, I could try integrating it with
JGAP. I also did some work with MapGene and fixed some open issues. Unit
tests were added, too.

Best

Klaus
PS: Is your name "Milan" or "Milca"? Your mail address and your sign differ.

> -----Original Message-----
> From: Milan Jedlicka [mailto:[hidden email]]
> Sent: Saturday, October 01, 2005 2:59 PM
> To: Klaus Meffert; [hidden email]
> Subject: Re: [jgap-devl] How to use MapGene?
>
> Hi Klaus,
>
> I tried to make my own Gene class and experimented a bit with
> it. I think that I have solved problems with MapGene and also
> with SetGen.
>
> I found and solved these problems:
>
> 1. Exception in thread "main" java.lang.IllegalArgumentException:  
> Allele value being set is not an element of the set of
> permitted values. (MapGene and SetGene problem)
>
> You get this exception because newGene() method only creates
> new SetGene but doesn't fill HashSet with values. When then
> setAllele() method is called it throws exception, 'cause
> geneSet is empty.
>
> 2. setToRandomValue() problem
> m_value = ( (List) geneSet).get(a_numberGenerator.nextInt(geneSet.size
> ()));
>
> This line throws also exception, cause Java can't change type
> from Set to List. When I moved values from geneSet to array,
> GeneSet works.
>
> 3. getInternalValue() problem
> On initialization m_value is null and JGAP throws exception.
> I solved this with line that fills m_value with random value
> from geneSet.
>
> Now these classes works in my applications properly. I hope
> that this info helps you to fix problems with GeneSet and
> MapSet. I think that these classes should be very usable for users.
>
> Best Regards
>
> Milca
>




-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
jgap-devl mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgap-devl
Loading...