Fixed a derp in my edgesTo implementation

This commit is contained in:
pahimar 2013-06-01 22:17:13 -04:00
parent d8e80366e1
commit e3079cbfef
2 changed files with 23 additions and 20 deletions

View file

@ -207,19 +207,21 @@ public class DynEMC {
} }
LogHelper.log(Level.INFO, "***** END EDGES FROM *****"); LogHelper.log(Level.INFO, "***** END EDGES FROM *****");
// LogHelper.log(Level.INFO, "***** START EDGES TO *****"); LogHelper.log(Level.INFO, "***** START EDGES TO *****");
// nodeIter = graph.iterator(); nodeIter = graph.iterator();
// while (nodeIter.hasNext()) { while (nodeIter.hasNext()) {
// CustomStackWrapper node = nodeIter.next(); CustomWrappedStack node = nodeIter.next();
// Set<WeightedEdge<CustomStackWrapper>> edgesTo = graph.edgesTo(node); Set<WeightedEdge<CustomWrappedStack>> edgesTo = graph.edgesTo(node);
// for (WeightedEdge<CustomStackWrapper> edge : edgesTo) { Iterator<WeightedEdge<CustomWrappedStack>> edgeIter = edgesTo.iterator();
// LogHelper.log(Level.INFO, "From: " + node); while (edgeIter.hasNext()) {
// LogHelper.log(Level.INFO, "To: " + edge.getTarget()); WeightedEdge<CustomWrappedStack> edge = edgeIter.next();
// LogHelper.log(Level.INFO, "Weight: " + edge.getWeight()); LogHelper.log(Level.INFO, "From: " + node);
// LogHelper.log(Level.INFO, ""); LogHelper.log(Level.INFO, "To: " + edge.getTarget());
// } LogHelper.log(Level.INFO, "Weight: " + edge.getWeight());
// } LogHelper.log(Level.INFO, "");
// LogHelper.log(Level.INFO, "***** END EDGES TO *****"); }
}
LogHelper.log(Level.INFO, "***** END EDGES TO *****");
return stringBuilder.toString(); return stringBuilder.toString();
} }

View file

@ -119,17 +119,18 @@ public class WeightedDirectedGraph<T> implements Iterable<T> {
Set<WeightedEdge<T>> edgesTo = new TreeSet<WeightedEdge<T>>(new Comparator<WeightedEdge<T>>() { Set<WeightedEdge<T>> edgesTo = new TreeSet<WeightedEdge<T>>(new Comparator<WeightedEdge<T>>() {
public int compare(WeightedEdge<T> o1, WeightedEdge<T> o2) { public int compare(WeightedEdge<T> o1, WeightedEdge<T> o2) {
return o1.hashCode() - o2.hashCode();
return orderedNodes.indexOf(o1.getTarget()) - orderedNodes.indexOf(o2.getTarget());
} }
}); });
for (T node : graph.keySet()) { for (T node : graph.keySet()) {
Set<WeightedEdge<T>> edgesFrom = edgesFrom(node); if (!node.equals(to)) {
Set<WeightedEdge<T>> edgesFrom = edgesFrom(node);
for (WeightedEdge<T> fromEdge : edgesFrom) { for (WeightedEdge<T> fromEdge : edgesFrom) {
if (fromEdge.getTarget().equals(to)) { if (fromEdge.getTarget().equals(to)) {
edgesTo.add(fromEdge); edgesTo.add(new WeightedEdge<T>(fromEdge.getWeight(), node));
}
} }
} }
} }