reworking parallel implementation, both single and DFJ runs build a zero-node configu...
authorjjenista <jjenista>
Sun, 3 Apr 2011 18:52:23 +0000 (18:52 +0000)
committerjjenista <jjenista>
Sun, 3 Apr 2011 18:52:23 +0000 (18:52 +0000)
Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedEdgeGraph.java
Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedGraph.java
Robust/src/Benchmarks/oooJava/DelaunayRefinement/EdgeGraph.java
Robust/src/Benchmarks/oooJava/DelaunayRefinement/SerialDelaunayRefinement.java

index 05c8057f696e11a334a8185d3a22d0eceae695d7..37a98c8b2ced5d6970825bd966e8b75c1f56084b 100644 (file)
@@ -1,10 +1,67 @@
 public class DirectedEdgeGraph implements EdgeGraph {
 
-  public DirectedEdgeGraph() {
-    // nodes = Collections.synchronizedSet(new HashSet());
-    // nodes = new HashSet();
+  // jjenista - we need this set to find all nodes in a graph
+  // (as hard a problem as keeping a reference to one node that
+  // is in the graph from which to do a traversal and find all
+  // nodes currently in the graph).
+  //
+  // Problem: when you add or remove one node, the obvious update
+  // is to add or remove it to this set as well.  That is a conflict
+  // for concurrent add and remove ops that don't collide in terms of
+  // modifying the graph elements though.
+  //
+  // SOLUTION: let add and remove ops to the true graph happen in
+  // parallel, then use a special update method to keep the set of
+  // all nodes maintained.  It is up the user to invoke a traversal
+  // of the set of all nodes only at points where the set is valid.
+  protected HashSet nodes;
+
+  // only use when the nodes set is up-to-date
+  public DirectedEdgeGraph() { nodes = new HashSet();   }
+  public Iterator iterator() { return nodes.iterator(); }
+  public int getNumNodes()   { return nodes.size();     }
+  public Node getRandom()    { return (Node) nodes.iterator().next(); }
+
+  // keep the nodes set up-to-date, but use AFTER...
+  public void addNodeToAllNodesSet( Node n ) {
+    if( !n.inGraph ) {
+      System.out.println( "Error: adding a node NOT IN the graph to the all-nodes set!" );
+      System.exit( -1 );
+    }
+    nodes.add( n );
+  }
+
+  public void removeNodeFromAllNodesSet( Node n ) {
+    if( n.inGraph ) {
+      System.out.println( "Error: removing a node IN the graph to the all-nodes set!" );
+      System.exit( -1 );
+    }
+    nodes.add( n );
+  }
+
+  // these are the normal methods for truly adding and removing nodes
+  // from the graph, nodes know locally if they are in and out but they
+  // haven't been added or removed from the nodes set until ABOVE methods
+  public boolean addNode(Node n) {
+    boolean notInAlready = !n.inGraph;
+    n.inGraph = true;
+    return notInAlready;
+  }
+
+  public boolean removeNode(Node n) {
+    boolean wasIn = n.inGraph;
+    removeConnectingEdges((EdgeGraphNode) n);
+    return wasIn;
   }
 
+  public boolean containsNode(Node n) {
+    return n.inGraph;
+  }
+
+
+
+
+
   public boolean addEdge(Edge_d e) {
     GraphEdge ge = (GraphEdge) e;
     EdgeGraphNode src = ge.getSrc();
@@ -90,46 +147,17 @@ public class DirectedEdgeGraph implements EdgeGraph {
     return retval;
   }
 
-  //public Iterator iterator() {
-  //  return nodes.iterator();
-  //}
-
-  public boolean addNode(Node n) {
-    boolean notInAlready = !n.inGraph;
-    n.inGraph = true;
-    return notInAlready;
-  }
-
-  public boolean containsNode(Node n) {
-    return n.inGraph;
-  }
-
   public Object getNodeData(Node n) {
     EdgeGraphNode egn = (EdgeGraphNode) n;
     return egn.data;
   }
 
-  //public int getNumNodes() {
-  //  return nodes.size();
-  //}
-
-  //public Node getRandom() {
-  //  // return (Node)Sets.getAny(nodes);
-  //  return (Node) nodes.iterator().next();
-  //}
-
   public boolean hasNeighbor(Node src, Node dest) {
     EdgeGraphNode esrc = (EdgeGraphNode) src;
     EdgeGraphNode edest = (EdgeGraphNode) dest;
     return esrc.hasOutNeighbor(edest);
   }
 
-  public boolean removeNode(Node n) {
-    boolean wasIn = n.inGraph;
-    removeConnectingEdges((EdgeGraphNode) n);
-    return wasIn;
-  }
-
   protected void removeConnectingEdges(EdgeGraphNode n) {
     EdgeGraphNode g;
     for (Iterator iterator1 = n.getOutNeighborsCopy(); iterator1.hasNext();) {
index a37fba5a5344de800679e0c444737b542c281c34..89aece39ff0193999c4a52680cd59bc2e5960258 100644 (file)
@@ -1,9 +1,9 @@
 public class DirectedGraph implements Graph {
-  protected HashSet nodes;
-
+  //protected HashSet nodes;
+  
   public DirectedGraph() {
     // nodes = Collections.synchronizedSet(new HashSet());
-    nodes = new HashSet();
+    //nodes = new HashSet();
   }
 
   public boolean addNeighbor(Node src, Node dest) {
@@ -13,11 +13,13 @@ public class DirectedGraph implements Graph {
   }
 
   public boolean addNode(Node n) {
-    return nodes.add((GraphNode) n);
+    boolean notInAlready = !n.inGraph;
+    n.inGraph = true;
+    return notInAlready;
   }
 
   public boolean containsNode(Node n) {
-    return nodes.contains(n);
+    n.inGraph;
   }
 
   public Node createNode(Object n) {
@@ -36,9 +38,9 @@ public class DirectedGraph implements Graph {
     return ((GraphNode)node).inNeighbors.size();
   }
 
-  public int getNumNodes() {
-    return nodes.size();
-  }
+  //public int getNumNodes() {
+  //  return nodes.size();
+  //}
 
   public Iterator getOutNeighbors(Node src) {
     GraphNode src_c = (GraphNode) src;
@@ -67,8 +69,9 @@ public class DirectedGraph implements Graph {
   }
 
   public boolean removeNode(Node n) {
+    boolean wasIn = n.inGraph;
     removeConnectingEdges((GraphNode) n);
-    return nodes.remove(n);
+    return wasIn;
   }
 
   protected void removeConnectingEdges(GraphNode n) {
@@ -95,9 +98,9 @@ public class DirectedGraph implements Graph {
     return retval;
   }
 
-  public Iterator iterator() {
-    return nodes.iterator();
-  }
+  //public Iterator iterator() {
+  //  return nodes.iterator();
+  //}
 
   public boolean isDirected() {
     return true;
index 1a6d24c84474b73e9fe8dcf44c7a4974c47f6ad7..61981cc4437b87eb53fd4acb3a64afaa9c755eaa 100644 (file)
@@ -21,4 +21,7 @@ public interface EdgeGraph extends Graph {
   public abstract Object getEdgeData(Edge_d edge);
 
   public abstract Object setEdgeData(Edge_d edge, Object obj);
+
+  public abstract void addNodeToAllNodesSet( Node n );
+  public abstract void removeNodeFromAllNodesSet( Node n );
 }
index 67d2eee4d191b06ca8fb854fc324a739c9f554e1..3ec6220b80e8f16b634ba3d7725915c74d949f4b 100644 (file)
@@ -203,8 +203,17 @@ public class SerialDelaunayRefinement {
             }
 
           } else {
-            // otherwise we did apply the cavity, but we
-            // may have introduced new bad triangles
+            // otherwise we did apply the cavity, so repair the all-nodes set of the mesh
+            Iterator itrPreNodes = cavity.getPre().getNodes().iterator();
+            while( itrPreNodes.hasNext() ) {
+              mesh.removeNodeFromAllNodesSet( (Node)itrPreNodes.next() );
+            }
+            Iterator itrPostNodes = cavity.getPost().getNodes().iterator();
+            while( itrPostNodes.hasNext() ) {
+              mesh.addNodeToAllNodesSet( (Node)itrPostNodes.next() );
+            }
+
+            // and we may have introduced new bad triangles
             HashMapIterator it2 = cavity.getPost().newBad(mesh).iterator();
             while (it2.hasNext()) {
               worklist.push((Node)it2.next());