Under Original/Normal_Java/ one would find the original Labyrinth project ported...
[IRC.git] / Robust / src / Benchmarks / Java-Single / Labyrinth / mlp / rBlocked / Labyrinth.java
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth/mlp/rBlocked/Labyrinth.java b/Robust/src/Benchmarks/Java-Single/Labyrinth/mlp/rBlocked/Labyrinth.java
new file mode 100644 (file)
index 0000000..500bc1d
--- /dev/null
@@ -0,0 +1,237 @@
+/* =============================================================================
+ *
+ * Labyrinth.java
+ *
+ * =============================================================================
+ *
+ * Copyright (C) Stanford University, 2006.  All Rights Reserved.
+ * Author: Chi Cao Minh
+ *
+ * =============================================================================
+ *
+ * For the license of bayes/sort.h and bayes/sort.c, please see the header
+ * of the files.
+ * 
+ * ------------------------------------------------------------------------
+ * 
+ * For the license of kmeans, please see kmeans/LICENSE.kmeans
+ * 
+ * ------------------------------------------------------------------------
+ * 
+ * For the license of ssca2, please see ssca2/COPYRIGHT
+ * 
+ * ------------------------------------------------------------------------
+ * 
+ * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the
+ * header of the files.
+ * 
+ * ------------------------------------------------------------------------
+ * 
+ * For the license of lib/rbtree.h and lib/rbtree.c, please see
+ * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree
+ * 
+ * ------------------------------------------------------------------------
+ * 
+ * Unless otherwise noted, the following license applies to STAMP files:
+ * 
+ * Copyright (c) 2007, Stanford University
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ * 
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ * 
+ *     * Neither the name of Stanford University nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * =============================================================================
+ */
+
+public class Labyrinth{
+
+    static String global_inputFile;
+    static boolean global_doPrint;
+    static int global_workload;
+    int numThread;
+    int bendCost;
+    int xCost;
+    int yCost;
+    int zCost;
+
+
+    // For threads
+    int threadID;
+    Solve_Arg routerArg;
+
+    private void setDefaultParams() {
+
+        /* default values */
+        global_inputFile = null;
+        global_doPrint = false;
+        bendCost = 1;
+        xCost = 1;
+        yCost = 1;
+        zCost = 2;
+        numThread = 1;
+        global_workload = 20;
+    }
+
+    private void parseArg(String[] argv) {
+        int i=0;
+        String arg;
+        boolean opterr = false;
+
+
+        setDefaultParams();
+
+        while (i < argv.length) {
+
+            if(argv[i].charAt(0) == '-' ) {
+                arg = argv[i++];
+                // check options
+                if(arg.equals("-b")) {
+                    bendCost = Integer.parseInt(argv[i++]);
+                }
+                else if(arg.equals("-x")) {
+                    xCost = Integer.parseInt(argv[i++]);
+                    }
+                else if(arg.equals("-y")) {
+                    yCost = Integer.parseInt(argv[i++]);
+                    }
+                else if(arg.equals("-z")) {
+                    zCost = Integer.parseInt(argv[i++]);
+                    }
+                else if(arg.equals("-t")) {
+                        numThread = Integer.parseInt(argv[i++]);
+                }
+                else if(arg.equals("-i")) {
+                    global_inputFile = argv[i++];
+                    }
+                else if(arg.equals("-p")) {
+                        global_doPrint = true;
+                }
+                else if(arg.equals("-w")){
+                       global_workload = Integer.parseInt(argv[i++]);
+                }
+                else {
+                    System.out.println("Non-option argument: " + argv[i]);
+                    opterr = true;
+                }   
+            
+            }
+        }
+        if(opterr) {
+            displayUsage();
+            System.exit(1);
+        }
+    }
+
+    public Labyrinth(String[] argv)
+    {     
+        parseArg(argv);
+    }
+
+
+    public Labyrinth(int myID,Solve_Arg rArg)
+    {
+        threadID = myID;
+        routerArg = rArg;
+    }
+
+    public Labyrinth() {}
+
+       public void displayUsage() 
+    {
+        System.out.println("Usage: Labyrinth [options]");
+        System.out.println("Options:");
+        System.out.println("    b <INT>     bend cost");
+        System.out.println("    i <FILE>    input file name");
+        System.out.println("    p           print routed maze");
+        System.out.println("    t <INT>     Number of threads (depricated)");
+        System.out.println("   w <INT>         Workload per rBlock");
+        System.out.println("    x <INT>     x movement cost");
+        System.out.println("    y <INT>     y movement cost");
+        System.out.println("    z <INT>     z movement cost");
+    }
+        
+
+    public static void main(String[] argv) 
+    {
+       //parse arguments
+        Labyrinth labyrinth = new Labyrinth(argv);
+
+        Maze maze = new Maze();
+        Maze mazePtr = maze.alloc();
+
+        //parse maze/grid
+        int numPathToRoute =  mazePtr.readMaze(labyrinth.global_inputFile);
+        
+        
+        Router routerPtr = Router.alloc(labyrinth.xCost,labyrinth.yCost,
+                                        labyrinth.zCost,labyrinth.bendCost);
+
+        List_t pathVectorListPtr = List_t.alloc(0);
+        
+        Solve_Arg routerArg = new Solve_Arg(routerPtr,mazePtr,pathVectorListPtr);
+
+        /* Start */
+        long start = System.currentTimeMillis();
+        
+        //rblocks are handled within Router.
+        Router.solve(routerArg);
+        
+        /* End of Solve */
+        long finish = System.currentTimeMillis();
+
+
+        int numPathRouted = 0;
+        List_Iter it = new List_Iter();
+
+        it.reset(pathVectorListPtr);
+        while(it.hasNext(pathVectorListPtr)) {
+            Vector_t pathVectorPtr = (Vector_t)it.next(pathVectorListPtr);
+            numPathRouted += pathVectorPtr.vector_getSize();
+        }
+
+        double elapsed = ((double)finish-(double)start)/1000;
+
+        System.out.println("Paths routed    = " + numPathRouted);
+        System.out.println("Elapsed time    = " + elapsed);
+
+        boolean stats = mazePtr.checkPaths(pathVectorListPtr,labyrinth.global_doPrint);
+        if(!stats)
+            System.out.println("Verification not passed");
+        else 
+            System.out.println("Verification passed.");
+        
+        System.out.println("Finished");    
+    }
+}
+
+/* =============================================================================
+ *
+ * End of labyrinth.c
+ *
+ * =============================================================================
+ */