?? generalmethod.java
字號:
package engine;
import integrate.Structure;
public class GeneralMethod {
public shortestPath sPath;
public genAlgrthm genRoute;
public int route[] = new int[41];
double distance[][]= new double[40][40];
int cells;
public double minDisGreedy;
public int optimalRoute[]=new int[41];
public double optDis;
public GeneralMethod(Structure input){
sPath = new shortestPath();
sPath.cells=input.unitNum;
for (int i=0; i<input.unitNum; i++){
sPath.xCell[i]=input.unitList[i].layer;
sPath.yCell[i]=input.unitList[i].rank;
}
}
public void shortestTest(){
System.out.print("Step 1: shortest path method"+"\n");
// shortestPath sPath = new shortestPath();
// sPath.randomTestData();
// sPath.preEvaluate();
cells = sPath.cells;
for (int i = 0; i < cells; i++) {
int x = sPath.xCell[i];
int y = sPath.yCell[i];
System.out.print(x);
System.out.print(y);
System.out.print('\n');
}
double minDistance = sPath.repeatetiveNearestNeighbour();
for (int j = 0; j < cells+1; j++){
optimalRoute[j]=sPath.route[j];
route[j]= sPath.route[j];
System.out.print(sPath.route[j]);
System.out.print('\n');
}
for (int i = 0; i < cells; i++){
for(int j = 0; j < cells; j++){
distance[i][j]=sPath.d[i][j];
}
}
minDisGreedy=minDistance;
System.out.print(minDistance);
}
public void genAlTest(){
System.out.print("\n"+"Step 2:genetic algorithm"+"\n");
genRoute = new genAlgrthm(minDisGreedy, optimalRoute);
genRoute.initialRoute(route);
genRoute.iteration(cells);
System.out.print("iterations: "+genRoute.iterations+"\n");
int it = genRoute.iterations;
// genRoute.initDistances();
int k=0;
while (k<=it){
/*
for (k = 0; k < cells+1; k++){
System.out.print(genRoute.route[k]+"->");
}
System.out.print("\n");
*/
genRoute.candidateRoute(cells);
genRoute.newRoute(genRoute.calDistance(distance, cells), cells);
if (genRoute.isChanged==1) {
k=0;
genRoute.isChanged=0;
}
else
k++;
}
System.out.print("route is:");
for (k = 0; k < cells+1; k++){
System.out.print(genRoute.optimal[k]+"->");
}
System.out.print("\n");
System.out.print("total distance is :"+genRoute.optimalDistance);
optDis=genRoute.optimalDistance;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -