Lab2: Obstacle Detection Cyrille Berger August 27, 2015

advertisement
Lab2: Obstacle Detection
Cyrille Berger
August 27, 2015
The goal of this lab is to implement an algorithm to detect if a road is passable
or not. In the simulation, there can be obstacle on the road, obstacles appear at the
beginning as the result of an earthquake and during the simulation when a building
is demolished by a re. It is important for agents to be able to detect if a specic
road element is passable or not. This will be use by police force to know which road
to clear and by other agents to decide which path to take.
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 StandardWorld1
Model .
The following code is an example on how to iterate over all the roads of the map:
for (Entity next : model) {
if (next instanceof Area)
{
Area road = (Area)next;
// Do something
}
}







2
Passable Area Algorithm
In this lab you are not expected to implement an optimal obstacle detection algorithm. The suggested algorithm is an approximation which should cover most cases.
The basic idea of the algorithm is to check if the line that goes between two road
areas cross an obstacle. If the line crosses an obstacle, then there is an obstacle
otherwise there is none. The result of the algorithm can be seen as a graph of
passable and non-passable areas as shown in gure 1.
Given two areas A1 and A2 , separated by an edge e12 , c12 is the middle point of
the edge e12 . It is possible for an agent to move from area A1 to area A2 if and only
if, the line segment [A1 , c12 ] and the line segment [c12 , A2 ] do not intersect with any
obstacle.
Figure 2 illustrate how this algorithm works.
1
http://www.ida.liu.se/~TDDD10/docs/javadoc/rescuecore2/standard/entities/
StandardWorldModel.html
1
Figure 1: Example of passable graph on the Kobe map. Red lines represent an edge
that is not passable while green lines represent a passable edge.
Figure 2: Details of how to check for a single road element. Considering a road
element R, with three neighbours A, B and C . eA , eB and eC are the edges between
R and respectively A, B and C . a, b and c are the middle points of the edges
eA , eB , eC . To check if it is possible to pass between R and one of its neighbour
N = AorBorC , you need to check if the segment [R, n] or the segment [N , n] (where
n is the middle of the edge between R and N ) intersect with an obstacle. The path
is not passable between R and A since the segment [a, R] collides with an obstacle.
All other road elements are passable.
2
Figure 3: Checking only if the line [a, b] does not collide with an obstacle would
mark the road between A and B to be passable, while in practise the gap between
the obstacle is too small for the agents to pass. Testing the intersection between the
orange rectangle and the obstacles would give the expected result.
However, as shown of gure 3, checking for an intersection between line segments
and obstacles does not take into account the size of agents and is not sucient to
guarantee that the agent can move from an area to an other area. It is necessary
to consider that the segment has the thickness equal to the size of an agent (or to
convert the segment into a rectangle).
3
Implementation
To implement your algorithm it is highly recommended to use the java.awt classes.
You can use the java.awt.Polygon class to represent obstacle. Then you can make
use of the java.awt.Area to check if the polygon (representing an obstacle) intersect
with a rectangle (see the intersect and isEmpty functions of java.awt.Area ).
3
4
Visualisation
To check that your algorithm is working, you are expected to provide a visualisation
that would look similar to gure 1.
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. You can check the
SampleLayer to see an example.
4
Download