run-doj-validation-test.sh: a single script that performs validation tests for all...
[IRC.git] / Robust / src / Benchmarks / oooJava / labyrinth / Labyrinth.java
1 /* =============================================================================
2  *
3  * Labyrinth.java
4  *
5  * =============================================================================
6  *
7  * Copyright (C) Stanford University, 2006.  All Rights Reserved.
8  * Author: Chi Cao Minh
9  *
10  * =============================================================================
11  *
12  * For the license of bayes/sort.h and bayes/sort.c, please see the header
13  * of the files.
14  * 
15  * ------------------------------------------------------------------------
16  * 
17  * For the license of kmeans, please see kmeans/LICENSE.kmeans
18  * 
19  * ------------------------------------------------------------------------
20  * 
21  * For the license of ssca2, please see ssca2/COPYRIGHT
22  * 
23  * ------------------------------------------------------------------------
24  * 
25  * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the
26  * header of the files.
27  * 
28  * ------------------------------------------------------------------------
29  * 
30  * For the license of lib/rbtree.h and lib/rbtree.c, please see
31  * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree
32  * 
33  * ------------------------------------------------------------------------
34  * 
35  * Unless otherwise noted, the following license applies to STAMP files:
36  * 
37  * Copyright (c) 2007, Stanford University
38  * All rights reserved.
39  * 
40  * Redistribution and use in source and binary forms, with or without
41  * modification, are permitted provided that the following conditions are
42  * met:
43  * 
44  *     * Redistributions of source code must retain the above copyright
45  *       notice, this list of conditions and the following disclaimer.
46  * 
47  *     * Redistributions in binary form must reproduce the above copyright
48  *       notice, this list of conditions and the following disclaimer in
49  *       the documentation and/or other materials provided with the
50  *       distribution.
51  * 
52  *     * Neither the name of Stanford University nor the names of its
53  *       contributors may be used to endorse or promote products derived
54  *       from this software without specific prior written permission.
55  * 
56  * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY
57  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
59  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE
60  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
61  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
62  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
63  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
64  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
66  * THE POSSIBILITY OF SUCH DAMAGE.
67  *
68  * =============================================================================
69  */
70
71 public class Labyrinth 
72 {
73   // jjenista -- not sure what is going with static fields in the general
74   // compiler, let alone disjoint/pointer/OOOJ/DOJ
75   /*static*/  String global_inputFile;
76   /*static*/  boolean global_doPrint;
77
78     int numThread;
79     int bendCost;
80     int xCost;
81     int yCost;
82     int zCost;
83
84
85     // For threads
86     int threadID;
87     Solve_Arg routerArg;
88     
89     //For rblocks
90     int global_workload;
91
92     private void setDefaultParams() {
93
94         /* default values */
95         global_inputFile = null;
96         global_doPrint = false;
97         bendCost = 1;
98         xCost = 1;
99         yCost = 1;
100         zCost = 2;
101         numThread = 1;
102         
103         global_workload = 20;
104     }
105
106     private void parseArg(String[] argv) {
107         int i=0;
108         String arg;
109         boolean opterr = false;
110
111
112         setDefaultParams();
113
114         while (i < argv.length) {
115
116             if(argv[i].charAt(0) == '-' ) {
117                 arg = argv[i++];
118                 // check options
119                 if(arg.equals("-b")) {
120                     bendCost = Integer.parseInt(argv[i++]);
121                 }
122                 else if(arg.equals("-x")) {
123                     xCost = Integer.parseInt(argv[i++]);
124                     }
125                 else if(arg.equals("-y")) {
126                     yCost = Integer.parseInt(argv[i++]);
127                     }
128                 else if(arg.equals("-z")) {
129                     zCost = Integer.parseInt(argv[i++]);
130                     }
131                 else if(arg.equals("-t")) {
132                         numThread = Integer.parseInt(argv[i++]);
133                 }
134                 else if(arg.equals("-i")) {
135                     global_inputFile = argv[i++];
136                     }
137                 else if(arg.equals("-p")) {
138                         global_doPrint = true;
139                 }
140                 else if(arg.equals("-w")){
141                         global_workload = Integer.parseInt(argv[i++]);
142                 }
143                 else {
144                     System.out.println("Non-option argument: " + argv[i]);
145                     opterr = true;
146                 }   
147             
148             }
149         }
150         if(opterr) {
151             displayUsage();
152             System.exit(1);
153         }
154     }
155
156     public Labyrinth(String[] argv)
157     {     
158         parseArg(argv);
159     }
160
161
162     public Labyrinth(int myID,Solve_Arg rArg)
163     {
164         threadID = myID;
165         routerArg = rArg;
166     }
167
168     public void displayUsage() 
169     {
170         System.out.println("Usage: Labyrinth [options]");
171         System.out.println("Options:");
172         System.out.println("    b <INT>     bend cost");
173         System.out.println("    i <FILE>    input file name");
174         System.out.println("    p           print routed maze");
175         System.out.println("    t <INT>     Number of threads");
176         System.out.println("    x <INT>     x movement cost");
177         System.out.println("    y <INT>     y movement cost");
178         System.out.println("    z <INT>     z movement cost");
179         System.out.println("    w <INT>     Workload per rBlock");
180     }
181         
182
183     public static void main(String[] argv) 
184     {
185         /*
186          * Initailization
187          */
188         Maze maze = new Maze();
189         Router router = new Router();
190         Labyrinth labyrinth = new Labyrinth(argv);
191         
192         Maze mazePtr = maze.alloc();
193
194         int numPathToRoute =  mazePtr.readMaze(labyrinth.global_inputFile);
195         
196         Router routerPtr = router.alloc(labyrinth.xCost,labyrinth.yCost,
197                                         labyrinth.zCost,labyrinth.bendCost);
198
199         List_t list_t = new List_t();
200         List_t pathVectorListPtr = list_t.alloc(0);     // list_t.alloc(null)
201         Solve_Arg routerArg = new Solve_Arg(routerPtr,mazePtr,pathVectorListPtr, labyrinth.global_workload);
202
203         /* Create and start thread */
204         long start = System.currentTimeMillis();
205         routerPtr.solve(routerArg);        
206
207         /* End of Solve */
208         long finish = System.currentTimeMillis();
209         long diff=finish-start;
210         System.out.println("TIME= " + diff);
211
212
213         int numPathRouted = 0;
214         List_Iter it = new List_Iter();
215
216         it.reset(pathVectorListPtr);
217         while(it.hasNext(pathVectorListPtr)) {
218                 Vector_t pathVectorPtr = (Vector_t)it.next(pathVectorListPtr);
219                 numPathRouted += pathVectorPtr.vector_getSize();
220         }
221
222         double elapsed = (finish-start)/1000.0;
223
224         System.out.println("Paths routed    = " + numPathRouted);
225         System.out.println("Elapsed time    = " + elapsed);
226
227         boolean stats = mazePtr.checkPaths(pathVectorListPtr,labyrinth.global_doPrint);
228         if(!stats)
229             System.out.println("Verification not passed");
230         else 
231             System.out.println("VALID");
232         
233         System.out.println("Finished");    
234     }
235 }
236
237 /* =============================================================================
238  *
239  * End of labyrinth.c
240  *
241  * =============================================================================
242  */