Graph.fromEdgeListString constructor
Graph.fromEdgeListString(
- String edgeListString
Create a Graph using a String format of its edge list.
The accepted format is similar to the NetworkX edge list format. Here, comments or any other arbitrary data is not allowed and will result in a FormatException.
Implementation
factory Graph.fromEdgeListString(String edgeListString) {
final EdgeList edgeList = {};
for (final line in edgeListString.split(RegExp(r'\r?\n'))) {
final nodes = line.split(' ');
if (nodes.length != 2) {
throw FormatException(
'Each line of an edge list must contain exactly two nodes.', line);
}
edgeList.add(Edge(
left: IntegerNode(int.parse(nodes[0])),
right: IntegerNode(int.parse(nodes[1])),
));
}
return Graph.fromEdgeList(edgeList);
}