makeGraph<num> static method

Graph<num> makeGraph<num>(
  1. List<Tuple<Node<num>, Node<num>>> incidentNodes,
  2. List<num> values, {
  3. bool isOriented = false,
})

Implementation

static Graph<num> makeGraph<num>(
    List<Tuple<Node<num>, Node<num>>> incidentNodes, List<num> values,
    {bool isOriented = false}) {
  if (incidentNodes.length == values.length) {
    var graph = Graph<num>.def(isOriented);
    int i = 0;
    for (var element in incidentNodes) {
      if (!graph.nodes.contains(element.item1)) {
        graph.addNode(element.item1);
      }
      if (!graph.nodes.contains(element.item2)) {
        graph.addNode(element.item2);
      }
      graph.connect(element.item1, element.item2, values[i]);
      i++;
    }
    return graph;
  } else {
    throw Exception("incorrect parameters");
  }
}