/**
  * @throws Exception
  * @author Klaus Meffert
  */
 public void testAddNaturalSelector_4() throws Exception {
   Configuration conf = new Configuration();
   Genotype.setStaticConfiguration(conf);
   NaturalSelector selector = new WeightedRouletteSelector();
   conf.addNaturalSelector(selector, true);
   conf.getNaturalSelectors(true).clear();
   conf.addNaturalSelector(selector, true);
   int i = conf.getNaturalSelectors(true).size();
   assertEquals(1, i);
 }
 /**
  * @throws Exception
  * @author Klaus Meffert
  * @since 3.2
  */
 public void testRemoveNaturalSelector_3() throws Exception {
   Configuration conf = new Configuration();
   NaturalSelector selector = new BestChromosomesSelector(conf);
   conf.addNaturalSelector(selector, false);
   conf.removeNaturalSelectors(true);
   assertEquals(0, conf.getNaturalSelectors(true).size());
   assertEquals(0, conf.getNaturalSelectorsSize(true));
   assertEquals(1, conf.getNaturalSelectors(false).size());
   assertEquals(1, conf.getNaturalSelectorsSize(false));
 }
 /**
  * @throws Exception
  * @author Klaus Meffert
  */
 public void testAddNaturalSelector_2() throws Exception {
   Configuration conf = new Configuration();
   Genotype.setStaticConfiguration(conf);
   NaturalSelector selector1 = new WeightedRouletteSelector();
   NaturalSelector selector2 = new WeightedRouletteSelector();
   conf.addNaturalSelector(selector1, false);
   assertEquals(selector1, conf.getNaturalSelectors(false).get(0));
   conf.addNaturalSelector(selector2, true);
   assertEquals(selector2, conf.getNaturalSelectors(true).get(0));
   assertEquals(selector1, conf.getNaturalSelectors(false).get(0));
   try {
     assertEquals(null, conf.getNaturalSelectors(false).get(1));
     fail();
   } catch (Exception ex) {; // this is OK
   }
 }
 /**
  * @throws Exception
  * @author Klaus Meffert
  */
 public void testAddNaturalSelector_1() throws Exception {
   Configuration conf = new Configuration();
   Genotype.setStaticConfiguration(conf);
   NaturalSelector selector = new WeightedRouletteSelector();
   conf.addNaturalSelector(selector, false);
   assertEquals(selector, conf.getNaturalSelectors(false).get(0));
 }
 /**
  * @throws Exception
  * @author Klaus Meffert
  */
 public void testGetter_0() throws Exception {
   Configuration conf = new Configuration();
   Genotype.setStaticConfiguration(conf);
   assertEquals(false, conf.isLocked());
   FitnessFunction fitFunc = new StaticFitnessFunction(2);
   conf.setFitnessFunction(fitFunc);
   Gene gene = new BooleanGene(conf);
   Chromosome sample = new Chromosome(conf, gene, 55);
   conf.setSampleChromosome(sample);
   NaturalSelector natSel = new WeightedRouletteSelector();
   conf.addNaturalSelector(natSel, false);
   RandomGenerator randGen = new StockRandomGenerator();
   conf.setRandomGenerator(randGen);
   IEventManager evMan = new EventManager();
   conf.setEventManager(evMan);
   GeneticOperator mutOp = new MutationOperator(conf);
   conf.addGeneticOperator(mutOp);
   GeneticOperator croOp = new CrossoverOperator(conf);
   conf.addGeneticOperator(croOp);
   conf.setPopulationSize(7);
   assertEquals(fitFunc, conf.getFitnessFunction());
   assertEquals(natSel, conf.getNaturalSelectors(false).get(0));
   assertEquals(randGen, conf.getRandomGenerator());
   assertEquals(sample, conf.getSampleChromosome());
   assertEquals(evMan, conf.getEventManager());
   assertEquals(7, conf.getPopulationSize());
   assertEquals(2, conf.getGeneticOperators().size());
   assertEquals(mutOp, conf.getGeneticOperators().get(0));
   assertEquals(croOp, conf.getGeneticOperators().get(1));
 }
 /**
  * @throws Exception
  * @author Klaus Meffert
  * @since 2.6
  */
 public void testToString_1() throws Exception {
   Configuration conf = new ConfigurationForTesting();
   conf.getGeneticOperators().clear();
   conf.getNaturalSelectors(false).clear();
   conf.getNaturalSelectors(true).clear();
   privateAccessor.setField(conf, "m_eventManager", null);
   String s = trimString(conf.toString());
   String eventmgr = conf.S_NONE;
   String genops = conf.S_NONE;
   // natural selectors (pre)
   String natselsPre = conf.S_NONE;
   // natural selectors (post)
   String natselsPost = conf.S_NONE;
   assertEquals(
       trimString(
           conf.S_CONFIGURATION
               + ":"
               + conf.S_CONFIGURATION_NAME
               + ":"
               + conf.getName()
               + " "
               + conf.S_POPULATION_SIZE
               + ":"
               + conf.getPopulationSize()
               + " "
               + conf.S_MINPOPSIZE
               + ":"
               + conf.getMinimumPopSizePercent()
               + " "
               + conf.S_CHROMOSOME_SIZE
               + ":"
               + conf.getChromosomeSize()
               + " "
               + conf.S_SAMPLE_CHROM
               + ":"
               + conf.S_SIZE
               + ":"
               + conf.getSampleChromosome().size()
               + " "
               + conf.S_TOSTRING
               + ":"
               + conf.getSampleChromosome().toString()
               + " "
               + conf.S_RANDOM_GENERATOR
               + ":"
               + conf.getRandomGenerator().getClass().getName()
               + " "
               + conf.S_EVENT_MANAGER
               + ":"
               + eventmgr
               + " "
               + conf.S_CONFIGURATION_HANDLER
               + ":"
               + conf.getConfigurationHandler().getName()
               + " "
               + conf.S_FITNESS_FUNCTION
               + ":"
               + conf.getFitnessFunction().getClass().getName()
               + " "
               + conf.S_FITNESS_EVALUATOR
               + ":"
               + conf.getFitnessEvaluator().getClass().getName()
               + " "
               + conf.S_GENETIC_OPERATORS
               + ":"
               + genops
               + " "
               + conf.S_NATURAL_SELECTORS
               + "("
               + conf.S_PRE
               + ")"
               + ":"
               + natselsPre
               + " "
               + conf.S_NATURAL_SELECTORS
               + "("
               + conf.S_POST
               + ")"
               + ":"
               + natselsPost
               + " "
           //                            + conf.S_POPCONSTANT_SELECTOR + ":"
           //                            + "null" + " "
           ),
       s);
 }
 /**
  * @throws Exception
  * @author Klaus Meffert
  * @since 2.4
  */
 public void testToString_0() throws Exception {
   Configuration conf = new ConfigurationForTesting();
   conf.addGeneticOperator(new MutationOperator(conf));
   conf.addNaturalSelector(new WeightedRouletteSelector(conf), true);
   conf.addNaturalSelector(new WeightedRouletteSelector(conf), false);
   conf.addNaturalSelector(new BestChromosomesSelector(conf), false);
   String s = trimString(conf.toString());
   String eventmgr =
       conf.getEventManager() != null ? conf.getEventManager().getClass().getName() : conf.S_NONE;
   String genops = "";
   if (conf.getGeneticOperators().size() < 1) {
     genops = conf.S_NONE;
   } else {
     for (int i = 0; i < conf.getGeneticOperators().size(); i++) {
       if (i > 0) {
         genops += "; ";
       }
       genops += conf.getGeneticOperators().get(i).getClass().getName();
       ;
     }
   }
   // natural selectors (pre)
   String natselsPre = "";
   int natsize = conf.getNaturalSelectors(true).size();
   if (natsize < 1) {
     natselsPre = conf.S_NONE;
   } else {
     for (int i = 0; i < natsize; i++) {
       if (i > 0) {
         natselsPre += "; ";
       }
       natselsPre += " " + conf.getNaturalSelectors(true).get(i).getClass().getName();
     }
   }
   // natural selectors (post)
   String natselsPost = "";
   natsize = conf.getNaturalSelectors(false).size();
   if (natsize < 1) {
     natselsPost = conf.S_NONE;
   } else {
     for (int i = 0; i < natsize; i++) {
       if (i > 0) {
         natselsPost += "; ";
       }
       natselsPost += " " + conf.getNaturalSelectors(false).get(i).getClass().getName();
     }
   }
   assertEquals(
       trimString(
           conf.S_CONFIGURATION
               + ":"
               + conf.S_CONFIGURATION_NAME
               + ":"
               + conf.getName()
               + " "
               + conf.S_POPULATION_SIZE
               + ":"
               + conf.getPopulationSize()
               + " "
               + conf.S_MINPOPSIZE
               + ":"
               + conf.getMinimumPopSizePercent()
               + " "
               + conf.S_CHROMOSOME_SIZE
               + ":"
               + conf.getChromosomeSize()
               + " "
               + conf.S_SAMPLE_CHROM
               + ":"
               + conf.S_SIZE
               + ":"
               + conf.getSampleChromosome().size()
               + " "
               + conf.S_TOSTRING
               + ":"
               + conf.getSampleChromosome().toString()
               + " "
               + conf.S_RANDOM_GENERATOR
               + ":"
               + conf.getRandomGenerator().getClass().getName()
               + " "
               + conf.S_EVENT_MANAGER
               + ":"
               + eventmgr
               + " "
               + conf.S_CONFIGURATION_HANDLER
               + ":"
               + conf.getConfigurationHandler().getName()
               + " "
               + conf.S_FITNESS_FUNCTION
               + ":"
               + conf.getFitnessFunction().getClass().getName()
               + " "
               + conf.S_FITNESS_EVALUATOR
               + ":"
               + conf.getFitnessEvaluator().getClass().getName()
               + " "
               + conf.S_GENETIC_OPERATORS
               + ":"
               + genops
               + " "
               + conf.S_NATURAL_SELECTORS
               + "("
               + conf.S_PRE
               + ")"
               + ":"
               + natselsPre
               + " "
               + conf.S_NATURAL_SELECTORS
               + "("
               + conf.S_POST
               + ")"
               + ":"
               + natselsPost
               + " "
           //                            + conf.S_POPCONSTANT_SELECTOR + ":"
           //                            + "null" + " "
           ),
       s);
 }