From: Gilles Thouenon Date: Wed, 25 Oct 2023 11:35:29 +0000 (+0200) Subject: Bump jgrapht upstream dependency to 1.5.2 X-Git-Tag: 9.0.0~73 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=transportpce.git;a=commitdiff_plain;h=ef07061cf7c0b08dc2f29d640892049c2f8c30b4 Bump jgrapht upstream dependency to 1.5.2 - bump to the latests jgrapht version - replace the KShortestSimplePaths deprecated algo by the new YenKShortestPath one JIRA: TRNSPRTPCE-770 Signed-off-by: Gilles Thouenon Change-Id: I0fefeefbab1d195bfbb466fd3f68cfffe19a0c77 --- diff --git a/pce/pom.xml b/pce/pom.xml index 8c9473dcc..0817accb7 100644 --- a/pce/pom.xml +++ b/pce/pom.xml @@ -152,7 +152,7 @@ org.jgrapht jgrapht-core - 1.2.0 + 1.5.2 com.github.spotbugs diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/graph/PceGraph.java b/pce/src/main/java/org/opendaylight/transportpce/pce/graph/PceGraph.java index dbd4111b2..768a65d56 100644 --- a/pce/src/main/java/org/opendaylight/transportpce/pce/graph/PceGraph.java +++ b/pce/src/main/java/org/opendaylight/transportpce/pce/graph/PceGraph.java @@ -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 allPceNodes = new HashMap<>(); private Map allPceLinks = new HashMap<>(); @@ -93,7 +91,7 @@ public class PceGraph { LOG.info(" In PCE GRAPH calcPath : K SHORT PATHS algorithm "); - DefaultDirectedWeightedGraph weightedGraph = + Graph weightedGraph = new DefaultDirectedWeightedGraph<>(PceGraphEdge.class); populateWithNodes(weightedGraph); populateWithLinks(weightedGraph); @@ -160,16 +158,15 @@ public class PceGraph { return (pceResult.getStatus()); } - private boolean runKgraphs(DefaultDirectedWeightedGraph weightedGraph) { + private boolean runKgraphs(Graph weightedGraph) { if (weightedGraph.edgeSet().isEmpty() || weightedGraph.vertexSet().isEmpty()) { return false; } PathValidator wpv = new InAlgoPathValidator(); - // KShortestPaths on weightedGraph - KShortestSimplePaths swp = - new KShortestSimplePaths<>(weightedGraph, mhopsPerPath, wpv); + // YenShortestPath on weightedGraph + YenKShortestPath swp = new YenKShortestPath<>(weightedGraph, wpv); List> 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 weightedGraph) { + private void populateWithNodes(Graph weightedGraph) { Iterator> nodes = allPceNodes.entrySet().iterator(); while (nodes.hasNext()) { Map.Entry node = nodes.next(); @@ -218,7 +215,7 @@ public class PceGraph { } } - private boolean populateWithLinks(DefaultDirectedWeightedGraph weightedGraph) { + private boolean populateWithLinks(Graph weightedGraph) { Iterator> 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 getPathAtoZ() { return shortestPathAtoZ; }