Compare commits

..

No commits in common. "9024c24c4c80e65c528fb3c8049fdaca8810b27b" and "2422274ea35ddc4f52d6f5989f1d0fdd2de95831" have entirely different histories.

5 changed files with 459 additions and 604 deletions

View File

@ -51,9 +51,10 @@ void main(List<String> arguments) {
List<Graphs> graphs = <Graphs>[];
String name;
String str = "";
Separators sep = Separators();
while (deistvie != 0) {
stdout.write(
"1 - создать граф, 2 - удалить граф, 3 - добавить в граф вершину,\n4 - удалить вершину, 5 - добавить ребро/дугу, 6 - удалить ребро/дугу,\n7 - вывести граф на экран, 8 - вывести граф в файл, 9 - обход в ширину,\n0 - выход\nDeistvie: ");
"1 - создать граф, 2 - удалить граф, 3 - добавить в граф вершину,\n4 - удалить вершину, 5 - добавить ребро/дугу, 6 - удалить ребро/дугу,\n7 - вывести граф на экран, 8 - вывести граф в файл, 0 - выход\nDeistvie: ");
deistvie = getIntLine();
switch (deistvie) {
case 1:
@ -111,9 +112,9 @@ void main(List<String> arguments) {
List<int> inn = <int>[];
List<int> len = <int>[];
List<String> a = str.split(Separators.space);
List<String> a = str.split(sep.space);
for (var splitted in a) {
var dt = splitted.split(Separators.dotToLength);
var dt = splitted.split(sep.dotToLength);
if (dt.length == 2) {
inn.add(int.parse(dt[0]));
len.add(int.parse(dt[1]));
@ -156,13 +157,13 @@ void main(List<String> arguments) {
stdout.write("Имя вершины: ");
String dotName = getStrLine();
/*stdout.write(
stdout.write(
"Ввод: *куда*|*вес* через пробел. Если граф не взвешенный, то *вес* можно не указывать.\nВершина cмежна с: ");
str = getStrLine();
List<String> a = str.split(Separators.space);
List<String> a = str.split(sep.space);
for (var splitted in a) {
var dt = splitted.split(Separators.dotToLength);
var dt = splitted.split(sep.dotToLength);
if (dt.length == 2) {
inn.add(int.parse(dt[0]));
len.add(int.parse(dt[1]));
@ -170,12 +171,12 @@ void main(List<String> arguments) {
inn.add(int.parse(splitted));
len.add(0);
}
}*/
}
printGraphsName(graphs);
stdout.write("Вставка в графа с номером: ");
int y = getIntLine();
if (y >= 0 && y < graphs.length) {
graphs[y].addIsolated(dotName);
graphs[y].addDotFromToLists(dotName, inn, len);
} else {
print("Не найден граф с таким номером");
}
@ -243,7 +244,7 @@ void main(List<String> arguments) {
num = graphs[y].getDotAmount();
stdout.write(
"Количество вершин: $num. Введите через пробел 2 вершины, между которыми удалить ребро: ");
List<String> x = getStrLine().split(Separators.space);
List<String> x = getStrLine().split(sep.space);
x1 = int.parse(x[0]);
x2 = int.parse(x[1]);
if (x1 >= 0 && x1 < num && x2 >= 0 && x2 < num) {
@ -285,29 +286,6 @@ void main(List<String> arguments) {
}
break;
}
case 9:
{
int num = graphs.length;
printGraphsName(graphs);
stdout.write("Работаем в графе с номером: ");
int y = getIntLine();
if (y >= 0 && y < num) {
graphs[y].printG();
num = graphs[y].getDotAmount();
stdout.write("Вершина, из которой выходят: ");
int x1 = getIntLine();
stdout.write("Вершина, в которую идут: ");
int x2 = getIntLine();
if (x1 >= 0 && x1 <= num && x2 >= 0 && x2 <= num) {
print("BFS: ${graphs[y].bfsPath(x1, x2)}");
} else {
print("Не найдены введеные вершины в графе\n");
}
} else {
print("Не найден граф с таким номером");
}
break;
}
case 0:
getStrLine();
exit(0);

View File

@ -1,15 +1,15 @@
import 'dart:io';
class Separators {
static const String dotToConnections = ": ";
static const String dotToLength = "|";
static const String space = " ";
static const String hasLength = "Взвешенный";
static const String hasNoLength = "НеВзвешенный";
static const String isOriented = "Ориентированный";
static const String isNotOriented = "НеОриентированный";
static const String nL = "\n";
static const String end = "END";
final String dotToConnections = ": ";
final String dotToLength = "|";
final String space = " ";
final String hasLength = "Взвешенный\n";
final String hasNoLength = "НеВзвешенный\n";
final String isOriented = "Ориентированный\n";
final String isNotOriented = "НеОриентированный\n";
final String nL = "\n";
final String end = "END";
Separators();
}
@ -25,7 +25,6 @@ class Dot {
String getName() => _name;
bool hasConnection(int n) => _ln.containsKey(n);
Map<int, int> getL() => _ln;
int getLength(int x) {
if (hasConnection(x)) {
return _ln[x]!;
@ -54,9 +53,9 @@ class Dot {
}
//******Constructor******
Dot([String name = "Undefined", int n = -1]) {
_name = name;
num = n;
Dot() {
_name = "Undefined";
num = -1;
_ln = <int, int>{};
}
Dot.fromTwoLists(String name, List<int> num0, List<int> length,
@ -98,9 +97,11 @@ class Graphs {
bool _oriented = false; //Ориентированность
//*********************Add************************
String? addDot(Dot a) {
bool addDot(Dot a) {
if (getNumByName(a.getName()) != null) {
return ("Dot name \"${a.getName()}\" already in use. Change name or use addPath");
print(
"Dot name ${a.getName()} already in use. Change name or use addPath");
return false;
}
_amount++;
a.num = _amount;
@ -108,7 +109,7 @@ class Graphs {
_syncNameTable();
checkDots(false);
if (!_oriented) _fullFix();
return null;
return true;
}
bool addDotFromToLists(String name, List<int> num0, List<int> length,
@ -128,40 +129,37 @@ class Graphs {
return true;
}
String? addIsolated(String name) {
var res = addDot(Dot.fromTwoLists(name, [], []));
bool addIsolated(String name) {
var o = addDot(Dot.fromTwoLists(name, [], []));
_syncNameTable();
return res;
return o;
}
String? addPath(int from, int to, [int len = 0]) {
bool addPath(int from, int to, [int len = 0]) {
if (from <= 0 || from > _amount || to <= 0 && to > _amount) {
return "Index out of range. Have dots 1..$_amount";
return false;
}
_dots[from - 1].addPath(to, len);
if (!_oriented) {
_dots[to - 1].addPath(from, len);
}
return null;
return true;
}
//*********************Add************************
//*********Delete*********
String? delPath(int from, int to) {
bool delPath(int from, int to) {
if (from <= 0 || from > _amount || to <= 0 && to > _amount) {
return "Can't find specified path";
return false;
}
_dots[from - 1].delPath(to);
if (!_oriented) {
_dots[to - 1].delPath(from);
}
return null;
return true;
}
String? delDot(int inn) {
if (inn > _amount || inn < 1) {
return "Index out of range. Allowed 1..$_amount";
}
bool delDot(int inn) {
List<int> toDel = <int>[];
for (int i in _dots[inn - 1].getL().keys) {
toDel.add(i);
@ -173,13 +171,7 @@ class Graphs {
_syncNum();
_syncNameTable();
_fixAfterDel(inn);
return null;
}
void flushData() {
_dots = <Dot>[];
_amount = 0;
_nameTable = <int, String>{};
return true;
}
//*********Delete*********
@ -249,121 +241,12 @@ class Graphs {
}
//******Helper*******
//*****Setters*******
void setName(String name) => _name = name;
String? flipUseOrientation() {
if (_amount != 0) {
return "Can change use of orientation only in empty graph";
}
_oriented = !_oriented;
return null;
}
String? flipUseLength() {
if (_amount != 0) {
return "Can change use of length only in empty graph";
}
_useLength = !_useLength;
return null;
}
String? replaceDataFromFile(String path) {
File file = File(path);
List<String> lines = file.readAsLinesSync();
if (lines.length < 3) {
return "Not enough lines in file";
}
String name = lines.removeAt(0);
bool oriented;
switch (lines.removeAt(0)) {
case Separators.isOriented:
oriented = true;
break;
case Separators.isNotOriented:
oriented = false;
break;
default:
return "Error on parsing \"IsOriented\"";
}
bool useLength;
switch (lines.removeAt(0).trim()) {
case Separators.hasLength:
useLength = true;
break;
case Separators.hasNoLength:
useLength = false;
break;
default:
return "Error on parsing \"HasLength\"";
}
List<Dot> dots = <Dot>[];
for (var l in lines) {
l = l.trimRight();
if (l != Separators.end) {
var spl = l.split(Separators.space);
List<int> dot = <int>[];
List<int> len = <int>[];
String name = spl.removeAt(0);
name = name.substring(0, name.length - 1);
for (var splitted in spl) {
if (splitted != "") {
var dt = splitted.split(Separators.dotToLength);
if (dt.length == 2) {
int? parsed = int.tryParse(dt[0]);
if (parsed == null) {
return "Error while parsing file\nin parsing int in \"${dt[0]}\"";
}
dot.add(parsed);
if (useLength) {
parsed = int.tryParse(dt[1]);
if (parsed == null) {
return "Error while parsing file\nin parsing int in \"${dt[1]}\"";
}
len.add(parsed);
} else {
len.add(0);
}
} else if (dt.length == 1) {
int? parsed = int.tryParse(splitted);
if (parsed == null) {
return "Error while parsing file\nin parsing int in \"$splitted\"";
}
dot.add(parsed);
len.add(0);
}
}
}
dots.add(Dot.fromTwoLists(name, dot, len));
}
}
_name = name;
_oriented = oriented;
_useLength = useLength;
_dots = dots;
_syncNum();
_syncNameTable();
if (!_oriented) _fullFix();
return null;
}
//*****Setters*******
//*****Getters*******
bool getDoubleSidedBool() => _oriented;
String getDoubleSidedStr() {
if (_oriented) return Separators.isOriented;
return Separators.isNotOriented;
}
bool getUseLengthBool() => _useLength;
String getUseLengthStr() {
if (_useLength) return Separators.hasLength;
return Separators.hasNoLength;
}
bool getDoubleSided() => _oriented;
bool getUseLength() => _useLength;
List<Dot> getDots() => _dots;
String getName() => _name;
String? getNameByNum(int n) => _nameTable[n];
Map<int, String> getNameTable() => _nameTable;
int getDotAmount() => _dots.length;
int? getNumByName(String n) {
for (var i in _nameTable.keys) {
@ -399,23 +282,6 @@ class Graphs {
}
return out;
}
/*List<Dot> getNoRepeatDots() {
List<Dot> ret = <Dot>[];
for (int i = 0; i < _amount; i++) {
ret.add(Dot(_dots[i].getName(), _dots[i].num));
}
for (int i = 0; i < _amount; i++) {
for (int j in _dots[i].getL().keys) {
if (!ret[j - 1].hasConnection(i + 1) && !ret[i].hasConnection(j) ||
i == j) {
var len = _dots[i].getLength(j);
ret[i].addPath(j, len);
}
}
}
return ret;
}*/
//*****Getters*******
//******Print******
@ -437,34 +303,31 @@ class Graphs {
}
void printToFile(String name) {
Separators sep = Separators();
var file = File(name);
file.writeAsStringSync("$_name\n");
if (_oriented) {
file.writeAsStringSync("${Separators.isOriented}\n",
mode: FileMode.append);
file.writeAsStringSync(sep.isOriented, mode: FileMode.append);
} else {
file.writeAsStringSync("${Separators.isNotOriented}\n",
mode: FileMode.append);
file.writeAsStringSync(sep.isNotOriented, mode: FileMode.append);
}
if (_useLength) {
file.writeAsStringSync("${Separators.hasLength}\n",
mode: FileMode.append);
file.writeAsStringSync(sep.hasLength, mode: FileMode.append);
} else {
file.writeAsStringSync("${Separators.hasNoLength}\n",
mode: FileMode.append);
file.writeAsStringSync(sep.hasNoLength, mode: FileMode.append);
}
for (int i = 0; i < _amount; i++) {
file.writeAsStringSync((i + 1).toString() + Separators.dotToConnections,
file.writeAsStringSync((i + 1).toString() + sep.dotToConnections,
mode: FileMode.append);
var d = _dots[i].getL();
for (var j in d.keys) {
file.writeAsStringSync(
j.toString() + Separators.dotToLength + d[j].toString() + " ",
j.toString() + sep.dotToLength + d[j].toString() + " ",
mode: FileMode.append);
}
file.writeAsStringSync(Separators.nL, mode: FileMode.append);
file.writeAsStringSync(sep.nL, mode: FileMode.append);
}
file.writeAsStringSync(Separators.end, mode: FileMode.append);
file.writeAsStringSync(sep.end, mode: FileMode.append);
}
//******Print******
@ -490,22 +353,22 @@ class Graphs {
if (!_oriented) _fullFix();
}
Graphs.fromFile(String path) {
replaceDataFromFile(path);
/*File file = File(path);
Separators sep = Separators();
File file = File(path);
List<String> lines = file.readAsLinesSync();
_name = lines.removeAt(0);
_oriented = lines.removeAt(0) == Separators.isOriented.trim();
_useLength = lines.removeAt(0) == Separators.hasLength.trim();
_oriented = lines.removeAt(0) == sep.isOriented.trim();
_useLength = lines.removeAt(0) == sep.hasLength.trim();
_dots = <Dot>[];
for (var l in lines) {
if (l != Separators.end) {
var spl = l.split(Separators.space);
if (l != sep.end) {
var spl = l.split(sep.space);
List<int> dot = <int>[];
List<int> len = <int>[];
String name = spl.removeAt(0);
name = name.substring(0, name.length - 1);
for (var splitted in spl) {
var dt = splitted.split(Separators.dotToLength);
var dt = splitted.split(sep.dotToLength);
if (dt.length == 2) {
dot.add(int.parse(dt[0]));
if (_useLength) {
@ -523,7 +386,7 @@ class Graphs {
}
_syncNum();
_syncNameTable();
if (!_oriented) _fullFix();*/
if (!_oriented) _fullFix();
}
//*******Constructor********
@ -531,14 +394,14 @@ class Graphs {
Graphs.clone(Graphs a) {
_name = a.getName();
_dots = a.getDots();
_oriented = a.getDoubleSidedBool();
_useLength = a.getUseLengthBool();
_oriented = a.getDoubleSided();
_useLength = a.getUseLength();
_amount = _dots.length;
_syncNameTable();
}
//************Алгоритмы************
/* bool bfsHasPath(int startDot, int goalDot) {
bool bfsHasPath(int startDot, int goalDot) {
// обход в ширину
startDot--;
goalDot--;
@ -565,10 +428,9 @@ class Graphs {
}
}
return false; // Целевой узел недостижим
}*/
}
List<int>? bfsPath(int startDot, int goalDot) {
if (startDot == goalDot) return [startDot];
//if (!bfsHasPath(startDot, goalDot)) return null;
startDot--;
goalDot--;
@ -608,6 +470,7 @@ class Graphs {
//Восстановим кратчайший путь
//Для восстановления пути пройдём его в обратном порядке, и развернём.
List<int> path = <int>[];
int cur = goalDot; //текущая вершина пути
@ -630,25 +493,21 @@ class Graphs {
List<bool>? dfsIterative(int v) {
v--;
//List<int>? pos = <int>[];
List<bool> label = <bool>[];
for (int i = 0; i < _amount; i++) {
label.add(false);
}
List<int> stack = <int>[];
stack.add(v);
//pos.add(v);
while (stack.isNotEmpty) {
v = stack.removeLast();
if (!label[v]) {
label[v] = true;
for (int i in _dots[v].getL().keys) {
stack.add(i - 1);
//pos.add(i);
}
}
}
//print(pos);
return label;
}

View File

@ -8,85 +8,71 @@ class CurvePainter extends CustomPainter {
Key? key,
required this.graphData,
required this.bfsPath,
required this.start,
required this.end,
required this.dfsStart,
required this.dfsAccessTable,
});
List<int>? bfsPath;
List<bool>? dfsAccessTable;
int? start;
int? end;
int? dfsStart;
Graphs graphData;
final double _dotRad = 6;
final double _lineWidth = 1.5;
final Color _lineColor = Colors.black;
final double _aboveHeight = 5;
double _circleRad = 100;
final TextStyle _textStyle = TextStyle(
color: Colors.red.shade900,
decorationColor: Colors.green.shade900,
decorationThickness: 10,
decorationStyle: TextDecorationStyle.dashed,
final double dotRad = 6;
final double lineWidth = 2;
final Color lineColor = Colors.black;
final double aboveHeight = 5;
double circleRad = 100;
final TextStyle textStyle = TextStyle(
color: Colors.green.shade900,
fontSize: 20,
);
Map<int, Offset> _off = <int, Offset>{};
void _drawLine(Canvas canvas, Offset p1, Offset p2) {
void drawLine(Canvas canvas, Offset p1, Offset p2) {
Paint p = Paint();
p.color = _lineColor;
p.strokeWidth = _lineWidth;
p.color = lineColor;
p.strokeWidth = lineWidth;
canvas.drawLine(p1, p2, p);
}
void _drawDot(Canvas canvas, Offset p1, [double plusRad = 0, Color? col]) {
col ??= Colors.yellow.shade900;
void drawDot(Canvas canvas, Offset p1) {
var p = Paint();
p.color = col;
p.strokeWidth = _lineWidth + 2;
canvas.drawCircle(p1, _dotRad + plusRad, p);
p.color = Colors.yellow.shade900;
p.strokeWidth = lineWidth + 2;
canvas.drawCircle(p1, dotRad, p);
}
void _drawSelfConnect(Canvas canvas, Offset p1) {
void drawSelfConnect(Canvas canvas, Offset p1) {
var p = Paint();
p.color = _lineColor;
p.strokeWidth = _lineWidth;
p.color = lineColor;
p.strokeWidth = lineWidth;
p.style = PaintingStyle.stroke;
canvas.drawCircle(Offset(p1.dx + _dotRad + 20, p1.dy), _dotRad + 20, p);
canvas.drawCircle(Offset(p1.dx + dotRad + 20, p1.dy), dotRad + 20, p);
}
TextSpan _getTextSpan(String s) => TextSpan(text: s, style: _textStyle);
TextSpan _getTextSpan(String s) => TextSpan(text: s, style: textStyle);
TextPainter _getTextPainter(String s) => TextPainter(
text: _getTextSpan(s),
textDirection: TextDirection.ltr,
textAlign: TextAlign.center);
void _drawDotNames(Canvas canvas, Offset place, String s) {
void drawDotNames(Canvas canvas, Offset place, String s) {
var textPainter = _getTextPainter(s);
textPainter.layout();
textPainter.paint(
canvas,
Offset((place.dx - textPainter.width),
(place.dy - textPainter.height) - _aboveHeight));
(place.dy - textPainter.height) - aboveHeight));
}
void _drawDotNum(Canvas canvas, Offset size, String s) {
var textPainter = TextPainter(
text: TextSpan(
text: s,
style: const TextStyle(
color: Colors.black,
fontSize: 17,
)),
textDirection: TextDirection.ltr,
textAlign: TextAlign.center);
void drawAboveText(Canvas canvas, Offset size, String s) {
var textPainter = _getTextPainter(s);
textPainter.layout();
textPainter.paint(
canvas,
Offset((size.dx - textPainter.width) + 25,
(size.dy - textPainter.height) + _aboveHeight + 30));
Offset((size.dx - textPainter.width),
(size.dy - textPainter.height) - aboveHeight));
}
int _getHighInputConnections() {
int getHighInputConnections() {
if (graphData.getDots().length != 1 && graphData.getDots().length <= 3) {
return -1;
}
@ -97,18 +83,17 @@ class CurvePainter extends CustomPainter {
return higest;
}
Map<int, Offset> _getDotPos(int dotsAm, Size size) {
Map<int, Offset> getDotPos(int dotsAm, Size size, [int? exclude]) {
Map<int, Offset> off = <int, Offset>{};
var width = size.width / 2;
var height = size.height / 2;
int add = 0;
int h = _getHighInputConnections();
int h = getHighInputConnections();
for (int i = 0; i < dotsAm; i++) {
if ((i + 1) != h) {
double x =
cos(2 * pi * (i - add) / (dotsAm - add)) * _circleRad + width;
double x = cos(2 * pi * (i - add) / (dotsAm - add)) * circleRad + width;
double y =
sin(2 * pi * (i - add) / (dotsAm - add)) * _circleRad + height;
sin(2 * pi * (i - add) / (dotsAm - add)) * circleRad + height;
off[i + 1] = Offset(x, y);
} else if ((i + 1) == h) {
@ -125,7 +110,7 @@ class CurvePainter extends CustomPainter {
return off;
}
void _drawHArrow(Canvas canvas, Size size, Offset from, Offset to,
void drawHArrow(Canvas canvas, Size size, Offset from, Offset to,
[bool doubleSided = false]) {
Path path;
@ -135,7 +120,7 @@ class CurvePainter extends CustomPainter {
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round
..strokeJoin = StrokeJoin.round
..strokeWidth = _lineWidth;
..strokeWidth = lineWidth;
var length = sqrt((to.dx - from.dx) * (to.dx - from.dx) +
(to.dy - from.dy) * (to.dy - from.dy));
@ -146,8 +131,8 @@ class CurvePainter extends CustomPainter {
path.relativeCubicTo(
0,
0,
-(from.dx + to.dx + length) / (length) - 40,
-(from.dy + to.dy + length) / (length) - 40,
-(from.dx + to.dx) / (length * 2) - 40,
-(from.dy + to.dy) / (length * 2) - 40,
to.dx - from.dx,
to.dy - from.dy);
path =
@ -155,7 +140,7 @@ class CurvePainter extends CustomPainter {
canvas.drawPath(path, paint);
}
void _drawHighArrow(Canvas canvas, Size size, Offset from, Offset to,
void drawHighArrow(Canvas canvas, Size size, Offset from, Offset to,
[bool doubleSided = false]) {
Path path;
@ -165,7 +150,7 @@ class CurvePainter extends CustomPainter {
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round
..strokeJoin = StrokeJoin.round
..strokeWidth = _lineWidth;
..strokeWidth = lineWidth;
var length = sqrt((to.dx - from.dx) * (to.dx - from.dx) +
(to.dy - from.dy) * (to.dy - from.dy));
@ -176,7 +161,7 @@ class CurvePainter extends CustomPainter {
path.relativeCubicTo(
0,
0,
(from.dx + to.dx) / (length * 2) + 40,
(from.dx + to.dx) / (length * 3) + 40,
(from.dy + to.dy) / (length * 2) + 40,
to.dx - from.dx,
to.dy - from.dy);
@ -188,29 +173,29 @@ class CurvePainter extends CustomPainter {
canvas.drawPath(path, paint);
}
void _drawConnections(
void drawConnections(
Canvas canvas, Size size, List<Dot> dots, Map<int, Offset> off) {
for (var i in dots) {
var list = i.getL();
var beg = off[i.num];
for (var d in list.keys) {
if (d == i.num) {
_drawSelfConnect(canvas, off[d]!);
drawSelfConnect(canvas, off[d]!);
} else {
if (graphData.getDoubleSidedBool()) {
if (d > i.num) {
_drawHArrow(canvas, size, beg!, off[d]!, false);
drawHArrow(canvas, size, beg!, off[d]!, false);
if (graphData.getUseLengthBool()) {
_drawDotNames(
drawDotNames(
canvas,
Offset((off[d]!.dx + beg.dx) / 2 - 18,
(off[d]!.dy + beg.dy) / 2 - 18),
i.getL()[d].toString());
}
} else {
_drawHighArrow(canvas, size, beg!, off[d]!, false);
drawHighArrow(canvas, size, beg!, off[d]!, false);
if (graphData.getUseLengthBool()) {
_drawDotNames(
drawDotNames(
canvas,
Offset((off[d]!.dx + beg.dx) / 2 + 30,
(off[d]!.dy + beg.dy) / 2 + 30),
@ -218,9 +203,9 @@ class CurvePainter extends CustomPainter {
}
}
} else {
_drawLine(canvas, beg!, off[d]!);
drawLine(canvas, beg!, off[d]!);
if (graphData.getUseLengthBool()) {
_drawDotNames(
drawDotNames(
canvas,
Offset((off[d]!.dx + beg.dx) / 2, (off[d]!.dy + beg.dy) / 2),
i.getL()[d].toString());
@ -231,67 +216,184 @@ class CurvePainter extends CustomPainter {
}
}
void _drawBFS(Canvas canvas) {
if (bfsPath != null) {
for (int i = 0; i < bfsPath!.length; i++) {
_drawDot(canvas, _off[bfsPath![i]]!, 8, Colors.yellow);
}
_drawDot(canvas, _off[start]!, 9, Colors.green);
_drawDot(canvas, _off[end]!, 7, Colors.red.shade200);
for (int i = 0; i < bfsPath!.length; i++) {
_drawDotNum(canvas, _off[bfsPath![i]]!, "bfs: №${i + 1}");
}
}
}
void _drawDFS(Canvas canvas) {
if (dfsAccessTable != null) {
print("nn");
for (int i = 0; i < dfsAccessTable!.length; i++) {
if (dfsAccessTable![i]) {
_drawDot(canvas, _off[i + 1]!, 8, Colors.green.shade500);
_drawDotNum(canvas, _off[i + 1]!, "dfs: visible");
} else {
_drawDot(canvas, _off[i + 1]!, 7, Colors.red.shade500);
_drawDotNum(canvas, _off[i + 1]!, "dfs: not visible");
}
}
_drawDot(canvas, _off[start]!, 9, Colors.green.shade900);
}
}
@override
void paint(Canvas canvas, Size size) {
if (size.width > size.height) {
_circleRad = size.height / 3;
circleRad = size.height / 3;
} else {
_circleRad = size.width / 3;
circleRad = size.width / 3;
}
//var paint = Paint();
//drawLine(canvas, Offset(0, size.height / 2),
//Offset(size.width, size.height / 2));
_off = _getDotPos(graphData.getDotAmount(), size); //, higest);
for (int i in _off.keys) {
_drawDot(canvas, _off[i]!);
//drawDotNames(canvas, off[i]!, "${graphData.getDots()[i - 1].getName()}:[$i]");
//gr = getGraph();
//int higest = getHighConnections();
//if (higest > -1) {
var off = getDotPos(graphData.getDotAmount(), size); //, higest);
//off[higest] = Offset(size.width / 2, size.height / 2);
for (int i in off.keys) {
drawDot(canvas, off[i]!);
drawDotNames(
canvas, off[i]!, "${graphData.getDots()[i - 1].getName()}:[$i]");
}
//var g = gr.getNoRepeatDots();
//print(g);
var g = graphData.getDots();
_drawBFS(canvas);
_drawDFS(canvas);
_drawConnections(canvas, size, g, _off);
drawConnections(canvas, size, g, off);
//pringArr(canvas, size);
//drawArrow(canvas, Offset(size.width / 2, size.height / 2),
// Offset(size.width / 2 + 50, size.height / 2 + 200));
//}
for (int i in _off.keys) {
//drawDot(canvas, off[i]!);
_drawDotNames(
canvas, _off[i]!, "${graphData.getDots()[i - 1].getName()}:[$i]");
}
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return true;
}
/*void _drawTextAt(String txt, Offset position, Canvas canvas) {
final textPainter = getTextPainter(txt);
textPainter.layout(minWidth: 0, maxWidth: 0);
Offset drawPosition =
Offset(position.dx, position.dy - (textPainter.height / 2));
textPainter.paint(canvas, drawPosition);
}*/
}
void pringArr(Canvas canvas, Size size) {
TextSpan textSpan;
TextPainter textPainter;
Path path;
// The arrows usually looks better with rounded caps.
Paint paint = Paint()
..color = Colors.black
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round
..strokeJoin = StrokeJoin.round
..strokeWidth = 3.0;
/// Draw a single arrow.
path = Path();
path.moveTo(size.width * 0.25, size.height * 0.10);
path.relativeCubicTo(0, 0, size.width * 0.25, 50, size.width * 0.5, 0);
path = ArrowPath.make(path: path);
canvas.drawPath(path, paint..color = Colors.blue);
textSpan = const TextSpan(
text: 'Single arrow',
style: TextStyle(color: Colors.blue),
);
textPainter = TextPainter(
text: textSpan,
textAlign: TextAlign.center,
textDirection: TextDirection.ltr,
);
textPainter.layout(minWidth: size.width);
textPainter.paint(canvas, Offset(0, size.height * 0.06));
/*
/// Draw a double sided arrow.
path = Path();
path.moveTo(size.width * 0.25, size.height * 0.2);
path.relativeCubicTo(0, 0, size.width * 0.25, 50, size.width * 0.5, 0);
path = ArrowPath.make(path: path, isDoubleSided: true);
canvas.drawPath(path, paint..color = Colors.cyan);
textSpan = const TextSpan(
text: 'Double sided arrow',
style: TextStyle(color: Colors.cyan),
);
textPainter = TextPainter(
text: textSpan,
textAlign: TextAlign.center,
textDirection: TextDirection.ltr,
);
textPainter.layout(minWidth: size.width);
textPainter.paint(canvas, Offset(0, size.height * 0.16));
/// Use complex path.
path = Path();
path.moveTo(size.width * 0.25, size.height * 0.3);
path.relativeCubicTo(0, 0, size.width * 0.25, 0, size.width * 0.5, 50);
path.relativeCubicTo(0, 0, -size.width * 0.25, 50, -size.width * 0.5, 50);
//path.relativeCubicTo(0, 0, size.width * 0.125, 10, size.width * 0.25, -10);
path = ArrowPath.make(path: path, isDoubleSided: true);
canvas.drawPath(path, paint..color = Colors.blue);
textSpan = const TextSpan(
text: 'Complex path',
style: TextStyle(color: Colors.blue),
);
textPainter = TextPainter(
text: textSpan,
textAlign: TextAlign.center,
textDirection: TextDirection.ltr,
);
textPainter.layout(minWidth: size.width);
textPainter.paint(canvas, Offset(0, size.height * 0.28));
/// Draw several arrows on the same path.
path = Path();
path.moveTo(size.width * 0.25, size.height * 0.53);
path.relativeCubicTo(0, 0, size.width * 0.25, 50, size.width * 0.5, 50);
path = ArrowPath.make(path: path);
path.relativeCubicTo(0, 0, -size.width * 0.25, 0, -size.width * 0.5, 50);
path = ArrowPath.make(path: path);
Path subPath = Path();
subPath.moveTo(size.width * 0.375, size.height * 0.53 + 100);
subPath.relativeCubicTo(0, 0, size.width * 0.125, 10, size.width * 0.25, -10);
subPath = ArrowPath.make(path: subPath, isDoubleSided: true);
path.addPath(subPath, Offset.zero);
canvas.drawPath(path, paint..color = Colors.cyan);
textSpan = const TextSpan(
text: 'Several arrows on the same path',
style: TextStyle(color: Colors.cyan),
);
textPainter = TextPainter(
text: textSpan,
textAlign: TextAlign.center,
textDirection: TextDirection.ltr,
);
textPainter.layout(minWidth: size.width);
textPainter.paint(canvas, Offset(0, size.height * 0.49));
/// Adjusted
path = Path();
path.moveTo(size.width * 0.1, size.height * 0.8);
path.relativeCubicTo(0, 0, size.width * 0.3, 50, size.width * 0.25, 75);
path = ArrowPath.make(path: path, isAdjusted: true);
canvas.drawPath(path, paint..color = Colors.blue);
textSpan = const TextSpan(
text: 'Adjusted',
style: TextStyle(color: Colors.blue),
);
textPainter = TextPainter(
text: textSpan,
textAlign: TextAlign.left,
textDirection: TextDirection.ltr,
);
textPainter.layout();
textPainter.paint(canvas, Offset(size.width * 0.2, size.height * 0.77));
/// Non adjusted.
path = Path();
path.moveTo(size.width * 0.6, size.height * 0.8);
path.relativeCubicTo(0, 0, size.width * 0.3, 50, size.width * 0.25, 75);
path = ArrowPath.make(path: path, isAdjusted: false);
canvas.drawPath(path, paint..color = Colors.blue);
textSpan = const TextSpan(
text: 'Non adjusted',
style: TextStyle(color: Colors.blue),
);
textPainter = TextPainter(
text: textSpan,
textAlign: TextAlign.left,
textDirection: TextDirection.ltr,
);
textPainter.layout();
textPainter.paint(canvas, Offset(size.width * 0.65, size.height * 0.77));*/
}

View File

@ -26,10 +26,7 @@ class _DrawingPageState extends State<DrawingPage> {
Graphs graphData = getGraph();
List<int>? bfsPath;
List<bool>? dfsAccessTable;
int? startDot;
int? endDot;
String? dropdownValue1;
String? dropdownValue2;
int? dfsStartDot;
final _textNameController = TextEditingController();
final _textNumbController = TextEditingController();
@ -37,23 +34,118 @@ class _DrawingPageState extends State<DrawingPage> {
final _textLnthController = TextEditingController();
final _textGrNmController = TextEditingController();
void clearInputData() {
setState(() {
_textDestController.clear();
_textNumbController.clear();
_textLnthController.clear();
_textNameController.clear();
dropdownValue1 = null;
dropdownValue2 = null;
/*startDot = null;
bfsPath = null;
dfsAccessTable = null;
endDot = null;*/
});
void clearTextControllers() {
_textDestController.clear();
_textNumbController.clear();
_textLnthController.clear();
_textNameController.clear();
}
// *************buttons*************
ElevatedButton createButton(String txt, void Function() onPressing) {
@override
Widget build(BuildContext context) {
screenSize = MediaQuery.of(context).size.width;
_textGrNmController.text = graphData.getName();
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Align(
alignment: Alignment.topLeft,
child: Text("Graph name:\n",
style: TextStyle(
fontSize: 18,
color: Colors.white,
))),
toolbarHeight: 110,
flexibleSpace: Container(
color: Colors.green.shade900,
child: Column(children: <Widget>[
const SizedBox(height: 5),
Row(children: [
addSpaceW(screenSize / 8 + 19),
createButton("\nAdd dot\n", addDotPushed),
createInputBox("Dot name", screenSize / 4 - 25, Icons.label,
_textNameController),
addSpaceW(8),
createButton("\nAdd path\n", addPathPushed),
createInputBox("Input length", screenSize / 4 - 25,
Icons.arrow_right_alt_outlined, _textLnthController),
]),
addSpaceH(3),
Row(children: [
addSpaceW(5),
createInputBox(
"Name", screenSize / 8 - 25, null, _textGrNmController),
//addSpaceW(screenSize / 8 - 4),
createButton("\nDel dot \n", delDotPushed),
createInputBox("Dot number", screenSize / 4 - 25,
Icons.fiber_manual_record, _textNumbController),
addSpaceW(13),
createButton("\nDel path\n", delPathPushed),
createInputBox("Destination number", screenSize / 4 - 25,
Icons.fiber_manual_record, _textDestController),
]),
]),
),
actions: [
IconButton(
onPressed: () => graphData.flushData(),
icon: const Icon(Icons.delete_sweep),
iconSize: 60,
),
]),
body: CustomPaint(
painter: CurvePainter(
graphData: graphData,
bfsPath: bfsPath,
dfsStart: dfsStartDot,
dfsAccessTable: dfsAccessTable),
child: Align(
alignment: Alignment.topRight,
child: ButtonBar(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
createButton("Bfs", bfsPushed),
createButton("Dfs", dfsPushed),
createButton("Clear dfs or bfs", () => bfsPath = null),
createButton(graphData.getUseLengthStr(), changeLength),
createButton(graphData.getDoubleSidedStr(), changeOriented),
/*Text(_textGrNmController.text,
style:
TextStyle(fontSize: 15, color: Colors.blueGrey.shade900)),*/
createButton("Save to file", fileSaver),
createButton("Load from file", fileOpener),
createButton("Help", () {
String out =
" В поле \"Graph name\" можно сменить имя графу.\n";
out +=
" Для добавления точки необходимо ввести имя в \"Dot name\" и нажать на \"Add dot\".\n";
out +=
" Для удаления точки необходимо ввести номер в \"Dot number\" и нажать на \"Del dot\".\n";
out +=
" Для добавления пути необходимо ввести: номер выходной вершины в \"Dot number\", номер входной вершины в \"Destination number\" ";
out +=
"и, если граф взвешенный, то ввести длину пути в \"Input length\". Затем нажать \"Add path\".\n";
out +=
" Для удаления пути необходимо ввести номер выходной вершины в \"Dot number\" и номер входной вершины в \"Destination number\". Затем нажать \"Del path\".\n\n";
out +=
" Кнопки \"Bfs\" и \"Dfs\" нумеруют точки в зависимости от послежовательности, в которой они будут пройдены.\n";
out +=
" Кнопки \"Взвешенный\" и \"Ориентированный\" позволяют сменить эти значения перед построением графа (т.е. для их работы граф должен быть пустым).\n";
out +=
" Кнопки \"Save to file\" и \"Load from file\" позволяют вывести информацию в файл и загрузить информацию из файла соответственно.\n";
out +=
" Кнопка \"Help\" описывает работу с интерфейсом программы.";
showPopUp("Help:", out);
})
],
),
),
),
));
}
// ignore: avoid_types_as_parameter_names, non_constant_identifier_names, use_function_type_syntax_for_parameters
ElevatedButton createButton(String txt, void onPressing()) {
return ElevatedButton(
onPressed: onPressing,
style: ButtonStyle(
@ -68,32 +160,6 @@ class _DrawingPageState extends State<DrawingPage> {
);
}
void showPopUp(String alertTitle, String err) => showDialog<String>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: Text(alertTitle),
content: Text(err),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context, 'OK'),
child: const Text('OK'),
),
],
),
);
// *************buttons*************
// ***addSpace***
SizedBox addSpaceH(double h) {
return SizedBox(height: h);
}
SizedBox addSpaceW(double w) {
return SizedBox(width: w);
}
// ***addSpace***
// *************inputs*************
Container createInputBox(String text, double wid, IconData? icon,
TextEditingController? controller) {
if (icon == null) {
@ -137,78 +203,32 @@ class _DrawingPageState extends State<DrawingPage> {
));
}
SizedBox dropList1(double width) {
var button = DropdownButton(
hint: const Text(
'Select Dot',
style: TextStyle(color: Colors.white, fontSize: 13),
),
//icon: const Icon(Icons.fiber_manual_record, color: Colors.white),
alignment: AlignmentDirectional.bottomEnd,
value: dropdownValue1,
isDense: true,
borderRadius: const BorderRadius.all(Radius.circular(20)),
dropdownColor: Colors.green.shade800,
style: const TextStyle(
color: Colors.white,
fontSize: 18,
),
onChanged: (String? newValue) {
setState(() {
dropdownValue1 = newValue;
});
},
items: graphData.getDots().map((location) {
return DropdownMenuItem(
child: Text(location.getName()),
value: location.num.toString(),
);
}).toList(),
);
return SizedBox(
child: button,
width: width,
);
SizedBox addSpaceH(double h) {
return SizedBox(height: h);
}
SizedBox dropList2(double width) {
var button = DropdownButton(
hint: const Text(
'Select Dot',
style: TextStyle(color: Colors.white, fontSize: 13),
),
alignment: AlignmentDirectional.centerEnd,
value: dropdownValue2,
isDense: true,
borderRadius: const BorderRadius.all(Radius.circular(20)),
dropdownColor: Colors.green.shade800,
style: const TextStyle(
color: Colors.white,
fontSize: 18,
),
onChanged: (String? newValue) {
setState(() {
dropdownValue2 = newValue;
});
},
items: graphData.getDots().map((location) {
return DropdownMenuItem(
child: Text(location.getName()),
value: location.num.toString(),
);
}).toList(),
);
return SizedBox(
child: button,
width: width,
);
SizedBox addSpaceW(double w) {
return SizedBox(width: w);
}
// *************inputs*************
void showPopUp(String alertTitle, String err) => showDialog<String>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: Text(alertTitle),
content: Text(err),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context, 'OK'),
child: const Text('OK'),
),
],
),
);
//*********ButtonsFunctions*********
void addDotPushed() {
//showPopUp("Test", "Test message");
//var inp = int.tryParse(_textNameController.text);
setState(() {
if (_textNameController.text == "") {
showPopUp("Error", "No name in \"Dot name\" box");
@ -218,24 +238,26 @@ class _DrawingPageState extends State<DrawingPage> {
showPopUp("Error", res);
}
}
clearInputData();
clearTextControllers();
});
}
void addPathPushed() {
setState(() {
if (dropdownValue1 == null) {
showPopUp("Error", "Select output dot");
} else if (dropdownValue2 == null) {
showPopUp("Error", "select input dot");
if (_textNumbController.text == "") {
showPopUp("Error", "No number in \"Dot number\" box");
} else if (_textDestController.text == "") {
showPopUp("Error", "No number in \"Destination number\" box");
} else if (_textLnthController.text == "" &&
graphData.getUseLengthBool()) {
showPopUp("Error", "No length in \"Input length\" box");
} else {
int? from = int.parse(dropdownValue1!);
int? to = int.parse(dropdownValue2!);
int? from = int.tryParse(_textNumbController.text);
int? to = int.tryParse(_textDestController.text);
int? len = int.tryParse(_textLnthController.text);
if (len == null && graphData.getUseLengthBool()) {
if (from == null ||
to == null ||
(len == null && graphData.getUseLengthBool())) {
showPopUp("Error",
"Can't parse input.\nInts only allowed in \"Dot number\", \"Destination number\" and \"Input length\"");
} else {
@ -246,7 +268,7 @@ class _DrawingPageState extends State<DrawingPage> {
}
}
}
clearInputData();
clearTextControllers();
});
}
@ -283,18 +305,26 @@ class _DrawingPageState extends State<DrawingPage> {
}
}
}
clearInputData();
clearTextControllers();
});
}
void delDotPushed() {
setState(() {
if (dropdownValue1 != null) {
graphData.delDot(int.parse(dropdownValue1!));
if (_textNumbController.text == "") {
showPopUp("Error", "No number in \"Dot number\" box");
} else {
showPopUp("Error", "Nothing in input");
int? dot = int.tryParse(_textNumbController.text);
if (dot == null) {
showPopUp("Error", "Can't parse input.\nInts only allowed");
} else {
String? res = graphData.delDot(dot);
if (res != null) {
showPopUp("Error", res);
}
}
}
clearInputData();
clearTextControllers();
});
}
@ -306,12 +336,14 @@ class _DrawingPageState extends State<DrawingPage> {
if (!result.files.single.path!.endsWith(".txt")) {
showPopUp("Error", "Can open only \".txt\" files");
} else {
//print(result.files.single.path!);
String? res =
graphData.replaceDataFromFile(result.files.single.path!);
if (res != null) showPopUp("Error", res);
}
} else {
showPopUp("Error", "No file selected");
// User canceled the picker
}
});
}
@ -323,6 +355,7 @@ class _DrawingPageState extends State<DrawingPage> {
allowedExtensions: ["txt"]);
if (outputFile == null) {
showPopUp("Error", "Save cancelled");
// User canceled the picker
} else {
if (!outputFile.endsWith(".txt")) {
outputFile += ".txt";
@ -333,167 +366,51 @@ class _DrawingPageState extends State<DrawingPage> {
void bfsPushed() {
setState(() {
bfsPath = null;
dfsAccessTable = null;
startDot = null;
endDot = null;
if (dropdownValue1 == null) {
bfsPath = null;
if (_textNumbController.text == "") {
showPopUp("Error", "No number in \"Dot number\" box");
} else if (dropdownValue2 == null) {
} else if (_textDestController.text == "") {
showPopUp("Error", "No number in \"Destination number\" box");
} else {
startDot = int.parse(dropdownValue1!);
endDot = int.parse(dropdownValue2!);
bfsPath = graphData.bfsPath(startDot!, endDot!);
if (bfsPath == null) {
showPopUp("Info", "There is no path");
int? from = int.tryParse(_textNumbController.text);
int? to = int.tryParse(_textDestController.text);
if (from == null || to == null) {
showPopUp("Error",
"Can't parse input.\nInts only allowed in \"Dot number\" and \"Destination number\"");
} else {
bfsPath = graphData.bfsPath(from, to);
if (bfsPath == null) {
showPopUp("Info", "There is no path");
}
print(bfsPath);
}
print(bfsPath);
}
clearTextControllers();
});
clearInputData();
}
void dfsPushed() {
setState(() {
bfsPath = null;
dfsAccessTable = null;
startDot = null;
endDot = null;
if (dropdownValue1 == null) {
bfsPath = null;
if (_textNumbController.text == "") {
showPopUp("Error", "No number in \"Dot number\" box");
} else {
startDot = int.parse(dropdownValue1!);
dfsAccessTable = graphData.dfsIterative(startDot!);
if (dfsAccessTable == null) {
showPopUp("Err", "report this error.");
int? from = int.tryParse(_textNumbController.text);
if (from == null) {
showPopUp("Error",
"Can't parse input.\nInts only allowed in \"Dot number\".");
} else {
dfsAccessTable = graphData.dfsIterative(from);
if (dfsAccessTable == null) {
showPopUp("Err", "report this error.");
}
print(dfsAccessTable);
}
print(dfsAccessTable);
}
clearInputData();
clearTextControllers();
});
}
//*********ButtonsFunctions*********
// build
@override
Widget build(BuildContext context) {
screenSize = MediaQuery.of(context).size.width;
_textGrNmController.text = graphData.getName();
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Align(
alignment: Alignment.topLeft,
child: Text("Graph name:\n",
style: TextStyle(
fontSize: 18,
color: Colors.white,
))),
toolbarHeight: 110,
flexibleSpace: Container(
color: Colors.green.shade900,
child: Column(children: <Widget>[
const SizedBox(height: 5),
Row(children: [
addSpaceW(screenSize / 8 + 19),
createButton("\nAdd dot\n", addDotPushed),
createInputBox("Dot name", screenSize / 4 - 25, Icons.label,
_textNameController),
addSpaceW(8),
createButton("\nAdd path\n", addPathPushed),
createInputBox("Input length", screenSize / 4 - 25,
Icons.arrow_right_alt_outlined, _textLnthController),
]),
addSpaceH(3),
Row(children: [
addSpaceW(6),
createInputBox(
"Name", screenSize / 8 - 25, null, _textGrNmController),
//addSpaceW(screenSize / 8 - 4),
createButton("\nDel dot \n", delDotPushed),
//createInputBox("Dot number", screenSize / 4 - 25, Icons.fiber_manual_record, _textNumbController),
addSpaceW(54),
dropList1(screenSize / 4 - 80),
addSpaceW(54),
createButton("\nDel path\n", delPathPushed),
addSpaceW(54),
dropList2(screenSize / 4 - 80),
//createInputBox("Destination number", screenSize / 4 - 25, Icons.fiber_manual_record, _textDestController),
]),
]),
),
actions: [
IconButton(
onPressed: () {
setState(() {
startDot = null;
endDot = null;
bfsPath = null;
dfsAccessTable = null;
graphData.flushData();
clearInputData();
});
},
icon: const Icon(Icons.delete_sweep),
iconSize: 60,
),
]),
body: CustomPaint(
painter: CurvePainter(
graphData: graphData,
bfsPath: bfsPath,
dfsAccessTable: dfsAccessTable,
start: startDot,
end: endDot),
child: Align(
alignment: Alignment.topRight,
child: ButtonBar(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
createButton("Bfs", bfsPushed),
createButton("Dfs", dfsPushed),
createButton("Clear dfs or bfs", () {
setState(() {
bfsPath = null;
dfsAccessTable = null;
startDot = null;
endDot = null;
clearInputData();
});
}),
createButton(graphData.getUseLengthStr(), changeLength),
createButton(graphData.getDoubleSidedStr(), changeOriented),
createButton("Save to file", fileSaver),
createButton("Load from file", fileOpener),
createButton("Help", () {
String out =
" В поле \"Graph name\" можно сменить имя графу.\n";
out +=
" Для добавления точки необходимо ввести имя в \"Dot name\" и нажать на \"Add dot\".\n";
out +=
" Для удаления точки необходимо ввести номер в \"Dot number\" и нажать на \"Del dot\".\n";
out +=
" Для добавления пути необходимо ввести: номер выходной вершины в \"Dot number\", номер входной вершины в \"Destination number\" ";
out +=
"и, если граф взвешенный, то ввести длину пути в \"Input length\". Затем нажать \"Add path\".\n";
out +=
" Для удаления пути необходимо ввести номер выходной вершины в \"Dot number\" и номер входной вершины в \"Destination number\". Затем нажать \"Del path\".\n\n";
out +=
" Кнопки \"Bfs\" и \"Dfs\" нумеруют точки в зависимости от послежовательности, в которой они будут пройдены.\n";
out +=
" Кнопки \"Взвешенный\" и \"Ориентированный\" позволяют сменить эти значения перед построением графа (т.е. для их работы граф должен быть пустым).\n";
out +=
" Кнопки \"Save to file\" и \"Load from file\" позволяют вывести информацию в файл и загрузить информацию из файла соответственно.\n";
out +=
" Кнопка \"Help\" описывает работу с интерфейсом программы.";
showPopUp("Help:", out);
})
],
),
),
),
));
}
}

View File

@ -363,7 +363,6 @@ class Graphs {
List<Dot> getDots() => _dots;
String getName() => _name;
String? getNameByNum(int n) => _nameTable[n];
Map<int, String> getNameTable() => _nameTable;
int getDotAmount() => _dots.length;
int? getNumByName(String n) {
for (var i in _nameTable.keys) {
@ -568,7 +567,6 @@ class Graphs {
}*/
List<int>? bfsPath(int startDot, int goalDot) {
if (startDot == goalDot) return [startDot];
//if (!bfsHasPath(startDot, goalDot)) return null;
startDot--;
goalDot--;
@ -608,6 +606,7 @@ class Graphs {
//Восстановим кратчайший путь
//Для восстановления пути пройдём его в обратном порядке, и развернём.
List<int> path = <int>[];
int cur = goalDot; //текущая вершина пути