|
@@ -18,12 +18,12 @@ public class IPMMSVertexServiceImpl implements IIPMMSVertexService {
|
|
@Override
|
|
@Override
|
|
public ArrayList<IPMMSVertex> getObtainTheOptimalPath(String startpoint,String endPoint,Map<String, List<IPMMSVertexEdge>> vertexEdgeList, Map<String, IPMMSVertex> vertexList) throws VertexAngEdgeException {
|
|
public ArrayList<IPMMSVertex> getObtainTheOptimalPath(String startpoint,String endPoint,Map<String, List<IPMMSVertexEdge>> vertexEdgeList, Map<String, IPMMSVertex> vertexList) throws VertexAngEdgeException {
|
|
//初始化数据
|
|
//初始化数据
|
|
- String[] startPoin=new String[]{"0","-1"};
|
|
|
|
|
|
+ int[] startPoin=new int[]{0,-1};
|
|
//创建S战队(放入的是已经遍历过边的顶点)
|
|
//创建S战队(放入的是已经遍历过边的顶点)
|
|
List<String> obtainTheOptimalPath=new ArrayList();
|
|
List<String> obtainTheOptimalPath=new ArrayList();
|
|
//obtainTheOptimalPath.add(statpoint);
|
|
//obtainTheOptimalPath.add(statpoint);
|
|
//创建 dist[] (起点到集合点中的最短路径) key:指向的点 new int[]{0,-1}; {权重、中间点}
|
|
//创建 dist[] (起点到集合点中的最短路径) key:指向的点 new int[]{0,-1}; {权重、中间点}
|
|
- HashMap<String,String[]> currentBestDinstance=new HashMap<>();
|
|
|
|
|
|
+ HashMap<String,int[]> currentBestDinstance=new HashMap<>();
|
|
currentBestDinstance.put(startpoint,startPoin);
|
|
currentBestDinstance.put(startpoint,startPoin);
|
|
while (obtainTheOptimalPath.size()!=vertexList.size()){
|
|
while (obtainTheOptimalPath.size()!=vertexList.size()){
|
|
// dist[]最小值
|
|
// dist[]最小值
|
|
@@ -53,10 +53,10 @@ public class IPMMSVertexServiceImpl implements IIPMMSVertexService {
|
|
//箭头出发点
|
|
//箭头出发点
|
|
BigDecimal outVertexID = ipmmsVertexEdge.getOutVertexID();
|
|
BigDecimal outVertexID = ipmmsVertexEdge.getOutVertexID();
|
|
//到该点的最短路径
|
|
//到该点的最短路径
|
|
- String[] starBestPath = currentBestDinstance.get(outVertexID.toString());
|
|
|
|
|
|
+ int[] starBestPath = currentBestDinstance.get(outVertexID.toString());
|
|
//被指向的顶点
|
|
//被指向的顶点
|
|
BigDecimal inVertexID= ipmmsVertexEdge.getInVertexID();
|
|
BigDecimal inVertexID= ipmmsVertexEdge.getInVertexID();
|
|
- String[] historyBestPaht = currentBestDinstance.get(inVertexID.toString());
|
|
|
|
|
|
+ int[] historyBestPaht = currentBestDinstance.get(inVertexID.toString());
|
|
if (starBestPath==null){
|
|
if (starBestPath==null){
|
|
throw new VertexAngEdgeException("这条边不存在!"+outVertexID.toString()+"->"+inVertexID.toString());
|
|
throw new VertexAngEdgeException("这条边不存在!"+outVertexID.toString()+"->"+inVertexID.toString());
|
|
}else if (!outVertexID.toString().equals(stringMinimumValue)){
|
|
}else if (!outVertexID.toString().equals(stringMinimumValue)){
|
|
@@ -64,14 +64,13 @@ public class IPMMSVertexServiceImpl implements IIPMMSVertexService {
|
|
}
|
|
}
|
|
//判断是否存在其路线到这个点的距离。如果不存在则将这条线路作为起点到该点最短路径、如果本条路线是最短路径需要替换最短路径
|
|
//判断是否存在其路线到这个点的距离。如果不存在则将这条线路作为起点到该点最短路径、如果本条路线是最短路径需要替换最短路径
|
|
if(historyBestPaht==null){
|
|
if(historyBestPaht==null){
|
|
- String distance=starBestPath[0]+ipmmsVertexEdge.getWeigh();
|
|
|
|
- String outVertex=outVertexID.toString();
|
|
|
|
- String[] bestPath=new String[]{distance,outVertex};
|
|
|
|
|
|
+ int distance=starBestPath[0]+ipmmsVertexEdge.getWeigh();
|
|
|
|
+ int outVertex=outVertexID.intValue();
|
|
|
|
+ int[] bestPath=new int[]{distance,outVertex};
|
|
currentBestDinstance.put(inVertexID.toString(),bestPath);
|
|
currentBestDinstance.put(inVertexID.toString(),bestPath);
|
|
|
|
+ }else if ((starBestPath[0]+ipmmsVertexEdge.getWeigh())<historyBestPaht[0]){
|
|
|
|
+ //更新和此顶点有关的数据
|
|
}
|
|
}
|
|
-// else if ((starBestPath[0]+ipmmsVertexEdge.getWeigh())<historyBestPaht[0]){
|
|
|
|
-// //更新和此顶点有关的数据
|
|
|
|
-// }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -79,7 +78,7 @@ public class IPMMSVertexServiceImpl implements IIPMMSVertexService {
|
|
return startPointToEndPointPaht(endPoint,currentBestDinstance,vertexList);
|
|
return startPointToEndPointPaht(endPoint,currentBestDinstance,vertexList);
|
|
}
|
|
}
|
|
//判断是否有进入这个顶点的边,如果没有这个顶点就是一个孤岛
|
|
//判断是否有进入这个顶点的边,如果没有这个顶点就是一个孤岛
|
|
- public Boolean island(HashMap<String,String[]> currentBestDinstance,String stringMinimumValue,Map<String, List<IPMMSVertexEdge>> vertexEdgeList){
|
|
|
|
|
|
+ public Boolean island(HashMap<String,int[]> currentBestDinstance,String stringMinimumValue,Map<String, List<IPMMSVertexEdge>> vertexEdgeList){
|
|
if(!currentBestDinstance.containsKey(stringMinimumValue)){
|
|
if(!currentBestDinstance.containsKey(stringMinimumValue)){
|
|
Collection<List<IPMMSVertexEdge>> values = vertexEdgeList.values();
|
|
Collection<List<IPMMSVertexEdge>> values = vertexEdgeList.values();
|
|
for (List<IPMMSVertexEdge> vertexEdges : values){
|
|
for (List<IPMMSVertexEdge> vertexEdges : values){
|
|
@@ -93,22 +92,22 @@ public class IPMMSVertexServiceImpl implements IIPMMSVertexService {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
//通过所有最优解集合选择我们要的
|
|
//通过所有最优解集合选择我们要的
|
|
- public ArrayList<IPMMSVertex> startPointToEndPointPaht(String point,HashMap<String,String[]> currentBestDinstance,Map<String, IPMMSVertex> vertexList){
|
|
|
|
|
|
+ public ArrayList<IPMMSVertex> startPointToEndPointPaht(String point,HashMap<String,int[]> currentBestDinstance,Map<String, IPMMSVertex> vertexList){
|
|
ArrayList<IPMMSVertex> obtainOptimalPath=new ArrayList();
|
|
ArrayList<IPMMSVertex> obtainOptimalPath=new ArrayList();
|
|
- String beforeDistance="100";
|
|
|
|
|
|
+ int beforeDistance=100;
|
|
do {
|
|
do {
|
|
- String[] ints = currentBestDinstance.get(point);
|
|
|
|
|
|
+ int[] ints = currentBestDinstance.get(point);
|
|
beforeDistance=ints[1];
|
|
beforeDistance=ints[1];
|
|
obtainOptimalPath.add(vertexList.get(point));
|
|
obtainOptimalPath.add(vertexList.get(point));
|
|
point=String.valueOf(ints[1]);
|
|
point=String.valueOf(ints[1]);
|
|
}
|
|
}
|
|
- while (beforeDistance.equals("-1"));
|
|
|
|
|
|
+ while (beforeDistance!=-1);
|
|
return obtainOptimalPath;
|
|
return obtainOptimalPath;
|
|
}
|
|
}
|
|
|
|
|
|
- public String getStringMinimumValue(HashMap<String,String[]> currentBestDinstance,List<String> obtainTheOptimalPath){
|
|
|
|
|
|
+ public String getStringMinimumValue(HashMap<String,int[]> currentBestDinstance,List<String> obtainTheOptimalPath){
|
|
|
|
|
|
- HashMap<String,String[]> bestDinstance = (HashMap<String, String[]>) SerializationUtils.clone(currentBestDinstance);
|
|
|
|
|
|
+ HashMap<String,int[]> bestDinstance = (HashMap<String, int[]>) SerializationUtils.clone(currentBestDinstance);
|
|
|
|
|
|
for (String item:obtainTheOptimalPath){
|
|
for (String item:obtainTheOptimalPath){
|
|
if (bestDinstance.containsKey(item)){
|
|
if (bestDinstance.containsKey(item)){
|
|
@@ -119,19 +118,15 @@ public class IPMMSVertexServiceImpl implements IIPMMSVertexService {
|
|
String vertex="";
|
|
String vertex="";
|
|
int minimumValue=100;
|
|
int minimumValue=100;
|
|
for (String key :keys){
|
|
for (String key :keys){
|
|
- String[] value = currentBestDinstance.get(key);
|
|
|
|
-// if (minimumValue>value[1]){
|
|
|
|
-// minimumValue=value[1];
|
|
|
|
-// vertex=key;
|
|
|
|
-// }
|
|
|
|
|
|
+ int[] value = currentBestDinstance.get(key);
|
|
|
|
+ if (minimumValue>value[1]){
|
|
|
|
+ minimumValue=value[1];
|
|
|
|
+ vertex=key;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return vertex;
|
|
return vertex;
|
|
}
|
|
}
|
|
|
|
|
|
-// public BigDecimal getStrsValues(String,){
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
public Map<String,IPMMSVertex> initIPMMSVertex(){
|
|
public Map<String,IPMMSVertex> initIPMMSVertex(){
|
|
|
|
|
|
Map<String,IPMMSVertex> IPMMSVertexList=new HashMap<>();
|
|
Map<String,IPMMSVertex> IPMMSVertexList=new HashMap<>();
|