com.waldura.tw
Class DenseRoutesMap

java.lang.Object
  extended by com.waldura.tw.DenseRoutesMap
All Implemented Interfaces:
RoutesMap

 class DenseRoutesMap
extends java.lang.Object
implements RoutesMap

This map stores routes in a matrix, a nxn array. It is most useful when there are lots of routes, otherwise using a sparse representation is recommended.

Version:
$Id: DenseRoutesMap.java 2367 2007-08-20 21:47:25Z renaud $
Author:
Renaud Waldura <renaud+tw@waldura.com>

Field Summary
private  int[][] distances
           
 
Constructor Summary
DenseRoutesMap(int numCities)
           
 
Method Summary
 void addDirectRoute(City start, City end, int distance)
          Link two cities by a direct route with the given distance.
 java.util.List<City> getDestinations(City city)
          Get the list of cities that can be reached from the given city.
 int getDistance(City start, City end)
          Get the value of a segment.
 RoutesMap getInverse()
           
 java.util.List<City> getPredecessors(City city)
          Get the list of cities that lead to the given city.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

distances

private final int[][] distances
Constructor Detail

DenseRoutesMap

DenseRoutesMap(int numCities)
Method Detail

addDirectRoute

public void addDirectRoute(City start,
                           City end,
                           int distance)
Link two cities by a direct route with the given distance.

Specified by:
addDirectRoute in interface RoutesMap

getDistance

public int getDistance(City start,
                       City end)
Description copied from interface: RoutesMap
Get the value of a segment.

Specified by:
getDistance in interface RoutesMap
Returns:
the distance between the two cities, or 0 if no path exists.

getDestinations

public java.util.List<City> getDestinations(City city)
Description copied from interface: RoutesMap
Get the list of cities that can be reached from the given city.

Specified by:
getDestinations in interface RoutesMap
Returns:
the list of all valid destinations from the given city.

getPredecessors

public java.util.List<City> getPredecessors(City city)
Description copied from interface: RoutesMap
Get the list of cities that lead to the given city.

Specified by:
getPredecessors in interface RoutesMap
Returns:
the list of all cities leading to the given city.

getInverse

public RoutesMap getInverse()
Specified by:
getInverse in interface RoutesMap
Returns:
the transposed graph of this graph, as a new RoutesMap instance.