Class LedaGraphReader
- java.lang.Object
-
- com.jgalgo.io.LedaGraphReader
-
- All Implemented Interfaces:
GraphReader<Integer,Integer>
public final class LedaGraphReader extends Object
Read a graph in 'LEDA' format.The LEDA format is a simple format for both directed and undirected graphs, used by the LEDA library. Vertices are numbered from 1 to n, and edges are numbered from 1 to m. It support a single weight for vertices and a single weight for edges. The weights can be any primitive, or a string.
When the reader reads a graph from a file with weights, it will be added to the graph as a
Weights
object with key"weight"
, for both vertices and edges. The weights are later available viewGraph.verticesWeights(String)
. To change the weights key, usesetVerticesWeightsKey(String)
andsetEdgesWeightsKey(String)
.- Author:
- Barak Ugav
- See Also:
LedaGraphWriter
-
-
Constructor Summary
Constructors Constructor Description LedaGraphReader()
Create a new reader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description IntGraph
readGraph(File file)
Read a graph from a file.IntGraph
readGraph(Reader reader)
Read a graph from an I/O reader.IntGraph
readGraph(String path)
Read a graph from a file, given a path to it.IntGraphBuilder
readIntoBuilder(Reader reader)
Read a graph from an I/O reader into aGraphBuilder
.void
setEdgesWeightsKey(String edgesWeightsKey)
Sets the key of the edges weights that will be read.void
setVerticesWeightsKey(String verticesWeightsKey)
Sets the key of the vertices weights that will be read.
-
-
-
Method Detail
-
setVerticesWeightsKey
public void setVerticesWeightsKey(String verticesWeightsKey)
Sets the key of the vertices weights that will be read.When the reader reads a graph with vertices weights,
Weights
will be added to the built graph. By default, the weights will be added with key "weight". Use this method to specify a different key.- Parameters:
verticesWeightsKey
- the key of the vertices weights that will be read
-
setEdgesWeightsKey
public void setEdgesWeightsKey(String edgesWeightsKey)
Sets the key of the edges weights that will be read.When the reader reads a graph with edges weights,
Weights
will be added to the built graph. By default, the weights will be added with key "weight". Use this method to specify a different key.- Parameters:
edgesWeightsKey
- the key of the edges weights that will be read
-
readGraph
public IntGraph readGraph(Reader reader)
Description copied from interface:GraphReader
Read a graph from an I/O reader.- Parameters:
reader
- an I/O reader that contain a graph description- Returns:
- a new graph read from the reader
-
readGraph
public IntGraph readGraph(File file)
Description copied from interface:GraphReader
Read a graph from a file.- Parameters:
file
- a file that contain a graph description- Returns:
- a new graph read from the file
-
readGraph
public IntGraph readGraph(String path)
Description copied from interface:GraphReader
Read a graph from a file, given a path to it.- Parameters:
path
- a path to a file that contain a graph description- Returns:
- a new graph read from the file
-
readIntoBuilder
public final IntGraphBuilder readIntoBuilder(Reader reader)
Description copied from interface:GraphReader
Read a graph from an I/O reader into aGraphBuilder
.- Specified by:
readIntoBuilder
in interfaceGraphReader<Integer,Integer>
- Parameters:
reader
- an I/O reader that contain a graph description- Returns:
- a graph builder containing the vertices and edge read from the reader
-
-