示例#1
0
  public ParallelVBPSO() {
    this.mainSwarm = new VBPSO();
    VBPSO pso = (VBPSO) this.mainSwarm;
    ((SynchronousIterationStrategy) pso.getIterationStrategy())
        .setBoundaryConstraint(new ReinitialisationBoundary());

    VBParticle mainSwarmParticle = new VBParticle();
    mainSwarmParticle.setVelocityInitializationStrategy(new RandomInitializationStrategy());
    StandardVelocityProvider velocityUpdateStrategy = new StandardVelocityProvider();
    velocityUpdateStrategy.setCognitiveAcceleration(ConstantControlParameter.of(1.0));
    velocityUpdateStrategy.setSocialAcceleration(ConstantControlParameter.of(1.0));
    velocityUpdateStrategy.setInertiaWeight(ConstantControlParameter.of(0.8));

    mainSwarmParticle.setVelocityProvider(velocityUpdateStrategy);
    PopulationInitialisationStrategy mainSwarmInitialisationStrategy =
        new ClonedPopulationInitialisationStrategy();
    mainSwarmInitialisationStrategy.setEntityType(mainSwarmParticle);
    mainSwarmInitialisationStrategy.setEntityNumber(20);

    this.mainSwarm.setInitialisationStrategy(mainSwarmInitialisationStrategy);
    this.randomProvider = new MersenneTwister();
    distanceMeaser = new EuclideanDistanceMeasure();
    currentNiche = 0;
    granularity = 0.05;
  }
示例#2
0
  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
 private void calculateNeighbourhoodBest() {
   yhead = mainSwarm.getTopology().get(0);
   double first, second;
   if (isMax) {
     for (VBParticle particle : mainSwarm.getTopology()) {
       first = function.apply((Vector) particle.getBestPosition());
       second = function.apply(yhead.getBestPosition());
       if (first > second) {
         yhead = particle;
       }
     }
   } else {
     for (VBParticle particle : mainSwarm.getTopology()) {
       first = function.apply((Vector) particle.getBestPosition());
       second = function.apply(yhead.getBestPosition());
       if (first < second) {
         yhead = particle;
       }
     }
   }
   mainSwarm.getTopology().remove(yhead);
 }
示例#4
0
 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--;
     }
   }
 }
示例#5
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);
  }
示例#6
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();
       }
     }
   }
 }