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

📄 goodnesslandscape.java

📁 pso源程序
💻 JAVA
字号:
/** * Description: The goodness landscape for 0-1 Quadratic Knapsack Problem (QKP). * * @ Author        Create/Modi     Note * Xiaofeng Xie    Jul 12, 2006 * Xiaofeng Xie    Aug 09, 2006 * * @version 1.0 * @Since SWAF1.0 */package implement.QKP.represent;import Global.basic.data.collection.*;import maosKernel.represent.problem.*;import maosKernel.represent.landscape.*;import maosKernel.represent.space.*;import implement.common.represent.*;public class GoodnessLandscape extends AbsILandscape implements IConstraintEngine {  protected IGetProblemDataEngine dataStorager = null;  private int[] selectedIDs;  public GoodnessLandscape(RealProblemData problemData) {    super(problemData);    this.dataStorager = problemData;    selectedIDs = new int[problemData.getNodeNumber()];  }  public int getTotalConstrainValueLimit() {    return dataStorager.getWeightLimit();  }  public int getLocalChangedConstrainValue(int nodeID) {    return dataStorager.getWeightAt(nodeID);  }  public AbsPureSpace getMeasurableSearchSpace() {    return new AbsPureSpace(){      public boolean isValid(SearchState searchState) {        boolean isV = getSearchSpace().isValid(searchState);        if (!isV) return false;        return (getWSum(searchState) <= dataStorager.getWeightLimit());      }    };  }  public IGetProblemDataEngine getIGetProblemDataEngine() {    return dataStorager;  }  protected AbsSearchSpace initSearchSpace(AbsProblemData problemData) {    return new SearchSpace(problemData.getNodeNumber());  }  private int getWSum(SearchState state) {    int wSum = 0;    IBasicICollectionEngine basicCollection = state.getTrueElements();    for (int i=0; i<basicCollection.getSize(); i++) {      wSum += dataStorager.getWeightAt(basicCollection.getElementAt(i));    }    return wSum;  }  public int getPSum(SearchState state) {    IBasicICollectionEngine basicCollection = state.getTrueElements();    int dataSize = basicCollection.getSize();    int i, j;    for (i=0; i<dataSize; i++) {      selectedIDs[i] = basicCollection.getElementAt(i);    }    int lSum = 0;    int qSum = 0;    for (i=0; i<dataSize; i++) {      lSum += dataStorager.getLinearValueAt(selectedIDs[i]);      int[] quadAtI = dataStorager.getQuadraticValueAt(selectedIDs[i]);      for (j = i+1; j < dataSize; j++) {        qSum += quadAtI[selectedIDs[j]];      }    }    return lSum+qSum;  }  public int getGlobalCost(SearchState state) {    return -1*(getPSum(state));  }}

⌨️ 快捷键说明

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