diff --git a/ee3_common/com/pahimar/ee3/emc/graph/WeightedDirectedGraph.java b/ee3_common/com/pahimar/ee3/emc/graph/WeightedDirectedGraph.java index fb51f1fd..a60fb55d 100644 --- a/ee3_common/com/pahimar/ee3/emc/graph/WeightedDirectedGraph.java +++ b/ee3_common/com/pahimar/ee3/emc/graph/WeightedDirectedGraph.java @@ -47,7 +47,10 @@ public class WeightedDirectedGraph implements Iterable { throw new NoSuchElementException("Missing nodes from graph"); } - graph.get(from).add(new WeightedEdge(weight, to)); + // If a directed edge of the same weight doesn't already exist, add the new edge + if (!edgeExists(from, to, weight)) { + graph.get(from).add(new WeightedEdge(weight, to)); + } } public boolean edgeExists(T from, T to) {