From 77fcc58d1facffbc3af50be8c05985350e9f1355 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Sun, 17 Apr 2016 15:01:44 -0400 Subject: Code maintenace and changes --- .../src/main/java/bjc/utils/graph/Graph.java | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java b/BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java index a72304d..d08c3f9 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java +++ b/BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java @@ -10,8 +10,8 @@ import java.util.Set; import java.util.function.BiConsumer; import java.util.function.BiPredicate; -import bjc.utils.data.experimental.IHolder; -import bjc.utils.data.experimental.Identity; +import bjc.utils.data.IHolder; +import bjc.utils.data.Identity; import bjc.utils.funcdata.FunctionalMap; import bjc.utils.funcdata.IFunctionalList; import bjc.utils.funcdata.IFunctionalMap; @@ -25,7 +25,6 @@ import bjc.utils.funcdata.IFunctionalMap; * The label for vertices */ public class Graph { - /** * The backing representation of the graph */ @@ -157,20 +156,20 @@ public class Graph { // Start at the initial vertex and visit it IHolder sourceVertex = new Identity<>(getInitial()); - visitedVertexes.add(sourceVertex.unwrap(vertex -> vertex)); + visitedVertexes.add(sourceVertex.getValue()); // Make sure we visit all the nodes while (visitedVertexes.size() != getVertexCount()) { // Grab all edges adjacent to the provided edge - forAllEdgesMatchingAt(sourceVertex.unwrap(vertex -> vertex), - (targetVertex, - vertexWeight) -> !visitedVertexes - .contains(targetVertex), - (targetVertex, - vertexWeight) -> availableEdges.add(new Edge<>( - sourceVertex.unwrap(vertex -> vertex), - targetVertex, vertexWeight))); + forAllEdgesMatchingAt(sourceVertex.getValue(), + (targetVertex, vertexWeight) -> { + return !visitedVertexes.contains(targetVertex); + }, (targetVertex, vertexWeight) -> { + availableEdges.add(new Edge<>( + sourceVertex.unwrap(vertex -> vertex), + targetVertex, vertexWeight)); + }); // Get the edge with the minimum distance IHolder> minimumEdge = @@ -178,20 +177,19 @@ public class Graph { // Only consider edges where we haven't visited the target of // the edge - while (visitedVertexes.contains( - minimumEdge.unwrap(vertex -> vertex.getTarget()))) { + while (visitedVertexes.contains(minimumEdge.getValue())) { minimumEdge.transform((edge) -> availableEdges.poll()); } // Add it to our MST - minimumEdges.add(minimumEdge.unwrap(edge -> edge)); + minimumEdges.add(minimumEdge.getValue()); // Advance to the next node sourceVertex.transform((vertex) -> minimumEdge .unwrap(edge -> edge.getTarget())); // Visit this node - visitedVertexes.add(sourceVertex.unwrap(vertex -> vertex)); + visitedVertexes.add(sourceVertex.getValue()); } return minimumEdges; @@ -281,8 +279,10 @@ public class Graph { public static Graph fromEdgeList(List> edges) { Graph g = new Graph<>(); - edges.forEach(edge -> g.addEdge(edge.getSource(), edge.getTarget(), - edge.getDistance(), true)); + edges.forEach(edge -> { + g.addEdge(edge.getSource(), edge.getTarget(), + edge.getDistance(), true); + }); return g; } -- cgit v1.2.3