コード例 #1
0
 /**
  * @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);
 }
コード例 #2
0
 /**
  * @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);
 }