public class MatrixFile<V,E> extends java.lang.Object implements GraphFile<V,E>
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.util.Map<E,java.lang.Number> weightKey,
org.apache.commons.collections4.Factory<? extends edu.uci.ics.jung.graph.Graph<V,E>> graphFactory,
org.apache.commons.collections4.Factory<V> vertexFactory,
org.apache.commons.collections4.Factory<E> edgeFactory)
Constructs MatrixFile instance.
|
Modifier and Type | Method and Description |
---|---|
edu.uci.ics.jung.graph.Graph<V,E> |
load(java.io.BufferedReader reader)
Loads a graph from an input reader
|
edu.uci.ics.jung.graph.Graph<V,E> |
load(java.lang.String filename)
Loads a graph from a file.
|
void |
save(edu.uci.ics.jung.graph.Graph<V,E> graph,
java.lang.String filename)
Saves a graph to a file
|
public MatrixFile(java.util.Map<E,java.lang.Number> weightKey, org.apache.commons.collections4.Factory<? extends edu.uci.ics.jung.graph.Graph<V,E>> graphFactory, org.apache.commons.collections4.Factory<V> vertexFactory, org.apache.commons.collections4.Factory<E> edgeFactory)
public edu.uci.ics.jung.graph.Graph<V,E> load(java.io.BufferedReader reader) throws java.io.IOException
reader
- the input readerjava.io.IOException
public edu.uci.ics.jung.graph.Graph<V,E> load(java.lang.String filename)
load
in interface GraphFile<V,E>
filename
- the location and name of the fileGraphFile.load(java.lang.String)
public void save(edu.uci.ics.jung.graph.Graph<V,E> graph, java.lang.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)