Difference between revisions of "Thread:Talk:Main Page/Running Error - Robot is not stopping, forcing a stop"

From Robowiki
Jump to navigation Jump to search
m
m (fix syntax highlighting so I can read it)
 
Line 17: Line 17:
 
Max turn computation time: 532809
 
Max turn computation time: 532809
  
<code>
+
<syntaxhighlight>
private boolean pathFinding_BFS(Node start, Node end){
+
private boolean pathFinding_BFS(Node start, Node end){
 
 
 
LinkedList<Node> queue = new LinkedList<Node>();
 
LinkedList<Node> queue = new LinkedList<Node>();
 
 
queue.add(start);
 
queue.add(start);
 
 
start.setMarked();
 
start.setMarked();
 
 
while (!queue.isEmpty()){
 
while (!queue.isEmpty()){
 
 
Node temp = (Node)queue.poll();
 
Node temp = (Node)queue.poll();
 
 
System.out.println("first node:" + temp.getPointInPath().getX() + " y " + temp.getPointInPath().getY());
 
System.out.println("first node:" + temp.getPointInPath().getX() + " y " + temp.getPointInPath().getY());
 
 
if (temp.equals(end)){
 
if (temp.equals(end)){
 
 
temp.setPrevNodeInPath(temp.getPrevNodeInPath());
 
temp.setPrevNodeInPath(temp.getPrevNodeInPath());
 
 
return true;
 
return true;
 
 
}else{
 
}else{
 
 
for (Node n : temp.getAdjacentNode()){
 
for (Node n : temp.getAdjacentNode()){
 
 
System.out.println("in node:" + n.getPointInPath().getX() + " y " +  
 
System.out.println("in node:" + n.getPointInPath().getX() + " y " +  
 
n.getPointInPath().getY());
 
n.getPointInPath().getY());
 
 
if (!n.isMarked()){
 
if (!n.isMarked()){
 
 
n.setMarked();
 
n.setMarked();
 
 
n.setPrevNodeInPath(temp);
 
n.setPrevNodeInPath(temp);
 
 
System.out.println("test n");
 
System.out.println("test n");
 
 
queue.add(n);  //problem here
 
queue.add(n);  //problem here
 
 
}
 
}
 
}
 
}
 
}
 
}
 
 
}
 
}
 
return false;
 
return false;
Line 65: Line 46:
  
 
public  List<Point> getShortestPath(Point start){
 
public  List<Point> getShortestPath(Point start){
 
 
Node src = new Node(start);
 
Node src = new Node(start);
 
 
List<Point> path = new ArrayList<Point>();
 
List<Point> path = new ArrayList<Point>();
 
 
for (int i=0;i<endup.size();i++){
 
for (int i=0;i<endup.size();i++){
 
 
Node destination = new Node(endup.get(i));
 
Node destination = new Node(endup.get(i));
 
 
if (pathFinding_BFS(src, destination)){
 
if (pathFinding_BFS(src, destination)){
 
 
while (destination.getPrevNodeInPath() != null){
 
while (destination.getPrevNodeInPath() != null){
 
 
destination = destination.getPrevNodeInPath();
 
destination = destination.getPrevNodeInPath();
 
 
path.add(destination.getPointInPath());
 
path.add(destination.getPointInPath());
 
 
}
 
}
 
 
Collections.reverse(path);
 
Collections.reverse(path);
 
 
return path;
 
return path;
 
}
 
}
 
 
}
 
}
 
return path;
 
return path;
 
}
 
}
</code>
+
</syntaxhighlight>

Latest revision as of 17:43, 7 December 2013

When I start the battlefield,my robot and other enemy are frozen. The println messages are not displayed in the robot console. But the command prompt shows the following error. I check that the cause of error is the addition of node in my queue (queue.add(n)). However, this line of code shall be fine i guess. So I would like to ask how to solve this error message? (this part of my program is for path finding using bfs)

Thank you.


          • BATTLE 1, ROUND 1 *****

TURN 1: StudentRobot* (1) hard deadline exceeded - 532809us

Err> Robot StudentRobot* (1) is not stopping. Forcing a stop.

Err> Robot StudentRobot* (2) is not stopping. Forcing a stop.

Average computation time per turn: 511706

Max turn computation time: 532809

	private boolean pathFinding_BFS(Node start, Node end){
		LinkedList<Node> queue = new LinkedList<Node>();
		queue.add(start);
		start.setMarked();
		while (!queue.isEmpty()){
			Node temp = (Node)queue.poll();
			System.out.println("first node:" + temp.getPointInPath().getX() + " y " + temp.getPointInPath().getY());
			if (temp.equals(end)){
				temp.setPrevNodeInPath(temp.getPrevNodeInPath());
				return true;
			}else{
				for (Node n : temp.getAdjacentNode()){	
					System.out.println("in node:" + n.getPointInPath().getX() + " y " + 
n.getPointInPath().getY());
					if (!n.isMarked()){
						n.setMarked();
						n.setPrevNodeInPath(temp);
						System.out.println("test n");
						queue.add(n);  //problem here
					}
				}
			}
		}
		return false;
	}
	

	public  List<Point> getShortestPath(Point start){
		Node src = new Node(start);
		List<Point> path = new ArrayList<Point>();
		for (int i=0;i<endup.size();i++){
			Node destination = new Node(endup.get(i));
			if (pathFinding_BFS(src, destination)){
				while (destination.getPrevNodeInPath() != null){
					destination = destination.getPrevNodeInPath();
					path.add(destination.getPointInPath());
				}
				Collections.reverse(path);
				return path;
			}
		}
		return path;
	}