From: yeom Date: Thu, 18 Nov 2010 05:32:01 +0000 (+0000) Subject: adds labyrinth without using scratchpad X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=ed2b691c5f430fa4c46547af46921ebf95808ab0;p=IRC.git adds labyrinth without using scratchpad --- diff --git a/Robust/src/Benchmarks/oooJava/labyrinthalloc/CoordPathWrapper.java b/Robust/src/Benchmarks/oooJava/labyrinthalloc/CoordPathWrapper.java new file mode 100644 index 00000000..52a6fdc8 --- /dev/null +++ b/Robust/src/Benchmarks/oooJava/labyrinthalloc/CoordPathWrapper.java @@ -0,0 +1,20 @@ +/* ============================================================================= + * + * CoordPathWrapper.java + * + * ============================================================================= + * + * Author: Stephen Yang + * University of California, Irvine + */ +public class CoordPathWrapper { + Pair coordinatePair; + Vector_t pathVector; + + public CoordPathWrapper(Pair coordinatePairPtr, Vector_t path) { + coordinatePair = coordinatePairPtr; + pathVector = path; + + } + +} diff --git a/Robust/src/Benchmarks/oooJava/labyrinthalloc/Coordinate.java b/Robust/src/Benchmarks/oooJava/labyrinthalloc/Coordinate.java new file mode 100644 index 00000000..a9c9c549 --- /dev/null +++ b/Robust/src/Benchmarks/oooJava/labyrinthalloc/Coordinate.java @@ -0,0 +1,175 @@ +/* ============================================================================= + * + * coordinate.java + * + * ============================================================================= + * + * Copyright (C) Stanford University, 2006. All Rights Reserved. + * Author: Chi Cao Minh + * + * ============================================================================= + * + * For the license of bayes/sort.h and bayes/sort.c, please see the header + * of the files. + * + * ------------------------------------------------------------------------ + * + * For the license of kmeans, please see kmeans/LICENSE.kmeans + * + * ------------------------------------------------------------------------ + * + * For the license of ssca2, please see ssca2/COPYRIGHT + * + * ------------------------------------------------------------------------ + * + * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the + * header of the files. + * + * ------------------------------------------------------------------------ + * + * For the license of lib/rbtree.h and lib/rbtree.c, please see + * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree + * + * ------------------------------------------------------------------------ + * + * Unless otherwise noted, the following license applies to STAMP files: + * + * Copyright (c) 2007, Stanford University + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Stanford University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * ============================================================================= + */ + +import java.lang.Math; + +public class Coordinate { + + public int x; + public int y; + public int z; + + public Coordinate() {} + + + // coordiate_alloc will be constructor + // coordinate_t* coordinate_alloc(long x, long y, long z) + public Coordinate(int x,int y,int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public Coordinate alloc(int x,int y,int z) { + Coordinate c = new Coordinate(x,y,z); + + return c; + } + + + // deallocate memory + // may not need + // coordinate_free + + /*======================================================== + // coordinate_isEqual + ==========================================================*/ + public boolean isEqual(Coordinate a,Coordinate b) + { + if((a.x == b.x) && (a.y == b.y) && (a.z == b.z)) + return true; + + return false; + } + + /*========================================================== + * + * getPairDistance + * + *========================================================*/ + private double getPairDistance(Pair p) + { + Coordinate a = (Coordinate)p.first; + Coordinate b = (Coordinate)p.second; + int dx = a.x - b.x; + int dy = a.y - b.y; + int dz = a.z - b.z; + int dx2 = dx* dx; + int dy2 = dy* dy; + int dz2 = dz* dz; + + return Math.sqrt((double)(dx2+dy2+dz2)); + } + + + /*================================================ + // coordinat_ comparePair + * -- For sorting in list of source/destination pairs + * -- Route longer paths first so they are more likely to suceed + + *================================================*/ + public int comparePair(final Object a,final Object b) + { + double aDistance = getPairDistance((Pair)a); + double bDistance = getPairDistance((Pair)b); + + if(aDistance < bDistance) { + return 1; + } else if(aDistance > bDistance) { + return -1; + } + + return 0; + } + + /*======================================================= + * coordinate_areAdjacent + *=======================================================*/ + + public boolean areAdjacent(Coordinate a,Coordinate b) + { + int dx = a.x - b.x; + int dy = a.y - b.y; + int dz = a.z - b.z; + int dx2 = dx * dx; + int dy2 = dy * dy; + int dz2 = dz * dz; + + return (((dx2 + dy2 + dz2) == 1) ? true : false); + } + } + + /*===================================================== + * + * End of Coordinate + * + *====================================================*/ + + diff --git a/Robust/src/Benchmarks/oooJava/labyrinthalloc/Grid.java b/Robust/src/Benchmarks/oooJava/labyrinthalloc/Grid.java new file mode 100644 index 00000000..b609e81a --- /dev/null +++ b/Robust/src/Benchmarks/oooJava/labyrinthalloc/Grid.java @@ -0,0 +1,287 @@ +/* ============================================================================= + * + * grid.java + * + * ============================================================================= + * + * Copyright (C) Stanford University, 2006. All Rights Reserved. + * Author: Chi Cao Minh + * + * ============================================================================= + * + * For the license of bayes/sort.h and bayes/sort.c, please see the header + * of the files. + * + * ------------------------------------------------------------------------ + * + * For the license of kmeans, please see kmeans/LICENSE.kmeans + * + * ------------------------------------------------------------------------ + * + * For the license of ssca2, please see ssca2/COPYRIGHT + * + * ------------------------------------------------------------------------ + * + * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the + * header of the files. + * + * ------------------------------------------------------------------------ + * + * For the license of lib/rbtree.h and lib/rbtree.c, please see + * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree + * + * ------------------------------------------------------------------------ + * + * Unless otherwise noted, the following license applies to STAMP files: + * + * Copyright (c) 2007, Stanford University + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Stanford University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * ============================================================================= + */ + + +public class Grid { + public int width; + public int height; + public int depth; + public int[][][] points_unaligned; + + public static int GRID_POINT_FULL; + public static int GRID_POINT_EMPTY; + + public Grid() + { + GRID_POINT_FULL = -2; + GRID_POINT_EMPTY = -1; + } + + +/* ============================================================================= + * grid_alloc + * ============================================================================= + grid_t* grid_alloc (long width, long height, long depth); + + well... need to implement + got stuck +*/ + public Grid alloc(int width,int height,int depth) { + Grid grid = new Grid(); + + grid.width = width; + grid.height = height; + grid.depth = depth; + + int[][][] points_unaligned = new int[width][height][depth]; + + + for(int i=0;i=0 && x< width && y>=0 && y=0 && z bend cost"); + System.out.println(" i input file name"); + System.out.println(" p print routed maze"); + System.out.println(" t Number of threads"); + System.out.println(" x x movement cost"); + System.out.println(" y y movement cost"); + System.out.println(" z z movement cost"); + System.out.println(" w Workload per rBlock"); + } + + + public static void main(String[] argv) + { + /* + * Initailization + */ + Maze maze = new Maze(); + Router router = new Router(); + Labyrinth labyrinth = new Labyrinth(argv); + + Maze mazePtr = maze.alloc(); + + int numPathToRoute = mazePtr.readMaze(labyrinth.global_inputFile); + + Router routerPtr = router.alloc(labyrinth.xCost,labyrinth.yCost, + labyrinth.zCost,labyrinth.bendCost); + + List_t list_t = new List_t(); + List_t pathVectorListPtr = list_t.alloc(0); // list_t.alloc(null) + Solve_Arg routerArg = new Solve_Arg(routerPtr,mazePtr,pathVectorListPtr, labyrinth.global_workload); + + /* Create and start thread */ + long start = System.currentTimeMillis(); + routerPtr.solve(routerArg); + + /* End of Solve */ + long finish = System.currentTimeMillis(); + long diff=finish-start; + System.out.println("TIME= " + diff); + + + int numPathRouted = 0; + List_Iter it = new List_Iter(); + + it.reset(pathVectorListPtr); + while(it.hasNext(pathVectorListPtr)) { + Vector_t pathVectorPtr = (Vector_t)it.next(pathVectorListPtr); + numPathRouted += pathVectorPtr.vector_getSize(); + } + + double elapsed = (finish-start)/1000.0; + + System.out.println("Paths routed = " + numPathRouted); + System.out.println("Elapsed time = " + elapsed); + + boolean stats = mazePtr.checkPaths(pathVectorListPtr,labyrinth.global_doPrint); + if(!stats) + System.out.println("Verification not passed"); + else + System.out.println("Verification passed."); + + System.out.println("Finished"); + } +} + +/* ============================================================================= + * + * End of labyrinth.c + * + * ============================================================================= + */ diff --git a/Robust/src/Benchmarks/oooJava/labyrinthalloc/List_Iter.java b/Robust/src/Benchmarks/oooJava/labyrinthalloc/List_Iter.java new file mode 100644 index 00000000..351e80d0 --- /dev/null +++ b/Robust/src/Benchmarks/oooJava/labyrinthalloc/List_Iter.java @@ -0,0 +1,38 @@ +public class List_Iter { + List_Node itPtr; + + /* ============================================================================= + * list_iter_reset + * ============================================================================= + void list_iter_reset (list_iter_t* itPtr, list_t* listPtr); + */ + public List_Iter() { + itPtr = null; + } + + public void reset(List_t listPtr) + { + itPtr = listPtr.head; + } + + /* ============================================================================= + * list_iter_hasNext + * ============================================================================= + * bool_t list_iter_hasNext (list_iter_t* itPtr, list_t* listPtr); + */ + public boolean hasNext(List_t listPtr) { + return (itPtr.nextPtr != null)? true : false; + } + + /* ============================================================================= + * list_iter_next + * ============================================================================= + * void* list_iter_next (list_iter_t* itPtr, list_t* listPtr); + */ + public Object next(List_t listPtr) + { + itPtr = itPtr.nextPtr; + return itPtr.dataPtr; + } +} + diff --git a/Robust/src/Benchmarks/oooJava/labyrinthalloc/List_Node.java b/Robust/src/Benchmarks/oooJava/labyrinthalloc/List_Node.java new file mode 100644 index 00000000..806baa19 --- /dev/null +++ b/Robust/src/Benchmarks/oooJava/labyrinthalloc/List_Node.java @@ -0,0 +1,10 @@ + +public class List_Node { + Object dataPtr; + List_Node nextPtr; + + public List_Node() { + dataPtr = null; + nextPtr = null; + } +} diff --git a/Robust/src/Benchmarks/oooJava/labyrinthalloc/List_t.java b/Robust/src/Benchmarks/oooJava/labyrinthalloc/List_t.java new file mode 100644 index 00000000..3b73d646 --- /dev/null +++ b/Robust/src/Benchmarks/oooJava/labyrinthalloc/List_t.java @@ -0,0 +1,307 @@ +/* ============================================================================= + * + * List_t.java + * -- Sorted singly linked list + * -- Options: duplicate allowed + * (DLIST_NO_DUPLICATES) is no implemented yet (default: allow duplicates) + * + * ============================================================================= + * + * Copyright (C) Stanford University, 2006. All Rights Reserved. + * Author: Chi Cao Minh + * + * ============================================================================= + * + * For the license of bayes/sort.h and bayes/sort.c, please see the header + * of the files. + * + * ------------------------------------------------------------------------ + * + * For the license of kmeans, please see kmeans/LICENSE.kmeans + * + * ------------------------------------------------------------------------ + * + * For the license of ssca2, please see ssca2/COPYRIGHT + * + * ------------------------------------------------------------------------ + * + * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the + * header of the files. + * + * ------------------------------------------------------------------------ + * + * For the license of lib/rbtree.h and lib/rbtree.c, please see + * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree + * + * ------------------------------------------------------------------------ + * + * Unless otherwise noted, the following license applies to STAMP files: + * + * Copyright (c) 2007, Stanford University + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Stanford University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * ============================================================================= + */ + + +public class List_t { + + public List_Node head; + boolean isCoordinate; + int size; + + public List_t() { + head = new List_Node(); + } + + + /* ======================================================================= + * allocNode + * -- Returns null on failure + * ======================================================================= + */ + private List_Node allocNode(Object dataPtr) + { + List_Node nodePtr = new List_Node(); + + + nodePtr.dataPtr = dataPtr; + nodePtr.nextPtr = null; + + return nodePtr; + } + + +/* ============================================================================= + * list_alloc + * -- If NULL passed for 'compare' function, will compare data pointer addresses + * -- Returns NULL on failure + * ============================================================================= + * list_t* list_alloc (long (*compare)(const void*, const void*)); + * + * + */ + + public List_t alloc(int isCoordinate) + { + List_t listPtr = new List_t(); + + + listPtr.head.dataPtr = null; + listPtr.head.nextPtr = null; + listPtr.size = 0; + + listPtr.isCoordinate = (isCoordinate==1)?true:false; + + return listPtr; + } + +/* ============================================================================= + * list_free + * -- If NULL passed for 'compare' function, will compare data pointer addresses + * -- Returns NULL on failure + * ============================================================================= + * void list_free (list_t* listPtr); + */ + public void free(List_t listPtr) + { + listPtr = null; + } + +// privae freeList + +/* ============================================================================= + * list_isEmpty + * -- Return TRUE if list is empty, else FALSE + * ============================================================================= + * bool_t list_isEmpty (list_t* listPtr); + */ + public boolean isEmpty() + { + return (head.nextPtr == null); + } + +/* ============================================================================= + * list_getSize + * -- Returns size of list + * ============================================================================= + * long list_getSize (list_t* listPtr); + */ + public int getSize() { + return size; + } + +/* ============================================================================= + * findPrevious + * ============================================================================= + * void* list_find (list_t* listPtr, void* dataPtr); + */ + private List_Node findPrevious(Object dataPtr) + { + List_Node prevPtr = head; + List_Node nodePtr = prevPtr.nextPtr; + + for(; nodePtr != null; nodePtr = nodePtr.nextPtr) { + if (compare(nodePtr.dataPtr,dataPtr) >= 0) { + return prevPtr; + } + prevPtr = nodePtr; + } + + return prevPtr; + } + + /* ============================================================================= + * list_find + * -- Returns NULL if not found, else returns pointer to data + * ============================================================================= + * void* list_find (list_t* listPtr, void* dataPtr); + */ + public Object find(Object dataPtr) { + List_Node nodePtr; + List_Node prevPtr = findPrevious(dataPtr); + + nodePtr = prevPtr.nextPtr; + + if((nodePtr == null) || + (compare(nodePtr.dataPtr,dataPtr) != 0)) { + return null; + } + + return (nodePtr.dataPtr); + } + + public int compare(Object obj1,Object obj2) + { + Coordinate coordinate = new Coordinate(); + if(isCoordinate) + { + return coordinate.comparePair(obj1,obj2); + } + else + return compareObject(obj1,obj2); + } + +/* ============================================================================= + * list_insert + * -- Return TRUE on success, else FALSE + * ============================================================================= + * bool_t list_insert (list_t* listPtr, void* dataPtr); + */ + public boolean insert(Object dataPtr) { + List_Node prevPtr; + List_Node nodePtr; + List_Node currPtr; + + prevPtr = findPrevious(dataPtr); + currPtr = prevPtr.nextPtr; + + nodePtr = allocNode(dataPtr); + if (nodePtr == null) { + return false; + } + + nodePtr.nextPtr = currPtr; + prevPtr.nextPtr = nodePtr; + size++; + + return true; + } + + +/* ============================================================================= + * list_remove + * -- Returns TRUE if successful, else FALSE + * ============================================================================= + * bool_t list_remove (list_t* listPtr, void* dataPtr); + */ + public boolean remove(Object dataPtr) + { + List_Node prevPtr; + List_Node nodePtr; + + prevPtr = findPrevious(dataPtr); + + nodePtr = prevPtr.nextPtr; + + if((nodePtr != null) && + (compare(nodePtr.dataPtr,dataPtr) == 0)) + { + prevPtr.nextPtr = nodePtr.nextPtr; + nodePtr.nextPtr = null; + nodePtr = null; + size--; + + return true; + } + + return false; + } + + int compareObject(Object obj1,Object obj2) { + return 1; + } + + +/* ============================================================================= + * list_clear + * -- Removes all elements + * ============================================================================= + * void list_clear (list_t* listPtr); + */ + public void clear() { + head = new List_Node(); + size = 0; + } + +/* ============================================================================= + * + * End of list.java + * + * ============================================================================= + */ + + /* Test list */ + +// public static void main(String[] argv) { +// List_t listPtr; +// int[] data1 = new int[5]; +// int[] data2 = new int[6]; +// +// int i; +// +// System.out.println("Starting..."); +// } +// +} + + + diff --git a/Robust/src/Benchmarks/oooJava/labyrinthalloc/Maze.java b/Robust/src/Benchmarks/oooJava/labyrinthalloc/Maze.java new file mode 100644 index 00000000..7608a091 --- /dev/null +++ b/Robust/src/Benchmarks/oooJava/labyrinthalloc/Maze.java @@ -0,0 +1,389 @@ +/*============================================================================= + * + * Maze.java + * + * ============================================================================= + * + * Copyright (C) Stanford University, 2006. All Rights Reserved. + * Author: Chi Cao Minh + * + * ============================================================================= + * + * For the license of bayes/sort.h and bayes/sort.c, please see the header + * of the files. + * + * ------------------------------------------------------------------------ + * + * For the license of kmeans, please see kmeans/LICENSE.kmeans + * + * ------------------------------------------------------------------------ + * + * For the license of ssca2, please see ssca2/COPYRIGHT + * + * ------------------------------------------------------------------------ + * + * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the + * header of the files. + * + * ------------------------------------------------------------------------ + * + * For the license of lib/rbtree.h and lib/rbtree.c, please see + * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree + * + * ------------------------------------------------------------------------ + * + * Unless otherwise noted, the following license applies to STAMP files: + * + * Copyright (c) 2007, Stanford University + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Stanford University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * ============================================================================= + */ + +public class Maze { + Grid gridPtr; + Queue_t workQueuePtr; + Vector_t wallVectorPtr; /* contains source/destination pairs to route */ + Vector_t srcVectorPtr; /* obstacles */ + Vector_t dstVectorPtr; /* destinations */ + + public int GRID_POINT_FULL; + public int GRID_POINT_EMPTY; + + public Maze() { + GRID_POINT_FULL = -2; + GRID_POINT_EMPTY = -1; + } + + /* + * ============================================================================ + * = maze_alloc + * ================================================================ + * ============= maze_t* maze_alloc (); + */ + public Maze alloc() { + Maze mazePtr = new Maze(); + Vector_t vector_t = new Vector_t(); + Queue_t queue_t = new Queue_t(); + + mazePtr.gridPtr = null; + mazePtr.workQueuePtr = queue_t.queue_alloc(1024); + mazePtr.wallVectorPtr = vector_t.vector_alloc(1); + mazePtr.srcVectorPtr = vector_t.vector_alloc(1); + mazePtr.dstVectorPtr = vector_t.vector_alloc(1); + + return mazePtr; + } + + /* + * ============================================================================ + * = maze_free + * ================================================================ + * ============= void maze_free (maze_t* mazePtr); + */ + public void free(Maze m) { + m = null; + } + + /* + * ============================================================================ + * = addToGrid + * ================================================================ + * ============= + */ + private void addToGrid(Grid gridPtr, Vector_t vectorPtr, String type) { + int i; + int n = vectorPtr.vector_getSize(); + + for (i = 0; i < n; i++) { + Coordinate coordinatePtr = (Coordinate) vectorPtr.vector_at(i); + if (!gridPtr.isPointValid(coordinatePtr.x, coordinatePtr.y, coordinatePtr.z)) { + System.out.println("Error: " + type + " (" + coordinatePtr.x + ", " + coordinatePtr.y + + ", " + coordinatePtr.z); + System.exit(1); + } + } + gridPtr.addPath(vectorPtr); + } + + /* + * ============================================================================ + * = maze_read -- Return number of path to route + * ============================== + * =============================================== long maze_read (maze_t* + * mazePtr, char* inputFileName); + */ + public int readMaze(String inputFileName) { + // Added for mlp compatiability + List_t list_t = new List_t(); + Coordinate coordinate = new Coordinate(); + Pair pair = new Pair(); + + FileInputStream in = new FileInputStream(inputFileName); + + /* + * Parse input file + */ + int lineNumber = 0; + int height = -1; + int width = -1; + int depth = -1; + boolean isParseError = false; + List_t workListPtr = list_t.alloc(1); // List.alloc(Coordinate.comparePair); + String line; + + while ((line = in.readLine()) != null) { + String code; + int[] xy = new int[6]; // equivalent to x1,y1,z1,x2,y2,z2 + int numToken = 0; + + StringTokenizer tok = new StringTokenizer(line); + + if ((numToken = tok.countTokens()) < 1) { + continue; + } + + code = tok.nextToken(); + + if (code.equals("#")) { + /* comment line */ + continue; + } + for (int i = 0; i < numToken - 1; i++) { + xy[i] = Integer.parseInt(tok.nextToken()); + } + + if (code.equals("d")) { + /* dimensions (format: d x y z) */ + if (numToken != 4) { + isParseError = true; + } else { + width = xy[0]; + height = xy[1]; + depth = xy[2]; + if (width < 1 || height < 1 || depth < 1) + isParseError = true; + } + } else if (code.equals("p")) { /* paths (format: p x1 y1 z1 x2 y2 z2) */ + if (numToken != 7) { + isParseError = true; + } else { + Coordinate srcPtr = coordinate.alloc(xy[0], xy[1], xy[2]); + Coordinate dstPtr = coordinate.alloc(xy[3], xy[4], xy[5]); + + if (coordinate.isEqual(srcPtr, dstPtr)) { + isParseError = true; + } else { + Pair coordinatePairPtr = pair.alloc(srcPtr, dstPtr); + boolean status = workListPtr.insert(coordinatePairPtr); + srcVectorPtr.vector_pushBack(srcPtr); + dstVectorPtr.vector_pushBack(dstPtr); + + } + } + } else if (code.equals("w")) { + /* walls (format: w x y z) */ + if (numToken != 4) { + isParseError = true; + } else { + Coordinate wallPtr = coordinate.alloc(xy[0], xy[1], xy[2]); + wallVectorPtr.vector_pushBack(wallPtr); + } + } else { /* error */ + isParseError = true; + } + + if (isParseError) {/* Error */ + System.out.println("Error: line " + lineNumber + " of " + inputFileName + "invalid"); + System.exit(1); + } + } + /* iterate over lines in put file */ + + in.close(); + /* + * Initialize grid contents + */ + if (width < 1 || height < 1 || depth < 1) { + System.out.println("Error : Invalid dimensions ( " + width + ", " + height + ", " + depth + + ")"); + System.exit(1); + } + + Grid grid = new Grid(); + Grid gridPtr = grid.alloc(width, height, depth); + this.gridPtr = gridPtr; + addToGrid(gridPtr, wallVectorPtr, "wall"); + addToGrid(gridPtr, srcVectorPtr, "source"); + addToGrid(gridPtr, dstVectorPtr, "destination"); + System.out.println("Maze dimensions = " + width + " x " + height + " x " + depth); + System.out.println("Paths to route = " + workListPtr.getSize()); + + /* + * Initialize work queue + */ + List_Iter it = new List_Iter(); + it.reset(workListPtr); + while (it.hasNext(workListPtr)) { + Pair coordinatePairPtr = (Pair) it.next(workListPtr); + workQueuePtr.queue_push(coordinatePairPtr); + } + + list_t.free(workListPtr); + + return srcVectorPtr.vector_getSize(); + } + + /* + * ============================================================================ + * = maze_checkPaths + * ========================================================== + * =================== bool_t maze_checkPaths (maze_t* mazePtr, list_t* + * pathListPtr, bool_t doPrintPaths); + */ + public boolean checkPaths(List_t pathVectorListPtr, boolean doPrintPaths) { + int i; + + /* Mark walls */ + Grid grid = new Grid(); + Grid testGridPtr = grid.alloc(gridPtr.width, gridPtr.height, gridPtr.depth); + testGridPtr.addPath(wallVectorPtr); + + /* Mark sources */ + int numSrc = srcVectorPtr.vector_getSize(); + // System.out.println("numSrc = " +numSrc); + // System.exit(1); + for (i = 0; i < numSrc; i++) { + Coordinate srcPtr = (Coordinate) srcVectorPtr.vector_at(i); + testGridPtr.setPoint(srcPtr.x, srcPtr.y, srcPtr.z, 0); + } + + /* Mark destinations */ + int numdst = dstVectorPtr.vector_getSize(); + for (i = 0; i < numdst; i++) { + Coordinate dstPtr = (Coordinate) dstVectorPtr.vector_at(i); + testGridPtr.setPoint(dstPtr.x, dstPtr.y, dstPtr.z, 0); + } + + // testGridPtr.print(); + + /* Make sure path is contiguous and does not overlap */ + int id = 0; + List_Iter it = new List_Iter(); + it.reset(pathVectorListPtr); + + int height = gridPtr.height; + int width = gridPtr.width; + int area = height * width; + + while (it.hasNext(pathVectorListPtr)) { + Vector_t pathVectorPtr = (Vector_t) it.next(pathVectorListPtr); + int numPath = pathVectorPtr.vector_getSize(); + + for (i = 0; i < numPath; i++) { + id++; + Vector_t pointVectorPtr = (Vector_t) pathVectorPtr.vector_at(i); + /* Check start */ + int prevGridPointIndex = ((Integer) pointVectorPtr.vector_at(0)).intValue(); + + int z = prevGridPointIndex / area; + int index2d = prevGridPointIndex % area; + int y = index2d / width; + int x = index2d % width; + + if (testGridPtr.getPoint(x, y, z) != 0) { + return false; + } + + Coordinate prevCoordinate = new Coordinate(); + prevCoordinate.x = x; + prevCoordinate.y = y; + prevCoordinate.z = z; + + int numPoint = pointVectorPtr.vector_getSize(); + int j; + + for (j = 1; j < (numPoint - 1); j++) { /* no need to check endpoints */ + int currGridPointIndex = ((Integer) pointVectorPtr.vector_at(j)).intValue(); + Coordinate currCoordinate = new Coordinate(); + + z = currGridPointIndex / area; + index2d = currGridPointIndex % area; + y = index2d / width; + x = index2d % width; + + currCoordinate.x = x; + currCoordinate.y = y; + currCoordinate.z = z; + + if (!currCoordinate.areAdjacent(currCoordinate, prevCoordinate)) { + System.out.println("you there?"); + return false; + } + + prevCoordinate = currCoordinate; + int xx = currCoordinate.x; + int yy = currCoordinate.y; + int zz = currCoordinate.z; + if (testGridPtr.getPoint(xx, yy, zz) != GRID_POINT_EMPTY) { + return false; + } else { + testGridPtr.setPoint(xx, yy, zz, id); + } + } + /* Check end */ + int lastGridPointIndex = ((Integer) pointVectorPtr.vector_at(j)).intValue(); + z = lastGridPointIndex / area; + index2d = lastGridPointIndex % area; + y = index2d / width; + x = index2d % width; + if (testGridPtr.getPoint(x, y, z) != 0) { + return false; + } + } /* iterate over pathVector */ + } /* iterate over pathVectorList */ + + if (doPrintPaths) { + System.out.println("\nRouted Maze:"); + testGridPtr.print(); + } + + return true; + } + +} +/* + * ============================================================================= + * + * End of maze.h + * + * ============================================================================= + */ diff --git a/Robust/src/Benchmarks/oooJava/labyrinthalloc/Pair.java b/Robust/src/Benchmarks/oooJava/labyrinthalloc/Pair.java new file mode 100644 index 00000000..ea735f04 --- /dev/null +++ b/Robust/src/Benchmarks/oooJava/labyrinthalloc/Pair.java @@ -0,0 +1,86 @@ + + +public class Pair { + public Object first; + public Object second; + + public Pair() { + first = null; + second = null; + } + + +/* ============================================================================= + * + * pair constructor + * + * pair_t* pair_alloc(void* firstPtr, void* secondPtr); + * ============================================================================= + */ + public Pair alloc(Object first,Object second) + { + Pair ptr= new Pair(); + ptr.first = first; + ptr.second = second; + + return ptr; + } + + + +/* ============================================================================= + * Ppair_alloc + * + * -- Returns NULL if failure + * ============================================================================= + */ + public Pair Ppair_alloc (Object firstPtr, Object secondPtr) { + Pair pairPtr = new Pair(); + pairPtr.first = firstPtr; + pairPtr.second = secondPtr; + return pairPtr; + } + + +/* ============================================================================= + * pair_free + * ============================================================================= + * + * void pair_free (pair_t* pairPtr); + * + */ + public void free(Pair pairPtr) + { + pairPtr = null; + } + + +/* ============================================================================= + * Ppair_free + * ============================================================================= + * +void Ppair_free (pair_t* pairPtr); +*/ + +/* ============================================================================= + * pair_swap + * -- Exchange 'firstPtr' and 'secondPtr' + * ============================================================================= + * void pair_swap (pair_t* pairPtr); +*/ + public void swap(Pair pairPtr) + { + Object tmpPtr = pairPtr.first; + + pairPtr.first = pairPtr.second; + pairPtr.second = tmpPtr; + } + +} + +/* ============================================================================= + * + * End of pair.java + * + * ============================================================================= + */ diff --git a/Robust/src/Benchmarks/oooJava/labyrinthalloc/Point.java b/Robust/src/Benchmarks/oooJava/labyrinthalloc/Point.java new file mode 100644 index 00000000..8905bd54 --- /dev/null +++ b/Robust/src/Benchmarks/oooJava/labyrinthalloc/Point.java @@ -0,0 +1,25 @@ + + public class Point { + int x; + int y; + int z; + int value; + int momentum; + + public Point() { + x = -1; + y = -1; + z = -1; + value = -1; + momentum = -1; + } + + public Point(int x,int y, int z,int value, int m) { + this.x = x; + this.y = y; + this.z = z; + this.value = value; + momentum = m; + } + } + diff --git a/Robust/src/Benchmarks/oooJava/labyrinthalloc/Queue_Int.java b/Robust/src/Benchmarks/oooJava/labyrinthalloc/Queue_Int.java new file mode 100644 index 00000000..07009fdf --- /dev/null +++ b/Robust/src/Benchmarks/oooJava/labyrinthalloc/Queue_Int.java @@ -0,0 +1,412 @@ +/* ============================================================================= + * + * queue.java + * + * ============================================================================= + * + * Copyright (C) Stanford University, 2006. All Rights Reserved. + * Author: Chi Cao Minh + * + * Ported to Java June 2009 Alokika Dash + * adash@uci.edu + * University of California, Irvine + * + * ============================================================================= + * + * Unless otherwise noted, the following license applies to STAMP files: + * + * Copyright (c) 2007, Stanford University + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Stanford University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * ============================================================================= + */ + + +public class Queue_Int { + int pop; /* points before element to pop */ + int push; + int capacity; + int[] elements; + + private int QUEUE_GROWTH_FACTOR; + + public Queue_Int() { + QUEUE_GROWTH_FACTOR = 2; + } + + /* ============================================================================= + * queue_alloc + * ============================================================================= + */ + public Queue_Int queue_alloc (int initCapacity) + { + Queue_Int queuePtr = new Queue_Int(); + + int capacity = ((initCapacity < 2) ? 2 : initCapacity); + queuePtr.elements = new int[capacity]; + queuePtr.pop = capacity - 1; + queuePtr.push = 0; + queuePtr.capacity = capacity; + + return queuePtr; + } + + + /* ============================================================================= + * Pqueue_alloc + * ============================================================================= + */ + public Queue_Int + Pqueue_alloc (int initCapacity) + { + Queue_Int queuePtr = new Queue_Int(); + + int capacity = ((initCapacity < 2) ? 2 : initCapacity); + queuePtr.elements = new int[capacity]; + queuePtr.pop = capacity - 1; + queuePtr.push = 0; + queuePtr.capacity = capacity; + + return queuePtr; + } + + + /* ============================================================================= + * TMqueue_alloc + * ============================================================================= + */ + public Queue_Int TMqueue_alloc (int initCapacity) + { + Queue_Int queuePtr = new Queue_Int(); + + int capacity = ((initCapacity < 2) ? 2 : initCapacity); + queuePtr.elements = new int[capacity]; + queuePtr.pop = capacity - 1; + queuePtr.push = 0; + queuePtr.capacity = capacity; + + return queuePtr; + } + + + /* ============================================================================= + * queue_free + * ============================================================================= + */ + public void + queue_free () + { + elements = null; + } + + + /* ============================================================================= + * Pqueue_free + * ============================================================================= + */ + public void + Pqueue_free () + { + elements = null; + } + + + /* ============================================================================= + * TMqueue_free + * ============================================================================= + */ + public void + TMqueue_free () + { + elements = null; + } + + + /* ============================================================================= + * queue_isEmpty + * ============================================================================= + */ + public boolean + queue_isEmpty () + { + return (((pop + 1) % capacity == push) ? true : false); + } + + + /* ============================================================================= + * queue_clear + * ============================================================================= + */ + public void + queue_clear () + { + pop = capacity - 1; + push = 0; + } + + + /* ============================================================================= + * TMqueue_isEmpty + * ============================================================================= + */ + public boolean + TMqueue_isEmpty (Queue_Int queuePtr) + { + int pop = queuePtr.pop; + int push = queuePtr.push; + int capacity = queuePtr.capacity; + + return (((pop + 1) % capacity == push) ? true : false); + } + + + /* ============================================================================= + * queue_push + * ============================================================================= + */ + public boolean + queue_push (int dataPtr) + { + + /* Need to resize */ + int newPush = (push + 1) % capacity; + if (newPush == pop) { + + int newCapacity = capacity * QUEUE_GROWTH_FACTOR; + int[] newElements = new int[newCapacity]; + + int dst = 0; + if (pop < push) { + int src; + for (src = (pop + 1); src < push; src++, dst++) { + newElements[dst] = elements[src]; + } + } else { + int src; + for (src = (pop + 1); src < capacity; src++, dst++) { + newElements[dst] = elements[src]; + } + for (src = 0; src < push; src++, dst++) { + newElements[dst] = elements[src]; + } + } + + elements = newElements; + pop = newCapacity - 1; + capacity = newCapacity; + push = dst; + newPush = push + 1; /* no need modulo */ + } + + elements[push] = dataPtr; + push = newPush; + + return true; + } + + + /* ============================================================================= + * Pqueue_push + * ============================================================================= + */ + public boolean + Pqueue_push (Queue_Int queuePtr, int dataPtr) + { + int pop = queuePtr.pop; + int push = queuePtr.push; + int capacity = queuePtr.capacity; + + + /* Need to resize */ + int newPush = (push + 1) % capacity; + if (newPush == pop) { + + int newCapacity = capacity * QUEUE_GROWTH_FACTOR; + int[] newElements = new int[newCapacity]; + + int dst = 0; + int[] elements = queuePtr.elements; + if (pop < push) { + int src; + for (src = (pop + 1); src < push; src++, dst++) { + newElements[dst] = elements[src]; + } + } else { + int src; + for (src = (pop + 1); src < capacity; src++, dst++) { + newElements[dst] = elements[src]; + } + for (src = 0; src < push; src++, dst++) { + newElements[dst] = elements[src]; + } + } + + elements = null; + queuePtr.elements = newElements; + queuePtr.pop = newCapacity - 1; + queuePtr.capacity = newCapacity; + push = dst; + newPush = push + 1; /* no need modulo */ + + } + + queuePtr.elements[push] = dataPtr; + queuePtr.push = newPush; + + return true; + } + + + /* ============================================================================= + * TMqueue_push + * ============================================================================= + */ + public boolean + TMqueue_push (Queue_Int queuePtr, int dataPtr) + { + int pop = (queuePtr.pop); + int push = (queuePtr.push); + int capacity = (queuePtr.capacity); + + + /* Need to resize */ + int newPush = (push + 1) % capacity; + if (newPush == pop) { + int newCapacity = capacity * QUEUE_GROWTH_FACTOR; + int[] newElements = new int[newCapacity]; + + int dst = 0; + int[] elements = queuePtr.elements; + if (pop < push) { + int src; + for (src = (pop + 1); src < push; src++, dst++) { + newElements[dst] = (elements[src]); + } + } else { + int src; + for (src = (pop + 1); src < capacity; src++, dst++) { + newElements[dst] = (elements[src]); + } + for (src = 0; src < push; src++, dst++) { + newElements[dst] = (elements[src]); + } + } + + elements = null; + queuePtr.elements = newElements; + queuePtr.pop = newCapacity - 1; + queuePtr.capacity = newCapacity; + push = dst; + newPush = push + 1; /* no need modulo */ + + } + + int[] elements = queuePtr.elements; + elements[push] = dataPtr; + queuePtr.push = newPush; + + return true; + } + + + /* ============================================================================= + * queue_pop + * ============================================================================= + */ + public int + queue_pop () + { + int newPop = (pop + 1) % capacity; + if (newPop == push) { + return 0; + } + + int dataPtr = elements[newPop]; + pop = newPop; + + return dataPtr; + } + + + /* ============================================================================= + * TMqueue_pop + * ============================================================================= + */ + public int + TMqueue_pop (Queue_Int queuePtr) + { + int pop = queuePtr.pop; + int push = queuePtr.push; + int capacity = queuePtr.capacity; + + int newPop = (pop + 1) % capacity; + if (newPop == push) { + return 0; + } + + int[] elements = queuePtr.elements; + int dataPtr = elements[newPop]; + queuePtr.pop = newPop; + + return dataPtr; + } + + /**** + * main method for testing + **/ + /* + public static void main(String[] args) { + testQueue queuePtr = testQueue.queue_alloc(-1); + int numData = 4; + if(queuePtr.queue_isEmpty()) + System.out.println("Queue is empty"); + + for(int i = 0; i