rescuecore.tools.mapgenerator
Class RescueMap

java.lang.Object
  extended byrescuecore.tools.mapgenerator.RescueMap

public class RescueMap
extends java.lang.Object

An internal representation of a city map used in Robocup Rescue simulation. This includes information on nodes, roads and buildings.


Constructor Summary
RescueMap(int nodeCount, int width, int height)
          Constructs new RescueMap.
 
Method Summary
 void addBuilding(int[][] api, int entrance, int floors, int type)
          Adds a new building.
 void addNode()
          Adds a node to the map.
 void align()
          Finds the lowest x and y coordinates and aligns the map so these have value 1.
 int distance(int n1, int n2)
          Gets the Euclidean distance between two nodes.
 int[] edges(int[] bIds, int[] rIds, int n)
          Get a list of edge IDs for a node.
 int getHeight()
          Get the height of the map.
 int getInDegree(int node)
          Gets the indegree of a node.
 int[] getNeighbours(int node)
          Get a list of neighbours of a node.
 int getNodeCount()
          Get the number of nodes in this map.
 int getOutDegree(int node)
          Gets the outdegree of a node.
 int getRoad(int n1, int n2)
          Gets the size of the road between two nodes.
 int[][] getRoads()
          Get a list of roads in the underlying graph.
 int[] getUnderlyingNeighbours(int node)
          Get a list of neighbours of a node in the underlying graph.
 int getWidth()
          Get the width of the map.
 int getX(int node)
          Get the x coordinate of a node.
 int getY(int node)
          Get the y coordinate of a node.
 boolean pathExists(int start, int end)
          Checks whether a path exists between two nodes.
 void setRoad(int a, int b, int size)
          Add, remove or resize a road between two nodes.
 void setX(int node, int x)
          Set the x coordinate of the node.
 void setY(int node, int y)
          Set the y coordinate of the node.
 void toFile()
          Writes this RescueMap to three files - road.bin, building.bin and node.bin.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RescueMap

public RescueMap(int nodeCount,
                 int width,
                 int height)
Constructs new RescueMap.

Parameters:
nodeCount - The number of potential intersections.
width - The approximate width of the map.
height - The approximate height of the map.
Method Detail

setX

public void setX(int node,
                 int x)
Set the x coordinate of the node.

Parameters:
node - The node to change.
x - The new x value.

setY

public void setY(int node,
                 int y)
Set the y coordinate of the node.

Parameters:
node - The node to change.
y - The new y value.

setRoad

public void setRoad(int a,
                    int b,
                    int size)
Add, remove or resize a road between two nodes.

Parameters:
a - The 'from' node.
b - The 'to' node.
size - The number of lanes.

getNodeCount

public int getNodeCount()
Get the number of nodes in this map.

Returns:
The number of nodes.

getX

public int getX(int node)
Get the x coordinate of a node.

Parameters:
node - The node to get info from.
Returns:
The x coordinate.

getY

public int getY(int node)
Get the y coordinate of a node.

Parameters:
node - The node to get info from.
Returns:
The y coordinate.

getWidth

public int getWidth()
Get the width of the map.

Returns:
The approcimate width.

getHeight

public int getHeight()
Get the height of the map.

Returns:
The approximate height.

getInDegree

public int getInDegree(int node)
Gets the indegree of a node.

Parameters:
node - The node to get info from.
Returns:
The indegree.

getOutDegree

public int getOutDegree(int node)
Gets the outdegree of a node.

Parameters:
node - The node to get info from.
Returns:
The outdegree.

getRoad

public int getRoad(int n1,
                   int n2)
Gets the size of the road between two nodes.

Parameters:
n1 - The 'from' node.
n2 - The 'to' node.
Returns:
The number of lanes on the road.

addNode

public void addNode()
Adds a node to the map.


addBuilding

public void addBuilding(int[][] api,
                        int entrance,
                        int floors,
                        int type)
Adds a new building. Uses the RescueMapToolit function centre() to find the centre.

Parameters:
api - The apexes of the building.
entrance - The entrance node.

getRoads

public int[][] getRoads()
Get a list of roads in the underlying graph.

Returns:
Roads in an array of size [roads][2], with the second dimension holing x,y coodinates.

getNeighbours

public int[] getNeighbours(int node)
Get a list of neighbours of a node.

Parameters:
node - The node to get the neighbours of.
Returns:
A list of neighbouring nodes.

getUnderlyingNeighbours

public int[] getUnderlyingNeighbours(int node)
Get a list of neighbours of a node in the underlying graph.

Parameters:
node - The node to get the neighbours of.
Returns:
A list of neighbouring nodes in the underlying graph.

edges

public int[] edges(int[] bIds,
                   int[] rIds,
                   int n)
Get a list of edge IDs for a node.

Parameters:
bIds - The IDs assigned to each building.
rIds - The IDs assigned to each road.
n - The node to find the edges of.
Returns:
A list of the IDs of all adjacent objects.

toFile

public void toFile()
            throws java.io.IOException
Writes this RescueMap to three files - road.bin, building.bin and node.bin.

Throws:
java.io.IOException

distance

public int distance(int n1,
                    int n2)
Gets the Euclidean distance between two nodes.

Parameters:
n1 - The first node.
n2 - The second node.
Returns:
The distance between them.

pathExists

public boolean pathExists(int start,
                          int end)
Checks whether a path exists between two nodes.

Parameters:
start - The node to start the path from.
end - The node we wish to reach.
Returns:
True if a path exists, otherwise false.

align

public void align()
Finds the lowest x and y coordinates and aligns the map so these have value 1.