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

📄 basicparamholder.java

📁 用于求解TSP(Traveling salesman problem
💻 JAVA
字号:
/** * Description: Holds the parameters. * * @ Author        Create/Modi     Note * Xiaofeng Xie    Apr 28, 2006 * Xiaofeng Xie    Apr 28, 2006    MAOS-TSP Beta 1.1.002 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. * * Please acknowledge the author(s) if you use this code in any way. * * @version 1.0 * @Since MAOS1.0 * */package maosKernel.infoIO;import Global.basic.*;import Global.define.*;import Global.methods.*;import Global.system.io.*;import Global.system.*;public class BasicParamHolder extends BasicAttrib {  // file system  public final String defaultSettingPath = GlobalPath.SettingPATH;  public final String defaultSettingFile = "default.par";  public final String defaultPathFile = "paths.par";  public final String InstancePath = "instance";  public final String SolutionPath = "solution";  public String solver = "";  public String problemName = "";  public String defaultProjectPath = GlobalPath.ProjectPath;  public String[] defaultProblemSuffixes = {};  public String solutionSuffix = ".sln";  //swarm parameters  public int DUP_TIMES = 1;  public int N = 300;     //importance: high level  public int Nact = -1;   //importance: high level  public int T = 500;     //importance: high level  public int Tcon = 50;   //importance: medium level  //outout parameters  public int Tout = 5;    //importance: null level  public String ResLABEL = "res";    //importance: null level, only for output (The prefix of created directory)  public String ResHOME = "temp";    //importance: null level, only for output (the home directory of result)  //For memory elements  public boolean MEMisPBest = true;   //pBest or pRecent  /*********************************************************/  public boolean printSol = false;    //importance: null level  /*********************************************************/  public BasicParamHolder() {  }  public String getSummary() {    String sumStr = "";    sumStr += "#Problem: "+problemName;    sumStr += getProbSummary();    sumStr += BasicTag.RETURN_TAG;    sumStr += "#BasicParams: ";    sumStr += "N="+N+",";    sumStr += "Nact="+Nact+",";    sumStr += "MEMisPBest="+MEMisPBest+",";    sumStr += "T="+T+",";    sumStr += "Tcon="+Tcon+"|";    sumStr += "DUP_TIMES="+DUP_TIMES+",";    sumStr += "Tout="+Tout;    sumStr += BasicTag.RETURN_TAG;    sumStr += "#SpecParams: ";    String specStr = getSpecSummary();    if (specStr.trim().length()==0) {      sumStr += "None";    } else {      sumStr += specStr;    }    sumStr += BasicTag.RETURN_TAG;    return sumStr;  }  public String getTempResultDir() {    String str = ResLABEL;    str += "_N"+N;    str += "_NAct"+Nact;    str += "_MEMisPBest("+MEMisPBest+")";    str += getSpecTempResultDir();    return GlobalFile.getFileLocation(this.ResHOME, str);  }  protected String getSpecTempResultDir() {    return "";  }  public String getSpecProjectPath() {    return GlobalFile.getFileLocation(defaultProjectPath, solver);  }  public String getSpecSettingPath() {    return GlobalFile.getFileLocation(defaultSettingPath, solver);  }  public String getSolutionPath() {    return GlobalFile.getFileLocation(getSpecProjectPath(), SolutionPath);  }  public String getInstancePath() {    return GlobalFile.getFileLocation(getSpecProjectPath(), InstancePath);  }  public String getResultLogFileName() {    return problemName+getSpecResultFileNameBody()+"_"+System.currentTimeMillis()+".log";  }  protected String getSpecResultFileNameBody()  {    return "";  }  protected String getProbSummary() {    return "";  }  protected String getSpecSummary() {    return "";  }  protected void readDefaultSettingFile(String fileName) {    try {      String content = GlobalFile.getStringFromFile(fileName);      String[] lines = GlobalString.getMeaningfulLines(content);      parserInputs(lines, false);    }    catch (Exception e) {      System.out.println(e.getMessage());    }  }  public void loadDefaultFile() {    String basicSettingFile = defaultSettingPath+BasicTag.FILE_SEP_TAG+defaultSettingFile;    readDefaultSettingFile(basicSettingFile);    String specSettingFile = getSpecSettingPath()+BasicTag.FILE_SEP_TAG+defaultSettingFile;    readDefaultSettingFile(specSettingFile);  }  protected boolean parserSpecParam(String name, String value) throws Exception {    return false;  }  private boolean parserParam(String name, String value) throws Exception {    if(name.equalsIgnoreCase("Problem")) problemName = value;    else if(name.equalsIgnoreCase("T")) T = TypeConverter.toInteger(value);    else if(name.equalsIgnoreCase("Tout")) Tout = TypeConverter.toInteger(value);    else if(name.equalsIgnoreCase("Tcon")) Tcon = TypeConverter.toInteger(value);    else if(name.equalsIgnoreCase("N")) N = TypeConverter.toInteger(value);    else if(name.equalsIgnoreCase("Nact")) Nact = TypeConverter.toInteger(value);    else if(name.equalsIgnoreCase("DUP_TIMES")) DUP_TIMES = TypeConverter.toInteger(value);    else if(name.equalsIgnoreCase("MEMisPBest")) MEMisPBest = new Boolean(value).booleanValue();    else if(name.equalsIgnoreCase("ResLABEL")) ResLABEL = value;    else if(name.equalsIgnoreCase("ResHOME")) ResHOME = value;    else if(name.equalsIgnoreCase("PrjPath")) defaultProjectPath = value;    else if(name.equalsIgnoreCase("printSol")) printSol = new Boolean(value).booleanValue();    else {      return parserSpecParam(name, value);    }    return true;  }  /**   * Support the commoand line inputs, format at follows: Name=value   */  public void parserInputs(String[] args, boolean isPrint) {    if(args.length>0) {      for(int i=0; i<args.length; i++) {        if (isPrint) System.out.println("     =>Reading: "+args[i]);        String[] vals = GlobalString.tokenize(args[i], BasicTag.EQUAL_TAG);        if(vals.length == 2) {          try {            if (!parserParam(vals[0], vals[1])) {              if(isPrint) System.out.println(" *ERROR: No such parameter: "+vals[0]);            }          } catch (Exception e) {            if(isPrint)System.out.println(" *ERROR: "+e.getMessage()+", use default value");          }        } else {          if(isPrint) System.out.println(" *ERROR: not a valid parameter");        }      }    }  }  protected String getSpecUsage() {    return "";  }  public String getUsage() {    String usageStr = "";    usageStr += "@Parameters can be given by [NAME=VALUE] or specfied in setting files"+BasicTag.RETURN_TAG;    usageStr += "NAME        V_Type   Description"+BasicTag.RETURN_TAG;    usageStr += "Problem     String   Mandatory! The name of problem to be solved"+BasicTag.RETURN_TAG;    usageStr += "------------------------Basic Parameters----------------------------"+BasicTag.RETURN_TAG;    usageStr += "N           integer  Swarm: The number of agents (N>1)"+BasicTag.RETURN_TAG;    usageStr += "Nact        integer  Swarm: The number of active agents in a cycle"+BasicTag.RETURN_TAG;    usageStr += "T           integer  Termiate condition: maximum learning cycles"+BasicTag.RETURN_TAG;    usageStr += "Tcon        integer  Termiate condition: cycles for unvaried best cost"+BasicTag.RETURN_TAG;    usageStr += "Knni        integer  Candidate set: The size of neighbors"+BasicTag.RETURN_TAG;    usageStr += "MEMisPBest  boolean  Memory element: pBest or pRecent"+BasicTag.RETURN_TAG;    usageStr += "Tout        integer  Output: the interval cycles"+BasicTag.RETURN_TAG;    String specStr = getSpecSummary();    if (specStr.trim().length()!=0) {      usageStr += "------------------------Spec  Parameters----------------------------"+BasicTag.RETURN_TAG;      usageStr += specStr;    }    return usageStr;  }}

⌨️ 快捷键说明

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