PGROUTING  3.2
pgr_trspHandler.h
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 FILE: pgr_trspHandler.h
4 
5 Copyright (c) 2017 pgRouting developers
7 
8 ------
9 
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 
24  ********************************************************************PGR-GNU*/
25 
26 #ifndef INCLUDE_TRSP_PGR_TRSPHANDLER_H_
27 #define INCLUDE_TRSP_PGR_TRSPHANDLER_H_
28 
29 #include <stdlib.h>
30 
31 #include <vector>
32 #include <deque>
33 #include <map>
34 #include <queue>
35 #include <string>
36 #include <iostream>
37 #include <utility>
38 #include <functional>
39 #include <limits>
40 
41 
43 #include "trsp/edgeInfo.h"
44 #include "cpp_common/rule.h"
45 
46 namespace pgrouting {
47 namespace trsp {
48 
49 
50 
51 
56  typedef std::pair<double, std::pair<int64_t, bool>> PDP;
57 
68  enum Position {ILLEGAL = -1, RC_EDGE = 0, C_EDGE = 1};
69 
70 
71  class Predecessor {
72  public:
74  e_idx(2),
75  v_pos(2) {
76  for (auto &p : v_pos) p = ILLEGAL;
77  }
78 
79  bool isIllegal(size_t i) {return v_pos[i] == ILLEGAL;}
80  bool isIllegal(Position i) {
81  pgassert(i != ILLEGAL);
82  if (i == ILLEGAL) return true;
83  return v_pos[static_cast<size_t>(i)] == ILLEGAL;}
84 
85  std::vector<size_t> e_idx;
86  std::vector<Position> v_pos;
87  };
88 
89 
90  class CostHolder {
91  public:
93  endCost = startCost = (std::numeric_limits<double>::max)();
94  }
95 
96  public:
97  double startCost;
98  double endCost;
99  };
100 
101 
102  public:
104  pgr_edge_t *edges,
105  const size_t edge_count,
106  const bool directed,
107  const std::vector<Rule> &ruleList);
108 
109  Pgr_trspHandler(void) = delete;
110  ~Pgr_trspHandler(void) = default;
111 
112 
113  Path process(
114  const int64_t start_vertex,
115  const int64_t end_vertex);
116 
117  std::deque<Path> process(
118  const std::vector<int64_t> sources,
119  const std::vector<int64_t> targets);
120 
121 
122  void clear();
123 
124  private:
125  void construct_graph(
126  pgr_edge_t *edges,
127  const size_t edge_count,
128  const bool directed);
129 
131  const std::vector<Rule> &ruleList);
132 
133  void initialize_que();
134 
136  size_t edge_count);
137 
139 
140 
141 
142  void explore(
143  int64_t cur_node,
144  const EdgeInfo cur_edge,
145  bool isStart);
146 
147  double getRestrictionCost(
148  int64_t cur_node,
149  const EdgeInfo &new_edge,
150  bool isStart);
151  bool addEdge(const pgr_edge_t edgeIn);
152 
153  void connectStartEdge(
154  size_t firstEdge_idx,
155  size_t secondEdge_idx);
156 
157  void connectEndEdge(
158  size_t firstEdge_idx,
159  size_t secondEdge_idx);
160 
161  double construct_path(int64_t ed_id, Position pos);
162 
163 
164  int64_t renumber_edges(
165  pgr_edge_t *edges,
166  const size_t edge_count) const;
167 
168  void add_to_que(
169  double cost,
170  size_t e_idx,
171  bool isStart);
172 
173  double get_tot_cost(
174  double cost,
175  size_t edge_idx,
176  bool isStart);
177 
178  private:
179  std::vector<EdgeInfo> m_edges;
180 
185  std::map<int64_t, int64_t> m_mapEdgeId2Index;
186 
190  std::map<int64_t, std::vector<size_t>> m_adjacency;
191 
192 
193  int64_t m_start_vertex;
194  int64_t m_end_vertex;
195 
196  /*
197  * Used in dijkstra_exploration
198  */
199  int64_t current_node;
200 
201  int64_t m_min_id;
202 
204 
205  std::vector<Predecessor> m_parent;
206  std::vector<CostHolder> m_dCost;
207 
208  std::map<int64_t, std::vector<Rule>> m_ruleTable;
209 
210  /*
211  * priority queue
212  */
213  std::priority_queue<PDP, std::vector<PDP>, std::greater<PDP> > que;
214 };
215 
216 
217 } // namespace trsp
218 } // namespace pgrouting
219 
220 #endif // INCLUDE_TRSP_PGR_TRSPHANDLER_H_
pgrouting::trsp::Pgr_trspHandler::renumber_edges
int64_t renumber_edges(pgr_edge_t *edges, const size_t edge_count) const
Definition: pgr_trspHandler.cpp:62
pgrouting::trsp::Pgr_trspHandler::CostHolder::CostHolder
CostHolder()
Definition: pgr_trspHandler.h:92
Path
Definition: basePath_SSEC.hpp:47
pgrouting::trsp::Pgr_trspHandler::m_start_vertex
int64_t m_start_vertex
Definition: pgr_trspHandler.h:193
pgrouting::trsp::Pgr_trspHandler::ILLEGAL
@ ILLEGAL
Definition: pgr_trspHandler.h:68
pgrouting::trsp::Pgr_trspHandler
Definition: pgr_trspHandler.h:52
pgrouting::trsp::Pgr_trspHandler::C_EDGE
@ C_EDGE
Definition: pgr_trspHandler.h:68
pgrouting::trsp::Pgr_trspHandler::initialize_que
void initialize_que()
Definition: pgr_trspHandler.cpp:329
pgr_edge_t
Definition: pgr_edge_t.h:37
pgrouting::trsp::Pgr_trspHandler::dijkstra_exploration
EdgeInfo dijkstra_exploration()
Definition: pgr_trspHandler.cpp:353
pgrouting::trsp::Pgr_trspHandler::process
Path process(const int64_t start_vertex, const int64_t end_vertex)
process
Definition: pgr_trspHandler.cpp:259
pgrouting::trsp::Pgr_trspHandler::Predecessor
Definition: pgr_trspHandler.h:71
pgrouting::trsp::Pgr_trspHandler::Predecessor::v_pos
std::vector< Position > v_pos
Definition: pgr_trspHandler.h:86
pgrouting::trsp::Pgr_trspHandler::explore
void explore(int64_t cur_node, const EdgeInfo cur_edge, bool isStart)
Definition: pgr_trspHandler.cpp:186
pgrouting::trsp::Pgr_trspHandler::m_dCost
std::vector< CostHolder > m_dCost
Definition: pgr_trspHandler.h:206
pgrouting::trsp::EdgeInfo
Definition: edgeInfo.h:39
pgrouting::trsp::Pgr_trspHandler::m_ruleTable
std::map< int64_t, std::vector< Rule > > m_ruleTable
Definition: pgr_trspHandler.h:208
pgrouting::trsp::Pgr_trspHandler::construct_graph
void construct_graph(pgr_edge_t *edges, const size_t edge_count, const bool directed)
Definition: pgr_trspHandler.cpp:435
pgrouting::trsp::Pgr_trspHandler::Predecessor::isIllegal
bool isIllegal(Position i)
Definition: pgr_trspHandler.h:80
pgrouting::trsp::Pgr_trspHandler::~Pgr_trspHandler
~Pgr_trspHandler(void)=default
pgrouting::trsp::Pgr_trspHandler::CostHolder
Definition: pgr_trspHandler.h:90
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
pgrouting::trsp::Pgr_trspHandler::m_end_vertex
int64_t m_end_vertex
Definition: pgr_trspHandler.h:194
pgrouting::trsp::Pgr_trspHandler::m_adjacency
std::map< int64_t, std::vector< size_t > > m_adjacency
m_adjacency[vertex] = {edges}
Definition: pgr_trspHandler.h:190
pgrouting::trsp::Pgr_trspHandler::Predecessor::Predecessor
Predecessor()
Definition: pgr_trspHandler.h:73
pgrouting::trsp::Pgr_trspHandler::Predecessor::isIllegal
bool isIllegal(size_t i)
Definition: pgr_trspHandler.h:79
pgrouting::trsp::Pgr_trspHandler::add_to_que
void add_to_que(double cost, size_t e_idx, bool isStart)
Definition: pgr_trspHandler.cpp:317
pgrouting::trsp::Pgr_trspHandler::Position
Position
predecesor edge
Definition: pgr_trspHandler.h:68
edgeInfo.h
pgrouting::trsp::Pgr_trspHandler::RC_EDGE
@ RC_EDGE
Definition: pgr_trspHandler.h:68
pgrouting::trsp::Pgr_trspHandler::Predecessor::e_idx
std::vector< size_t > e_idx
Definition: pgr_trspHandler.h:85
pgrouting::trsp::Pgr_trspHandler::m_mapEdgeId2Index
std::map< int64_t, int64_t > m_mapEdgeId2Index
Used only to veryfy that there are no reppetitions inserted the way it orks, repeating edges id is no...
Definition: pgr_trspHandler.h:185
pgrouting::trsp::Pgr_trspHandler::CostHolder::endCost
double endCost
Definition: pgr_trspHandler.h:98
pgrouting::trsp::Pgr_trspHandler::addEdge
bool addEdge(const pgr_edge_t edgeIn)
Definition: pgr_trspHandler.cpp:508
rule.h
pgrouting::trsp::Pgr_trspHandler::process_trsp
Path process_trsp(size_t edge_count)
Definition: pgr_trspHandler.cpp:389
pgrouting::trsp::Pgr_trspHandler::m_path
Path m_path
Definition: pgr_trspHandler.h:203
pgrouting::trsp::Pgr_trspHandler::m_min_id
int64_t m_min_id
Definition: pgr_trspHandler.h:201
pgrouting::trsp::Pgr_trspHandler::m_edges
std::vector< EdgeInfo > m_edges
Definition: pgr_trspHandler.h:179
pgrouting::trsp::Pgr_trspHandler::get_tot_cost
double get_tot_cost(double cost, size_t edge_idx, bool isStart)
Definition: pgr_trspHandler.cpp:172
pgrouting::trsp::Pgr_trspHandler::CostHolder::startCost
double startCost
Definition: pgr_trspHandler.h:97
pgrouting::trsp::Pgr_trspHandler::clear
void clear()
Definition: pgr_trspHandler.cpp:87
pgrouting::trsp::Pgr_trspHandler::connectStartEdge
void connectStartEdge(size_t firstEdge_idx, size_t secondEdge_idx)
Definition: pgr_trspHandler.cpp:462
pgrouting::trsp::Pgr_trspHandler::Pgr_trspHandler
Pgr_trspHandler(void)=delete
pgrouting::trsp::Pgr_trspHandler::initialize_restrictions
int initialize_restrictions(const std::vector< Rule > &ruleList)
Definition: pgr_trspHandler.cpp:237
pgrouting::trsp::Pgr_trspHandler::m_parent
std::vector< Predecessor > m_parent
Definition: pgr_trspHandler.h:205
pgrouting::trsp::Pgr_trspHandler::PDP
std::pair< double, std::pair< int64_t, bool > > PDP
Used in the priority queue.
Definition: pgr_trspHandler.h:56
pgrouting::trsp::Pgr_trspHandler::getRestrictionCost
double getRestrictionCost(int64_t cur_node, const EdgeInfo &new_edge, bool isStart)
Definition: pgr_trspHandler.cpp:139
pgrouting::trsp::Pgr_trspHandler::connectEndEdge
void connectEndEdge(size_t firstEdge_idx, size_t secondEdge_idx)
Definition: pgr_trspHandler.cpp:485
pgrouting::trsp::Pgr_trspHandler::que
std::priority_queue< PDP, std::vector< PDP >, std::greater< PDP > > que
Definition: pgr_trspHandler.h:213
pgrouting
Book keeping class for swapping orders between vehicles.
Definition: pgr_alphaShape.cpp:56
pgrouting::trsp::Pgr_trspHandler::current_node
int64_t current_node
Definition: pgr_trspHandler.h:199
basePath_SSEC.hpp
pgrouting::trsp::Pgr_trspHandler::construct_path
double construct_path(int64_t ed_id, Position pos)
Definition: pgr_trspHandler.cpp:95