コード例 #1
0
ファイル: ParallelVBPSO.java プロジェクト: sayamz/cilib
  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);
  }
コード例 #2
0
ファイル: ParallelVBPSO.java プロジェクト: sayamz/cilib
  private void createNiches() {
    calculateNeighbourhoodBest();
    double smallR = 1000000000000000.0;
    double radius;

    for (VBParticle p : mainSwarm.getTopology()) {
      p.setNeighbourhoodBest(yhead.getClone());
      p.calculateVG();
      p.calculateDotProduct();
      radius = distanceMeaser.distance(yhead.getBestPosition(), p.getPosition());
      p.setRadius(radius);
      if (radius < smallR && p.getDotProduct() < 0) {
        smallR = radius;
      }
    }
    nicheRadius = smallR;
    calculateNewNiche();
  }
コード例 #3
0
ファイル: ParallelVBPSO.java プロジェクト: sayamz/cilib
 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();
       }
     }
   }
 }
コード例 #4
0
ファイル: ParallelVBPSO.java プロジェクト: sayamz/cilib
 private void merge() {
   if (subPopulationsAlgorithms.size() < 2) return;
   VBPSO subi, subj;
   double d1, d2;
   VBParticle yi, yj, swap;
   for (int i = 0; i < subPopulationsAlgorithms.size() - 1; i++) {
     subi = (VBPSO) subPopulationsAlgorithms.get(i);
     yi = (VBParticle) subi.getTopology().get(0).getNeighbourhoodBest();
     for (int j = i + 1; j < subPopulationsAlgorithms.size(); j++) {
       subj = (VBPSO) subPopulationsAlgorithms.get(j);
       yj = (VBParticle) subj.getTopology().get(0).getNeighbourhoodBest();
       d1 = distanceMeaser.distance(yi.getBestPosition(), yj.getBestPosition());
       if (d1 < granularity) {
         if (yi.getBestFitness().compareTo(yj.getBestFitness()) >= 0.0) {
           int n = subj.getTopology().size();
           VBParticle p;
           if (n == 1) {
             swap = subj.getTopology().get(0).getClone();
             swap.setNeighbourhoodBest(yi);
             swap.setNicheID(i);
             swap.calculateVP();
             swap.calculateVG();
             swap.calculateDotProduct();
             subi.getTopology().add(swap);
             subj.getTopology().remove(0);
           } else {
             for (int k = 0; k < n; k++) {
               p = subj.getTopology().get(k);
               d2 = distanceMeaser.distance(p.getBestPosition(), yi.getBestPosition());
               if (d2 < granularity) {
                 swap = p.getClone();
                 swap.setNeighbourhoodBest(yi);
                 swap.setNicheID(i);
                 swap.calculateVP();
                 swap.calculateVG();
                 swap.calculateDotProduct();
                 subi.getTopology().add(swap);
                 subj.getTopology().remove(k);
                 k--;
                 n--;
               } else if (n == 1) {
                 swap = subj.getTopology().get(0).getClone();
                 swap.setNeighbourhoodBest(yi);
                 swap.setNicheID(i);
                 swap.calculateVP();
                 swap.calculateVG();
                 swap.calculateDotProduct();
                 subi.getTopology().add(swap);
                 subj.getTopology().remove(0);
                 break;
               }
             }
           }
         } else {
           int n = subi.getTopology().size();
           VBParticle p;
           if (n == 1) {
             swap = subi.getTopology().get(0);
             swap.setNeighbourhoodBest(yj);
             swap.setNicheID(j);
             swap.calculateVP();
             swap.calculateVG();
             swap.calculateDotProduct();
             subj.getTopology().add(swap);
             subi.getTopology().remove(0);
           } else {
             for (int k = 0; k < n; k++) {
               p = subi.getTopology().get(k);
               d2 = distanceMeaser.distance(p.getPosition(), yj.getBestPosition());
               if (d2 < granularity) {
                 swap = p.getClone();
                 swap.setNeighbourhoodBest(yj);
                 swap.setNicheID(j);
                 swap.calculateVP();
                 swap.calculateVG();
                 swap.calculateDotProduct();
                 subj.getTopology().add(swap);
                 subi.getTopology().remove(k);
                 k--;
                 n--;
               } else if (n == 1) {
                 swap = subi.getTopology().get(0);
                 swap.setNeighbourhoodBest(yj);
                 swap.setNicheID(j);
                 swap.calculateVP();
                 swap.calculateVG();
                 swap.calculateDotProduct();
                 subj.getTopology().add(swap);
                 subi.getTopology().remove(0);
               }
             }
           }
         }
       }
       subPopulationsAlgorithms.set(j, subj);
       if (subj.getTopology().size() == 0) {
         subPopulationsAlgorithms.remove(j);
         j--;
       }
     }
     subPopulationsAlgorithms.set(i, subi);
     if (subi.getTopology().size() == 0) {
       subPopulationsAlgorithms.remove(i);
       i--;
     }
   }
 }