1 /* =============================================================================
5 * =============================================================================
7 * Copyright (C) Stanford University, 2006. All Rights Reserved.
10 * =============================================================================
12 * For the license of bayes/sort.h and bayes/sort.c, please see the header
15 * ------------------------------------------------------------------------
17 * For the license of kmeans, please see kmeans/LICENSE.kmeans
19 * ------------------------------------------------------------------------
21 * For the license of ssca2, please see ssca2/COPYRIGHT
23 * ------------------------------------------------------------------------
25 * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the
26 * header of the files.
28 * ------------------------------------------------------------------------
30 * For the license of lib/rbtree.h and lib/rbtree.c, please see
31 * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree
33 * ------------------------------------------------------------------------
35 * Unless otherwise noted, the following license applies to STAMP files:
37 * Copyright (c) 2007, Stanford University
38 * All rights reserved.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions are
44 * * Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
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
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.
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.
68 * =============================================================================
71 public class Labyrinth extends Thread{
73 static String global_inputFile;
74 static boolean global_doPrint;
86 private void setDefaultParams() {
89 global_inputFile = null;
90 global_doPrint = false;
98 private void parseArg(String[] argv) {
101 boolean opterr = false;
106 while (i < argv.length) {
108 if(argv[i].charAt(0) == '-' ) {
111 if(arg.equals("-b")) {
112 bendCost = Integer.parseInt(argv[i++]);
114 else if(arg.equals("-x")) {
115 xCost = Integer.parseInt(argv[i++]);
117 else if(arg.equals("-y")) {
118 yCost = Integer.parseInt(argv[i++]);
120 else if(arg.equals("-z")) {
121 zCost = Integer.parseInt(argv[i++]);
123 else if(arg.equals("-t")) {
124 numThread = Integer.parseInt(argv[i++]);
126 else if(arg.equals("-i")) {
127 global_inputFile = argv[i++];
129 else if(arg.equals("-p")) {
130 global_doPrint = true;
133 System.out.println("Non-option argument: " + argv[i]);
145 public Labyrinth(String[] argv)
151 public Labyrinth(int myID,Solve_Arg rArg)
158 Barrier.enterBarrier();
159 Router.solve(routerArg);
160 Barrier.enterBarrier();
163 public void displayUsage()
165 System.out.println("Usage: Labyrinth [options]");
166 System.out.println("Options:");
167 System.out.println(" b <INT> bend cost");
168 System.out.println(" i <FILE> input file name");
169 System.out.println(" p print routed maze");
170 System.out.println(" t <INT> Number of threads");
171 System.out.println(" x <INT> x movement cost");
172 System.out.println(" y <INT> y movement cost");
173 System.out.println(" z <INT> z movement cost");
177 public static void main(String[] argv)
183 Labyrinth labyrinth = new Labyrinth(argv);
185 Barrier.setBarrier(labyrinth.numThread);
187 Maze mazePtr = Maze.alloc();
189 int numPathToRoute = mazePtr.readMaze(labyrinth.global_inputFile);
191 Router routerPtr = Router.alloc(labyrinth.xCost,labyrinth.yCost,
192 labyrinth.zCost,labyrinth.bendCost);
194 List_t pathVectorListPtr = List_t.alloc(0); // list_t.alloc(null)
198 Solve_Arg routerArg = new Solve_Arg(routerPtr,mazePtr,pathVectorListPtr);
200 /* Create and start thread */
202 Labyrinth[] lb = new Labyrinth[labyrinth.numThread];
204 for(int i = 1; i<labyrinth.numThread;i++) {
205 lb[i] = new Labyrinth(i,routerArg);
208 long start = System.currentTimeMillis();
210 for(int i = 1; i<labyrinth.numThread;i++) {
214 Barrier.enterBarrier();
215 Router.solve(routerArg);
216 Barrier.enterBarrier();
219 long finish = System.currentTimeMillis();
222 int numPathRouted = 0;
223 List_Iter it = new List_Iter();
225 it.reset(pathVectorListPtr);
226 while(it.hasNext(pathVectorListPtr)) {
227 Vector_t pathVectorPtr = (Vector_t)it.next(pathVectorListPtr);
228 numPathRouted += pathVectorPtr.vector_getSize();
231 float elapsed = ((float)finish-(float)start)/1000;
233 System.out.println("Paths routed = " + numPathRouted);
234 System.out.println("Elapsed time = " + elapsed);
236 boolean stats = mazePtr.checkPaths(pathVectorListPtr,labyrinth.global_doPrint);
239 System.out.println("Verification not passed");
243 System.out.println("Verification passed.");
244 System.out.println("Finished");
248 /* =============================================================================
252 * =============================================================================