edu.uci.ics.jung.io
Class MatrixFile

java.lang.Object
  extended by edu.uci.ics.jung.io.MatrixFile
All Implemented Interfaces:
GraphFile

public class MatrixFile
extends Object
implements GraphFile

Basic I/O handler for ascii matrix files. An ascii matrix is simply a square matrix where 0 values for cell (i,j) indicates no edge exists between vertex i and vertex j and non-zero values indicates there is an edge. If a non-null weight key is specified then it will be used to treat the non-zero values as a weight stored in the edges' user data keyed off the specified weight key value.

When loading a graph from a file, a symmetric graph will result in the construction of an undirected sparse graph while a non-symmetric graph will result in the construction of a directed sparse graph.

For example the following ascii matrix when loaded using the code:
MatrixFile mf = new MatrixFile(null);
Graph g = mf.load(filename);

will produce an undirected sparse matrix with no weights:

 0 1 0 1
 1 0 0 1
 0 0 0 0
 1 1 0 0
 

whereas the following ascii matrix when loaded using the code:
MatrixFile mf = new MatrixFile("WEIGHT");
Graph g = mf.load(filename);

will produce a directed sparse matrix with double weight values stored in the edges user data under the key "WEIGHT" :

 0 .5 10 0
 0 1 0 0
 0 0 0 -30
 5 0 0 0
 

Author:
Scott

Constructor Summary
MatrixFile(String weightKey)
          Constructs MatrixFile instance.
 
Method Summary
 Graph load(BufferedReader reader)
          Loads a graph from an input reader
 Graph load(String filename)
          Loads a graph from a file per the appropriate format
 void save(Graph graph, String filename)
          Save a graph to disk per the appropriate format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MatrixFile

public MatrixFile(String weightKey)
Constructs MatrixFile instance. If weightKey is not null then, it will attempt to use that key to store and retreive weights from the edges' UserData.

Method Detail

load

public Graph load(BufferedReader reader)
Loads a graph from an input reader

Parameters:
reader - the input reader
Returns:
the graph

load

public Graph load(String filename)
Description copied from interface: GraphFile
Loads a graph from a file per the appropriate format

Specified by:
load in interface GraphFile
Parameters:
filename - the location and name of the file
Returns:
the graph

save

public void save(Graph graph,
                 String filename)
Description copied from interface: GraphFile
Save a graph to disk per the appropriate format

Specified by:
save in interface GraphFile
Parameters:
graph - the location and name of the file
filename - the graph