Package org.jgap

Examples of org.jgap.Configuration


    reset(threadIndex);

    final EcEvolver myFunc = new EcEvolver(source, destination, requiredActions);
    evolvers[threadIndex] = myFunc;

    final Configuration conf = constructConfiguration(threadIndex, myFunc);

    final Genotype population = Genotype.randomInitialGenotype(conf);

    //Please justify this code.
    //-Lomilar
//    if (!firstrun)
//    {
//      int totalevoSinceDiscoveryOnBest = 0;
//      int numBestThreads = 0;
//      synchronized (bestScores)
//      {
//        for (int i = 0; i < bestScores.length; i++)
//        {
//          if (bestScores[i] >= bestScore)
//          {
//            numBestThreads++;
//            totalevoSinceDiscoveryOnBest += evolutionsSinceDiscovery[i];
//          }
//        }
//      }
//
//      if (!(totalevoSinceDiscoveryOnBest > Math.max(stagnationLimit, STAGNATION_LIMIT_MIN) * numBestThreads)
//          && numBestThreads < Math.max(Math.ceil(NUM_THREADS / 3), 1))
//      {
//        loadOldBuildOrders(population, conf, myFunc);
//      }
//    }
//    else
      if (firstrun && threadIndex == 0)
    {
      loadOldBuildOrders(population, conf, myFunc);
    }
    else if (firstrun && threadIndex == NUM_THREADS - 1)
    {
      firstrun = false;
    }

    final Thread thread = new Thread(population);
    conf.getEventManager().addEventListener(GeneticEvent.GENOTYPE_EVOLVED_EVENT, new GeneticEventListener()
    {
      @Override
      public void geneticEventFired(GeneticEvent a_firedEvent)
      {
        Collections.shuffle(conf.getGeneticOperators());
        BASE_MUTATION_RATE += .001;
        if (BASE_MUTATION_RATE >= (double) CHROMOSOME_LENGTH / 2.0 )
          BASE_MUTATION_RATE = 1;
        IChromosome fittestChromosome = population.getFittestChromosome();
        if (killThreads)
View Full Code Here


  private Configuration constructConfiguration(final int threadIndex, final EcEvolver myFunc)
      throws InvalidConfigurationException
  {
    DefaultConfiguration.reset(threadIndex + " thread.");
    final Configuration conf = new DefaultConfiguration(threadIndex + " thread.", threadIndex + " thread.");
    conf.setFitnessFunction(myFunc);
    conf.addGeneticOperator(EcGeneticUtil.getCleansingOperator(this));
    conf.addGeneticOperator(EcGeneticUtil.getOverlordingOperator(this, requiredActions));
    conf.addGeneticOperator(EcGeneticUtil.getInsertionOperator(this));
    conf.addGeneticOperator(EcGeneticUtil.getDeletionOperator(this));
    conf.addGeneticOperator(EcGeneticUtil.getTwiddleOperator(this));
    conf.addGeneticOperator(EcGeneticUtil.getSwapOperator(this));
    conf.setPopulationSize(POPULATION_SIZE);
    conf.setSelectFromPrevGen(1);
    conf.setPreservFittestIndividual(false);
    conf.setAlwaysCaculateFitness(false);
    conf.setKeepPopulationSizeConstant(false);
    Gene[] initialGenes = importInitialGenes(conf);
    Chromosome c = new Chromosome(conf, initialGenes);
    conf.setSampleChromosome(c);
    return conf;
  }
View Full Code Here

TOP

Related Classes of org.jgap.Configuration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.