⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 depsagent.java

📁 用java实现的改进粒子群算法
💻 JAVA
字号:
/**
 * Description: The description of agent with hybrid differential evolution and particle swarm.
 *
 * @ Author        Create/Modi     Note
 * Xiaofeng Xie    Jun 10, 2004
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * Please acknowledge the author(s) if you use this code in any way.
 *
 * @version 1.0
 * @Since MAOS1.0
 *
 * @References:
 * [1] Xie X F, Zhang W J, Bi D C. Handling equality constraints by adaptive
 * relaxing rule for swarm algorithms. Congress on Evolutionary Computation
 * (CEC), Oregon, USA, 2004: 2012-2016
 * [2] Zhang W J, Xie X F. DEPSO: hybrid particle swarm with differential
 * evolution operator. IEEE Int. Conf. on Systems, Man & Cybernetics,
 * Washington D C, USA, 2003: 3816-3821
 * @ The experimental-based explanation on the differential vector

 * @See PSAgent.java
 * @See DEAgent.java
 */

package agent;

import knowledge.*;

import Global.*;
import problem.*;
import space.*;

public class DEPSAgent extends AbstractAgent implements ILibEngine {
  //PS parameters
  public double CL=0;
  //constriction factors
  public double c1=1.494;
  public double c2=1.494;
  public double weight = 0.729;

  //DE parameters
  public int DVNum = 2;  //Number of differential vectors
  public double FACTOR = 0.5; //scale factor
  public double CR = 0.9;     //crossover factor

  //The referred library
  protected Library socialLib;
  //the own memory: store the point that generated in old learning cycle
  protected BasicPoint pold_t;
  //the own memory: store the point that generated in last learning cycle
  protected BasicPoint pcurrent_t;
  //the own memory: store the personal best point
  protected SearchPoint pbest_t;
  //the best point in the social sharing information
  protected BasicPoint gbest_t;

  private boolean isPSMode = true;

  public void setLibrary(Library lib) {
    socialLib = lib;
  }

  public void setProblemEncoder(ProblemEncoder encoder) {
    super.setProblemEncoder(encoder);
    pold_t = problemEncoder.getFreshSearchPoint();
    pcurrent_t = problemEncoder.getFreshSearchPoint();
  }

  public void setGbest(SearchPoint gbest) {
    gbest_t = gbest;
  }

  public void setPbest(SearchPoint pbest) {
    pbest_t = pbest;
  }

  public void generatePSPoint(ILocationEngine tempPoint) {
    DesignSpace designSpace = problemEncoder.getDesignSpace();
    int DIMENSION = designSpace.getDimension();
    double deltaxb, deltaxbm;
    for (int b=0;b<DIMENSION;b++) {
      if (Math.random()<CL) {
        designSpace.mutationAt(tempPoint.getLocation(), b);
      } else {
        deltaxb = weight*(pcurrent_t.getLocation()[b]-pold_t.getLocation()[b])
             + c1*Math.random()*(pbest_t.getLocation()[b]-pcurrent_t.getLocation()[b])
             + c2*Math.random()*(gbest_t.getLocation()[b]-pcurrent_t.getLocation()[b]);
        //limitation for deltaxb
        deltaxbm = 0.5*designSpace.getMagnitudeIn(b);
        if(deltaxb<-deltaxbm) {
          deltaxb = -deltaxbm;
        } else if (deltaxb>deltaxbm) {
          deltaxb = deltaxbm;
        }
        tempPoint.getLocation()[b] = pcurrent_t.getLocation()[b]+deltaxb;
      }
    }
  }

  protected void generatePoint(ILocationEngine tempPoint, int t) {
    isPSMode = (t%2)==0;
    if(isPSMode) {
      generatePSPoint(tempPoint);
    } else {
      generateDEPoint(tempPoint);
    }
  }

  protected void generateDEPoint(ILocationEngine tempPoint) {
    BasicPoint[] referPoints = getReferPoints();
    int DIMENSION = problemEncoder.getDesignSpace().getDimension();
    int rj = RandomGenerator.intRangeRandom(0, DIMENSION-1);
    for (int k=0; k<DIMENSION; k++) {
      if (Math.random()<CR || k == DIMENSION-1) {
        double diff = 0;
        for(int i=0; i<referPoints.length; i++) {
          diff += Math.pow(-1, i%2)*referPoints[i].getLocation()[rj];
        }
        tempPoint.getLocation()[rj] = gbest_t.getLocation()[rj]+FACTOR*diff;
      } else {
        tempPoint.getLocation()[rj] = pbest_t.getLocation()[rj];
      }
      rj = (rj+1)%DIMENSION;
    }
  }

  public void updateInfo() {
    Library.replace(specComparator, trailPoint, pbest_t);
    if(isPSMode) {
      pold_t.importLocation(pcurrent_t);
      pcurrent_t.importLocation(trailPoint);
    }
  }

  protected SearchPoint[] getReferPoints() {
    SearchPoint[] referPoints = new SearchPoint[DVNum*2];
    for(int i=0; i<referPoints.length; i++) {
      referPoints[i] = socialLib.getSelectedPoint(RandomGenerator.intRangeRandom(0, socialLib.getPopSize()-1));
    }
    return referPoints;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -