public class MatrixFile extends java.lang.Object implements GraphFile
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
Constructor and Description |
---|
MatrixFile(java.lang.String weightKey)
Constructs MatrixFile instance.
|
Modifier and Type | Method and Description |
---|---|
Graph |
load(java.io.BufferedReader reader)
Loads a graph from an input reader
|
Graph |
load(java.lang.String filename)
Loads a graph from a file per the appropriate format
|
void |
save(Graph graph,
java.lang.String filename)
Save a graph to disk per the appropriate format
|
public MatrixFile(java.lang.String weightKey)
public Graph load(java.io.BufferedReader reader)
reader
- the input readerpublic Graph load(java.lang.String filename)
GraphFile