Esempio n. 1
0
  private void calculateNewNiche() {
    setCurrentNiche(getCurrentNiche() + 1);
    VBPSO sub = mainSwarm.getClone();
    sub.getTopology().clear();
    yhead.setNicheID(getCurrentNiche());
    yhead.setNeighbourhoodBest(yhead.getClone());
    sub.getTopology().add(yhead);

    for (VBParticle p : mainSwarm.getTopology()) {
      if ((p.getDotProduct() > 0 && p.getRadius() < nicheRadius)
          || (p.getBestPosition().equals(yhead.getBestPosition()))) {
        p.setNicheID(getCurrentNiche());
        p.setNeighbourhoodBest(yhead.getClone());
        sub.getTopology().add(p);
      }
    }

    for (VBParticle p : sub.getTopology()) {
      mainSwarm.getTopology().remove(p);
    }
    VBParticle tmp = yhead.getClone();
    while (sub.getTopology().size() < 3) {
      tmp.reinitialise();
      tmp.setNeighbourhoodBest(yhead.getClone());
      tmp.setPersonalBest(tmp.getPosition().getClone());
      sub.getTopology().add(tmp);
    }

    subPopulationsAlgorithms.add(sub);
  }
Esempio n. 2
0
 private void updateVPs() {
   if (this.getIterations() == 0) {
     try {
       FunctionMaximisationProblem prob =
           (FunctionMaximisationProblem) this.getOptimisationProblem();
       function = (ContinuousFunction) prob.getFunction();
       isMax = true;
     } catch (ClassCastException e) {
       FunctionMinimisationProblem prob =
           (FunctionMinimisationProblem) this.getOptimisationProblem();
       function = (ContinuousFunction) prob.getFunction();
       isMax = false;
     } finally {
       double s;
       for (VBParticle p : mainSwarm.getTopology()) {
         p.calculateFitness();
         Vector random = (Vector) p.getPosition().getClone();
         random.randomize(randomProvider);
         s = function.apply(random);
         if (isMax) {
           if (s > p.getFitness().getValue()) {
             p.setPersonalBest(random);
           } else {
             p.setPersonalBest(p.getPosition());
             p.setPosition(random);
           }
         } else {
           if (s < p.getFitness().getValue()) {
             p.setPersonalBest(random);
           } else {
             p.setPersonalBest(p.getPosition());
             p.setPosition(random);
           }
         }
         p.setNeighbourhoodBest(p.getClone());
         p.calculateVP();
       }
     }
   }
 }