aima.search.map
Class ExtendableMap

java.lang.Object
  extended by aima.search.map.ExtendableMap
All Implemented Interfaces:
Map
Direct Known Subclasses:
SimplifiedRoadMapOfAustralia, SimplifiedRoadMapOfPartOfRomania

public class ExtendableMap
extends java.lang.Object
implements Map

Implements a map with locations, distance labeled links between the locations, straight line distances, and 2d-placement positions of locations. Locations are represented by strings and travel distances by integer values. Locations and links can be added dynamically and removed after creation. This enables to read maps from file or to modify them with respect to newly obtained knowledge.


Constructor Summary
ExtendableMap()
          Creates an empty map.
 
Method Summary
 void addBidirectionalLink(java.lang.String fromLocation, java.lang.String toLocation, java.lang.Double distance)
          Adds a connection which can be traveled in both direction.
 void addUnidirectionalLink(java.lang.String fromLocation, java.lang.String toLocation, java.lang.Double distance)
          Adds a one-way connection to the map.
 void clear()
          Removes everything.
 void clearLinks()
          Clears all connections but keeps location position informations.
 java.lang.Double getDistance(java.lang.String fromLocation, java.lang.String toLocation)
          Returns the travel distance between the two specified locations if they are linked by a connection and null otherwise.
 java.util.List<java.lang.String> getLocations()
          Returns a list of all locations.
 java.util.List<java.lang.String> getLocationsLinkedTo(java.lang.String fromLocation)
          Answers to the question: Where can I get, following one of the connections starting at the specified location?
 Point2D getPosition(java.lang.String loc)
          Returns an array with two integers describing the the position of the specified location.
 boolean isLocation(java.lang.String str)
          Checks whether the given string is the name of a location.
 java.lang.String randomlyGenerateDestination()
          Returns a location which is selected by random.
 void removeBidirectionalLink(java.lang.String fromLocation, java.lang.String toLocation)
          Removes the two corresponding one-way connections.
 void removeUnidirectionalLink(java.lang.String fromLocation, java.lang.String toLocation)
          Removes a one-way connection.
 void setDistAndDirToRefLocation(java.lang.String loc, double dist, int dir)
          Defines the position of a location within the map.
 void setPosition(java.lang.String loc, double x, double y)
          Defines the position of a location as with respect to an orthogonal coordinate system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExtendableMap

public ExtendableMap()
Creates an empty map.

Method Detail

clear

public void clear()
Removes everything.


clearLinks

public void clearLinks()
Clears all connections but keeps location position informations.


getLocations

public java.util.List<java.lang.String> getLocations()
Returns a list of all locations.

Specified by:
getLocations in interface Map

isLocation

public boolean isLocation(java.lang.String str)
Checks whether the given string is the name of a location.


getLocationsLinkedTo

public java.util.List<java.lang.String> getLocationsLinkedTo(java.lang.String fromLocation)
Answers to the question: Where can I get, following one of the connections starting at the specified location?

Specified by:
getLocationsLinkedTo in interface Map

getDistance

public java.lang.Double getDistance(java.lang.String fromLocation,
                                    java.lang.String toLocation)
Returns the travel distance between the two specified locations if they are linked by a connection and null otherwise.

Specified by:
getDistance in interface Map

addUnidirectionalLink

public void addUnidirectionalLink(java.lang.String fromLocation,
                                  java.lang.String toLocation,
                                  java.lang.Double distance)
Adds a one-way connection to the map.


addBidirectionalLink

public void addBidirectionalLink(java.lang.String fromLocation,
                                 java.lang.String toLocation,
                                 java.lang.Double distance)
Adds a connection which can be traveled in both direction. Internally, such a connection is represented as two one-way connections.


randomlyGenerateDestination

public java.lang.String randomlyGenerateDestination()
Returns a location which is selected by random.

Specified by:
randomlyGenerateDestination in interface Map

removeUnidirectionalLink

public void removeUnidirectionalLink(java.lang.String fromLocation,
                                     java.lang.String toLocation)
Removes a one-way connection.


removeBidirectionalLink

public void removeBidirectionalLink(java.lang.String fromLocation,
                                    java.lang.String toLocation)
Removes the two corresponding one-way connections.


setPosition

public void setPosition(java.lang.String loc,
                        double x,
                        double y)
Defines the position of a location as with respect to an orthogonal coordinate system.


setDistAndDirToRefLocation

public void setDistAndDirToRefLocation(java.lang.String loc,
                                       double dist,
                                       int dir)
Defines the position of a location within the map. Using this method, one location should be selected as reference position (dist=0 and dir=0) and all the other location should be placed relative to it.

Parameters:
loc - location name
dist - distance to a reference position
dir - bearing (compass direction) in which the location is seen from the reference position

getPosition

public Point2D getPosition(java.lang.String loc)
Returns an array with two integers describing the the position of the specified location.

Specified by:
getPosition in interface Map