From: yeom Date: Fri, 16 Jul 2010 05:58:23 +0000 (+0000) Subject: changes on labyrinth. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=4ae0551b2e88a1c25515f138922ae9a9751c788e;p=IRC.git changes on labyrinth. --- diff --git a/Robust/src/Benchmarks/oooJava/labyrinth/Labyrinth.java b/Robust/src/Benchmarks/oooJava/labyrinth/Labyrinth.java index 9d609420..9d92273b 100644 --- a/Robust/src/Benchmarks/oooJava/labyrinth/Labyrinth.java +++ b/Robust/src/Benchmarks/oooJava/labyrinth/Labyrinth.java @@ -97,7 +97,7 @@ public class Labyrinth zCost = 2; numThread = 1; - global_workload = 100; + global_workload = 20; } private void parseArg(String[] argv) { diff --git a/Robust/src/Benchmarks/oooJava/labyrinth/Maze.java b/Robust/src/Benchmarks/oooJava/labyrinth/Maze.java index 197f91a2..7608a091 100644 --- a/Robust/src/Benchmarks/oooJava/labyrinth/Maze.java +++ b/Robust/src/Benchmarks/oooJava/labyrinth/Maze.java @@ -69,327 +69,321 @@ */ 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; + 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); + } -/* ============================================================================= - * 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); + 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); + } - return mazePtr; - } + // testGridPtr.print(); -/* ============================================================================= - * maze_free - * ============================================================================= - void maze_free (maze_t* mazePtr); - */ - public void free(Maze m) - { - m = null; - } + /* Make sure path is contiguous and does not overlap */ + int id = 0; + List_Iter it = new List_Iter(); + it.reset(pathVectorListPtr); -/* ============================================================================= - * 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