Locus No Pilotus
Project of four first grade MIPT DAFE/RSE students (for engineering practical work in the second semester) in Qt C++
Loading...
Searching...
No Matches
math::DijkstrasAlgorithm Class Reference

Реализация алгоритма Дейкстры More...

#include <path_graph.h>

Collaboration diagram for math::DijkstrasAlgorithm:

Public Member Functions

 DijkstrasAlgorithm (PathWayGraph graph)
 Инициализирует новый экземпляр Dijkstras_algorithm.
 
double Get_Min_Len () const
 
std::vector< std::size_t > Get_Min_Path () const
 

Private Member Functions

void Calculate_Min_Path ()
 Определяет длину кратчайшего пути из start_ в end_.
 

Private Attributes

std::size_t first_point_
 
std::map< std::size_t, double > graphs_vertex_
 
double min_length_
 
std::vector< std::size_t > min_path_
 
std::vector< std::shared_ptr< PathWayNode > > path_nodes_
 
std::size_t second_point_
 

Detailed Description

Реализация алгоритма Дейкстры

Constructor & Destructor Documentation

◆ DijkstrasAlgorithm()

math::DijkstrasAlgorithm::DijkstrasAlgorithm ( PathWayGraph graph)
inline

Инициализирует новый экземпляр Dijkstras_algorithm.

Parameters
startначальная точка
endконечная точка
104 : first_point_{graph.nodes.size() - 2},
105 second_point_{graph.nodes.size() - 1},
106 path_nodes_{graph.nodes},
107 min_length_{0} {
111 }
std::size_t first_point_
Definition path_graph.h:121
void Calculate_Min_Path()
Определяет длину кратчайшего пути из start_ в end_.
Definition path_graph.cpp:9
std::map< std::size_t, double > graphs_vertex_
Definition path_graph.h:136
std::vector< std::shared_ptr< PathWayNode > > path_nodes_
Definition path_graph.h:127
double min_length_
Definition path_graph.h:130
std::size_t second_point_
Definition path_graph.h:124
Here is the call graph for this function:

Member Function Documentation

◆ Calculate_Min_Path()

void math::DijkstrasAlgorithm::Calculate_Min_Path ( )
private

Определяет длину кратчайшего пути из start_ в end_.

9 {
11 std::shared_ptr<PathWayNode> min_len_key;
12 for (auto& elem : graphs_vertex_)
13 if ((std::abs(elem.second - min_length_) <= precision) &&
14 (!path_nodes_[elem.first]->is_visited))
15 min_len_key = path_nodes_[elem.first];
16
17 for (std::size_t i = 0; i < min_len_key->edges.size(); ++i)
18 if ((graphs_vertex_.find(min_len_key->edges[i]->number) ==
19 graphs_vertex_.end()) ||
20 (graphs_vertex_[min_len_key->edges[i]->number] >
21 graphs_vertex_[min_len_key->number] + min_len_key->edges_lens[i]))
22 graphs_vertex_[min_len_key->edges[i]->number] =
23 graphs_vertex_[min_len_key->number] + min_len_key->edges_lens[i];
24 else
25 continue;
26 min_len_key->is_visited = true;
27
28 min_length_ = inf;
29 for (auto& elem : graphs_vertex_)
30 if ((elem.second < min_length_) &&
31 (!(*path_nodes_[elem.first]).is_visited))
32 min_length_ = elem.second;
33 }
34
35 // Определение маршрута по длинам, сохранившимся в graphs_vertex_
36 std::size_t end = second_point_;
37 min_path_.push_back(end);
38 while (end != first_point_) {
39 for (std::size_t i = 0; i < path_nodes_[end]->edges.size(); ++i)
40 if (std::abs(graphs_vertex_[path_nodes_[end]->number] -
41 graphs_vertex_[path_nodes_[end]->edges[i]->number] -
42 path_nodes_[end]->edges_lens[i]) <= precision) {
43 end = path_nodes_[end]->edges[i]->number;
44 min_path_.push_back(end);
45 break;
46 }
47 }
48 std::reverse(min_path_.begin(), min_path_.end());
49}
std::vector< std::size_t > min_path_
Definition path_graph.h:133
Here is the caller graph for this function:

◆ Get_Min_Len()

double math::DijkstrasAlgorithm::Get_Min_Len ( ) const
inline
114{ return min_length_; }
Here is the caller graph for this function:

◆ Get_Min_Path()

std::vector< std::size_t > math::DijkstrasAlgorithm::Get_Min_Path ( ) const
inline
117{ return min_path_; }
Here is the caller graph for this function:

Member Data Documentation

◆ first_point_

std::size_t math::DijkstrasAlgorithm::first_point_
private

◆ graphs_vertex_

std::map<std::size_t, double> math::DijkstrasAlgorithm::graphs_vertex_
private

◆ min_length_

double math::DijkstrasAlgorithm::min_length_
private

◆ min_path_

std::vector<std::size_t> math::DijkstrasAlgorithm::min_path_
private

◆ path_nodes_

std::vector<std::shared_ptr<PathWayNode> > math::DijkstrasAlgorithm::path_nodes_
private

◆ second_point_

std::size_t math::DijkstrasAlgorithm::second_point_
private

The documentation for this class was generated from the following files: