solutionoutputhandler.java

来自「用于求解TSP(Traveling salesman problem」· Java 代码 · 共 52 行

JAVA
52
字号
/**
 * Description: provide the capability for handling historical best state
 *
 * @ Author        Create/Modi     Note
 * Xiaofeng Xie    Jul 19, 2006
 */

package maosKernel.infoIO;

import java.io.*;
import Global.system.io.*;
import Global.define.*;

public class SolutionOutputHandler {
  private RandomAccessFile onlineResultFile = null;

  public SolutionOutputHandler(String tempResultDir, String resultFileName) throws Exception {
    new File(tempResultDir).mkdirs();
    String outfileName = GlobalFile.getFileLocation(tempResultDir, resultFileName);
    onlineResultFile = new RandomAccessFile(outfileName, "rw");
    System.out.println("@Output file: "+outfileName);
  }

  public void writeBytes(String message) throws Exception {
    onlineResultFile.writeBytes(message);
  }

  public void writeHead() throws Exception {
    onlineResultFile.writeBytes(this.getResultHeadString());
  }

  public void writeInitInfo(IBestCycleInfoEngine bestCycleInfoEngine) throws Exception {
    onlineResultFile.writeBytes(bestCycleInfoEngine.getBestState().writeEncodeInfo()+BasicTag.NULL_SEPERATE_TAG + bestCycleInfoEngine.getBestTime()+BasicTag.NULL_SEPERATE_TAG);
  }

  public void writeLastInfo(IBestCycleInfoEngine bestCycleInfoEngine) throws Exception {
    onlineResultFile.writeBytes(bestCycleInfoEngine.getBestState().writeEncodeInfo()+BasicTag.NULL_SEPERATE_TAG + bestCycleInfoEngine.getBestNCycle()+BasicTag.NULL_SEPERATE_TAG+bestCycleInfoEngine.getBestTime()+BasicTag.RETURN_TAG);
  }

  private String getResultHeadString() {
    return "#"
      + "Eval0" + BasicTag.NULL_SEPERATE_TAG
      + "Time0" + BasicTag.NULL_SEPERATE_TAG
      + "EvalT" + BasicTag.NULL_SEPERATE_TAG
      + "Num_T" + BasicTag.NULL_SEPERATE_TAG
      + "TimeT" + BasicTag.NULL_SEPERATE_TAG
      + BasicTag.RETURN_TAG;
  }

}

⌨️ 快捷键说明

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