From 603a88bb1c9fedf4a4eb03a517fdaef1cb58369d Mon Sep 17 00:00:00 2001 From: pahimar Date: Thu, 30 May 2013 15:42:41 -0400 Subject: [PATCH] Forgot to check to make sure that a weighted directed edge doesn't already exist between two nodes when attempting to add an edge --- .../com/pahimar/ee3/emc/graph/WeightedDirectedGraph.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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) {