Lab1: Path Planning Cyrille Berger August 25, 2015

advertisement
Lab1: Path Planning
Cyrille Berger
August 25, 2015
The goal of this lab is to implement path planning for your agents. Currently they
move randomly around neighbourh roads, using the randomWalk function of AbstractSampleAgent. The randomWalk function uses the class SampleSearch to look up for
neighbourhs in the graph.
1
Accessing the map
Your agents already know the map at the beginning of the simulation. It can be accessed
from whithin the agent using the member model of class StandardWorldModel1 .
The following code is an example on how to iterate over all the roads of the map:
for (Entity next : model) {
if (next instanceof Road)
{
Road road = (Road)next;
// Do something
}
}
1
2
3
4
5
6
7
2
A*
The most commonly used algorithm for path planning is the A* algorithm, if you do not
know the algorithm or need to be refresh, we can suggest the following resources:
• Artificial Intelligence: A Modern Approach, 3rd Edition Stuart Russell, Peter Norvig
http://aima.cs.berkeley.edu/
• Wikipedia: http://en.wikipedia.org/wiki/A*_search_algorithm
• A* Pathfinding for beginners http://www.policyalmanac.org/games/aStarTutorial.
htm
3
Graph of Long-Roads
The naive approach for solving the navigation problem in the rescue simulator would
be to use the full graph, insert all roads, buildings and other points of interest. However
http://www.ida.liu.se/~TDDD10/docs/javadoc/rescuecore2/standard/entities/
StandardWorldModel.html
1
1
Figure 1: Example of long road graph on the Kobe map. Red dot represent a crossing,
blue lines represent a road. Warning: this is only an example, it contains errors (errare
humanum est) and you may want to use a different representation.
it would result in a graph that is so complicated that it would not be computationally
efficient to use it. At the same time, it is rather pointless, indeed, if you consider a
specific building, it is connected to a single road, so if you want to reach that building,
what you need is actually to reach the road. This is the idea behind the concept of graph
of long-roads, a graph where the edges are the streets, and the nodes are the crossing,
you can see an example of a graph of long-roads on the Kobe map in figure 1. And as
you can see, while the graph has been simplified, it is still quiet complex.
The general idea is to figure out if a road is a crossing or a dead-end (see figure 2).
You will need to do some analysis of the graph structure.
4
Implementation
While you will need to integrate the A* algorithm in your agent to complete this assignment, you may find it easier to debug the algorithm if you implement it in a separate
Java project first, but then you would need to provide your own graph structure.
• The first step would be to compute the long-roads graph from the map and store
it for the path planner to use. Before implementing your long-roads graph
algorithm, present it to the assistant.
• Based on that, develop a planner interface to plan using the graph of long-roads.
There should be two possible calls to the planner:
1. one computing the actual path (as in SampleSearch)
2
5
3
2
1
4
Figure 2: Detecting a crossing or a dead-end can be a bit difficult, 5 is clearly a dead-end,
it is connected to a single other road. 1 has three neighbors and is therefor a crossing,
but that is not enough, since 4 has also three neighbors and is not a crossing. But it
seems that dead-ends have a maximum of two neighbors (see 3 and 5).
2. a second one, just returning the costs of the query
The first one would be used for navigation, once the agent know its destination,
it would request the planner for a path. The second one is needed for planning,
and decide which is the next goal of the agent.
• The interface should be able to convert a path planning query for any node to longroad queries and long-road answers of the planner back to full answers. Refer to
the SampleSearch in the base package for an example.
• A few hints, in your implementation of A*: use a Priority Queue (or Fibonacci
Heap) for the open list (in O(log(N))) and use a Hash Map for the close list O(1).
For the first implementation you should ignore the existence of blockade, and assign
a cost that is dependent on the length of the road. You can get the length between two
road using the getDistance function of the WorldModel class2 . And then you can calculate
the length of the line.
5
Visualisation
The most challenging part of this lab is to correctly construct the graph of long road. It
is recommended to display that graph. For this purpose, you can use a StandardViewer
agent and in your agents project, you have a SampleViewer that you can extend.
First you need to have the SampleViewer show up. For this, you simply need to
instantiate it in your LaunchSampleAgents class. Then you will need to create a layer
that display the graph of long road. For this purpose, you can implement your own
AbstractViewLayer and use it in your SampleViewer.
http://www.ida.liu.se/~TDDD10/docs/javadoc/rescuecore2/standard/entities/
StandardWorldModel.html#getDistance(rescuecore2.worldmodel.EntityID,
rescuecore2.worldmodel.EntityID)
2
3
Figure 3: Get the entity ID of a building.
6
Testing
For testing your algorithm, you can use the Kobe2013-one map and disable all simulators:
1
./start.sh -m /home/TDDD10/maps/Kobe2013-one/map/ --disable-traffic-sim --disable-fire-sim --disable-ambulance-sim
It will span a single agent, in your code you can make so that the agent reach a
specific destination. You can get the entity ID of a building with the world view of the
simulator (see 3)
4
Download