drasys.or.graph
Class MatrixGraph

java.lang.Object
  |
  +--drasys.or.graph.Graph
        |
        +--drasys.or.graph.MatrixGraph

public class MatrixGraph
extends Graph
implements GraphI

This graph is essentially a dense matrix of double values inside a GraphI wrapper. The origin vertices are associated with the rows and the destination vertices are associated with the columns. A matrix element value of Double.POSITIVE_INFINITY represents a missing edge. A missing edge will cause 'getEdge()' to return null and will not be counted in the degree of any vertex.
The edge method 'doubleValue()' returns the double value from the matrix that corresponds to the edge. The edge method 'getValue()' returns a new instance of 'Double' containing the value.
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 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
MatrixGraph(GraphI graph, java.lang.Object edgeKey)
          Initializes the graph from another graph.
MatrixGraph(GraphI graph, java.lang.Object edgeKey, EdgePropertiesI properties)
          Initializes the graph from another graph.
MatrixGraph(MatrixI cost, MatrixI time, MatrixI distance)
          Initializes the graph from the values in 'matrix', the matrix must be square.
MatrixGraph(MatrixI cost, MatrixI time, MatrixI distance, java.util.Vector vertexKeys)
          Initializes the graph from the values in 'matrix', the matrix must be square.
MatrixGraph(MatrixI cost, MatrixI time, MatrixI distance, java.util.Vector vertexKeys, java.util.Vector vertexValues)
          Initializes the graph from the values in 'matrix', the matrix must be square.
MatrixGraph(MatrixI cost, MatrixI time, MatrixI distance, VertexI[] fromVertices, VertexI[] toVertices)
          Initializes the graph from the values in 'matrix', the matrix can be any rectangular shape.
 
Method Summary
 int getChangeCount()
          Always returns zero since this graph is immutable.
 EdgeI getEdge(VertexI from, VertexI to, java.lang.Object edgeKey)
          Get the edge between the from and to vertices, the edge key must be null for a match.
 EdgeI getMutableEdge(VertexI from, VertexI to, java.lang.Object edgeKey)
          Get the edge between the from and to vertices, the edge key must be null for a match.
 VertexI getVertex(java.lang.Object key)
          Get the vertex that matches the key.
 boolean isSymmetric()
          Returns 'isSymmetric()' from the initialization matrix by default.
 int sizeOfDirectedEdges()
           
 int sizeOfEdges()
           
 int sizeOfVertices()
           
 java.util.Enumeration vertices()
          Creates an enumeration on the vertices of the graph.
 
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, toString, wait, wait, wait
 

Constructor Detail

MatrixGraph

public MatrixGraph(MatrixI cost,
                   MatrixI time,
                   MatrixI distance)
Initializes the graph from the values in 'matrix', the matrix must be square. The vertex keys will be an Integer object equal to the row/column index and the vertex values will be null. The edges will be directed and the matrix row corresponds to the from vertex of the edge. The set of 'from' vertices and the set of 'to' vertices will be equivalent.

MatrixGraph

public MatrixGraph(MatrixI cost,
                   MatrixI time,
                   MatrixI distance,
                   java.util.Vector vertexKeys)
            throws DuplicateVertexException
Initializes the graph from the values in 'matrix', the matrix must be square. The vertex keys will be set to the elements of 'vertexKeys' and the vertex values will be null. The edges will be directed and the matrix row corresponds to the from vertex of the edge. The set of 'from' vertices and the set of 'to' vertices will be equivalent.

MatrixGraph

public MatrixGraph(MatrixI cost,
                   MatrixI time,
                   MatrixI distance,
                   java.util.Vector vertexKeys,
                   java.util.Vector vertexValues)
            throws DuplicateVertexException
Initializes the graph from the values in 'matrix', the matrix must be square. The vertex keys will be set to the elements of 'vertexKeys' and the vertex values will be set to the elements of 'vertexValues'. The edges will be directed and the matrix row corresponds to the from vertex of the edge. The set of 'from' vertices and the set of 'to' vertices will be equivalent.

MatrixGraph

public MatrixGraph(MatrixI cost,
                   MatrixI time,
                   MatrixI distance,
                   VertexI[] fromVertices,
                   VertexI[] toVertices)
            throws ParallelEdgeException
Initializes the graph from the values in 'matrix', the matrix can be any rectangular shape. The the origin vertices will be set from 'fromVertices' and must have the same number of elements as there are rows in the matrix. The the destination vertices will be set from 'toVertices' and must have the same number of elements as there are columns in the matrix. The same vertex can appear in both the 'fromVertices' and 'toVertices' arrays. The edges will be directed and the matrix row corresponds to the from vertex of the edge. The set of 'from' vertices and the set of 'to' vertices can be different. The from keys correspond to the rows and the to keys correspond to the columns.

MatrixGraph

public MatrixGraph(GraphI graph,
                   java.lang.Object edgeKey)
Initializes the graph from another graph. The new graph will contain all the vertices from the original and the value matrix will be square. The matrix elements will be initialized from the 'doubleValue()' method of the edges with matching keys. The value of missing edges will be set to Double.POSITIVE_INFINITY. The double value of undirected edges will be placed in two entries in the value matrix.

MatrixGraph

public MatrixGraph(GraphI graph,
                   java.lang.Object edgeKey,
                   EdgePropertiesI properties)
Initializes the graph from another graph. The new graph will contain all the vertices from the original and the value matrix will be square. The matrix elements will be initialized from the 'getEdgeCost()' method in the properties object. The value of missing edges will be set to Double.POSITIVE_INFINITY. Undirected edges will cause two calls to 'getEdgeCost()', one for each element position. If 'isEdgeRestricted()' returns true, the corresponding matrix element will be set to Double.POSITIVE_INFINITY.
Method Detail

getChangeCount

public int getChangeCount()
Always returns zero since this graph is immutable.
Specified by:
getChangeCount in interface GraphI

sizeOfVertices

public int sizeOfVertices()
Specified by:
sizeOfVertices in interface GraphI
Returns:
The number vertices in the graph.

sizeOfEdges

public int sizeOfEdges()
Specified by:
sizeOfEdges in interface GraphI
Returns:
The number edges in the graph.

sizeOfDirectedEdges

public int sizeOfDirectedEdges()
Specified by:
sizeOfDirectedEdges in interface GraphI
Returns:
The number of directed edges in the graph.

isSymmetric

public boolean isSymmetric()
Returns 'isSymmetric()' from the initialization matrix by default. If 'setSymmetric' has been called, then the override value is returned.
Specified by:
isSymmetric in interface GraphI

getMutableEdge

public EdgeI getMutableEdge(VertexI from,
                            VertexI to,
                            java.lang.Object edgeKey)
Get the edge between the from and to vertices, the edge key must be null for a 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 from this graph. The argument 'edgeKey' is not used.
Specified by:
getMutableEdge in interface GraphI
Returns:
Null if the edge is not in the graph.

vertices

public java.util.Enumeration vertices()
Creates an enumeration on the vertices of the graph.
Specified by:
vertices in interface GraphI
Returns:
An enumeration with elements of class VertexI.

getVertex

public VertexI getVertex(java.lang.Object key)
Get the vertex that matches the key.
Specified by:
getVertex in interface GraphI
Returns:
Null if the edge is not in the graph.

getEdge

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


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