drasys.or.graph
Class PointGraph

java.lang.Object
  |
  +--drasys.or.graph.Graph
        |
        +--drasys.or.graph.BaseGraph
              |
              +--drasys.or.graph.PointGraph

public class PointGraph
extends BaseGraph
implements GraphI, AddVertexI, RemoveVertexI

An implementation of a graph where the vertices are a set of points and the edge values are the distances between the end points. The distance between two end points is dependent on the coordinate system.
The edge method 'getCost' returns the distance scaled by 'costPerDistance'. The edge method 'getTime' returns the distance scaled by 'timePerDistance'. The edge method 'getDistance' returns the distance between the end points. The edge method 'getValue()'returns a new 'EdgeValue' containing the values.
The vertex method 'doubleValue()' returns a double value based on the vertex value object. If the value object is not null and either implements 'DoubleI' or is a subclass of 'Number' then the returned value is 'value.doubleValue()'. Otherwise; the value is zero.

References:

Graphs : Theory and Algorithms
    K. Thulasiraman, M.N.S. Swamy / Paperback / Published 1992

See Also:
Serialized Form

Fields inherited from class drasys.or.graph.Graph
_symmetric
 
Constructor Summary
PointGraph()
           
PointGraph(int vertexCapacity)
           
PointGraph(VectorI x, VectorI y)
          Initializes the graph with vertices from the values in the vectors.
PointGraph(VectorI x, VectorI y, VectorI z)
          Initializes the graph with vertices from the values in the vectors.
 
Method Summary
 VertexI addVertex(java.lang.Object key, java.lang.Object value)
          Adds a new vertex to the graph.
 CoordinateSystemI cordinateSystem()
          Returns the coordinate system used by the graph.
 EdgeI getEdge(VertexI from, VertexI to, java.lang.Object edgeKey)
          Get the edge between the 'from' and 'to' vertices whose key matches 'edgeKey'.
 EdgeI getMutableEdge(VertexI from, VertexI to, java.lang.Object edgeKey)
          Get the edge between the 'from' and 'to' vertices whose key matches 'edgeKey'.
 boolean isSymmetric()
          Returns true if the points are from a symmetric coordinate system, false otherwise.
 GraphI newGraph(int vertexCapacity, int edgeCapacity)
          Create a new empty PointGraph.
protected  VertexI newVertex(java.lang.Object key, java.lang.Object value)
           
 VertexI removeVertex(java.lang.Object key, boolean removeZeroVertices)
          Removes a vertex whose key matches the argument and all its adjacent edges.
 VertexI removeVertex(VertexI vertex, boolean removeZeroVertices)
          Removes a vertex whose key matches the key in the argument and all its adjacent edges.
 void setCost(double cost)
          Sets the cost per distance used to compute travel cost from the distance.
 void setSpeed(double speed)
          Sets the speed used to compute travel time from the distance.
 java.lang.String toString()
           
 void useDistanceProxy(boolean useProxy)
          If useProxy is true then PointI.distanceProxyTo() will be used as the edge value.
 
Methods inherited from class drasys.or.graph.BaseGraph
addVertex, addVertex, ensureVertexCapacity, getChangeCount, getVertex, removeAllVertices, sizeOfDirectedEdges, sizeOfEdges, sizeOfVertices, vertices
 
Methods inherited from class drasys.or.graph.Graph
edges, equals, getEdge, getEdge, isSubsetOf, mutableEdges, setSymmetric, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PointGraph

public PointGraph()

PointGraph

public PointGraph(int vertexCapacity)

PointGraph

public PointGraph(VectorI x,
                  VectorI y)
Initializes the graph with vertices from the values in the vectors. The vertex key will be an 'Integer' object with a value corresponding to the vector index. The vertex value will be a 'rect2.Point'.

PointGraph

public PointGraph(VectorI x,
                  VectorI y,
                  VectorI z)
Initializes the graph with vertices from the values in the vectors. The vertex key will be an 'Integer' object with a value corresponding to the vector index. The vertex value will be a 'rect3.Point'.
Method Detail

setSpeed

public void setSpeed(double speed)
Sets the speed used to compute travel time from the distance. The default value is '1.0'. (time=distance/speed)

setCost

public void setCost(double cost)
Sets the cost per distance used to compute travel cost from the distance. The default value is '1.0'. (cost=distance*costPerDistance)

cordinateSystem

public CoordinateSystemI cordinateSystem()
Returns the coordinate system used by the graph.
Returns:
null if no points have been added.

useDistanceProxy

public void useDistanceProxy(boolean useProxy)
If useProxy is true then PointI.distanceProxyTo() will be used as the edge value. If useProxy is false then PointI.distanceTo() will be used as the edge value. The default is to use PointI.distanceTo() for the return value.

addVertex

public VertexI addVertex(java.lang.Object key,
                         java.lang.Object value)
                  throws DuplicateVertexException
Adds a new vertex to the graph. The first point added to the graph sets the coordinate system of the graph.
Specified by:
addVertex in interface AddVertexI
Overrides:
addVertex in class BaseGraph
Throws:
DuplicateVertexException - if the vertex already exists.
GraphError - if the vertex value is null, does not implement geom.PointI or is not from the correct coordinate system.

newVertex

protected VertexI newVertex(java.lang.Object key,
                            java.lang.Object value)
Overrides:
newVertex in class BaseGraph

isSymmetric

public boolean isSymmetric()
Returns true if the points are from a symmetric coordinate system, false otherwise. If 'setSymmetric' has been called, then the override value is returned.
Specified by:
isSymmetric in interface GraphI

newGraph

public GraphI newGraph(int vertexCapacity,
                       int edgeCapacity)
Create a new empty PointGraph.
Returns:
Null if not successfull.

getEdge

public EdgeI getEdge(VertexI from,
                     VertexI to,
                     java.lang.Object edgeKey)
Get the edge between the 'from' and 'to' vertices whose key matches 'edgeKey'. All the edges in a PointGraph have a null key value so 'edgeKey' must be null to match. The arguments 'from' and 'to' must be vertices owned by this graph.
Specified by:
getEdge in interface GraphI
Returns:
Null if the edge is not in the graph.

getMutableEdge

public EdgeI getMutableEdge(VertexI from,
                            VertexI to,
                            java.lang.Object edgeKey)
Get the edge between the 'from' and 'to' vertices whose key matches 'edgeKey'. All the edges in a PointGraph have a null key value so 'edgeKey' must be null to match. The graph is allowed to return a mutable edge if that is more efficient, but the edge contents must be used before 'getMutableEdge()' is called again. The arguments 'from' and 'to' must be vertices owned by this graph.
Specified by:
getMutableEdge in interface GraphI
Returns:
Null if the edge is not in the graph.

removeVertex

public VertexI removeVertex(VertexI vertex,
                            boolean removeZeroVertices)
                     throws VertexNotFoundException
Removes a vertex whose key matches the key in the argument and all its adjacent edges. The argument 'removeZeroVertices' is not used.
Specified by:
removeVertex in interface RemoveVertexI
Returns:
The removed vertex.

removeVertex

public VertexI removeVertex(java.lang.Object key,
                            boolean removeZeroVertices)
                     throws VertexNotFoundException
Removes a vertex whose key matches the argument and all its adjacent edges. The argument 'removeZeroVertices' is not used.
Specified by:
removeVertex in interface RemoveVertexI
Returns:
The removed vertex.

toString

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


Copyright(C)1997-2000 by DRA Systems all rights reserved. OpsResearch.com