1 #include "mm/composite_graph.hpp"
2 #include "util/debug.hpp"
9 DummyGraph::DummyGraph(){}
12 if (traj_candidates.empty())
return;
13 int N = traj_candidates.size();
14 std::unordered_map<EdgeIndex,const Candidate*> ca;
15 std::unordered_map<EdgeIndex,const Candidate*> cb;
16 std::unordered_map<EdgeIndex,const Candidate*> *prev_cmap = &ca;
17 std::unordered_map<EdgeIndex,const Candidate*> *cur_cmap = &cb;
18 for (
int i=0; i<N; ++i) {
22 add_edge(c.edge->source, n, c.edge->index, c.offset);
23 add_edge(n,c.edge->target, c.edge->index, c.edge->length - c.offset);
24 cur_cmap->insert(std::make_pair(c.edge->index,&c));
25 auto iter = prev_cmap->find(c.edge->index);
26 if (iter!=prev_cmap->end()) {
27 if (iter->second->offset <= c.offset) {
28 add_edge(iter->second->index,
29 n, c.edge->index, c.offset-iter->second->offset);
33 std::unordered_map<EdgeIndex,const Candidate*> *temp = prev_cmap;
44 const Graph_T &DummyGraph::get_boost_graph()
const {
48 int DummyGraph::get_num_vertices()
const {
49 return boost::num_vertices(g);
52 bool DummyGraph::containNodeIndex(
NodeIndex external_index)
const {
53 return internal_index_map.find(external_index)!=internal_index_map.end();
57 return external_index_vec[inner_index];
61 return internal_index_map.at(external_index);
66 SPDLOG_TRACE(
"Dummy graph get edge index {} {} cost {}",source,target,cost);
69 NodeIndex source_idx = get_internal_index(source);
70 NodeIndex target_idx = get_internal_index(target);
71 for (boost::tie(out_i, out_end) = boost::out_edges(source_idx,g);
72 out_i != out_end; ++out_i) {
74 SPDLOG_TRACE(
"Target index {} {} id {} e length {} {}",
75 target_idx, boost::target(e,g),
78 std::abs(g[e].length - cost));
79 if (target_idx == boost::target(e,g) &&
80 (std::abs(g[e].length - cost) <= DOUBLE_MIN)) {
87 void DummyGraph::print_node_index_map()
const {
88 std::cout<<
"Inner index map\n";
89 for (
auto const& pair:internal_index_map) {
90 std::cout <<
"{" << pair.first <<
": " << pair.second <<
"}\n";
98 auto search1 = internal_index_map.find(source);
99 auto search2 = internal_index_map.find(target);
101 if (search1!=internal_index_map.end()) {
102 source_idx = search1->second;
104 source_idx = external_index_vec.size();
105 external_index_vec.push_back(source);
106 internal_index_map.insert({source,source_idx});
108 if (search2!=internal_index_map.end()) {
109 target_idx = search2->second;
111 target_idx = external_index_vec.size();
112 external_index_vec.push_back(target);
113 internal_index_map.insert({target,target_idx});
117 boost::tie(e, inserted) = boost::add_edge(source_idx,target_idx,g);
119 g[e].index = edge_index;
134 if (u >= num_vertices || v >= num_vertices) {
153 for (boost::tie(out_i, out_end) = boost::out_edges(u_internal,dg);
154 out_i != out_end; ++out_i) {
156 NodeIndex v_internal = boost::target(e, dg);
161 if (u < num_vertices) {
163 for (boost::tie(out_i, out_end)=boost::out_edges(u,g);
164 out_i != out_end; ++out_i) {
175 return u>=num_vertices;