Bases: object
Reads a partition file that contains a binary list of pairs (node, partition(node)). It is assumed that all integers are unsigned.
firstNode (int, optional) – The id of the first node, this is subtracted from all read node ids. Default: 0
width (int, optional) – The width of the unsigned integer in bytes (4 or 8). Default: 4
Read the partition from one or multiple files
paths (str or list(str)) – The input path(s)
The resulting partition.
networkit.Partition
Bases: object
Writes a partition file that contains a binary list of pairs (node, partition(node)).
firstNode (int, optional) – The id of the first node, this is added to all writen node ids. Default: 0
width (int, optional) – The width of the unsigned integer in bytes (4 or 8). Default: 4
Write the partition to the given file.
P (networkit.Partition) – The input partition.
path (str) – The output path.
Bases: object
Reads a partition from a binary file that contains an unsigned integer of the given width for each node.
width (int, optional) – The width of the unsigned integer in bytes (4 or 8). Default: 4
Reads a partition from a binary file.
path (str) – The input path.
The resulting partition.
networkit.Partition
Bases: object
Writes a partition to a file to contains a binary list of partition ids. Partition ids are unsigned integers.
width (int, optional) – The width of the unsigned integer in bytes (4 or 8). Default: 4
Write the partition to the given file.
Bases: object
Reads a cover from a file File format: each line contains the space-separated node ids of a community
path (str) – Input file path.
G (networkit.Graph) – Graph corresponding to the community from path.
The resulting cover of a graph.
networkit.Cover
Bases: object
Writes a partition to a file. File format: each line contains the space-separated node ids of a community
zeta (networkit.Partition) – The input partition.
path (str) – The output path.
Bases: GraphWriter
Writes graphs in the .dot/GraphViz format.
Bases: object
Reads a cover from an edge list type of file. File format: each line starts with a node id and continues with a list of the communities the node belongs to.
firstNode (int, optional) – Id of first node. Default: 1
Reads a cover from an edge list file.
path (str) – The input path.
G (networkit.Graph) – Graph corresponding to the community from path.
Cover of graph.
networkit.Cover
Bases: object
Reads a partition from an edge list type of file.
firstNode (int, optional) – Id of first node. Default: 1
sepChar (str) – Character which is used for data seperation. Default: ‘ ‘ (tab)
Reads a partition from ad edge list file.
path (str) – The input path.
The resulting partition.
networkit.Partition
Bases: GraphReader
Reads a graph from various text-based edge list formats.
A line has to contain two or three entries separated with the separator symbol (one ASCII character). If at least one line contains three entries, the generated graph will be weighted and each line with only two fields will be interpreted as weight 1.0.
A file may contain the same edge multiple times; then, the weight of the first occurrence is used.
Undirected graphs need to include an edge only in one direction, i.e. edge {u, v} may be represented by (u, v) or (v, u) or both (again, only the first occurrence is used).
If the input file contains non-continuous node ids with large gaps or non-integer node labels, set the parameter continuous to False. Then, gaps are automatically removed and node ids are reassigned to [0, n) where n is the number of nodes in the graph. The mapping will be arbitrary and can be accessed using getNodeMap().
To shift continuous integer node labels which are not zero-indexed, set firstNode to the smallest id used in the file. firstNode will be ignored in the non-continuous case.
The file may also include line comments which start with the commentPrefix.
separator (str) – The separator character. Must have length of exactly one.
firstNode (int) – The id of the first node, this value will be subtracted from all node ids.
commentPrefix (str, optional) – Lines starting with this prefix will be ignored. Default: #
continuous (bool, optional) – File uses continuous node ids. Default: True
directed (bool, optional) – Treat input file as a directed graph. Default: False
Returns mapping of non-continuous files.
The mapping is returned as dict(str, int) projecting the original labels (as Strings) to the reassigned node ids.
Mapping from labels to node ids.
dict(str,int)
Bases: GraphWriter
Writes graphs in various edge list formats.
separator (str) – The separator character.
firstNode (int) – The id of the first node, this value will be added to all node ids
bothDirections (bool, optional) – If undirected edges shall be written in both directions, i.e., as symmetric directed graph. Default: False
Bases: __AutoNumber
Simple enumeration class to list supported file types. Possible values:
networkit.graphio.Format.DOT
networkit.graphio.Format.EdgeList
networkit.graphio.Format.EdgeListCommaOne
networkit.graphio.Format.EdgeListSpaceZero
networkit.graphio.Format.EdgeListSpaceOne
networkit.graphio.Format.EdgeListTabZero
networkit.graphio.Format.EdgeListTabOne
networkit.graphio.Format.GraphML
networkit.graphio.Format.GraphToolBinary
networkit.graphio.Format.GraphViz
networkit.graphio.Format.GEXF
networkit.graphio.Format.GML
networkit.graphio.Format.KONECT
networkit.graphio.Format.LFR
networkit.graphio.Format.METIS
networkit.graphio.Format.NetworkitBinary
networkit.graphio.Format.SNAP
networkit.graphio.Format.MatrixMarket
Bases: object
This class provides a function to read a file in the GEXF (Graph Exchange XML Format) format. For more details see: http://gexf.net/
Creates a NetworKit::GraphEvent from the supplied parameters and passes it to eventStream.
eventTime (int) – Timestep indicating when the event happen (creating an order of events).
eventType (str) – Abbreviation string representing a graph event. Should be one of the following: {e, an, dn, rn, ae, re, de, ce.}
u (int) – Id of node u involved in graph event.
v (int) – Id of node v involved in graph event.
w (float) – Edgeweight of edge between u and v.
Dictionary containing mapping from GEXF ID to node ID
dict(int :
int)
Node ID of a dynamic node must be determined before it’s mapped to its GEXF ID. This requires processing the sorted eventStream and figuring out the addition order of the nodes. After that, node addition/deletion/restoration operations of this node must be readded to eventStream with correct mapping. .. note:
New mapping of a node can be equal to old mapping of a node. In order to prevent collisions,
isMapped array must be maintained and controlled.
Determine the operations as follows: 1. Element has start and not deleted before: Create add event 2. Element has start and deleted before: Create restore event 3. Element has end:Create del event 4. If an element has end before start(or no start at all), add it to the initial graph 5. For dynamic edges, simply go over the attvalues and create weight update events A dynamic element must be defined either using only spells or inline attributes. These 2 shouldn’t be mixed. (For example, Gephi will treat them differently. It’ll ignore the inline declaration if the same element also contains spells)
element (str) – Element to add during reading a GEXF-file.
elementType (str) – Element type (“n” for node or “e” for edge).
controlList (dict) – Dict with elements indicate element properties. Example {'elementAdded': False, 'elementDeleted': False}
u (str) – Node u involved in element parsing.
v (str, optional) – Node v involved in element parsing. Default: “0”
w (str, optional) – Edgeweight w involved in element parsing. Default: “0”
Reads and returns the graph object defined in fpath.
fpath (str) – File path for GEXF-file.
Tuple with the graph parsed from the given fpath and the list of graph events sorted by timestamp.
tuple(networkit.Graph, list(str))
Bases: object
This class provides a function to write a NetworKit graph to a file in the GEXF format.
Writes a graph to the specified file fname.
graph (networkit.Graph) – The input graph.
fname (str) – The desired file path and name to be written to.
eventStream (list(networkit.dynamics.GraphEvent)) – Stream of events, each represented by networkit.dynamics.GraphEvent. Default: list()
mapping (list(int)) – Random node mapping. Default: list()
Write a single event. This is a supporting function and should normally not be called independently. :param xmlElement: XML-encoded element, representing one GEXF-element. :type xmlElement: xml.etree.cElementTree :param eventStream: Stream of events, each represented by networkit.dynamics.GraphEvent. :type eventStream: list(networkit.dynamics.GraphEvent) :param graphElement: Tuple representing one graph element given by (node u, node v, edge weight w). :type graphElement: tuple(int, int, float)
Bases: GraphReader
Reader for the GML graph format, which is documented here: http://www.fim.uni-passau.de/fileadmin/files/lehrstuhl/brandenburg/projekte/gml/gml-technical-report.pdf
Bases: GraphWriter
Writes a graph and its coordinates as a GML file: http://svn.bigcat.unimaas.nl/pvplugins/GML/trunk/docs/gml-technical-report.pdf
Bases: object
Converts a format input to another or the same file format. The execute the conversion call convert.
reader (networkit.graphio.GraphReader) – A supported graph reader.
writer (networkit.graphio.GraphWriter) – A supported graph writer.
Execute the conversion.
inPath (str) – The input path.
outPath (str) – The output path.
Bases: object
This class serves as wrapper for the GraphMLSAX class which is able to parse a GraphML XML file and construct a graph.
Parses a GraphML XML file and returns the constructed Graph
fpath (str) – The path to the file as a String.
The constructed graph.
networkit.Graph
Bases: ContentHandler
Parser for GraphML XML files, based on Pythons XML.SAX implementation.
Appends content string to the textbuffer.
content (str) – String to be added.
Finalizes parsing of the started Element and processes retrieved data.
name (str) – Name of the element. Possible values: edge, data
Returns current textbuffer and clears it afterwards.
Return parsed graph.
Parses all currently relevant XML tags and retrieves data.
name (str) – Name of the element. Possible values: graph, node, edge, key, data
attr (dict()) – Attributes of element.
Bases: object
This class provides a function to write a NetworKit graph to a file in the GraphML format.
Writes a NetworKit graph to the specified file fname.
graph (networkit.Graph) – The input graph.
fname (str) – The desired file path and name to be written to.
nodeAttributes (dict(), optional) – Dictionary of node attributes in the form attribute name => list of attribute values. Default: {}
edgeAttributes (dict(), optional) – Dictionary of edge attributes in the form attribute name => list of attribute values. Default: {}
Bases: object
Abstract base class for graph readers
Read graph given by path.
path (str) – Path string.
The resulting graph.
networkit.Graph
Bases: GraphReader
Reads the binary file format defined by graph-tool: http://graph-tool.skewed.de/static/doc/gt_format.html
Bases: GraphWriter
Reads the binary file format defined by graph-tool: http://graph-tool.skewed.de/static/doc/gt_format.html
Bases: object
Abstract base class for graph writers
Write the graph to a file.
G (networkit.Graph) – The graph to write.
paths (str) – The output path.
Bases: GraphReader
Reader for the KONECT graph format, which is described in detail on the KONECT website: http://konect.uni-koblenz.de/downloads/konect-handbook.pdf
Parameter handlingmethod
can be one of the following:
networkit.graphio.MultipleEdgesHandling.DISCARD_EDGES
networkit.graphio.MultipleEdgesHandling.SUM_WEIGHTS_UP
networkit.graphio.MultipleEdgesHandling.KEEP_MINIMUM_WEIGHT
remapNodes (bool, optional) – Indicates whether nodes are remapped. Default: False
handlingmethod (networkit.graphio.MultipleEdgesHandling, optional) – Sets method of handling multiple edges. Default: networkit.graphio.MultipleEdgesHandling.DISCARD_EDGES
Bases: object
Reads a file and puts each line in a list of strings.
Reads a file and returns list of strings.
path (str) – The input path.
List of strings, each string representing one line of an input file.
list(str)
Bases: GraphReader
Reads the METIS adjacency file format [1]. If the Fast reader fails, use readGraph(path, graphio.formats.metis) as an alternative. [1]: http://people.sc.fsu.edu/~jburkardt/data/metis_graph/metis_graph.html
Bases: GraphWriter
Writes graphs in the METIS format.
Bases: GraphReader
Reader for the MTX / MatrixMarket graph format, which is documented here: https://networkrepository.com/mtx-matrix-market-format.html
Bases: object
Matlab file reader. File format: Adjacency matrix in matlab file format.
key (str, optional) – Key to identify graph. Default: ‘G’
Reads a graph from a matlab file.
path (str) – The input path.
The resulting graph.
networkit.Graph
Bases: object
Matlab file writer.
key (str, optional) – Key to identify graph. Default: ‘G’
Writes a graph to a file.
G (networkit.Graph) – The input graph.
path (str) – The output path.
key (str, optional) – Key to identify graph. Default: ‘G’
Bases: GraphReader
Reads a graph written in the custom Networkit binary format. Note that there are multiple versions of the Networkit binary format. This Reader can read files that are written with format version 2 and 3. Format version 3 was released with Networkit 9.1 (December 2021). Further information can be found here: https://github.com/networkit/networkit/blob/master/networkit/cpp/io/NetworkitBinaryGraph.md
Read graph based on input buffer.
buffer (list(int)) – Input data buffer.
Bases: GraphWriter
Writes a graph written in the custom Networkit format. Note that there are multiple versions of the Networkit binary format. Since Networkit 9.1 (December 2021), the writer always writes files using format version 3. Reading a binary file with version < 3 and re-writing it, implicitly upgrades the format to the current version. Further information can be found here: https://github.com/networkit/networkit/blob/master/networkit/cpp/io/NetworkitBinaryGraph.md
Write graph to data buffer.
G (networkit.Graph) – The input graph.
Bases: object
Reads a partition from a file. File format: line i contains subset id of element i.
Reads a partition from a file.
path (str) – The input path.
The resulting partition.
networkit.Partition
Bases: object
Writes a partition to a file. File format: line i contains subset id of element i.
Writes a partition to a file. File format: line i contains subset id of element i.
zeta (networkit.Partition) – The input partition.
path (str) – The output path.
Bases: object
Reads a partition from a SNAP ‘community with ground truth’ file
Bases: GraphReader
Reads a graph from the SNAP graph data collection: http://snap.stanford.edu/data/index.html
directed (bool, optional) – Indicates whether input represents a directed graph. Default: False
remapNodes (bool, optional) – Indicates whether nodes should be remapped. Default: True
nodeCount (int, optional) – Indicate the first node id. Default: 0
Bases: GraphWriter
Writes graphs in a format suitable for the Georgia Tech SNAP software: http://snap-graph.sourceforge.net/
Bases: GraphReader
Reads a graph format consisting of a serialized DIA of vector<uint32_t> from thrill. When the number of nodes is given, reading the graph is more efficient. Otherwise nodes are added to the graph as they are encountered. Edges must be present only in one direction.
n (int, optional) – The number of nodes. Default: 0
Read the graph from one or multiple files.
paths (str or list(str)) – The input path(s).
The resulting graph.
networkit.Graph
Bases: GraphWriter
Writes a graph format consisting of a serialized DIA of vector<uint32_t> from Thrill. Edges are written only in one direction.
Converts a graph given by a set of file formats and path.
fromFormat (networkit.graphio.Format) – Source for conversion.
toFormat (networkit.graphio.Format) – Target for conversion.
fromPath (str) – The input path.
toPath (str, optional) – The output path. Default: None
Returns a converter for a given set of file formats.
fromFormat (networkit.graphio.Format) – Source for conversion.
toFormat (networkit.graphio.Format) – Target for conversion.
Corresponding GraphConverter object.
Returns reader based on input fileformat.
fileformat (networkit.graphio.Format) – A supported file format.
*kargs (tuple()) – Additional input parameter (depending on the file format).
**kwargs (dict()) – Additional input parameter (depending on the file format).
Returns reader based on input fileformat.
fileformat (networkit.graphio.Format) – A supported file format.
*kargs (tuple()) – Additional input parameter (depending on the file format).
**kwargs (dict()) – Additional input parameter (depending on the file format).
Guesses the graph file format using heuristics. May fail and throw an IOException.
The running time of this function depends on the file format: Guessing Binary formats and structured text (GEXF, GraphML, GraphViz, GML, KONECT, MatrixMarket) takes constant time. If the format is EdgeList, METIS or SNAP, running time is linear in the file size.
Returns networkit.graphio.Format
filepath (str) – Input file path.
Read graph file in various formats and return a graph.
fileformat (networkit.graphio.Format or None) – A supported file format. If None is passed, this function will try to guess the format. May fail and throw an exception.
*kargs (tuple()) – Additional input parameter (depending on the file format).
**kwargs (dict()) – Additional input parameter (depending on the file format). In case of a custom edge list,
pass the generic Fromat.EdgeList accompanied by the defining paramaters as follows:
separator, firstNode, commentPrefix, continuous, directed
. commentPrefix,
continuous=True and directed
are optional because of their default values.
firstNode
is not needed when continuous=True
.
Read all graph files contained in a directory whose filename contains the pattern, return a dictionary of name to Graph object.
dirPath (str) – Path, which contains input graphs.
pattern (str) – Unix-style string pattern for file selection.
fileformat (networkit.graphio.Format) – A supported file format.
some (int, optional) – Restrict number of graphs to be read. Default: None
exclude (str, optional) – Unix-style string pattern for file exclusion. Default: None
**kwargs (dict()) – Additional input parameter (depending on the file format). In case of a custom edge list,
pass the generic Fromat.EdgeList accompanied by the defining paramaters as follows:
separator, firstNode, commentPrefix, continuous, directed
. commentPrefix,
continuous=True and directed
are optional because of their default values.
firstNode
is not needed when continuous=True
.
Reads a Graph from a matlab object file containing an adjacency matrix and returns a graph.
key (str, optional) – Key to identify graph. Default: ‘G’
Read a graph event stream from a file.
path (str) – The input path.
mapped (bool, optional) – Indicates whether the ids should be mapped. Default: True
baseIndex (int, optional) – Sets base index of nodes. Default: 0
Write graph to various output formats.
G (networkit.Graph) – The input graph.
path (str) – Output file path.
fileformat (networkit.graphio.Format) – A supported file format.
*kargs (tuple()) – Additional input parameter (depending on the file format).
**kwargs (dict()) – Additional input parameter (depending on the file format). In case of a custom edge list,
pass the generic Fromat.EdgeList accompanied by the defining paramaters as follows:
separator, firstNode, commentPrefix, continuous, directed
. commentPrefix,
continuous=True and directed
are optional because of their default values.
firstNode
is not needed when continuous=True
.
Writes a graph to a file.
G (networkit.Graph) – The input graph.
path (str) – The output path.
key (str, optional) – Key to identify graph. Default: ‘G’
Write a graph event stream to a file.
stream (networkit.dynamics.GraphEvent) – The input event stream.
path (str) – The output path.