📄 cycleinfomanager.java
字号:
/**
* Description: For managing the results in each cycle
*
* @ Author Create/Modi Note
* Xiaofeng Xie Nov 10, 2006
*/
package maosKernel.infoIO;
import Global.define.*;
import Global.system.*;
import Global.util.*;
import maosKernel.represent.*;
import maosKernel.infoIO.runtime.*;
import maosKernel.represent.landscape.*;
import maosKernel.memory.*;
import maosKernel.infoIO.historical.*;
import maosKernel.infoIO.screen.*;
public final class CycleInfoManager {
private final String RUN_TIME_FLAG = "runTime";
private CycleResult currCycleResult; //for current CycleResult
private CycleRunInfo cycleRunInfo; //for best CycleResult
private NormalScreenOutputHandler normalScreenOutputHandler;
private IHistoricalHandleEngine historicalStateHandler;
private ResultOutputHandler resultOutputHandler;
private RuntimeScheduler runtimeScheduler;
private ITerminateCycleCheckEngine terminationCondition;
boolean isLastImproved = false;
public CycleInfoManager(AbsLandscape virtualLandscape, CycleResult cycleResult, IHistoricalHandleEngine historicalStateHandler, NormalScreenOutputHandler normalScreenOutputHandler, ResultOutputHandler resultOutputHandler, ITerminateCycleInfoEngine terminateCycleInfoEngine) {
this.currCycleResult = cycleResult;
cycleRunInfo = new CycleRunInfo(virtualLandscape);
cycleRunInfo.setTemplate(cycleResult);
TerminationCondition realTerminationCondition = new TerminationCondition();
realTerminationCondition.setCycleLimit(cycleRunInfo, terminateCycleInfoEngine);
this.terminationCondition = realTerminationCondition;
this.historicalStateHandler = historicalStateHandler;
this.resultOutputHandler = resultOutputHandler;
this.normalScreenOutputHandler = normalScreenOutputHandler;
this.terminationCondition = terminationCondition;
}
public void setRuntimeScheduler(RuntimeScheduler runtimeScheduler) {
this.runtimeScheduler = runtimeScheduler;
}
public void writeResultHeadMessage(String msgString) throws Exception {
resultOutputHandler.writeHeadString(msgString);
}
public void setStart() {
GlobalTools.CPUTimeCostCounter.setStart(RUN_TIME_FLAG);
}
public void setEnd() {
GlobalTools.CPUTimeCostCounter.setEnd(RUN_TIME_FLAG);
}
public CycleResult getCurrentCycleResult() {
return currCycleResult;
}
public boolean cycleCheck() throws Exception {
GlobalTools.CPUTimeCostCounter.setEnd(RUN_TIME_FLAG);
if (runtimeScheduler!=null) runtimeScheduler.schedule();
int cycleNumber = currCycleResult.NCycle;
EncodedState cycleBestState = currCycleResult.BState;
currCycleResult.Time = GlobalTools.CPUTimeCostCounter.getTotalTimeInSeconds(RUN_TIME_FLAG);
//Check if the cost of best state is changed
boolean isImproved = cycleRunInfo.checkCycle(currCycleResult);
if (isImproved) isLastImproved = true;
if (cycleNumber==0) {
GradedOut.showNORMALMessage(currCycleResult.getFullHeadString("_C")+"|"+BasicTag.NULL_SEPERATE_TAG+cycleRunInfo.getCycleResult().getFullHeadString("_B"));
resultOutputHandler.writeInitInfo(currCycleResult);
}
//Check termination conditions
boolean isTerminated =
historicalStateHandler.isOptimalState(cycleBestState) ||
terminationCondition.isCycleTerminated(cycleNumber);
boolean hasRecordState = historicalStateHandler.updateHistoricalState(cycleBestState);
boolean isNormalOutput = normalScreenOutputHandler.isCycleNormalOutput(cycleNumber);
if (isTerminated||isNormalOutput||hasRecordState) { //print screen information
String msg = currCycleResult.getFullDataLine();
if (isLastImproved) {
msg += "|"+BasicTag.NULL_SEPERATE_TAG+cycleRunInfo.getCycleResult().getFullDataLine();
isLastImproved = false;
}
GradedOut.showNORMALMessage(msg);
}
if (isTerminated) {
//output information
resultOutputHandler.writeLastInfo(cycleRunInfo.getCycleResult());
historicalStateHandler.outputHistoryState();
GradedOut.showIMPORTANTMessage(MessageTags.MSGTAG_PLAIN+"Trial summary: "+cycleRunInfo.getCycleResult().getCycleInfo());
} else {
}
GlobalTools.CPUTimeCostCounter.setStart(RUN_TIME_FLAG);
return isTerminated;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -