Read graph from file

This commit is contained in:
Морозов Андрей 2021-10-25 02:17:56 +04:00
parent f4304de14a
commit c79951d361
5 changed files with 28 additions and 11 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
# Files and directories created by pub. # Files and directories created by pub.
.dart_tool/ .dart_tool/
.packages .packages
*.txt
# Conventional directory for build output. # Conventional directory for build output.
build/ build/

View File

@ -1,7 +1,7 @@
import 'src/graph.dart'; import 'src/graph.dart';
void main(List<String> arguments) { void main(List<String> arguments) {
Map<int, int> x = {1: 10, 2: 20}; Map<int, int> x = {1: 10, 2: 11};
var p = Dot.fromMap("Т1", x); var p = Dot.fromMap("Т1", x);
p.printD(); p.printD();
x = <int, int>{}; x = <int, int>{};

View File

@ -3,8 +3,9 @@ import 'dart:io';
class Separators { class Separators {
final String dotToConnections = ": "; final String dotToConnections = ": ";
final String dotToLength = "|"; final String dotToLength = "|";
final String hasLength = "Вес\n"; final String space = " ";
final String hasNoLength = "НетВеса\n"; final String hasLength = "Взвешенный\n";
final String hasNoLength = "НеВзвешенный\n";
final String isOriented = "Ориентированный\n"; final String isOriented = "Ориентированный\n";
final String isNotOriented = "НеОриентированный\n"; final String isNotOriented = "НеОриентированный\n";
final String nL = "\n"; final String nL = "\n";
@ -289,19 +290,34 @@ class Graphs {
_amount = _dots.length; _amount = _dots.length;
_oriented = oriented; _oriented = oriented;
_syncNum(); _syncNum();
if (!_oriented) {
for (int i = 0; i < _amount; i++) {
_fixPathAfterInsert(_dots[i]);
}
}
if (!_oriented) _fullFix(); if (!_oriented) _fullFix();
} }
Graphs.fromFile(String path) { Graphs.fromFile(String path) {
Separators sep = Separators();
File file = File(path); File file = File(path);
List<String> lines = file.readAsLinesSync(); List<String> lines = file.readAsLinesSync();
_name = lines.removeAt(0);
_oriented = lines.removeAt(0) == sep.isOriented;
_useLength = lines.removeAt(0) == sep.hasLength;
_dots = <Dot>[];
for (var l in lines) { for (var l in lines) {
print(l); 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(sep.dotToLength);
dot.add(int.parse(dt[0]));
len.add(int.parse(dt[1]));
}
Dot add = Dot.fromTwoLists(name, dot, len);
_dots.add(add);
}
} }
_syncNameTable();
if (!_oriented) _fullFix();
} }
//*******Constructor******** //*******Constructor********

View File

@ -9,4 +9,4 @@ packages:
source: hosted source: hosted
version: "1.0.1" version: "1.0.1"
sdks: sdks:
dart: ">=2.15.0-178.0.dev <3.0.0" dart: ">=2.14.0-178.0.dev <3.0.0"

View File

@ -4,7 +4,7 @@ version: 1.0.0
# homepage: https://www.example.com # homepage: https://www.example.com
environment: environment:
sdk: '>=2.15.0-178.0.dev <3.0.0' sdk: '>=2.14.0-178.0.dev <3.0.0'
# dependencies: # dependencies: