From 1a23d8a48c5a17b59963d31147c20a4231e87bd1 Mon Sep 17 00:00:00 2001 From: stephey Date: Wed, 30 Mar 2011 04:11:15 +0000 Subject: [PATCH] It compiles and runs now... but it doesn't appear to be doing the right thing... It passes internal verification but appears to be taking fewer iterations than the original program... --- .../oooJava/DelaunayRefinement/Cavity.java | 2 +- .../DelaunayRefinement/DirectedEdgeGraph.java | 16 ++-- .../DelaunayRefinement/DirectedGraph.java | 87 ------------------- .../DelaunayRefinement/EdgeGraphNode.java | 8 +- .../oooJava/DelaunayRefinement/GraphNode.java | 86 ++++++++++++++++++ .../oooJava/DelaunayRefinement/Mesh.java | 4 + .../SerialDelaunayRefinement.java | 17 ++-- .../UndirectedEdgeGraph.java | 1 + .../UndirectedEdgeGraphNode.java | 16 ++++ 9 files changed, 133 insertions(+), 104 deletions(-) create mode 100644 Robust/src/Benchmarks/oooJava/DelaunayRefinement/GraphNode.java create mode 100644 Robust/src/Benchmarks/oooJava/DelaunayRefinement/UndirectedEdgeGraphNode.java diff --git a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/Cavity.java b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/Cavity.java index 948c3820..a45f9cff 100644 --- a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/Cavity.java +++ b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/Cavity.java @@ -120,7 +120,7 @@ public class Cavity { post.addNode(node2); } Node ne_node; - for (Iterator iterator = connections.iterator(); iterator.hasNext(); post.addNode(ne_node)) { + for (HashMapIterator iterator = connections.iterator(); iterator.hasNext(); post.addNode(ne_node)) { Edge_d conn = (Edge_d) iterator.next(); ElementEdge edge = (ElementEdge) graph.getEdgeData(conn); Element new_element = new Element(center, edge.getPoint(0), edge.getPoint(1)); diff --git a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedEdgeGraph.java b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedEdgeGraph.java index 8110268d..f0a1c140 100644 --- a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedEdgeGraph.java +++ b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedEdgeGraph.java @@ -63,8 +63,9 @@ public class DirectedEdgeGraph implements EdgeGraph { public int getInNeighborsSize(Node node) { int i = 0; - for (Iterator it = getInNeighbors(node); it.hasNext(); i++) - ; + for (Iterator it = getInNeighbors(node); it.hasNext(); i++) { + it.next(); + } return i; } @@ -74,8 +75,9 @@ public class DirectedEdgeGraph implements EdgeGraph { public int getOutNeighborsSize(Node node) { int i = 0; - for (Iterator it = getOutNeighbors(node); it.hasNext(); i++) - ; + for (Iterator it = getOutNeighbors(node); it.hasNext(); i++) { + it.next(); + } return i; } @@ -135,12 +137,14 @@ public class DirectedEdgeGraph implements EdgeGraph { protected void removeConnectingEdges(EdgeGraphNode n) { EdgeGraphNode g; - for (Iterator iterator1 = n.getOutNeighborsCopy(); iterator1.hasNext(); removeNeighbor(n, g)) { + for (Iterator iterator1 = n.getOutNeighborsCopy(); iterator1.hasNext();) { g = (EdgeGraphNode) iterator1.next(); + removeNeighbor(n, g); } - for (Iterator iterator2 = n.getInNeighborsCopy(); iterator2.hasNext(); removeNeighbor(g, n)) { + for (Iterator iterator2 = n.getInNeighborsCopy(); iterator2.hasNext(); ) { g = (EdgeGraphNode) iterator2.next(); + removeNeighbor(g, n); } } diff --git a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedGraph.java b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedGraph.java index 3ad06ef1..60919cd6 100644 --- a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedGraph.java +++ b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedGraph.java @@ -1,93 +1,6 @@ public class DirectedGraph implements Graph { protected HashSet nodes; - protected class GraphNode implements Node { - protected Object data; - // protected List inNeighbors; - // protected List outNeighbors; - protected LinkedList inNeighbors; - protected LinkedList outNeighbors; - - protected GraphNode() { - super(); - } - - public GraphNode(Object n) { - super(); - data = n; - inNeighbors = new LinkedList(); - outNeighbors = new LinkedList(); - } - - public Object getData() { - return getNodeData(this); - } - - public Object setData(Object n) { - return setNodeData(this, n); - } - - public final boolean addInNeighbor(GraphNode n) { - if (inNeighbors.contains(n)) { - return false; - } else { - inNeighbors.addLast(n); - return true; - } - } - - public final boolean removeInNeighbor(GraphNode n) { - return inNeighbors.remove(n); - } - - public final boolean hasInNeighbor(GraphNode n) { - return inNeighbors.contains(n); - } - - public final Iterator getInNeighbors() { - return inNeighbors.iterator(); - } - - public final Iterator getInNeighborsCopy() { - LinkedList l = new LinkedList(); - Iterator o = inNeighbors.iterator(); - while (o.hasNext()) { - l.addLast(o); - } - return l.iterator(); - } - - public final boolean addOutNeighbor(GraphNode n) { - if (outNeighbors.contains(n)) { - return false; - } else { - outNeighbors.addLast(n); - return true; - } - } - - public final boolean removeOutNeighbor(GraphNode n) { - return outNeighbors.remove(n); - } - - public final boolean hasOutNeighbor(GraphNode n) { - return outNeighbors.contains(n); - } - - public final Iterator getOutNeighbors() { - return outNeighbors.iterator(); - } - - public final Iterator getOutNeighborsCopy() { - LinkedList l = new LinkedList(); - Iterator o = outNeighbors.iterator(); - while (o.hasNext()) { - l.addLast(o); - } - return l.iterator(); - } - } - public DirectedGraph() { // nodes = Collections.synchronizedSet(new HashSet()); nodes = new HashSet(); diff --git a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/EdgeGraphNode.java b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/EdgeGraphNode.java index 0c74d66c..5139aed1 100644 --- a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/EdgeGraphNode.java +++ b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/EdgeGraphNode.java @@ -51,9 +51,9 @@ public class EdgeGraphNode extends Node { // TODO someone check this for performance. protected final Iterator getInNeighborsCopy() { LinkedList l = new LinkedList(); - Iterator o = inEdges.iterator(0); + HashMapIterator o = inEdges.iterator(0); while (o.hasNext()) { - l.addLast(o); + l.addLast(o.next()); } return l.iterator(); } @@ -95,9 +95,9 @@ public class EdgeGraphNode extends Node { // TODO someone check this for performance. protected final Iterator getOutNeighborsCopy() { LinkedList l = new LinkedList(); - Iterator o = outEdges.iterator(0); + HashMapIterator o = outEdges.iterator(0); while (o.hasNext()) { - l.addLast(o); + l.addLast(o.next()); } return l.iterator(); } diff --git a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/GraphNode.java b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/GraphNode.java new file mode 100644 index 00000000..e8231779 --- /dev/null +++ b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/GraphNode.java @@ -0,0 +1,86 @@ +public class GraphNode extends Node { + protected Object data; + // protected List inNeighbors; + // protected List outNeighbors; + protected LinkedList inNeighbors; + protected LinkedList outNeighbors; + + protected GraphNode() { + super(); + } + + public GraphNode(Object n) { + super(); + data = n; + inNeighbors = new LinkedList(); + outNeighbors = new LinkedList(); + } + +// public Object getData() { +// return getNodeData(this); +// } +// +// public Object setData(Object n) { +// return setNodeData(this, n); +// } + + public final boolean addInNeighbor(GraphNode n) { + if (inNeighbors.contains(n)) { + return false; + } else { + inNeighbors.addLast(n); + return true; + } + } + + public final boolean removeInNeighbor(GraphNode n) { + return inNeighbors.remove(n); + } + + public final boolean hasInNeighbor(GraphNode n) { + return inNeighbors.contains(n); + } + + public final Iterator getInNeighbors() { + return inNeighbors.iterator(); + } + + public final Iterator getInNeighborsCopy() { + LinkedList l = new LinkedList(); + Iterator o = inNeighbors.iterator(); + while (o.hasNext()) { + l.addLast(o); + } + return l.iterator(); + } + + public final boolean addOutNeighbor(GraphNode n) { + if (outNeighbors.contains(n)) { + return false; + } else { + outNeighbors.addLast(n); + return true; + } + } + + public final boolean removeOutNeighbor(GraphNode n) { + return outNeighbors.remove(n); + } + + public final boolean hasOutNeighbor(GraphNode n) { + return outNeighbors.contains(n); + } + + public final Iterator getOutNeighbors() { + return outNeighbors.iterator(); + } + + public final Iterator getOutNeighborsCopy() { + LinkedList l = new LinkedList(); + Iterator o = outNeighbors.iterator(); + while (o.hasNext()) { + l.addLast(o); + } + return l.iterator(); + } +} \ No newline at end of file diff --git a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/Mesh.java b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/Mesh.java index 39142607..247ae8d5 100644 --- a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/Mesh.java +++ b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/Mesh.java @@ -98,6 +98,8 @@ public class Mesh { } public boolean verify(EdgeGraph mesh) { + + for (Iterator iterator = mesh.iterator(); iterator.hasNext();) { Node node = (Node) iterator.next(); Element element = (Element) mesh.getNodeData(node); @@ -115,6 +117,8 @@ public class Mesh { System.out.println("-> Figures with " + element.getDim() + " edges"); return false; } + + } Node start = mesh.getRandom(); diff --git a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/SerialDelaunayRefinement.java b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/SerialDelaunayRefinement.java index 1746b2c6..1c4fcd03 100644 --- a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/SerialDelaunayRefinement.java +++ b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/SerialDelaunayRefinement.java @@ -65,25 +65,30 @@ public class SerialDelaunayRefinement { System.out.println(); } // long id = Time.getNewTimeId(); - long startTime = System.currentTimeMillis(); + long startTime = System.currentTimeMillis(); while (!worklist.isEmpty()) { + Node bad_element = (Node) worklist.pop(); if (bad_element != null && mesh.containsNode(bad_element)) { cavity.initialize(bad_element); cavity.build(); cavity.update(); + Node node; - for (Iterator iterator = cavity.getPre().getNodes().iterator(); iterator.hasNext(); mesh.removeNode(node)) { + for (Iterator iterator = cavity.getPre().getNodes().iterator(); iterator.hasNext();) { node = (Node) iterator.next(); + mesh.removeNode(node); } - for (Iterator iterator1 = cavity.getPost().getNodes().iterator(); iterator1.hasNext(); mesh.addNode(node)) { + for (Iterator iterator1 = cavity.getPost().getNodes().iterator(); iterator1.hasNext();) { node = (Node) iterator1.next(); + mesh.addNode(node); } Edge_d edge; - for (Iterator iterator2 = cavity.getPost().getEdges().iterator(); iterator2.hasNext(); mesh.addEdge(edge)) { + for (Iterator iterator2 = cavity.getPost().getEdges().iterator(); iterator2.hasNext();) { edge = (Edge_d) iterator2.next(); + mesh.addEdge(edge); } // worklist.addAll(cavity.getPost().newBad(mesh)); @@ -99,7 +104,8 @@ public class SerialDelaunayRefinement { } long time = System.currentTimeMillis() - startTime; System.out.println("runtime: " + time + " ms"); - if (isFirstRun && args.length > 1) { + //TODO note how we only verify on first run... + if (args.length > 1) { verify(mesh); } isFirstRun = false; @@ -109,7 +115,6 @@ public class SerialDelaunayRefinement { public void verify(EdgeGraph result) { //Put in cuz of static issues. Mesh m = new Mesh(); - if (!m.verify(result)) { // throw new IllegalStateException("refinement failed."); System.out.println("Refinement Failed."); diff --git a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/UndirectedEdgeGraph.java b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/UndirectedEdgeGraph.java index 9406fa3e..9ed3aabb 100644 --- a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/UndirectedEdgeGraph.java +++ b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/UndirectedEdgeGraph.java @@ -1,5 +1,6 @@ public class UndirectedEdgeGraph extends DirectedEdgeGraph { public UndirectedEdgeGraph() { + super(); } public Edge_d createEdge(Node src, Node dest, Object e) { diff --git a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/UndirectedEdgeGraphNode.java b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/UndirectedEdgeGraphNode.java new file mode 100644 index 00000000..1709a2a2 --- /dev/null +++ b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/UndirectedEdgeGraphNode.java @@ -0,0 +1,16 @@ +public class UndirectedEdgeGraphNode extends EdgeGraphNode { + + public int compareTo(UndirectedEdgeGraphNode n) { + return n.hashCode() - hashCode(); + } + + public int compareTo(Object obj) { + return compareTo((UndirectedEdgeGraphNode) obj); + } + + UndirectedEdgeGraphNode(Object d) { + data = d; + inEdges = new HashMap(); + outEdges = inEdges; + } + } \ No newline at end of file -- 2.34.1