|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.uci.ics.jung.io.MatrixFile<V,E>
public class MatrixFile<V,E>
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(Map<E,Number> weightKey,
org.apache.commons.collections15.Factory<? extends Graph<V,E>> graphFactory,
org.apache.commons.collections15.Factory<V> vertexFactory,
org.apache.commons.collections15.Factory<E> edgeFactory)
Constructs MatrixFile instance. |
Method Summary | |
---|---|
Graph<V,E> |
load(BufferedReader reader)
Loads a graph from an input reader |
Graph<V,E> |
load(String filename)
Loads a graph from a file. |
void |
save(Graph<V,E> graph,
String filename)
Saves a graph to a file |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MatrixFile(Map<E,Number> weightKey, org.apache.commons.collections15.Factory<? extends Graph<V,E>> graphFactory, org.apache.commons.collections15.Factory<V> vertexFactory, org.apache.commons.collections15.Factory<E> edgeFactory)
Method Detail |
---|
public Graph<V,E> load(BufferedReader reader) throws IOException
reader
- the input reader
IOException
public Graph<V,E> load(String filename)
load
in interface GraphFile<V,E>
filename
- the location and name of the file
GraphFile.load(java.lang.String)
public void save(Graph<V,E> graph, String filename)
save
in interface GraphFile<V,E>
graph
- the location and name of the filefilename
- the graphGraphFile.save(edu.uci.ics.jung.graph.Graph, java.lang.String)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |