Closer to compiling. at the moment, it throws a NullPointerException right after...
[IRC.git] / Robust / src / Benchmarks / oooJava / DelaunayRefinement / SerialDelaunayrefinement.java
1 public class SerialDelaunayrefinement {
2
3   private static boolean isFirstRun = true;
4   
5   public SerialDelaunayrefinement() {
6   }
7
8   public static void main(String args[]) {
9     long runtime = 0;
10     //Numbers below are Long.Max_Value
11     long lasttime = 0x7fffffffffffffffL;
12     long mintime = 0x7fffffffffffffffL;
13     for (long run = 0; ((run < 3) || Math.abs(lasttime - runtime) * 64 > Math.min(lasttime, runtime)) && run < 7; run++) {
14       runtime = run(args);
15       if (runtime < mintime) {
16         mintime = runtime;
17       }
18     }
19
20     System.out.println("minimum runtime: " + mintime + " ms");
21     System.out.println("");
22   }
23
24   public static long run(String args[]) {
25     if (isFirstRun) {
26       System.out.println();
27       System.out.println("Lonestar Benchmark Suite v2.1");
28       System.out.println("Copyright (C) 2007, 2008, 2009 The University of Texas at Austin");
29       System.out.println("http://iss.ices.utexas.edu/lonestar/");
30       System.out.println();
31       System.out.println("application: Delaunay Mesh Refinement (serial version)");
32       System.out.println("Refines a Delaunay triangulation mesh such that no angle");
33       System.out.println("in the mesh is less than 30 degrees");
34       System.out.println("http://iss.ices.utexas.edu/lonestar/delaunayrefinement.html");
35       System.out.println();
36     }
37     if (args.length < 1) {
38       System.out.println("Arguments: <input file> [verify]");
39       System.exit(-1);
40     }
41
42     EdgeGraph mesh = new UndirectedEdgeGraph();
43
44     Mesh m = new Mesh();
45     m.read(mesh, args[0]);
46
47     Stack worklist = new Stack();
48
49     // worklist.addAll(Mesh.getBad(mesh));
50     HashMapIterator it = m.getBad(mesh).iterator();
51     while (it.hasNext()) {
52       worklist.push(it.next());
53     }
54
55     Cavity cavity = new Cavity(mesh);
56     if (isFirstRun) {
57       System.err.println("configuration: " + mesh.getNumNodes() + " total triangles, " + worklist.size() + " bad triangles");
58       System.out.println();
59     }
60 //    long id = Time.getNewTimeId();
61     long startTime = System.currentTimeMillis();
62     while (!worklist.empty()) {
63       Node bad_element = (Node) worklist.pop();
64       if (bad_element != null && mesh.containsNode(bad_element)) {
65         cavity.initialize(bad_element);
66         cavity.build();
67         cavity.update();
68         Node node;
69         for (Iterator iterator = cavity.getPre().getNodes().iterator(); iterator.hasNext(); mesh.removeNode(node)) {
70           node = (Node) iterator.next();
71         }
72
73         for (Iterator iterator1 = cavity.getPost().getNodes().iterator(); iterator1.hasNext(); mesh.addNode(node)) {
74           node = (Node) iterator1.next();
75         }
76
77         Edge_d edge;
78         for (Iterator iterator2 = cavity.getPost().getEdges().iterator(); iterator2.hasNext(); mesh.addEdge(edge)) {
79           edge = (Edge_d) iterator2.next();
80         }
81
82         // worklist.addAll(cavity.getPost().newBad(mesh));
83         it = cavity.getPost().newBad(mesh).iterator();
84         while (it.hasNext()) {
85           worklist.push(it.next());
86         }
87
88         if (mesh.containsNode(bad_element)) {
89           worklist.push(bad_element);
90         }
91       }
92     }
93     long time = System.currentTimeMillis() - startTime;
94     System.out.println("runtime: " + time + " ms");
95     if (isFirstRun && args.length > 1) {
96       verify(mesh);
97     }
98     isFirstRun = false;
99     return time;
100   }
101
102   public static void verify(EdgeGraph result) {
103     if (!Mesh.verify(result)) {
104 //      throw new IllegalStateException("refinement failed.");
105       System.out.println("Refinement Failed.");
106       System.exit(-1);
107     }
108     
109     int size = Mesh.getBad(result).size();
110     if (size != 0) {
111       System.out.println("refinement failed\nstill have "+size+" bad triangles left.\n");
112       System.exit(-1);
113     } else {
114       System.out.println("OK");
115       return;
116     }
117   }
118 }