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::TrajectoryCalculator Class Reference

#include <trajectory.h>

Collaboration diagram for math::TrajectoryCalculator:

Public Member Functions

 TrajectoryCalculator (const std::vector< lib::Target > &targets, const std::vector< lib::TrappyLine > &lines, const std::vector< lib::TrappyCircle > &circles, const std::vector< lib::Hill > &hills, unsigned short num_of_flyers)
 Инициализирует экземпляр класса TrajectoryCalculator.
 
std::vector< lib::SegmentGetTrajectory ()
 Возвращает траекторию
 

Private Member Functions

void CalculateTrajectory ()
 Рассчитывает траекторию
 
std::vector< lib::SegmentGetTrajectoryPart (std::vector< std::size_t > optimal_way, const std::vector< std::shared_ptr< PathWayNode > > &nodes)
 Подсчет части траектории
 

Private Attributes

std::vector< CircleObstaclecircles_
 
std::vector< std::pair< std::size_t, std::size_t > > forbidden_lines_
 
unsigned short number_of_flyers_
 
std::vector< PolygonObstaclepolys_
 
std::vector< Pointtargets_
 
std::vector< lib::Segmenttrajectory_
 

Constructor & Destructor Documentation

◆ TrajectoryCalculator()

math::TrajectoryCalculator::TrajectoryCalculator ( const std::vector< lib::Target > & targets,
const std::vector< lib::TrappyLine > & lines,
const std::vector< lib::TrappyCircle > & circles,
const std::vector< lib::Hill > & hills,
unsigned short num_of_flyers )
inline

Инициализирует экземпляр класса TrajectoryCalculator.

Parameters
targetsконтрольные точки
linesзапрещённые перелеты
circlesкруговые препятствия
hillsмногоугольные препятствия
24 : number_of_flyers_{num_of_flyers} {
25 for (auto& target : targets) targets_.push_back(Point(target.GetPoint()));
26
27 for (auto& line : lines) {
28 std::pair<std::size_t, std::size_t> indexes;
29 std::pair<lib::Target, lib::Target> points = line.GetTargets();
30 for (std::size_t i = 0; i < targets.size(); ++i)
31 if (targets[i] == points.first)
32 indexes.first = i;
33 else if (targets[i] == points.second)
34 indexes.second = i;
35 forbidden_lines_.push_back(indexes);
36 }
37
38 for (auto& circle : circles)
39 circles_.push_back(
40 CircleObstacle(Point(circle.GetCenter()), circle.GetRadius()));
41
42 for (auto& hill : hills) {
43 std::vector<Point> vertexes;
44 for (auto& vertex : hill.GetVertices()) vertexes.push_back(Point(vertex));
45 polys_.push_back(PolygonObstacle(vertexes));
46 }
47
49 }
std::vector< CircleObstacle > circles_
Definition trajectory.h:65
std::vector< std::pair< std::size_t, std::size_t > > forbidden_lines_
Definition trajectory.h:62
std::vector< PolygonObstacle > polys_
Definition trajectory.h:68
void CalculateTrajectory()
Рассчитывает траекторию
Definition trajectory.cpp:12
std::vector< Point > targets_
Definition trajectory.h:59
unsigned short number_of_flyers_
Definition trajectory.h:56
Here is the call graph for this function:

Member Function Documentation

◆ CalculateTrajectory()

void math::TrajectoryCalculator::CalculateTrajectory ( )
private

Рассчитывает траекторию

12 {
13 // Матрица смежности контрольных точек
14 std::vector<std::vector<double>> matrix(targets_.size());
15 for (auto& elem : matrix) elem.resize(targets_.size());
16
17 // Матрица оптимальных путей между контрольными точками
18 std::vector<std::vector<std::vector<Segment>>> optimal_ways(targets_.size());
19 for (auto& elem : optimal_ways) elem.resize(targets_.size());
20
21 // Заполнение матриц
22 OptimalWayCalculator owc(circles_, polys_);
23
24 for (std::size_t i = 0; i < targets_.size(); ++i) {
25 matrix[i][i] = inf;
26 for (std::size_t j = 0; j < i; ++j) {
27 owc.FindOptimalWay(targets_[i], targets_[j]);
28 std::vector<Segment> segment_way = owc.GetTrajectoryPart();
29
30 optimal_ways[i][j] = segment_way;
31 std::reverse(segment_way.begin(), segment_way.end());
32 for (auto& seg_part : segment_way) {
33 if (seg_part.IsArc())
34 seg_part =
35 Segment(seg_part.End(), seg_part.Start(), seg_part.Center());
36 else
37 seg_part = Segment(seg_part.End(), seg_part.Start());
38 }
39 optimal_ways[j][i] = segment_way;
40
41 matrix[i][j] = owc.GetOptimalWayLength();
42 matrix[j][i] = owc.GetOptimalWayLength();
43 }
44 }
45
46 for (auto& line : forbidden_lines_) {
47 matrix[line.first][line.second] = inf;
48 matrix[line.second][line.first] = inf;
49 }
50
51 // Просчет кратчайшей траектории по алгоритму Литтла
52 AdjacencyMatrix adj_matrix = AdjacencyMatrix::WithExtraRowCol(matrix);
53 TravellingSalesmansProblem tsp(adj_matrix, number_of_flyers_);
54 std::vector<std::size_t> traj = tsp.GetTrajectory();
55
56 // Объединение частей траектории
57 for (std::size_t i = 0; i < traj.size(); ++i) {
58 trajectory_.insert(
59 trajectory_.end(),
60 optimal_ways[traj[i]][traj[(i + 1) % traj.size()]].begin(),
61 optimal_ways[traj[i]][traj[(i + 1) % traj.size()]].end());
62 }
63}
Сегмент математический траектории
Definition segment.h:12
static AdjacencyMatrix WithExtraRowCol(const std::vector< std::vector< double > > &nums)
Создает новый экземпляр AdjacencyMatrix с добавлением строки и столбца номеров точек
Definition adjacency_matrix.cpp:9
std::vector< lib::Segment > trajectory_
Definition trajectory.h:71
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetTrajectory()

std::vector< lib::Segment > math::TrajectoryCalculator::GetTrajectory ( )
inline

Возвращает траекторию

52{ return trajectory_; }
Here is the caller graph for this function:

◆ GetTrajectoryPart()

std::vector< lib::Segment > math::TrajectoryCalculator::GetTrajectoryPart ( std::vector< std::size_t > optimal_way,
const std::vector< std::shared_ptr< PathWayNode > > & nodes )
private

Подсчет части траектории

Parameters
optimal_wayпорядок обхода точек
nodesвершины графа
Returns
часть траектории

Member Data Documentation

◆ circles_

std::vector<CircleObstacle> math::TrajectoryCalculator::circles_
private

◆ forbidden_lines_

std::vector<std::pair<std::size_t, std::size_t> > math::TrajectoryCalculator::forbidden_lines_
private

◆ number_of_flyers_

unsigned short math::TrajectoryCalculator::number_of_flyers_
private

◆ polys_

std::vector<PolygonObstacle> math::TrajectoryCalculator::polys_
private

◆ targets_

std::vector<Point> math::TrajectoryCalculator::targets_
private

◆ trajectory_

std::vector<lib::Segment> math::TrajectoryCalculator::trajectory_
private

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