/
graph_logic_example.dart
54 lines (48 loc) · 1.22 KB
/
graph_logic_example.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import 'package:graph_logic/graph_logic.dart';
void main() {
example1();
}
void example1() {
var list = [0, 1, 2, 3, 4];
var nodes = list.map((e) => Node(e)).toList();
List<Tuple<Node<int>, Node<int>>> incedentNodes = [
Tuple(nodes[0], nodes[1]),
Tuple(nodes[1], nodes[2]),
Tuple(nodes[2], nodes[3]),
Tuple(nodes[3], nodes[4]),
Tuple(nodes[4], nodes[1]),
Tuple(nodes[4], nodes[0]),
];
var values = [11, 4, 12, 9, 5, 2];
var graph = Graph.makeGraph<int>(incedentNodes, values, isOriented: false);
printTable(graph);
}
void example2() {
var list = List.generate(4, (index) => List.generate(4, (index) => 0));
list[0][1] = 1;
list[1][2] = 2;
list[2][3] = 3;
list[3][0] = 4;
var graph = list.getGraph(isOriented: true);
printTable(graph);
}
void example3() {
var node1 = Node<int>(1);
var node2 = Node<int>(2);
var edge1 = Edge(node1, node2, 3);
var edge2 = Edge(node2, node1, 3);
print(edge1 == edge2);
}
void printTable(Graph<num> graph) {
var table = graph.linkTable;
var i = 0;
for (var item in table) {
print(i.toString() + ": ");
String text = "";
for (var item2 in item) {
text += item2.value.toString() + " ";
}
print(text);
i++;
}
}