1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . IO ;
4
- using System . Linq ;
5
4
6
5
namespace DijkstraAlgorithm
7
6
{
8
7
class Program
9
8
{
10
9
static void Main ( string [ ] args )
11
10
{
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 ) ;
15
16
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 ) ;
18
19
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 ) ;
19
27
20
- double shortestPathLength ;
28
+ // Записываем получившуюся поверхность в файл
29
+ string docPath = Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) ;
30
+ graph . WriteSurfaceToFile ( Path . Combine ( docPath , "surface.txt" ) ) ;
21
31
22
- Point2D startPoint = new Point2D ( 4 , 46 ) ;
23
- Point2D goalPoint = new Point2D ( 95 , 4 ) ;
32
+ // Вычисляем кратчайший путь
33
+ double shortestPathLength = 0.0 ;
24
34
25
- List < Point2D > path = graph . FindShortestPathAndLength ( startPoint , goalPoint , out shortestPathLength ) ;
35
+ Point2D startPoint = new Point2D ( 92 , 7 ) ;
36
+ Point2D goalPoint = new Point2D ( 14 , 21 ) ;
26
37
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" ) ) ;
28
42
29
43
Console . ReadLine ( ) ;
30
44
}
@@ -37,5 +51,14 @@ private static void WriteShortestPathToFile(List<Point2D> shortestPath, string f
37
51
38
52
File . WriteAllLines ( fileName , lines ) ;
39
53
}
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
+ }
40
63
}
41
64
}
0 commit comments