Read graph from file
This commit is contained in:
parent
f4304de14a
commit
c79951d361
|
@ -1,6 +1,7 @@
|
|||
# Files and directories created by pub.
|
||||
.dart_tool/
|
||||
.packages
|
||||
*.txt
|
||||
|
||||
# Conventional directory for build output.
|
||||
build/
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import 'src/graph.dart';
|
||||
|
||||
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);
|
||||
p.printD();
|
||||
x = <int, int>{};
|
||||
|
|
|
@ -3,8 +3,9 @@ import 'dart:io';
|
|||
class Separators {
|
||||
final String dotToConnections = ": ";
|
||||
final String dotToLength = "|";
|
||||
final String hasLength = "Вес\n";
|
||||
final String hasNoLength = "НетВеса\n";
|
||||
final String space = " ";
|
||||
final String hasLength = "Взвешенный\n";
|
||||
final String hasNoLength = "НеВзвешенный\n";
|
||||
final String isOriented = "Ориентированный\n";
|
||||
final String isNotOriented = "НеОриентированный\n";
|
||||
final String nL = "\n";
|
||||
|
@ -289,19 +290,34 @@ class Graphs {
|
|||
_amount = _dots.length;
|
||||
_oriented = oriented;
|
||||
_syncNum();
|
||||
if (!_oriented) {
|
||||
for (int i = 0; i < _amount; i++) {
|
||||
_fixPathAfterInsert(_dots[i]);
|
||||
}
|
||||
}
|
||||
if (!_oriented) _fullFix();
|
||||
}
|
||||
Graphs.fromFile(String path) {
|
||||
Separators sep = Separators();
|
||||
File file = File(path);
|
||||
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) {
|
||||
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********
|
||||
|
||||
|
|
|
@ -9,4 +9,4 @@ packages:
|
|||
source: hosted
|
||||
version: "1.0.1"
|
||||
sdks:
|
||||
dart: ">=2.15.0-178.0.dev <3.0.0"
|
||||
dart: ">=2.14.0-178.0.dev <3.0.0"
|
||||
|
|
|
@ -4,7 +4,7 @@ version: 1.0.0
|
|||
# homepage: https://www.example.com
|
||||
|
||||
environment:
|
||||
sdk: '>=2.15.0-178.0.dev <3.0.0'
|
||||
sdk: '>=2.14.0-178.0.dev <3.0.0'
|
||||
|
||||
|
||||
# dependencies:
|
||||
|
|
Loading…
Reference in New Issue