Fix when len is not used

This commit is contained in:
Морозов Андрей 2021-10-26 12:35:06 +00:00
parent b09465e8a5
commit 4d3f63e00f
1 changed files with 35 additions and 4 deletions

View File

@ -371,7 +371,14 @@ class Graphs {
var dt = splitted.split(sep.dotToLength); var dt = splitted.split(sep.dotToLength);
if (dt.length == 2) { if (dt.length == 2) {
dot.add(int.parse(dt[0])); dot.add(int.parse(dt[0]));
if (_useLength) {
len.add(int.parse(dt[1])); 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)); _dots.add(Dot.fromTwoLists(name, dot, len));
@ -478,8 +485,8 @@ class Graphs {
path = path.reversed.toList(); path = path.reversed.toList();
//print("Shortest path between vertices ${startDot+1} and ${goalDot+1} is: $path"); //print("Shortest path between vertices ${startDot+1} and ${goalDot+1} is: $path");
if (path[0] == (startDot+1) && if (path[0] == (startDot + 1) &&
path[1] == (goalDot+1) && path[1] == (goalDot + 1) &&
!_dots[startDot].hasConnection(goalDot + 1)) return null; !_dots[startDot].hasConnection(goalDot + 1)) return null;
return path; return path;
} }
@ -497,11 +504,35 @@ class Graphs {
if (!label[v]) { if (!label[v]) {
label[v] = true; label[v] = true;
for (int i in _dots[v].getL().keys) { for (int i in _dots[v].getL().keys) {
stack.add(i-1); stack.add(i - 1);
} }
} }
} }
return label; 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[]*/
}
//************Алгоритмы************ //************Алгоритмы************
} }