From 4d3f63e00f6e4f13498409ef2c027704dfa91c2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BE=D1=80=D0=BE=D0=B7=D0=BE=D0=B2=20=D0=90=D0=BD?= =?UTF-8?q?=D0=B4=D1=80=D0=B5=D0=B9?= Date: Tue, 26 Oct 2021 12:35:06 +0000 Subject: [PATCH] Fix when len is not used --- bin/src/graph.dart | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/bin/src/graph.dart b/bin/src/graph.dart index 8cd0c20..74df1c3 100644 --- a/bin/src/graph.dart +++ b/bin/src/graph.dart @@ -371,7 +371,14 @@ class Graphs { var dt = splitted.split(sep.dotToLength); if (dt.length == 2) { dot.add(int.parse(dt[0])); - len.add(int.parse(dt[1])); + if (_useLength) { + len.add(int.parse(dt[1])); + } else { + len.add(0); + } + } else if (dt.length == 1) { + dot.add(int.parse(splitted)); + len.add(0); } } _dots.add(Dot.fromTwoLists(name, dot, len)); @@ -478,8 +485,8 @@ class Graphs { path = path.reversed.toList(); //print("Shortest path between vertices ${startDot+1} and ${goalDot+1} is: $path"); - if (path[0] == (startDot+1) && - path[1] == (goalDot+1) && + if (path[0] == (startDot + 1) && + path[1] == (goalDot + 1) && !_dots[startDot].hasConnection(goalDot + 1)) return null; return path; } @@ -497,11 +504,35 @@ class Graphs { if (!label[v]) { label[v] = true; for (int i in _dots[v].getL().keys) { - stack.add(i-1); + stack.add(i - 1); } } } return label; } + + void dijkstra(int source) { + /* + create vertex set Q; + + for each vertex v in Graph{ + dist[v] ← INFINITY ; + prev[v] ← UNDEFINED ; + add v to Q;} + dist[source] ← 0; + + while Q is not empty{ + u ← vertex in Q with min dist[u] + + remove u from Q + + for each neighbor v of u still in Q{ + alt ← dist[u] + length(u, v); + if alt < dist[v]: { + dist[v] ← alt; + prev[v] ← u;} + }} + return dist[], prev[]*/ + } //************Алгоритмы************ }