|
@@ -18,11 +18,11 @@ public class IPMMSVertexServiceImpl implements IIPMMSVertexService {
|
|
|
@Override
|
|
|
public ArrayList<IPMMSVertex> getObtainTheOptimalPath(String startpoint,String endPoint,Map<String, List<IPMMSVertexEdge>> vertexEdgeList, Map<String, IPMMSVertex> vertexList) throws VertexAngEdgeException {
|
|
|
|
|
|
- int[] startPoin=new int[]{0,-1};
|
|
|
+ int[] startPoin=new int[]{0,-1,0};
|
|
|
|
|
|
List<String> obtainTheOptimalPath=new ArrayList();
|
|
|
|
|
|
-
|
|
|
+
|
|
|
HashMap<String,int[]> currentBestDinstance=new HashMap<>();
|
|
|
currentBestDinstance.put(startpoint,startPoin);
|
|
|
while (obtainTheOptimalPath.size()!=vertexList.size()){
|
|
@@ -36,9 +36,6 @@ public class IPMMSVertexServiceImpl implements IIPMMSVertexService {
|
|
|
if (island(currentBestDinstance,stringMinimumValue,vertexEdgeList)){
|
|
|
continue;
|
|
|
}
|
|
|
- if (stringMinimumValue.equals("0")||stringMinimumValue.equals("13")){
|
|
|
- System.out.println();
|
|
|
- }
|
|
|
|
|
|
|
|
|
List<IPMMSVertexEdge> ipmmsVertexEdges = vertexEdgeList.get(stringMinimumValue);
|
|
@@ -66,17 +63,37 @@ public class IPMMSVertexServiceImpl implements IIPMMSVertexService {
|
|
|
if(historyBestPaht==null){
|
|
|
int distance=starBestPath[0]+ipmmsVertexEdge.getWeigh();
|
|
|
int outVertex=outVertexID.intValue();
|
|
|
- int[] bestPath=new int[]{distance,outVertex};
|
|
|
+ int[] bestPath=new int[]{distance,outVertex,ipmmsVertexEdge.getWeigh()};
|
|
|
currentBestDinstance.put(inVertexID.toString(),bestPath);
|
|
|
}else if ((starBestPath[0]+ipmmsVertexEdge.getWeigh())<historyBestPaht[0]){
|
|
|
|
|
|
+ int distance=starBestPath[0]+ipmmsVertexEdge.getWeigh();
|
|
|
+ int outVertex=outVertexID.intValue();
|
|
|
+ int[] bestPath=new int[]{distance,outVertex,ipmmsVertexEdge.getWeigh()};
|
|
|
+ currentBestDinstance.put(inVertexID.toString(),bestPath);
|
|
|
+ ArrayList<String> updateList = new ArrayList<>();
|
|
|
+ updateRelactionVertex(updateList, stringMinimumValue, currentBestDinstance);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+ if (!currentBestDinstance.containsKey(endPoint)){
|
|
|
+ throw new VertexAngEdgeException("没有该条路径,请检查是否缺少边!");
|
|
|
+ }
|
|
|
return startPointToEndPointPaht(endPoint,currentBestDinstance,vertexList);
|
|
|
}
|
|
|
+
|
|
|
+ public void updateRelactionVertex(List<String> result,String currentVertex,HashMap<String,int[]> currentBestDinstance){
|
|
|
+ Set<String> keys = currentBestDinstance.keySet();
|
|
|
+ for (String key: keys){
|
|
|
+ int[] value=currentBestDinstance.get(key);
|
|
|
+ if (value[1]==Integer.valueOf(currentVertex).intValue()){
|
|
|
+ value[0]=value[2]+currentBestDinstance.get(currentVertex)[0];
|
|
|
+ currentBestDinstance.put(key,value);
|
|
|
+ updateRelactionVertex(result,key,currentBestDinstance);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
public Boolean island(HashMap<String,int[]> currentBestDinstance,String stringMinimumValue,Map<String, List<IPMMSVertexEdge>> vertexEdgeList){
|
|
|
if(!currentBestDinstance.containsKey(stringMinimumValue)){
|
|
@@ -91,10 +108,10 @@ public class IPMMSVertexServiceImpl implements IIPMMSVertexService {
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public ArrayList<IPMMSVertex> startPointToEndPointPaht(String point,HashMap<String,int[]> currentBestDinstance,Map<String, IPMMSVertex> vertexList){
|
|
|
ArrayList<IPMMSVertex> obtainOptimalPath=new ArrayList();
|
|
|
- int beforeDistance=100;
|
|
|
+ int beforeDistance=0;
|
|
|
do {
|
|
|
int[] ints = currentBestDinstance.get(point);
|
|
|
beforeDistance=ints[1];
|
|
@@ -105,6 +122,7 @@ public class IPMMSVertexServiceImpl implements IIPMMSVertexService {
|
|
|
return obtainOptimalPath;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public String getStringMinimumValue(HashMap<String,int[]> currentBestDinstance,List<String> obtainTheOptimalPath){
|
|
|
|
|
|
HashMap<String,int[]> bestDinstance = (HashMap<String, int[]>) SerializationUtils.clone(currentBestDinstance);
|