--- /dev/null
+/* =============================================================================
+ *
+ * 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;
+
+ }
+
+}
--- /dev/null
+/* =============================================================================
+ *
+ * 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
+ *
+ *====================================================*/
+
+
--- /dev/null
+/* =============================================================================
+ *
+ * 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
+ *
+ * =============================================================================
+ */
--- /dev/null
+/* =============================================================================
+ *
+ * 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 = 20;
+ }
+
+ private void parseArg(String[] argv) {
+ int i=0;
+ String arg;
+ boolean opterr = false;
+
+
+ setDefaultParams();
+
+ while (i < argv.length) {
+
+ if(argv[i].charAt(0) == '-' ) {
+ arg = argv[i++];
+ // check options
+ if(arg.equals("-b")) {
+ bendCost = Integer.parseInt(argv[i++]);
+ }
+ else if(arg.equals("-x")) {
+ xCost = Integer.parseInt(argv[i++]);
+ }
+ else if(arg.equals("-y")) {
+ yCost = Integer.parseInt(argv[i++]);
+ }
+ else if(arg.equals("-z")) {
+ zCost = Integer.parseInt(argv[i++]);
+ }
+ else if(arg.equals("-t")) {
+ numThread = Integer.parseInt(argv[i++]);
+ }
+ else if(arg.equals("-i")) {
+ global_inputFile = argv[i++];
+ }
+ else if(arg.equals("-p")) {
+ global_doPrint = true;
+ }
+ else if(arg.equals("-w")){
+ global_workload = Integer.parseInt(argv[i++]);
+ }
+ else {
+ System.out.println("Non-option argument: " + argv[i]);
+ opterr = true;
+ }
+
+ }
+ }
+ if(opterr) {
+ displayUsage();
+ System.exit(1);
+ }
+ }
+
+ public Labyrinth(String[] argv)
+ {
+ parseArg(argv);
+ }
+
+
+ public Labyrinth(int myID,Solve_Arg rArg)
+ {
+ threadID = myID;
+ routerArg = rArg;
+ }
+
+ public 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
+ *
+ * =============================================================================
+ */
--- /dev/null
+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;
+ }
+}
+
--- /dev/null
+
+public class List_Node {
+ Object dataPtr;
+ List_Node nextPtr;
+
+ public List_Node() {
+ dataPtr = null;
+ nextPtr = null;
+ }
+}
--- /dev/null
+/* =============================================================================
+ *
+ * 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...");
+// }
+//
+}
+
+
+
--- /dev/null
+/*=============================================================================
+ *
+ * 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
+ *
+ * =============================================================================
+ */
--- /dev/null
+
+
+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
+ *
+ * =============================================================================
+ */
--- /dev/null
+
+ 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;
+ }
+ }
+
--- /dev/null
+/* =============================================================================
+ *
+ * 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
+ *
+ * =============================================================================
+ */
--- /dev/null
+/* =============================================================================
+ *
+ * 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
+ *
+ * =============================================================================
+ */
--- /dev/null
+/* =============================================================================
+ *
+ * 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)
+ {
+
+ // initialization
+ Solve_Arg routerArgPtr = (Solve_Arg) argPtr;
+ Router routerPtr = routerArgPtr.routerPtr;
+ Maze mazePtr = routerArgPtr.mazePtr;
+ int workload = routerArgPtr.rblock_workload;
+ int bendCost = routerPtr.bendCost;
+ List_t pathVectorListPtr = routerArgPtr.pathVectorListPtr;
+ Queue_t masterWorkQueue = mazePtr.workQueuePtr;
+ Grid masterGrid=mazePtr.gridPtr;
+ Queue_Int queue_int=new Queue_Int();
+ Vector_t vt=new Vector_t();
+
+ Vector_t pathArray[]=new Vector_t[workload];
+ Grid gridArray[]=new Grid[workload];
+ Pair workItemArray[]=new Pair[workload];
+
+// for(int i=0;i<gridArray.length;i++){
+// gridArray[i]=masterGrid.scratchalloc(masterGrid.width, masterGrid.height, masterGrid.depth);
+// }
+
+ while(!masterWorkQueue.queue_isEmpty()){
+ Vector_t myPathVectorPtr=vt.vector_alloc(workload);
+ //System.out.println("\nnew round");
+ for(int i=0;i<workload;i++){
+ pathArray[i]=null;
+ }
+
+ //gets work item
+ for(int i=0;i<workload;i++){
+ Pair coordinatePairPtr=null;
+ if(!masterWorkQueue.queue_isEmpty()){
+ coordinatePairPtr=(Pair)masterWorkQueue.queue_pop();
+ }
+ workItemArray[i]=coordinatePairPtr;
+ }
+
+ //parallel loop
+ for(int i=0;i<workload;i++){
+
+ Pair coordinatePairPtr=workItemArray[i];
+ if(coordinatePairPtr==null){
+ break;
+ }
+ Coordinate srcPtr = (Coordinate) coordinatePairPtr.first;
+ Coordinate dstPtr = (Coordinate) coordinatePairPtr.second;
+
+ // not using scratch pad
+// Grid myGrid=gridArray[i];
+
+ Vector_t path=null;
+ sese parallel{
+ //allocate grid, not using scratch pad
+ Grid myGrid=masterGrid.alloc(masterGrid.width, masterGrid.height, masterGrid.depth);
+ myGrid.copy(myGrid, masterGrid);
+ Queue_Int myExpansionQueuePtr=queue_int.queue_alloc(-1);
+ if(routerPtr.PdoExpansion(routerPtr, myGrid, myExpansionQueuePtr, srcPtr, dstPtr)){
+ path=routerPtr.PdoTraceback(myGrid, dstPtr, bendCost);
+ }
+ }
+ sese serial{
+ pathArray[i]=path;
+ }
+ }
+
+ //check path
+ for(int i=0;i<workload;i++){
+ if(pathArray[i]!=null){
+ if(masterGrid.TM_addPath(pathArray[i])){
+ //fail
+ //System.out.print("F ");
+ masterWorkQueue.queue_push(workItemArray[i]);
+ }else{
+ //success
+ //System.out.print("S ");
+ myPathVectorPtr.vector_pushBack(pathArray[i]);
+ }
+ }
+ }
+ pathVectorListPtr.insert(myPathVectorPtr);
+ }
+
+ }
+}
+/*
+ * =============================================================================
+ *
+ * End of router.java
+ *
+ * =============================================================================
+ */
--- /dev/null
+/* =============================================================================
+ *
+ * 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)
+ {
+ //Grabs Data
+ Solve_Arg routerArgPtr = (Solve_Arg) argPtr;
+ Router routerPtr = routerArgPtr.routerPtr;
+ Maze mazePtr = routerArgPtr.mazePtr;
+ int bendCost = routerPtr.bendCost;
+ List_t pathVectorListPtr = routerArgPtr.pathVectorListPtr;
+ Queue_t masterWorkQueue = mazePtr.workQueuePtr;
+ Grid masterGrid=mazePtr.gridPtr;
+ Queue_Int queue_int=new Queue_Int();
+ Vector_t vt=new Vector_t();
+
+ //initialization
+ Grid myGrid = masterGrid.scratchalloc(masterGrid.width, masterGrid.height, masterGrid.depth);
+ Vector_t myPathVectorPtr=vt.vector_alloc(-1);
+
+
+ while(!masterWorkQueue.queue_isEmpty()){
+ Pair coordinatePairPtr =(Pair)masterWorkQueue.queue_pop();
+ if(coordinatePairPtr == null)
+ break;
+
+ Coordinate srcPtr = (Coordinate) coordinatePairPtr.first;
+ Coordinate dstPtr = (Coordinate) coordinatePairPtr.second;
+ myGrid.copy(myGrid, masterGrid);
+
+ Queue_Int myExpansionQueuePtr=queue_int.queue_alloc(-1);
+ if(routerPtr.PdoExpansion(routerPtr, myGrid, myExpansionQueuePtr, srcPtr, dstPtr)){
+ Vector_t path = routerPtr.PdoTraceback(myGrid, dstPtr, bendCost);
+
+ //if successful
+ if(path != null && !masterGrid.TM_addPath(path))
+ myPathVectorPtr.vector_pushBack(path);
+ }
+ }
+
+ pathVectorListPtr.insert(myPathVectorPtr);
+ }
+}
+/*
+ * =============================================================================
+ *
+ * End of router.java
+ *
+ * =============================================================================
+ */
--- /dev/null
+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;
+ }
+}
+
--- /dev/null
+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;
+ }
+}
--- /dev/null
+PROGRAM=Labyrinth
+
+SOURCE_FILES=Coordinate.java CoordPathWrapper.java Grid.java Labyrinth.java List_Iter.java List_Node.java List_t.java Maze.java Pair.java Point.java Queue_Int.java Queue_t.java Router.java Solve_Arg.java Vector_t.java
+
+NUM_OOO_WORKERS=24
+NUM_RCR_WORKERS=24
+
+include ../master-makefile
--- /dev/null
+#time ./Labyrinthp.bin -i ./inputs/random-x32-y32-z3-n64.txt
+#time ./Labyrinthp.bin -i ./inputs/random-x256-y256-z3-n256.txt
+time ./Labyrinthp.bin -w 24 -i ./inputs/random-x512-y512-z7-n512.txt
--- /dev/null
+#time ./Labyrinthr.bin -w 24 -i ./inputs/random-x32-y32-z3-n64.txt
+#time ./Labyrinthr.bin -w 24 -i ./inputs/random-x256-y256-z3-n256.txt
+time ./Labyrinthr.bin -w 24 -i ./inputs/random-x512-y512-z7-n512.txt
--- /dev/null
+#./Labyrinths.bin -i ./inputs/random-x32-y32-z3-n64.txt
+#./Labyrinths.bin -i ./inputs/random-x256-y256-z3-n256.txt
+./Labyrinths.bin -w 1 -i ./inputs/random-x512-y512-z7-n512.txt