Adding Labyrinth3D files
authorstephey <stephey>
Sat, 19 Jun 2010 00:15:30 +0000 (00:15 +0000)
committerstephey <stephey>
Sat, 19 Jun 2010 00:15:30 +0000 (00:15 +0000)
in mlp, Normal_Java is a form of Labyrinth3D that can compile under normal Java.
in mlp, rBlocked is the rBlocked version that will compile with our compiler
NOTE: there seems to be a bug with make java in that the program skips right over rBlocks to print out statistics on the last part of the program EVEN THOUGH there are data dependencies. Yonghun suspects it's a bug in the compiler and will investigate over the weekend

in Original, Normal_Java is the original Labyrinth3D code with TM code removed and slightly modded to work with Normal Java.

48 files changed:
Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Coordinate.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Grid.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Labyrinth.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/List_Iter.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/List_Node.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/List_t.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Math.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Maze.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Pair.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Point.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Queue_Int.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Queue_t.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Router.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Solve_arg.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Vector_t.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/extractLines [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/CoordPathWrapper.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Coordinate.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Grid.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Labyrinth.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/List_Iter.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/List_Node.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/List_t.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Math.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Maze.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Pair.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Point.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Queue_Int.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Queue_t.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Router.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Solve_Arg.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Vector_t.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/extractLines [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/CoordPathWrapper.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Coordinate.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Grid.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Labyrinth.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/List_Iter.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/List_Node.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/List_t.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Maze.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Pair.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Point.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Queue_Int.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Queue_t.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Router.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Solve_Arg.java [new file with mode: 0644]
Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Vector_t.java [new file with mode: 0644]

diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Coordinate.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Coordinate.java
new file mode 100644 (file)
index 0000000..68f792b
--- /dev/null
@@ -0,0 +1,178 @@
+/* =============================================================================
+ *
+ * coordinate.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.
+ *
+ * =============================================================================
+ */
+
+
+
+
+import java.lang.Math;
+
+public class Coordinate {
+
+    public int x;
+    public int y;
+    public int z;
+
+    public Coordinate() {}
+
+
+    // coordiate_alloc will be constructor
+    // coordinate_t* coordinate_alloc(long x, long y, long z)
+    public Coordinate(int x,int y,int z) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+    }
+
+    public static Coordinate alloc(int x,int y,int z) {
+        Coordinate c = new Coordinate(x,y,z);
+
+        return c;
+    }
+
+    
+    // deallocate memory
+    // may not need
+    //  coordinate_free
+
+    /*========================================================
+    // coordinate_isEqual
+    ==========================================================*/
+    public static boolean isEqual(Coordinate a,Coordinate b) 
+    {
+        if((a.x == b.x) && (a.y == b.y) && (a.z == b.z))
+            return true;
+        
+        return false;
+    }
+
+    /*==========================================================
+      *
+      * getPairDistance
+      *
+      *========================================================*/   
+    private static double getPairDistance(Pair p)
+    {
+        Coordinate a = (Coordinate)p.first;
+        Coordinate b = (Coordinate)p.second;
+        int dx = a.x - b.x;
+        int dy = a.y - b.y;
+        int dz = a.z - b.z;
+        int dx2 = dx* dx;
+        int dy2 = dy* dy;
+        int dz2 = dz* dz;
+
+        return Math.sqrt((double)(dx2+dy2+dz2));
+    }
+
+
+    /*================================================
+    // coordinat_ comparePair
+     * -- For sorting in list of source/destination pairs
+     * -- Route longer paths first so they are more likely to suceed
+     
+    *================================================*/
+    public static int comparePair(final Object a,final Object b) 
+    {
+        double aDistance = getPairDistance((Pair)a);
+        double bDistance = getPairDistance((Pair)b);
+
+        if(aDistance < bDistance) {
+            return 1;
+        } else if(aDistance > bDistance) {
+            return -1;
+        }
+
+        return 0;
+    }
+
+    /*=======================================================
+      * coordinate_areAdjacent
+      *=======================================================*/
+
+    public static boolean areAdjacent(Coordinate a,Coordinate b) 
+    {
+        int dx = a.x - b.x;
+        int dy = a.y - b.y;
+        int dz = a.z - b.z;
+        int dx2 = dx * dx;
+        int dy2 = dy * dy;
+        int dz2 = dz * dz;
+
+        return (((dx2 + dy2 + dz2) == 1) ? true : false);
+    }
+    }
+
+    /*=====================================================
+      * 
+      * End of Coordinate
+      *
+      *====================================================*/
+    
+    
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Grid.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Grid.java
new file mode 100644 (file)
index 0000000..6e4e2ac
--- /dev/null
@@ -0,0 +1,281 @@
+/* =============================================================================
+ *
+ * grid.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.
+ *
+ * =============================================================================
+ */
+
+import java.lang.Long;
+
+public class Grid {
+    public int width;
+    public int height;
+    public int depth;
+    public int[][][] points_unaligned;
+    
+    public static int GRID_POINT_FULL;
+    public static int GRID_POINT_EMPTY;
+
+    public Grid() 
+    {
+       GRID_POINT_FULL = -2;
+       GRID_POINT_EMPTY = -1;
+    }
+    
+/* =============================================================================
+ * grid_alloc
+ * =============================================================================
+    grid_t* grid_alloc (long width, long height, long depth);
+
+    well... need to implement
+    got stuck
+*/
+  public static Grid alloc(int width,int height,int depth) {
+    Grid grid = new Grid();
+    
+    grid.width = width;
+    grid.height = height;
+    grid.depth = depth;
+    
+    int[][][] points_unaligned = new int[width][height][depth];
+    
+    
+    for(int i=0;i<width;i++)
+      for(int j=0;j<height;j++)
+       for(int k=0;k<depth;k++)
+         points_unaligned[i][j][k]= GRID_POINT_EMPTY;
+    
+    grid.points_unaligned = points_unaligned;
+    
+    return grid;         
+  }
+
+  public static Grid scratchalloc(int width,int height,int depth) {
+    Grid grid = new Grid();
+    grid.width = width;
+    grid.height = height;
+    grid.depth = depth;
+    int[][][] points_unaligned = new int[width][height][depth];
+    grid.points_unaligned = points_unaligned;
+    return grid;         
+  }
+
+
+
+/* =============================================================================
+ * grid_copy
+ * =============================================================================
+    void grid_copy (grid_t* dstGridPtr, grid_t* srcGridPtr);
+ */
+  public static void copy(Grid dstGridPtr,Grid srcGridPtr) {
+    if((srcGridPtr.width == dstGridPtr.width) ||
+       (srcGridPtr.height == dstGridPtr.height) ||
+       (srcGridPtr.depth == dstGridPtr.depth)) {   
+      deepArrayCopy(dstGridPtr.points_unaligned, srcGridPtr.points_unaligned);
+    }      
+  }
+  //Array copy function added to replace System.deepArrayCopy in original 
+  //assumes they are of the same size
+  private static void deepArrayCopy(int[][][] dst, int[][][] src)
+  {
+         for(int i = 0; i < src.length; i++)
+                 for(int j = 0; j < src[i].length; j++)
+                         for(int k = 0; k < src[i][j].length; k++)
+                                 dst[i][j][k] = src[i][j][k];  
+  }
+
+/* =============================================================================
+ * grid_isPointValid
+ * =============================================================================
+ bool_t grid_isPointValid (grid_t* gridPtr, long x, long y, long z);
+ */
+  public boolean isPointValid(int x,int y,int z) {
+    return x>=0 && x< width && y>=0 && y<height && z>=0 && z<depth;
+  }
+
+
+  public int getPoint(int x,int y,int z) {
+    return this.points_unaligned[x][y][z];
+  }
+
+
+/* =============================================================================
+ * grid_isPointEmpty
+ * =============================================================================
+ bool_t grid_isPointEmpty (grid_t* gridPtr, long x, long y, long z); {
+ */
+
+  public boolean isPointEmpty(int x,int y,int z) {
+    return points_unaligned[x][y][z]==GRID_POINT_EMPTY;
+  }
+
+
+
+/* =============================================================================
+ * grid_isPointFull
+ * =============================================================================
+ bool_t grid_isPointFull (grid_t* gridPtr, long x, long y, long z);
+ */
+  public boolean isPointFull(int x,int y,int z) {
+    return points_unaligned[x][y][z]==GRID_POINT_FULL;
+  }
+
+
+/* =============================================================================
+ * grid_setPoint
+ * =============================================================================
+ void grid_setPoint (grid_t* gridPtr, long x, long y, long z, long value);
+ */
+  public void setPoint(int x,int y,int z,int value) {
+    points_unaligned[x][y][z] = value;
+  }
+
+
+/* =============================================================================
+ * grid_addPath
+ * =============================================================================
+void grid_addPath (grid_t* gridPtr, vector_t* pointVectorPtr);
+*/
+  public void addPath(Vector_t pointVectorPtr) {
+    int i;
+    int n = pointVectorPtr.vector_getSize();
+    
+    for(i = 0; i < n; i++) {
+      Coordinate coordinatePtr = (Coordinate)pointVectorPtr.vector_at(i);
+      int x = coordinatePtr.x;
+      int y = coordinatePtr.y;
+      int z = coordinatePtr.z;
+
+      points_unaligned[x][y][z]=GRID_POINT_FULL;
+    }
+  }
+
+  public boolean TM_addPath(Vector_t pointVectorPtr) {
+    int i;
+    int n = pointVectorPtr.vector_getSize();
+
+    int height = this.height;
+    int width = this.width;
+    int area = height * width;
+    boolean dowrites=true;
+    for(i = 1; i < (n-1); i++) {
+      int gridPointIndex = ((Integer)(pointVectorPtr.vector_at(i))).intValue();
+      int z = gridPointIndex / area;
+      int index2d = gridPointIndex % area;
+      int y = index2d / width;
+      int x = index2d % width;        
+      if (points_unaligned[x][y][z] != GRID_POINT_EMPTY) {
+       dowrites=false;
+      }
+    }
+
+    for(i = 1; i < (n-1); i++) {
+      int gridPointIndex = ((Integer)(pointVectorPtr.vector_at(i))).intValue();
+      int z = gridPointIndex / area;
+      int index2d = gridPointIndex % area;
+      int y = index2d / width;
+      int x = index2d % width;
+      int[] array=points_unaligned[x][y];
+      if (dowrites) array[z] = GRID_POINT_FULL;
+    }
+    return !dowrites;
+  }
+
+  public int getPointIndex(int x,int y,int z) {
+    return ((z * height) + y) * width + x;
+  }
+
+  
+  public void print() {
+    int width  = this.width;
+    int height = this.height;
+    int depth  = this.depth;
+
+    for (int z = 0; z < depth; z++) {
+      System.out.println("[z ="+z+"]");
+      for (int x = 0; x < width; x++) {
+       for (int y = 0; y < height; y++) {
+         String str=String.valueOf(points_unaligned[x][y][z]);
+         for(int sp=0; sp<(4-str.length());sp++)
+           System.out.print(" ");
+         System.out.print(str);
+       }
+       System.out.println("");
+      }
+      System.out.println("");
+    }
+  }
+}
+
+
+/* =============================================================================
+ *
+ * End of grid.c
+ *
+ * =============================================================================
+ */
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Labyrinth.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Labyrinth.java
new file mode 100644 (file)
index 0000000..eb88650
--- /dev/null
@@ -0,0 +1,248 @@
+/* =============================================================================
+ *
+ * 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 extends Thread{
+
+    static String global_inputFile;
+    static boolean global_doPrint;
+    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;
+    }
+
+    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 {
+                    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 void run() {
+            Router.solve(routerArg);
+    }
+
+    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");
+        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) 
+    {
+        /*
+         * Initailization
+         */
+
+        Labyrinth labyrinth = new Labyrinth(argv);
+
+        Maze mazePtr = Maze.alloc();
+
+        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);     // list_t.alloc(null)
+        /*
+         * Run transactions
+         */
+        Solve_Arg routerArg = new Solve_Arg(routerPtr,mazePtr,pathVectorListPtr);
+
+        /* Create and start thread */
+
+        Labyrinth[] lb = new Labyrinth[labyrinth.numThread];
+
+        for(int i = 1; i<labyrinth.numThread;i++) {
+            lb[i] = new Labyrinth(i,routerArg);
+        }
+
+        for(int i = 1; i<labyrinth.numThread;i++) {
+            lb[i].start();
+        }
+        long start = System.currentTimeMillis();
+
+        Router.solve(routerArg);        
+
+        /* End of Solve */
+        long finish = System.currentTimeMillis();
+       long diff=finish-start;
+       System.out.println("TIME="+diff);
+
+
+        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 = (finish-start)/1000.0;
+
+        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
+ *
+ * =============================================================================
+ */
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/List_Iter.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/List_Iter.java
new file mode 100644 (file)
index 0000000..351e80d
--- /dev/null
@@ -0,0 +1,38 @@
+public class List_Iter {
+    List_Node itPtr;
+
+    /* =============================================================================
+     * list_iter_reset
+     * =============================================================================
+       void list_iter_reset (list_iter_t* itPtr, list_t* listPtr);
+    */
+     public List_Iter() {
+         itPtr = null;
+     }
+        
+     public void reset(List_t listPtr) 
+     {
+         itPtr = listPtr.head;
+     }
+
+    /* =============================================================================
+     * list_iter_hasNext
+     * =============================================================================
+     * bool_t list_iter_hasNext (list_iter_t* itPtr, list_t* listPtr);
+     */
+     public boolean hasNext(List_t listPtr) {
+         return (itPtr.nextPtr != null)? true : false;
+     }
+
+    /* =============================================================================
+     * list_iter_next
+     * =============================================================================
+     * void* list_iter_next (list_iter_t* itPtr, list_t* listPtr);
+     */
+     public Object next(List_t listPtr) 
+     {
+         itPtr = itPtr.nextPtr;
+         return itPtr.dataPtr; 
+     }
+}
+
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/List_Node.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/List_Node.java
new file mode 100644 (file)
index 0000000..806baa1
--- /dev/null
@@ -0,0 +1,10 @@
+
+public class List_Node {
+    Object dataPtr;
+    List_Node nextPtr;
+
+    public List_Node() {
+        dataPtr = null;
+        nextPtr = null;
+    }
+}
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/List_t.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/List_t.java
new file mode 100644 (file)
index 0000000..699f1a4
--- /dev/null
@@ -0,0 +1,306 @@
+/* =============================================================================
+ *
+ * List_t.java
+ * -- Sorted singly linked list
+ * -- Options: duplicate allowed  
+ *    (DLIST_NO_DUPLICATES) is no implemented yet (default: allow duplicates)
+ *
+ * =============================================================================
+ *
+ * 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 List_t {
+
+    public List_Node head;
+    boolean isCoordinate;
+    int size;
+
+    public List_t() {
+        head = new List_Node();
+    }
+
+
+    /* =======================================================================
+     * allocNode
+     * -- Returns null on failure
+     * =======================================================================
+     */
+    private List_Node allocNode(Object dataPtr) 
+    {
+        List_Node nodePtr = new List_Node();
+
+
+        nodePtr.dataPtr = dataPtr;
+        nodePtr.nextPtr = null;
+
+        return nodePtr;
+    }
+        
+    
+/* =============================================================================
+ * list_alloc
+ * -- If NULL passed for 'compare' function, will compare data pointer addresses
+ * -- Returns NULL on failure
+ * =============================================================================
+ * list_t* list_alloc (long (*compare)(const void*, const void*));
+ *
+ *
+ */
+
+    public static List_t alloc(int isCoordinate) 
+    {
+        List_t listPtr = new List_t();
+
+
+        listPtr.head.dataPtr = null;
+        listPtr.head.nextPtr = null;
+        listPtr.size = 0;
+        
+        listPtr.isCoordinate = (isCoordinate==1)?true:false;
+
+        return listPtr;
+    }
+    
+/* =============================================================================
+ * list_free
+ * -- If NULL passed for 'compare' function, will compare data pointer addresses
+ * -- Returns NULL on failure
+ * =============================================================================
+ * void list_free (list_t* listPtr);
+ */
+    public static void free(List_t listPtr) 
+    {
+        listPtr = null;
+    }
+
+//    privae freeList
+
+/* =============================================================================
+ * list_isEmpty
+ * -- Return TRUE if list is empty, else FALSE
+ * =============================================================================
+ * bool_t list_isEmpty (list_t* listPtr);
+ */
+    public boolean isEmpty() 
+    {
+        return (head.nextPtr == null);
+    }
+
+/* =============================================================================
+ * list_getSize
+ * -- Returns size of list
+ * =============================================================================
+ * long list_getSize (list_t* listPtr);
+ */
+    public int getSize() {
+        return size;
+    }
+
+/* =============================================================================
+ * findPrevious
+ * =============================================================================
+ * void* list_find (list_t* listPtr, void* dataPtr);
+ */                                                                             
+    private List_Node findPrevious(Object dataPtr) 
+    {
+        List_Node prevPtr = head;
+        List_Node nodePtr = prevPtr.nextPtr;
+
+        for(; nodePtr != null; nodePtr = nodePtr.nextPtr) {
+            if (compare(nodePtr.dataPtr,dataPtr) >= 0) {
+                return prevPtr;
+            }
+            prevPtr = nodePtr;
+        }
+
+        return prevPtr;
+    }
+
+    /* =============================================================================
+     * list_find
+     * -- Returns NULL if not found, else returns pointer to data
+     * =============================================================================
+     * void* list_find (list_t* listPtr, void* dataPtr);
+     */
+    public Object find(Object dataPtr) {
+        List_Node nodePtr;
+        List_Node prevPtr = findPrevious(dataPtr);
+
+        nodePtr = prevPtr.nextPtr;
+
+        if((nodePtr == null) ||
+                (compare(nodePtr.dataPtr,dataPtr) != 0)) {
+            return null;
+        }
+
+        return (nodePtr.dataPtr);
+    }
+
+    public int compare(Object obj1,Object obj2) 
+    {
+        if(isCoordinate)
+        {
+            return Coordinate.comparePair(obj1,obj2);
+        }
+        else 
+            return compareObject(obj1,obj2);
+    }
+
+/* =============================================================================
+ * list_insert
+ * -- Return TRUE on success, else FALSE
+ * =============================================================================
+ * bool_t list_insert (list_t* listPtr, void* dataPtr);
+ */
+    public boolean insert(Object dataPtr) {
+        List_Node prevPtr;
+        List_Node nodePtr;
+        List_Node currPtr;
+
+        prevPtr = findPrevious(dataPtr);
+        currPtr = prevPtr.nextPtr;
+
+        nodePtr = allocNode(dataPtr);
+        if (nodePtr == null) {
+            return false;
+        }
+
+        nodePtr.nextPtr = currPtr;
+        prevPtr.nextPtr = nodePtr;
+        size++;
+
+        return true;
+    }
+        
+    
+/* =============================================================================
+ * list_remove
+ * -- Returns TRUE if successful, else FALSE
+ * =============================================================================
+ * bool_t list_remove (list_t* listPtr, void* dataPtr);
+ */
+    public boolean remove(Object dataPtr) 
+    {
+        List_Node prevPtr;
+        List_Node nodePtr;
+
+        prevPtr = findPrevious(dataPtr);
+
+        nodePtr = prevPtr.nextPtr;
+
+        if((nodePtr != null) &&
+            (compare(nodePtr.dataPtr,dataPtr) == 0))
+        {
+            prevPtr.nextPtr = nodePtr.nextPtr;
+            nodePtr.nextPtr = null;
+            nodePtr = null;
+            size--;
+
+            return true;
+        }
+    
+        return false;
+    }
+
+    int compareObject(Object obj1,Object obj2) {
+        return 1;
+    }
+    
+
+/* =============================================================================
+ * list_clear
+ * -- Removes all elements
+ * =============================================================================
+ * void list_clear (list_t* listPtr);
+ */
+    public void clear() {
+        head = new List_Node();
+        size = 0;    
+    }
+
+/* =============================================================================
+ *
+ * End of list.java
+ *
+ * =============================================================================
+ */
+
+ /* Test list */
+
+ public static void main(String[] argv) {
+     List_t listPtr;
+     int[] data1 = new int[5];
+     int[] data2 = new int[6];
+
+     int i;
+
+     System.out.println("Starting...");
+        }
+
+}
+
+
+     
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Math.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Math.java
new file mode 100644 (file)
index 0000000..7e6a59f
--- /dev/null
@@ -0,0 +1,136 @@
+public class Math {
+
+  public static double setPI() {
+    double PI = 3.14159265358979323846;
+    return PI;
+  }
+
+  // an alias for setPI()
+  public static double PI() {
+    double PI = 3.14159265358979323846;
+    return PI;
+  }
+
+  public static int abs(int x) {
+    if (x < 0) {
+      return -x;
+    } else {
+      return x;
+    }
+  }
+
+  public static double fabs(double x) {
+    if (x < 0) {
+      return -x;
+    } else {
+      return x;
+    }
+  }
+
+  public static double abs(double x) {
+    if (x < 0) {
+      return -x;
+    } else {
+      return x;
+    }
+  }
+
+  public static float abs(float a) {
+    if (a<0)
+      return -a;
+    else return a;
+  }
+
+  public static double max(double a, double b) {
+    if(a == b)
+      return a;
+    if(a > b) {
+      return a;
+    } else {
+      return b;
+    }
+  }
+
+  public static int max(int a, int b) {
+    if(a == b)
+      return a;
+    if(a > b) {
+      return a;
+    } else {
+      return b;
+    }
+  }
+
+  public static int imax(int a, int b) {
+    if(a == b)
+      return a;
+    if(a > b) {
+      return a;
+    } else {
+      return b;
+    }
+  }
+
+  public static int imin(int a, int b) {
+    if(a == b)
+      return a;
+    if(a > b) {
+      return b;
+    } else {
+      return a;
+    }
+  }
+
+  /** sqrt(a^2 + b^2) without under/overflow. **/
+  public static double hypot(double a, double b) {
+    double r;
+    if (fabs(a) > fabs(b)) {
+      r = b/a;
+      r = fabs(a)*sqrt(1+r*r);
+    } else if (b != 0) {
+      r = a/b;
+      r = fabs(b)*sqrt(1+r*r);
+    } else {
+      r = 0.0;
+    }
+    return r;
+  }
+
+  public static double rint(double x) {
+    double y = ceil(x);
+    double d = y - x;
+    if( d == 0.5 ) {
+      if( ((int)y)%2 == 0 ) {
+       return y;
+      } else {
+       return y - 1.0;
+      }
+    } else if( d < 0.5 ) {
+      return y;
+    }
+    return y - 1.0;
+  }
+
+  public static native double sin(double a);
+  public static native double cos(double a);
+  public static native double asin(double a);
+  public static native double acos(double a);
+  public static native double tan(double a);
+  public static native double atan(double a);
+  public static native double atan2(double a, double b);
+  public static native double exp(double a);
+  public static native double sqrt(double a);
+  public static native double log(double a);
+  public static native double pow(double a, double b);
+
+  public static native double ceil(double a);
+  public static native double floor(double a);
+
+  public static native float sinf(float a);
+  public static native float cosf(float a);
+  public static native float expf(float a);
+  public static native float sqrtf(float a);
+  public static native float logf(float a);
+  public static native float powf(float a, float b);
+  public static native float ceilf(float a);
+}
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Maze.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Maze.java
new file mode 100644 (file)
index 0000000..354269e
--- /dev/null
@@ -0,0 +1,406 @@
+import java.io.File;
+import java.util.Scanner;
+import java.util.StringTokenizer;
+
+/*=============================================================================
+ *
+ * Maze.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 Maze {
+    Grid gridPtr;
+    Queue_t workQueuePtr;
+    Vector_t wallVectorPtr; /* contains source/destination pairs to route */
+    Vector_t srcVectorPtr;  /* obstacles */
+    Vector_t dstVectorPtr;  /* destinations */
+    
+    public int GRID_POINT_FULL;
+    public int GRID_POINT_EMPTY;
+
+    public Maze() 
+    {
+       GRID_POINT_FULL = -2;
+       GRID_POINT_EMPTY = -1;
+    }
+
+
+/* =============================================================================
+ * maze_alloc
+ * =============================================================================
+ maze_t* maze_alloc ();
+ */
+   public static Maze alloc() 
+   {
+       Maze mazePtr = new Maze();
+
+       mazePtr.gridPtr = null;
+       mazePtr.workQueuePtr = Queue_t.queue_alloc(1024);
+       mazePtr.wallVectorPtr = Vector_t.vector_alloc(1);
+       mazePtr.srcVectorPtr = Vector_t.vector_alloc(1);
+       mazePtr.dstVectorPtr = Vector_t.vector_alloc(1);
+
+
+       return mazePtr;
+   }
+
+/* =============================================================================
+ * maze_free
+ * =============================================================================
+ void maze_free (maze_t* mazePtr);
+ */
+    public static void free(Maze m)
+    {
+        m = null;
+    }    
+
+/* =============================================================================
+ * addToGrid
+ * =============================================================================
+ */
+    private void addToGrid(Grid gridPtr,Vector_t vectorPtr,String type)
+    {
+        int i;
+        int n = vectorPtr.vector_getSize();
+
+        for(i = 0; i < n; i++) {
+            Coordinate coordinatePtr = (Coordinate)vectorPtr.vector_at(i);
+            if(!gridPtr.isPointValid(coordinatePtr.x,coordinatePtr.y,coordinatePtr.z))
+            {
+                System.out.println("Error: " + type + " (" + coordinatePtr.x + 
+                                                      ", " + coordinatePtr.y + 
+                                                      ", " + coordinatePtr.z);
+                System.exit(1);
+            }
+        }
+        gridPtr.addPath(vectorPtr);
+    }
+/* =============================================================================
+ * maze_read
+ * -- Return number of path to route
+ * =============================================================================
+ long maze_read (maze_t* mazePtr, char* inputFileName);
+ */
+    public int readMaze(String inputFileName)
+    {
+       //TODO remove TRY
+       try
+       {
+//          FileInputStream in = new FileInputStream(inputFileName);
+               //TODO remove this and uncomment the line above. 
+               Scanner in = new Scanner(new File(inputFileName));
+            /*
+             * Parse input file
+             */
+            int lineNumber = 0;
+            int height = -1;
+            int width = -1;
+            int depth = -1;
+            boolean isParseError = false;
+            List_t workListPtr = List_t.alloc(1); // List.alloc(Coordinate.comparePair);
+            String line;
+
+            //TODO change this back as well
+//          while((line = in.readLine()) != null) {
+            while(in.hasNextLine()){
+                line = in.nextLine();
+            //TODO remove the above
+                
+                String code;
+                int[] xy = new int[6];  // equivalent to x1,y1,z1,x2,y2,z2
+                int numToken = 0;
+                
+                StringTokenizer tok = new StringTokenizer(line);
+
+                if((numToken = tok.countTokens()) < 1 ) {
+                    continue;
+                }
+
+                code = tok.nextToken();
+
+                if(code.equals("#")) {
+                    /* comment line */
+                    continue;
+                }
+                for(int i=0;i<numToken-1;i++) {
+                    xy[i] = Integer.parseInt(tok.nextToken());
+                }
+
+                if(code.equals("d")) {
+                      /* dimensions (format: d x y z) */
+                     if(numToken != 4) {
+                        isParseError = true;
+                     }
+                     else {
+                        width = xy[0];
+                        height = xy[1];
+                        depth = xy[2];
+                        if(width < 1 || height < 1 || depth <1)
+                            isParseError = true;
+                     }
+                 }else if(code.equals("p")) { /* paths (format: p x1 y1 z1 x2 y2 z2) */
+                    if(numToken != 7) {
+                        isParseError = true;
+                    }
+                    else {
+                        Coordinate srcPtr = Coordinate.alloc(xy[0],xy[1],xy[2]);
+                        Coordinate dstPtr = Coordinate.alloc(xy[3],xy[4],xy[5]);
+
+                        if(Coordinate.isEqual(srcPtr,dstPtr)) {
+                            isParseError = true;
+                        }
+                        else { 
+                            Pair coordinatePairPtr = Pair.alloc(srcPtr,dstPtr);
+                            boolean status = workListPtr.insert(coordinatePairPtr);
+                            srcVectorPtr.vector_pushBack(srcPtr);
+                            dstVectorPtr.vector_pushBack(dstPtr);
+                            
+                        }
+                    }
+                }else if(code.equals("w")) {
+                         /* walls (format: w x y z) */
+                        if(numToken != 4) {
+                            isParseError = true;
+                        } else {
+                            Coordinate wallPtr = Coordinate.alloc(xy[0],xy[1],xy[2]);
+                            wallVectorPtr.vector_pushBack(wallPtr);
+                        }
+                }else { /* error */
+                       isParseError = true;
+                }
+                
+                if(isParseError)  {/* Error */
+                    System.out.println("Error: line " + lineNumber + " of " + inputFileName + "invalid");
+                    System.exit(1);
+                }
+            }
+            /* iterate over lines in put file */
+          
+            in.close();
+            /* 
+             * Initialize grid contents
+             */
+            if(width < 1 || height < 1 || depth < 1) {
+                System.out.println("Error : Invalid dimensions ( " + width + ", " + height + ", "+ depth + ")");
+                System.exit(1);
+            }
+
+            Grid gridPtr = Grid.alloc(width,height,depth);
+            this.gridPtr = gridPtr;
+            addToGrid(gridPtr,wallVectorPtr,"wall");
+            addToGrid(gridPtr,srcVectorPtr, "source");
+            addToGrid(gridPtr,dstVectorPtr, "destination");
+            System.out.println("Maze dimensions = " + width + " x " + height + " x " + depth);
+            System.out.println("Paths to route  = " + workListPtr.getSize());
+
+            /*
+             * Initialize work queue
+             */
+            List_Iter it = new List_Iter();
+            it.reset(workListPtr);
+            while(it.hasNext(workListPtr)) {
+                Pair coordinatePairPtr = (Pair)it.next(workListPtr);
+                workQueuePtr.queue_push(coordinatePairPtr);
+            }
+
+            List_t.free(workListPtr);
+
+            return srcVectorPtr.vector_getSize();
+       } //TODO remove this parenthesis (goes with Try) and the below
+       catch(Exception e)
+       {
+               System.out.println("The File is non-existant: " + inputFileName);
+               e.getStackTrace();
+               return -1;
+       }
+    }
+    
+
+/* =============================================================================
+ * maze_checkPaths
+ * =============================================================================
+ bool_t maze_checkPaths (maze_t* mazePtr, list_t* pathListPtr, bool_t doPrintPaths);
+ */
+    public boolean checkPaths(List_t pathVectorListPtr,boolean doPrintPaths)
+    {
+        int i;
+       
+        /* Mark walls */
+        Grid testGridPtr = Grid.alloc(gridPtr.width,gridPtr.height,gridPtr.depth);
+        testGridPtr.addPath(wallVectorPtr);
+
+        /* Mark sources */
+        int numSrc = srcVectorPtr.vector_getSize();
+//        System.out.println("numSrc = " +numSrc);
+//        System.exit(1);
+        for(i = 0; i < numSrc; i++) {
+            Coordinate srcPtr = (Coordinate)srcVectorPtr.vector_at(i);
+            testGridPtr.setPoint(srcPtr.x,srcPtr.y,srcPtr.z,0);
+        }
+
+        /* Mark destinations */
+        int numdst = dstVectorPtr.vector_getSize();
+        for(i = 0; i < numdst; i++) {
+            Coordinate dstPtr = (Coordinate)dstVectorPtr.vector_at(i);
+            testGridPtr.setPoint(dstPtr.x,dstPtr.y,dstPtr.z,0);
+        }
+
+//        testGridPtr.print();
+
+        /* Make sure path is contiguous and does not overlap */
+        int id = 0;
+        List_Iter it = new List_Iter();
+        it.reset(pathVectorListPtr);
+
+        int height = gridPtr.height;
+        int width = gridPtr.width;
+        int area = height * width;
+
+        while(it.hasNext(pathVectorListPtr)) {
+            Vector_t pathVectorPtr = (Vector_t)it.next(pathVectorListPtr);
+            int numPath = pathVectorPtr.vector_getSize();
+          
+            for(i = 0; i < numPath; i++) {
+                id++;
+                Vector_t pointVectorPtr = (Vector_t)pathVectorPtr.vector_at(i);
+                /* Check start */
+                int prevGridPointIndex = ((Integer)pointVectorPtr.vector_at(0)).intValue();
+
+               int z=prevGridPointIndex/area;
+               int index2d=prevGridPointIndex%area;
+               int y=index2d/width;
+               int x=index2d%width;
+
+                if(testGridPtr.getPoint(x,y,z) != 0) {
+                    return false;
+                }
+
+                Coordinate prevCoordinate = new Coordinate();
+                prevCoordinate.x = x;
+                prevCoordinate.y = y;
+                prevCoordinate.z = z;
+
+                
+                int numPoint = pointVectorPtr.vector_getSize();
+                int j;
+
+                for(j = 1; j< (numPoint - 1) ;j++) { /* no need to check endpoints */
+                    int currGridPointIndex = ((Integer)pointVectorPtr.vector_at(j)).intValue();
+                    Coordinate currCoordinate = new Coordinate();
+
+                   z=currGridPointIndex/area;
+                   index2d=currGridPointIndex%area;
+                   y=index2d/width;
+                   x=index2d%width;
+
+                    currCoordinate.x = x;
+                    currCoordinate.y = y;
+                    currCoordinate.z = z;
+
+                    if(!Coordinate.areAdjacent(currCoordinate,prevCoordinate)) {
+                        System.out.println("you there?");
+                        return false;
+                    }
+
+                    prevCoordinate = currCoordinate;
+                    int xx = currCoordinate.x;
+                    int yy = currCoordinate.y;
+                    int zz = currCoordinate.z;
+                    if(testGridPtr.getPoint(xx,yy,zz) != GRID_POINT_EMPTY) {
+                        return false;
+                    } else {
+                        testGridPtr.setPoint(xx,yy,zz,id);
+                    }
+                }
+                /* Check end */
+                int lastGridPointIndex = ((Integer)pointVectorPtr.vector_at(j)).intValue();
+               z=lastGridPointIndex/area;
+               index2d=lastGridPointIndex%area;
+               y=index2d/width;
+               x=index2d%width;
+                if(testGridPtr.getPoint(x,y,z) != 0) {
+                    return false;
+                }
+            } /* iterate over pathVector */
+        } /* iterate over pathVectorList */
+
+        if(doPrintPaths) {
+            System.out.println("\nRouted Maze:");
+           testGridPtr.print();
+        }
+
+
+        return true;
+    }
+                    
+ }
+/* =============================================================================
+ *
+ * End of maze.h
+ *
+ * =============================================================================
+ */
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Pair.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Pair.java
new file mode 100644 (file)
index 0000000..1869fdb
--- /dev/null
@@ -0,0 +1,86 @@
+
+
+public class Pair {
+    public Object first;
+    public Object second;
+
+    public Pair() {
+        first = null;
+        second = null;
+    }
+
+
+/* =============================================================================
+ * 
+ * pair constructor
+ * 
+ * pair_t* pair_alloc(void* firstPtr, void* secondPtr);
+ * =============================================================================
+ */
+    public static Pair alloc(Object first,Object second)
+    {
+        Pair ptr= new Pair();
+        ptr.first = first;
+        ptr.second = second;
+
+        return ptr;
+    }
+
+
+
+/* =============================================================================
+ * Ppair_alloc
+ *
+ * -- Returns NULL if failure
+ * =============================================================================
+ */
+  public Pair Ppair_alloc (Object firstPtr, Object secondPtr) {
+    Pair pairPtr = new Pair();       
+    pairPtr.first = firstPtr;
+    pairPtr.second = secondPtr;
+    return pairPtr;
+  }
+
+
+/* =============================================================================
+ * pair_free
+ * =============================================================================
+ *
+ *  void pair_free (pair_t* pairPtr);
+ *
+ */
+    public void free(Pair pairPtr)
+    {
+        pairPtr = null;
+    }
+
+
+/* =============================================================================
+ * Ppair_free
+ * =============================================================================
+ *
+void Ppair_free (pair_t* pairPtr);
+*/
+
+/* =============================================================================
+ * pair_swap
+ * -- Exchange 'firstPtr' and 'secondPtr'
+ * =============================================================================
+ * void pair_swap (pair_t* pairPtr);
+*/
+    public void swap(Pair pairPtr)
+    {
+        Object tmpPtr = pairPtr.first;
+
+        pairPtr.first = pairPtr.second;
+        pairPtr.second = tmpPtr;
+    }
+
+}    
+
+/* =============================================================================
+ *
+ * End of pair.java
+ *
+ * =============================================================================
+ */
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Point.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Point.java
new file mode 100644 (file)
index 0000000..8905bd5
--- /dev/null
@@ -0,0 +1,25 @@
+
+  public class Point {
+        int x;
+        int y;
+        int z;
+        int value;
+        int momentum;
+
+        public Point() {
+            x = -1;
+            y = -1;
+            z = -1;
+            value = -1;
+            momentum = -1;
+        }
+        
+        public Point(int x,int y, int z,int value, int m) {
+            this.x = x;
+            this.y = y;
+            this.z = z;
+            this.value = value;
+            momentum = m;
+        }
+    }
+
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Queue_Int.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Queue_Int.java
new file mode 100644 (file)
index 0000000..49088e5
--- /dev/null
@@ -0,0 +1,412 @@
+/* =============================================================================
+ *
+ * queue.java
+ *
+ * =============================================================================
+ *
+ * Copyright (C) Stanford University, 2006.  All Rights Reserved.
+ * Author: Chi Cao Minh
+ *
+ * Ported to Java June 2009 Alokika Dash
+ * adash@uci.edu
+ * University of California, Irvine
+ *
+ * =============================================================================
+ * 
+ * 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 Queue_Int {
+  int pop; /* points before element to pop */
+  int push;
+  int capacity;
+  int[] elements;
+
+  private int QUEUE_GROWTH_FACTOR;
+  
+  public Queue_Int() {
+         QUEUE_GROWTH_FACTOR = 2;
+  }
+
+  /* =============================================================================
+   * queue_alloc
+   * =============================================================================
+   */
+  public static Queue_Int queue_alloc (int initCapacity)
+  {
+    Queue_Int queuePtr = new Queue_Int();
+
+    int capacity = ((initCapacity < 2) ? 2 : initCapacity);
+    queuePtr.elements = new int[capacity];
+    queuePtr.pop      = capacity - 1;
+    queuePtr.push     = 0;
+    queuePtr.capacity = capacity;
+
+    return queuePtr;
+  }
+
+
+  /* =============================================================================
+   * Pqueue_alloc
+   * =============================================================================
+   */
+  public Queue_Int
+    Pqueue_alloc (int initCapacity)
+    {
+      Queue_Int queuePtr = new Queue_Int();
+
+      int capacity = ((initCapacity < 2) ? 2 : initCapacity);
+      queuePtr.elements = new int[capacity];
+      queuePtr.pop      = capacity - 1;
+      queuePtr.push     = 0;
+      queuePtr.capacity = capacity;
+
+      return queuePtr;
+    }
+
+
+  /* =============================================================================
+   * TMqueue_alloc
+   * =============================================================================
+   */
+  public Queue_Int TMqueue_alloc (int initCapacity)
+  {
+    Queue_Int queuePtr = new Queue_Int();
+
+    int capacity = ((initCapacity < 2) ? 2 : initCapacity);
+    queuePtr.elements = new int[capacity];
+    queuePtr.pop      = capacity - 1;
+    queuePtr.push     = 0;
+    queuePtr.capacity = capacity;
+
+    return queuePtr;
+  }
+
+
+  /* =============================================================================
+   * queue_free
+   * =============================================================================
+   */
+  public void
+    queue_free ()
+    {
+      elements = null;
+    }
+
+
+  /* =============================================================================
+   * Pqueue_free
+   * =============================================================================
+   */
+  public void
+    Pqueue_free ()
+    {
+      elements = null;
+    }
+
+
+  /* =============================================================================
+   * TMqueue_free
+   * =============================================================================
+   */
+  public void
+    TMqueue_free ()
+    {
+      elements = null;
+    }
+
+
+  /* =============================================================================
+   * queue_isEmpty
+   * =============================================================================
+   */
+  public boolean
+    queue_isEmpty ()
+    {
+      return (((pop + 1) % capacity == push) ? true : false);
+    }
+
+
+  /* =============================================================================
+   * queue_clear
+   * =============================================================================
+   */
+  public void
+    queue_clear ()
+    {
+      pop  = capacity - 1;
+      push = 0;
+    }
+
+
+  /* =============================================================================
+   * TMqueue_isEmpty
+   * =============================================================================
+   */
+  public boolean
+    TMqueue_isEmpty (Queue_Int queuePtr)
+    {
+      int pop      = queuePtr.pop;
+      int push     = queuePtr.push;
+      int capacity = queuePtr.capacity;
+
+      return (((pop + 1) % capacity == push) ? true : false);
+    }
+
+
+  /* =============================================================================
+   * queue_push
+   * =============================================================================
+   */
+  public boolean
+    queue_push (int dataPtr)
+    {
+
+      /* Need to resize */
+      int newPush = (push + 1) % capacity;
+      if (newPush == pop) {
+
+        int newCapacity = capacity * QUEUE_GROWTH_FACTOR;
+        int[] newElements = new int[newCapacity];
+
+        int dst = 0;
+        int[] tmpelements = elements;
+        if (pop < push) {
+          int src;
+          for (src = (pop + 1); src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        } else {
+          int src;
+          for (src = (pop + 1); src < capacity; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+          for (src = 0; src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        }
+
+        elements = newElements;
+        pop      = newCapacity - 1;
+        capacity = newCapacity;
+        push = dst;
+        newPush = push + 1; /* no need modulo */
+      }
+
+      elements[push] = dataPtr;
+      push = newPush;
+
+      return true;
+    }
+
+
+  /* =============================================================================
+   * Pqueue_push
+   * =============================================================================
+   */
+  public boolean
+    Pqueue_push (Queue_Int queuePtr, int dataPtr)
+    {
+      int pop      = queuePtr.pop;
+      int push     = queuePtr.push;
+      int capacity = queuePtr.capacity;
+
+
+      /* Need to resize */
+      int newPush = (push + 1) % capacity;
+      if (newPush == pop) {
+
+        int newCapacity = capacity * QUEUE_GROWTH_FACTOR;
+        int[] newElements = new int[newCapacity];
+
+        int dst = 0;
+        int[] elements = queuePtr.elements;
+        if (pop < push) {
+          int src;
+          for (src = (pop + 1); src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        } else {
+          int src;
+          for (src = (pop + 1); src < capacity; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+          for (src = 0; src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        }
+
+        elements = null;
+        queuePtr.elements = newElements;
+        queuePtr.pop      = newCapacity - 1;
+        queuePtr.capacity = newCapacity;
+        push = dst;
+        newPush = push + 1; /* no need modulo */
+
+      }
+
+      queuePtr.elements[push] = dataPtr;
+      queuePtr.push = newPush;
+
+      return true;
+    }
+
+
+  /* =============================================================================
+   * TMqueue_push
+   * =============================================================================
+   */
+  public boolean
+    TMqueue_push (Queue_Int queuePtr, int dataPtr)
+    {
+      int pop      = (queuePtr.pop);
+      int push     = (queuePtr.push);
+      int capacity = (queuePtr.capacity);
+
+
+      /* Need to resize */
+      int newPush = (push + 1) % capacity;
+      if (newPush == pop) {
+        int newCapacity = capacity * QUEUE_GROWTH_FACTOR;
+        int[] newElements = new int[newCapacity];
+
+        int dst = 0;
+        int[] elements = queuePtr.elements;
+        if (pop < push) {
+          int src;
+          for (src = (pop + 1); src < push; src++, dst++) {
+            newElements[dst] = (elements[src]);
+          }
+        } else {
+          int src;
+          for (src = (pop + 1); src < capacity; src++, dst++) {
+            newElements[dst] = (elements[src]);
+          }
+          for (src = 0; src < push; src++, dst++) {
+            newElements[dst] = (elements[src]);
+          }
+        }
+
+        elements = null;
+        queuePtr.elements = newElements;
+        queuePtr.pop      = newCapacity - 1;
+        queuePtr.capacity = newCapacity;
+        push = dst;
+        newPush = push + 1; /* no need modulo */
+
+      }
+
+      int[] elements = queuePtr.elements;
+      elements[push] = dataPtr;
+      queuePtr.push = newPush;
+
+      return true;
+    }
+
+
+  /* =============================================================================
+   * queue_pop
+   * =============================================================================
+   */
+  public int
+    queue_pop ()
+    {
+      int newPop = (pop + 1) % capacity;
+      if (newPop == push) {
+        return 0;
+      }
+
+      int dataPtr = elements[newPop];
+      pop = newPop;
+
+      return dataPtr;
+    }
+
+
+  /* =============================================================================
+   * TMqueue_pop
+   * =============================================================================
+   */
+  public int
+    TMqueue_pop (Queue_Int queuePtr)
+    {
+      int pop      = queuePtr.pop;
+      int push     = queuePtr.push;
+      int capacity = queuePtr.capacity;
+
+      int newPop = (pop + 1) % capacity;
+      if (newPop == push) {
+        return 0;
+      }
+
+      int[] elements = queuePtr.elements;
+      int dataPtr = elements[newPop];
+      queuePtr.pop = newPop;
+
+      return dataPtr;
+    }
+
+  /****
+   * main method for testing
+   **/
+  /*
+     public static void main(String[] args) {
+     testQueue queuePtr = testQueue.queue_alloc(-1);
+     int numData = 4;
+     if(queuePtr.queue_isEmpty())
+     System.out.println("Queue is empty");
+
+     for(int i = 0; i<numData; i++) {
+     System.out.println("Inserting " + i);
+     queuePtr.queue_push(i);
+     }
+
+     for(int i = 0; i<numData; i++) {
+     int val = queuePtr.queue_pop();
+     System.out.println("Removing " + val);
+     }
+
+     if(queuePtr.queue_isEmpty())
+     System.out.println("Queue is empty");
+     }
+     */
+}
+/* =============================================================================
+ *
+ * End of queue.java
+ *
+ * =============================================================================
+ */
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Queue_t.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Queue_t.java
new file mode 100644 (file)
index 0000000..d1b6e3d
--- /dev/null
@@ -0,0 +1,300 @@
+/* =============================================================================
+ *
+ * queue.java
+ *
+ * =============================================================================
+ *
+ * Copyright (C) Stanford University, 2006.  All Rights Reserved.
+ * Author: Chi Cao Minh
+ *
+ * Ported to Java
+ * Author:Alokika Dash
+ * University of California, Irvine
+ *
+ * =============================================================================
+ * 
+ * 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 Queue_t {
+  int pop; /* points before element to pop */
+  int push;
+  int capacity;
+  Object[] elements;
+  
+  private int QUEUE_GROWTH_FACTOR;
+
+  public Queue_t() {
+         QUEUE_GROWTH_FACTOR = 2;
+  }
+
+  /* =============================================================================
+   * queue_alloc
+   * =============================================================================
+   */
+  public static Queue_t queue_alloc (int initCapacity)
+  {
+    Queue_t queuePtr = new Queue_t();
+
+    int capacity = ((initCapacity < 2) ? 2 : initCapacity);
+    queuePtr.elements = new Object[capacity];
+    queuePtr.pop      = capacity - 1;
+    queuePtr.push     = 0;
+    queuePtr.capacity = capacity;
+
+    return queuePtr;
+  }
+
+
+  /* =============================================================================
+   * Pqueue_alloc
+   * =============================================================================
+   */
+  public Queue_t
+    Pqueue_alloc (int initCapacity)
+    {
+      Queue_t queuePtr = new Queue_t();
+
+      int capacity = ((initCapacity < 2) ? 2 : initCapacity);
+      queuePtr.elements = new Object[capacity];
+      queuePtr.pop      = capacity - 1;
+      queuePtr.push     = 0;
+      queuePtr.capacity = capacity;
+
+      return queuePtr;
+    }
+
+  /* =============================================================================
+   * queue_free
+   * =============================================================================
+   */
+  public void
+    queue_free (Queue_t queuePtr)
+    {
+      queuePtr.elements = null;
+      queuePtr = null;
+    }
+
+
+  /* =============================================================================
+   * Pqueue_free
+   * =============================================================================
+   */
+  public void
+    Pqueue_free (Queue_t queuePtr)
+    {
+      queuePtr.elements = null;
+      queuePtr = null;
+    }
+
+
+  /* =============================================================================
+   * TMqueue_free
+   * =============================================================================
+   *
+  public void
+    TMqueue_free (TM_ARGDECL  Queue* queuePtr)
+    {
+      queuePtr.elements = null;
+      queuePtr = null;
+    }
+
+*/
+  /* =============================================================================
+   * queue_isEmpty
+   * =============================================================================
+   */
+  public boolean
+    queue_isEmpty ()
+    {
+      //int pop      = queuePtr.pop;
+      //int push     = queuePtr.push;
+      //int capacity = queuePtr.capacity;
+
+      return (((pop + 1) % capacity == push) ? true : false);
+    }
+
+
+  /* =============================================================================
+   * queue_clear
+   * =============================================================================
+   */
+  public void
+    queue_clear ()
+    {
+      pop  = capacity - 1;
+      push = 0;
+    }
+
+
+  /* =============================================================================
+   * TMqueue_isEmpty
+   * =============================================================================
+   */
+
+
+
+  /* =============================================================================
+   * queue_push
+   * =============================================================================
+   */
+  public boolean
+    queue_push (Object dataPtr)
+    {
+    
+
+      /* Need to resize */
+      int newPush = (push + 1) % capacity;
+      if (newPush == pop) {
+
+        int newCapacity = capacity * QUEUE_GROWTH_FACTOR;
+        Object[] newElements = new Object[newCapacity];
+
+        int dst = 0;
+        Object[] tmpelements = elements;
+        if (pop < push) {
+          int src;
+          for (src = (pop + 1); src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        } else {
+          int src;
+          for (src = (pop + 1); src < capacity; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+          for (src = 0; src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        }
+
+        //elements = null;
+        elements = newElements;
+        pop      = newCapacity - 1;
+        capacity = newCapacity;
+        push = dst;
+        newPush = push + 1; /* no need modulo */
+      }
+
+      elements[push] = dataPtr;
+      push = newPush;
+
+      return true;
+    }
+
+
+  /* =============================================================================
+   * Pqueue_push
+   * =============================================================================
+   */
+  public boolean
+    Pqueue_push (Queue_t queuePtr, Object dataPtr)
+    {
+      int pop      = queuePtr.pop;
+      int push     = queuePtr.push;
+      int capacity = queuePtr.capacity;
+
+
+      /* Need to resize */
+      int newPush = (push + 1) % capacity;
+      if (newPush == pop) {
+
+        int newCapacity = capacity * QUEUE_GROWTH_FACTOR;
+        Object[] newElements = new Object[newCapacity];
+        int dst = 0;
+        Object[] elements = queuePtr.elements;
+        if (pop < push) {
+          int src;
+          for (src = (pop + 1); src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        } else {
+          int src;
+          for (src = (pop + 1); src < capacity; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+          for (src = 0; src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        }
+
+        elements = null;
+        queuePtr.elements = newElements;
+        queuePtr.pop      = newCapacity - 1;
+        queuePtr.capacity = newCapacity;
+        push = dst;
+        newPush = push + 1; /* no need modulo */
+
+      }
+
+      queuePtr.elements[push] = dataPtr;
+      queuePtr.push = newPush;
+
+      return true;
+    }
+
+  /* =============================================================================
+   * queue_pop
+   * =============================================================================
+   */
+  public Object
+    //queue_pop (Queue queuePtr)
+    queue_pop ()
+    {
+      //int pop      = queuePtr.pop;
+      //int push     = queuePtr.push;
+      //int capacity = queuePtr.capacity;
+
+      int newPop = (pop + 1) % capacity;
+      if (newPop == push) {
+        return null;
+      }
+
+      //Object dataPtr = queuePtr.elements[newPop];
+      //queuePtr.pop = newPop;
+      Object dataPtr = elements[newPop];
+      pop = newPop;
+
+      return dataPtr;
+    }
+
+
+}
+/* =============================================================================
+ *
+ * End of queue.java
+ *
+ * =============================================================================
+ */
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Router.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Router.java
new file mode 100644 (file)
index 0000000..bb4f555
--- /dev/null
@@ -0,0 +1,415 @@
+/* =============================================================================
+ *
+ * Router.java
+ *
+ * =============================================================================
+ *
+ * Copyright (C) Stanford University, 2006.  All Rights Reserved.
+ * Author: Chi Cao Minh
+ * 
+ * Ported to Java
+ * Author: Jihoon Lee
+ * University of California, Irvine
+ *
+ * =============================================================================
+ *
+ * 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 Router {
+    public int xCost;
+    public int yCost;
+    public int zCost;
+    public int bendCost;
+    public static Point MOVE_POSX;
+    public static Point MOVE_POSY;
+    public static Point MOVE_POSZ;
+    public static Point MOVE_NEGX;
+    public static Point MOVE_NEGY;
+    public static Point MOVE_NEGZ;
+    
+       private static int  MOMENTUM_ZERO;
+       private static int  MOMENTUM_POSX;
+       private static int  MOMENTUM_POSY;
+       private static int  MOMENTUM_POSZ;
+       private static int  MOMENTUM_NEGX;
+       private static int  MOMENTUM_NEGY;
+       private static int  MOMENTUM_NEGZ;
+       private static int  GRID_POINT_FULL;
+       private static int  GRID_POINT_EMPTY;
+
+    public Router() {
+       //Replaced #defines
+       MOMENTUM_ZERO = 0;
+       MOMENTUM_POSX = 1;
+       MOMENTUM_POSY = 2;
+       MOMENTUM_POSZ = 3;
+       MOMENTUM_NEGX = 4;
+       MOMENTUM_NEGY = 5;
+       MOMENTUM_NEGZ = 6;
+       GRID_POINT_FULL = -2;
+       GRID_POINT_EMPTY = -1;
+    }
+
+/* =============================================================================
+ * router_alloc
+ * =============================================================================
+ * router_t* router_alloc (long xCost, long yCost, long zCost, long bendCost);
+ */
+  public static Router alloc(int xCost,int yCost,int zCost,int bendCost) {
+    Router routerPtr = new Router();
+
+    
+    routerPtr.MOVE_POSX = new Point(1,0,0,0,MOMENTUM_POSX);
+    routerPtr.MOVE_POSY = new Point(0,1,0,0,MOMENTUM_POSY);
+    routerPtr.MOVE_POSZ = new Point(0,0,1,0,MOMENTUM_POSZ);
+    routerPtr.MOVE_NEGX = new Point(-1,0,0,0,MOMENTUM_NEGX);
+    routerPtr.MOVE_NEGY = new Point(0,-1,0,0,MOMENTUM_NEGY);
+    routerPtr.MOVE_NEGZ = new Point(0,0,-1,0,MOMENTUM_NEGZ);
+
+    routerPtr.xCost = xCost;
+    routerPtr.yCost = yCost;
+    routerPtr.zCost = zCost;
+    routerPtr.bendCost = bendCost;
+    
+    return routerPtr;    
+  }
+
+
+/* ============================================================================
+ * PexpandToneighbor
+ * ============================================================================
+ */
+  private void PexpandToNeighbor(Grid myGridPtr, 
+                                int x,int y,int z, int value,Queue_Int queuePtr) {
+    if (myGridPtr.isPointValid(x,y,z)) {
+      int neighborValue = myGridPtr.points_unaligned[x][y][z];
+      if (neighborValue == GRID_POINT_EMPTY) {
+       int neighborGridPointIndex = myGridPtr.getPointIndex(x,y,z);
+       myGridPtr.points_unaligned[x][y][z] = value;
+       queuePtr.queue_push(neighborGridPointIndex);
+      } else if (neighborValue != GRID_POINT_FULL) {
+       if (value < neighborValue) {
+         int neighborGridPointIndex = myGridPtr.getPointIndex(x,y,z);
+         myGridPtr.points_unaligned[x][y][z] = value;
+         queuePtr.queue_push(neighborGridPointIndex);
+       }
+      }
+    }
+  }
+
+
+/* ============================================================================
+ * PdoExpansion
+ * ============================================================================
+ */
+    public boolean PdoExpansion (Router routerPtr,Grid myGridPtr,Queue_Int queuePtr,
+                                  Coordinate srcPtr,Coordinate dstPtr) {
+        int xCost = routerPtr.xCost;
+        int yCost = routerPtr.yCost;
+        int zCost = routerPtr.zCost;
+
+        /* 
+         * Potential Optimization: Make 'src' the one closet to edge.
+         * This will likely decrease the area of the emitted wave.
+         */
+
+        queuePtr.queue_clear();
+
+        int srcGridPointIndex = myGridPtr.getPointIndex(srcPtr.x,srcPtr.y,srcPtr.z);
+
+        queuePtr.queue_push(srcGridPointIndex);
+
+        myGridPtr.setPoint(srcPtr.x,srcPtr.y,srcPtr.z,0);
+        myGridPtr.setPoint(dstPtr.x,dstPtr.y,dstPtr.z,GRID_POINT_EMPTY);
+        int dstGridPointIndex = myGridPtr.getPointIndex(dstPtr.x,dstPtr.y,dstPtr.z);
+        boolean isPathFound = false;
+       int height = myGridPtr.height;
+       int width = myGridPtr.width;
+       int area = height * width;
+        while (!queuePtr.queue_isEmpty()) {
+            int gridPointIndex = queuePtr.queue_pop();
+
+            if(gridPointIndex == dstGridPointIndex) {
+             isPathFound = true;
+             break;
+            }
+           
+           int z = gridPointIndex / area;
+           int index2d = gridPointIndex % area;
+           int y = index2d / width;
+           int x = index2d % width;        
+           int value = myGridPtr.points_unaligned[x][y][z];
+           
+            /*
+             * Check 6 neighbors
+             *
+             * Potential Optimization: Only need to check 5 of these
+             */
+           PexpandToNeighbor(myGridPtr, x+1, y,   z,   (value + xCost), queuePtr);
+           PexpandToNeighbor(myGridPtr, x-1, y,   z,   (value + xCost), queuePtr);
+           PexpandToNeighbor(myGridPtr, x, y+1,   z,   (value + yCost), queuePtr);
+           PexpandToNeighbor(myGridPtr, x, y-1,   z,   (value + yCost), queuePtr);   
+           PexpandToNeighbor(myGridPtr, x, y,   z+1,   (value + zCost), queuePtr);
+           PexpandToNeighbor(myGridPtr, x, y,   z-1,   (value + zCost), queuePtr);
+           
+        } /* iterate over work queue */
+       
+        return isPathFound;
+    }
+            
+            
+/* ============================================================================
+ * traceToNeighbor
+ * ============================================================================
+ */
+    private void traceToNeighbor(Grid myGridPtr,
+                                 Point currPtr,
+                                 Point movePtr,
+                                 boolean useMomentum,
+                                 int bendCost,
+                                 Point nextPtr)
+    {
+      int x = currPtr.x + movePtr.x;
+      int y = currPtr.y + movePtr.y;
+      int z = currPtr.z + movePtr.z;
+
+        if (myGridPtr.isPointValid(x,y,z) &&
+                !myGridPtr.isPointEmpty(x,y,z) &&
+                !myGridPtr.isPointFull(x,y,z))
+        {
+            int value = myGridPtr.getPoint(x,y,z);
+            int b = 0;
+            
+            if (useMomentum && (currPtr.momentum != movePtr.momentum)) {
+                b = bendCost;
+            }
+            if ((value + b) <= nextPtr.value) { /* '=' favors neighbors over current */
+                nextPtr.x = x;
+                nextPtr.y = y;
+                nextPtr.z = z;
+                nextPtr.value = value;
+                nextPtr.momentum = movePtr.momentum;
+            }
+        }
+    }
+/* =============================================================================
+ * PdoTraceback
+ * =============================================================================
+ */
+
+    private Vector_t PdoTraceback(Grid myGridPtr,
+                                  Coordinate dstPtr, int bendCost) {
+        Vector_t pointVectorPtr = Vector_t.vector_alloc(1);
+
+        Point next = new Point();
+        next.x = dstPtr.x;
+        next.y = dstPtr.y;
+        next.z = dstPtr.z;
+        next.value = myGridPtr.getPoint(next.x,next.y,next.z);
+        next.momentum = MOMENTUM_ZERO;
+
+        while(true) {
+            int gridPointIndex = myGridPtr.getPointIndex(next.x,next.y,next.z);
+            pointVectorPtr.vector_pushBack(new Integer(gridPointIndex));
+            myGridPtr.setPoint(next.x,next.y,next.z,GRID_POINT_FULL);
+
+            /* Check if we are done */
+            if (next.value == 0) {
+                break;
+            }
+            Point curr = new Point();
+            curr.x = next.x;
+            curr.y = next.y;
+            curr.z = next.z;
+            curr.value = next.value;
+            curr.momentum = next.momentum;
+
+            /*
+             * Check 6 neibors
+             */
+
+            traceToNeighbor(myGridPtr,curr,MOVE_POSX,true, bendCost, next);
+            traceToNeighbor(myGridPtr,curr,MOVE_POSY,true, bendCost, next);   
+            traceToNeighbor(myGridPtr,curr,MOVE_POSZ,true, bendCost, next);
+            traceToNeighbor(myGridPtr,curr,MOVE_NEGX,true, bendCost, next); 
+            traceToNeighbor(myGridPtr,curr,MOVE_NEGY,true, bendCost, next);           
+            traceToNeighbor(myGridPtr,curr,MOVE_NEGZ,true, bendCost, next);          
+            /* 
+             * Because of bend costs, none of the neighbors may appear to be closer.
+             * In this case, pick a neighbor while ignoring momentum.
+             */
+
+
+            
+            if ((curr.x == next.x) &&
+                (curr.y == next.y) &&
+                (curr.z == next.z)) {
+                next.value = curr.value;
+                traceToNeighbor(myGridPtr,curr,MOVE_POSX,false, bendCost, next);
+                traceToNeighbor(myGridPtr,curr,MOVE_POSY,false, bendCost, next);
+                traceToNeighbor(myGridPtr,curr,MOVE_POSZ,false, bendCost, next);
+                traceToNeighbor(myGridPtr,curr,MOVE_NEGX,false, bendCost, next);
+                traceToNeighbor(myGridPtr,curr,MOVE_NEGY,false, bendCost, next);
+                traceToNeighbor(myGridPtr,curr,MOVE_NEGZ,false, bendCost, next);
+                
+                if ((curr.x == next.x) &&
+                    (curr.y == next.y) &&
+                    (curr.z == next.z)) {
+                    System.out.println("Dead");
+                    return null;
+                }
+            }
+        }
+
+        return pointVectorPtr;
+    }
+
+/* =============================================================================
+ * router_solve
+ * =============================================================================
+ * void router_solve (void* argPtr);
+ */
+    public static void solve(Object argPtr) 
+    {
+        // TM_THREAD_ENTER();
+        //
+        Solve_Arg routerArgPtr = (Solve_Arg) argPtr;
+        Router routerPtr = routerArgPtr.routerPtr;
+        Maze mazePtr = routerArgPtr.mazePtr;
+        Vector_t myPathVectorPtr = Vector_t.vector_alloc(1);
+
+        Queue_t workQueuePtr = mazePtr.workQueuePtr;
+        Grid gridPtr = mazePtr.gridPtr;
+        Grid myGridPtr = Grid.scratchalloc(gridPtr.width,gridPtr.height,gridPtr.depth);
+        int bendCost = routerPtr.bendCost;
+        Queue_Int myExpansionQueuePtr = Queue_Int.queue_alloc(-1);
+
+        /*
+         * Iterate over work list to route each path. This involves an
+         * 'expansion' and 'tracback' phase for each source/destination pair.
+         */
+        while(true) {
+            Pair coordinatePairPtr;
+            
+            // TM_BEGIN();
+                if(workQueuePtr.queue_isEmpty()) {
+                    coordinatePairPtr = null;
+                } else {
+                    coordinatePairPtr = (Pair)workQueuePtr.queue_pop();
+                }
+            // TM_END();
+            //
+            
+            if (coordinatePairPtr == null) {
+                break;
+            }
+
+            Coordinate srcPtr = (Coordinate)coordinatePairPtr.first;
+            Coordinate dstPtr = (Coordinate)coordinatePairPtr.second;
+
+//            System.out.println("SRC x = " + srcPtr.x + "  y = " + srcPtr.y + " z = " +srcPtr.z);
+            
+            boolean success = false;
+            Vector_t pointVectorPtr = null;
+           boolean retry=true;
+
+            // TM_BEGIN();
+           while(retry) {
+             retry=false;
+               Grid.copy(myGridPtr, gridPtr); /* ok if not most up-to-date */
+               if(routerPtr.PdoExpansion(routerPtr,myGridPtr,myExpansionQueuePtr,srcPtr,dstPtr)) {
+                 pointVectorPtr = routerPtr.PdoTraceback(myGridPtr,dstPtr,bendCost);
+                 if (pointVectorPtr != null) {
+                   if (gridPtr.TM_addPath(pointVectorPtr)) {
+                     pointVectorPtr=null;
+                     retry=true;
+                   } else
+                     success=true;
+                 }
+               }
+           }
+           
+            if(success) {
+                boolean status = myPathVectorPtr.vector_pushBack(pointVectorPtr);
+                
+            }
+        }
+
+        /*
+         * Add my paths to global list
+         */
+        List_t pathVectorListPtr = routerArgPtr.pathVectorListPtr;
+
+            pathVectorListPtr.insert(myPathVectorPtr);
+
+        myGridPtr = null;
+        myExpansionQueuePtr = null;
+//        System.out.println("Final Grid: ");
+//        gridPtr.print();
+        
+        // TM_THREAD_EXIT();
+    }
+}
+/* =============================================================================
+ *
+ * End of router.java
+ * 
+ * =============================================================================
+ */
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Solve_arg.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Solve_arg.java
new file mode 100644 (file)
index 0000000..27df282
--- /dev/null
@@ -0,0 +1,15 @@
+
+
+    public class Solve_Arg {
+        Router routerPtr;
+        Maze mazePtr;
+        List_t pathVectorListPtr;
+
+        public Solve_Arg(Router r,Maze m,List_t l)
+        {
+            routerPtr = r;
+            mazePtr = m;
+            pathVectorListPtr = l;
+        }
+    }
+
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Vector_t.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/Vector_t.java
new file mode 100644 (file)
index 0000000..5132241
--- /dev/null
@@ -0,0 +1,140 @@
+public class Vector_t {
+  int size;
+  int capacity;
+  Object[] elements;
+//  QuickSort qsort;
+
+  public Vector_t() {
+//    qsort = new QuickSort();
+  }
+
+  /* =============================================================================
+   * Vector_alloc
+   * -- Returns null if failed
+   * =============================================================================
+   */
+  public static Vector_t vector_alloc (int initCapacity) {
+    int capacity = Math.imax(initCapacity, 1);
+    Vector_t vectorPtr = new Vector_t();
+    vectorPtr.capacity = capacity;
+    vectorPtr.elements = new Object[capacity];
+    return vectorPtr;
+  }
+
+  /* =============================================================================
+   * Vector_free
+   * =============================================================================
+   */
+  public void
+    vector_free ()
+    {
+      elements = null;
+    }
+
+  /* =============================================================================
+   * Vector_at
+   * -- Returns null if failed
+   * =============================================================================
+   */
+  public Object vector_at (int i) {
+    return (elements[i]);
+  }
+
+
+  /* =============================================================================
+   * Vector_pushBack
+   * -- Returns false if fail, else true
+   * =============================================================================
+   */
+  public boolean vector_pushBack (Object dataPtr) {
+    if (size == capacity) {
+      int newCapacity = capacity * 2;
+      Object[] newElements = new Object[newCapacity];
+
+      //void** newElements = (void**)malloc(newCapacity * sizeof(void*));
+      capacity = newCapacity;
+      for (int i = 0; i < size; i++) {
+        newElements[i] = elements[i];
+      }
+      elements = null;
+      elements = newElements;
+    }
+
+    elements[size++] = dataPtr;
+
+    return true;
+  }
+
+  /* =============================================================================
+   * Vector_popBack
+   * -- Returns null if fail, else returns last element
+   * =============================================================================
+   */
+  public Object
+    vector_popBack ()
+    {
+      if (size < 1) {
+        return null;
+      }
+
+      return (elements[--(size)]);
+    }
+
+  /* =============================================================================
+   * Vector_getSize
+   * =============================================================================
+   */
+  public int
+    vector_getSize ()
+    {
+      return (size);
+    }
+
+  /* =============================================================================
+   * Vector_clear
+   * =============================================================================
+   */
+  public void
+    vector_clear ()
+    {
+      size = 0;
+    }
+  
+  /* =============================================================================
+   * Vector_sort
+   * =============================================================================
+   *
+  public void
+    vector_sort ()
+    {
+      //qsort.sort(elements, 0, (elements.length - 1));
+      qsort.sort(elements);
+      //qsort(elements, size, 4, compare);
+    }
+
+  * =============================================================================
+   * Vector_copy
+   * =============================================================================
+   */
+  public static boolean
+    vector_copy (Vector_t dstVectorPtr, Vector_t srcVectorPtr)
+    {
+      int dstCapacity = dstVectorPtr.capacity;
+      int srcSize = srcVectorPtr.size;
+      if (dstCapacity < srcSize) {
+        int srcCapacity = srcVectorPtr.capacity;
+        Object[] elements = new Object[srcCapacity];
+        dstVectorPtr.elements = null;
+        dstVectorPtr.elements = elements;
+        dstVectorPtr.capacity = srcCapacity;
+      }
+
+      for(int i = 0; i< srcSize; i++) {
+        dstVectorPtr.elements[i] = srcVectorPtr.elements[i];
+      }
+
+      dstVectorPtr.size = srcSize;
+
+      return true;
+    }
+}
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/extractLines b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/Original/Normal_Java/extractLines
new file mode 100644 (file)
index 0000000..c75e572
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+lines=$(grep -n "#" $1 | cut -d: -f1 | sed '1q')
+sed '/^#/d' $1 > ttt$1
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/CoordPathWrapper.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/CoordPathWrapper.java
new file mode 100644 (file)
index 0000000..790681c
--- /dev/null
@@ -0,0 +1,12 @@
+
+public class CoordPathWrapper {
+       Pair coordinatePair;
+       Vector_t pathVector;
+
+       public CoordPathWrapper(Pair coordinatePairPtr, Vector_t path) {
+               coordinatePair = coordinatePairPtr;
+               pathVector = path;
+                       
+       }
+
+}
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Coordinate.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Coordinate.java
new file mode 100644 (file)
index 0000000..a9c9c54
--- /dev/null
@@ -0,0 +1,175 @@
+/* =============================================================================
+ *
+ * coordinate.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.
+ *
+ * =============================================================================
+ */
+
+import java.lang.Math;
+
+public class Coordinate {
+
+    public int x;
+    public int y;
+    public int z;
+
+    public Coordinate() {}
+
+
+    // coordiate_alloc will be constructor
+    // coordinate_t* coordinate_alloc(long x, long y, long z)
+    public Coordinate(int x,int y,int z) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+    }
+
+    public Coordinate alloc(int x,int y,int z) {
+        Coordinate c = new Coordinate(x,y,z);
+
+        return c;
+    }
+
+    
+    // deallocate memory
+    // may not need
+    //  coordinate_free
+
+    /*========================================================
+    // coordinate_isEqual
+    ==========================================================*/
+    public boolean isEqual(Coordinate a,Coordinate b) 
+    {
+        if((a.x == b.x) && (a.y == b.y) && (a.z == b.z))
+            return true;
+        
+        return false;
+    }
+
+    /*==========================================================
+      *
+      * getPairDistance
+      *
+      *========================================================*/   
+    private double getPairDistance(Pair p)
+    {
+        Coordinate a = (Coordinate)p.first;
+        Coordinate b = (Coordinate)p.second;
+        int dx = a.x - b.x;
+        int dy = a.y - b.y;
+        int dz = a.z - b.z;
+        int dx2 = dx* dx;
+        int dy2 = dy* dy;
+        int dz2 = dz* dz;
+
+        return Math.sqrt((double)(dx2+dy2+dz2));
+    }
+
+
+    /*================================================
+    // coordinat_ comparePair
+     * -- For sorting in list of source/destination pairs
+     * -- Route longer paths first so they are more likely to suceed
+     
+    *================================================*/
+    public int comparePair(final Object a,final Object b) 
+    {
+        double aDistance = getPairDistance((Pair)a);
+        double bDistance = getPairDistance((Pair)b);
+
+        if(aDistance < bDistance) {
+            return 1;
+        } else if(aDistance > bDistance) {
+            return -1;
+        }
+
+        return 0;
+    }
+
+    /*=======================================================
+      * coordinate_areAdjacent
+      *=======================================================*/
+
+    public boolean areAdjacent(Coordinate a,Coordinate b) 
+    {
+        int dx = a.x - b.x;
+        int dy = a.y - b.y;
+        int dz = a.z - b.z;
+        int dx2 = dx * dx;
+        int dy2 = dy * dy;
+        int dz2 = dz * dz;
+
+        return (((dx2 + dy2 + dz2) == 1) ? true : false);
+    }
+    }
+
+    /*=====================================================
+      * 
+      * End of Coordinate
+      *
+      *====================================================*/
+    
+    
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Grid.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Grid.java
new file mode 100644 (file)
index 0000000..b609e81
--- /dev/null
@@ -0,0 +1,287 @@
+/* =============================================================================
+ *
+ * grid.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 Grid {
+    public int width;
+    public int height;
+    public int depth;
+    public int[][][] points_unaligned;
+    
+    public static int GRID_POINT_FULL;
+    public static int GRID_POINT_EMPTY;
+
+    public Grid() 
+    {
+       GRID_POINT_FULL = -2;
+       GRID_POINT_EMPTY = -1;
+    }
+
+    
+/* =============================================================================
+ * grid_alloc
+ * =============================================================================
+    grid_t* grid_alloc (long width, long height, long depth);
+
+    well... need to implement
+    got stuck
+*/
+  public Grid alloc(int width,int height,int depth) {
+    Grid grid = new Grid();
+    
+    grid.width = width;
+    grid.height = height;
+    grid.depth = depth;
+    
+    int[][][] points_unaligned = new int[width][height][depth];
+    
+    
+    for(int i=0;i<width;i++)
+      for(int j=0;j<height;j++)
+         for(int k=0;k<depth;k++)
+                 points_unaligned[i][j][k]= GRID_POINT_EMPTY;
+    
+    grid.points_unaligned = points_unaligned;
+    
+    return grid;         
+  }
+
+  
+  //What does scratchalloc do?
+  public Grid scratchalloc(int width,int height,int depth) {
+    Grid grid = /*scratch */ new Grid();
+    grid.width = width;
+    grid.height = height;
+    grid.depth = depth;
+    int[][][] points_unaligned = /*scratch*/ new int[width][height][depth];
+    grid.points_unaligned = points_unaligned;
+    return grid;         
+  }
+
+
+
+/* =============================================================================
+ * grid_copy
+ * =============================================================================
+    void grid_copy (grid_t* dstGridPtr, grid_t* srcGridPtr);
+ */
+  public void copy(Grid dstGridPtr,Grid srcGridPtr) {
+    if((srcGridPtr.width == dstGridPtr.width) ||
+       (srcGridPtr.height == dstGridPtr.height) ||
+       (srcGridPtr.depth == dstGridPtr.depth)) 
+    {   
+      deepArrayCopy(dstGridPtr.points_unaligned, srcGridPtr.points_unaligned);
+    }      
+  }
+  //Array copy function added to replace System.deepArrayCopy in original 
+  //assumes they are of the same size
+  private void deepArrayCopy(int[][][] dst, int[][][] src)
+  {
+         for(int i = 0; i < src.length; i++)
+                 for(int j = 0; j < src[i].length; j++)
+                         for(int k = 0; k < src[i][j].length; k++)
+                                 dst[i][j][k] = src[i][j][k];
+  }
+
+/* =============================================================================
+ * grid_isPointValid
+ * =============================================================================
+ bool_t grid_isPointValid (grid_t* gridPtr, long x, long y, long z);
+ */
+  public boolean isPointValid(int x,int y,int z) {
+    return x>=0 && x< width && y>=0 && y<height && z>=0 && z<depth;
+  }
+
+
+  public int getPoint(int x,int y,int z) {
+    return this.points_unaligned[x][y][z];
+  }
+
+
+/* =============================================================================
+ * grid_isPointEmpty
+ * =============================================================================
+ bool_t grid_isPointEmpty (grid_t* gridPtr, long x, long y, long z); {
+ */
+
+  public boolean isPointEmpty(int x,int y,int z) {
+    return points_unaligned[x][y][z]==GRID_POINT_EMPTY;
+  }
+
+
+
+/* =============================================================================
+ * grid_isPointFull
+ * =============================================================================
+ bool_t grid_isPointFull (grid_t* gridPtr, long x, long y, long z);
+ */
+  public boolean isPointFull(int x,int y,int z) {
+    return points_unaligned[x][y][z]==GRID_POINT_FULL;
+  }
+
+
+/* =============================================================================
+ * grid_setPoint
+ * =============================================================================
+ void grid_setPoint (grid_t* gridPtr, long x, long y, long z, long value);
+ */
+  public void setPoint(int x,int y,int z,int value) {
+    points_unaligned[x][y][z] = value;
+  }
+
+
+/* =============================================================================
+ * grid_addPath
+ * =============================================================================
+void grid_addPath (grid_t* gridPtr, vector_t* pointVectorPtr);
+*/
+  public void addPath(Vector_t pointVectorPtr) {
+    int i;
+    int n = pointVectorPtr.vector_getSize();
+    
+    for(i = 0; i < n; i++) {
+      Coordinate coordinatePtr = (Coordinate)pointVectorPtr.vector_at(i);
+      int x = coordinatePtr.x;
+      int y = coordinatePtr.y;
+      int z = coordinatePtr.z;
+
+      points_unaligned[x][y][z]=GRID_POINT_FULL;
+    }
+  }
+
+  //True is fail, false is success.
+  public boolean TM_addPath(Vector_t pointVectorPtr) {
+    int i;
+    int n = pointVectorPtr.vector_getSize();
+
+    int height = this.height;
+    int width = this.width;
+    int area = height * width;
+    boolean dowrites=true;
+    
+    for(i = 1; i < (n-1); i++) {
+      int gridPointIndex = ((Integer)(pointVectorPtr.vector_at(i))).intValue();
+      int z = gridPointIndex / area;
+      int index2d = gridPointIndex % area;
+      int y = index2d / width;
+      int x = index2d % width;        
+      if (points_unaligned[x][y][z] != GRID_POINT_EMPTY) {
+         dowrites=false;
+      }
+    }
+
+    for(i = 1; i < (n-1); i++) {
+      int gridPointIndex = ((Integer)(pointVectorPtr.vector_at(i))).intValue();
+      int z = gridPointIndex / area;
+      int index2d = gridPointIndex % area;
+      int y = index2d / width;
+      int x = index2d % width;
+      int[] array=points_unaligned[x][y];
+      if (dowrites) array[z] = GRID_POINT_FULL;
+    }
+    return !dowrites;
+  }
+
+  public int getPointIndex(int x,int y,int z) {
+    return ((z * height) + y) * width + x;
+  }
+
+  
+  public void print() {
+    int width  = this.width;
+    int height = this.height;
+    int depth  = this.depth;
+
+    for (int z = 0; z < depth; z++) {
+      System.out.println("[z ="+z+"]");
+      for (int x = 0; x < width; x++) {
+       for (int y = 0; y < height; y++) {
+         String str=String.valueOf(points_unaligned[x][y][z]);
+         for(int sp=0; sp<(4-str.length());sp++)
+           System.out.print(" ");
+         System.out.print(str);
+       }
+       System.out.println("");
+      }
+      System.out.println("");
+    }
+  }
+}
+
+
+/* =============================================================================
+ *
+ * End of grid.c
+ *
+ * =============================================================================
+ */
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Labyrinth.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Labyrinth.java
new file mode 100644 (file)
index 0000000..efe8c5c
--- /dev/null
@@ -0,0 +1,239 @@
+/* =============================================================================
+ *
+ * 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;
+    int numThread;
+    int bendCost;
+    int xCost;
+    int yCost;
+    int zCost;
+
+
+    // For threads
+    int threadID;
+    Solve_Arg routerArg;
+    
+    //For rblocks
+    static int global_workload;
+
+    private void setDefaultParams() {
+
+        /* default values */
+        global_inputFile = null;
+        global_doPrint = false;
+        bendCost = 1;
+        xCost = 1;
+        yCost = 1;
+        zCost = 2;
+        numThread = 1;
+        
+        global_workload = 100;
+    }
+
+    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 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");
+        System.out.println("    x <INT>     x movement cost");
+        System.out.println("    y <INT>     y movement cost");
+        System.out.println("    z <INT>     z movement cost");
+        System.out.println("    w <INT>     Workload per rBlock");
+    }
+        
+
+    public static void main(String[] argv) 
+    {
+        /*
+         * Initailization
+         */
+       Maze maze = new Maze();
+       Router router = new Router();
+        Labyrinth labyrinth = new Labyrinth(argv);
+        
+        Maze mazePtr = maze.alloc();
+
+        int numPathToRoute =  mazePtr.readMaze(labyrinth.global_inputFile);
+        
+        Router routerPtr = router.alloc(labyrinth.xCost,labyrinth.yCost,
+                                        labyrinth.zCost,labyrinth.bendCost);
+
+        List_t list_t = new List_t();
+        List_t pathVectorListPtr = list_t.alloc(0);     // list_t.alloc(null)
+        Solve_Arg routerArg = new Solve_Arg(routerPtr,mazePtr,pathVectorListPtr, global_workload);
+
+        /* Create and start thread */
+        long start = System.currentTimeMillis();
+        routerPtr.solve(routerArg);        
+
+        /* End of Solve */
+        long finish = System.currentTimeMillis();
+        long diff=finish-start;
+        System.out.println("TIME= " + diff);
+
+
+        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 = (finish-start)/1000.0;
+
+        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
+ *
+ * =============================================================================
+ */
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/List_Iter.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/List_Iter.java
new file mode 100644 (file)
index 0000000..351e80d
--- /dev/null
@@ -0,0 +1,38 @@
+public class List_Iter {
+    List_Node itPtr;
+
+    /* =============================================================================
+     * list_iter_reset
+     * =============================================================================
+       void list_iter_reset (list_iter_t* itPtr, list_t* listPtr);
+    */
+     public List_Iter() {
+         itPtr = null;
+     }
+        
+     public void reset(List_t listPtr) 
+     {
+         itPtr = listPtr.head;
+     }
+
+    /* =============================================================================
+     * list_iter_hasNext
+     * =============================================================================
+     * bool_t list_iter_hasNext (list_iter_t* itPtr, list_t* listPtr);
+     */
+     public boolean hasNext(List_t listPtr) {
+         return (itPtr.nextPtr != null)? true : false;
+     }
+
+    /* =============================================================================
+     * list_iter_next
+     * =============================================================================
+     * void* list_iter_next (list_iter_t* itPtr, list_t* listPtr);
+     */
+     public Object next(List_t listPtr) 
+     {
+         itPtr = itPtr.nextPtr;
+         return itPtr.dataPtr; 
+     }
+}
+
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/List_Node.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/List_Node.java
new file mode 100644 (file)
index 0000000..806baa1
--- /dev/null
@@ -0,0 +1,10 @@
+
+public class List_Node {
+    Object dataPtr;
+    List_Node nextPtr;
+
+    public List_Node() {
+        dataPtr = null;
+        nextPtr = null;
+    }
+}
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/List_t.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/List_t.java
new file mode 100644 (file)
index 0000000..3b73d64
--- /dev/null
@@ -0,0 +1,307 @@
+/* =============================================================================
+ *
+ * List_t.java
+ * -- Sorted singly linked list
+ * -- Options: duplicate allowed  
+ *    (DLIST_NO_DUPLICATES) is no implemented yet (default: allow duplicates)
+ *
+ * =============================================================================
+ *
+ * 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 List_t {
+
+    public List_Node head;
+    boolean isCoordinate;
+    int size;
+
+    public List_t() {
+        head = new List_Node();
+    }
+
+
+    /* =======================================================================
+     * allocNode
+     * -- Returns null on failure
+     * =======================================================================
+     */
+    private List_Node allocNode(Object dataPtr) 
+    {
+        List_Node nodePtr = new List_Node();
+
+
+        nodePtr.dataPtr = dataPtr;
+        nodePtr.nextPtr = null;
+
+        return nodePtr;
+    }
+        
+    
+/* =============================================================================
+ * list_alloc
+ * -- If NULL passed for 'compare' function, will compare data pointer addresses
+ * -- Returns NULL on failure
+ * =============================================================================
+ * list_t* list_alloc (long (*compare)(const void*, const void*));
+ *
+ *
+ */
+
+    public List_t alloc(int isCoordinate) 
+    {
+        List_t listPtr = new List_t();
+
+
+        listPtr.head.dataPtr = null;
+        listPtr.head.nextPtr = null;
+        listPtr.size = 0;
+        
+        listPtr.isCoordinate = (isCoordinate==1)?true:false;
+
+        return listPtr;
+    }
+    
+/* =============================================================================
+ * list_free
+ * -- If NULL passed for 'compare' function, will compare data pointer addresses
+ * -- Returns NULL on failure
+ * =============================================================================
+ * void list_free (list_t* listPtr);
+ */
+    public void free(List_t listPtr) 
+    {
+        listPtr = null;
+    }
+
+//    privae freeList
+
+/* =============================================================================
+ * list_isEmpty
+ * -- Return TRUE if list is empty, else FALSE
+ * =============================================================================
+ * bool_t list_isEmpty (list_t* listPtr);
+ */
+    public boolean isEmpty() 
+    {
+        return (head.nextPtr == null);
+    }
+
+/* =============================================================================
+ * list_getSize
+ * -- Returns size of list
+ * =============================================================================
+ * long list_getSize (list_t* listPtr);
+ */
+    public int getSize() {
+        return size;
+    }
+
+/* =============================================================================
+ * findPrevious
+ * =============================================================================
+ * void* list_find (list_t* listPtr, void* dataPtr);
+ */                                                                             
+    private List_Node findPrevious(Object dataPtr) 
+    {
+        List_Node prevPtr = head;
+        List_Node nodePtr = prevPtr.nextPtr;
+
+        for(; nodePtr != null; nodePtr = nodePtr.nextPtr) {
+            if (compare(nodePtr.dataPtr,dataPtr) >= 0) {
+                return prevPtr;
+            }
+            prevPtr = nodePtr;
+        }
+
+        return prevPtr;
+    }
+
+    /* =============================================================================
+     * list_find
+     * -- Returns NULL if not found, else returns pointer to data
+     * =============================================================================
+     * void* list_find (list_t* listPtr, void* dataPtr);
+     */
+    public Object find(Object dataPtr) {
+        List_Node nodePtr;
+        List_Node prevPtr = findPrevious(dataPtr);
+
+        nodePtr = prevPtr.nextPtr;
+
+        if((nodePtr == null) ||
+                (compare(nodePtr.dataPtr,dataPtr) != 0)) {
+            return null;
+        }
+
+        return (nodePtr.dataPtr);
+    }
+
+    public int compare(Object obj1,Object obj2) 
+    {
+       Coordinate coordinate  = new Coordinate();
+        if(isCoordinate)
+        {
+            return coordinate.comparePair(obj1,obj2);
+        }
+        else 
+            return compareObject(obj1,obj2);
+    }
+
+/* =============================================================================
+ * list_insert
+ * -- Return TRUE on success, else FALSE
+ * =============================================================================
+ * bool_t list_insert (list_t* listPtr, void* dataPtr);
+ */
+    public boolean insert(Object dataPtr) {
+        List_Node prevPtr;
+        List_Node nodePtr;
+        List_Node currPtr;
+
+        prevPtr = findPrevious(dataPtr);
+        currPtr = prevPtr.nextPtr;
+
+        nodePtr = allocNode(dataPtr);
+        if (nodePtr == null) {
+            return false;
+        }
+
+        nodePtr.nextPtr = currPtr;
+        prevPtr.nextPtr = nodePtr;
+        size++;
+
+        return true;
+    }
+        
+    
+/* =============================================================================
+ * list_remove
+ * -- Returns TRUE if successful, else FALSE
+ * =============================================================================
+ * bool_t list_remove (list_t* listPtr, void* dataPtr);
+ */
+    public boolean remove(Object dataPtr) 
+    {
+        List_Node prevPtr;
+        List_Node nodePtr;
+
+        prevPtr = findPrevious(dataPtr);
+
+        nodePtr = prevPtr.nextPtr;
+
+        if((nodePtr != null) &&
+            (compare(nodePtr.dataPtr,dataPtr) == 0))
+        {
+            prevPtr.nextPtr = nodePtr.nextPtr;
+            nodePtr.nextPtr = null;
+            nodePtr = null;
+            size--;
+
+            return true;
+        }
+    
+        return false;
+    }
+
+    int compareObject(Object obj1,Object obj2) {
+        return 1;
+    }
+    
+
+/* =============================================================================
+ * list_clear
+ * -- Removes all elements
+ * =============================================================================
+ * void list_clear (list_t* listPtr);
+ */
+    public void clear() {
+        head = new List_Node();
+        size = 0;    
+    }
+
+/* =============================================================================
+ *
+ * End of list.java
+ *
+ * =============================================================================
+ */
+
+ /* Test list */
+
+// public static void main(String[] argv) {
+//     List_t listPtr;
+//     int[] data1 = new int[5];
+//     int[] data2 = new int[6];
+//
+//     int i;
+//
+//     System.out.println("Starting...");
+//        }
+//
+}
+
+
+     
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Math.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Math.java
new file mode 100644 (file)
index 0000000..7e6a59f
--- /dev/null
@@ -0,0 +1,136 @@
+public class Math {
+
+  public static double setPI() {
+    double PI = 3.14159265358979323846;
+    return PI;
+  }
+
+  // an alias for setPI()
+  public static double PI() {
+    double PI = 3.14159265358979323846;
+    return PI;
+  }
+
+  public static int abs(int x) {
+    if (x < 0) {
+      return -x;
+    } else {
+      return x;
+    }
+  }
+
+  public static double fabs(double x) {
+    if (x < 0) {
+      return -x;
+    } else {
+      return x;
+    }
+  }
+
+  public static double abs(double x) {
+    if (x < 0) {
+      return -x;
+    } else {
+      return x;
+    }
+  }
+
+  public static float abs(float a) {
+    if (a<0)
+      return -a;
+    else return a;
+  }
+
+  public static double max(double a, double b) {
+    if(a == b)
+      return a;
+    if(a > b) {
+      return a;
+    } else {
+      return b;
+    }
+  }
+
+  public static int max(int a, int b) {
+    if(a == b)
+      return a;
+    if(a > b) {
+      return a;
+    } else {
+      return b;
+    }
+  }
+
+  public static int imax(int a, int b) {
+    if(a == b)
+      return a;
+    if(a > b) {
+      return a;
+    } else {
+      return b;
+    }
+  }
+
+  public static int imin(int a, int b) {
+    if(a == b)
+      return a;
+    if(a > b) {
+      return b;
+    } else {
+      return a;
+    }
+  }
+
+  /** sqrt(a^2 + b^2) without under/overflow. **/
+  public static double hypot(double a, double b) {
+    double r;
+    if (fabs(a) > fabs(b)) {
+      r = b/a;
+      r = fabs(a)*sqrt(1+r*r);
+    } else if (b != 0) {
+      r = a/b;
+      r = fabs(b)*sqrt(1+r*r);
+    } else {
+      r = 0.0;
+    }
+    return r;
+  }
+
+  public static double rint(double x) {
+    double y = ceil(x);
+    double d = y - x;
+    if( d == 0.5 ) {
+      if( ((int)y)%2 == 0 ) {
+       return y;
+      } else {
+       return y - 1.0;
+      }
+    } else if( d < 0.5 ) {
+      return y;
+    }
+    return y - 1.0;
+  }
+
+  public static native double sin(double a);
+  public static native double cos(double a);
+  public static native double asin(double a);
+  public static native double acos(double a);
+  public static native double tan(double a);
+  public static native double atan(double a);
+  public static native double atan2(double a, double b);
+  public static native double exp(double a);
+  public static native double sqrt(double a);
+  public static native double log(double a);
+  public static native double pow(double a, double b);
+
+  public static native double ceil(double a);
+  public static native double floor(double a);
+
+  public static native float sinf(float a);
+  public static native float cosf(float a);
+  public static native float expf(float a);
+  public static native float sqrtf(float a);
+  public static native float logf(float a);
+  public static native float powf(float a, float b);
+  public static native float ceilf(float a);
+}
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Maze.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Maze.java
new file mode 100644 (file)
index 0000000..e439d03
--- /dev/null
@@ -0,0 +1,417 @@
+import java.io.File;
+import java.util.Scanner;
+import java.util.StringTokenizer;
+
+/*=============================================================================
+ *
+ * Maze.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 Maze {
+    Grid gridPtr;
+    Queue_t workQueuePtr;
+    Vector_t wallVectorPtr; /* contains source/destination pairs to route */
+    Vector_t srcVectorPtr;  /* obstacles */
+    Vector_t dstVectorPtr;  /* destinations */
+    
+    public int GRID_POINT_FULL;
+    public int GRID_POINT_EMPTY;
+
+    public Maze() 
+    {
+       GRID_POINT_FULL = -2;
+       GRID_POINT_EMPTY = -1;
+    }
+
+
+/* =============================================================================
+ * maze_alloc
+ * =============================================================================
+ maze_t* maze_alloc ();
+ */
+   public Maze alloc() 
+   {
+       Maze mazePtr = new Maze();
+       Vector_t vector_t = new Vector_t();
+       Queue_t queue_t = new Queue_t();
+
+       mazePtr.gridPtr = null;
+       mazePtr.workQueuePtr = queue_t.queue_alloc(1024);
+       mazePtr.wallVectorPtr = vector_t.vector_alloc(1);
+       mazePtr.srcVectorPtr = vector_t.vector_alloc(1);
+       mazePtr.dstVectorPtr = vector_t.vector_alloc(1);
+
+
+       return mazePtr;
+   }
+
+/* =============================================================================
+ * maze_free
+ * =============================================================================
+ void maze_free (maze_t* mazePtr);
+ */
+    public void free(Maze m)
+    {
+        m = null;
+    }    
+
+/* =============================================================================
+ * addToGrid
+ * =============================================================================
+ */
+    private void addToGrid(Grid gridPtr,Vector_t vectorPtr,String type)
+    {
+        int i;
+        int n = vectorPtr.vector_getSize();
+
+        for(i = 0; i < n; i++) {
+            Coordinate coordinatePtr = (Coordinate)vectorPtr.vector_at(i);
+            if(!gridPtr.isPointValid(coordinatePtr.x,coordinatePtr.y,coordinatePtr.z))
+            {
+                System.out.println("Error: " + type + " (" + coordinatePtr.x + 
+                                                      ", " + coordinatePtr.y + 
+                                                      ", " + coordinatePtr.z);
+                System.exit(1);
+            }
+        }
+        gridPtr.addPath(vectorPtr);
+    }
+/* =============================================================================
+ * maze_read
+ * -- Return number of path to route
+ * =============================================================================
+ long maze_read (maze_t* mazePtr, char* inputFileName);
+ */
+    public int readMaze(String inputFileName)
+    {
+       //TODO remove TRY
+       try
+       {
+       
+               //Added for mlp compatiability
+               List_t list_t = new List_t();
+               Coordinate coordinate = new Coordinate();
+               Pair pair = new Pair();
+               
+//        FileInputStream in = new FileInputStream(inputFileName);
+               //TODO remove this and uncomment the line above. 
+               Scanner in = new Scanner(new File(inputFileName));
+               
+        /*
+         * Parse input file
+         */
+        int lineNumber = 0;
+        int height = -1;
+        int width = -1;
+        int depth = -1;
+        boolean isParseError = false;
+        List_t workListPtr = list_t.alloc(1); // List.alloc(Coordinate.comparePair);
+        String line;
+
+        //TODO change this back as well
+//      while((line = in.readLine()) != null) {
+        while(in.hasNextLine()){
+            line = in.nextLine();
+        //TODO remove the above
+            
+            String code;
+            int[] xy = new int[6];  // equivalent to x1,y1,z1,x2,y2,z2
+            int numToken = 0;
+            
+            StringTokenizer tok = new StringTokenizer(line);
+
+            if((numToken = tok.countTokens()) < 1 ) {
+                continue;
+            }
+
+            code = tok.nextToken();
+
+            if(code.equals("#")) {
+                /* comment line */
+                continue;
+            }
+            for(int i=0;i<numToken-1;i++) {
+                xy[i] = Integer.parseInt(tok.nextToken());
+            }
+
+            if(code.equals("d")) {
+                  /* dimensions (format: d x y z) */
+                 if(numToken != 4) {
+                    isParseError = true;
+                 }
+                 else {
+                    width = xy[0];
+                    height = xy[1];
+                    depth = xy[2];
+                    if(width < 1 || height < 1 || depth <1)
+                        isParseError = true;
+                 }
+             }else if(code.equals("p")) { /* paths (format: p x1 y1 z1 x2 y2 z2) */
+                if(numToken != 7) {
+                    isParseError = true;
+                }
+                else {
+                    Coordinate srcPtr = coordinate.alloc(xy[0],xy[1],xy[2]);
+                    Coordinate dstPtr = coordinate.alloc(xy[3],xy[4],xy[5]);
+
+                    if(coordinate.isEqual(srcPtr,dstPtr)) {
+                        isParseError = true;
+                    }
+                    else { 
+                        Pair coordinatePairPtr = pair.alloc(srcPtr,dstPtr);
+                        boolean status = workListPtr.insert(coordinatePairPtr);
+                        srcVectorPtr.vector_pushBack(srcPtr);
+                        dstVectorPtr.vector_pushBack(dstPtr);
+                        
+                    }
+                }
+            }else if(code.equals("w")) {
+                     /* walls (format: w x y z) */
+                    if(numToken != 4) {
+                        isParseError = true;
+                    } else {
+                        Coordinate wallPtr = coordinate.alloc(xy[0],xy[1],xy[2]);
+                        wallVectorPtr.vector_pushBack(wallPtr);
+                    }
+            }else { /* error */
+                   isParseError = true;
+            }
+            
+            if(isParseError)  {/* Error */
+                System.out.println("Error: line " + lineNumber + " of " + inputFileName + "invalid");
+                System.exit(1);
+            }
+        }
+        /* iterate over lines in put file */
+      
+        in.close();
+        /* 
+         * Initialize grid contents
+         */
+        if(width < 1 || height < 1 || depth < 1) {
+            System.out.println("Error : Invalid dimensions ( " + width + ", " + height + ", "+ depth + ")");
+            System.exit(1);
+        }
+
+        Grid grid = new Grid();
+        Grid gridPtr = grid.alloc(width,height,depth);
+        this.gridPtr = gridPtr;
+        addToGrid(gridPtr,wallVectorPtr,"wall");
+        addToGrid(gridPtr,srcVectorPtr, "source");
+        addToGrid(gridPtr,dstVectorPtr, "destination");
+        System.out.println("Maze dimensions = " + width + " x " + height + " x " + depth);
+        System.out.println("Paths to route  = " + workListPtr.getSize());
+
+        /*
+         * Initialize work queue
+         */
+        List_Iter it = new List_Iter();
+        it.reset(workListPtr);
+        while(it.hasNext(workListPtr)) {
+            Pair coordinatePairPtr = (Pair)it.next(workListPtr);
+            workQueuePtr.queue_push(coordinatePairPtr);
+        }
+
+        list_t.free(workListPtr);
+
+        return srcVectorPtr.vector_getSize();
+       } //TODO remove this parenthesis (goes with Try) and the below
+       catch(Exception e)
+       {
+               System.out.println("The File is non-existant: " + inputFileName);
+               e.getStackTrace();
+               return -1;
+       }
+    }
+    
+
+/* =============================================================================
+ * maze_checkPaths
+ * =============================================================================
+ bool_t maze_checkPaths (maze_t* mazePtr, list_t* pathListPtr, bool_t doPrintPaths);
+ */
+    public boolean checkPaths(List_t pathVectorListPtr,boolean doPrintPaths)
+    {
+        int i;
+       
+        /* Mark walls */
+        Grid grid = new Grid();
+        Grid testGridPtr = grid.alloc(gridPtr.width,gridPtr.height,gridPtr.depth);
+        testGridPtr.addPath(wallVectorPtr);
+
+        /* Mark sources */
+        int numSrc = srcVectorPtr.vector_getSize();
+//        System.out.println("numSrc = " +numSrc);
+//        System.exit(1);
+        for(i = 0; i < numSrc; i++) {
+            Coordinate srcPtr = (Coordinate)srcVectorPtr.vector_at(i);
+            testGridPtr.setPoint(srcPtr.x,srcPtr.y,srcPtr.z,0);
+        }
+
+        /* Mark destinations */
+        int numdst = dstVectorPtr.vector_getSize();
+        for(i = 0; i < numdst; i++) {
+            Coordinate dstPtr = (Coordinate)dstVectorPtr.vector_at(i);
+            testGridPtr.setPoint(dstPtr.x,dstPtr.y,dstPtr.z,0);
+        }
+
+//        testGridPtr.print();
+
+        /* Make sure path is contiguous and does not overlap */
+        int id = 0;
+        List_Iter it = new List_Iter();
+        it.reset(pathVectorListPtr);
+
+        int height = gridPtr.height;
+        int width = gridPtr.width;
+        int area = height * width;
+
+        while(it.hasNext(pathVectorListPtr)) {
+            Vector_t pathVectorPtr = (Vector_t)it.next(pathVectorListPtr);
+            int numPath = pathVectorPtr.vector_getSize();
+          
+            for(i = 0; i < numPath; i++) {
+                id++;
+                Vector_t pointVectorPtr = (Vector_t)pathVectorPtr.vector_at(i);
+                /* Check start */
+                int prevGridPointIndex = ((Integer)pointVectorPtr.vector_at(0)).intValue();
+
+               int z=prevGridPointIndex/area;
+               int index2d=prevGridPointIndex%area;
+               int y=index2d/width;
+               int x=index2d%width;
+
+                if(testGridPtr.getPoint(x,y,z) != 0) {
+                    return false;
+                }
+
+                Coordinate prevCoordinate = new Coordinate();
+                prevCoordinate.x = x;
+                prevCoordinate.y = y;
+                prevCoordinate.z = z;
+
+                
+                int numPoint = pointVectorPtr.vector_getSize();
+                int j;
+
+                for(j = 1; j< (numPoint - 1) ;j++) { /* no need to check endpoints */
+                    int currGridPointIndex = ((Integer)pointVectorPtr.vector_at(j)).intValue();
+                    Coordinate currCoordinate = new Coordinate();
+
+                   z=currGridPointIndex/area;
+                   index2d=currGridPointIndex%area;
+                   y=index2d/width;
+                   x=index2d%width;
+
+                    currCoordinate.x = x;
+                    currCoordinate.y = y;
+                    currCoordinate.z = z;
+
+                    if(!currCoordinate.areAdjacent(currCoordinate,prevCoordinate)) {
+                        System.out.println("you there?");
+                        return false;
+                    }
+
+                    prevCoordinate = currCoordinate;
+                    int xx = currCoordinate.x;
+                    int yy = currCoordinate.y;
+                    int zz = currCoordinate.z;
+                    if(testGridPtr.getPoint(xx,yy,zz) != GRID_POINT_EMPTY) {
+                        return false;
+                    } else {
+                        testGridPtr.setPoint(xx,yy,zz,id);
+                    }
+                }
+                /* Check end */
+                int lastGridPointIndex = ((Integer)pointVectorPtr.vector_at(j)).intValue();
+               z=lastGridPointIndex/area;
+               index2d=lastGridPointIndex%area;
+               y=index2d/width;
+               x=index2d%width;
+                if(testGridPtr.getPoint(x,y,z) != 0) {
+                    return false;
+                }
+            } /* iterate over pathVector */
+        } /* iterate over pathVectorList */
+
+        if(doPrintPaths) {
+            System.out.println("\nRouted Maze:");
+           testGridPtr.print();
+        }
+
+
+        return true;
+    }
+                    
+ }
+/* =============================================================================
+ *
+ * End of maze.h
+ *
+ * =============================================================================
+ */
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Pair.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Pair.java
new file mode 100644 (file)
index 0000000..ea735f0
--- /dev/null
@@ -0,0 +1,86 @@
+
+
+public class Pair {
+    public Object first;
+    public Object second;
+
+    public Pair() {
+        first = null;
+        second = null;
+    }
+
+
+/* =============================================================================
+ * 
+ * pair constructor
+ * 
+ * pair_t* pair_alloc(void* firstPtr, void* secondPtr);
+ * =============================================================================
+ */
+    public Pair alloc(Object first,Object second)
+    {
+        Pair ptr= new Pair();
+        ptr.first = first;
+        ptr.second = second;
+
+        return ptr;
+    }
+
+
+
+/* =============================================================================
+ * Ppair_alloc
+ *
+ * -- Returns NULL if failure
+ * =============================================================================
+ */
+  public Pair Ppair_alloc (Object firstPtr, Object secondPtr) {
+    Pair pairPtr = new Pair();       
+    pairPtr.first = firstPtr;
+    pairPtr.second = secondPtr;
+    return pairPtr;
+  }
+
+
+/* =============================================================================
+ * pair_free
+ * =============================================================================
+ *
+ *  void pair_free (pair_t* pairPtr);
+ *
+ */
+    public void free(Pair pairPtr)
+    {
+        pairPtr = null;
+    }
+
+
+/* =============================================================================
+ * Ppair_free
+ * =============================================================================
+ *
+void Ppair_free (pair_t* pairPtr);
+*/
+
+/* =============================================================================
+ * pair_swap
+ * -- Exchange 'firstPtr' and 'secondPtr'
+ * =============================================================================
+ * void pair_swap (pair_t* pairPtr);
+*/
+    public void swap(Pair pairPtr)
+    {
+        Object tmpPtr = pairPtr.first;
+
+        pairPtr.first = pairPtr.second;
+        pairPtr.second = tmpPtr;
+    }
+
+}    
+
+/* =============================================================================
+ *
+ * End of pair.java
+ *
+ * =============================================================================
+ */
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Point.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Point.java
new file mode 100644 (file)
index 0000000..8905bd5
--- /dev/null
@@ -0,0 +1,25 @@
+
+  public class Point {
+        int x;
+        int y;
+        int z;
+        int value;
+        int momentum;
+
+        public Point() {
+            x = -1;
+            y = -1;
+            z = -1;
+            value = -1;
+            momentum = -1;
+        }
+        
+        public Point(int x,int y, int z,int value, int m) {
+            this.x = x;
+            this.y = y;
+            this.z = z;
+            this.value = value;
+            momentum = m;
+        }
+    }
+
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Queue_Int.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Queue_Int.java
new file mode 100644 (file)
index 0000000..07009fd
--- /dev/null
@@ -0,0 +1,412 @@
+/* =============================================================================
+ *
+ * queue.java
+ *
+ * =============================================================================
+ *
+ * Copyright (C) Stanford University, 2006.  All Rights Reserved.
+ * Author: Chi Cao Minh
+ *
+ * Ported to Java June 2009 Alokika Dash
+ * adash@uci.edu
+ * University of California, Irvine
+ *
+ * =============================================================================
+ * 
+ * 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 Queue_Int {
+  int pop; /* points before element to pop */
+  int push;
+  int capacity;
+  int[] elements;
+
+  private int QUEUE_GROWTH_FACTOR;
+  
+  public Queue_Int() {
+         QUEUE_GROWTH_FACTOR = 2;
+  }
+
+  /* =============================================================================
+   * queue_alloc
+   * =============================================================================
+   */
+  public Queue_Int queue_alloc (int initCapacity)
+  {
+    Queue_Int queuePtr = new Queue_Int();
+
+    int capacity = ((initCapacity < 2) ? 2 : initCapacity);
+    queuePtr.elements = new int[capacity];
+    queuePtr.pop      = capacity - 1;
+    queuePtr.push     = 0;
+    queuePtr.capacity = capacity;
+
+    return queuePtr;
+  }
+
+
+  /* =============================================================================
+   * Pqueue_alloc
+   * =============================================================================
+   */
+  public Queue_Int
+    Pqueue_alloc (int initCapacity)
+    {
+      Queue_Int queuePtr = new Queue_Int();
+
+      int capacity = ((initCapacity < 2) ? 2 : initCapacity);
+      queuePtr.elements = new int[capacity];
+      queuePtr.pop      = capacity - 1;
+      queuePtr.push     = 0;
+      queuePtr.capacity = capacity;
+
+      return queuePtr;
+    }
+
+
+  /* =============================================================================
+   * TMqueue_alloc
+   * =============================================================================
+   */
+  public Queue_Int TMqueue_alloc (int initCapacity)
+  {
+    Queue_Int queuePtr = new Queue_Int();
+
+    int capacity = ((initCapacity < 2) ? 2 : initCapacity);
+    queuePtr.elements = new int[capacity];
+    queuePtr.pop      = capacity - 1;
+    queuePtr.push     = 0;
+    queuePtr.capacity = capacity;
+
+    return queuePtr;
+  }
+
+
+  /* =============================================================================
+   * queue_free
+   * =============================================================================
+   */
+  public void
+    queue_free ()
+    {
+      elements = null;
+    }
+
+
+  /* =============================================================================
+   * Pqueue_free
+   * =============================================================================
+   */
+  public void
+    Pqueue_free ()
+    {
+      elements = null;
+    }
+
+
+  /* =============================================================================
+   * TMqueue_free
+   * =============================================================================
+   */
+  public void
+    TMqueue_free ()
+    {
+      elements = null;
+    }
+
+
+  /* =============================================================================
+   * queue_isEmpty
+   * =============================================================================
+   */
+  public boolean
+    queue_isEmpty ()
+    {
+      return (((pop + 1) % capacity == push) ? true : false);
+    }
+
+
+  /* =============================================================================
+   * queue_clear
+   * =============================================================================
+   */
+  public void
+    queue_clear ()
+    {
+      pop  = capacity - 1;
+      push = 0;
+    }
+
+
+  /* =============================================================================
+   * TMqueue_isEmpty
+   * =============================================================================
+   */
+  public boolean
+    TMqueue_isEmpty (Queue_Int queuePtr)
+    {
+      int pop      = queuePtr.pop;
+      int push     = queuePtr.push;
+      int capacity = queuePtr.capacity;
+
+      return (((pop + 1) % capacity == push) ? true : false);
+    }
+
+
+  /* =============================================================================
+   * queue_push
+   * =============================================================================
+   */
+  public boolean
+    queue_push (int dataPtr)
+    {
+
+      /* Need to resize */
+      int newPush = (push + 1) % capacity;
+      if (newPush == pop) {
+
+        int newCapacity = capacity * QUEUE_GROWTH_FACTOR;
+        int[] newElements = new int[newCapacity];
+
+        int dst = 0;
+        if (pop < push) {
+          int src;
+          for (src = (pop + 1); src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        } else {
+          int src;
+          for (src = (pop + 1); src < capacity; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+          for (src = 0; src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        }
+
+        elements = newElements;
+        pop      = newCapacity - 1;
+        capacity = newCapacity;
+        push = dst;
+        newPush = push + 1; /* no need modulo */
+      }
+
+      elements[push] = dataPtr;
+      push = newPush;
+
+      return true;
+    }
+
+
+  /* =============================================================================
+   * Pqueue_push
+   * =============================================================================
+   */
+  public boolean
+    Pqueue_push (Queue_Int queuePtr, int dataPtr)
+    {
+      int pop      = queuePtr.pop;
+      int push     = queuePtr.push;
+      int capacity = queuePtr.capacity;
+
+
+      /* Need to resize */
+      int newPush = (push + 1) % capacity;
+      if (newPush == pop) {
+
+        int newCapacity = capacity * QUEUE_GROWTH_FACTOR;
+        int[] newElements = new int[newCapacity];
+
+        int dst = 0;
+        int[] elements = queuePtr.elements;
+        if (pop < push) {
+          int src;
+          for (src = (pop + 1); src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        } else {
+          int src;
+          for (src = (pop + 1); src < capacity; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+          for (src = 0; src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        }
+
+        elements = null;
+        queuePtr.elements = newElements;
+        queuePtr.pop      = newCapacity - 1;
+        queuePtr.capacity = newCapacity;
+        push = dst;
+        newPush = push + 1; /* no need modulo */
+
+      }
+
+      queuePtr.elements[push] = dataPtr;
+      queuePtr.push = newPush;
+
+      return true;
+    }
+
+
+  /* =============================================================================
+   * TMqueue_push
+   * =============================================================================
+   */
+  public boolean
+    TMqueue_push (Queue_Int queuePtr, int dataPtr)
+    {
+      int pop      = (queuePtr.pop);
+      int push     = (queuePtr.push);
+      int capacity = (queuePtr.capacity);
+
+
+      /* Need to resize */
+      int newPush = (push + 1) % capacity;
+      if (newPush == pop) {
+        int newCapacity = capacity * QUEUE_GROWTH_FACTOR;
+        int[] newElements = new int[newCapacity];
+
+        int dst = 0;
+        int[] elements = queuePtr.elements;
+        if (pop < push) {
+          int src;
+          for (src = (pop + 1); src < push; src++, dst++) {
+            newElements[dst] = (elements[src]);
+          }
+        } else {
+          int src;
+          for (src = (pop + 1); src < capacity; src++, dst++) {
+            newElements[dst] = (elements[src]);
+          }
+          for (src = 0; src < push; src++, dst++) {
+            newElements[dst] = (elements[src]);
+          }
+        }
+
+        elements = null;
+        queuePtr.elements = newElements;
+        queuePtr.pop      = newCapacity - 1;
+        queuePtr.capacity = newCapacity;
+        push = dst;
+        newPush = push + 1; /* no need modulo */
+
+      }
+
+      int[] elements = queuePtr.elements;
+      elements[push] = dataPtr;
+      queuePtr.push = newPush;
+
+      return true;
+    }
+
+
+  /* =============================================================================
+   * queue_pop
+   * =============================================================================
+   */
+  public int
+    queue_pop ()
+    {
+      int newPop = (pop + 1) % capacity;
+      if (newPop == push) {
+        return 0;
+      }
+
+      int dataPtr = elements[newPop];
+      pop = newPop;
+
+      return dataPtr;
+    }
+
+
+  /* =============================================================================
+   * TMqueue_pop
+   * =============================================================================
+   */
+  public int
+    TMqueue_pop (Queue_Int queuePtr)
+    {
+      int pop      = queuePtr.pop;
+      int push     = queuePtr.push;
+      int capacity = queuePtr.capacity;
+
+      int newPop = (pop + 1) % capacity;
+      if (newPop == push) {
+        return 0;
+      }
+
+      int[] elements = queuePtr.elements;
+      int dataPtr = elements[newPop];
+      queuePtr.pop = newPop;
+
+      return dataPtr;
+    }
+
+  /****
+   * main method for testing
+   **/
+  /*
+     public static void main(String[] args) {
+     testQueue queuePtr = testQueue.queue_alloc(-1);
+     int numData = 4;
+     if(queuePtr.queue_isEmpty())
+     System.out.println("Queue is empty");
+
+     for(int i = 0; i<numData; i++) {
+     System.out.println("Inserting " + i);
+     queuePtr.queue_push(i);
+     }
+
+     for(int i = 0; i<numData; i++) {
+     int val = queuePtr.queue_pop();
+     System.out.println("Removing " + val);
+     }
+
+     if(queuePtr.queue_isEmpty())
+     System.out.println("Queue is empty");
+     }
+     */
+}
+/* =============================================================================
+ *
+ * End of queue.java
+ *
+ * =============================================================================
+ */
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Queue_t.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Queue_t.java
new file mode 100644 (file)
index 0000000..6f642f2
--- /dev/null
@@ -0,0 +1,308 @@
+/* =============================================================================
+ *
+ * queue.java
+ *
+ * =============================================================================
+ *
+ * Copyright (C) Stanford University, 2006.  All Rights Reserved.
+ * Author: Chi Cao Minh
+ *
+ * Ported to Java
+ * Author:Alokika Dash
+ * University of California, Irvine
+ *
+ * =============================================================================
+ * 
+ * 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 Queue_t {
+  int pop; /* points before element to pop */
+  int push;
+  int capacity;
+  Object[] elements;
+  
+  private int QUEUE_GROWTH_FACTOR;
+
+  public Queue_t() {
+         QUEUE_GROWTH_FACTOR = 2;
+  }
+
+  /* =============================================================================
+   * queue_alloc
+   * =============================================================================
+   */
+  public Queue_t queue_alloc (int initCapacity)
+  {
+    Queue_t queuePtr = new Queue_t();
+
+    int capacity = ((initCapacity < 2) ? 2 : initCapacity);
+    queuePtr.elements = new Object[capacity];
+    queuePtr.pop      = capacity - 1;
+    queuePtr.push     = 0;
+    queuePtr.capacity = capacity;
+
+    return queuePtr;
+  }
+
+
+  /* =============================================================================
+   * Pqueue_alloc
+   * =============================================================================
+   */
+  public Queue_t
+    Pqueue_alloc (int initCapacity)
+    {
+      Queue_t queuePtr = new Queue_t();
+
+      int capacity = ((initCapacity < 2) ? 2 : initCapacity);
+      queuePtr.elements = new Object[capacity];
+      queuePtr.pop      = capacity - 1;
+      queuePtr.push     = 0;
+      queuePtr.capacity = capacity;
+
+      return queuePtr;
+    }
+
+  /* =============================================================================
+   * queue_free
+   * =============================================================================
+   */
+  public void
+    queue_free (Queue_t queuePtr)
+    {
+      queuePtr.elements = null;
+      queuePtr = null;
+    }
+
+
+  /* =============================================================================
+   * Pqueue_free
+   * =============================================================================
+   */
+  public void
+    Pqueue_free (Queue_t queuePtr)
+    {
+      queuePtr.elements = null;
+      queuePtr = null;
+    }
+
+
+  /* =============================================================================
+   * TMqueue_free
+   * =============================================================================
+   *
+  public void
+    TMqueue_free (TM_ARGDECL  Queue* queuePtr)
+    {
+      queuePtr.elements = null;
+      queuePtr = null;
+    }
+
+*/
+  /* =============================================================================
+   * queue_isEmpty
+   * =============================================================================
+   */
+  public boolean
+    queue_isEmpty ()
+    {
+      //int pop      = queuePtr.pop;
+      //int push     = queuePtr.push;
+      //int capacity = queuePtr.capacity;
+
+      return (((pop + 1) % capacity == push) ? true : false);
+    }
+
+
+  /* =============================================================================
+   * queue_clear
+   * =============================================================================
+   */
+  public void
+    queue_clear ()
+    {
+      pop  = capacity - 1;
+      push = 0;
+    }
+
+
+  /* =============================================================================
+   * TMqueue_isEmpty
+   * =============================================================================
+   */
+
+
+
+  /* =============================================================================
+   * queue_push
+   * =============================================================================
+   */
+  public boolean
+    queue_push (Object dataPtr)
+    {
+    
+
+      /* Need to resize */
+      int newPush = (push + 1) % capacity;
+      if (newPush == pop) {
+
+        int newCapacity = capacity * QUEUE_GROWTH_FACTOR;
+        Object[] newElements = new Object[newCapacity];
+
+        int dst = 0;
+        if (pop < push) {
+          int src;
+          for (src = (pop + 1); src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        } else {
+          int src;
+          for (src = (pop + 1); src < capacity; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+          for (src = 0; src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        }
+
+        //elements = null;
+        elements = newElements;
+        pop      = newCapacity - 1;
+        capacity = newCapacity;
+        push = dst;
+        newPush = push + 1; /* no need modulo */
+      }
+
+      elements[push] = dataPtr;
+      push = newPush;
+
+      return true;
+    }
+
+
+  /* =============================================================================
+   * Pqueue_push
+   * =============================================================================
+   */
+  public boolean
+    Pqueue_push (Queue_t queuePtr, Object dataPtr)
+    {
+      int pop      = queuePtr.pop;
+      int push     = queuePtr.push;
+      int capacity = queuePtr.capacity;
+
+
+      /* Need to resize */
+      int newPush = (push + 1) % capacity;
+      if (newPush == pop) {
+
+        int newCapacity = capacity * QUEUE_GROWTH_FACTOR;
+        Object[] newElements = new Object[newCapacity];
+        int dst = 0;
+        Object[] elements = queuePtr.elements;
+        if (pop < push) {
+          int src;
+          for (src = (pop + 1); src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        } else {
+          int src;
+          for (src = (pop + 1); src < capacity; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+          for (src = 0; src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        }
+
+        elements = null;
+        queuePtr.elements = newElements;
+        queuePtr.pop      = newCapacity - 1;
+        queuePtr.capacity = newCapacity;
+        push = dst;
+        newPush = push + 1; /* no need modulo */
+
+      }
+
+      queuePtr.elements[push] = dataPtr;
+      queuePtr.push = newPush;
+
+      return true;
+    }
+
+  /* =============================================================================
+   * queue_pop
+   * =============================================================================
+   */
+  public Object
+    //queue_pop (Queue queuePtr)
+    queue_pop ()
+    {
+      //int pop      = queuePtr.pop;
+      //int push     = queuePtr.push;
+      //int capacity = queuePtr.capacity;
+
+      int newPop = (pop + 1) % capacity;
+      if (newPop == push) {
+        return null;
+      }
+
+      //Object dataPtr = queuePtr.elements[newPop];
+      //queuePtr.pop = newPop;
+      Object dataPtr = elements[newPop];
+      pop = newPop;
+
+      return dataPtr;
+    }
+  
+  public Queue_t queue_getUpTo(int num) 
+  {
+       Queue_t subset = Pqueue_alloc(num + 2);
+       Object pop;
+       
+       for(int i = 0; i < num && (pop = queue_pop()) != null; i++)
+               subset.queue_push(pop);
+       
+       return subset;
+  }
+
+}
+/* =============================================================================
+ *
+ * End of queue.java
+ *
+ * =============================================================================
+ */
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Router.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Router.java
new file mode 100644 (file)
index 0000000..e259390
--- /dev/null
@@ -0,0 +1,459 @@
+/* =============================================================================
+ *
+ * Router.java
+ *
+ * =============================================================================
+ *
+ * Copyright (C) Stanford University, 2006.  All Rights Reserved.
+ * Author: Chi Cao Minh
+ * 
+ * Ported to Java
+ * Author: Jihoon Lee
+ * University of California, Irvine
+ *
+ * =============================================================================
+ *
+ * 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 Router {
+    public int xCost;
+    public int yCost;
+    public int zCost;
+    public int bendCost;
+    public Point MOVE_POSX;
+    public Point MOVE_POSY;
+    public Point MOVE_POSZ;
+    public Point MOVE_NEGX;
+    public Point MOVE_NEGY;
+    public Point MOVE_NEGZ;
+    
+       private int  MOMENTUM_ZERO;
+       private int  MOMENTUM_POSX;
+       private int  MOMENTUM_POSY;
+       private int  MOMENTUM_POSZ;
+       private int  MOMENTUM_NEGX;
+       private int  MOMENTUM_NEGY;
+       private int  MOMENTUM_NEGZ;
+       private int  GRID_POINT_FULL;
+       private int  GRID_POINT_EMPTY;
+
+    public Router() {
+       //Replaced #defines
+       MOMENTUM_ZERO = 0;
+       MOMENTUM_POSX = 1;
+       MOMENTUM_POSY = 2;
+       MOMENTUM_POSZ = 3;
+       MOMENTUM_NEGX = 4;
+       MOMENTUM_NEGY = 5;
+       MOMENTUM_NEGZ = 6;
+       GRID_POINT_FULL = -2;
+       GRID_POINT_EMPTY = -1;
+    }
+
+/* =============================================================================
+ * router_alloc
+ * =============================================================================
+ * router_t* router_alloc (long xCost, long yCost, long zCost, long bendCost);
+ */
+  public Router alloc(int xCost,int yCost,int zCost,int bendCost) {
+    Router routerPtr = new Router();
+
+    
+    routerPtr.MOVE_POSX = new Point(1,0,0,0,MOMENTUM_POSX);
+    routerPtr.MOVE_POSY = new Point(0,1,0,0,MOMENTUM_POSY);
+    routerPtr.MOVE_POSZ = new Point(0,0,1,0,MOMENTUM_POSZ);
+    routerPtr.MOVE_NEGX = new Point(-1,0,0,0,MOMENTUM_NEGX);
+    routerPtr.MOVE_NEGY = new Point(0,-1,0,0,MOMENTUM_NEGY);
+    routerPtr.MOVE_NEGZ = new Point(0,0,-1,0,MOMENTUM_NEGZ);
+
+    routerPtr.xCost = xCost;
+    routerPtr.yCost = yCost;
+    routerPtr.zCost = zCost;
+    routerPtr.bendCost = bendCost;
+    
+    return routerPtr;    
+  }
+
+
+/* ============================================================================
+ * PexpandToneighbor
+ * ============================================================================
+ */
+  private void PexpandToNeighbor(Grid myGridPtr, 
+                                int x,int y,int z, int value,Queue_Int queuePtr) {
+    if (myGridPtr.isPointValid(x,y,z)) {
+      int neighborValue = myGridPtr.points_unaligned[x][y][z];
+      if (neighborValue == GRID_POINT_EMPTY) {
+       int neighborGridPointIndex = myGridPtr.getPointIndex(x,y,z);
+       myGridPtr.points_unaligned[x][y][z] = value;
+       queuePtr.queue_push(neighborGridPointIndex);
+      } else if (neighborValue != GRID_POINT_FULL) {
+       if (value < neighborValue) {
+         int neighborGridPointIndex = myGridPtr.getPointIndex(x,y,z);
+         myGridPtr.points_unaligned[x][y][z] = value;
+         queuePtr.queue_push(neighborGridPointIndex);
+       }
+      }
+    }
+  }
+
+
+/* ============================================================================
+ * PdoExpansion
+ * ============================================================================
+ */
+    public boolean PdoExpansion (Router routerPtr,Grid myGridPtr,Queue_Int queuePtr,
+                                  Coordinate srcPtr,Coordinate dstPtr) {
+        int xCost = routerPtr.xCost;
+        int yCost = routerPtr.yCost;
+        int zCost = routerPtr.zCost;
+
+        /* 
+         * Potential Optimization: Make 'src' the one closet to edge.
+         * This will likely decrease the area of the emitted wave.
+         */
+
+        queuePtr.queue_clear();
+
+        int srcGridPointIndex = myGridPtr.getPointIndex(srcPtr.x,srcPtr.y,srcPtr.z);
+
+        queuePtr.queue_push(srcGridPointIndex);
+
+        myGridPtr.setPoint(srcPtr.x,srcPtr.y,srcPtr.z,0);
+        myGridPtr.setPoint(dstPtr.x,dstPtr.y,dstPtr.z,GRID_POINT_EMPTY);
+        int dstGridPointIndex = myGridPtr.getPointIndex(dstPtr.x,dstPtr.y,dstPtr.z);
+        boolean isPathFound = false;
+       int height = myGridPtr.height;
+       int width = myGridPtr.width;
+       int area = height * width;
+        while (!queuePtr.queue_isEmpty()) {
+            int gridPointIndex = queuePtr.queue_pop();
+
+            if(gridPointIndex == dstGridPointIndex) {
+             isPathFound = true;
+             break;
+            }
+           
+           int z = gridPointIndex / area;
+           int index2d = gridPointIndex % area;
+           int y = index2d / width;
+           int x = index2d % width;        
+           int value = myGridPtr.points_unaligned[x][y][z];
+           
+            /*
+             * Check 6 neighbors
+             *
+             * Potential Optimization: Only need to check 5 of these
+             */
+           PexpandToNeighbor(myGridPtr, x+1, y,   z,   (value + xCost), queuePtr);
+           PexpandToNeighbor(myGridPtr, x-1, y,   z,   (value + xCost), queuePtr);
+           PexpandToNeighbor(myGridPtr, x, y+1,   z,   (value + yCost), queuePtr);
+           PexpandToNeighbor(myGridPtr, x, y-1,   z,   (value + yCost), queuePtr);   
+           PexpandToNeighbor(myGridPtr, x, y,   z+1,   (value + zCost), queuePtr);
+           PexpandToNeighbor(myGridPtr, x, y,   z-1,   (value + zCost), queuePtr);
+           
+        } /* iterate over work queue */
+       
+        return isPathFound;
+    }
+            
+            
+/* ============================================================================
+ * traceToNeighbor
+ * ============================================================================
+ */
+    private void traceToNeighbor(Grid myGridPtr,
+                                 Point currPtr,
+                                 Point movePtr,
+                                 boolean useMomentum,
+                                 int bendCost,
+                                 Point nextPtr)
+    {
+      int x = currPtr.x + movePtr.x;
+      int y = currPtr.y + movePtr.y;
+      int z = currPtr.z + movePtr.z;
+
+        if (myGridPtr.isPointValid(x,y,z) &&
+                !myGridPtr.isPointEmpty(x,y,z) &&
+                !myGridPtr.isPointFull(x,y,z))
+        {
+            int value = myGridPtr.getPoint(x,y,z);
+            int b = 0;
+            
+            if (useMomentum && (currPtr.momentum != movePtr.momentum)) {
+                b = bendCost;
+            }
+            if ((value + b) <= nextPtr.value) { /* '=' favors neighbors over current */
+                nextPtr.x = x;
+                nextPtr.y = y;
+                nextPtr.z = z;
+                nextPtr.value = value;
+                nextPtr.momentum = movePtr.momentum;
+            }
+        }
+    }
+/* =============================================================================
+ * PdoTraceback
+ * =============================================================================
+ */
+
+    private Vector_t PdoTraceback(Grid myGridPtr,
+                                  Coordinate dstPtr, int bendCost) {
+       Vector_t vector_t = new Vector_t();
+        Vector_t pointVectorPtr = vector_t.vector_alloc(1);
+
+        Point next = new Point();
+        next.x = dstPtr.x;
+        next.y = dstPtr.y;
+        next.z = dstPtr.z;
+        next.value = myGridPtr.getPoint(next.x,next.y,next.z);
+        next.momentum = MOMENTUM_ZERO;
+
+        while(true) {
+            int gridPointIndex = myGridPtr.getPointIndex(next.x,next.y,next.z);
+            pointVectorPtr.vector_pushBack(new Integer(gridPointIndex));
+            myGridPtr.setPoint(next.x,next.y,next.z,GRID_POINT_FULL);
+
+            /* Check if we are done */
+            if (next.value == 0) {
+                break;
+            }
+            Point curr = new Point();
+            curr.x = next.x;
+            curr.y = next.y;
+            curr.z = next.z;
+            curr.value = next.value;
+            curr.momentum = next.momentum;
+
+            /*
+             * Check 6 neibors
+             */
+
+            traceToNeighbor(myGridPtr,curr,MOVE_POSX,true, bendCost, next);
+            traceToNeighbor(myGridPtr,curr,MOVE_POSY,true, bendCost, next);   
+            traceToNeighbor(myGridPtr,curr,MOVE_POSZ,true, bendCost, next);
+            traceToNeighbor(myGridPtr,curr,MOVE_NEGX,true, bendCost, next); 
+            traceToNeighbor(myGridPtr,curr,MOVE_NEGY,true, bendCost, next);           
+            traceToNeighbor(myGridPtr,curr,MOVE_NEGZ,true, bendCost, next);          
+            /* 
+             * Because of bend costs, none of the neighbors may appear to be closer.
+             * In this case, pick a neighbor while ignoring momentum.
+             */
+
+
+            
+            if ((curr.x == next.x) &&
+                (curr.y == next.y) &&
+                (curr.z == next.z)) {
+                next.value = curr.value;
+                traceToNeighbor(myGridPtr,curr,MOVE_POSX,false, bendCost, next);
+                traceToNeighbor(myGridPtr,curr,MOVE_POSY,false, bendCost, next);
+                traceToNeighbor(myGridPtr,curr,MOVE_POSZ,false, bendCost, next);
+                traceToNeighbor(myGridPtr,curr,MOVE_NEGX,false, bendCost, next);
+                traceToNeighbor(myGridPtr,curr,MOVE_NEGY,false, bendCost, next);
+                traceToNeighbor(myGridPtr,curr,MOVE_NEGZ,false, bendCost, next);
+                
+                if ((curr.x == next.x) &&
+                    (curr.y == next.y) &&
+                    (curr.z == next.z)) {
+                    System.out.println("Dead");
+                    return null;
+                }
+            }
+        }
+
+        return pointVectorPtr;
+    }
+
+/* =============================================================================
+ * router_solve
+ * =============================================================================
+ * void router_solve (void* argPtr);
+ */
+    public void solve(Object argPtr) 
+    {
+       
+        Solve_Arg routerArgPtr = (Solve_Arg) argPtr;
+        Router routerPtr = routerArgPtr.routerPtr;
+        Maze mazePtr = routerArgPtr.mazePtr;
+        int workload = routerArgPtr.rblock_workload;
+        List_t pathVectorListPtr = routerArgPtr.pathVectorListPtr; 
+
+        Queue_t masterWorkQueuePtr = mazePtr.workQueuePtr;
+        Grid masterGridPtr = mazePtr.gridPtr; 
+        int bendCost = routerPtr.bendCost;
+
+        while(!masterWorkQueuePtr.queue_isEmpty())
+        {
+               Queue_t redoQueue = masterWorkQueuePtr.Pqueue_alloc(masterWorkQueuePtr.capacity);
+               
+               while(!masterWorkQueuePtr.queue_isEmpty())
+               {
+                       //moved to outside rBlock due to potential r/w conflicts 
+                       Queue_t localWorkQueue = masterWorkQueuePtr.queue_getUpTo(workload);
+                       
+//                     sese P
+//                     {
+                               //Clone needed since new paths are added to local Grid. Cannot add to master Grid because of rBlock p conflicts
+                               Grid MGClone  = masterGridPtr.alloc(masterGridPtr.width, masterGridPtr.height, masterGridPtr.depth);
+                               masterGridPtr.copy(MGClone, masterGridPtr);
+                               
+                               Vector_t computedPaths = solveLogic(localWorkQueue, MGClone, routerPtr, bendCost, workload);
+//                     }
+               
+//             sese S
+//             {
+                       Vector_t sucessfulPaths = computedPaths.vector_alloc(workload);
+                       
+                       CoordPathWrapper singlePathSolution = (CoordPathWrapper) computedPaths.vector_popBack();
+                       while(singlePathSolution != null)
+                       {
+                               if(masterGridPtr.TM_addPath(singlePathSolution.pathVector))
+                                       //fail
+                                       redoQueue.queue_push(singlePathSolution.coordinatePair);
+                               else //success
+                                       sucessfulPaths.vector_pushBack(singlePathSolution.pathVector);
+                               
+                               singlePathSolution = (CoordPathWrapper)computedPaths.vector_popBack(); 
+                       }
+                       
+                       pathVectorListPtr.insert(sucessfulPaths);
+//             }
+               }
+               masterWorkQueuePtr = redoQueue;
+        }
+               
+        
+        
+        
+        
+        
+        
+        
+
+        /*
+         * Add my paths to global list
+         */
+//        List_t pathVectorListPtr = routerArgPtr.pathVectorListPtr;
+//
+//            pathVectorListPtr.insert(myPathVectorPtr);
+    }
+    
+    private Vector_t solveLogic(Queue_t localWorkQueue, Grid MGCopyPtr, Router routerPtr, int bendCost, int workload)
+    {
+        /*
+         * Iterate over work list to route each path. This involves an
+         * 'expansion' and 'traceback' phase for each source/destination pair.
+         */
+
+       Vector_t vector_t = new Vector_t();
+       Queue_Int queue_int = new Queue_Int();
+        Vector_t computedPathsPtr = vector_t.vector_alloc(workload + 2);
+        while(true) {
+            Pair coordinatePairPtr;
+            Queue_Int myExpansionQueuePtr = queue_int.queue_alloc(-1);
+            
+            if(localWorkQueue.queue_isEmpty()) {
+               coordinatePairPtr = null;
+            } 
+            else {
+               coordinatePairPtr = (Pair)localWorkQueue.queue_pop();
+            }
+            
+            if (coordinatePairPtr == null)
+                break;
+
+            Coordinate srcPtr = (Coordinate)coordinatePairPtr.first;
+            Coordinate dstPtr = (Coordinate)coordinatePairPtr.second;
+
+//            System.out.println("SRC x = " + srcPtr.x + "  y = " + srcPtr.y + " z = " +srcPtr.z);
+            Vector_t pointVectorPtr = null;
+               
+            //Copy needed here since PdoExpansion fills grid with misc data
+            Grid tempGrid = MGCopyPtr.alloc(MGCopyPtr.width,MGCopyPtr.height,MGCopyPtr.depth);
+            MGCopyPtr.copy(tempGrid, MGCopyPtr); /* ok if not most up-to-date */
+      
+               if(routerPtr.PdoExpansion(routerPtr,tempGrid,myExpansionQueuePtr,srcPtr,dstPtr)) {
+                       pointVectorPtr = routerPtr.PdoTraceback(tempGrid,dstPtr,bendCost);
+                       if (pointVectorPtr != null) {
+                               //Cannot add to master grid as original due to rBlocks conflicting
+                               if (MGCopyPtr.TM_addPath(pointVectorPtr)) {
+                                       pointVectorPtr=null;
+                               }
+                               else
+                               {
+                                       //Success!
+                                       CoordPathWrapper currPath = new CoordPathWrapper(coordinatePairPtr, pointVectorPtr);
+                                       computedPathsPtr.vector_pushBack(currPath);
+                               }
+                       }
+               }
+        }
+        
+        return computedPathsPtr;
+    }
+}
+/* =============================================================================
+ *
+ * End of router.java
+ * 
+ * =============================================================================
+ */
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Solve_Arg.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Solve_Arg.java
new file mode 100644 (file)
index 0000000..b1ccee5
--- /dev/null
@@ -0,0 +1,16 @@
+public class Solve_Arg 
+{
+    Router routerPtr;
+    Maze mazePtr;
+    List_t pathVectorListPtr;
+    int rblock_workload;
+
+    public Solve_Arg(Router r,Maze m,List_t l, int workload)
+    {
+        routerPtr = r;
+        mazePtr = m;
+        pathVectorListPtr = l;
+        rblock_workload = workload;
+    }
+}
+
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Vector_t.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/Vector_t.java
new file mode 100644 (file)
index 0000000..1fd44ba
--- /dev/null
@@ -0,0 +1,140 @@
+public class Vector_t {
+  int size;
+  int capacity;
+  Object[] elements;
+//  QuickSort qsort;
+
+  public Vector_t() {
+//    qsort = new QuickSort();
+  }
+
+  /* =============================================================================
+   * Vector_alloc
+   * -- Returns null if failed
+   * =============================================================================
+   */
+  public Vector_t vector_alloc (int initCapacity) {
+    int capacity = Math.imax(initCapacity, 1);
+    Vector_t vectorPtr = new Vector_t();
+    vectorPtr.capacity = capacity;
+    vectorPtr.elements = new Object[capacity];
+    return vectorPtr;
+  }
+
+  /* =============================================================================
+   * Vector_free
+   * =============================================================================
+   */
+  public void
+    vector_free ()
+    {
+      elements = null;
+    }
+
+  /* =============================================================================
+   * Vector_at
+   * -- Returns null if failed
+   * =============================================================================
+   */
+  public Object vector_at (int i) {
+    return (elements[i]);
+  }
+
+
+  /* =============================================================================
+   * Vector_pushBack
+   * -- Returns false if fail, else true
+   * =============================================================================
+   */
+  public boolean vector_pushBack (Object dataPtr) {
+    if (size == capacity) {
+      int newCapacity = capacity * 2;
+      Object[] newElements = new Object[newCapacity];
+
+      //void** newElements = (void**)malloc(newCapacity * sizeof(void*));
+      capacity = newCapacity;
+      for (int i = 0; i < size; i++) {
+        newElements[i] = elements[i];
+      }
+      elements = null;
+      elements = newElements;
+    }
+
+    elements[size++] = dataPtr;
+
+    return true;
+  }
+
+  /* =============================================================================
+   * Vector_popBack
+   * -- Returns null if fail, else returns last element
+   * =============================================================================
+   */
+  public Object
+    vector_popBack ()
+    {
+      if (size < 1) {
+        return null;
+      }
+
+      return (elements[--(size)]);
+    }
+
+  /* =============================================================================
+   * Vector_getSize
+   * =============================================================================
+   */
+  public int
+    vector_getSize ()
+    {
+      return (size);
+    }
+
+  /* =============================================================================
+   * Vector_clear
+   * =============================================================================
+   */
+  public void
+    vector_clear ()
+    {
+      size = 0;
+    }
+  
+  /* =============================================================================
+   * Vector_sort
+   * =============================================================================
+   *
+  public void
+    vector_sort ()
+    {
+      //qsort.sort(elements, 0, (elements.length - 1));
+      qsort.sort(elements);
+      //qsort(elements, size, 4, compare);
+    }
+
+  * =============================================================================
+   * Vector_copy
+   * =============================================================================
+   */
+  public static boolean
+    vector_copy (Vector_t dstVectorPtr, Vector_t srcVectorPtr)
+    {
+      int dstCapacity = dstVectorPtr.capacity;
+      int srcSize = srcVectorPtr.size;
+      if (dstCapacity < srcSize) {
+        int srcCapacity = srcVectorPtr.capacity;
+        Object[] elements = new Object[srcCapacity];
+        dstVectorPtr.elements = null;
+        dstVectorPtr.elements = elements;
+        dstVectorPtr.capacity = srcCapacity;
+      }
+
+      for(int i = 0; i< srcSize; i++) {
+        dstVectorPtr.elements[i] = srcVectorPtr.elements[i];
+      }
+
+      dstVectorPtr.size = srcSize;
+
+      return true;
+    }
+}
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/extractLines b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/Normal_Java/extractLines
new file mode 100644 (file)
index 0000000..c75e572
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+lines=$(grep -n "#" $1 | cut -d: -f1 | sed '1q')
+sed '/^#/d' $1 > ttt$1
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/CoordPathWrapper.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/CoordPathWrapper.java
new file mode 100644 (file)
index 0000000..52a6fdc
--- /dev/null
@@ -0,0 +1,20 @@
+/* =============================================================================
+ *
+ * CoordPathWrapper.java
+ *
+ * =============================================================================
+ *
+ * Author: Stephen Yang
+ * University of California, Irvine
+ */
+public class CoordPathWrapper {
+       Pair coordinatePair;
+       Vector_t pathVector;
+
+       public CoordPathWrapper(Pair coordinatePairPtr, Vector_t path) {
+               coordinatePair = coordinatePairPtr;
+               pathVector = path;
+                       
+       }
+
+}
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Coordinate.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Coordinate.java
new file mode 100644 (file)
index 0000000..a9c9c54
--- /dev/null
@@ -0,0 +1,175 @@
+/* =============================================================================
+ *
+ * coordinate.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.
+ *
+ * =============================================================================
+ */
+
+import java.lang.Math;
+
+public class Coordinate {
+
+    public int x;
+    public int y;
+    public int z;
+
+    public Coordinate() {}
+
+
+    // coordiate_alloc will be constructor
+    // coordinate_t* coordinate_alloc(long x, long y, long z)
+    public Coordinate(int x,int y,int z) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+    }
+
+    public Coordinate alloc(int x,int y,int z) {
+        Coordinate c = new Coordinate(x,y,z);
+
+        return c;
+    }
+
+    
+    // deallocate memory
+    // may not need
+    //  coordinate_free
+
+    /*========================================================
+    // coordinate_isEqual
+    ==========================================================*/
+    public boolean isEqual(Coordinate a,Coordinate b) 
+    {
+        if((a.x == b.x) && (a.y == b.y) && (a.z == b.z))
+            return true;
+        
+        return false;
+    }
+
+    /*==========================================================
+      *
+      * getPairDistance
+      *
+      *========================================================*/   
+    private double getPairDistance(Pair p)
+    {
+        Coordinate a = (Coordinate)p.first;
+        Coordinate b = (Coordinate)p.second;
+        int dx = a.x - b.x;
+        int dy = a.y - b.y;
+        int dz = a.z - b.z;
+        int dx2 = dx* dx;
+        int dy2 = dy* dy;
+        int dz2 = dz* dz;
+
+        return Math.sqrt((double)(dx2+dy2+dz2));
+    }
+
+
+    /*================================================
+    // coordinat_ comparePair
+     * -- For sorting in list of source/destination pairs
+     * -- Route longer paths first so they are more likely to suceed
+     
+    *================================================*/
+    public int comparePair(final Object a,final Object b) 
+    {
+        double aDistance = getPairDistance((Pair)a);
+        double bDistance = getPairDistance((Pair)b);
+
+        if(aDistance < bDistance) {
+            return 1;
+        } else if(aDistance > bDistance) {
+            return -1;
+        }
+
+        return 0;
+    }
+
+    /*=======================================================
+      * coordinate_areAdjacent
+      *=======================================================*/
+
+    public boolean areAdjacent(Coordinate a,Coordinate b) 
+    {
+        int dx = a.x - b.x;
+        int dy = a.y - b.y;
+        int dz = a.z - b.z;
+        int dx2 = dx * dx;
+        int dy2 = dy * dy;
+        int dz2 = dz * dz;
+
+        return (((dx2 + dy2 + dz2) == 1) ? true : false);
+    }
+    }
+
+    /*=====================================================
+      * 
+      * End of Coordinate
+      *
+      *====================================================*/
+    
+    
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Grid.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Grid.java
new file mode 100644 (file)
index 0000000..b609e81
--- /dev/null
@@ -0,0 +1,287 @@
+/* =============================================================================
+ *
+ * grid.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 Grid {
+    public int width;
+    public int height;
+    public int depth;
+    public int[][][] points_unaligned;
+    
+    public static int GRID_POINT_FULL;
+    public static int GRID_POINT_EMPTY;
+
+    public Grid() 
+    {
+       GRID_POINT_FULL = -2;
+       GRID_POINT_EMPTY = -1;
+    }
+
+    
+/* =============================================================================
+ * grid_alloc
+ * =============================================================================
+    grid_t* grid_alloc (long width, long height, long depth);
+
+    well... need to implement
+    got stuck
+*/
+  public Grid alloc(int width,int height,int depth) {
+    Grid grid = new Grid();
+    
+    grid.width = width;
+    grid.height = height;
+    grid.depth = depth;
+    
+    int[][][] points_unaligned = new int[width][height][depth];
+    
+    
+    for(int i=0;i<width;i++)
+      for(int j=0;j<height;j++)
+         for(int k=0;k<depth;k++)
+                 points_unaligned[i][j][k]= GRID_POINT_EMPTY;
+    
+    grid.points_unaligned = points_unaligned;
+    
+    return grid;         
+  }
+
+  
+  //What does scratchalloc do?
+  public Grid scratchalloc(int width,int height,int depth) {
+    Grid grid = /*scratch */ new Grid();
+    grid.width = width;
+    grid.height = height;
+    grid.depth = depth;
+    int[][][] points_unaligned = /*scratch*/ new int[width][height][depth];
+    grid.points_unaligned = points_unaligned;
+    return grid;         
+  }
+
+
+
+/* =============================================================================
+ * grid_copy
+ * =============================================================================
+    void grid_copy (grid_t* dstGridPtr, grid_t* srcGridPtr);
+ */
+  public void copy(Grid dstGridPtr,Grid srcGridPtr) {
+    if((srcGridPtr.width == dstGridPtr.width) ||
+       (srcGridPtr.height == dstGridPtr.height) ||
+       (srcGridPtr.depth == dstGridPtr.depth)) 
+    {   
+      deepArrayCopy(dstGridPtr.points_unaligned, srcGridPtr.points_unaligned);
+    }      
+  }
+  //Array copy function added to replace System.deepArrayCopy in original 
+  //assumes they are of the same size
+  private void deepArrayCopy(int[][][] dst, int[][][] src)
+  {
+         for(int i = 0; i < src.length; i++)
+                 for(int j = 0; j < src[i].length; j++)
+                         for(int k = 0; k < src[i][j].length; k++)
+                                 dst[i][j][k] = src[i][j][k];
+  }
+
+/* =============================================================================
+ * grid_isPointValid
+ * =============================================================================
+ bool_t grid_isPointValid (grid_t* gridPtr, long x, long y, long z);
+ */
+  public boolean isPointValid(int x,int y,int z) {
+    return x>=0 && x< width && y>=0 && y<height && z>=0 && z<depth;
+  }
+
+
+  public int getPoint(int x,int y,int z) {
+    return this.points_unaligned[x][y][z];
+  }
+
+
+/* =============================================================================
+ * grid_isPointEmpty
+ * =============================================================================
+ bool_t grid_isPointEmpty (grid_t* gridPtr, long x, long y, long z); {
+ */
+
+  public boolean isPointEmpty(int x,int y,int z) {
+    return points_unaligned[x][y][z]==GRID_POINT_EMPTY;
+  }
+
+
+
+/* =============================================================================
+ * grid_isPointFull
+ * =============================================================================
+ bool_t grid_isPointFull (grid_t* gridPtr, long x, long y, long z);
+ */
+  public boolean isPointFull(int x,int y,int z) {
+    return points_unaligned[x][y][z]==GRID_POINT_FULL;
+  }
+
+
+/* =============================================================================
+ * grid_setPoint
+ * =============================================================================
+ void grid_setPoint (grid_t* gridPtr, long x, long y, long z, long value);
+ */
+  public void setPoint(int x,int y,int z,int value) {
+    points_unaligned[x][y][z] = value;
+  }
+
+
+/* =============================================================================
+ * grid_addPath
+ * =============================================================================
+void grid_addPath (grid_t* gridPtr, vector_t* pointVectorPtr);
+*/
+  public void addPath(Vector_t pointVectorPtr) {
+    int i;
+    int n = pointVectorPtr.vector_getSize();
+    
+    for(i = 0; i < n; i++) {
+      Coordinate coordinatePtr = (Coordinate)pointVectorPtr.vector_at(i);
+      int x = coordinatePtr.x;
+      int y = coordinatePtr.y;
+      int z = coordinatePtr.z;
+
+      points_unaligned[x][y][z]=GRID_POINT_FULL;
+    }
+  }
+
+  //True is fail, false is success.
+  public boolean TM_addPath(Vector_t pointVectorPtr) {
+    int i;
+    int n = pointVectorPtr.vector_getSize();
+
+    int height = this.height;
+    int width = this.width;
+    int area = height * width;
+    boolean dowrites=true;
+    
+    for(i = 1; i < (n-1); i++) {
+      int gridPointIndex = ((Integer)(pointVectorPtr.vector_at(i))).intValue();
+      int z = gridPointIndex / area;
+      int index2d = gridPointIndex % area;
+      int y = index2d / width;
+      int x = index2d % width;        
+      if (points_unaligned[x][y][z] != GRID_POINT_EMPTY) {
+         dowrites=false;
+      }
+    }
+
+    for(i = 1; i < (n-1); i++) {
+      int gridPointIndex = ((Integer)(pointVectorPtr.vector_at(i))).intValue();
+      int z = gridPointIndex / area;
+      int index2d = gridPointIndex % area;
+      int y = index2d / width;
+      int x = index2d % width;
+      int[] array=points_unaligned[x][y];
+      if (dowrites) array[z] = GRID_POINT_FULL;
+    }
+    return !dowrites;
+  }
+
+  public int getPointIndex(int x,int y,int z) {
+    return ((z * height) + y) * width + x;
+  }
+
+  
+  public void print() {
+    int width  = this.width;
+    int height = this.height;
+    int depth  = this.depth;
+
+    for (int z = 0; z < depth; z++) {
+      System.out.println("[z ="+z+"]");
+      for (int x = 0; x < width; x++) {
+       for (int y = 0; y < height; y++) {
+         String str=String.valueOf(points_unaligned[x][y][z]);
+         for(int sp=0; sp<(4-str.length());sp++)
+           System.out.print(" ");
+         System.out.print(str);
+       }
+       System.out.println("");
+      }
+      System.out.println("");
+    }
+  }
+}
+
+
+/* =============================================================================
+ *
+ * End of grid.c
+ *
+ * =============================================================================
+ */
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Labyrinth.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Labyrinth.java
new file mode 100644 (file)
index 0000000..9d60942
--- /dev/null
@@ -0,0 +1,239 @@
+/* =============================================================================
+ *
+ * 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;
+    int numThread;
+    int bendCost;
+    int xCost;
+    int yCost;
+    int zCost;
+
+
+    // For threads
+    int threadID;
+    Solve_Arg routerArg;
+    
+    //For rblocks
+    int global_workload;
+
+    private void setDefaultParams() {
+
+        /* default values */
+        global_inputFile = null;
+        global_doPrint = false;
+        bendCost = 1;
+        xCost = 1;
+        yCost = 1;
+        zCost = 2;
+        numThread = 1;
+        
+        global_workload = 100;
+    }
+
+    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 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");
+        System.out.println("    x <INT>     x movement cost");
+        System.out.println("    y <INT>     y movement cost");
+        System.out.println("    z <INT>     z movement cost");
+        System.out.println("    w <INT>     Workload per rBlock");
+    }
+        
+
+    public static void main(String[] argv) 
+    {
+        /*
+         * Initailization
+         */
+       Maze maze = new Maze();
+       Router router = new Router();
+        Labyrinth labyrinth = new Labyrinth(argv);
+        
+        Maze mazePtr = maze.alloc();
+
+        int numPathToRoute =  mazePtr.readMaze(labyrinth.global_inputFile);
+        
+        Router routerPtr = router.alloc(labyrinth.xCost,labyrinth.yCost,
+                                        labyrinth.zCost,labyrinth.bendCost);
+
+        List_t list_t = new List_t();
+        List_t pathVectorListPtr = list_t.alloc(0);     // list_t.alloc(null)
+        Solve_Arg routerArg = new Solve_Arg(routerPtr,mazePtr,pathVectorListPtr, labyrinth.global_workload);
+
+        /* Create and start thread */
+        long start = System.currentTimeMillis();
+        routerPtr.solve(routerArg);        
+
+        /* End of Solve */
+        long finish = System.currentTimeMillis();
+        long diff=finish-start;
+        System.out.println("TIME= " + diff);
+
+
+        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 = (finish-start)/1000.0;
+
+        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
+ *
+ * =============================================================================
+ */
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/List_Iter.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/List_Iter.java
new file mode 100644 (file)
index 0000000..351e80d
--- /dev/null
@@ -0,0 +1,38 @@
+public class List_Iter {
+    List_Node itPtr;
+
+    /* =============================================================================
+     * list_iter_reset
+     * =============================================================================
+       void list_iter_reset (list_iter_t* itPtr, list_t* listPtr);
+    */
+     public List_Iter() {
+         itPtr = null;
+     }
+        
+     public void reset(List_t listPtr) 
+     {
+         itPtr = listPtr.head;
+     }
+
+    /* =============================================================================
+     * list_iter_hasNext
+     * =============================================================================
+     * bool_t list_iter_hasNext (list_iter_t* itPtr, list_t* listPtr);
+     */
+     public boolean hasNext(List_t listPtr) {
+         return (itPtr.nextPtr != null)? true : false;
+     }
+
+    /* =============================================================================
+     * list_iter_next
+     * =============================================================================
+     * void* list_iter_next (list_iter_t* itPtr, list_t* listPtr);
+     */
+     public Object next(List_t listPtr) 
+     {
+         itPtr = itPtr.nextPtr;
+         return itPtr.dataPtr; 
+     }
+}
+
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/List_Node.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/List_Node.java
new file mode 100644 (file)
index 0000000..806baa1
--- /dev/null
@@ -0,0 +1,10 @@
+
+public class List_Node {
+    Object dataPtr;
+    List_Node nextPtr;
+
+    public List_Node() {
+        dataPtr = null;
+        nextPtr = null;
+    }
+}
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/List_t.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/List_t.java
new file mode 100644 (file)
index 0000000..3b73d64
--- /dev/null
@@ -0,0 +1,307 @@
+/* =============================================================================
+ *
+ * List_t.java
+ * -- Sorted singly linked list
+ * -- Options: duplicate allowed  
+ *    (DLIST_NO_DUPLICATES) is no implemented yet (default: allow duplicates)
+ *
+ * =============================================================================
+ *
+ * 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 List_t {
+
+    public List_Node head;
+    boolean isCoordinate;
+    int size;
+
+    public List_t() {
+        head = new List_Node();
+    }
+
+
+    /* =======================================================================
+     * allocNode
+     * -- Returns null on failure
+     * =======================================================================
+     */
+    private List_Node allocNode(Object dataPtr) 
+    {
+        List_Node nodePtr = new List_Node();
+
+
+        nodePtr.dataPtr = dataPtr;
+        nodePtr.nextPtr = null;
+
+        return nodePtr;
+    }
+        
+    
+/* =============================================================================
+ * list_alloc
+ * -- If NULL passed for 'compare' function, will compare data pointer addresses
+ * -- Returns NULL on failure
+ * =============================================================================
+ * list_t* list_alloc (long (*compare)(const void*, const void*));
+ *
+ *
+ */
+
+    public List_t alloc(int isCoordinate) 
+    {
+        List_t listPtr = new List_t();
+
+
+        listPtr.head.dataPtr = null;
+        listPtr.head.nextPtr = null;
+        listPtr.size = 0;
+        
+        listPtr.isCoordinate = (isCoordinate==1)?true:false;
+
+        return listPtr;
+    }
+    
+/* =============================================================================
+ * list_free
+ * -- If NULL passed for 'compare' function, will compare data pointer addresses
+ * -- Returns NULL on failure
+ * =============================================================================
+ * void list_free (list_t* listPtr);
+ */
+    public void free(List_t listPtr) 
+    {
+        listPtr = null;
+    }
+
+//    privae freeList
+
+/* =============================================================================
+ * list_isEmpty
+ * -- Return TRUE if list is empty, else FALSE
+ * =============================================================================
+ * bool_t list_isEmpty (list_t* listPtr);
+ */
+    public boolean isEmpty() 
+    {
+        return (head.nextPtr == null);
+    }
+
+/* =============================================================================
+ * list_getSize
+ * -- Returns size of list
+ * =============================================================================
+ * long list_getSize (list_t* listPtr);
+ */
+    public int getSize() {
+        return size;
+    }
+
+/* =============================================================================
+ * findPrevious
+ * =============================================================================
+ * void* list_find (list_t* listPtr, void* dataPtr);
+ */                                                                             
+    private List_Node findPrevious(Object dataPtr) 
+    {
+        List_Node prevPtr = head;
+        List_Node nodePtr = prevPtr.nextPtr;
+
+        for(; nodePtr != null; nodePtr = nodePtr.nextPtr) {
+            if (compare(nodePtr.dataPtr,dataPtr) >= 0) {
+                return prevPtr;
+            }
+            prevPtr = nodePtr;
+        }
+
+        return prevPtr;
+    }
+
+    /* =============================================================================
+     * list_find
+     * -- Returns NULL if not found, else returns pointer to data
+     * =============================================================================
+     * void* list_find (list_t* listPtr, void* dataPtr);
+     */
+    public Object find(Object dataPtr) {
+        List_Node nodePtr;
+        List_Node prevPtr = findPrevious(dataPtr);
+
+        nodePtr = prevPtr.nextPtr;
+
+        if((nodePtr == null) ||
+                (compare(nodePtr.dataPtr,dataPtr) != 0)) {
+            return null;
+        }
+
+        return (nodePtr.dataPtr);
+    }
+
+    public int compare(Object obj1,Object obj2) 
+    {
+       Coordinate coordinate  = new Coordinate();
+        if(isCoordinate)
+        {
+            return coordinate.comparePair(obj1,obj2);
+        }
+        else 
+            return compareObject(obj1,obj2);
+    }
+
+/* =============================================================================
+ * list_insert
+ * -- Return TRUE on success, else FALSE
+ * =============================================================================
+ * bool_t list_insert (list_t* listPtr, void* dataPtr);
+ */
+    public boolean insert(Object dataPtr) {
+        List_Node prevPtr;
+        List_Node nodePtr;
+        List_Node currPtr;
+
+        prevPtr = findPrevious(dataPtr);
+        currPtr = prevPtr.nextPtr;
+
+        nodePtr = allocNode(dataPtr);
+        if (nodePtr == null) {
+            return false;
+        }
+
+        nodePtr.nextPtr = currPtr;
+        prevPtr.nextPtr = nodePtr;
+        size++;
+
+        return true;
+    }
+        
+    
+/* =============================================================================
+ * list_remove
+ * -- Returns TRUE if successful, else FALSE
+ * =============================================================================
+ * bool_t list_remove (list_t* listPtr, void* dataPtr);
+ */
+    public boolean remove(Object dataPtr) 
+    {
+        List_Node prevPtr;
+        List_Node nodePtr;
+
+        prevPtr = findPrevious(dataPtr);
+
+        nodePtr = prevPtr.nextPtr;
+
+        if((nodePtr != null) &&
+            (compare(nodePtr.dataPtr,dataPtr) == 0))
+        {
+            prevPtr.nextPtr = nodePtr.nextPtr;
+            nodePtr.nextPtr = null;
+            nodePtr = null;
+            size--;
+
+            return true;
+        }
+    
+        return false;
+    }
+
+    int compareObject(Object obj1,Object obj2) {
+        return 1;
+    }
+    
+
+/* =============================================================================
+ * list_clear
+ * -- Removes all elements
+ * =============================================================================
+ * void list_clear (list_t* listPtr);
+ */
+    public void clear() {
+        head = new List_Node();
+        size = 0;    
+    }
+
+/* =============================================================================
+ *
+ * End of list.java
+ *
+ * =============================================================================
+ */
+
+ /* Test list */
+
+// public static void main(String[] argv) {
+//     List_t listPtr;
+//     int[] data1 = new int[5];
+//     int[] data2 = new int[6];
+//
+//     int i;
+//
+//     System.out.println("Starting...");
+//        }
+//
+}
+
+
+     
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Maze.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Maze.java
new file mode 100644 (file)
index 0000000..197f91a
--- /dev/null
@@ -0,0 +1,395 @@
+/*=============================================================================
+ *
+ * Maze.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 Maze {
+    Grid gridPtr;
+    Queue_t workQueuePtr;
+    Vector_t wallVectorPtr; /* contains source/destination pairs to route */
+    Vector_t srcVectorPtr;  /* obstacles */
+    Vector_t dstVectorPtr;  /* destinations */
+    
+    public int GRID_POINT_FULL;
+    public int GRID_POINT_EMPTY;
+
+    public Maze() 
+    {
+       GRID_POINT_FULL = -2;
+       GRID_POINT_EMPTY = -1;
+    }
+
+
+/* =============================================================================
+ * maze_alloc
+ * =============================================================================
+ maze_t* maze_alloc ();
+ */
+   public Maze alloc() 
+   {
+       Maze mazePtr = new Maze();
+       Vector_t vector_t = new Vector_t();
+       Queue_t queue_t = new Queue_t();
+
+       mazePtr.gridPtr = null;
+       mazePtr.workQueuePtr = queue_t.queue_alloc(1024);
+       mazePtr.wallVectorPtr = vector_t.vector_alloc(1);
+       mazePtr.srcVectorPtr = vector_t.vector_alloc(1);
+       mazePtr.dstVectorPtr = vector_t.vector_alloc(1);
+
+
+       return mazePtr;
+   }
+
+/* =============================================================================
+ * maze_free
+ * =============================================================================
+ void maze_free (maze_t* mazePtr);
+ */
+    public void free(Maze m)
+    {
+        m = null;
+    }    
+
+/* =============================================================================
+ * addToGrid
+ * =============================================================================
+ */
+    private void addToGrid(Grid gridPtr,Vector_t vectorPtr,String type)
+    {
+        int i;
+        int n = vectorPtr.vector_getSize();
+
+        for(i = 0; i < n; i++) {
+            Coordinate coordinatePtr = (Coordinate)vectorPtr.vector_at(i);
+            if(!gridPtr.isPointValid(coordinatePtr.x,coordinatePtr.y,coordinatePtr.z))
+            {
+                System.out.println("Error: " + type + " (" + coordinatePtr.x + 
+                                                      ", " + coordinatePtr.y + 
+                                                      ", " + coordinatePtr.z);
+                System.exit(1);
+            }
+        }
+        gridPtr.addPath(vectorPtr);
+    }
+/* =============================================================================
+ * maze_read
+ * -- Return number of path to route
+ * =============================================================================
+ long maze_read (maze_t* mazePtr, char* inputFileName);
+ */
+    public int readMaze(String inputFileName)
+    {          
+               //Added for mlp compatiability
+               List_t list_t = new List_t();
+               Coordinate coordinate = new Coordinate();
+               Pair pair = new Pair();
+               
+        FileInputStream in = new FileInputStream(inputFileName);
+               
+        /*
+         * Parse input file
+         */
+        int lineNumber = 0;
+        int height = -1;
+        int width = -1;
+        int depth = -1;
+        boolean isParseError = false;
+        List_t workListPtr = list_t.alloc(1); // List.alloc(Coordinate.comparePair);
+        String line;
+
+      while((line = in.readLine()) != null) {            
+            String code;
+            int[] xy = new int[6];  // equivalent to x1,y1,z1,x2,y2,z2
+            int numToken = 0;
+            
+            StringTokenizer tok = new StringTokenizer(line);
+
+            if((numToken = tok.countTokens()) < 1 ) {
+                continue;
+            }
+
+            code = tok.nextToken();
+
+            if(code.equals("#")) {
+                /* comment line */
+                continue;
+            }
+            for(int i=0;i<numToken-1;i++) {
+                xy[i] = Integer.parseInt(tok.nextToken());
+            }
+
+            if(code.equals("d")) {
+                  /* dimensions (format: d x y z) */
+                 if(numToken != 4) {
+                    isParseError = true;
+                 }
+                 else {
+                    width = xy[0];
+                    height = xy[1];
+                    depth = xy[2];
+                    if(width < 1 || height < 1 || depth <1)
+                        isParseError = true;
+                 }
+             }else if(code.equals("p")) { /* paths (format: p x1 y1 z1 x2 y2 z2) */
+                if(numToken != 7) {
+                    isParseError = true;
+                }
+                else {
+                    Coordinate srcPtr = coordinate.alloc(xy[0],xy[1],xy[2]);
+                    Coordinate dstPtr = coordinate.alloc(xy[3],xy[4],xy[5]);
+
+                    if(coordinate.isEqual(srcPtr,dstPtr)) {
+                        isParseError = true;
+                    }
+                    else { 
+                        Pair coordinatePairPtr = pair.alloc(srcPtr,dstPtr);
+                        boolean status = workListPtr.insert(coordinatePairPtr);
+                        srcVectorPtr.vector_pushBack(srcPtr);
+                        dstVectorPtr.vector_pushBack(dstPtr);
+                        
+                    }
+                }
+            }else if(code.equals("w")) {
+                     /* walls (format: w x y z) */
+                    if(numToken != 4) {
+                        isParseError = true;
+                    } else {
+                        Coordinate wallPtr = coordinate.alloc(xy[0],xy[1],xy[2]);
+                        wallVectorPtr.vector_pushBack(wallPtr);
+                    }
+            }else { /* error */
+                   isParseError = true;
+            }
+            
+            if(isParseError)  {/* Error */
+                System.out.println("Error: line " + lineNumber + " of " + inputFileName + "invalid");
+                System.exit(1);
+            }
+        }
+        /* iterate over lines in put file */
+      
+        in.close();
+        /* 
+         * Initialize grid contents
+         */
+        if(width < 1 || height < 1 || depth < 1) {
+            System.out.println("Error : Invalid dimensions ( " + width + ", " + height + ", "+ depth + ")");
+            System.exit(1);
+        }
+
+        Grid grid = new Grid();
+        Grid gridPtr = grid.alloc(width,height,depth);
+        this.gridPtr = gridPtr;
+        addToGrid(gridPtr,wallVectorPtr,"wall");
+        addToGrid(gridPtr,srcVectorPtr, "source");
+        addToGrid(gridPtr,dstVectorPtr, "destination");
+        System.out.println("Maze dimensions = " + width + " x " + height + " x " + depth);
+        System.out.println("Paths to route  = " + workListPtr.getSize());
+
+        /*
+         * Initialize work queue
+         */
+        List_Iter it = new List_Iter();
+        it.reset(workListPtr);
+        while(it.hasNext(workListPtr)) {
+            Pair coordinatePairPtr = (Pair)it.next(workListPtr);
+            workQueuePtr.queue_push(coordinatePairPtr);
+        }
+
+        list_t.free(workListPtr);
+
+        return srcVectorPtr.vector_getSize();
+    }
+    
+
+/* =============================================================================
+ * maze_checkPaths
+ * =============================================================================
+ bool_t maze_checkPaths (maze_t* mazePtr, list_t* pathListPtr, bool_t doPrintPaths);
+ */
+    public boolean checkPaths(List_t pathVectorListPtr,boolean doPrintPaths)
+    {
+        int i;
+       
+        /* Mark walls */
+        Grid grid = new Grid();
+        Grid testGridPtr = grid.alloc(gridPtr.width,gridPtr.height,gridPtr.depth);
+        testGridPtr.addPath(wallVectorPtr);
+
+        /* Mark sources */
+        int numSrc = srcVectorPtr.vector_getSize();
+//        System.out.println("numSrc = " +numSrc);
+//        System.exit(1);
+        for(i = 0; i < numSrc; i++) {
+            Coordinate srcPtr = (Coordinate)srcVectorPtr.vector_at(i);
+            testGridPtr.setPoint(srcPtr.x,srcPtr.y,srcPtr.z,0);
+        }
+
+        /* Mark destinations */
+        int numdst = dstVectorPtr.vector_getSize();
+        for(i = 0; i < numdst; i++) {
+            Coordinate dstPtr = (Coordinate)dstVectorPtr.vector_at(i);
+            testGridPtr.setPoint(dstPtr.x,dstPtr.y,dstPtr.z,0);
+        }
+
+//        testGridPtr.print();
+
+        /* Make sure path is contiguous and does not overlap */
+        int id = 0;
+        List_Iter it = new List_Iter();
+        it.reset(pathVectorListPtr);
+
+        int height = gridPtr.height;
+        int width = gridPtr.width;
+        int area = height * width;
+
+        while(it.hasNext(pathVectorListPtr)) {
+            Vector_t pathVectorPtr = (Vector_t)it.next(pathVectorListPtr);
+            int numPath = pathVectorPtr.vector_getSize();
+          
+            for(i = 0; i < numPath; i++) {
+                id++;
+                Vector_t pointVectorPtr = (Vector_t)pathVectorPtr.vector_at(i);
+                /* Check start */
+                int prevGridPointIndex = ((Integer)pointVectorPtr.vector_at(0)).intValue();
+
+               int z=prevGridPointIndex/area;
+               int index2d=prevGridPointIndex%area;
+               int y=index2d/width;
+               int x=index2d%width;
+
+                if(testGridPtr.getPoint(x,y,z) != 0) {
+                    return false;
+                }
+
+                Coordinate prevCoordinate = new Coordinate();
+                prevCoordinate.x = x;
+                prevCoordinate.y = y;
+                prevCoordinate.z = z;
+
+                
+                int numPoint = pointVectorPtr.vector_getSize();
+                int j;
+
+                for(j = 1; j< (numPoint - 1) ;j++) { /* no need to check endpoints */
+                    int currGridPointIndex = ((Integer)pointVectorPtr.vector_at(j)).intValue();
+                    Coordinate currCoordinate = new Coordinate();
+
+                   z=currGridPointIndex/area;
+                   index2d=currGridPointIndex%area;
+                   y=index2d/width;
+                   x=index2d%width;
+
+                    currCoordinate.x = x;
+                    currCoordinate.y = y;
+                    currCoordinate.z = z;
+
+                    if(!currCoordinate.areAdjacent(currCoordinate,prevCoordinate)) {
+                        System.out.println("you there?");
+                        return false;
+                    }
+
+                    prevCoordinate = currCoordinate;
+                    int xx = currCoordinate.x;
+                    int yy = currCoordinate.y;
+                    int zz = currCoordinate.z;
+                    if(testGridPtr.getPoint(xx,yy,zz) != GRID_POINT_EMPTY) {
+                        return false;
+                    } else {
+                        testGridPtr.setPoint(xx,yy,zz,id);
+                    }
+                }
+                /* Check end */
+                int lastGridPointIndex = ((Integer)pointVectorPtr.vector_at(j)).intValue();
+               z=lastGridPointIndex/area;
+               index2d=lastGridPointIndex%area;
+               y=index2d/width;
+               x=index2d%width;
+                if(testGridPtr.getPoint(x,y,z) != 0) {
+                    return false;
+                }
+            } /* iterate over pathVector */
+        } /* iterate over pathVectorList */
+
+        if(doPrintPaths) {
+            System.out.println("\nRouted Maze:");
+           testGridPtr.print();
+        }
+
+
+        return true;
+    }
+                    
+ }
+/* =============================================================================
+ *
+ * End of maze.h
+ *
+ * =============================================================================
+ */
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Pair.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Pair.java
new file mode 100644 (file)
index 0000000..ea735f0
--- /dev/null
@@ -0,0 +1,86 @@
+
+
+public class Pair {
+    public Object first;
+    public Object second;
+
+    public Pair() {
+        first = null;
+        second = null;
+    }
+
+
+/* =============================================================================
+ * 
+ * pair constructor
+ * 
+ * pair_t* pair_alloc(void* firstPtr, void* secondPtr);
+ * =============================================================================
+ */
+    public Pair alloc(Object first,Object second)
+    {
+        Pair ptr= new Pair();
+        ptr.first = first;
+        ptr.second = second;
+
+        return ptr;
+    }
+
+
+
+/* =============================================================================
+ * Ppair_alloc
+ *
+ * -- Returns NULL if failure
+ * =============================================================================
+ */
+  public Pair Ppair_alloc (Object firstPtr, Object secondPtr) {
+    Pair pairPtr = new Pair();       
+    pairPtr.first = firstPtr;
+    pairPtr.second = secondPtr;
+    return pairPtr;
+  }
+
+
+/* =============================================================================
+ * pair_free
+ * =============================================================================
+ *
+ *  void pair_free (pair_t* pairPtr);
+ *
+ */
+    public void free(Pair pairPtr)
+    {
+        pairPtr = null;
+    }
+
+
+/* =============================================================================
+ * Ppair_free
+ * =============================================================================
+ *
+void Ppair_free (pair_t* pairPtr);
+*/
+
+/* =============================================================================
+ * pair_swap
+ * -- Exchange 'firstPtr' and 'secondPtr'
+ * =============================================================================
+ * void pair_swap (pair_t* pairPtr);
+*/
+    public void swap(Pair pairPtr)
+    {
+        Object tmpPtr = pairPtr.first;
+
+        pairPtr.first = pairPtr.second;
+        pairPtr.second = tmpPtr;
+    }
+
+}    
+
+/* =============================================================================
+ *
+ * End of pair.java
+ *
+ * =============================================================================
+ */
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Point.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Point.java
new file mode 100644 (file)
index 0000000..8905bd5
--- /dev/null
@@ -0,0 +1,25 @@
+
+  public class Point {
+        int x;
+        int y;
+        int z;
+        int value;
+        int momentum;
+
+        public Point() {
+            x = -1;
+            y = -1;
+            z = -1;
+            value = -1;
+            momentum = -1;
+        }
+        
+        public Point(int x,int y, int z,int value, int m) {
+            this.x = x;
+            this.y = y;
+            this.z = z;
+            this.value = value;
+            momentum = m;
+        }
+    }
+
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Queue_Int.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Queue_Int.java
new file mode 100644 (file)
index 0000000..07009fd
--- /dev/null
@@ -0,0 +1,412 @@
+/* =============================================================================
+ *
+ * queue.java
+ *
+ * =============================================================================
+ *
+ * Copyright (C) Stanford University, 2006.  All Rights Reserved.
+ * Author: Chi Cao Minh
+ *
+ * Ported to Java June 2009 Alokika Dash
+ * adash@uci.edu
+ * University of California, Irvine
+ *
+ * =============================================================================
+ * 
+ * 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 Queue_Int {
+  int pop; /* points before element to pop */
+  int push;
+  int capacity;
+  int[] elements;
+
+  private int QUEUE_GROWTH_FACTOR;
+  
+  public Queue_Int() {
+         QUEUE_GROWTH_FACTOR = 2;
+  }
+
+  /* =============================================================================
+   * queue_alloc
+   * =============================================================================
+   */
+  public Queue_Int queue_alloc (int initCapacity)
+  {
+    Queue_Int queuePtr = new Queue_Int();
+
+    int capacity = ((initCapacity < 2) ? 2 : initCapacity);
+    queuePtr.elements = new int[capacity];
+    queuePtr.pop      = capacity - 1;
+    queuePtr.push     = 0;
+    queuePtr.capacity = capacity;
+
+    return queuePtr;
+  }
+
+
+  /* =============================================================================
+   * Pqueue_alloc
+   * =============================================================================
+   */
+  public Queue_Int
+    Pqueue_alloc (int initCapacity)
+    {
+      Queue_Int queuePtr = new Queue_Int();
+
+      int capacity = ((initCapacity < 2) ? 2 : initCapacity);
+      queuePtr.elements = new int[capacity];
+      queuePtr.pop      = capacity - 1;
+      queuePtr.push     = 0;
+      queuePtr.capacity = capacity;
+
+      return queuePtr;
+    }
+
+
+  /* =============================================================================
+   * TMqueue_alloc
+   * =============================================================================
+   */
+  public Queue_Int TMqueue_alloc (int initCapacity)
+  {
+    Queue_Int queuePtr = new Queue_Int();
+
+    int capacity = ((initCapacity < 2) ? 2 : initCapacity);
+    queuePtr.elements = new int[capacity];
+    queuePtr.pop      = capacity - 1;
+    queuePtr.push     = 0;
+    queuePtr.capacity = capacity;
+
+    return queuePtr;
+  }
+
+
+  /* =============================================================================
+   * queue_free
+   * =============================================================================
+   */
+  public void
+    queue_free ()
+    {
+      elements = null;
+    }
+
+
+  /* =============================================================================
+   * Pqueue_free
+   * =============================================================================
+   */
+  public void
+    Pqueue_free ()
+    {
+      elements = null;
+    }
+
+
+  /* =============================================================================
+   * TMqueue_free
+   * =============================================================================
+   */
+  public void
+    TMqueue_free ()
+    {
+      elements = null;
+    }
+
+
+  /* =============================================================================
+   * queue_isEmpty
+   * =============================================================================
+   */
+  public boolean
+    queue_isEmpty ()
+    {
+      return (((pop + 1) % capacity == push) ? true : false);
+    }
+
+
+  /* =============================================================================
+   * queue_clear
+   * =============================================================================
+   */
+  public void
+    queue_clear ()
+    {
+      pop  = capacity - 1;
+      push = 0;
+    }
+
+
+  /* =============================================================================
+   * TMqueue_isEmpty
+   * =============================================================================
+   */
+  public boolean
+    TMqueue_isEmpty (Queue_Int queuePtr)
+    {
+      int pop      = queuePtr.pop;
+      int push     = queuePtr.push;
+      int capacity = queuePtr.capacity;
+
+      return (((pop + 1) % capacity == push) ? true : false);
+    }
+
+
+  /* =============================================================================
+   * queue_push
+   * =============================================================================
+   */
+  public boolean
+    queue_push (int dataPtr)
+    {
+
+      /* Need to resize */
+      int newPush = (push + 1) % capacity;
+      if (newPush == pop) {
+
+        int newCapacity = capacity * QUEUE_GROWTH_FACTOR;
+        int[] newElements = new int[newCapacity];
+
+        int dst = 0;
+        if (pop < push) {
+          int src;
+          for (src = (pop + 1); src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        } else {
+          int src;
+          for (src = (pop + 1); src < capacity; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+          for (src = 0; src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        }
+
+        elements = newElements;
+        pop      = newCapacity - 1;
+        capacity = newCapacity;
+        push = dst;
+        newPush = push + 1; /* no need modulo */
+      }
+
+      elements[push] = dataPtr;
+      push = newPush;
+
+      return true;
+    }
+
+
+  /* =============================================================================
+   * Pqueue_push
+   * =============================================================================
+   */
+  public boolean
+    Pqueue_push (Queue_Int queuePtr, int dataPtr)
+    {
+      int pop      = queuePtr.pop;
+      int push     = queuePtr.push;
+      int capacity = queuePtr.capacity;
+
+
+      /* Need to resize */
+      int newPush = (push + 1) % capacity;
+      if (newPush == pop) {
+
+        int newCapacity = capacity * QUEUE_GROWTH_FACTOR;
+        int[] newElements = new int[newCapacity];
+
+        int dst = 0;
+        int[] elements = queuePtr.elements;
+        if (pop < push) {
+          int src;
+          for (src = (pop + 1); src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        } else {
+          int src;
+          for (src = (pop + 1); src < capacity; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+          for (src = 0; src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        }
+
+        elements = null;
+        queuePtr.elements = newElements;
+        queuePtr.pop      = newCapacity - 1;
+        queuePtr.capacity = newCapacity;
+        push = dst;
+        newPush = push + 1; /* no need modulo */
+
+      }
+
+      queuePtr.elements[push] = dataPtr;
+      queuePtr.push = newPush;
+
+      return true;
+    }
+
+
+  /* =============================================================================
+   * TMqueue_push
+   * =============================================================================
+   */
+  public boolean
+    TMqueue_push (Queue_Int queuePtr, int dataPtr)
+    {
+      int pop      = (queuePtr.pop);
+      int push     = (queuePtr.push);
+      int capacity = (queuePtr.capacity);
+
+
+      /* Need to resize */
+      int newPush = (push + 1) % capacity;
+      if (newPush == pop) {
+        int newCapacity = capacity * QUEUE_GROWTH_FACTOR;
+        int[] newElements = new int[newCapacity];
+
+        int dst = 0;
+        int[] elements = queuePtr.elements;
+        if (pop < push) {
+          int src;
+          for (src = (pop + 1); src < push; src++, dst++) {
+            newElements[dst] = (elements[src]);
+          }
+        } else {
+          int src;
+          for (src = (pop + 1); src < capacity; src++, dst++) {
+            newElements[dst] = (elements[src]);
+          }
+          for (src = 0; src < push; src++, dst++) {
+            newElements[dst] = (elements[src]);
+          }
+        }
+
+        elements = null;
+        queuePtr.elements = newElements;
+        queuePtr.pop      = newCapacity - 1;
+        queuePtr.capacity = newCapacity;
+        push = dst;
+        newPush = push + 1; /* no need modulo */
+
+      }
+
+      int[] elements = queuePtr.elements;
+      elements[push] = dataPtr;
+      queuePtr.push = newPush;
+
+      return true;
+    }
+
+
+  /* =============================================================================
+   * queue_pop
+   * =============================================================================
+   */
+  public int
+    queue_pop ()
+    {
+      int newPop = (pop + 1) % capacity;
+      if (newPop == push) {
+        return 0;
+      }
+
+      int dataPtr = elements[newPop];
+      pop = newPop;
+
+      return dataPtr;
+    }
+
+
+  /* =============================================================================
+   * TMqueue_pop
+   * =============================================================================
+   */
+  public int
+    TMqueue_pop (Queue_Int queuePtr)
+    {
+      int pop      = queuePtr.pop;
+      int push     = queuePtr.push;
+      int capacity = queuePtr.capacity;
+
+      int newPop = (pop + 1) % capacity;
+      if (newPop == push) {
+        return 0;
+      }
+
+      int[] elements = queuePtr.elements;
+      int dataPtr = elements[newPop];
+      queuePtr.pop = newPop;
+
+      return dataPtr;
+    }
+
+  /****
+   * main method for testing
+   **/
+  /*
+     public static void main(String[] args) {
+     testQueue queuePtr = testQueue.queue_alloc(-1);
+     int numData = 4;
+     if(queuePtr.queue_isEmpty())
+     System.out.println("Queue is empty");
+
+     for(int i = 0; i<numData; i++) {
+     System.out.println("Inserting " + i);
+     queuePtr.queue_push(i);
+     }
+
+     for(int i = 0; i<numData; i++) {
+     int val = queuePtr.queue_pop();
+     System.out.println("Removing " + val);
+     }
+
+     if(queuePtr.queue_isEmpty())
+     System.out.println("Queue is empty");
+     }
+     */
+}
+/* =============================================================================
+ *
+ * End of queue.java
+ *
+ * =============================================================================
+ */
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Queue_t.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Queue_t.java
new file mode 100644 (file)
index 0000000..6f642f2
--- /dev/null
@@ -0,0 +1,308 @@
+/* =============================================================================
+ *
+ * queue.java
+ *
+ * =============================================================================
+ *
+ * Copyright (C) Stanford University, 2006.  All Rights Reserved.
+ * Author: Chi Cao Minh
+ *
+ * Ported to Java
+ * Author:Alokika Dash
+ * University of California, Irvine
+ *
+ * =============================================================================
+ * 
+ * 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 Queue_t {
+  int pop; /* points before element to pop */
+  int push;
+  int capacity;
+  Object[] elements;
+  
+  private int QUEUE_GROWTH_FACTOR;
+
+  public Queue_t() {
+         QUEUE_GROWTH_FACTOR = 2;
+  }
+
+  /* =============================================================================
+   * queue_alloc
+   * =============================================================================
+   */
+  public Queue_t queue_alloc (int initCapacity)
+  {
+    Queue_t queuePtr = new Queue_t();
+
+    int capacity = ((initCapacity < 2) ? 2 : initCapacity);
+    queuePtr.elements = new Object[capacity];
+    queuePtr.pop      = capacity - 1;
+    queuePtr.push     = 0;
+    queuePtr.capacity = capacity;
+
+    return queuePtr;
+  }
+
+
+  /* =============================================================================
+   * Pqueue_alloc
+   * =============================================================================
+   */
+  public Queue_t
+    Pqueue_alloc (int initCapacity)
+    {
+      Queue_t queuePtr = new Queue_t();
+
+      int capacity = ((initCapacity < 2) ? 2 : initCapacity);
+      queuePtr.elements = new Object[capacity];
+      queuePtr.pop      = capacity - 1;
+      queuePtr.push     = 0;
+      queuePtr.capacity = capacity;
+
+      return queuePtr;
+    }
+
+  /* =============================================================================
+   * queue_free
+   * =============================================================================
+   */
+  public void
+    queue_free (Queue_t queuePtr)
+    {
+      queuePtr.elements = null;
+      queuePtr = null;
+    }
+
+
+  /* =============================================================================
+   * Pqueue_free
+   * =============================================================================
+   */
+  public void
+    Pqueue_free (Queue_t queuePtr)
+    {
+      queuePtr.elements = null;
+      queuePtr = null;
+    }
+
+
+  /* =============================================================================
+   * TMqueue_free
+   * =============================================================================
+   *
+  public void
+    TMqueue_free (TM_ARGDECL  Queue* queuePtr)
+    {
+      queuePtr.elements = null;
+      queuePtr = null;
+    }
+
+*/
+  /* =============================================================================
+   * queue_isEmpty
+   * =============================================================================
+   */
+  public boolean
+    queue_isEmpty ()
+    {
+      //int pop      = queuePtr.pop;
+      //int push     = queuePtr.push;
+      //int capacity = queuePtr.capacity;
+
+      return (((pop + 1) % capacity == push) ? true : false);
+    }
+
+
+  /* =============================================================================
+   * queue_clear
+   * =============================================================================
+   */
+  public void
+    queue_clear ()
+    {
+      pop  = capacity - 1;
+      push = 0;
+    }
+
+
+  /* =============================================================================
+   * TMqueue_isEmpty
+   * =============================================================================
+   */
+
+
+
+  /* =============================================================================
+   * queue_push
+   * =============================================================================
+   */
+  public boolean
+    queue_push (Object dataPtr)
+    {
+    
+
+      /* Need to resize */
+      int newPush = (push + 1) % capacity;
+      if (newPush == pop) {
+
+        int newCapacity = capacity * QUEUE_GROWTH_FACTOR;
+        Object[] newElements = new Object[newCapacity];
+
+        int dst = 0;
+        if (pop < push) {
+          int src;
+          for (src = (pop + 1); src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        } else {
+          int src;
+          for (src = (pop + 1); src < capacity; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+          for (src = 0; src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        }
+
+        //elements = null;
+        elements = newElements;
+        pop      = newCapacity - 1;
+        capacity = newCapacity;
+        push = dst;
+        newPush = push + 1; /* no need modulo */
+      }
+
+      elements[push] = dataPtr;
+      push = newPush;
+
+      return true;
+    }
+
+
+  /* =============================================================================
+   * Pqueue_push
+   * =============================================================================
+   */
+  public boolean
+    Pqueue_push (Queue_t queuePtr, Object dataPtr)
+    {
+      int pop      = queuePtr.pop;
+      int push     = queuePtr.push;
+      int capacity = queuePtr.capacity;
+
+
+      /* Need to resize */
+      int newPush = (push + 1) % capacity;
+      if (newPush == pop) {
+
+        int newCapacity = capacity * QUEUE_GROWTH_FACTOR;
+        Object[] newElements = new Object[newCapacity];
+        int dst = 0;
+        Object[] elements = queuePtr.elements;
+        if (pop < push) {
+          int src;
+          for (src = (pop + 1); src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        } else {
+          int src;
+          for (src = (pop + 1); src < capacity; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+          for (src = 0; src < push; src++, dst++) {
+            newElements[dst] = elements[src];
+          }
+        }
+
+        elements = null;
+        queuePtr.elements = newElements;
+        queuePtr.pop      = newCapacity - 1;
+        queuePtr.capacity = newCapacity;
+        push = dst;
+        newPush = push + 1; /* no need modulo */
+
+      }
+
+      queuePtr.elements[push] = dataPtr;
+      queuePtr.push = newPush;
+
+      return true;
+    }
+
+  /* =============================================================================
+   * queue_pop
+   * =============================================================================
+   */
+  public Object
+    //queue_pop (Queue queuePtr)
+    queue_pop ()
+    {
+      //int pop      = queuePtr.pop;
+      //int push     = queuePtr.push;
+      //int capacity = queuePtr.capacity;
+
+      int newPop = (pop + 1) % capacity;
+      if (newPop == push) {
+        return null;
+      }
+
+      //Object dataPtr = queuePtr.elements[newPop];
+      //queuePtr.pop = newPop;
+      Object dataPtr = elements[newPop];
+      pop = newPop;
+
+      return dataPtr;
+    }
+  
+  public Queue_t queue_getUpTo(int num) 
+  {
+       Queue_t subset = Pqueue_alloc(num + 2);
+       Object pop;
+       
+       for(int i = 0; i < num && (pop = queue_pop()) != null; i++)
+               subset.queue_push(pop);
+       
+       return subset;
+  }
+
+}
+/* =============================================================================
+ *
+ * End of queue.java
+ *
+ * =============================================================================
+ */
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Router.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Router.java
new file mode 100644 (file)
index 0000000..4c7e05f
--- /dev/null
@@ -0,0 +1,453 @@
+/* =============================================================================
+ *
+ * Router.java
+ *
+ * =============================================================================
+ *
+ * Copyright (C) Stanford University, 2006.  All Rights Reserved.
+ * Author: Chi Cao Minh
+ * 
+ * Ported to Java
+ * Author: Jihoon Lee
+ * University of California, Irvine
+ * 
+ * rBlock Compilation
+ * Author: Stephen Yang
+ * University of California, Irvine
+ *
+ * =============================================================================
+ *
+ * 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 Router {
+    public int xCost;
+    public int yCost;
+    public int zCost;
+    public int bendCost;
+    public Point MOVE_POSX;
+    public Point MOVE_POSY;
+    public Point MOVE_POSZ;
+    public Point MOVE_NEGX;
+    public Point MOVE_NEGY;
+    public Point MOVE_NEGZ;
+    
+       private int  MOMENTUM_ZERO;
+       private int  MOMENTUM_POSX;
+       private int  MOMENTUM_POSY;
+       private int  MOMENTUM_POSZ;
+       private int  MOMENTUM_NEGX;
+       private int  MOMENTUM_NEGY;
+       private int  MOMENTUM_NEGZ;
+       private int  GRID_POINT_FULL;
+       private int  GRID_POINT_EMPTY;
+
+    public Router() {
+       //Replaced #defines
+       MOMENTUM_ZERO = 0;
+       MOMENTUM_POSX = 1;
+       MOMENTUM_POSY = 2;
+       MOMENTUM_POSZ = 3;
+       MOMENTUM_NEGX = 4;
+       MOMENTUM_NEGY = 5;
+       MOMENTUM_NEGZ = 6;
+       GRID_POINT_FULL = -2;
+       GRID_POINT_EMPTY = -1;
+    }
+
+/* =============================================================================
+ * router_alloc
+ * =============================================================================
+ * router_t* router_alloc (long xCost, long yCost, long zCost, long bendCost);
+ */
+  public Router alloc(int xCost,int yCost,int zCost,int bendCost) {
+    Router routerPtr = new Router();
+
+    
+    routerPtr.MOVE_POSX = new Point(1,0,0,0,MOMENTUM_POSX);
+    routerPtr.MOVE_POSY = new Point(0,1,0,0,MOMENTUM_POSY);
+    routerPtr.MOVE_POSZ = new Point(0,0,1,0,MOMENTUM_POSZ);
+    routerPtr.MOVE_NEGX = new Point(-1,0,0,0,MOMENTUM_NEGX);
+    routerPtr.MOVE_NEGY = new Point(0,-1,0,0,MOMENTUM_NEGY);
+    routerPtr.MOVE_NEGZ = new Point(0,0,-1,0,MOMENTUM_NEGZ);
+
+    routerPtr.xCost = xCost;
+    routerPtr.yCost = yCost;
+    routerPtr.zCost = zCost;
+    routerPtr.bendCost = bendCost;
+    
+    return routerPtr;    
+  }
+
+
+/* ============================================================================
+ * PexpandToneighbor
+ * ============================================================================
+ */
+  private void PexpandToNeighbor(Grid myGridPtr, 
+                                int x,int y,int z, int value,Queue_Int queuePtr) {
+    if (myGridPtr.isPointValid(x,y,z)) {
+      int neighborValue = myGridPtr.points_unaligned[x][y][z];
+      if (neighborValue == GRID_POINT_EMPTY) {
+       int neighborGridPointIndex = myGridPtr.getPointIndex(x,y,z);
+       myGridPtr.points_unaligned[x][y][z] = value;
+       queuePtr.queue_push(neighborGridPointIndex);
+      } else if (neighborValue != GRID_POINT_FULL) {
+       if (value < neighborValue) {
+         int neighborGridPointIndex = myGridPtr.getPointIndex(x,y,z);
+         myGridPtr.points_unaligned[x][y][z] = value;
+         queuePtr.queue_push(neighborGridPointIndex);
+       }
+      }
+    }
+  }
+
+
+/* ============================================================================
+ * PdoExpansion
+ * ============================================================================
+ */
+    public boolean PdoExpansion (Router routerPtr,Grid myGridPtr,Queue_Int queuePtr,
+                                  Coordinate srcPtr,Coordinate dstPtr) {
+        int xCost = routerPtr.xCost;
+        int yCost = routerPtr.yCost;
+        int zCost = routerPtr.zCost;
+
+        /* 
+         * Potential Optimization: Make 'src' the one closet to edge.
+         * This will likely decrease the area of the emitted wave.
+         */
+
+        queuePtr.queue_clear();
+
+        int srcGridPointIndex = myGridPtr.getPointIndex(srcPtr.x,srcPtr.y,srcPtr.z);
+
+        queuePtr.queue_push(srcGridPointIndex);
+
+        myGridPtr.setPoint(srcPtr.x,srcPtr.y,srcPtr.z,0);
+        myGridPtr.setPoint(dstPtr.x,dstPtr.y,dstPtr.z,GRID_POINT_EMPTY);
+        int dstGridPointIndex = myGridPtr.getPointIndex(dstPtr.x,dstPtr.y,dstPtr.z);
+        boolean isPathFound = false;
+       int height = myGridPtr.height;
+       int width = myGridPtr.width;
+       int area = height * width;
+        while (!queuePtr.queue_isEmpty()) {
+            int gridPointIndex = queuePtr.queue_pop();
+
+            if(gridPointIndex == dstGridPointIndex) {
+             isPathFound = true;
+             break;
+            }
+           
+           int z = gridPointIndex / area;
+           int index2d = gridPointIndex % area;
+           int y = index2d / width;
+           int x = index2d % width;        
+           int value = myGridPtr.points_unaligned[x][y][z];
+           
+            /*
+             * Check 6 neighbors
+             *
+             * Potential Optimization: Only need to check 5 of these
+             */
+           PexpandToNeighbor(myGridPtr, x+1, y,   z,   (value + xCost), queuePtr);
+           PexpandToNeighbor(myGridPtr, x-1, y,   z,   (value + xCost), queuePtr);
+           PexpandToNeighbor(myGridPtr, x, y+1,   z,   (value + yCost), queuePtr);
+           PexpandToNeighbor(myGridPtr, x, y-1,   z,   (value + yCost), queuePtr);   
+           PexpandToNeighbor(myGridPtr, x, y,   z+1,   (value + zCost), queuePtr);
+           PexpandToNeighbor(myGridPtr, x, y,   z-1,   (value + zCost), queuePtr);
+           
+        } /* iterate over work queue */
+       
+        return isPathFound;
+    }
+            
+            
+/* ============================================================================
+ * traceToNeighbor
+ * ============================================================================
+ */
+    private void traceToNeighbor(Grid myGridPtr,
+                                 Point currPtr,
+                                 Point movePtr,
+                                 boolean useMomentum,
+                                 int bendCost,
+                                 Point nextPtr)
+    {
+      int x = currPtr.x + movePtr.x;
+      int y = currPtr.y + movePtr.y;
+      int z = currPtr.z + movePtr.z;
+
+        if (myGridPtr.isPointValid(x,y,z) &&
+                !myGridPtr.isPointEmpty(x,y,z) &&
+                !myGridPtr.isPointFull(x,y,z))
+        {
+            int value = myGridPtr.getPoint(x,y,z);
+            int b = 0;
+            
+            if (useMomentum && (currPtr.momentum != movePtr.momentum)) {
+                b = bendCost;
+            }
+            if ((value + b) <= nextPtr.value) { /* '=' favors neighbors over current */
+                nextPtr.x = x;
+                nextPtr.y = y;
+                nextPtr.z = z;
+                nextPtr.value = value;
+                nextPtr.momentum = movePtr.momentum;
+            }
+        }
+    }
+/* =============================================================================
+ * PdoTraceback
+ * =============================================================================
+ */
+
+    private Vector_t PdoTraceback(Grid myGridPtr,
+                                  Coordinate dstPtr, int bendCost) {
+       Vector_t vector_t = new Vector_t();
+        Vector_t pointVectorPtr = vector_t.vector_alloc(1);
+
+        Point next = new Point();
+        next.x = dstPtr.x;
+        next.y = dstPtr.y;
+        next.z = dstPtr.z;
+        next.value = myGridPtr.getPoint(next.x,next.y,next.z);
+        next.momentum = MOMENTUM_ZERO;
+
+        while(true) {
+            int gridPointIndex = myGridPtr.getPointIndex(next.x,next.y,next.z);
+            pointVectorPtr.vector_pushBack(new Integer(gridPointIndex));
+            myGridPtr.setPoint(next.x,next.y,next.z,GRID_POINT_FULL);
+
+            /* Check if we are done */
+            if (next.value == 0) {
+                break;
+            }
+            Point curr = new Point();
+            curr.x = next.x;
+            curr.y = next.y;
+            curr.z = next.z;
+            curr.value = next.value;
+            curr.momentum = next.momentum;
+
+            /*
+             * Check 6 neibors
+             */
+
+            traceToNeighbor(myGridPtr,curr,MOVE_POSX,true, bendCost, next);
+            traceToNeighbor(myGridPtr,curr,MOVE_POSY,true, bendCost, next);   
+            traceToNeighbor(myGridPtr,curr,MOVE_POSZ,true, bendCost, next);
+            traceToNeighbor(myGridPtr,curr,MOVE_NEGX,true, bendCost, next); 
+            traceToNeighbor(myGridPtr,curr,MOVE_NEGY,true, bendCost, next);           
+            traceToNeighbor(myGridPtr,curr,MOVE_NEGZ,true, bendCost, next);          
+            /* 
+             * Because of bend costs, none of the neighbors may appear to be closer.
+             * In this case, pick a neighbor while ignoring momentum.
+             */
+
+
+            
+            if ((curr.x == next.x) &&
+                (curr.y == next.y) &&
+                (curr.z == next.z)) {
+                next.value = curr.value;
+                traceToNeighbor(myGridPtr,curr,MOVE_POSX,false, bendCost, next);
+                traceToNeighbor(myGridPtr,curr,MOVE_POSY,false, bendCost, next);
+                traceToNeighbor(myGridPtr,curr,MOVE_POSZ,false, bendCost, next);
+                traceToNeighbor(myGridPtr,curr,MOVE_NEGX,false, bendCost, next);
+                traceToNeighbor(myGridPtr,curr,MOVE_NEGY,false, bendCost, next);
+                traceToNeighbor(myGridPtr,curr,MOVE_NEGZ,false, bendCost, next);
+                
+                if ((curr.x == next.x) &&
+                    (curr.y == next.y) &&
+                    (curr.z == next.z)) {
+                    System.out.println("Dead");
+                    return null;
+                }
+            }
+        }
+
+        return pointVectorPtr;
+    }
+
+/* =============================================================================
+ * router_solve
+ * =============================================================================
+ * void router_solve (void* argPtr);
+ */
+    public void solve(Object argPtr) 
+    {
+       
+        Solve_Arg routerArgPtr = (Solve_Arg) argPtr;
+        Router routerPtr = routerArgPtr.routerPtr;
+        Maze mazePtr = routerArgPtr.mazePtr;
+        int workload = routerArgPtr.rblock_workload;
+        List_t pathVectorListPtr = routerArgPtr.pathVectorListPtr; 
+
+        Queue_t masterWorkQueuePtr = mazePtr.workQueuePtr;
+        Grid masterGridPtr = mazePtr.gridPtr; 
+        int bendCost = routerPtr.bendCost;
+
+        int id = 0;
+
+        while(!masterWorkQueuePtr.queue_isEmpty())
+        {
+               Queue_t redoQueue = masterWorkQueuePtr.Pqueue_alloc(masterWorkQueuePtr.capacity);
+               
+               while(!masterWorkQueuePtr.queue_isEmpty())
+               {
+                       //moved to outside rBlock due to potential r/w conflicts 
+                       Queue_t localWorkQueue = masterWorkQueuePtr.queue_getUpTo(workload);
+                       System.out.println("Got work!");
+                       
+                       sese P
+                       {
+                               //Clone needed since new paths are added to local Grid. Cannot add to master Grid because of rBlock p conflicts
+                               Grid MGClone  = masterGridPtr.alloc(masterGridPtr.width, masterGridPtr.height, masterGridPtr.depth);
+                               masterGridPtr.copy(MGClone, masterGridPtr);
+                               
+                               Vector_t computedPaths = solveLogic(localWorkQueue, MGClone, routerPtr, bendCost, workload);
+                       }
+               
+               sese S
+               {
+                       Vector_t sucessfulPaths = computedPaths.vector_alloc(workload);
+                       
+                       CoordPathWrapper singlePathSolution = (CoordPathWrapper) computedPaths.vector_popBack();
+                       while(singlePathSolution != null)
+                       {
+                               if(masterGridPtr.TM_addPath(singlePathSolution.pathVector))
+                                       //fail
+                                       redoQueue.queue_push(singlePathSolution.coordinatePair);
+                               else //success
+                                   {
+                                       sucessfulPaths.vector_pushBack(singlePathSolution.pathVector);
+                                       System.out.println("Path # " + ++id + " added sucessfully!");
+                                   }
+                               
+                               singlePathSolution = (CoordPathWrapper)computedPaths.vector_popBack(); 
+                       }
+                       
+                       pathVectorListPtr.insert(sucessfulPaths);
+               }
+               }
+               masterWorkQueuePtr = redoQueue;
+        }
+    }
+    
+    private Vector_t solveLogic(Queue_t localWorkQueue, Grid MGCopyPtr, Router routerPtr, int bendCost, int workload)
+    {
+        /*
+         * Iterate over work list to route each path. This involves an
+         * 'expansion' and 'traceback' phase for each source/destination pair.
+         */
+
+       Vector_t vector_t = new Vector_t();
+       Queue_Int queue_int = new Queue_Int();
+        Vector_t computedPathsPtr = vector_t.vector_alloc(workload + 2);
+        while(true) {
+            Pair coordinatePairPtr;
+            Queue_Int myExpansionQueuePtr = queue_int.queue_alloc(-1);
+            
+            if(localWorkQueue.queue_isEmpty()) {
+               coordinatePairPtr = null;
+            } 
+            else {
+               coordinatePairPtr = (Pair)localWorkQueue.queue_pop();
+            }
+            
+            if (coordinatePairPtr == null)
+                break;
+
+            Coordinate srcPtr = (Coordinate)coordinatePairPtr.first;
+            Coordinate dstPtr = (Coordinate)coordinatePairPtr.second;
+
+//            System.out.println("SRC x = " + srcPtr.x + "  y = " + srcPtr.y + " z = " +srcPtr.z);
+            Vector_t pointVectorPtr = null;
+               
+            //Copy needed here since PdoExpansion fills grid with misc data
+            Grid tempGrid = MGCopyPtr.alloc(MGCopyPtr.width,MGCopyPtr.height,MGCopyPtr.depth);
+            MGCopyPtr.copy(tempGrid, MGCopyPtr); /* ok if not most up-to-date */
+      
+               if(routerPtr.PdoExpansion(routerPtr,tempGrid,myExpansionQueuePtr,srcPtr,dstPtr)) {
+                       pointVectorPtr = routerPtr.PdoTraceback(tempGrid,dstPtr,bendCost);
+                       if (pointVectorPtr != null) {
+                               //Cannot add to master grid as original due to rBlocks conflicting
+                               if (MGCopyPtr.TM_addPath(pointVectorPtr)) {
+                                       pointVectorPtr=null;
+                               }
+                               else
+                               {
+                                       //Success!
+                                       CoordPathWrapper currPath = new CoordPathWrapper(coordinatePairPtr, pointVectorPtr);
+                                       computedPathsPtr.vector_pushBack(currPath);
+                               }
+                       }
+               }
+        }
+        
+        return computedPathsPtr;
+    }
+}
+/* =============================================================================
+ *
+ * End of router.java
+ * 
+ * =============================================================================
+ */
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Solve_Arg.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Solve_Arg.java
new file mode 100644 (file)
index 0000000..b1ccee5
--- /dev/null
@@ -0,0 +1,16 @@
+public class Solve_Arg 
+{
+    Router routerPtr;
+    Maze mazePtr;
+    List_t pathVectorListPtr;
+    int rblock_workload;
+
+    public Solve_Arg(Router r,Maze m,List_t l, int workload)
+    {
+        routerPtr = r;
+        mazePtr = m;
+        pathVectorListPtr = l;
+        rblock_workload = workload;
+    }
+}
+
diff --git a/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Vector_t.java b/Robust/src/Benchmarks/Java-Single/Labyrinth3D/mlp/rBlocked/Vector_t.java
new file mode 100644 (file)
index 0000000..1fd44ba
--- /dev/null
@@ -0,0 +1,140 @@
+public class Vector_t {
+  int size;
+  int capacity;
+  Object[] elements;
+//  QuickSort qsort;
+
+  public Vector_t() {
+//    qsort = new QuickSort();
+  }
+
+  /* =============================================================================
+   * Vector_alloc
+   * -- Returns null if failed
+   * =============================================================================
+   */
+  public Vector_t vector_alloc (int initCapacity) {
+    int capacity = Math.imax(initCapacity, 1);
+    Vector_t vectorPtr = new Vector_t();
+    vectorPtr.capacity = capacity;
+    vectorPtr.elements = new Object[capacity];
+    return vectorPtr;
+  }
+
+  /* =============================================================================
+   * Vector_free
+   * =============================================================================
+   */
+  public void
+    vector_free ()
+    {
+      elements = null;
+    }
+
+  /* =============================================================================
+   * Vector_at
+   * -- Returns null if failed
+   * =============================================================================
+   */
+  public Object vector_at (int i) {
+    return (elements[i]);
+  }
+
+
+  /* =============================================================================
+   * Vector_pushBack
+   * -- Returns false if fail, else true
+   * =============================================================================
+   */
+  public boolean vector_pushBack (Object dataPtr) {
+    if (size == capacity) {
+      int newCapacity = capacity * 2;
+      Object[] newElements = new Object[newCapacity];
+
+      //void** newElements = (void**)malloc(newCapacity * sizeof(void*));
+      capacity = newCapacity;
+      for (int i = 0; i < size; i++) {
+        newElements[i] = elements[i];
+      }
+      elements = null;
+      elements = newElements;
+    }
+
+    elements[size++] = dataPtr;
+
+    return true;
+  }
+
+  /* =============================================================================
+   * Vector_popBack
+   * -- Returns null if fail, else returns last element
+   * =============================================================================
+   */
+  public Object
+    vector_popBack ()
+    {
+      if (size < 1) {
+        return null;
+      }
+
+      return (elements[--(size)]);
+    }
+
+  /* =============================================================================
+   * Vector_getSize
+   * =============================================================================
+   */
+  public int
+    vector_getSize ()
+    {
+      return (size);
+    }
+
+  /* =============================================================================
+   * Vector_clear
+   * =============================================================================
+   */
+  public void
+    vector_clear ()
+    {
+      size = 0;
+    }
+  
+  /* =============================================================================
+   * Vector_sort
+   * =============================================================================
+   *
+  public void
+    vector_sort ()
+    {
+      //qsort.sort(elements, 0, (elements.length - 1));
+      qsort.sort(elements);
+      //qsort(elements, size, 4, compare);
+    }
+
+  * =============================================================================
+   * Vector_copy
+   * =============================================================================
+   */
+  public static boolean
+    vector_copy (Vector_t dstVectorPtr, Vector_t srcVectorPtr)
+    {
+      int dstCapacity = dstVectorPtr.capacity;
+      int srcSize = srcVectorPtr.size;
+      if (dstCapacity < srcSize) {
+        int srcCapacity = srcVectorPtr.capacity;
+        Object[] elements = new Object[srcCapacity];
+        dstVectorPtr.elements = null;
+        dstVectorPtr.elements = elements;
+        dstVectorPtr.capacity = srcCapacity;
+      }
+
+      for(int i = 0; i< srcSize; i++) {
+        dstVectorPtr.elements[i] = srcVectorPtr.elements[i];
+      }
+
+      dstVectorPtr.size = srcSize;
+
+      return true;
+    }
+}