-
Notifications
You must be signed in to change notification settings - Fork 0
/
transport_router.h
80 lines (58 loc) · 2.5 KB
/
transport_router.h
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#pragma once
#include <string>
#include <iostream>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <memory>
#include <algorithm>
#include <deque>
#include "transport_catalogue.h"
#include "json_builder.h"
#include "router.h"
struct RouteSettings {
int bus_wait_time; // мин
double bus_velocity; // м/мин
};
struct Route {
Route() = default;
Route(std::shared_ptr<Stop> stop_from, std::shared_ptr<Stop> stop_to, double waiting_time,
const std::string& bus_name, int span_count)
: stop_from(stop_from), stop_to(stop_to), waiting_time(waiting_time),
bus_name(bus_name), span_count(span_count) {
}
std::shared_ptr<Stop> stop_from;
std::shared_ptr<Stop> stop_to;
double waiting_time;
const std::string& bus_name;
int span_count;
};
class TransportRouter {
public:
TransportRouter(TransportCatalogue& transoprt_catalogue);
void SetRouteSettings(const RouteSettings& route_settings);
// Обработка запроса
void ParseQuery(const std::string& stop_from, const std::string& stop_to, int request_id, json::Builder& json_builder);
std::deque<std::shared_ptr<Route>> SetHash();
// Создание графа на основе всевозможных путей в рамках каждого маршрута
void SetGraph();
RouteSettings& GetRouteSettings();
std::shared_ptr<graph::DirectedWeightedGraph<double>> GetGraph();
std::shared_ptr<graph::Router<double>> GetRouter();
private:
RouteSettings route_settings_;
std::shared_ptr<graph::DirectedWeightedGraph<double>> graph_;
std::shared_ptr<graph::Router<double>> router_;
TransportCatalogue& transoprt_catalogue_;
std::map<double, std::shared_ptr<Route>> hash_to_route_;
// Расчет времени пути между остановками с учетом времени ожидания
double CalculateTimeWithWaiting_(const std::shared_ptr<Stop> stop_from, const std::shared_ptr<Stop> stop_to);
// Расчет времени пути между остановками
double CalculateTime_(const std::shared_ptr<Stop> stop_from, const std::shared_ptr<Stop> stop_to);
// Сложение маршрутов с общими остановками
std::shared_ptr<Route> SumRoutes_(const std::shared_ptr<Route> left, const std::shared_ptr<Route> right, const std::string& bus_name);
// Расчет хэша структуры маршрута
double Hash_(graph::VertexId id_from, graph::VertexId id_to, double waiting_time);
void ExitWithEmptyResult_(int request_id, json::Builder& json_builder);
};