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