예제 #1
0
  public void init() {
    //		System.out.println("TRIBES.init()");
    // Generate a swarm
    swarm =
        new TribesSwarm(
            this, range, initRange); // TODO initRange is hard coded equal to problem range
    // swarm.generateSwarm(initExplorerNb, initType, m_problem);

    //   swarm.displaySwarm(swarm,out);
    //  print("\n Best after init: "+swarm.Best.position.fitness,out);

    iter = 0;
    adapt = 0;
    informOption = -1;
    //        Hard coded option
    //        -1 = absolute best informant
    //        1 = relative (pseudo-gradient) best informant. For "niching"
    //       See also moveExplorer, which can be modified in order to avoid this parameter

    population.clear();
    population.addAll(swarm.toPopulation());
    population.init(); // necessary to allow for multi-runs

    if (m_Show) show();
  }
예제 #2
0
 public AbstractEAIndividual getBestInd() {
   TribesPosition bestMemPos = swarm.getBestMemory().getPos();
   AbstractEAIndividual bestExp = population.getBestEAIndividual();
   if (bestMemPos.firstIsBetter(bestMemPos.getFitness(), bestExp.getFitness())) {
     AbstractEAIndividual indy = (AbstractEAIndividual) bestExp.clone();
     indy.SetFitness(bestMemPos.getFitness());
     ((InterfaceDataTypeDouble) indy).SetDoubleGenotype(bestMemPos.getPos());
     return indy;
   } else return bestExp;
 }
예제 #3
0
 /**
  * Return a SolutionSet of TribesExplorers (AbstractEAIndividuals) of which some where memory
  * particles, thus the returned population is larger than the current population.
  *
  * @return a population of possible solutions.
  */
 public InterfaceSolutionSet getAllSolutions() {
   // return population and memories?
   Population all = (Population) population.clone();
   List<TribesPosition> mems = swarm.collectMem();
   for (Iterator<TribesPosition> iterator = mems.iterator(); iterator.hasNext(); ) {
     TribesPosition tp = iterator.next();
     all.add(positionToExplorer(tp));
   }
   all.SetFunctionCalls(population.getFunctionCalls());
   all.setGenerationTo(population.getGeneration());
   // all.addPopulation(pop);
   return new SolutionSet(population, all);
 }
예제 #4
0
  public void optimize() {

    int initOption = 0;
    if (iter == 0) { // first iteration!
      if (initRange == null) {
        rangeInitType = 0;
      } else {
        rangeInitType = 1; // 1 means in initRange for a start
      }
      // * initOption Options: 0 - random, 1 - on the bounds, 2 - sunny spell, 3 - around a center
      // * rangeInitType for options 0,1: 1 means use initRange, 0 use default range
      swarm.generateSwarm(initExplorerNb, initOption, rangeInitType, m_problem);
    }
    iter++;

    m_problem.evaluatePopulationStart(population);
    swarm.setSwarmSize();
    // swarm.Best.positionPrev = swarm.Best.position;

    swarm.moveSwarm(
        range, new TribesParam(), informOption, m_problem); // *** HERE IT MOVES and EVALUATES
    // public void moveSwarm(double[][] range, int fitnessSize, TribesParam pb, TribesSwarm swarm,
    //      int informOption, AbstractOptimizationProblem prob) {

    if (Tribes.adaptOption != 0) { // perform adaption
      if (Tribes.adaptOption == 1) { // Just reinitialize the swarm
        adaptThreshold = iter - adapt;
        //   adaptMax=swarmSize;
        adaptMax = swarm.linkNb(swarm);
        if (adaptThreshold >= adaptMax) {
          if (swarm.getBestMemory().getPrevPos().getTotalError()
              <= swarm.getBestMemory().getPos().getTotalError()) {
            adapt = iter; // Memorize at which iteration adaptation occurs

            for (int i = 0; i < swarm.getTribeCnt(); i++) {
              swarm.reinitTribe(i, rangeInitType, m_problem);
            }
          }
        }
      } else //   if(swarm.Best.positionPrev.getTotalError()<=swarm.Best.position.getTotalError())
      {
        // Structural adaptations

        adaptThreshold = iter - adapt;
        //   adaptMax=swarmSize;
        adaptMax = swarm.linkNb(swarm);

        if (adaptThreshold >= adaptMax) {
          adapt = iter; // Memorize at which iteration adaptation occurs
          swarm.adaptSwarm(rangeInitType, m_problem); // Re´alise l'adaptation
        }
      }
    }
    population.clear();
    population.addAll(swarm.toPopulation());
    if (m_Show) plotAll(population);
    m_problem.evaluatePopulationEnd(population);

    //		this.population.incrFunctionCallsby(evals);
    this.population.incrGeneration();
    // this.firePropertyChangedEvent("NextGenerationPerformed");	// This is now done implicitely, as
    // after every evaluation, addEvals is called

    if (TRACE) {
      System.out.println("loop finished after " + population.getFunctionCalls() + " evaluations");
      // for (int i=0; i<population.size(); i++) System.out.println(" *
      // "+((TribesExplorer)population.get(i)).getStringRepresentation());
      System.out.println(
          " best: "
              + population.getBestEAIndividual().getStringRepresentation()
              + " - "
              + population.getBestEAIndividual().getFitness(0));
      System.out.println(
          "swarm contains " + swarm.numParticles() + " particles in iteration " + iter);
    }
  }