From 852281b02ea154a1878ecf16a182d67b632295ce Mon Sep 17 00:00:00 2001 From: jzhou Date: Wed, 3 Sep 2008 18:06:14 +0000 Subject: [PATCH] changes --- Robust/src/Benchmarks/MMG/Java/Ghost.java | 30 ++++---- Robust/src/Benchmarks/MMG/Java/Map.java | 83 +++++++++++----------- Robust/src/Benchmarks/MMG/Java/Node.java | 34 --------- Robust/src/Benchmarks/MMG/Java/Pacman.java | 38 +++++----- Robust/src/Benchmarks/MMG/Nor/Ghost.java | 34 ++++----- Robust/src/Benchmarks/MMG/Nor/MMG.java | 2 +- Robust/src/Benchmarks/MMG/Nor/Map.java | 83 +++++++++++----------- Robust/src/Benchmarks/MMG/Nor/Node.java | 34 --------- Robust/src/Benchmarks/MMG/Nor/Pacman.java | 40 +++++------ Robust/src/Benchmarks/MMG/Tag/Ghost.java | 30 ++++---- Robust/src/Benchmarks/MMG/Tag/Map.java | 83 +++++++++++----------- Robust/src/Benchmarks/MMG/Tag/Node.java | 34 --------- Robust/src/Benchmarks/MMG/Tag/Pacman.java | 40 +++++------ 13 files changed, 228 insertions(+), 337 deletions(-) delete mode 100644 Robust/src/Benchmarks/MMG/Java/Node.java delete mode 100644 Robust/src/Benchmarks/MMG/Nor/Node.java delete mode 100644 Robust/src/Benchmarks/MMG/Tag/Node.java diff --git a/Robust/src/Benchmarks/MMG/Java/Ghost.java b/Robust/src/Benchmarks/MMG/Java/Ghost.java index 1793f49e..9b3c46f2 100755 --- a/Robust/src/Benchmarks/MMG/Java/Ghost.java +++ b/Robust/src/Benchmarks/MMG/Java/Ghost.java @@ -30,7 +30,7 @@ public class Ghost { private void setNextDirection() { // current position of the ghost - Node start = this.m_map.m_mapNodes[this.m_locY * this.m_map.m_nrofblocks + this.m_locX]; + int start = this.m_locY * this.m_map.m_nrofblocks + this.m_locX; boolean set = false; Vector cuts = new Vector(); int tmptarget = 0; @@ -57,7 +57,7 @@ public class Ghost { //System.printString("Target: " + this.m_target + "\n"); while(!found) { int parent = parents[index]; - if(parent == start.getIndex()) { + if(parent == start) { found = true; } else { index = parent; @@ -65,8 +65,8 @@ public class Ghost { } // set the chase direction - int nx = this.m_map.m_mapNodes[index].getXLoc(); - int ny = this.m_map.m_mapNodes[index].getYLoc(); + int nx = index % this.m_map.m_nrofblocks; + int ny = index / this.m_map.m_nrofblocks; this.m_dx = nx - this.m_locX; this.m_dy = ny - this.m_locY; if(this.m_dx > 0) { @@ -114,17 +114,17 @@ public class Ghost { // Array parents records parent for a node in the BFS search, // the last item of parents records the least steps to reach end node from start node // Vector cuts specifies which nodes can not be the first one to access in this BFS - private boolean BFS(Node start, int[] parents, Vector cuts) { + private boolean BFS(int start, int[] parents, Vector cuts) { int steps = 0; Vector toaccess = new Vector(); - toaccess.addElement(start); + toaccess.addElement(new Integer(start)); while(toaccess.size() > 0) { //System.printString("bbb\n"); // pull out the first one to access - Node access = (Node)toaccess.elementAt(0); + int access = ((Integer)toaccess.elementAt(0)).intValue(); toaccess.removeElementAt(0); for(int i = 0; i < this.m_map.m_pacMenX.length; i++) { - if((access.getXLoc() == this.m_map.m_pacMenX[i]) && (access.getYLoc() == this.m_map.m_pacMenY[i])) { + if(((access%this.m_map.m_nrofblocks) == this.m_map.m_pacMenX[i]) && ((access/this.m_map.m_nrofblocks) == this.m_map.m_pacMenY[i])) { // hit one pacman this.m_target = i; parents[parents.length - 1] = steps; @@ -132,26 +132,26 @@ public class Ghost { } } steps++; - Vector neighbours = access.getNeighbours(); + Vector neighbours = this.m_map.getNeighbours(access); for(int i = 0; i < neighbours.size(); i++) { - Node neighbour = (Node)neighbours.elementAt(i); - if(parents[neighbour.getIndex()] == -1) { + int neighbour = ((Integer)neighbours.elementAt(i)).intValue(); + if(parents[neighbour] == -1) { // not accessed boolean ignore = false; - if(access.getIndex() == start.getIndex()) { + if(access == start) { // start node, check if the neighbour node is in cuts int j = 0; while((!ignore) && (j < cuts.size())) { int tmp = ((Integer)cuts.elementAt(j)).intValue(); - if(tmp == neighbour.getIndex()) { + if(tmp == neighbour) { ignore = true; } j++; } } if(!ignore) { - parents[neighbour.getIndex()] = access.getIndex(); - toaccess.addElement(neighbour); + parents[neighbour] = access; + toaccess.addElement(new Integer(neighbour)); } } } diff --git a/Robust/src/Benchmarks/MMG/Java/Map.java b/Robust/src/Benchmarks/MMG/Java/Map.java index 5cf20975..4720b2e8 100755 --- a/Robust/src/Benchmarks/MMG/Java/Map.java +++ b/Robust/src/Benchmarks/MMG/Java/Map.java @@ -2,7 +2,6 @@ public class Map { // maze private int m_nrofblocks; public int[] m_map; - public Node[] m_mapNodes; public Ghost[] m_ghosts; public Pacman[] m_pacmen; @@ -31,7 +30,6 @@ public class Map { //System.printString("step 1\n"); this.m_nrofblocks = 15; this.m_map = new int[this.m_nrofblocks*this.m_nrofblocks]; - this.m_mapNodes = new Node[this.m_nrofblocks*this.m_nrofblocks]; this.m_nrofpacs = nrofpacs; this.m_pacMenX = new int[this.m_nrofpacs]; @@ -56,7 +54,6 @@ public class Map { for(int i = 0; i < this.m_nrofblocks*this.m_nrofblocks; i++) { this.m_map[i] = -1; - this.m_mapNodes[i] = new Node(i%this.m_nrofblocks, i/this.m_nrofblocks, i); } //System.printString("step 2\n"); @@ -92,46 +89,6 @@ public class Map { this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=6;this.m_map[i++]=13;this.m_map[i++]=5;this.m_map[i++]=11;this.m_map[i++]=2;this.m_map[i++]=14;this.m_map[i++]=5;this.m_map[i++]=13;this.m_map[i++]=3;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=4; this.m_map[i++]=5;this.m_map[i++]=11;this.m_map[i++]=14;this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=8;this.m_map[i++]=6;this.m_map[i++]=13;this.m_map[i++]=3;this.m_map[i++]=8;this.m_map[i++]=10;this.m_map[i++]=4;this.m_map[i++]=11;this.m_map[i++]=14;this.m_map[i++]=5; this.m_map[i++]=9;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=12;this.m_map[i++]=3;this.m_map[i++]=6;this.m_map[i++]=9;this.m_map[i++]=10;this.m_map[i++]=12;this.m_map[i++]=3;this.m_map[i++]=6;this.m_map[i++]=9;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=12; // 15*15 - - // initilize the graph of the maze - for(i = 0; i < this.m_nrofblocks*this.m_nrofblocks; i++) { - int tmp = this.m_map[i]; - Node tmpNode = this.m_mapNodes[i]; - int locX = tmpNode.getXLoc(); - int locY = tmpNode.getYLoc(); - if((int)(tmp & 1) == 0) { - // can go left - if(locX == 0) { - tmpNode.addNeighbour(this.m_mapNodes[locY * this.m_nrofblocks + this.m_nrofblocks - 1]); - } else { - tmpNode.addNeighbour(this.m_mapNodes[i - 1]); - } - } - if((int)(tmp & 2) == 0) { - // can go up - if(locY == 0) { - tmpNode.addNeighbour(this.m_mapNodes[(this.m_nrofblocks - 1) * this.m_nrofblocks + locX]); - } else { - tmpNode.addNeighbour(this.m_mapNodes[(locY - 1) * this.m_nrofblocks + locX]); - } - } - if((int)(tmp & 4) == 0) { - // can go right - if(locX == this.m_nrofblocks - 1) { - tmpNode.addNeighbour(this.m_mapNodes[locY * this.m_nrofblocks]); - } else { - tmpNode.addNeighbour(this.m_mapNodes[i + 1]); - } - } - if((int)(tmp & 8) == 0) { - // can go down - if(locY == this.m_nrofblocks - 1) { - tmpNode.addNeighbour(this.m_mapNodes[locX]); - } else { - tmpNode.addNeighbour(this.m_mapNodes[(locY + 1) * this.m_nrofblocks + locX]); - } - } - } } public void placePacman(Pacman t) { @@ -176,4 +133,44 @@ public class Map { public boolean isfinish() { return this.m_nrofpacs == 0; } + + public Vector getNeighbours(int index) { + Vector neighbours = new Vector(); + int tmp = this.m_map[index]; + int locX = index % this.m_nrofblocks; + int locY = index / this.m_nrofblocks; + if((int)(tmp & 1) == 0) { + // can go left + if(locX == 0) { + neighbours.addElement(new Integer(locY * this.m_nrofblocks + this.m_nrofblocks - 1)); + } else { + neighbours.addElement(new Integer(index - 1)); + } + } + if((int)(tmp & 2) == 0) { + // can go up + if(locY == 0) { + neighbours.addElement(new Integer((this.m_nrofblocks - 1) * this.m_nrofblocks + locX)); + } else { + neighbours.addElement(new Integer((locY - 1) * this.m_nrofblocks + locX)); + } + } + if((int)(tmp & 4) == 0) { + // can go right + if(locX == this.m_nrofblocks - 1) { + neighbours.addElement(new Integer(locY * this.m_nrofblocks)); + } else { + neighbours.addElement(new Integer(index + 1)); + } + } + if((int)(tmp & 8) == 0) { + // can go down + if(locY == this.m_nrofblocks - 1) { + neighbours.addElement(new Integer(locX)); + } else { + neighbours.addElement(new Integer((locY + 1) * this.m_nrofblocks + locX)); + } + } + return neighbours; + } } diff --git a/Robust/src/Benchmarks/MMG/Java/Node.java b/Robust/src/Benchmarks/MMG/Java/Node.java deleted file mode 100644 index bcc4d3e1..00000000 --- a/Robust/src/Benchmarks/MMG/Java/Node.java +++ /dev/null @@ -1,34 +0,0 @@ -public class Node { - - int m_locX; - int m_locY; - int m_index; - Vector m_neighbours; - - public Node(int locX, int locY, int index) { - this.m_locX = locX; - this.m_locY = locY; - this.m_index = index; - this.m_neighbours = new Vector(); - } - - public void addNeighbour(Node n) { - this.m_neighbours.addElement(n); - } - - public Vector getNeighbours() { - return this.m_neighbours; - } - - public int getXLoc() { - return this.m_locX; - } - - public int getYLoc() { - return this.m_locY; - } - - public int getIndex() { - return this.m_index; - } -} \ No newline at end of file diff --git a/Robust/src/Benchmarks/MMG/Java/Pacman.java b/Robust/src/Benchmarks/MMG/Java/Pacman.java index 6cbff494..386704e5 100755 --- a/Robust/src/Benchmarks/MMG/Java/Pacman.java +++ b/Robust/src/Benchmarks/MMG/Java/Pacman.java @@ -35,7 +35,7 @@ public class Pacman { private void setNextDirection() { // current position of the ghost - Node start = this.m_map.m_mapNodes[this.m_locY * this.m_map.m_nrofblocks + this.m_locX]; + int start = this.m_locY * this.m_map.m_nrofblocks + this.m_locX; // get target's position int targetx = this.m_tx; @@ -44,7 +44,7 @@ public class Pacman { nextLocation[0] = nextLocation[1] = -1; // target's position - Node end = this.m_map.m_mapNodes[targety * this.m_map.m_nrofblocks + targetx]; + int end = targety * this.m_map.m_nrofblocks + targetx; // breadth-first traverse the graph view of the maze // check the shortest path for the start node to the end node @@ -68,10 +68,10 @@ public class Pacman { } else { // Reversely go over the parents array to find the next node to reach boolean found = false; - int index = end.getIndex(); + int index = end; while(!found) { int parent = parents[index]; - if(parent == start.getIndex()) { + if(parent == start) { found = true; } else { index = parent; @@ -79,8 +79,8 @@ public class Pacman { } // set the chase direction - int nx = this.m_map.m_mapNodes[index].getXLoc(); - int ny = this.m_map.m_mapNodes[index].getYLoc(); + int nx = index % this.m_map.m_nrofblocks; + int ny = index / this.m_map.m_nrofblocks; this.m_dx = nx - this.m_locX; this.m_dy = ny - this.m_locY; if(this.m_dx > 0) { @@ -127,40 +127,40 @@ public class Pacman { // Array parents records parent for a node in the BFS search, // the last item of parents records the least steps to reach end node from start node // Vector cuts specifies which nodes can not be the first one to access in this BFS - private boolean BFS(Node start, Node end, int[] parents, Vector cuts) { + private boolean BFS(int start, int end, int[] parents, Vector cuts) { int steps = 0; Vector toaccess = new Vector(); - toaccess.addElement(start); + toaccess.addElement(new Integer(start)); while(toaccess.size() > 0) { // pull out the first one to access - Node access = (Node)toaccess.elementAt(0); + int access = ((Integer)toaccess.elementAt(0)).intValue(); toaccess.removeElementAt(0); - if(access.getIndex() == end.getIndex()) { + if(access == end) { // hit the end node parents[parents.length - 1] = steps; return true; } steps++; - Vector neighbours = access.getNeighbours(); + Vector neighbours = this.m_map.getNeighbours(access); for(int i = 0; i < neighbours.size(); i++) { - Node neighbour = (Node)neighbours.elementAt(i); - if(parents[neighbour.getIndex()] == -1) { + int neighbour = ((Integer)neighbours.elementAt(i)).intValue(); + if(parents[neighbour] == -1) { // not accessed boolean ignore = false; - if(access.getIndex() == start.getIndex()) { + if(access == start) { // start node, check if the neighbour node is in cuts int j = 0; while((!ignore) && (j < cuts.size())) { int tmp = ((Integer)cuts.elementAt(j)).intValue(); - if(tmp == neighbour.getIndex()) { + if(tmp == neighbour) { ignore = true; } j++; } } if(!ignore) { - parents[neighbour.getIndex()] = access.getIndex(); - toaccess.addElement(neighbour); + parents[neighbour] = access; + toaccess.addElement(new Integer(neighbour)); } } } @@ -265,9 +265,9 @@ public class Pacman { // check the least steps for the ghosts to reach point location int chasesteps = -1; - Node end = this.m_map.m_mapNodes[point[1] * this.m_map.m_nrofblocks + point[0]]; + int end = point[1] * this.m_map.m_nrofblocks + point[0]; for(int i = 0; i < this.m_map.m_ghostsX.length; i++) { - Node start = this.m_map.m_mapNodes[this.m_map.m_ghostsY[i] * this.m_map.m_nrofblocks + this.m_map.m_ghostsX[i]]; + int start = this.m_map.m_ghostsY[i] * this.m_map.m_nrofblocks + this.m_map.m_ghostsX[i]; int parents[] = new int[this.m_map.m_nrofblocks * this.m_map.m_nrofblocks + 1]; for(int j = 0; j < parents.length; j++) { parents[j] = -1; diff --git a/Robust/src/Benchmarks/MMG/Nor/Ghost.java b/Robust/src/Benchmarks/MMG/Nor/Ghost.java index 91f32614..e150c31e 100755 --- a/Robust/src/Benchmarks/MMG/Nor/Ghost.java +++ b/Robust/src/Benchmarks/MMG/Nor/Ghost.java @@ -32,7 +32,7 @@ public class Ghost { private void setNextDirection() { // current position of the ghost - Node start = this.m_map.m_mapNodes[this.m_locY * this.m_map.m_nrofblocks + this.m_locX]; + int start = this.m_locY * this.m_map.m_nrofblocks + this.m_locX; boolean set = false; Vector cuts = new Vector(); int tmptarget = 0; @@ -59,7 +59,7 @@ public class Ghost { //System.printString("Target: " + this.m_target + "\n"); while(!found) { int parent = parents[index]; - if(parent == start.getIndex()) { + if(parent == start) { found = true; } else { index = parent; @@ -67,8 +67,8 @@ public class Ghost { } // set the chase direction - int nx = this.m_map.m_mapNodes[index].getXLoc(); - int ny = this.m_map.m_mapNodes[index].getYLoc(); + int nx = index % this.m_map.m_nrofblocks; + int ny = index / this.m_map.m_nrofblocks; this.m_dx = nx - this.m_locX; this.m_dy = ny - this.m_locY; if(this.m_dx > 0) { @@ -116,17 +116,18 @@ public class Ghost { // Array parents records parent for a node in the BFS search, // the last item of parents records the least steps to reach end node from start node // Vector cuts specifies which nodes can not be the first one to access in this BFS - private boolean BFS(Node start, int[] parents, Vector cuts) { + private boolean BFS(int start, int[] parents, Vector cuts) { + //System.printString("aaa\n"); int steps = 0; Vector toaccess = new Vector(); - toaccess.addElement(start); + toaccess.addElement(new Integer(start)); while(toaccess.size() > 0) { //System.printString("bbb\n"); // pull out the first one to access - Node access = (Node)toaccess.elementAt(0); + int access = ((Integer)toaccess.elementAt(0)).intValue(); toaccess.removeElementAt(0); for(int i = 0; i < this.m_map.m_pacMenX.length; i++) { - if((access.getXLoc() == this.m_map.m_pacMenX[i]) && (access.getYLoc() == this.m_map.m_pacMenY[i])) { + if(((access%this.m_map.m_nrofblocks) == this.m_map.m_pacMenX[i]) && ((access/this.m_map.m_nrofblocks) == this.m_map.m_pacMenY[i])) { // hit one pacman this.m_target = i; parents[parents.length - 1] = steps; @@ -134,30 +135,31 @@ public class Ghost { } } steps++; - Vector neighbours = access.getNeighbours(); + Vector neighbours = this.m_map.getNeighbours(access); for(int i = 0; i < neighbours.size(); i++) { - Node neighbour = (Node)neighbours.elementAt(i); - if(parents[neighbour.getIndex()] == -1) { + int neighbour = ((Integer)neighbours.elementAt(i)).intValue(); + if(parents[neighbour] == -1) { // not accessed boolean ignore = false; - if(access.getIndex() == start.getIndex()) { + if(access == start) { // start node, check if the neighbour node is in cuts int j = 0; while((!ignore) && (j < cuts.size())) { int tmp = ((Integer)cuts.elementAt(j)).intValue(); - if(tmp == neighbour.getIndex()) { + if(tmp == neighbour) { ignore = true; } j++; } } if(!ignore) { - parents[neighbour.getIndex()] = access.getIndex(); - toaccess.addElement(neighbour); + parents[neighbour] = access; + toaccess.addElement(new Integer(neighbour)); } } } } + //System.printString("ccc\n"); parents[parents.length - 1] = -1; return false; } @@ -320,4 +322,4 @@ public class Ghost { this.m_dy = 0; //System.printString("Ghost " + this.m_index + ": (" + this.m_locX + ", " + this.m_locY + ")\n"); } -} +} \ No newline at end of file diff --git a/Robust/src/Benchmarks/MMG/Nor/MMG.java b/Robust/src/Benchmarks/MMG/Nor/MMG.java index 40392422..54043358 100755 --- a/Robust/src/Benchmarks/MMG/Nor/MMG.java +++ b/Robust/src/Benchmarks/MMG/Nor/MMG.java @@ -134,6 +134,6 @@ task next(Map map{next}) { } task finish(Map map{finish}) { - System.printString("Task Finish\n"); + System.printString("Task Finish\n"); taskexit(map{!finish}); } diff --git a/Robust/src/Benchmarks/MMG/Nor/Map.java b/Robust/src/Benchmarks/MMG/Nor/Map.java index 650f0a62..14903686 100755 --- a/Robust/src/Benchmarks/MMG/Nor/Map.java +++ b/Robust/src/Benchmarks/MMG/Nor/Map.java @@ -8,7 +8,6 @@ public class Map { // maze private int m_nrofblocks; public int[] m_map; - public Node[] m_mapNodes; // pacmen information public int m_nrofpacs; @@ -36,7 +35,6 @@ public class Map { //System.printString("step 1\n"); this.m_nrofblocks = 15; this.m_map = new int[this.m_nrofblocks*this.m_nrofblocks]; - this.m_mapNodes = new Node[this.m_nrofblocks*this.m_nrofblocks]; this.m_nrofpacs = nrofpacs; this.m_pacMenX = new int[this.m_nrofpacs]; @@ -59,7 +57,6 @@ public class Map { for(int i = 0; i < this.m_nrofblocks*this.m_nrofblocks; i++) { this.m_map[i] = -1; - this.m_mapNodes[i] = new Node(i%this.m_nrofblocks, i/this.m_nrofblocks, i); } //System.printString("step 2\n"); @@ -93,46 +90,6 @@ public class Map { this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=6;this.m_map[i++]=13;this.m_map[i++]=5;this.m_map[i++]=11;this.m_map[i++]=2;this.m_map[i++]=14;this.m_map[i++]=5;this.m_map[i++]=13;this.m_map[i++]=3;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=4; this.m_map[i++]=5;this.m_map[i++]=11;this.m_map[i++]=14;this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=8;this.m_map[i++]=6;this.m_map[i++]=13;this.m_map[i++]=3;this.m_map[i++]=8;this.m_map[i++]=10;this.m_map[i++]=4;this.m_map[i++]=11;this.m_map[i++]=14;this.m_map[i++]=5; this.m_map[i++]=9;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=12;this.m_map[i++]=3;this.m_map[i++]=6;this.m_map[i++]=9;this.m_map[i++]=10;this.m_map[i++]=12;this.m_map[i++]=3;this.m_map[i++]=6;this.m_map[i++]=9;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=12; // 15*15 - - // initilize the graph of the maze - for(i = 0; i < this.m_nrofblocks*this.m_nrofblocks; i++) { - int tmp = this.m_map[i]; - Node tmpNode = this.m_mapNodes[i]; - int locX = tmpNode.getXLoc(); - int locY = tmpNode.getYLoc(); - if((int)(tmp & 1) == 0) { - // can go left - if(locX == 0) { - tmpNode.addNeighbour(this.m_mapNodes[locY * this.m_nrofblocks + this.m_nrofblocks - 1]); - } else { - tmpNode.addNeighbour(this.m_mapNodes[i - 1]); - } - } - if((int)(tmp & 2) == 0) { - // can go up - if(locY == 0) { - tmpNode.addNeighbour(this.m_mapNodes[(this.m_nrofblocks - 1) * this.m_nrofblocks + locX]); - } else { - tmpNode.addNeighbour(this.m_mapNodes[(locY - 1) * this.m_nrofblocks + locX]); - } - } - if((int)(tmp & 4) == 0) { - // can go right - if(locX == this.m_nrofblocks - 1) { - tmpNode.addNeighbour(this.m_mapNodes[locY * this.m_nrofblocks]); - } else { - tmpNode.addNeighbour(this.m_mapNodes[i + 1]); - } - } - if((int)(tmp & 8) == 0) { - // can go down - if(locY == this.m_nrofblocks - 1) { - tmpNode.addNeighbour(this.m_mapNodes[locX]); - } else { - tmpNode.addNeighbour(this.m_mapNodes[(locY + 1) * this.m_nrofblocks + locX]); - } - } - } } public void placePacman(Pacman t) { @@ -177,4 +134,44 @@ public class Map { public boolean isfinish() { return this.m_nrofpacs == 0; } + + public Vector getNeighbours(int index) { + Vector neighbours = new Vector(); + int tmp = this.m_map[index]; + int locX = index % this.m_nrofblocks; + int locY = index / this.m_nrofblocks; + if((int)(tmp & 1) == 0) { + // can go left + if(locX == 0) { + neighbours.addElement(new Integer(locY * this.m_nrofblocks + this.m_nrofblocks - 1)); + } else { + neighbours.addElement(new Integer(index - 1)); + } + } + if((int)(tmp & 2) == 0) { + // can go up + if(locY == 0) { + neighbours.addElement(new Integer((this.m_nrofblocks - 1) * this.m_nrofblocks + locX)); + } else { + neighbours.addElement(new Integer((locY - 1) * this.m_nrofblocks + locX)); + } + } + if((int)(tmp & 4) == 0) { + // can go right + if(locX == this.m_nrofblocks - 1) { + neighbours.addElement(new Integer(locY * this.m_nrofblocks)); + } else { + neighbours.addElement(new Integer(index + 1)); + } + } + if((int)(tmp & 8) == 0) { + // can go down + if(locY == this.m_nrofblocks - 1) { + neighbours.addElement(new Integer(locX)); + } else { + neighbours.addElement(new Integer((locY + 1) * this.m_nrofblocks + locX)); + } + } + return neighbours; + } } diff --git a/Robust/src/Benchmarks/MMG/Nor/Node.java b/Robust/src/Benchmarks/MMG/Nor/Node.java deleted file mode 100644 index bcc4d3e1..00000000 --- a/Robust/src/Benchmarks/MMG/Nor/Node.java +++ /dev/null @@ -1,34 +0,0 @@ -public class Node { - - int m_locX; - int m_locY; - int m_index; - Vector m_neighbours; - - public Node(int locX, int locY, int index) { - this.m_locX = locX; - this.m_locY = locY; - this.m_index = index; - this.m_neighbours = new Vector(); - } - - public void addNeighbour(Node n) { - this.m_neighbours.addElement(n); - } - - public Vector getNeighbours() { - return this.m_neighbours; - } - - public int getXLoc() { - return this.m_locX; - } - - public int getYLoc() { - return this.m_locY; - } - - public int getIndex() { - return this.m_index; - } -} \ No newline at end of file diff --git a/Robust/src/Benchmarks/MMG/Nor/Pacman.java b/Robust/src/Benchmarks/MMG/Nor/Pacman.java index 651b90dc..2737b80c 100755 --- a/Robust/src/Benchmarks/MMG/Nor/Pacman.java +++ b/Robust/src/Benchmarks/MMG/Nor/Pacman.java @@ -38,7 +38,7 @@ public class Pacman { private void setNextDirection() { // current position of the ghost - Node start = this.m_map.m_mapNodes[this.m_locY * this.m_map.m_nrofblocks + this.m_locX]; + int start = this.m_locY * this.m_map.m_nrofblocks + this.m_locX; // get target's position int targetx = this.m_tx; @@ -47,7 +47,7 @@ public class Pacman { nextLocation[0] = nextLocation[1] = -1; // target's position - Node end = this.m_map.m_mapNodes[targety * this.m_map.m_nrofblocks + targetx]; + int end = targety * this.m_map.m_nrofblocks + targetx; // breadth-first traverse the graph view of the maze // check the shortest path for the start node to the end node @@ -71,10 +71,10 @@ public class Pacman { } else { // Reversely go over the parents array to find the next node to reach boolean found = false; - int index = end.getIndex(); + int index = end; while(!found) { int parent = parents[index]; - if(parent == start.getIndex()) { + if(parent == start) { found = true; } else { index = parent; @@ -82,8 +82,8 @@ public class Pacman { } // set the chase direction - int nx = this.m_map.m_mapNodes[index].getXLoc(); - int ny = this.m_map.m_mapNodes[index].getYLoc(); + int nx = index % this.m_map.m_nrofblocks; + int ny = index / this.m_map.m_nrofblocks; this.m_dx = nx - this.m_locX; this.m_dy = ny - this.m_locY; if(this.m_dx > 0) { @@ -130,40 +130,40 @@ public class Pacman { // Array parents records parent for a node in the BFS search, // the last item of parents records the least steps to reach end node from start node // Vector cuts specifies which nodes can not be the first one to access in this BFS - private boolean BFS(Node start, Node end, int[] parents, Vector cuts) { + private boolean BFS(int start, int end, int[] parents, Vector cuts) { int steps = 0; Vector toaccess = new Vector(); - toaccess.addElement(start); + toaccess.addElement(new Integer(start)); while(toaccess.size() > 0) { // pull out the first one to access - Node access = (Node)toaccess.elementAt(0); + int access = ((Integer)toaccess.elementAt(0)).intValue(); toaccess.removeElementAt(0); - if(access.getIndex() == end.getIndex()) { + if(access == end) { // hit the end node parents[parents.length - 1] = steps; return true; } steps++; - Vector neighbours = access.getNeighbours(); + Vector neighbours = this.m_map.getNeighbours(access); for(int i = 0; i < neighbours.size(); i++) { - Node neighbour = (Node)neighbours.elementAt(i); - if(parents[neighbour.getIndex()] == -1) { + int neighbour = ((Integer)neighbours.elementAt(i)).intValue(); + if(parents[neighbour] == -1) { // not accessed boolean ignore = false; - if(access.getIndex() == start.getIndex()) { + if(access == start) { // start node, check if the neighbour node is in cuts int j = 0; while((!ignore) && (j < cuts.size())) { int tmp = ((Integer)cuts.elementAt(j)).intValue(); - if(tmp == neighbour.getIndex()) { + if(tmp == neighbour) { ignore = true; } j++; } } if(!ignore) { - parents[neighbour.getIndex()] = access.getIndex(); - toaccess.addElement(neighbour); + parents[neighbour] = access; + toaccess.addElement(new Integer(neighbour)); } } } @@ -195,7 +195,7 @@ public class Pacman { locX++; } steps++; - + boolean set = false; // Determine next turning location. while (!set) { @@ -268,9 +268,9 @@ public class Pacman { // check the least steps for the ghosts to reach point location int chasesteps = -1; - Node end = this.m_map.m_mapNodes[point[1] * this.m_map.m_nrofblocks + point[0]]; + int end = point[1] * this.m_map.m_nrofblocks + point[0]; for(int i = 0; i < this.m_map.m_ghostsX.length; i++) { - Node start = this.m_map.m_mapNodes[this.m_map.m_ghostsY[i] * this.m_map.m_nrofblocks + this.m_map.m_ghostsX[i]]; + int start = this.m_map.m_ghostsY[i] * this.m_map.m_nrofblocks + this.m_map.m_ghostsX[i]; int parents[] = new int[this.m_map.m_nrofblocks * this.m_map.m_nrofblocks + 1]; for(int j = 0; j < parents.length; j++) { parents[j] = -1; diff --git a/Robust/src/Benchmarks/MMG/Tag/Ghost.java b/Robust/src/Benchmarks/MMG/Tag/Ghost.java index d7126aed..e150c31e 100755 --- a/Robust/src/Benchmarks/MMG/Tag/Ghost.java +++ b/Robust/src/Benchmarks/MMG/Tag/Ghost.java @@ -32,7 +32,7 @@ public class Ghost { private void setNextDirection() { // current position of the ghost - Node start = this.m_map.m_mapNodes[this.m_locY * this.m_map.m_nrofblocks + this.m_locX]; + int start = this.m_locY * this.m_map.m_nrofblocks + this.m_locX; boolean set = false; Vector cuts = new Vector(); int tmptarget = 0; @@ -59,7 +59,7 @@ public class Ghost { //System.printString("Target: " + this.m_target + "\n"); while(!found) { int parent = parents[index]; - if(parent == start.getIndex()) { + if(parent == start) { found = true; } else { index = parent; @@ -67,8 +67,8 @@ public class Ghost { } // set the chase direction - int nx = this.m_map.m_mapNodes[index].getXLoc(); - int ny = this.m_map.m_mapNodes[index].getYLoc(); + int nx = index % this.m_map.m_nrofblocks; + int ny = index / this.m_map.m_nrofblocks; this.m_dx = nx - this.m_locX; this.m_dy = ny - this.m_locY; if(this.m_dx > 0) { @@ -116,18 +116,18 @@ public class Ghost { // Array parents records parent for a node in the BFS search, // the last item of parents records the least steps to reach end node from start node // Vector cuts specifies which nodes can not be the first one to access in this BFS - private boolean BFS(Node start, int[] parents, Vector cuts) { + private boolean BFS(int start, int[] parents, Vector cuts) { //System.printString("aaa\n"); int steps = 0; Vector toaccess = new Vector(); - toaccess.addElement(start); + toaccess.addElement(new Integer(start)); while(toaccess.size() > 0) { //System.printString("bbb\n"); // pull out the first one to access - Node access = (Node)toaccess.elementAt(0); + int access = ((Integer)toaccess.elementAt(0)).intValue(); toaccess.removeElementAt(0); for(int i = 0; i < this.m_map.m_pacMenX.length; i++) { - if((access.getXLoc() == this.m_map.m_pacMenX[i]) && (access.getYLoc() == this.m_map.m_pacMenY[i])) { + if(((access%this.m_map.m_nrofblocks) == this.m_map.m_pacMenX[i]) && ((access/this.m_map.m_nrofblocks) == this.m_map.m_pacMenY[i])) { // hit one pacman this.m_target = i; parents[parents.length - 1] = steps; @@ -135,26 +135,26 @@ public class Ghost { } } steps++; - Vector neighbours = access.getNeighbours(); + Vector neighbours = this.m_map.getNeighbours(access); for(int i = 0; i < neighbours.size(); i++) { - Node neighbour = (Node)neighbours.elementAt(i); - if(parents[neighbour.getIndex()] == -1) { + int neighbour = ((Integer)neighbours.elementAt(i)).intValue(); + if(parents[neighbour] == -1) { // not accessed boolean ignore = false; - if(access.getIndex() == start.getIndex()) { + if(access == start) { // start node, check if the neighbour node is in cuts int j = 0; while((!ignore) && (j < cuts.size())) { int tmp = ((Integer)cuts.elementAt(j)).intValue(); - if(tmp == neighbour.getIndex()) { + if(tmp == neighbour) { ignore = true; } j++; } } if(!ignore) { - parents[neighbour.getIndex()] = access.getIndex(); - toaccess.addElement(neighbour); + parents[neighbour] = access; + toaccess.addElement(new Integer(neighbour)); } } } diff --git a/Robust/src/Benchmarks/MMG/Tag/Map.java b/Robust/src/Benchmarks/MMG/Tag/Map.java index a75ec229..4afacc75 100755 --- a/Robust/src/Benchmarks/MMG/Tag/Map.java +++ b/Robust/src/Benchmarks/MMG/Tag/Map.java @@ -8,7 +8,6 @@ public class Map { // maze private int m_nrofblocks; public int[] m_map; - public Node[] m_mapNodes; // pacmen information public int m_nrofpacs; @@ -36,7 +35,6 @@ public class Map { //System.printString("step 1\n"); this.m_nrofblocks = 15; this.m_map = new int[this.m_nrofblocks*this.m_nrofblocks]; - this.m_mapNodes = new Node[this.m_nrofblocks*this.m_nrofblocks]; this.m_nrofpacs = nrofpacs; this.m_pacMenX = new int[this.m_nrofpacs]; @@ -59,7 +57,6 @@ public class Map { for(int i = 0; i < this.m_nrofblocks*this.m_nrofblocks; i++) { this.m_map[i] = -1; - this.m_mapNodes[i] = new Node(i%this.m_nrofblocks, i/this.m_nrofblocks, i); } //System.printString("step 2\n"); @@ -93,46 +90,6 @@ public class Map { this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=6;this.m_map[i++]=13;this.m_map[i++]=5;this.m_map[i++]=11;this.m_map[i++]=2;this.m_map[i++]=14;this.m_map[i++]=5;this.m_map[i++]=13;this.m_map[i++]=3;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=4; this.m_map[i++]=5;this.m_map[i++]=11;this.m_map[i++]=14;this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=8;this.m_map[i++]=6;this.m_map[i++]=13;this.m_map[i++]=3;this.m_map[i++]=8;this.m_map[i++]=10;this.m_map[i++]=4;this.m_map[i++]=11;this.m_map[i++]=14;this.m_map[i++]=5; this.m_map[i++]=9;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=12;this.m_map[i++]=3;this.m_map[i++]=6;this.m_map[i++]=9;this.m_map[i++]=10;this.m_map[i++]=12;this.m_map[i++]=3;this.m_map[i++]=6;this.m_map[i++]=9;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=12; // 15*15 - - // initilize the graph of the maze - for(i = 0; i < this.m_nrofblocks*this.m_nrofblocks; i++) { - int tmp = this.m_map[i]; - Node tmpNode = this.m_mapNodes[i]; - int locX = tmpNode.getXLoc(); - int locY = tmpNode.getYLoc(); - if((int)(tmp & 1) == 0) { - // can go left - if(locX == 0) { - tmpNode.addNeighbour(this.m_mapNodes[locY * this.m_nrofblocks + this.m_nrofblocks - 1]); - } else { - tmpNode.addNeighbour(this.m_mapNodes[i - 1]); - } - } - if((int)(tmp & 2) == 0) { - // can go up - if(locY == 0) { - tmpNode.addNeighbour(this.m_mapNodes[(this.m_nrofblocks - 1) * this.m_nrofblocks + locX]); - } else { - tmpNode.addNeighbour(this.m_mapNodes[(locY - 1) * this.m_nrofblocks + locX]); - } - } - if((int)(tmp & 4) == 0) { - // can go right - if(locX == this.m_nrofblocks - 1) { - tmpNode.addNeighbour(this.m_mapNodes[locY * this.m_nrofblocks]); - } else { - tmpNode.addNeighbour(this.m_mapNodes[i + 1]); - } - } - if((int)(tmp & 8) == 0) { - // can go down - if(locY == this.m_nrofblocks - 1) { - tmpNode.addNeighbour(this.m_mapNodes[locX]); - } else { - tmpNode.addNeighbour(this.m_mapNodes[(locY + 1) * this.m_nrofblocks + locX]); - } - } - } } public void placePacman(Pacman t) { @@ -177,4 +134,44 @@ public class Map { public boolean isfinish() { return this.m_nrofpacs == 0; } + + public Vector getNeighbours(int index) { + Vector neighbours = new Vector(); + int tmp = this.m_map[index]; + int locX = index % this.m_nrofblocks; + int locY = index / this.m_nrofblocks; + if((int)(tmp & 1) == 0) { + // can go left + if(locX == 0) { + neighbours.addElement(new Integer(locY * this.m_nrofblocks + this.m_nrofblocks - 1)); + } else { + neighbours.addElement(new Integer(index - 1)); + } + } + if((int)(tmp & 2) == 0) { + // can go up + if(locY == 0) { + neighbours.addElement(new Integer((this.m_nrofblocks - 1) * this.m_nrofblocks + locX)); + } else { + neighbours.addElement(new Integer((locY - 1) * this.m_nrofblocks + locX)); + } + } + if((int)(tmp & 4) == 0) { + // can go right + if(locX == this.m_nrofblocks - 1) { + neighbours.addElement(new Integer(locY * this.m_nrofblocks)); + } else { + neighbours.addElement(new Integer(index + 1)); + } + } + if((int)(tmp & 8) == 0) { + // can go down + if(locY == this.m_nrofblocks - 1) { + neighbours.addElement(new Integer(locX)); + } else { + neighbours.addElement(new Integer((locY + 1) * this.m_nrofblocks + locX)); + } + } + return neighbours; + } } \ No newline at end of file diff --git a/Robust/src/Benchmarks/MMG/Tag/Node.java b/Robust/src/Benchmarks/MMG/Tag/Node.java deleted file mode 100644 index bcc4d3e1..00000000 --- a/Robust/src/Benchmarks/MMG/Tag/Node.java +++ /dev/null @@ -1,34 +0,0 @@ -public class Node { - - int m_locX; - int m_locY; - int m_index; - Vector m_neighbours; - - public Node(int locX, int locY, int index) { - this.m_locX = locX; - this.m_locY = locY; - this.m_index = index; - this.m_neighbours = new Vector(); - } - - public void addNeighbour(Node n) { - this.m_neighbours.addElement(n); - } - - public Vector getNeighbours() { - return this.m_neighbours; - } - - public int getXLoc() { - return this.m_locX; - } - - public int getYLoc() { - return this.m_locY; - } - - public int getIndex() { - return this.m_index; - } -} \ No newline at end of file diff --git a/Robust/src/Benchmarks/MMG/Tag/Pacman.java b/Robust/src/Benchmarks/MMG/Tag/Pacman.java index 651b90dc..2737b80c 100755 --- a/Robust/src/Benchmarks/MMG/Tag/Pacman.java +++ b/Robust/src/Benchmarks/MMG/Tag/Pacman.java @@ -38,7 +38,7 @@ public class Pacman { private void setNextDirection() { // current position of the ghost - Node start = this.m_map.m_mapNodes[this.m_locY * this.m_map.m_nrofblocks + this.m_locX]; + int start = this.m_locY * this.m_map.m_nrofblocks + this.m_locX; // get target's position int targetx = this.m_tx; @@ -47,7 +47,7 @@ public class Pacman { nextLocation[0] = nextLocation[1] = -1; // target's position - Node end = this.m_map.m_mapNodes[targety * this.m_map.m_nrofblocks + targetx]; + int end = targety * this.m_map.m_nrofblocks + targetx; // breadth-first traverse the graph view of the maze // check the shortest path for the start node to the end node @@ -71,10 +71,10 @@ public class Pacman { } else { // Reversely go over the parents array to find the next node to reach boolean found = false; - int index = end.getIndex(); + int index = end; while(!found) { int parent = parents[index]; - if(parent == start.getIndex()) { + if(parent == start) { found = true; } else { index = parent; @@ -82,8 +82,8 @@ public class Pacman { } // set the chase direction - int nx = this.m_map.m_mapNodes[index].getXLoc(); - int ny = this.m_map.m_mapNodes[index].getYLoc(); + int nx = index % this.m_map.m_nrofblocks; + int ny = index / this.m_map.m_nrofblocks; this.m_dx = nx - this.m_locX; this.m_dy = ny - this.m_locY; if(this.m_dx > 0) { @@ -130,40 +130,40 @@ public class Pacman { // Array parents records parent for a node in the BFS search, // the last item of parents records the least steps to reach end node from start node // Vector cuts specifies which nodes can not be the first one to access in this BFS - private boolean BFS(Node start, Node end, int[] parents, Vector cuts) { + private boolean BFS(int start, int end, int[] parents, Vector cuts) { int steps = 0; Vector toaccess = new Vector(); - toaccess.addElement(start); + toaccess.addElement(new Integer(start)); while(toaccess.size() > 0) { // pull out the first one to access - Node access = (Node)toaccess.elementAt(0); + int access = ((Integer)toaccess.elementAt(0)).intValue(); toaccess.removeElementAt(0); - if(access.getIndex() == end.getIndex()) { + if(access == end) { // hit the end node parents[parents.length - 1] = steps; return true; } steps++; - Vector neighbours = access.getNeighbours(); + Vector neighbours = this.m_map.getNeighbours(access); for(int i = 0; i < neighbours.size(); i++) { - Node neighbour = (Node)neighbours.elementAt(i); - if(parents[neighbour.getIndex()] == -1) { + int neighbour = ((Integer)neighbours.elementAt(i)).intValue(); + if(parents[neighbour] == -1) { // not accessed boolean ignore = false; - if(access.getIndex() == start.getIndex()) { + if(access == start) { // start node, check if the neighbour node is in cuts int j = 0; while((!ignore) && (j < cuts.size())) { int tmp = ((Integer)cuts.elementAt(j)).intValue(); - if(tmp == neighbour.getIndex()) { + if(tmp == neighbour) { ignore = true; } j++; } } if(!ignore) { - parents[neighbour.getIndex()] = access.getIndex(); - toaccess.addElement(neighbour); + parents[neighbour] = access; + toaccess.addElement(new Integer(neighbour)); } } } @@ -195,7 +195,7 @@ public class Pacman { locX++; } steps++; - + boolean set = false; // Determine next turning location. while (!set) { @@ -268,9 +268,9 @@ public class Pacman { // check the least steps for the ghosts to reach point location int chasesteps = -1; - Node end = this.m_map.m_mapNodes[point[1] * this.m_map.m_nrofblocks + point[0]]; + int end = point[1] * this.m_map.m_nrofblocks + point[0]; for(int i = 0; i < this.m_map.m_ghostsX.length; i++) { - Node start = this.m_map.m_mapNodes[this.m_map.m_ghostsY[i] * this.m_map.m_nrofblocks + this.m_map.m_ghostsX[i]]; + int start = this.m_map.m_ghostsY[i] * this.m_map.m_nrofblocks + this.m_map.m_ghostsX[i]; int parents[] = new int[this.m_map.m_nrofblocks * this.m_map.m_nrofblocks + 1]; for(int j = 0; j < parents.length; j++) { parents[j] = -1; -- 2.34.1