ationID.get(p)-stationID.get(q)==1){ ? ? ?Dist[p][q] = 1; ? ? ?Dist[q][p] = 1; ? ? }else{ ? ? ?Dist[p][q] = 0; ? ? ?Dist[q][p] = 0; ? ? } ? ? ? ? Path[p][q] = 0; ? ? Path[p][q] = 0; ? ?} ? } ? // 营口道? 转乘认为是一站地,13 78 得严格按照文件的顺序写,自己数数去 ? Dist[13][78]=1; ? Dist[78][13]=1; ? // 西南角? 转乘认为是一站地 ? Dist[9][53]=1; ? Dist[53][9]=1; ? // 天津站? 转乘认为是一站地 ? Dist[46][57]=1; ? Dist[57][46]=1; ? Dist[46][81]=1; ? Dist[81][46]=1; ? Dist[57][81]=1; ? Dist[81][57]=1; ? ?} ?/* 功能:递归函数的调用,计算路径所经过的站点时,会用到的 ? * @param: null ? * @调用其他函数: null ? * @return: null ? */ ?// 递归求各个路径上的点 ?private void Root(int p,int q){ ? if(Path[p][q]>0){ ? ? ? ? Root(p,Path[p][q]); ? ? ? ? Root(Path[p][q],q); ? ? }else{ ? ? ? ? Line[k]=q; ? ? ? ? k++; ? ? } ?} ?/* 功能:核心算法,floyd计算各个站点之间的路径 ? * @param: null ? * @调用其他函数: null ? * @return: null ? */ ?// floyd算法的计算最短路径 ?private void floyd() ?{ ? ? int k,p,q; ? ? for(k=1;k<=Vertex;k++){ ? ? ? ? for(p=1;p<=Vertex;p++){ ? ? ? ? ? ? if(Dist[p][k]>0){ ? ? ? ? ? ? ? ? for(q=1;q<=Vertex;q++){ ? ? ? ? ? ? ? ? ? ? if(Dist[k][q]>0){ ? ? ? ? ? ? ? ? ? ? ? ? if(((Dist[p][q]>Dist[p][k]+Dist[k][q])||(Dist[p][q]==0))&&(p!=q)){ ? ? ? ? ? ? ? ? ? ? ? ? ? ? Dist[p][q]=Dist[p][k]+Dist[k][q]; ? ? ? ? ? ? ? ? ? ? ? ? ? ? Path[p][q]=k; ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? } ? ? } ?} ? ? ?public static void main(String[] args){ ? MetroFloyd metroFloyd = new MetroFloyd(); ? ? // 2305,刘园,117.123174,39.214493 ? String originalPath = "D:\\tjdata_metro\\STATIONID_NAME_NEW.csv"; ? String destinationPath="D:\\tjdata_metro\\MetroFloydID.csv"; ? String destinationPath2="D:\\tjdata_metro\\MetroFloydName.csv"; ? metroFloyd.readText(originalPath); ? metroFloyd.init(); ? metroFloyd.floyd(); ? metroFloyd.writeText(destinationPath); ? metroFloyd.writeText2(destinationPath2); ?}
|