コード例 #1
0
ファイル: ExplorerBeeTest.java プロジェクト: heatzync/cilib
  @Before
  public void setUp() throws Exception {
    FunctionMinimisationProblem problem = new FunctionMinimisationProblem();
    problem.setDomain("R(-5.0, 5.0)^5");
    problem.setFunction(new Rastrigin());

    StoppingCondition condition = new MaximumIterations(2);

    abc = new ABC();
    ClonedPopulationInitialisationStrategy initStrategy =
        new ClonedPopulationInitialisationStrategy();
    initStrategy.setEntityNumber(10);
    WorkerBee bee = new WorkerBee();
    initStrategy.setEntityType(bee);
    abc.setForageLimit(new ConstantControlParameter(-1));
    abc.setInitialisationStrategy(initStrategy);
    abc.setWorkerBeePercentage(new ConstantControlParameter(0.5));
    abc.addStoppingCondition(condition);
    abc.setOptimisationProblem(problem);
    abc.initialise();
  }
コード例 #2
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();
       }
     }
   }
 }