logist.topology
Class Topology

java.lang.Object
  extended by logist.topology.Topology
All Implemented Interfaces:
java.lang.Iterable<Topology.City>

public class Topology
extends java.lang.Object
implements java.lang.Iterable<Topology.City>

The Topology encapsulates the cities and routes in the Pickup and Delivery problem.

Each Topology.City in the topology has a unique id field in the range [0, size). This allows to use cities as indices in array- or list-based data structures, for example:

 distance[from.id][to.id]
 

This class provides the following shortcut to iterate over all cities in the topology:

        for (City city : topology) ...
 

The lists returned by the cities and neighbors methods are read-only and must be copied before they can be modified.

Author:
Robin Steiger

Nested Class Summary
static class Topology.Builder
          A builder class to facilitate the construction of a topology.
 class Topology.City
           This class provides the following shortcut to iterate over all neighbors of this city: for (City neighbor : myCity) ...
 
Method Summary
 java.util.List<Topology.City> cities()
          Returns the list of all cities in the topology.
 boolean contains(Topology.City city)
          Checks whether a city is contained by this topology.
 java.util.Iterator<Topology.City> iterator()
          An iterator over all cities in the topology.
 Topology.City parseCity(java.lang.String name)
          Find a city by name
 Topology.City randomCity(java.util.Random rnd)
          Returns a random city in the topology
 int size()
          the number of cities in the topology
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

iterator

public java.util.Iterator<Topology.City> iterator()
An iterator over all cities in the topology. The cities are returned by increasing id fields.

Specified by:
iterator in interface java.lang.Iterable<Topology.City>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

cities

public java.util.List<Topology.City> cities()
Returns the list of all cities in the topology.

The list must be copied before it can be modified.


size

public int size()
the number of cities in the topology


randomCity

public Topology.City randomCity(java.util.Random rnd)
Returns a random city in the topology

Parameters:
rnd - a random number generator

contains

public boolean contains(Topology.City city)
Checks whether a city is contained by this topology. For system use only.

Parameters:
city - the city to check

parseCity

public Topology.City parseCity(java.lang.String name)
Find a city by name

Parameters:
name - The name of the city
Returns:
The city object
Throws:
java.lang.IllegalArgumentException - if no city with that name exists