-
Notifications
You must be signed in to change notification settings - Fork 0
Worker #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
S4ll7
wants to merge
25
commits into
rk4
Choose a base branch
from
Worker
base: rk4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Worker #21
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
6e5686a
add queue header and tests
Greenader 7e28275
delete Foo
Greenader 9ede2a8
delete comment
Greenader e435813
delete spaces
Greenader 3d58e35
delete resize()
Greenader e4f5634
fufSuze rename
Greenader 03f979b
add realization
Greenader 7ffe36d
add spaces for goodread
Greenader 4ca7c12
algo header, realisation and 1 test
Greenader fa6cce5
add 4 tests
Greenader 3768fca
work with syntax
Greenader 53f1f96
add const & in functions
Greenader 6b7fe9e
syntax
Greenader 439314b
start work newAlg
Greenader 66c0448
corrections
Greenader 72e1d53
жадный обход
Greenader 8b25a2e
...
Greenader f422dc2
Merge branch 'rk3' into queue
AlekseySirmais7 2d54bd5
Merge pull request #11 from Sermelyan/queue
AlekseySirmais7 2383320
Merge branch 'rk3' into algorithm
AlekseySirmais7 4f1ff78
Merge pull request #13 from Sermelyan/algorithm
AlekseySirmais7 c965346
1
S4ll7 d67f40a
2
S4ll7 b3774d3
new
S4ll7 5fd30f9
1
S4ll7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| 1 1 1 Почтампт #0 | ||
| 2 24 78 Музей_Пушкина #Пушкин#Дворец | ||
| 3 5 13 Красная_площадь #Красная_площадь | ||
| 4 5 10 Пушкинский_музей #История#Красная_площадь | ||
| 5 4 8 Грановитая_палата #История#Красная_площадь#Искуство#шапка | ||
| 6 5 11 Сабор_василия_блаженного #Красная_площадь#История#Храмы | ||
| 7 56 65 ВДНХ #Выставка#Прогулка | ||
| 8 58 65 Фонтан_дружбы_народов #Фонтан#История | ||
| 9 54 63 Музей_космонавтики #Музеи#История#Космос | ||
| 10 60 65 Каменный_цветок #Фонтан#История | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #include <iostream> | ||
| #include <string> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| #ifndef INCLUDE_DATA_HPP_ | ||
| #define INCLUDE_DATA_HPP_ | ||
|
|
||
| static const unsigned MIN_IN_HOUR = 60; | ||
|
|
||
| typedef std::pair<double, double> Point; | ||
| typedef std::vector<Point> Points; | ||
| typedef std::vector<std::string> Filters; | ||
|
|
||
| struct DataIn { | ||
| Filters FilterList; | ||
| unsigned TimeLimit; | ||
| unsigned MaxDots; | ||
| Point StartPoint; | ||
| Point EndPoint; | ||
| int UserID; | ||
| DataIn() {} | ||
| DataIn(::Filters _f, unsigned _t, unsigned _md, Point _sp, Point _ep, | ||
| int _u) | ||
| : FilterList(_f), | ||
| TimeLimit(_t), | ||
| MaxDots(_md), | ||
| StartPoint(_sp), | ||
| EndPoint(_ep), | ||
| UserID(_u) {} | ||
| }; | ||
|
|
||
| struct DataOut { | ||
| Points RoutePoints; | ||
| unsigned MaxTime; | ||
| int UserID; | ||
| DataOut() {} | ||
| DataOut(const Points&& _p, unsigned _t, int _u) | ||
| : RoutePoints(_p), MaxTime(_t), UserID(_u) {} | ||
| }; | ||
|
|
||
| #endif // INCLUDE_DATA_HPP_ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,57 @@ | ||
| /* | ||
| * Copyright 2019 <Copyright Owner> | ||
| * Copyright 2019 <Alex> | ||
| */ | ||
|
|
||
| #ifndef INCLUDE_ALGORITHM_HPP_ | ||
| #define INCLUDE_ALGORITHM_HPP_ | ||
|
|
||
| #include <utility> | ||
| #include <vector> | ||
| #include <unordered_set> | ||
| #include <boost/graph/graph_traits.hpp> | ||
| #include <boost/graph/adjacency_list.hpp> | ||
| #include <boost/graph/dijkstra_shortest_paths.hpp> | ||
| #include <assert.h> | ||
|
|
||
| class Algorithm { | ||
|
|
||
| public: | ||
| typedef std::size_t dotId; | ||
| typedef std::pair<dotId, dotId> edge; | ||
| typedef std::size_t weight; | ||
|
|
||
| private: | ||
| typedef boost::adjacency_list <boost::listS, boost::vecS, boost::directedS, | ||
| boost::no_property,boost::property<boost::edge_weight_t, size_t> > graph_t; | ||
| typedef boost::graph_traits<graph_t>::vertex_descriptor vertex_descriptor; | ||
|
|
||
| public: | ||
| Algorithm()= delete; | ||
| explicit Algorithm(const std::vector<edge> &edgeArr, const std::vector<weight> &weightArr); | ||
| ~Algorithm(); | ||
| Algorithm(const Algorithm&) = delete; | ||
| Algorithm(const Algorithm&&) = delete; | ||
| Algorithm& operator=(const Algorithm&) = delete; | ||
| Algorithm& operator=(const Algorithm&&) = delete; | ||
|
|
||
| std::vector<dotId> CalcRoute(const dotId &A, const dotId &B); | ||
|
|
||
| std::pair<std::vector<Algorithm::dotId>, size_t> | ||
| getRoute(dotId from, const size_t &pointsCount, | ||
| const size_t &time, const size_t &maxPlacesCount); | ||
|
|
||
|
|
||
|
|
||
| // delete this from algo and use from WorkerAPI | ||
| long int getWeightIndex(const size_t &pointsCount, const size_t &from, const size_t &to); | ||
|
|
||
| private: | ||
| void MakeGraph(); | ||
| edge * edgeArr; | ||
| size_t edgeSize; | ||
| weight * weightArr; | ||
| graph_t myGraph; | ||
| const size_t MAX_PLACES = 200; // контроль (максимальное кол-во мест в пути) | ||
| }; | ||
|
|
||
| #endif // INCLUDE_ALGORITHM_HPP_ |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Copyright 2019 <Alex> | ||
| */ | ||
|
|
||
| #ifndef INCLUDE_QUEUE_HPP_ | ||
| #define INCLUDE_QUEUE_HPP_ | ||
|
|
||
|
|
||
| #include <queue> | ||
| #include <mutex> | ||
| #include <memory> | ||
|
|
||
| template <class T> | ||
| class GQueue { | ||
| public: | ||
| GQueue() = delete; | ||
| explicit GQueue(const T &element404); | ||
| ~GQueue(); | ||
| void push(const T &element); | ||
| T popIfNotEmpty(); | ||
|
|
||
| GQueue(const GQueue&) = delete; | ||
| GQueue(const GQueue&&) = delete; | ||
| GQueue& operator=(const GQueue&) = delete; | ||
| GQueue& operator=(const GQueue&&) = delete; | ||
|
|
||
| private: | ||
| T element404; | ||
| std::unique_ptr<std::queue<T>> queue; | ||
| std::mutex GQueueMutex; | ||
| }; | ||
|
|
||
| template <class T> | ||
| GQueue<T>::~GQueue() = default; | ||
|
|
||
| template <class T> | ||
| GQueue<T>::GQueue(const T &element404) { | ||
| queue.reset(new std::queue<T>); | ||
| this->element404 = element404; | ||
| } | ||
|
|
||
| template <class T> | ||
| void GQueue<T>::push(const T &element) { | ||
| const std::lock_guard<std::mutex> lock(GQueueMutex); | ||
| queue->push(element); | ||
| } | ||
|
|
||
| template <class T> | ||
| T GQueue<T>::popIfNotEmpty() { | ||
| const std::lock_guard<std::mutex> lock(GQueueMutex); | ||
| T answer = this->element404; | ||
| if (!queue->empty()) { | ||
| answer = queue->front(); | ||
| queue->pop(); | ||
| } | ||
| return answer; | ||
| } | ||
|
|
||
| #endif // INCLUDE_QUEU_HPP_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,54 +1,77 @@ | ||
| /* | ||
| * Copyright 2019 <Copyright Alex> | ||
| */ | ||
| #include <string> | ||
| #include <utility> | ||
| #include <vector> | ||
| #include <map> | ||
| //#include "sqlite-autoconf-3300100/sqlite3.h" | ||
| #include "gmock/gmock.h" | ||
| #include "gtest/gtest.h" | ||
| #include "queue.hpp" | ||
| #include "algorithm.hpp" | ||
| #include <thread> | ||
| #include "Data.hpp" | ||
| #include <fstream> | ||
|
|
||
| #ifndef INCLUDE_WORKER_HPP_ | ||
| #define INCLUDE_WORKER_HPP_ | ||
|
|
||
| #include <vector> | ||
| #include <list> | ||
| #include <string> | ||
| #include <sstream> | ||
| #include <boost/beast.hpp> | ||
| #include <boost/asio/connect.hpp> | ||
| #include <boost/asio/ip/tcp.hpp> | ||
| #include <boost/property_tree/json_parser.hpp> | ||
| #include <boost/property_tree/ptree.hpp> | ||
|
|
||
|
|
||
| struct Point | ||
| struct Limit | ||
| { | ||
| double X; | ||
| double Y; | ||
| double Point[4]; | ||
| int Number_of_dots; | ||
| int Time; | ||
| }; | ||
|
|
||
| namespace http = boost::beast::http; | ||
|
|
||
| class Worker { | ||
|
|
||
| public: // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! PRIVATE AFTER TESTS !!!!!!!!!!!!!!!!!!!!!! | ||
|
|
||
| // this typedef get from Algorithm before merge we don't know about Algo | ||
| typedef std::size_t dotId; | ||
| typedef std::pair<dotId, dotId> edge; | ||
| typedef std::size_t weight; | ||
|
|
||
| // храним в этих векторах данные, которые получим из API | ||
| std::vector<edge> edges; | ||
| std::vector<weight> weightArr; | ||
| struct Line { | ||
| int id; | ||
| std::string Name; | ||
| double x; | ||
| double y; | ||
| std::vector<std::string>Tags; | ||
| Line(int ID, std::string n, double X, double Y, std::vector<std::string>T): id(ID), Name(std::move(n)), x(X), y(Y), Tags(std::move(T)){}; | ||
| Line(): id(0), Name("name"), x(0), y(0), Tags({}){}; | ||
| }; | ||
|
|
||
| const size_t MAX_POINT_COUNT = 500; | ||
| const size_t MIN_POINT_COUNT = 3; | ||
| class Table { | ||
| public: | ||
| std::ifstream file; | ||
| std::vector<Line> table; | ||
| public: | ||
| void SelectTag(std::vector<std::string> values, std::vector<Point>& res); | ||
| void SelectAll(std::vector<Point>& res); | ||
| Table(std::string filename); | ||
| virtual ~Table(); | ||
| }; | ||
|
|
||
| class Worker | ||
| { | ||
| private: | ||
| DataIn request; | ||
| Table DB; | ||
| GQueue<DataIn> &In; | ||
| GQueue<DataOut> &Out; | ||
| bool Stop; | ||
| std::vector<std::pair<size_t,size_t>> edges; // вектор из 2 точек | ||
| std::vector<size_t> weightArr; // вес ребра | ||
| std::thread WProces; | ||
| DataIn GetFromQueueIn(); | ||
| void SendToQueueOut(const DataOut &value); | ||
| void GetDotsFromDB(const DataIn &value, std::vector<Point> &points); | ||
| void GetRibsFromAPI(const std::vector<Point> &points); | ||
| void getWeightFromPythonAPI(const std::string &jsonPoints, std::string &answer); | ||
| std::string createJsonForSending(const std::vector<Point> &points); | ||
| void setJsonAnswerInClass(const std::string &answer, const size_t &pointCount); | ||
|
|
||
| void GetRoutefromAlgorithm(const std::vector<Algorithm::edge> edge, const std::vector<size_t> weight, | ||
| std::pair<std::vector<Algorithm::dotId >, size_t> &res, size_t num_dots, DataIn value); | ||
| void FinalPoints(std::vector<Point> &points, const std::pair<std::vector<Algorithm::dotId >, size_t> &res); | ||
| void WorkerProcess(); | ||
| public: | ||
|
|
||
| static long int getWeightIndex(const size_t &pointsCount, const size_t &from, const size_t &to); | ||
|
|
||
| Worker(GQueue<DataIn> &in, GQueue<DataOut> &out, std::string DBName); | ||
| ~Worker(); | ||
| void GetRest(int timeToSleep); | ||
| void Kill(); | ||
| FRIEND_TEST(Get, Get_from_queu); | ||
| FRIEND_TEST(Send, Send_to_queu); | ||
| FRIEND_TEST(Get_dots, Get_dots_from_DB); | ||
| FRIEND_TEST(Get_dots2, Get_dots_from_DB2); | ||
| FRIEND_TEST(Get_dots3, Get_dots_from_DB3); | ||
| FRIEND_TEST(Get_dots4, NumberOfDots); | ||
| FRIEND_TEST(Get_dots5, NumberOfDots); | ||
| }; | ||
| #endif // INCLUDE_WORKER_HPP_ | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
значения должны передаваться в функцию по значению
именовать переменный через нижнее подчеркивание - плохой стиль. Такое именование используется в системных библиотеках для приватных членов