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

📄 firstimproveswaper.java

📁 pso源程序
💻 JAVA
字号:
/**
 * Description: The description of first improvement search schedule.
 *
 * @ Author        Create/Modi     Note
 * Xiaofeng Xie    Oct 06, 2006
 *
 * @version 1.0
 *
 * @Reference
 * [1] T. St黷zle, "An ant approach to the flow shop problem," European
 * Congress on Intelligent Techniques and Soft Computing, Aachen, Germany,
 * pp. 1560-1564, 1998.
 */

package maosKernel.behavior.greedy;

import maosKernel.represent.space.*;
import maosKernel.behavior.mutate.*;
import Global.basic.nodes.utilities.*;
import Global.methods.*;
import maosKernel.represent.landscape.*;

public class FirstImproveSwaper extends AbsSystematicChanger {
  private int improveTimes = Integer.MAX_VALUE;

  public FirstImproveSwaper() {
  }

  protected void setRootInfo(AbsLandscape landscape) {
    int nodeNumber = landscape.getSearchSpace().getNodeNumber();
    super.init(nodeNumber);
  }

  public void initUtilities() {
    super.initUtilities();
    initUtility(new IntegerUtility("improveTimes", improveTimes));
  }

  public void shortcutInit() throws Exception  {
    super.shortcutInit();
    improveTimes = TypeConverter.toInteger(getValue("improveTimes"));
  }

  // 2-change systematic search, return delta_Cost
  public int systematicSearch(SearchState state, ILocalChangeEngine localChangeEngine){
    int nodeA, nodeB;
    boolean isImproved = true;
    int totalDelta = 0;
    int nodeNumber = state.getNodeNumber();

    int[] randArrayA, randArrayB;
    localChangeEngine.setState(state);
    int j, k;
    int times, delta, minDelta, minNodeB=-1;

    while (isImproved) {
      isImproved = false;
      randArrayA = getRandomOrderArray();
      for (j = 0; j < nodeNumber; j ++) {
        if (isImproved) break;
        nodeA = randArrayA[j];
        localChangeEngine.setBaseNodeID(nodeA);
        randArrayB = getRandomOrderArray();
        times = 0;
        minDelta = 0;
        for (k = 0; k < nodeNumber; k++) {
          nodeB = randArrayB[k];
          if (nodeA==nodeB) continue;
          delta = localChangeEngine.getDeltaCost(nodeB);
          if (delta < minDelta) {
            minDelta = delta;
            minNodeB = nodeB;
            times++;
            if (times>=improveTimes) {
              break;
            }
          }
        }
        if (minDelta<0) {
          totalDelta += minDelta; localChangeEngine.changeBehavior(minNodeB); isImproved = true;
        }
      }
    }
    return totalDelta;
  }
}

⌨️ 快捷键说明

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