connections.clear();
frontier = new LinkedList();
centerNode = node;
- for (centerElement = (Element) graph.getNodeData(centerNode); graph.containsNode(centerNode)
+ for (centerElement = (Element) getNodeData(centerNode); graph.containsNode(centerNode)
&& centerElement.isObtuse();) {
Edge_d oppositeEdge = getOpposite(centerNode);
- if (graph.getSource(oppositeEdge) == centerNode)
- centerNode = graph.getDest(oppositeEdge);
+ if (getSource(oppositeEdge) == centerNode)
+ centerNode = getDest(oppositeEdge);
else
- centerNode = graph.getSource(oppositeEdge);
- centerElement = (Element) graph.getNodeData(centerNode);
+ centerNode = getSource(oppositeEdge);
+ centerElement = (Element) getNodeData(centerNode);
if (centerNode == null)
System.exit(-1);
}
}
private Edge_d getOpposite(Node node) {
- Element element = (Element) graph.getNodeData(node);
+ Element element = (Element) getNodeData(node);
// Don't think we'd run into it but..
// TODO check this.
// Integer.valueOf(neighbors.size())
// }));
- for (Iterator iterator = graph.getOutNeighbors(node); iterator.hasNext();) {
+ for (Iterator iterator = getOutNeighbors(node); iterator.hasNext();) {
Node neighbor = (Node) iterator.next();
- Edge_d edge = graph.getEdge(node, neighbor);
- ElementEdge edge_data = (ElementEdge) graph.getEdgeData(edge);
+ Edge_d edge = getEdge(node, neighbor);
+ ElementEdge edge_data = (ElementEdge) getEdgeData(edge);
if (element.getObtuse().notEquals(edge_data.getPoint(0))
&& element.getObtuse().notEquals(edge_data.getPoint(1)))
return edge;
}
public boolean isMember(Node node) {
- Element element = (Element) graph.getNodeData(node);
+ Element element = (Element) getNodeData(node);
return element.inCircle(center);
}
public void build() {
while (frontier.size() != 0) {
Node curr = (Node) frontier.removeFirst();
- for (Iterator iterator = graph.getOutNeighbors(curr); iterator.hasNext();) {
+ for (Iterator iterator = getOutNeighbors(curr); iterator.hasNext();) {
Node next = (Node) iterator.next();
- Element nextElement = (Element) graph.getNodeData(next);
- Edge_d edge = graph.getEdge(curr, next);
+ Element nextElement = (Element) getNodeData(next);
+ Edge_d edge = getEdge(curr, next);
if ((dim != 2 || nextElement.getDim() != 2 || next == centerNode) && isMember(next)) {
if (nextElement.getDim() == 2 && dim != 2) {
initialize(next);
Node 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);
+ ElementEdge edge = (ElementEdge) getEdgeData(conn);
Element new_element = new Element(center, edge.getPoint(0), edge.getPoint(1));
ne_node = graph.createNode(new_element);
Node ne_connection;
- if (pre.existsNode(graph.getDest(conn)))
- ne_connection = graph.getSource(conn);
+ if (pre.existsNode(getDest(conn)))
+ ne_connection = getSource(conn);
else
- ne_connection = graph.getDest(conn);
+ ne_connection = getDest(conn);
ElementEdge new_edge =
- new_element.getRelatedEdge((Element) graph.getNodeData(ne_connection));
- post.addEdge(graph.createEdge(ne_node, ne_connection, new_edge));
+ new_element.getRelatedEdge((Element) getNodeData(ne_connection));
+ post.addEdge(createEdge(ne_node, ne_connection, new_edge));
// Collection postnodes = (Collection)post.getNodes().clone();
LinkedList postnodes = new LinkedList();
for (Iterator iterator1 = postnodes.iterator(); iterator1.hasNext();) {
Node node = (Node) iterator1.next();
- Element element = (Element) graph.getNodeData(node);
+ Element element = (Element) getNodeData(node);
if (element.isRelated(new_element)) {
ElementEdge ele_edge = new_element.getRelatedEdge(element);
- post.addEdge(graph.createEdge(ne_node, node, ele_edge));
+ post.addEdge(createEdge(ne_node, node, ele_edge));
}
}
}
}
+
+ private Object getNodeData(Node n) {
+ return ((EdgeGraphNode) n).data;
+ }
+
+ public Node getSource(Edge_d e) {
+ return ((GraphEdge) e).getSrc();
+ }
+
+ public Node getDest(Edge_d e) {
+ return ((GraphEdge) e).getDest();
+ }
+
+ public Edge_d getEdge(Node src, Node dest) {
+ return ((EdgeGraphNode) src).getOutEdge((EdgeGraphNode) dest);
+ }
+
+
+ public Edge_d createEdge(Node src, Node dest, Object e) {
+ return new GraphEdge((EdgeGraphNode) src, (EdgeGraphNode) dest, e);
+ }
+
+ public Iterator getOutNeighbors(Node src) {
+ return ((EdgeGraphNode) src).getOutNeighbors();
+ }
+
+ public Object getEdgeData(Edge_d e) {
+ return ((GraphEdge) e).d;
+ }
}
long startTime = System.currentTimeMillis();
while (!worklist.isEmpty()) {
-
-
-// Node bad_element = (Node) worklist.pop();
- Node[] bad_elements = new Node[20];
- for(int i=0;i<20;i++) {
+ Node[] bad_elements = new Node[23];
+ for(int i=0;i<23;i++) {
if(worklist.isEmpty()) {
- bad_elements[i] = null;
+ bad_elements[i] = null;
} else {
bad_elements[i] = (Node) worklist.pop();
}
}
- for(int i = 0; i<20;i++)
- {
+ // Node bad_element = (Node) worklist.pop();
+ for(int i=0;i<23;i++) {
Node bad_element = bad_elements[i];
if (bad_element != null && mesh.containsNode(bad_element)) {
- rblock P {
- Cavity cavity = new Cavity(mesh);
- cavity.initialize(bad_element);
- cavity.build();
- cavity.update();
-
- //remove old data
- Node node;
- for (Iterator iterator = cavity.getPre().getNodes().iterator(); iterator.hasNext();) {
- node = (Node) iterator.next();
- mesh.removeNode(node);
- }
-
- //add new data
- 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();) {
- edge = (Edge_d) iterator2.next();
- mesh.addEdge(edge);
- }
+ sese P {
+ //takes < 1 sec
+ Cavity cavity = new Cavity(mesh);
+
+ //Appears to only call getters (only possible conflict is inherent in Hashmap)
+ cavity.initialize(bad_element);
+
+ //Takes up 15% of computation
+ //Problem:: Build is recursive upon building neighbor upon neighbor upon neighbor
+ //This is could be a problem....
+ //TODO check dimensions problem
+ cavity.build();
+
+ //Takes up a whooping 50% of computation time and changes NOTHING but cavity :D
+ cavity.update();
}
- rblock S {
- // worklist.addAll(cavity.getPost().newBad(mesh));
- it = cavity.getPost().newBad(mesh).iterator();
- while (it.hasNext()) {
- worklist.push((Node)it.next());
- }
-
- if (mesh.containsNode(bad_element)) {
- worklist.push((Node) bad_element);
- }
+ sese S {
+ //28% of runtime #Removes stuff out of our mesh
+ middle(mesh, cavity);
+
+ //1.5% of runtime # adds stuff back to the work queue.
+ end(mesh, worklist, bad_element, cavity);
}
}
+
}
}
long time = System.currentTimeMillis() - startTime;
return time;
}
+ private void end(EdgeGraph mesh, Stack worklist, Node bad_element, Cavity cavity) {
+ HashMapIterator it2 = cavity.getPost().newBad(mesh).iterator();
+ while (it2.hasNext()) {
+ worklist.push((Node)it2.next());
+ }
+
+ if (mesh.containsNode(bad_element)) {
+ worklist.push((Node) bad_element);
+ }
+ }
+
+ private void middle(EdgeGraph mesh, Cavity cavity) {
+ //remove old data
+ Node node;
+
+ //Takes up 8.9% of runtime
+ for (Iterator iterator = cavity.getPre().getNodes().iterator(); iterator.hasNext();) {
+ node = (Node) iterator.next();
+ mesh.removeNode(node);
+ }
+
+ //add new data
+ //Takes up 1.7% of runtime
+ for (Iterator iterator1 = cavity.getPost().getNodes().iterator(); iterator1.hasNext();) {
+ node = (Node) iterator1.next();
+ mesh.addNode(node);
+ }
+
+
+ //Takes up 7.8% of runtime
+ Edge_d edge;
+ for (Iterator iterator2 = cavity.getPost().getEdges().iterator(); iterator2.hasNext();) {
+ edge = (Edge_d) iterator2.next();
+ mesh.addEdge(edge);
+ }
+ }
+
public void verify(EdgeGraph result) {
//Put in cuz of static issues.
Mesh m = new Mesh();