简体   繁体   中英

Set a Gene limit on a Chromosome

I'm currently experimenting with JGAP 3.6 to generate levels for a simple dungeon game. The problem involves using a Chromosome representation where each Gene contains an integer value which represents the type of a room eg 0 = Starting room, 1 = Monster room, and so forth.

The problem is, I want to make sure that there is only one Starting room in a level (Only one Gene with value of 0 in a Chromosome). I've read the javadocs specifically the Chromosome and Gene class yet found no straightforward way to do this. I've also considered using custom-made Gene but it seems useless because I figured this kind of 'validation' needs to be done by the Chromosome class and not the Gene class.

My current workaround plan for the problem is by giving a large penalty during fitness evaluation for Chromosomes that doesn't satisfy said condition. Any thoughts, solutions, suggestions, or comments? Thank you

The easiest way do to it is to limit the Genes values in the Configuration setup.

A basig example to have only one Starting room in the first gene may be:

sampleGenes[0] = new IntegerGene(conf, 0, 0);  // Starting room
sampleGenes[1] = new IntegerGene(conf, 1, 5);  // Monster room 1
sampleGenes[2] = new IntegerGene(conf, 1, 5);  // Monster room 2
sampleGenes[3] = new IntegerGene(conf, 1, 5);  // Monster room 3

This ensures you will get only one gene with the value 0, but have its limitations. You have to decide what gene will be the starting room and it can't be undone.

Another one way is to do what you suggests. Create a FitnessFunction that penalize the Chromosomes with more than a Gene with it's value equal to zero.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM