Bump jgrapht upstream dependency to 1.5.2 55/108655/5
authorGilles Thouenon <gilles.thouenon@orange.com>
Wed, 25 Oct 2023 11:35:29 +0000 (13:35 +0200)
committerGilles Thouenon <gilles.thouenon@orange.com>
Thu, 9 Nov 2023 07:52:52 +0000 (08:52 +0100)
- bump to the latests jgrapht version
- replace the KShortestSimplePaths deprecated algo by the new
YenKShortestPath one

JIRA: TRNSPRTPCE-770
Signed-off-by: Gilles Thouenon <gilles.thouenon@orange.com>
Change-Id: I0fefeefbab1d195bfbb466fd3f68cfffe19a0c77

pce/pom.xml
pce/src/main/java/org/opendaylight/transportpce/pce/graph/PceGraph.java

index 8c9473dcc06a6db45bac53ad29f9ad84d44afa6c..0817accb7c723136dedb41d573a2b45adbc03ae3 100644 (file)
     <dependency>
       <groupId>org.jgrapht</groupId>
       <artifactId>jgrapht-core</artifactId>
-      <version>1.2.0</version>
+      <version>1.5.2</version>
     </dependency>
     <dependency>
       <groupId>com.github.spotbugs</groupId>
index dbd4111b2e838f38ceaa802167f5d87ca11333ef..768a65d5600009775eb63b1428ebdfb826d229f0 100644 (file)
@@ -17,9 +17,10 @@ import java.util.Map.Entry;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 import java.util.stream.IntStream;
+import org.jgrapht.Graph;
 import org.jgrapht.GraphPath;
-import org.jgrapht.alg.shortestpath.KShortestSimplePaths;
 import org.jgrapht.alg.shortestpath.PathValidator;
+import org.jgrapht.alg.shortestpath.YenKShortestPath;
 import org.jgrapht.graph.DefaultDirectedWeightedGraph;
 import org.opendaylight.transportpce.common.ResponseCodes;
 import org.opendaylight.transportpce.common.StringConstants;
@@ -44,9 +45,6 @@ public class PceGraph {
     // how many paths to bring
     private int kpathsToBring = 15;
 
-    // max #hops
-    private int mhopsPerPath = 100;
-
     // input
     private Map<NodeId, PceNode> allPceNodes = new HashMap<>();
     private Map<LinkId, PceLink> allPceLinks = new HashMap<>();
@@ -93,7 +91,7 @@ public class PceGraph {
 
         LOG.info(" In PCE GRAPH calcPath : K SHORT PATHS algorithm ");
 
-        DefaultDirectedWeightedGraph<String, PceGraphEdge> weightedGraph =
+        Graph<String, PceGraphEdge> weightedGraph =
                 new DefaultDirectedWeightedGraph<>(PceGraphEdge.class);
         populateWithNodes(weightedGraph);
         populateWithLinks(weightedGraph);
@@ -160,16 +158,15 @@ public class PceGraph {
         return (pceResult.getStatus());
     }
 
-    private boolean runKgraphs(DefaultDirectedWeightedGraph<String, PceGraphEdge> weightedGraph) {
+    private boolean runKgraphs(Graph<String, PceGraphEdge> weightedGraph) {
 
         if (weightedGraph.edgeSet().isEmpty() || weightedGraph.vertexSet().isEmpty()) {
             return false;
         }
         PathValidator<String, PceGraphEdge> wpv = new InAlgoPathValidator();
 
-        // KShortestPaths on weightedGraph
-        KShortestSimplePaths<String, PceGraphEdge> swp =
-            new KShortestSimplePaths<>(weightedGraph, mhopsPerPath, wpv);
+        // YenShortestPath on weightedGraph
+        YenKShortestPath<String, PceGraphEdge> swp = new YenKShortestPath<>(weightedGraph, wpv);
         List<GraphPath<String, PceGraphEdge>> weightedPathList = swp
             .getPaths(apceNode.getNodeId().getValue(), zpceNode.getNodeId().getValue(), kpathsToBring);
         allWPaths = IntStream
@@ -207,7 +204,7 @@ public class PceGraph {
         return true;
     }
 
-    private void populateWithNodes(DefaultDirectedWeightedGraph<String, PceGraphEdge> weightedGraph) {
+    private void populateWithNodes(Graph<String, PceGraphEdge> weightedGraph) {
         Iterator<Map.Entry<NodeId, PceNode>> nodes = allPceNodes.entrySet().iterator();
         while (nodes.hasNext()) {
             Map.Entry<NodeId, PceNode> node = nodes.next();
@@ -218,7 +215,7 @@ public class PceGraph {
         }
     }
 
-    private boolean populateWithLinks(DefaultDirectedWeightedGraph<String, PceGraphEdge> weightedGraph) {
+    private boolean populateWithLinks(Graph<String, PceGraphEdge> weightedGraph) {
 
         Iterator<Map.Entry<NodeId, PceNode>> nodes = allPceNodes.entrySet().iterator();
         while (nodes.hasNext()) {
@@ -283,10 +280,6 @@ public class PceGraph {
         this.kpathsToBring = kpathsToBring;
     }
 
-    public void setMhopsPerPath(int mhopsPerPath) {
-        this.mhopsPerPath = mhopsPerPath;
-    }
-
     public List<PceLink> getPathAtoZ() {
         return shortestPathAtoZ;
     }