- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
Latest commit
57 lines (44 loc) · 2.2 KB
/
Copy pathProgram.cs
File metadata and controls
57 lines (44 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
usingSystem;
usingSystem.Collections.Generic;
usingSystem.IO;
usingSystem.Linq;
namespaceDijkstraAlgorithm
{
classProgram
{
staticvoidMain(string[]args)
{
// Создаем матрицу-препятствий из csv-файла
stringdocPath=Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
int[,]obstacleMatrix=Obstacle.CreateObstacleMatrixFromCSVFile(Path.Combine(docPath,"obstacle1.csv"));
// Инициализируем граф с помощью этой матрицы
Graphgraph=newGraph(obstacleMatrix);
// Вычисляем кратчайший путь
doubleshortestPathLength=0.0;
Point2DstartPoint=newPoint2D(3,4);
Point2DgoalPoint=newPoint2D(12,4);
List<Point2D>shortestPath=graph.FindShortestPathAndLength(startPoint,goalPoint,outshortestPathLength);
// Записываем найденный путь в файл
//WriteShortestPathToFile(shortestPath, Path.Combine(docPath, "shortestPath.txt"));
Console.WriteLine("Coordinates of shortest path: ");
foreach(Point2DpinshortestPath)
Console.WriteLine(string.Format("({0}, {1})",p.i,p.j));
Console.WriteLine(string.Format("Length of shortest path: {0}",shortestPathLength));
Console.ReadLine();
}
privatestaticvoidWriteShortestPathToFile(List<Point2D>shortestPath,stringfileName)
{
List<string>lines=newList<string>();
foreach(Point2DpointinshortestPath)
lines.Add(string.Format("{0};{1};1",point.i,point.j));
File.WriteAllLines(fileName,lines);
}
privatestaticvoidWriteShortestPathToFile(List<Point2D>shortestPath,Graphgraph,stringfileName)
{
List<string>lines=newList<string>();
foreach(Point2DpointinshortestPath)
lines.Add(string.Format("{0};{1};{2}",point.i*0.1,point.j*0.1,graph.Vertices[point.i,point.j].Height));
File.WriteAllLines(fileName,lines);
}
}
}