public int y;
public int z;
+ public Coordinate() {}
+
// coordiate_alloc will be constructor
// coordinate_t* coordinate_alloc(long x, long y, long z)
*========================================================*/
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;
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;
public int points_index;
public int[][] points_unaligned;
+ public 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;
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;
(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);
}
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];
}
*/
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;
}
*/
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);
}
*/
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);
}
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);
{
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++) {
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("");
}
}
// For threads
int threadID;
- Router.Arg routerArg;
+ Solve_Arg routerArg;
private void setDefaultParams() {
setDefaultParams();
- while (i < args.length && argv[i].startswith("-")) {
+ while (i < arg.length() && argv[i].charAt(0) == '-' ) {
arg = argv[i++];
// check options
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);
}
}
}
- public Labyrinth(int myID,Router.Arg rArg)
+ public Labyrinth(int myID,Solve_Arg rArg)
{
threadID = myID;
routerArg = rArg;
}
}
+ public void displayUsage()
+ {
+ System.out.println("Usage: Labyrinth [options]");
+ System.out.println("Options:");
+ System.out.println(" b <INT> bend cost");
+ System.out.println(" i <FILE> input file name");
+ System.out.println(" p print routed maze");
+ System.out.println(" t <INT> Number of threads");
+ System.out.println(" x <INT> x movement cost");
+ System.out.println(" y <INT> y movement cost");
+ System.out.println(" z <INT> z movement cost");
+ }
+
+
public static void main(String[] argv)
{
/*
*/
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 */
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");
* -- 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();
}
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;
}
* =============================================================================
* void list_free (list_t* listPtr);
*/
- public static void free(List listPtr)
+ public static void free(List_t listPtr)
{
listPtr = null;
}
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;
}
List_Node currPtr;
prevPtr = findPrevious(dataPtr);
- currPtr = prePtr.nextPtr;
+ currPtr = prevPtr.nextPtr;
nodePtr = allocNode(dataPtr);
if (nodePtr == null) {
}
nodePtr.nextPtr = currPtr;
- prevPtr.nextPr = nodePtr;
+ prevPtr.nextPtr = nodePtr;
size++;
return true;
}
int compareObject(Object obj1,Object obj2) {
- return obj1 - obj2;
+ return 1;
}
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;
* =============================================================================
*/
+#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
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);
}
* 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);
}
}
* =============================================================================
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
*/
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;
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;
}
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;
}
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();
}
* =============================================================================
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);
}
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];
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;
} /* iterate over pathVectorList */
if(doPrintPaths) {
- system.out.println("\nRouted Maze:");
+ System.out.println("\nRouted Maze:");
testGridPtr.print();
}
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;
#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
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;
* ============================================================================
*/
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));
}
}
}
* 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.
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;
} /* iterate over work queue */
- return isPathfound;
+ return isPathFound;
}
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;
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 */
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
// 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;
}
if(success) {
boolean status = myPathVectorPtr.vector_pushBack(pointVectorPtr);
+ if(status) {
+ System.out.println("Error in Router_Solve");
+ System.exit(1);
+ }
}
}
int size;
int capacity;
Object[] elements;
- QuickSort qsort;
+// QuickSort qsort;
public Vector_t() {
- qsort = new QuickSort();
+// qsort = new QuickSort();
}
/* =============================================================================
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 \
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