Skip to content

Commit 5d20415

Browse files
author
Зелёный Андрей Сергеевич
committed
Рефакторинг метода Main() для поиска кратчайшего пути на поверхности
1 parent a14fa31 commit 5d20415

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

Program.cs

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4-
using System.Linq;
54

65
namespace DijkstraAlgorithm
76
{
87
class Program
98
{
109
static void Main(string[] args)
1110
{
12-
string directoryPath = Environment.CurrentDirectory;
13-
int[,] obstacleMatrix = Obstacle.CreateObstacleMatrixFromCSVFile(directoryPath + "Maze1.csv");
14-
Obstacle.WriteObstacleToFile(obstacleMatrix, directoryPath + "Maze1Obstacle.txt");
11+
// Создаем несколько экземпляров параметров для Гауссиана для имитации гор (холмов) и одного оврага
12+
GaussianParameter gaussianParameter1 = new GaussianParameter(1.5, 0.5, 0.5, 2.0, 4.0);
13+
GaussianParameter gaussianParameter2 = new GaussianParameter(1.0, 0.5, 0.5, 7.5, 1.0);
14+
GaussianParameter gaussianParameter3 = new GaussianParameter(-0.5, 0.2, 1.0, 5.0, 0.5);
15+
GaussianParameter gaussianParameter4 = new GaussianParameter(1.0, 0.5, 0.8, 3.5, 2.2);
1516

16-
//Graph graph = new Graph(1, 1, 2, 3, Surface.Plane);
17-
Graph graph = new Graph(obstacleMatrix);
17+
// Инициализируем граф
18+
Graph graph = new Graph(0.1, 0.1, 101, 51, 20.0, gaussianParameter1, gaussianParameter2, gaussianParameter3, gaussianParameter4);
1819

20+
// Создаем искуственные сооружения на карте
21+
graph.CreateBuilding(new Point2D(57, 20), 2, 20, 0.3);
22+
graph.CreateBuilding(new Point2D(64, 16), 3, 5, 0.3);
23+
graph.CreateBuilding(new Point2D(18, 4), 2, 5, 0.3);
24+
graph.CreateBuilding(new Point2D(10, 14), 4, 2, 0.4);
25+
graph.CreateBuilding(new Point2D(64, 29), 5, 2, 0.4);
26+
graph.CreateBuilding(new Point2D(14, 24), 5, 2, 0.3);
1927

20-
double shortestPathLength;
28+
// Записываем получившуюся поверхность в файл
29+
string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
30+
graph.WriteSurfaceToFile(Path.Combine(docPath, "surface.txt"));
2131

22-
Point2D startPoint = new Point2D(4, 46);
23-
Point2D goalPoint = new Point2D(95, 4);
32+
// Вычисляем кратчайший путь
33+
double shortestPathLength = 0.0;
2434

25-
List<Point2D> path = graph.FindShortestPathAndLength(startPoint, goalPoint, out shortestPathLength);
35+
Point2D startPoint = new Point2D(92, 7);
36+
Point2D goalPoint = new Point2D(14, 21);
2637

27-
WriteShortestPathToFile(path, directoryPath + "Maze1ShortestPath.txt");
38+
List<Point2D> shortestPath = graph.FindShortestPathAndLength(startPoint, goalPoint, out shortestPathLength);
39+
40+
// Записываем найденный путь в файл
41+
WriteShortestPathToFile(shortestPath, graph, Path.Combine(docPath, "shortestPath.txt"));
2842

2943
Console.ReadLine();
3044
}
@@ -37,5 +51,14 @@ private static void WriteShortestPathToFile(List<Point2D> shortestPath, string f
3751

3852
File.WriteAllLines(fileName, lines);
3953
}
54+
55+
private static void WriteShortestPathToFile(List<Point2D> shortestPath, Graph graph, string fileName)
56+
{
57+
List<string> lines = new List<string>();
58+
foreach (Point2D point in shortestPath)
59+
lines.Add(string.Format("{0};{1};{2}", point.i * 0.1, point.j * 0.1, graph.Vertices[point.i, point.j].Height));
60+
61+
File.WriteAllLines(fileName, lines);
62+
}
4063
}
4164
}

0 commit comments

Comments
 (0)