public void testToString() throws IOException {
    out = new BufferedWriter(new FileWriter(CONFIG));
    startConfig();
    endConfig();
    Path fileResource = new Path(CONFIG);
    conf.addResource(fileResource);

    String expectedOutput =
        "Configuration: core-default.xml, core-site.xml, " + fileResource.toString();
    assertEquals(expectedOutput, conf.toString());
  }
 /*
  * Broadcast local configuration to others over the network.
  * @return true if broadcast successful, false if failed.
  */
 public static boolean doBroadcast(String releaseVersion, Configuration config, long publishTime) {
   boolean taskSuccess = true;
   _log.debug("{} - broadcasting cluster configuration {}", config.getNodeId(), config.toString());
   try {
     MulticastUtil.create(config.getHwConfig().get(PropertyConstants.PROPERTY_KEY_NETIF))
         .publish(releaseVersion, config.getNodeId(), config.getConfigMap(), publishTime);
   } catch (IOException e) {
     taskSuccess = false;
     _log.error("broadcast configuration caught exception with: " + e.getMessage());
   } finally {
     _log.info(
         "broadcast configuration via {} for {} is done",
         config.getHwConfig().get(PropertyConstants.PROPERTY_KEY_NETIF),
         config.getScenario());
   }
   return taskSuccess;
 }
示例#3
0
  public static void main(String[] args) {
    Funid funid = new Funid();
    int executionTimes = 10;

    System.out.println("Start");

    // Map<String, List<GeneticApplication>> applicationMap = new
    // HashMap<String, List<GeneticApplication>>();
    // List<GeneticApplication> applications;

    List<Configuration> configurations = Configuration.getBasicsConfigurations();

    try {

      for (Configuration config : configurations) {
        System.out.println(config.toString());
        System.out.println("Algo 1");
        System.out.println("Execucao;Melhor;Gen. Enc.;Med. P. Ini; Med. P. Fin.;Razao;Tempo");
        for (int i = 0; i < executionTimes; i++) {
          funid.setPopulationSize(config.getPopulationSize());
          System.out.print((i + 1) + ";");

          GeneticParameters params =
              new GeneticParameters(
                  config.getCrossoverRate(),
                  config.getMutationRate(),
                  config.getPopulationSize(),
                  config.getMaxGeneration(),
                  MAXIMIZE,
                  new Elitism(),
                  new OnePointCrosserOver(),
                  new RoulleteSelector(MAXIMIZE),
                  new InversionMutator(),
                  funid);

          new GeneticApplication(funid.getInitialPopulation()).setParams(params).execute();
        }

        System.out.println(config.toString());
        System.out.println("Algo 2");
        System.out.println("Execucao;Melhor;Gen. Enc.;Med. P. Ini; Med. P. Fin.;Razao;Tempo");
        for (int i = 0; i < executionTimes; i++) {
          System.out.print((i + 1) + ";");
          GeneticParameters params =
              new GeneticParameters(
                  config.getCrossoverRate(),
                  config.getMutationRate(),
                  config.getPopulationSize(),
                  config.getMaxGeneration(),
                  MAXIMIZE,
                  new Generational(),
                  new TwoPointsCrosserOver(),
                  new RoulleteSelector(MAXIMIZE),
                  new InversionMutator(),
                  funid);

          new GeneticApplication(funid.getInitialPopulation()).setParams(params).execute();
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
 /**
  * @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);
 }