Undocumented
Function | _construct |
Constructs a graph based on an adjacency matrix from the given file. |
Function | _construct |
Reads a graph from a file conforming to the DIMACS minimum-cost flow file format. |
Function | _construct |
Unified reading function for graphs. |
Function | _construct |
Reads a graph from a zipped GraphML file. |
Function | _construct |
Reads a graph from Python pickled format |
Function | _construct |
Reads a graph from compressed Python pickled format, uncompressing it on-the-fly. |
Function | _identify |
_identify_format(filename) |
Function | _write |
Writes the adjacency matrix of the graph to the given file |
Function | _write |
Writes the graph in DIMACS format to the given file. |
Function | _write |
Unified writing function for graphs. |
Function | _write |
Writes the graph to a zipped GraphML file. |
Function | _write |
Saves the graph in Python pickled format |
Function | _write |
Saves the graph in Python pickled format, compressed with gzip. |
Constructs a graph based on an adjacency matrix from the given file.
Additional positional and keyword arguments not mentioned here are passed intact to Graph.Adjacency
.
Parameters | |
cls | Undocumented |
f | the name of the file to be read or a file object |
sep | the string that separates the matrix elements in a row. None means an arbitrary sequence of whitespace characters. |
comment | lines starting with this string are treated as comments. |
attribute | an edge attribute name where the edge weights are stored in the case of a weighted adjacency matrix. If None, no weights are stored, values larger than 1 are considered as edge multiplicities. |
*args | Undocumented |
**kwds | Undocumented |
Returns | |
the created graph |
Reads a graph from a file conforming to the DIMACS minimum-cost flow file format.
For the exact definition of the format, see http://lpsolve.sourceforge.net/5.5/DIMACS.htm.
Restrictions compared to the official description of the format are as follows:
- igraph's DIMACS reader requires only three fields in an arc definition, describing the edge's source and target node and its capacity.
- Source vertices are identified by 's' in the FLOW field, target vertices are identified by 't'.
- Node indices start from 1. Only a single source and target node is allowed.
Parameters | |
cls | Undocumented |
f | the name of the file or a Python file handle |
directed | whether the generated graph should be directed. |
Returns | |
the generated graph. The indices of the source and target vertices are attached as graph attributes source and target, the edge capacities are stored in the capacity edge attribute. |
Unified reading function for graphs.
This method tries to identify the format of the graph given in the first parameter and calls the corresponding reader method.
The remaining arguments are passed to the reader method without any changes.
Parameters | |
cls | Undocumented |
f | the file containing the graph to be loaded |
format | the format of the file (if known in advance). None means auto-detection. Possible values are: "ncol" (NCOL format), "lgl" (LGL format), "graphdb" (GraphDB format), "graphml", "graphmlz" (GraphML and gzipped GraphML format), "gml" (GML format), "net", "pajek" (Pajek format), "dimacs" (DIMACS format), "edgelist", "edges" or "edge" (edge list), "adjacency" (adjacency matrix), "dl" (DL format used by UCINET), "pickle" (Python pickled format), "picklez" (gzipped Python pickled format) |
*args | Undocumented |
**kwds | Undocumented |
Raises | |
IOError | if the file format can't be identified and none was given. |
Reads a graph from a zipped GraphML file.
Parameters | |
cls | Undocumented |
f | the name of the file |
index | if the GraphML file contains multiple graphs, specified the one that should be loaded. Graph indices start from zero, so if you want to load the first graph, specify 0 here. |
Returns | |
the loaded graph object |
Reads a graph from Python pickled format
Parameters | |
cls | Undocumented |
fname | the name of the file, a stream to read from, or a string containing the pickled data. |
Returns | |
the created graph object. |
Reads a graph from compressed Python pickled format, uncompressing it on-the-fly.
Parameters | |
cls | Undocumented |
fname | the name of the file or a stream to read from. |
Returns | |
the created graph object. |
_identify_format(filename)
Tries to identify the format of the graph stored in the file with the given filename. It identifies most file formats based on the extension of the file (and not on syntactic evaluation). The only exception is the adjacency matrix format and the edge list format: the first few lines of the file are evaluated to decide between the two.
Parameters | |
filename | the name of the file or a file object whose name attribute is set. |
Returns | |
the format of the file as a string. | |
Note | |
Internal function, should not be called directly. |
Writes the adjacency matrix of the graph to the given file
All the remaining arguments not mentioned here are passed intact to Graph.get_adjacency
.
Parameters | |
graph | Undocumented |
f | the name of the file to be written. |
sep | the string that separates the matrix elements in a row |
eol | the string that separates the rows of the matrix. Please note that igraph is able to read back the written adjacency matrix if and only if this is a single newline character |
*args | Undocumented |
**kwds | Undocumented |
Writes the graph in DIMACS format to the given file.
Parameters | |
graph | Undocumented |
f | the name of the file to be written or a Python file handle. |
source | the source vertex ID. If None, igraph will try to infer it from the source graph attribute. |
target | the target vertex ID. If None, igraph will try to infer it from the target graph attribute. |
capacity | the capacities of the edges in a list or the name of an edge attribute that holds the capacities. If there is no such edge attribute, every edge will have a capacity of 1. |
Unified writing function for graphs.
This method tries to identify the format of the graph given in the first parameter (based on extension) and calls the corresponding writer method.
The remaining arguments are passed to the writer method without any changes.
Parameters | |
graph | Undocumented |
f | the file containing the graph to be saved |
format | the format of the file (if one wants to override the format determined from the filename extension, or the filename itself is a stream). None means auto-detection. Possible values are:
|
*args | Undocumented |
**kwds | Undocumented |
Raises | |
IOError | if the file format can't be identified and none was given. |
Writes the graph to a zipped GraphML file.
The library uses the gzip compression algorithm, so the resulting file can be unzipped with regular gzip uncompression (like gunzip or zcat from Unix command line) or the Python gzip module.
Uses a temporary file to store intermediate GraphML data, so make sure you have enough free space to store the unzipped GraphML file as well.
Parameters | |
graph | Undocumented |
f | the name of the file to be written. |
compresslevel | the level of compression. 1 is fastest and produces the least compression, and 9 is slowest and produces the most compression. |
Saves the graph in Python pickled format
Parameters | |
graph | Undocumented |
fname | the name of the file or a stream to save to. If None, saves the graph to a string and returns the string. |
version | pickle protocol version to be used. If -1, uses the highest protocol available |
Returns | |
None if the graph was saved successfully to the given file, or a string if fname was None. |
Saves the graph in Python pickled format, compressed with gzip.
Saving in this format is a bit slower than saving in a Python pickle without compression, but the final file takes up much less space on the hard drive.
Parameters | |
graph | Undocumented |
fname | the name of the file or a stream to save to. |
version | pickle protocol version to be used. If -1, uses the highest protocol available |
Returns | |
None if the graph was saved successfully to the given file. |