stateset.java

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

JAVA
105
字号
/** * Description: Include the states and the relative information. * * @ Author        Create/Modi     Note * Xiaofeng Xie    Mar  7, 2003 * Xiaofeng Xie    May  3, 2003 * 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.1 * @Since MAOS1.0 */package maosKernel.represent;import Global.basic.*;import Global.methods.*;import maosKernel.represent.space.*;public class StateSet extends BasicAttrib implements IINFOStateTag {  protected EncodedState[] libPoints = new EncodedState[0];  public StateSet(int number, AbsSearchSpace initSpace) {    EncodedState[] libPoints = new EncodedState[number];    for (int i=0; i<number; i++) {      libPoints[i] = new EncodedState(initSpace.getRandomState());    }    initPoints(libPoints);  }  public StateSet(EncodedState[] libPoints) {    this.libPoints = libPoints;  }  protected void initPoints(EncodedState[] points) {    libPoints = points;  }  protected void appendPoints(EncodedState[] points) {    if(points==null) return;    this.libPoints = appendPoints(libPoints, points);  }  protected static EncodedState[] appendPoints(EncodedState[] points1, EncodedState[] points2) {    EncodedState[] newPoints = new EncodedState[points1.length+points2.length];    System.arraycopy(points1, 0, newPoints, 0, points1.length);    System.arraycopy(points2, 0, newPoints, points1.length, points2.length);    return newPoints;  }  public int getLibSize() {    return libPoints.length;  }  public int getRandomIndex() {    int num = getLibSize();    if (num==0) return -1;    return RandomGenerator.intRangeRandom(num);  }  public EncodedState getRandomPoint() {    int index = getRandomIndex();    if (index==-1) return null;    return getSelectedPoint(index);  }  public EncodedState getSelectedPoint(int index) {    return libPoints[index];  }  public int getPointIndex(EncodedState point) {    for(int i=0; i<this.libPoints.length; i++) {      if(point.equals(libPoints[i])) {        return i;      }    }    return -1;  }  public EncodedState[] getAllPoints(int[] idArray) {    EncodedState[] points = new EncodedState[idArray.length];    for(int i=0; i<idArray.length; i++) {      points[i] = libPoints[idArray[i]];    }    return points;  }  public EncodedState[] getAllPoints() {    return libPoints;  }}

⌨️ 快捷键说明

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