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));
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;
}
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;
}
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);
}
}
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();
// TODO someone check this for performance.\r
protected final Iterator getInNeighborsCopy() {\r
LinkedList l = new LinkedList();\r
- Iterator o = inEdges.iterator(0);\r
+ HashMapIterator o = inEdges.iterator(0);\r
while (o.hasNext()) {\r
- l.addLast(o);\r
+ l.addLast(o.next());\r
}\r
return l.iterator();\r
}\r
// TODO someone check this for performance.\r
protected final Iterator getOutNeighborsCopy() {\r
LinkedList l = new LinkedList();\r
- Iterator o = outEdges.iterator(0);\r
+ HashMapIterator o = outEdges.iterator(0);\r
while (o.hasNext()) {\r
- l.addLast(o);\r
+ l.addLast(o.next());\r
}\r
return l.iterator();\r
}\r
--- /dev/null
+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
}
public boolean verify(EdgeGraph mesh) {
+
+
for (Iterator iterator = mesh.iterator(); iterator.hasNext();) {
Node node = (Node) iterator.next();
Element element = (Element) mesh.getNodeData(node);
System.out.println("-> Figures with " + element.getDim() + " edges");
return false;
}
+
+
}
Node start = mesh.getRandom();
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));
}
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;
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.");
public class UndirectedEdgeGraph extends DirectedEdgeGraph {
public UndirectedEdgeGraph() {
+ super();
}
public Edge_d createEdge(Node src, Node dest, Object e) {
--- /dev/null
+public class UndirectedEdgeGraphNode extends EdgeGraphNode {\r
+\r
+ public int compareTo(UndirectedEdgeGraphNode n) {\r
+ return n.hashCode() - hashCode();\r
+ }\r
+\r
+ public int compareTo(Object obj) {\r
+ return compareTo((UndirectedEdgeGraphNode) obj);\r
+ }\r
+\r
+ UndirectedEdgeGraphNode(Object d) {\r
+ data = d;\r
+ inEdges = new HashMap();\r
+ outEdges = inEdges;\r
+ }\r
+ }
\ No newline at end of file