|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.uci.ics.jung.io.MatrixFile
public class MatrixFile
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
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 |
---|
public MatrixFile(String weightKey)
Method Detail |
---|
public Graph load(BufferedReader reader)
reader
- the input reader
public Graph load(String filename)
GraphFile
load
in interface GraphFile
filename
- the location and name of the file
public void save(Graph graph, String filename)
GraphFile
save
in interface GraphFile
graph
- the location and name of the filefilename
- the graph
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |