📄 multifullgreedyswaper.java
字号:
/**
* Description: The description of 2-change strategy.
*
* @ Author Create/Modi Note
* Xiaofeng Xie Jun 12, 2006
* Xiaofeng Xie Aug 08, 2006 To common class by using ILocalChangeEngine
* Xiaofeng Xie Sep 08, 2006 Use AbsSystematicChanger
*
* @version 1.0
*
* @Reference
* [1] Taillard ED. FANT: Fast ant system. Technical Report, IDSIA-46-98, Lugano: IDSIA, 1998.
*/
package maosKernel.behavior.greedy;
import maosKernel.represent.landscape.*;
import maosKernel.represent.space.*;
import maosKernel.behavior.mutate.*;
import Global.basic.nodes.utilities.*;
import Global.methods.*;
public class MultiFullGreedySwaper extends AbsPairSystematicChanger {
public boolean isLocalReset = false;
public int MaxTrialTimes = 2;
public MultiFullGreedySwaper() {
}
protected void setRootInfo(AbsLandscape landscape) {
super.init(landscape.getSearchSpace().getNodeNumber());
}
public void initUtilities() {
super.initUtilities();
initUtility(new IntegerUtility("MaxTrialTimes", MaxTrialTimes));
initUtility(new BooleanUtility("isLocalReset", isLocalReset));
}
public void shortcutInit() throws Exception {
super.shortcutInit();
MaxTrialTimes = TypeConverter.toInteger(getValue("MaxTrialTimes"));
isLocalReset = TypeConverter.toBoolean(getValue("isLocalReset").toString());
}
// 2-change systematic search, return delta_Cost
public int systematicSearch(SearchState state, ILocalChangeEngine localChangeEngine){
int nodeA, nodeB;
int delta;
boolean isImproved = true;
int totalDelta = 0;
int nodeNumber = state.getNodeNumber();
int[] randArrayA, randArrayB;
localChangeEngine.setState(state);
int i, j, k;
for (i = 0; i < MaxTrialTimes && isImproved; i++) {
isImproved = false;
initTestFlagMatrix();
randArrayA = getRandomOrderArray();
for (j = 0; j < nodeNumber; j ++) {
nodeA = randArrayA[j];
if (isNodeInvalid(nodeA)) continue;
localChangeEngine.setBaseNodeID(nodeA);
randArrayB = getRandomOrderArray();
for (k = 0; k < nodeNumber; k++) {
nodeB = randArrayB[k];
if (nodeA==nodeB) continue;
if (isNodeInvalid(nodeB)) continue;
if (isNodePairValid(nodeA, nodeB)) {
delta = localChangeEngine.getDeltaCost(nodeB);
if (delta < 0) {
totalDelta += delta; localChangeEngine.changeBehavior(nodeB); isImproved = true;
localChangeEngine.setBaseNodeID(nodeA);
if(isLocalReset) { refreshTestFlagMatrixAt(nodeA); refreshTestFlagMatrixAt(nodeB);}
else initTestFlagMatrix();
} else {
setNodePairInvalid(nodeA, nodeB);
}
}
}
}
}
return totalDelta;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -