PGROUTING  3.2
GraphDefinition.h
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 FILE: GraphDefinition.h
4 
5 
6 Copyright (c) 2012 pgRouting developers
8 
9 Copyright 2012 steve
10 ------
11 
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16 
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21 
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 
26  ********************************************************************PGR-GNU*/
27 
28 #ifndef INCLUDE_TRSP_GRAPHDEFINITION_H_
29 #define INCLUDE_TRSP_GRAPHDEFINITION_H_
30 
31 #include <stdlib.h>
32 
33 #include <vector>
34 #include <map>
35 #include <queue>
36 #include <string>
37 #include <iostream>
38 #include <utility>
39 #include <functional>
40 
41 
42 #include "c_types/trsp/trsp.h"
43 
44 // using namespace std;
45 
46 typedef std::vector<int64> LongVector;
47 typedef std::vector<LongVector> VectorOfLongVector;
48 typedef std::pair<int64, bool> PIB;
49 typedef std::pair<double, PIB> PDP;
50 typedef std::pair<double, std::vector<int64> > PDVI;
51 
52 /*
53 typedef struct edge
54 {
55  int id;
56  int source;
57  int target;
58  double cost;
59  double reverse_cost;
60 } edge_t;
61 
62 typedef struct path_element
63 {
64  int vertex_id;
65  int edge_id;
66  double cost;
67 }path_element_tt;
68 */
69 
70 typedef struct {
71  int64 ed_ind[2];
72  int64 v_pos[2];
73 } PARENT_PATH;
74 
75 typedef struct Rule {
76  double cost;
77  std::vector<int64> precedencelist;
78  Rule(double c, std::vector<int64> p) : cost(c), precedencelist(p) { }
79 }Rule;
80 
81 typedef struct {
82  double startCost, endCost;
83 } CostHolder;
84 
85 typedef std::map<int64, std::vector<Rule> > RuleTable;
86 
87 
88 
90  public:
91  int64 m_lEdgeID;
92  int64 m_lEdgeIndex;
93  int64 m_sDirection;
94  double m_dCost;
100 
102  int64 m_lEndNode;
103 };
104 
105 
106 
107 
108 typedef std::vector<GraphEdgeInfo*> GraphEdgeVector;
109 typedef std::map<int64, LongVector> Long2LongVectorMap;
110 typedef std::map<int64, int64> Long2LongMap;
111 
112 
113 
114 
116  public:
117  GraphDefinition(void);
118  ~GraphDefinition(void);
119 
120  int my_dijkstra3(edge_t *edges, size_t edge_count,
121  int64 start_vertex, int64 end_vertex,
122  bool directed, bool has_reverse_cost,
123  path_element_tt **path, size_t *path_count,
124  char **err_msg);
125 
126  int my_dijkstra2(edge_t *edges, size_t edge_count,
127  int64 start_vertex, int64 end_vertex,
128  bool directed, bool has_reverse_cost,
129  path_element_tt **path, size_t *path_count,
130  char **err_msg,
131  std::vector<PDVI> &ruleList);
132 
133  int my_dijkstra1(edge_t *edges, size_t edge_count,
134  int64 start_edge, double start_part,
135  int64 end_edge, double end_part,
136  bool directed, bool has_reverse_cost,
137  path_element_tt **path, size_t *path_count,
138  char **err_msg,
139  std::vector<PDVI> &ruleList);
140 
141  bool construct_graph(edge_t *edges, size_t edge_count,
142  bool has_reverse_cost, bool directed);
143 
144 
145  private:
146  double construct_path(int64 ed_id, int64 v_pos);
147  void explore(int64 cur_node, GraphEdgeInfo& cur_edge, bool isStart,
148  LongVector &vecIndex, std::priority_queue<PDP,
149  std::vector<PDP>, std::greater<PDP> > &que);
150  double getRestrictionCost(int64 cur_node, GraphEdgeInfo& new_edge,
151  bool isStart);
152  bool addEdge(edge_t edgeIn);
153  bool connectEdge(GraphEdgeInfo& firstEdge, GraphEdgeInfo& secondEdge,
154  bool bIsStartNodeSame);
155  bool get_single_cost(double total_cost, path_element_tt **path,
156  size_t *path_count);
157  void init();
158  void deleteall();
159 
160  private:
164  int64 max_node_id;
165  int64 max_edge_id;
168  double m_dStartpart;
169  double m_dEndPart;
172 
173  std::vector <path_element_tt> m_vecPath;
179 };
180 
181 #endif // INCLUDE_TRSP_GRAPHDEFINITION_H_
GraphEdgeInfo::m_sDirection
int64 m_sDirection
Definition: GraphDefinition.h:93
GraphDefinition::m_mapNodeId2Edge
Long2LongVectorMap m_mapNodeId2Edge
Definition: GraphDefinition.h:163
GraphDefinition::m_vecPath
std::vector< path_element_tt > m_vecPath
Definition: GraphDefinition.h:173
Rule
struct Rule Rule
GraphEdgeInfo::m_dCost
double m_dCost
Definition: GraphDefinition.h:94
GraphDefinition::m_vecEdgeVector
GraphEdgeVector m_vecEdgeVector
Definition: GraphDefinition.h:161
GraphDefinition::addEdge
bool addEdge(edge_t edgeIn)
Definition: GraphDefinition.cpp:594
PIB
std::pair< int64, bool > PIB
Definition: GraphDefinition.h:48
GraphEdgeInfo::m_lEdgeID
int64 m_lEdgeID
Definition: GraphDefinition.h:91
GraphEdgeInfo::m_lEdgeIndex
int64 m_lEdgeIndex
Definition: GraphDefinition.h:92
GraphEdgeInfo::m_vecEndConnedtedEdge
LongVector m_vecEndConnedtedEdge
Definition: GraphDefinition.h:97
edge_t
Definition: trsp_types.h:37
GraphDefinition::m_dStartpart
double m_dStartpart
Definition: GraphDefinition.h:168
GraphDefinition::GraphDefinition
GraphDefinition(void)
Definition: GraphDefinition.cpp:39
path_element
Definition: trsp.h:56
GraphDefinition::~GraphDefinition
~GraphDefinition(void)
Definition: GraphDefinition.cpp:52
GraphEdgeInfo::m_vecStartConnectedEdge
LongVector m_vecStartConnectedEdge
Definition: GraphDefinition.h:96
GraphDefinition::m_dEndPart
double m_dEndPart
Definition: GraphDefinition.h:169
VectorOfLongVector
std::vector< LongVector > VectorOfLongVector
Definition: GraphDefinition.h:47
PDVI
std::pair< double, std::vector< int64 > > PDVI
Definition: GraphDefinition.h:50
GraphEdgeVector
std::vector< GraphEdgeInfo * > GraphEdgeVector
Definition: GraphDefinition.h:108
Rule::Rule
Rule(double c, std::vector< int64 > p)
Definition: GraphDefinition.h:78
GraphDefinition::m_bIsturnRestrictOn
bool m_bIsturnRestrictOn
Definition: GraphDefinition.h:177
GraphEdgeInfo::m_bIsLeadingRestrictedEdge
bool m_bIsLeadingRestrictedEdge
Definition: GraphDefinition.h:98
GraphDefinition::explore
void explore(int64 cur_node, GraphEdgeInfo &cur_edge, bool isStart, LongVector &vecIndex, std::priority_queue< PDP, std::vector< PDP >, std::greater< PDP > > &que)
Definition: GraphDefinition.cpp:153
GraphEdgeInfo::m_lEndNode
int64 m_lEndNode
Definition: GraphDefinition.h:102
GraphDefinition::connectEdge
bool connectEdge(GraphEdgeInfo &firstEdge, GraphEdgeInfo &secondEdge, bool bIsStartNodeSame)
Definition: GraphDefinition.cpp:561
Long2LongMap
std::map< int64, int64 > Long2LongMap
Definition: GraphDefinition.h:110
GraphDefinition::max_node_id
int64 max_node_id
Definition: GraphDefinition.h:164
GraphDefinition::parent
PARENT_PATH * parent
Definition: GraphDefinition.h:174
PDP
std::pair< double, PIB > PDP
Definition: GraphDefinition.h:49
GraphDefinition::m_dCost
CostHolder * m_dCost
Definition: GraphDefinition.h:175
GraphDefinition::m_mapEdgeId2Index
Long2LongMap m_mapEdgeId2Index
Definition: GraphDefinition.h:162
Rule::precedencelist
std::vector< int64 > precedencelist
Definition: GraphDefinition.h:77
CostHolder
Definition: GraphDefinition.h:81
GraphDefinition::m_lEndEdgeId
int64 m_lEndEdgeId
Definition: GraphDefinition.h:167
GraphDefinition::isStartVirtual
bool isStartVirtual
Definition: GraphDefinition.h:170
GraphDefinition::construct_graph
bool construct_graph(edge_t *edges, size_t edge_count, bool has_reverse_cost, bool directed)
Definition: GraphDefinition.cpp:543
GraphDefinition::construct_path
double construct_path(int64 ed_id, int64 v_pos)
Definition: GraphDefinition.cpp:79
Rule
Definition: GraphDefinition.h:75
GraphEdgeInfo::m_vecRestrictedEdge
VectorOfLongVector m_vecRestrictedEdge
Definition: GraphDefinition.h:99
GraphDefinition::deleteall
void deleteall()
Definition: GraphDefinition.cpp:66
GraphEdgeInfo::m_lStartNode
int64 m_lStartNode
Definition: GraphDefinition.h:101
RuleTable
std::map< int64, std::vector< Rule > > RuleTable
Definition: GraphDefinition.h:85
GraphDefinition::m_lStartEdgeId
int64 m_lStartEdgeId
Definition: GraphDefinition.h:166
GraphDefinition::get_single_cost
bool get_single_cost(double total_cost, path_element_tt **path, size_t *path_count)
Definition: GraphDefinition.cpp:506
GraphEdgeInfo
Definition: GraphDefinition.h:89
trsp.h
Long2LongVectorMap
std::map< int64, LongVector > Long2LongVectorMap
Definition: GraphDefinition.h:109
GraphDefinition::m_bIsGraphConstructed
bool m_bIsGraphConstructed
Definition: GraphDefinition.h:178
Rule::cost
double cost
Definition: GraphDefinition.h:76
GraphDefinition::my_dijkstra3
int my_dijkstra3(edge_t *edges, size_t edge_count, int64 start_vertex, int64 end_vertex, bool directed, bool has_reverse_cost, path_element_tt **path, size_t *path_count, char **err_msg)
Definition: GraphDefinition.cpp:368
LongVector
std::vector< int64 > LongVector
Definition: GraphDefinition.h:46
GraphDefinition::my_dijkstra1
int my_dijkstra1(edge_t *edges, size_t edge_count, int64 start_edge, double start_part, int64 end_edge, double end_part, bool directed, bool has_reverse_cost, path_element_tt **path, size_t *path_count, char **err_msg, std::vector< PDVI > &ruleList)
Definition: GraphDefinition.cpp:210
GraphDefinition::max_edge_id
int64 max_edge_id
Definition: GraphDefinition.h:165
GraphEdgeInfo::m_dReverseCost
double m_dReverseCost
Definition: GraphDefinition.h:95
GraphDefinition::isEndVirtual
bool isEndVirtual
Definition: GraphDefinition.h:171
CostHolder::startCost
double startCost
Definition: GraphDefinition.h:82
GraphDefinition::getRestrictionCost
double getRestrictionCost(int64 cur_node, GraphEdgeInfo &new_edge, bool isStart)
Definition: GraphDefinition.cpp:117
PARENT_PATH
Definition: GraphDefinition.h:70
GraphDefinition::init
void init()
Definition: GraphDefinition.cpp:57
GraphDefinition
Definition: GraphDefinition.h:115
GraphDefinition::my_dijkstra2
int my_dijkstra2(edge_t *edges, size_t edge_count, int64 start_vertex, int64 end_vertex, bool directed, bool has_reverse_cost, path_element_tt **path, size_t *path_count, char **err_msg, std::vector< PDVI > &ruleList)
Definition: GraphDefinition.cpp:307
GraphDefinition::m_ruleTable
RuleTable m_ruleTable
Definition: GraphDefinition.h:176