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

📄 scagent.java

📁 用java实现的改进粒子群算法
💻 JAVA
字号:
/**
 * Description: The description of social cognitive agent.
 *
 * @Information source: a) external library (L); b) the own memory: a point that
 * generated in the last learning cycle
 *
 * @Coefficients: TaoB and TaoW
 *
 * @ Author        Create/Modi     Note
 * Xiaofeng Xie    Mar 11, 2003
 * Xiaofeng Xie    May 11, 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. Solving engineering design problems by social
 * cognitive optimization. Genetic and Evolutionary Computation Conference
 * (GECCO), Part I, Washington, USA, 2004: 261-262 (LNCS 3102, \u00A9Springer)
 */
package agent;

import knowledge.*;

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

public class SCAgent extends AbstractAgent implements ILibEngine {
  private double[] imagePoint;  //temp value for speedup

  //the coefficients of SCAgent
  public int TaoB = 2;  //Tournament size for better point
  //The early version set TaoW as the size of external library (NL), but 4 is often enough
  public int TaoW = 4;  //Tournament size for worse point

  //The referred external library
  protected Library socialLib;

  //the own memory: store the point that generated in last learning cycle
  protected SearchPoint pcurrent_t;

  public void setProblemEncoder(ProblemEncoder encoder) {
    super.setProblemEncoder(encoder);
    pcurrent_t = problemEncoder.getEncodedSearchPoint();
    imagePoint = new double[pcurrent_t.getLocation().length];
  }

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

  protected void generatePoint(ILocationEngine tempPoint, int t) {
    SearchPoint Xmodel, Xrefer, libBPoint;

    // choose Selects a better point (libBPoint) from socialLib (L) based
    // on tournament selection
    int xb = socialLib.tournamentSelection(specComparator, TaoB, true);
    libBPoint = socialLib.getSelectedPoint(xb);
    // Compares pcurrent_t with libBPoint
    // The better one becomes model point (Xmodel)
    // The worse one becomes refer point (Xrefer)
    if(specComparator.compare(pcurrent_t.getEncodeInfo(), libBPoint.getEncodeInfo())==IGoodnessCompareEngine.LARGER_THAN) {
      Xmodel = libBPoint;
      Xrefer = pcurrent_t;
    } else {
      Xmodel = pcurrent_t;
      Xrefer = libBPoint;
    }
    // observational learning: generates a new point near the model point, which
    // the variation range is decided by the difference of Xmodel and Xrefer
    directBehavior(tempPoint, Xmodel, Xrefer, problemEncoder.getDesignSpace());
  }

  public void updateInfo() {
    //Selects a bad point kw from TaoW points in Library
    int xw = socialLib.tournamentSelection(specComparator, TaoW, false);
    //Repaces kw with pcurrent_t
    socialLib.getSelectedPoint(xw).importPoint(pcurrent_t);
    //Repaces pcurrent_t (x(t)) with trailPoint (x(t+1))
    pcurrent_t.importPoint(trailPoint);
   }

  //  1---model point, 2---refer point
  public boolean directBehavior(ILocationEngine newPoint, ILocationEngine agent1,ILocationEngine agent2, DesignSpace space){
    double[] real1, real2;
    real1 = agent1.getLocation();
    real2 = agent2.getLocation();
    //get image point
    for (int i=0; i<imagePoint.length; i++) {
      imagePoint[i] = real1[i]*2-real2[i];
    }
    //boundary handling (the S_infer the intersect of Search space and the neighour space)
    space.boundAdjust(imagePoint);
    //Infers a new point x(t+1) that random selected from infer space (S_infer)
    for(int i=0;i<space.getDimension();i++) {
      newPoint.getLocation()[i]=RandomGenerator.doubleRangeRandom(imagePoint[i], real2[i]);
    }
    return true;
  }
}

⌨️ 快捷键说明

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