Esempio n. 1
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();
       }
     }
   }
 }