compiled
authorjihoonl <jihoonl>
Tue, 23 Jun 2009 06:13:57 +0000 (06:13 +0000)
committerjihoonl <jihoonl>
Tue, 23 Jun 2009 06:13:57 +0000 (06:13 +0000)
Robust/src/Benchmarks/SingleTM/Labyrinth/Coordinate.java
Robust/src/Benchmarks/SingleTM/Labyrinth/Grid.java
Robust/src/Benchmarks/SingleTM/Labyrinth/Labyrinth.java
Robust/src/Benchmarks/SingleTM/Labyrinth/List_t.java
Robust/src/Benchmarks/SingleTM/Labyrinth/Maze.java
Robust/src/Benchmarks/SingleTM/Labyrinth/Point.java
Robust/src/Benchmarks/SingleTM/Labyrinth/Router.java
Robust/src/Benchmarks/SingleTM/Labyrinth/Vector_t.java
Robust/src/Benchmarks/SingleTM/Labyrinth/makefile

index 0aca62e6427e545035b1b3094fe0ea75e8562a2d..68f792b9b414d186f89209ec68a9b8a445abbed2 100644 (file)
@@ -79,6 +79,8 @@ public class Coordinate {
     public int y;
     public int z;
 
+    public Coordinate() {}
+
 
     // coordiate_alloc will be constructor
     // coordinate_t* coordinate_alloc(long x, long y, long z)
@@ -117,8 +119,8 @@ public class Coordinate {
       *========================================================*/   
     private static double getPairDistance(Pair p)
     {
-        Coordinate a = (Coordinate)p.a;
-        Coordinate b = (Coordinate)p.b;
+        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;
@@ -139,7 +141,7 @@ public class Coordinate {
     public static int comparePair(final Object a,final Object b) 
     {
         double aDistance = getPairDistance((Pair)a);
-        double bDistnace = getPairDistance((Pair)b);
+        double bDistance = getPairDistance((Pair)b);
 
         if(aDistance < bDistance) {
             return 1;
index 1d94d15366270a25731a03aa4e60dd79b020e0d0..09bd64f0301ea4f7551327ad6e3f6a123852fdf0 100644 (file)
@@ -81,6 +81,7 @@ public class Grid {
     public int points_index;
     public int[][] points_unaligned;
 
+    public Grid() {}
 
     
 /* =============================================================================
@@ -94,7 +95,7 @@ public class Grid {
     public static Grid alloc(int width,int height,int depth) {
         Grid grid = new Grid();
 
-        if(grid) {
+        if(grid != null) {
 
             grid.width = width;
             grid.height = height;
@@ -110,7 +111,7 @@ public class Grid {
             grid.points_index = CACHE_LINE_SIZE;        // not sure it is right..
 
             for(int i=grid.points_index;i<n;i++) 
-                grid.points_unaligned[i] = GRID_POINT_EMPTY;            
+                grid.points_unaligned[i][0] = GRID_POINT_EMPTY;            
         }
                     
         return grid;         
@@ -155,7 +156,7 @@ public class Grid {
            (srcGridPtr.height == dstGridPtr.height) ||
            (srcGridPtr.depth == dstGridPtr.depth))
         {
-            System.err.println("Assert in Grid_Copy");
+            System.out.println("Assert in Grid_Copy");
             System.out.exit(1);
         }
 
@@ -164,7 +165,7 @@ public class Grid {
         int n = srcGridPtr.width * srcGridPtr.height * srcGridPtr.depth;
 
         for(int i=0;i<n;i++)
-            dstGridPtr.points_unaligned[points_index + i][0] = srcGridPtr.points_unaligned[points_index + i][0];   
+            dstGridPtr.points_unaligned[dstGridPtr.points_index + i][0] = srcGridPtr.points_unaligned[srcGridPtr.points_index + i][0];   
     }
 
 
@@ -208,12 +209,12 @@ long* grid_getPointRef (grid_t* gridPtr, long x, long y, long z);
  */
     public void getPointIndices(int gridPointIndex,int[] xPtr, int[] yPtr,int[] zPtr)
     {
-        int height = this.heigt;
+        int height = this.height;
         int width = this.width;
         int area = height * width;
         int index3d = (gridPointIndex - this.points_index);
         zPtr[0] = index3d / area;
-        long index2d = index3d % area;
+        int index2d = index3d % area;
         yPtr[0] = index2d / width;
         xPtr[0] = index2d % width;        
     }
@@ -242,7 +243,7 @@ long* grid_getPointRef (grid_t* gridPtr, long x, long y, long z);
  */
     public boolean isPointEmpty(int x,int y,int z)
     {
-        int value = getPoint(x,y,z)[0];
+        int value = getPoint(x,y,z);
         return ((value == GRID_POINT_EMPTY) ? true:false);
     }
 
@@ -255,7 +256,7 @@ long* grid_getPointRef (grid_t* gridPtr, long x, long y, long z);
  */
     public boolean isPointFull(int x,int y,int z)
     {
-        int value = getPoint(x,y,z)[0];
+        int value = getPoint(x,y,z);
         return ((value == GRID_POINT_FULL) ? true : false);
     }
 
@@ -285,7 +286,7 @@ void grid_addPath (grid_t* gridPtr, vector_t* pointVectorPtr);
     public void addPath(Vector_t pointVectorPtr)
     {
         int i;
-        int n = pointVectorPtr.getSize();
+        int n = pointVectorPtr.vector_getSize();
 
         for(i = 1; i < (n-1); i++) {
             Coordinate coordinatePtr = (Coordinate)pointVectorPtr.vector_at(i);
@@ -315,7 +316,7 @@ void grid_print (grid_t* gridPtr);
     {
         int z;
 
-        for(z=0;j<depth;z++) {
+        for(z = 0; z < depth; z++) {
             System.out.println("[z = " + z + "]");
             int x;
             for(x = 0; x < width; x++) {
@@ -323,9 +324,9 @@ void grid_print (grid_t* gridPtr);
                 for(y = 0; y < height; y++) {
                     System.out.println(points_unaligned[getPointIndex(x,y,z)]);
                 }
-                System.out.println();
+                System.out.println("");
             }
-            System.out.println();
+            System.out.println("");
         }
  
     }
index f671c29c8939e82346cdea1968f009326257ff77..124c93bf1474d3abd247cc95409bb9e48b203f06 100644 (file)
@@ -81,7 +81,7 @@ public class Labyrinth extends Thread{
 
     // For threads
     int threadID;
-    Router.Arg routerArg;
+    Solve_Arg routerArg;
 
     private void setDefaultParams() {
 
@@ -102,7 +102,7 @@ public class Labyrinth extends Thread{
 
         setDefaultParams();
 
-        while (i < args.length && argv[i].startswith("-")) {
+        while (i < arg.length() && argv[i].charAt(0) == '-' ) {
             arg = argv[i++];
 
             // check options
@@ -128,14 +128,14 @@ public class Labyrinth extends Thread{
                 global_doPrint = true;
             }
             else {
-                System.err.println("Non-option argument: " + argv[i]);
+                System.out.println("Non-option argument: " + argv[i]);
                 opterr = true;
             }
         }
 
         if(opterr) {
             displayUsage();
-            System.out.exit(1);
+            System.exit(1);
         }
     }
 
@@ -145,7 +145,7 @@ public class Labyrinth extends Thread{
     }
 
 
-    public Labyrinth(int myID,Router.Arg rArg)
+    public Labyrinth(int myID,Solve_Arg rArg)
     {
         threadID = myID;
         routerArg = rArg;
@@ -159,6 +159,20 @@ public class Labyrinth extends Thread{
         }
     }
 
+    public void displayUsage() 
+    {
+        System.out.println("Usage: Labyrinth [options]");
+        System.out.println("Options:");
+        System.out.println("    b <INT>     bend cost");
+        System.out.println("    i <FILE>    input file name");
+        System.out.println("    p           print routed maze");
+        System.out.println("    t <INT>     Number of threads");
+        System.out.println("    x <INT>     x movement cost");
+        System.out.println("    y <INT>     y movement cost");
+        System.out.println("    z <INT>     z movement cost");
+    }
+        
+
     public static void main(String[] argv) 
     {
         /*
@@ -166,32 +180,30 @@ public class Labyrinth extends Thread{
          */
         Labyrinth labyrinth = new Labyrinth(argv);
         
-        Barrier.setBarrier(laybyrinth.numThread);
+        Barrier.setBarrier(labyrinth.numThread);
 
         Maze mazePtr = Maze.alloc();
 
-        int numPathToRoute =  mazePtr.read(global_inputFile);
+        int numPathToRoute =  mazePtr.readMaze(labyrinth.global_inputFile);
         
-        Router routerPtr = Router.alloc(laybyrinth.xCost,laybyrinth.yCost,
-                                        laybyrinth.zCost,laybyrinth.bendCost);
+        Router routerPtr = Router.alloc(labyrinth.xCost,labyrinth.yCost,
+                                        labyrinth.zCost,labyrinth.bendCost);
 
         List_t pathVectorListPtr = List_t.alloc(0);     // list_t.alloc(null)
-
         /*
          * Run transactions
          */
-        Solve_arg routerArg = new Solve_arg(routerPtr,mazePtr,pathVectorListPtr);
-
+        Solve_Arg routerArg = new Solve_Arg(routerPtr,mazePtr,pathVectorListPtr);
 
         /* Create and start thread */
-        Layrinth[] lb = new Labyrinth[numThread];
+        Labyrinth[] lb = new Labyrinth[labyrinth.numThread];
 
-        for(int i = 1; i<numThread;i++) {
+        for(int i = 1; i<labyrinth.numThread;i++) {
             lb[i] = new Labyrinth(i,routerArg);
         }
 
-        for(int i = 1; i<numThread;i++) {
-            ib[i].start();
+        for(int i = 1; i<labyrinth.numThread;i++) {
+            lb[i].start();
         }
 
         /* End of Solve */
@@ -202,12 +214,12 @@ public class Labyrinth extends Thread{
         it.reset(pathVectorListPtr);
         while(it.hasNext(pathVectorListPtr)) {
             Vector_t pathVectorPtr = (Vector_t)it.next(pathVectorListPtr);
-            numPathRouted += pathVectorPtr.getSize();
+            numPathRouted += pathVectorPtr.vector_getSize();
         }
 
-        System.out.println("Paths routed    = " + numPaathRouted);
+        System.out.println("Paths routed    = " + numPathRouted);
 
-        boolean stats = mazePtr.checkPaths(pathVectorListPtr,global_doPrint);
+        boolean stats = mazePtr.checkPaths(pathVectorListPtr,labyrinth.global_doPrint);
         if(!stats)
         {
             System.out.println("Verification not passed");
index 3ad5c71459ccc434e97946913befec9b83a6b389..935939660c58a9f8ff886b779c9bd523b357b4ca 100644 (file)
@@ -109,8 +109,11 @@ public class List_t {
  * -- Returns NULL on failure
  * =============================================================================
  * list_t* list_alloc (long (*compare)(const void*, const void*));
+ *
+ *
  */
-    public static List_t alloc(int flag) 
+
+    public static List_t alloc(int isCoordinate) 
     {
         List_t listPtr = new List_t();
 
@@ -119,10 +122,10 @@ public class List_t {
         }
 
         listPtr.head.dataPtr = null;
-        listPtr.nextPtr = null;
+        listPtr.head.nextPtr = null;
         listPtr.size = 0;
         
-        isCoordinate = (flag==1)?true:false;
+        listPtr.isCoordinate = (isCoordinate==1)?true:false;
 
         return listPtr;
     }
@@ -134,7 +137,7 @@ public class List_t {
  * =============================================================================
  * void list_free (list_t* listPtr);
  */
-    public static void free(List listPtr) 
+    public static void free(List_t listPtr) 
     {
         listPtr = null;
     }
@@ -172,7 +175,7 @@ public class List_t {
         List_Node prevPtr = head;
         List_Node nodePtr = prevPtr.nextPtr;
 
-        for(; nodePtr != null; noePtr = nodePtr.nextPtr) {
+        for(; nodePtr != null; nodePtr = nodePtr.nextPtr) {
             if (compare(nodePtr.dataPtr,dataPtr) >= 0) {
                 return prevPtr;
             }
@@ -224,7 +227,7 @@ public class List_t {
         List_Node currPtr;
 
         prevPtr = findPrevious(dataPtr);
-        currPtr = prePtr.nextPtr;
+        currPtr = prevPtr.nextPtr;
 
         nodePtr = allocNode(dataPtr);
         if (nodePtr == null) {
@@ -232,7 +235,7 @@ public class List_t {
         }
 
         nodePtr.nextPtr = currPtr;
-        prevPtr.nextPr = nodePtr;
+        prevPtr.nextPtr = nodePtr;
         size++;
 
         return true;
@@ -269,7 +272,7 @@ public class List_t {
     }
 
     int compareObject(Object obj1,Object obj2) {
-        return obj1 - obj2;
+        return 1;
     }
     
 
@@ -296,7 +299,7 @@ public class List_t {
  public static void main(String[] argv) {
      List_t listPtr;
      int[] data1 = new int[5];
-     int[] data2 = new int [6];
+     int[] data2 = new int[6];
 
      int i;
 
index 56417db8442e568775cf91d5c45b26e2d2336e5d..c2ac425b3fd2b2b1f6f7dfe162d017a21326ff51 100644 (file)
  * =============================================================================
  */
 
+#define GRID_POINT_FULL -2
+#define GRID_POINT_EMPTY -1
 
 public class Maze {
     Grid gridPtr;
-    Queue workQueuePtr;
-    Vector_t wallvectorPtr; /* contains source/destination pairs to route */
+    Queue_t workQueuePtr;
+    Vector_t wallVectorPtr; /* contains source/destination pairs to route */
     Vector_t srcVectorPtr;  /* obstacles */
     Vector_t dstVectorPtr;  /* destinations */
 
+    public Maze() {}
+
 
 /* =============================================================================
  * maze_alloc
@@ -88,10 +92,10 @@ public class Maze {
 
        if(mazePtr != null) {
            mazePtr.gridPtr = null;
-           mazePtr.workQueuePtr = Queue.alloc(1024);
-           mazePtr.wallVectorPtr = Vector.alloc(1);
-           mazePtr.srcVectorPtr = Vector.alloc(1);
-           mazePtr.dstVectorPtr = Vector.alloc(1);
+           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);
 
        }
 
@@ -112,18 +116,18 @@ public class Maze {
  * addToGrid
  * =============================================================================
  */
-    private void addToGrid(Grid gridPtr,Vector_t vectorPtr,char[] type)
+    private void addToGrid(Grid gridPtr,Vector_t vectorPtr,String type)
     {
         int i;
-        int n = vectorPtr.getSize();
+        int n = vectorPtr.vector_getSize();
 
         for(i = 0; i < n; i++) {
             Coordinate coordinatePtr = (Coordinate)vectorPtr.vector_at(i);
-            if(!gridPtr.isPointValid(coodinatePtr.x,coordinatePtr.y,coordinatePtr.z))
+            if(!gridPtr.isPointValid(coordinatePtr.x,coordinatePtr.y,coordinatePtr.z))
             {
-                System.err.println("Error: " + type + " (" + coordinate.x + 
-                                                      ", " + coordinate.y + 
-                                                      ", " + coordinate.z);
+                System.out.println("Error: " + type + " (" + coordinatePtr.x + 
+                                                      ", " + coordinatePtr.y + 
+                                                      ", " + coordinatePtr.z);
                 System.exit(1);
             }
         }
@@ -135,10 +139,9 @@ public class Maze {
  * =============================================================================
  long maze_read (maze_t* mazePtr, char* inputFileName);
  */
-    public int read(String inputFileName)
+    public int readMaze(String inputFileName)
     {
-            BufferedReader in = new BufferedReader(new FileReader(inputFileName));
-
+            FileInputStream in = new FileInputStream(inputFileName);    
             /*
              * Parse input file
              */
@@ -146,34 +149,33 @@ public class Maze {
             int height = -1;
             int width = -1;
             int depth = -1;
-            char[] line = new char[256];
             boolean isParseError = false;
-            List_t workListPtr = List.alloc(1); // List.alloc(Coordinate.comparePair);
+            List_t workListPtr = List_t.alloc(1); // List.alloc(Coordinate.comparePair);
             String line;
             
-            while(line = in.readLine()) {
+            while((line = in.readLine()) != null) {
                 
-                char code;
+                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 ) {
+                if((numToken = tok.countTokens()) < 1 ) {
                     continue;
                 }
 
-                code = (char)tok.nextElement();
+                code = tok.nextToken();
                
-                for(i=0;i<numToken-1;i++) {
-                    xy[i] = Integer.ParserInt(tok.nextToken());
+                for(int i=0;i<numToken-1;i++) {
+                    xy[i] = Integer.parseInt(tok.nextToken());
                 }                
                 
-                if(code == '#'
+                if(code.equals("#")
                  { /* comment */
                    /* ignore line */
                 
-                 }else if(code == 'd') {
+                 }else if(code.equals("d")) {
                       /* dimensions (format: d x y z) */
                      if(numToken != 4) {
                         isParseError = true;
@@ -185,7 +187,7 @@ public class Maze {
                         if(width < 1 || height < 1 || depth <1)
                             isParseError = true;
                      }
-                 }else if(code == 'p') { /* paths (format: p x1 y1 z1 x2 y2 z2) */
+                 }else if(code.equals("p")) { /* paths (format: p x1 y1 z1 x2 y2 z2) */
                     if(numToken != 7) {
                         isParseError = true;
                     }
@@ -197,11 +199,11 @@ public class Maze {
                             isParseError = true;
                         }
                         else { 
-                            Pair coordinatePtr = Pair.alloc(srcPtr,dstPtr);
+                            Pair coordinatePairPtr = Pair.alloc(srcPtr,dstPtr);
                             boolean status = workListPtr.insert((Object)coordinatePairPtr);
                         }
                     }
-                }else if(code == 'w') {
+                }else if(code.equals("w")) {
                          /* walls (format: w x y z) */
                         if(numToken != 4) {
                             isParseError = true;
@@ -214,43 +216,44 @@ public class Maze {
                 }
                 
                 if(isParseError)  {/* Error */
-                    System.err.println("Error: line " + lineNumber + " of " + inputfileName + "invalid");
+                    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.err.println("Error : Invalid dimensions ( " + width + ", " + height + ", "+ depth + ")");
+                System.out.println("Error : Invalid dimensions ( " + width + ", " + height + ", "+ depth + ")");
                 System.exit(1);
             }
 
             Grid gridPtr = Grid.alloc(width,height,depth);
-            mazePtr.gridPtr = gridPtr;
-            gridPtr.addToGrid(wallVectorPtr,"wall");
-            gridPtr.addToGrid(srcVectorPtr, "source");
-            grdPtr.addToGrid(dstVectorPtr, " destination");
+            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
              */
-            Queue workQueuePtr = mazePtr.workQueuePtr;
+            Queue_t workQueuePtr = workQueuePtr;
             List_Iter it = new List_Iter();
             it.reset(workListPtr);
 
-            while(it.hasNext(wrokListPtr)) {
-                Pair coordinatePtr = (Pair)it.next(workListPtr);
+            while(it.hasNext(workListPtr)) {
+                Pair coordinatePairPtr = (Pair)it.next(workListPtr);
                 workQueuePtr.queue_push((Object)coordinatePairPtr);
             }
 
-            workListPtr = free;
+            List_t.free(workListPtr);
 
-            return srcVectorPtr.getSize();
+            return srcVectorPtr.vector_getSize();
     }
     
 
@@ -259,25 +262,25 @@ public class Maze {
  * =============================================================================
  bool_t maze_checkPaths (maze_t* mazePtr, list_t* pathListPtr, bool_t doPrintPaths);
  */
-    public boolean checkPaths(List_t pathListPtr,boolean doPrintPaths)
+    public boolean checkPaths(List_t pathVectorListPtr,boolean doPrintPaths)
     {
         int i;
-
+       
         /* Mark walls */
-        Grid testGridPtr = Grid.alloc(width,height,depth);
+        Grid testGridPtr = Grid.alloc(gridPtr.width,gridPtr.height,gridPtr.depth);
         testGridPtr.addPath(wallVectorPtr);
 
         /* Mark sources */
-        int numSrc = srcVectorPtr.getSize();
+        int numSrc = srcVectorPtr.vector_getSize();
         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 = destVectorPtr.getSize();
+        int numdst = dstVectorPtr.vector_getSize();
         for(i = 0; i < numdst; i++) {
-            Coordinate dstPtr = (Coordinate)dstVector.vector_at(i);
+            Coordinate dstPtr = (Coordinate)dstVectorPtr.vector_at(i);
             testGridPtr.setPoint(dstPtr.x,dstPtr.y,dstPtr.z,0);
         }
 
@@ -286,14 +289,14 @@ public class Maze {
         List_Iter it = new List_Iter();
         it.reset(pathVectorListPtr);
         while(it.hasNext(pathVectorListPtr)) {
-            Vector_t pathVectorPtr = it.next(pathVectorListPtr);
-            int numPath = pathVectorPtr.getSize();
-            int i;
+            Vector_t pathVectorPtr = (Vector_t)it.next(pathVectorListPtr);
+            int numPath = pathVectorPtr.vector_getSize();
+          
             for(i = 0; i < numPath; i++) {
                 id++;
-                Vector pointVectorPtr = pathVectorPtr.vector_at(i);
+                Vector_t pointVectorPtr = (Vector_t)pathVectorPtr.vector_at(i);
                 /* Check start */
-                int prevGridPointIndex = pointVectorPtr.vector_at(0);
+                int prevGridPointIndex = ((Integer)pointVectorPtr.vector_at(0)).intValue();
                 int[] x = new int[1];
                 int[] y = new int[1];
                 int[] z = new int[1];
@@ -303,46 +306,46 @@ public class Maze {
                     return false;
                 }
                 Coordinate prevCoordinate = new Coordinate();
-                int[] x = new int[1];
-                int[] y = new int[1];
-                int[] z = new int[1];
-                gridPtr.getpointIndices(prevGridPointIndex,x,y,z);
+                x = new int[1];
+                y = new int[1];
+                z = new int[1];
+                gridPtr.getPointIndices(prevGridPointIndex,x,y,z);
                 prevCoordinate.x = x[0];
                 prevCoordinate.y = y[0];
                 prevCoordinate.z = z[0];
 
-                int numPoiont = pointVectorPtr.getSize();
+                int numPoint = pointVectorPtr.vector_getSize();
                 int j;
                 for(j = 1; j< (numPoint - 1) ;j++) { /* no need to check endpoints */
-                    int currGridPointIndex = pointVectorPtr.vector_at(j);
+                    int currGridPointIndex = ((Integer)pointVectorPtr.vector_at(j)).intValue();
                     Coordinate currCoordinate = new Coordinate();
-                    int[] x = new int[1];
-                    int[] y = new int[1];
-                    int[] z = new int[1];
+                    x = new int[1];
+                    y = new int[1];
+                    z = new int[1];
                     gridPtr.getPointIndices(currGridPointIndex,x,y,z);
-                    currGridPoint.x = x[0];
-                    currGridPoint.y = y[0];
-                    currGridPoint.z = z[0];
+                    currCoordinate.x = x[0];
+                    currCoordinate.y = y[0];
+                    currCoordinate.z = z[0];
 
-                    if(Coordinate.areAdjacent(currCoordinate,preCoordinate)) {
+                    if(Coordinate.areAdjacent(currCoordinate,prevCoordinate)) {
                         Grid.free(testGridPtr);
                         return false;
                     }
 
                     prevCoordinate = currCoordinate;
-                    int x = currCoordinate.x;
-                    int y = currCoordinate.y;
-                    int z = currCoordinate.z;
-                    if(testGridPtr.getPoint(x,y,z) != GRID_POINT_EMPTY) {
+                    int xx = currCoordinate.x;
+                    int yy = currCoordinate.y;
+                    int zz = currCoordinate.z;
+                    if(testGridPtr.getPoint(xx,yy,zz) != GRID_POINT_EMPTY) {
                         Grid.free(testGridPtr);
                         return false;
                     } else {
-                        testGridPtr.setPoint(x,y,z,id);
+                        testGridPtr.setPoint(xx,yy,zz,id);
                     }
                 }
                 /* Check end */
-                int lastGridPointIndex = pointVectorPtr.vector_at(j);
-                gridPtr.getPointindices(lastGridPointIndex,x,y,z);
+                int lastGridPointIndex = ((Integer)pointVectorPtr.vector_at(j)).intValue();
+                gridPtr.getPointIndices(lastGridPointIndex,x,y,z);
                 if(testGridPtr.getPoint(x[0],y[0],z[0]) != 0) {
                     Grid.free(testGridPtr);
                     return false;
@@ -351,7 +354,7 @@ public class Maze {
         } /* iterate over pathVectorList */
 
         if(doPrintPaths) {
-            system.out.println("\nRouted Maze:");
+            System.out.println("\nRouted Maze:");
             testGridPtr.print();
         }
 
index ffc066532aa24d6b2023252acd5d69c3213f2b52..8905bd54ef67570c8b62c7671eb9c9ce92f74804 100644 (file)
@@ -5,6 +5,14 @@
         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;
index 22da7ce466f698029411ccb1ab699fb85566ba1e..9c0fa1aba2c3669bb588fdeb518a42d5641794ed 100644 (file)
 #define MOMENTUM_NEGX 4
 #define MOMENTUM_NEGY 5
 #define MOMENTUM_NEGZ 6
-
+#define GRID_POINT_FULL -2
+#define GRID_POINT_EMPTY -1
 
 public class Router {
-    int xCost;
-    int yCost;
-    int zCost;
-    int bendCost;
-  
+    public int xCost;
+    public int yCost;
+    public int zCost;
+    public int bendCost;
+    public static Point MOVE_POSX;
+    public static Point MOVE_POSY;
+    public static Point MOVE_POSZ;
+    public static Point MOVE_NEGX;
+    public static Point MOVE_NEGY;
+    public static Point MOVE_NEGZ;
+
+    public Router() {}
 
 /* =============================================================================
  * router_alloc
@@ -98,12 +106,12 @@ public class Router {
         Router routerPtr = new Router();
 
 
-        Point MOVE_POSX = new Point(1,0,0,0,MOMENTUM_POSX);
-        Point MOVE_POSY = new Point(0,1,0,0,MOMENTUM_POSY);
-        Point MOVE_POSZ = new Point(0,0,1,0,MOMENTUM_POSZ);
-        Point MOVE_NEGX = new Point(-1,0,0,0,MOMENTUM_NEGX);
-        Point MOVE_NEGY = new Point(0,-1,0,0,MOMENTUM_NEGY);
-        Point MOVE_NEGZ = new Point(0,0,-1,0,MOMENTUM_NEGZ);
+        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);
 
         if(routerPtr != null) {
             routerPtr.xCost = xCost;
@@ -133,19 +141,19 @@ public class Router {
  * ============================================================================
  */
     private void PexpandToNeighbor(Grid myGridPtr, 
-                                    int x,int y,int z, int value,Queue queuePtr)
+                                    int x,int y,int z, int value,Queue_t queuePtr)
     {
         if (myGridPtr.isPointValid(x,y,z)) {
             int neighborGridPointIndex = myGridPtr.getPointIndex(x,y,z);
             int neighborValue = myGridPtr.getPoint(neighborGridPointIndex);
             if (neighborValue == GRID_POINT_EMPTY) {
                 myGridPtr.setPoint(neighborGridPointIndex,value);
-                queuePtr.queue_push(neighborGridPointIndex);
+                queuePtr.queue_push(new Integer(neighborGridPointIndex));
             } else if (neighborValue != GRID_POINT_FULL) {
                 
                 if (value < neighborValue) {
                     myGridPtr.setPoint(neighborGridPointIndex,value);
-                    queuePtr.queue_push(neighborGridPointIndex);
+                    queuePtr.queue_push(new Integer(neighborGridPointIndex));
                 }
             }
         }
@@ -156,13 +164,14 @@ public class Router {
  * PdoExpansion
  * ============================================================================
  */
-    private boolean PdoExpansion (Router routerPtr,Grid myGridPtr,Queue queuePtr,
+    public boolean PdoExpansion (Router routerPtr,Grid myGridPtr,Queue_t 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.
@@ -171,14 +180,14 @@ public class Router {
         queuePtr.queue_clear();
 
         int srcGridPointIndex = myGridPtr.getPointIndex(srcPtr.x,srcPtr.y,srcPtr.z);
-        queuePtr.queue_push(srcGridPointIndex);
+        queuePtr.queue_push(new Integer(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;
 
         while (queuePtr.queue_isEmpty()) {
-            int gridPointIndex = queuePtr.queue_pop();
+            int gridPointIndex = ((Integer)queuePtr.queue_pop()).intValue();
             if(gridPointIndex == dstGridPointIndex) {
                 isPathFound = true;
                 break;
@@ -205,7 +214,7 @@ public class Router {
 
         } /* iterate over work queue */
 
-        return isPathfound;
+        return isPathFound;
     }
             
             
@@ -251,7 +260,7 @@ public class Router {
     private Vector_t PdoTraceback(Grid gridPtr,Grid myGridPtr,
                                   Coordinate dstPtr, int bendCost)
     {
-        Vector_t pointVectorPtr = Vector.vector_alloc(1);
+        Vector_t pointVectorPtr = Vector_t.vector_alloc(1);
 
         Point next = new Point();
         next.x = dstPtr.x;
@@ -262,7 +271,7 @@ public class Router {
 
         while(true) {
             int gridPointIndex = gridPtr.getPointIndex(next.x,next.y,next.z);
-            pointVectorPtr.vector_pushBack(gridPointIndex);
+            pointVectorPtr.vector_pushBack(new Integer(gridPointIndex));
             myGridPtr.setPoint(next.x,next.y,next.z,GRID_POINT_FULL);
 
             /* Check if we are done */
@@ -320,16 +329,16 @@ public class Router {
     public static void solve(Object argPtr) 
     {
         // TM_THREAD_ENTER();
-        Solve_Arg routerArgPtr = (SolveArg) argPtr;
+        Solve_Arg routerArgPtr = (Solve_Arg) argPtr;
         Router routerPtr = routerArgPtr.routerPtr;
         Maze mazePtr = routerArgPtr.mazePtr;
-        Vector_t myPathVectorPtr = Vector.alloc(1);
+        Vector_t myPathVectorPtr = Vector_t.vector_alloc(1);
 
-        Queue workQueuePtr = mazePtr.workqueuePtr;
+        Queue_t workQueuePtr = mazePtr.workQueuePtr;
         Grid gridPtr = mazePtr.gridPtr;
         Grid myGridPtr = Grid.alloc(gridPtr.width,gridPtr.height,gridPtr.depth);
         int bendCost = routerPtr.bendCost;
-        Queue myExpansionQueuePtr = Queue.queue_alloc(-1);
+        Queue_t myExpansionQueuePtr = Queue_t.queue_alloc(-1);
 
         /*
          * Iterate over work list to route each path. This involves an
@@ -349,24 +358,25 @@ public class Router {
             // TM_END();
             //
             
-            if (coordinatePairPtr = null) {
+            if (coordinatePairPtr == null) {
                 break;
             }
 
-            Coordinate srcPtr = coordinatePairPtr.firstPtr;
-            Coordinate dstPtr = coordinatePairPtr.secondPtr;
-
+            Coordinate srcPtr = (Coordinate)coordinatePairPtr.first;
+            Coordinate dstPtr = (Coordinate)coordinatePairPtr.second;
+            
             boolean success = false;
-            Vector_t pointvectorPtr = null;
+            Vector_t pointVectorPtr = null;
 
             // TM_BEGIN();
             atomic {
                 Grid.copy(myGridPtr, gridPtr); /* ok if not most up-to-date */
-                if (PdoExpansion(routerPtr, myGridPtr, myExpansionQueuePtr,
-                            srcPtr, dstPtr)) {
-                    pointVectorPtr = PdoTraceback(gridPtr,myGridPtr,dstPtr,bendCost);
+                               
+                boolean result = routerPtr.PdoExpansion(routerPtr,myGridPtr,myExpansionQueuePtr,srcPtr,dstPtr);
+                if(result) {
+                    pointVectorPtr = routerPtr.PdoTraceback(gridPtr,myGridPtr,dstPtr,bendCost);
 
-                    if (pointVectorPtr) {
+                    if (pointVectorPtr != null) {
                         gridPtr.addPath(pointVectorPtr);
                         success = true;
                     }
@@ -375,6 +385,10 @@ public class Router {
 
             if(success) {
                 boolean status = myPathVectorPtr.vector_pushBack(pointVectorPtr);
+                if(status) {
+                    System.out.println("Error in Router_Solve");
+                    System.exit(1);
+                }
             }
         }
 
index f1ae2ba168f54c6e7219c1f899f961bb8404dfdc..91138e7375a09d2e6e31092f5fb0d542f1cd3b15 100644 (file)
@@ -2,10 +2,10 @@ public class Vector_t {
   int size;
   int capacity;
   Object[] elements;
-  QuickSort qsort;
+//  QuickSort qsort;
 
   public Vector_t() {
-    qsort = new QuickSort();
+//    qsort = new QuickSort();
   }
 
   /* =============================================================================
index 2c89deffcab91de9aa813576f23553c471091171..e8c2f6d47ca78dc421735458cfef1b1ee12ba3d8 100644 (file)
@@ -1,14 +1,14 @@
 MAINCLASS=Labyrinth
 SRC=ttttmp${MAINCLASS}.java \
        ../common/Pair.java \
-       ../common/Queue_t.java \
+       ttttmpQueue_t.java \
        Vector_t.java \
-       ../common/List_t.java \
-       ../common/List_Node.java \
-       ../common/List_Iter.java \
+       List_t.java \
+       List_Node.java \
+       List_Iter.java \
        Coordinate.java \
        ttttmpGrid.java \
-       Maze.java \
+       ttttmpMaze.java \
        ttttmpRouter.java \
        Point.java \
        Solve_arg.java \
@@ -20,9 +20,13 @@ default:
        cpp ${MAINCLASS}.java > tmp${MAINCLASS}.java
        cpp Grid.java   > tmpGrid.java
        cpp Router.java > tmpRouter.java
+       cpp Maze.java > tmpMaze.java
+       cpp Queue_t.java > tmpQueue_t.java
        ./extractLines tmp${MAINCLASS}.java
        ./extractLines tmpGrid.java
        ./extractLines tmpRouter.java
+       ./extractLines tmpMaze.java
+       ./extractLines tmpQueue_t.java
        ../../../buildscript ${FLAGS} -o ${MAINCLASS} ${SRC}
        rm ttt*.java tmp*.java