forked from valhalla/valhalla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphparser.cc
788 lines (643 loc) · 31.4 KB
/
graphparser.cc
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
#include "baldr/graphreader.h"
#include "baldr/rapidjson_utils.h"
#include "baldr/tilehierarchy.h"
#include "midgard/sequence.h"
#include "mjolnir/bssbuilder.h"
#include "mjolnir/graphbuilder.h"
#include "mjolnir/osmnode.h"
#include "mjolnir/pbfgraphparser.h"
#include "test.h"
#include <boost/property_tree/ptree.hpp>
#include <cstdint>
#include <filesystem>
#include <fstream>
#include "baldr/directededge.h"
#include "baldr/graphconstants.h"
#if !defined(VALHALLA_SOURCE_DIR)
#define VALHALLA_SOURCE_DIR
#endif
using namespace valhalla::midgard;
using namespace valhalla::mjolnir;
using namespace valhalla::baldr;
namespace {
const std::string config_file = "test/test_config_gp";
std::string ways_file = "test_ways.bin";
std::string way_nodes_file = "test_way_nodes.bin";
std::string nodes_file = "test_nodes.bin";
std::string edges_file = "test_edges.bin";
std::string access_file = "test_access.bin";
std::string from_restriction_file = "test_from_complex_restrictions.bin";
std::string to_restriction_file = "test_to_complex_restrictions.bin";
std::string bss_nodes_file = "test_bss_nodes.bin";
std::string linguistic_node_file = "test_linguistic_node.bin";
const auto node_predicate = [](const OSMWayNode& a, const OSMWayNode& b) {
return a.node.osmid_ < b.node.osmid_;
};
OSMNode GetNode(uint64_t node_id, sequence<OSMWayNode>& way_nodes) {
auto found = way_nodes.find({node_id}, node_predicate);
if (found == way_nodes.end())
throw std::runtime_error("Couldn't find node: " + std::to_string(node_id));
return (*found).node;
}
auto way_predicate = [](const OSMWay& a, const OSMWay& b) { return a.osmwayid_ < b.osmwayid_; };
OSMWay GetWay(uint32_t way_id, sequence<OSMWay>& ways) {
auto found = ways.find({way_id}, way_predicate);
if (found == ways.end())
throw std::runtime_error("Couldn't find way: " + std::to_string(way_id));
return *found;
}
void DoConfig() {
std::ofstream file;
try {
file.open(config_file, std::ios_base::trunc);
file << "{ \
\"mjolnir\": { \
\"id_table_size\": 1000, \
\"tile_dir\": \"test/data/parser_tiles\" \
} \
}";
} catch (...) {}
file.close();
}
// must do clean up here vs TearDown() as we are building data
// in the same directory multiple times
void CleanUp() {
if (std::filesystem::exists(ways_file))
std::filesystem::remove(ways_file);
if (std::filesystem::exists(way_nodes_file))
std::filesystem::remove(way_nodes_file);
if (std::filesystem::exists(nodes_file))
std::filesystem::remove(nodes_file);
if (std::filesystem::exists(edges_file))
std::filesystem::remove(edges_file);
if (std::filesystem::exists(access_file))
std::filesystem::remove(access_file);
if (std::filesystem::exists(from_restriction_file))
std::filesystem::remove(from_restriction_file);
if (std::filesystem::exists(to_restriction_file))
std::filesystem::remove(to_restriction_file);
if (std::filesystem::exists(bss_nodes_file))
std::filesystem::remove(bss_nodes_file);
if (std::filesystem::exists(linguistic_node_file))
std::filesystem::remove(linguistic_node_file);
}
void BollardsGatesAndAccess(const std::string& config_file) {
boost::property_tree::ptree conf;
rapidjson::read_json(config_file, conf);
auto osmdata =
PBFGraphParser::ParseWays(conf.get_child("mjolnir"),
{VALHALLA_SOURCE_DIR "test/data/liechtenstein-latest.osm.pbf"},
ways_file, way_nodes_file, access_file);
PBFGraphParser::ParseRelations(conf.get_child("mjolnir"),
{VALHALLA_SOURCE_DIR "test/data/liechtenstein-latest.osm.pbf"},
from_restriction_file, to_restriction_file, osmdata);
PBFGraphParser::ParseNodes(conf.get_child("mjolnir"),
{VALHALLA_SOURCE_DIR "test/data/liechtenstein-latest.osm.pbf"},
way_nodes_file, bss_nodes_file, linguistic_node_file, osmdata);
sequence<OSMWayNode> way_nodes(way_nodes_file, false);
way_nodes.sort(node_predicate);
sequence<OSMWay> ways(ways_file, false);
ways.sort(way_predicate);
// bus access tests.
auto way_85744121 = GetWay(85744121, ways);
EXPECT_FALSE(way_85744121.auto_forward());
EXPECT_FALSE(way_85744121.moped_forward());
EXPECT_TRUE(way_85744121.bike_forward());
EXPECT_TRUE(way_85744121.bus_forward());
EXPECT_TRUE(way_85744121.pedestrian_forward());
EXPECT_TRUE(way_85744121.pedestrian_backward());
EXPECT_FALSE(way_85744121.auto_backward());
EXPECT_FALSE(way_85744121.moped_backward());
EXPECT_FALSE(way_85744121.bike_backward());
EXPECT_FALSE(way_85744121.bus_backward());
auto way_86260080 = GetWay(86260080, ways);
EXPECT_TRUE(way_86260080.auto_forward());
EXPECT_TRUE(way_86260080.bike_forward());
EXPECT_TRUE(way_86260080.bus_forward());
EXPECT_TRUE(way_86260080.moped_forward());
EXPECT_TRUE(way_86260080.pedestrian_forward());
EXPECT_TRUE(way_86260080.pedestrian_backward());
EXPECT_TRUE(way_86260080.auto_backward());
EXPECT_TRUE(way_86260080.bike_backward());
EXPECT_TRUE(way_86260080.bus_backward());
EXPECT_TRUE(way_86260080.moped_backward());
auto way_161683833 = GetWay(161683833, ways);
EXPECT_TRUE(way_161683833.auto_forward());
EXPECT_TRUE(way_161683833.bike_forward());
EXPECT_TRUE(way_161683833.bus_forward());
EXPECT_TRUE(way_161683833.moped_forward());
EXPECT_TRUE(way_161683833.pedestrian_forward());
EXPECT_TRUE(way_161683833.pedestrian_backward());
EXPECT_TRUE(way_161683833.auto_backward());
EXPECT_TRUE(way_161683833.bike_backward());
EXPECT_TRUE(way_161683833.bus_backward());
EXPECT_TRUE(way_161683833.moped_backward());
// We split set the uses at bollards and gates.
auto node = GetNode(392700757, way_nodes);
EXPECT_TRUE(node.intersection()) << "Bollard not marked as intersection.";
// We split set the uses at bollards and gates.
node = GetNode(376947468, way_nodes);
EXPECT_TRUE(node.intersection()) << "Gate not marked as intersection.";
// Is a gate with foot and bike flags set; however, access is private.
// Gate at the end of way
node = GetNode(2949666866, way_nodes);
EXPECT_TRUE(node.intersection());
EXPECT_EQ(node.type(), NodeType::kGate);
EXPECT_EQ(node.access(), (kAutoAccess | kHOVAccess | kTaxiAccess | kTruckAccess | kBusAccess |
kEmergencyAccess | kPedestrianAccess | kWheelchairAccess |
kBicycleAccess | kMopedAccess | kMotorcycleAccess));
// block
node = GetNode(1819036441, way_nodes);
EXPECT_TRUE(node.intersection());
EXPECT_EQ(node.type(), NodeType::kBollard);
EXPECT_EQ(node.access(), kPedestrianAccess | kWheelchairAccess | kBicycleAccess);
// border control
node = GetNode(3256854624, way_nodes);
EXPECT_TRUE(node.intersection());
EXPECT_EQ(node.type(), NodeType::kBorderControl);
EXPECT_EQ(node.access(), kAutoAccess | kHOVAccess | kTaxiAccess | kTruckAccess | kBusAccess |
kEmergencyAccess | kPedestrianAccess | kWheelchairAccess |
kBicycleAccess | kMopedAccess | kMotorcycleAccess);
// has bike tag but all should have access
// Bike access only test
node = GetNode(696222071, way_nodes);
EXPECT_TRUE(node.intersection());
EXPECT_EQ(node.access(), kAutoAccess | kHOVAccess | kTaxiAccess | kTruckAccess | kBusAccess |
kEmergencyAccess | kPedestrianAccess | kWheelchairAccess |
kBicycleAccess | kMopedAccess | kMotorcycleAccess);
// Is a bollard with no flags set.
node = GetNode(569645326, way_nodes);
EXPECT_TRUE(node.intersection());
EXPECT_EQ(node.type(), NodeType::kBollard);
EXPECT_EQ(node.access(), kPedestrianAccess | kWheelchairAccess | kBicycleAccess);
// Is a bollard=block with foot flag set.
node = GetNode(1819036441, way_nodes);
EXPECT_TRUE(node.intersection());
EXPECT_EQ(node.type(), NodeType::kBollard);
EXPECT_EQ(node.access(), kPedestrianAccess | kWheelchairAccess | kBicycleAccess);
auto bike = osmdata.bike_relations.equal_range(25452580);
auto way_25452580 = GetWay(25452580, ways);
uint32_t bike_network = 0;
for (auto b = bike.first; b != bike.second; ++b)
bike_network |= b->second.bike_network;
EXPECT_EQ(bike_network, kRcn) << "rcn not marked on way 25452580.";
EXPECT_EQ(way_25452580.bike_network(), 0) << "rcn not marked on way 25452580.";
auto way_74584853 = GetWay(74584853, ways);
bike_network = 0;
bike = osmdata.bike_relations.equal_range(74584853);
for (auto b = bike.first; b != bike.second; ++b)
// mountain bike networks have local, regional, and national networks set too.
if (b->second.bike_network & kMcn)
bike_network |= kMcn;
else
bike_network |= b->second.bike_network;
EXPECT_TRUE((bike_network & kMcn) && (bike_network & kLcn) && way_74584853.bike_network() == 0)
<< "lcn and mtb not marked on way 74584853.";
auto way_75786176 = GetWay(75786176, ways);
bike_network = 0;
bike = osmdata.bike_relations.equal_range(75786176);
for (auto b = bike.first; b != bike.second; ++b) {
// mountain bike networks have local, regional, and national networks set too.
if (b->second.bike_network & kMcn)
bike_network |= kMcn;
else
bike_network |= b->second.bike_network;
}
EXPECT_TRUE((bike_network & kMcn) && (bike_network & kRcn) && way_75786176.bike_network() == 0)
<< "rcn and mtb not marked on way 75786176.";
CleanUp();
}
void RemovableBollards(const std::string& config_file) {
boost::property_tree::ptree conf;
rapidjson::read_json(config_file, conf);
auto osmdata = PBFGraphParser::ParseWays(conf.get_child("mjolnir"),
{VALHALLA_SOURCE_DIR "test/data/rome.osm.pbf"}, ways_file,
way_nodes_file, access_file);
PBFGraphParser::ParseRelations(conf.get_child("mjolnir"),
{VALHALLA_SOURCE_DIR "test/data/rome.osm.pbf"},
from_restriction_file, to_restriction_file, osmdata);
PBFGraphParser::ParseNodes(conf.get_child("mjolnir"),
{VALHALLA_SOURCE_DIR "test/data/rome.osm.pbf"}, way_nodes_file,
bss_nodes_file, linguistic_node_file, osmdata);
sequence<OSMWayNode> way_nodes(way_nodes_file, false);
way_nodes.sort(node_predicate);
// Is a bollard=rising is saved as a gate...with foot flag and bike set.
auto node = GetNode(2425784125, way_nodes);
EXPECT_TRUE(node.intersection()) << "Rising Bollard not marked as intersection.";
EXPECT_EQ(node.type(), NodeType::kGate);
EXPECT_EQ(node.access(), kAutoAccess | kHOVAccess | kTaxiAccess | kTruckAccess | kBusAccess |
kEmergencyAccess | kPedestrianAccess | kWheelchairAccess |
kBicycleAccess | kMopedAccess | kMotorcycleAccess);
CleanUp();
}
void Exits(const std::string& config_file) {
boost::property_tree::ptree conf;
rapidjson::read_json(config_file, conf);
auto osmdata = PBFGraphParser::ParseWays(conf.get_child("mjolnir"),
{VALHALLA_SOURCE_DIR "test/data/harrisburg.osm.pbf"},
ways_file, way_nodes_file, access_file);
PBFGraphParser::ParseRelations(conf.get_child("mjolnir"),
{VALHALLA_SOURCE_DIR "test/data/harrisburg.osm.pbf"},
from_restriction_file, to_restriction_file, osmdata);
PBFGraphParser::ParseNodes(conf.get_child("mjolnir"),
{VALHALLA_SOURCE_DIR "test/data/harrisburg.osm.pbf"}, way_nodes_file,
bss_nodes_file, linguistic_node_file, osmdata);
sequence<OSMWayNode> way_nodes(way_nodes_file, false);
way_nodes.sort(node_predicate);
auto node = GetNode(33698177, way_nodes);
EXPECT_TRUE(node.intersection());
EXPECT_TRUE(node.has_ref());
EXPECT_EQ(osmdata.node_names.name(node.ref_index()), "51A-B") << "Ref not set correctly .";
node = GetNode(1901353894, way_nodes);
EXPECT_TRUE(node.intersection());
EXPECT_TRUE(node.has_ref());
EXPECT_EQ(osmdata.node_names.name(node.name_index()), "Harrisburg East")
<< "node name not set correctly .";
node = GetNode(462240654, way_nodes);
EXPECT_TRUE(node.intersection());
EXPECT_EQ(osmdata.node_names.name(node.exit_to_index()), "PA441")
<< "node exit_to not set correctly .";
CleanUp();
}
void Baltimore(const std::string& config_file) {
boost::property_tree::ptree conf;
rapidjson::read_json(config_file, conf);
auto osmdata = PBFGraphParser::ParseWays(conf.get_child("mjolnir"),
{VALHALLA_SOURCE_DIR "test/data/baltimore.osm.pbf"},
ways_file, way_nodes_file, access_file);
PBFGraphParser::ParseRelations(conf.get_child("mjolnir"),
{VALHALLA_SOURCE_DIR "test/data/baltimore.osm.pbf"},
from_restriction_file, to_restriction_file, osmdata);
PBFGraphParser::ParseNodes(conf.get_child("mjolnir"),
{VALHALLA_SOURCE_DIR "test/data/baltimore.osm.pbf"}, way_nodes_file,
bss_nodes_file, linguistic_node_file, osmdata);
sequence<OSMWay> ways(ways_file, false);
ways.sort(way_predicate);
// bike_forward and reverse is set to false by default. Meaning defaults for
// highway = pedestrian. Bike overrides bicycle=designated and/or cycleway=shared_lane
// make it bike_forward and reverse = true
auto way_216240466 = GetWay(216240466, ways);
EXPECT_FALSE(way_216240466.auto_forward());
EXPECT_FALSE(way_216240466.bus_forward());
EXPECT_FALSE(way_216240466.moped_forward());
EXPECT_TRUE(way_216240466.bike_forward());
EXPECT_TRUE(way_216240466.pedestrian_forward());
EXPECT_TRUE(way_216240466.pedestrian_backward());
EXPECT_FALSE(way_216240466.auto_backward());
EXPECT_FALSE(way_216240466.bus_backward());
EXPECT_FALSE(way_216240466.moped_backward());
EXPECT_TRUE(way_216240466.bike_backward());
// access for all
auto way_138388359 = GetWay(138388359, ways);
EXPECT_TRUE(way_138388359.auto_forward());
EXPECT_TRUE(way_138388359.bus_forward());
EXPECT_TRUE(way_138388359.moped_forward());
EXPECT_TRUE(way_138388359.bike_forward());
EXPECT_TRUE(way_138388359.pedestrian_forward());
EXPECT_TRUE(way_138388359.pedestrian_backward());
EXPECT_TRUE(way_138388359.auto_backward());
EXPECT_TRUE(way_138388359.bus_backward());
EXPECT_TRUE(way_138388359.moped_backward());
EXPECT_TRUE(way_138388359.bike_backward());
// footway...pedestrian only
auto way_133689121 = GetWay(133689121, ways);
EXPECT_FALSE(way_133689121.auto_forward());
EXPECT_FALSE(way_133689121.bus_forward());
EXPECT_FALSE(way_133689121.moped_forward());
EXPECT_FALSE(way_133689121.bike_forward());
EXPECT_TRUE(way_133689121.pedestrian_forward());
EXPECT_TRUE(way_133689121.pedestrian_backward());
EXPECT_FALSE(way_133689121.auto_backward());
EXPECT_FALSE(way_133689121.bus_backward());
EXPECT_FALSE(way_133689121.moped_backward());
EXPECT_FALSE(way_133689121.bike_backward());
// oneway
auto way_49641455 = GetWay(49641455, ways);
EXPECT_TRUE(way_49641455.auto_forward());
EXPECT_TRUE(way_49641455.bus_forward());
EXPECT_TRUE(way_49641455.moped_forward());
EXPECT_TRUE(way_49641455.bike_forward());
EXPECT_TRUE(way_49641455.pedestrian_forward());
EXPECT_TRUE(way_49641455.pedestrian_backward());
EXPECT_FALSE(way_49641455.auto_backward());
EXPECT_FALSE(way_49641455.bus_backward());
EXPECT_FALSE(way_49641455.moped_backward());
EXPECT_FALSE(way_49641455.bike_backward());
// Oneway test. Make sure auto backward is set for ways where oneway=no.
// Check Forward/Backward/Pedestrian access is set correctly for way 192573108.
auto way_192573108 = GetWay(192573108, ways);
EXPECT_TRUE(way_192573108.auto_forward());
EXPECT_TRUE(way_192573108.bus_forward());
EXPECT_TRUE(way_192573108.moped_forward());
EXPECT_TRUE(way_192573108.bike_forward());
EXPECT_TRUE(way_192573108.pedestrian_forward());
EXPECT_TRUE(way_192573108.pedestrian_backward());
EXPECT_TRUE(way_192573108.auto_backward());
EXPECT_TRUE(way_192573108.bus_backward());
EXPECT_TRUE(way_192573108.moped_backward());
EXPECT_TRUE(way_192573108.bike_backward());
sequence<OSMWayNode> way_nodes(way_nodes_file, false, true);
way_nodes.sort(node_predicate);
auto node = GetNode(49473254, way_nodes);
EXPECT_TRUE(node.intersection()) << "Toll Booth 49473254";
EXPECT_EQ(node.type(), NodeType::kTollBooth) << "Toll Booth 49473254";
auto res = osmdata.restrictions.equal_range(98040438);
ASSERT_NE(res.first, osmdata.restrictions.end()) << "Failed to find 98040438 restriction.";
for (auto r = res.first; r != res.second; ++r) {
if (r->second.to() == 6003340) {
EXPECT_EQ(r->second.via(), 2123388822) << "98040438 restriction test failed for to: 6003340";
EXPECT_EQ(r->second.type(), RestrictionType::kNoLeftTurn)
<< "98040438 restriction test failed for to: 6003340";
} else if (r->second.to() == 98040438) {
EXPECT_EQ(r->second.via(), 2123388822) << "98040438 restriction test failed for to: 98040438";
EXPECT_EQ(r->second.type(), RestrictionType::kNoUTurn)
<< "98040438 restriction test failed for to: 98040438";
} else
FAIL() << "98040438 restriction test failed.";
}
CleanUp();
}
void Bike(const std::string& config_file) {
boost::property_tree::ptree conf;
rapidjson::read_json(config_file, conf);
auto osmdata = PBFGraphParser::ParseWays(conf.get_child("mjolnir"),
{VALHALLA_SOURCE_DIR "test/data/bike.osm.pbf"}, ways_file,
way_nodes_file, access_file);
PBFGraphParser::ParseRelations(conf.get_child("mjolnir"),
{VALHALLA_SOURCE_DIR "test/data/bike.osm.pbf"},
from_restriction_file, to_restriction_file, osmdata);
PBFGraphParser::ParseNodes(conf.get_child("mjolnir"),
{VALHALLA_SOURCE_DIR "test/data/bike.osm.pbf"}, way_nodes_file,
bss_nodes_file, linguistic_node_file, osmdata);
sequence<OSMWay> ways(ways_file, false);
ways.sort(way_predicate);
// http://www.openstreetmap.org/way/6885577#map=14/51.9774/5.7718
// direction of this way for oneway is flipped. Confirmed on opencyclemap.org.
auto way_6885577 = GetWay(6885577, ways);
EXPECT_TRUE(way_6885577.auto_forward());
EXPECT_TRUE(way_6885577.bus_forward());
EXPECT_TRUE(way_6885577.moped_forward());
EXPECT_FALSE(way_6885577.bike_forward());
EXPECT_TRUE(way_6885577.pedestrian_forward());
EXPECT_TRUE(way_6885577.pedestrian_backward());
EXPECT_TRUE(way_6885577.auto_backward());
EXPECT_TRUE(way_6885577.bus_backward());
EXPECT_TRUE(way_6885577.moped_backward());
EXPECT_TRUE(way_6885577.bike_backward());
auto way_156539494 = GetWay(156539494, ways);
EXPECT_FALSE(way_156539494.auto_forward());
EXPECT_FALSE(way_156539494.bus_forward());
EXPECT_FALSE(way_156539494.moped_forward());
EXPECT_TRUE(way_156539494.bike_forward());
EXPECT_FALSE(way_156539494.pedestrian_forward());
EXPECT_FALSE(way_156539494.pedestrian_backward());
EXPECT_FALSE(way_156539494.auto_backward());
EXPECT_FALSE(way_156539494.bus_backward());
EXPECT_FALSE(way_156539494.moped_backward());
EXPECT_FALSE(way_156539494.bike_backward());
auto way_6885404 = GetWay(6885404, ways);
EXPECT_FALSE(way_6885404.auto_forward());
EXPECT_FALSE(way_6885404.bus_forward());
EXPECT_FALSE(way_6885404.moped_forward());
EXPECT_TRUE(way_6885404.bike_forward());
EXPECT_FALSE(way_6885404.pedestrian_forward());
EXPECT_FALSE(way_6885404.pedestrian_backward());
EXPECT_FALSE(way_6885404.auto_backward());
EXPECT_FALSE(way_6885404.bus_backward());
EXPECT_FALSE(way_6885404.moped_backward());
EXPECT_TRUE(way_6885404.bike_backward());
auto way_156539492 = GetWay(156539492, ways);
EXPECT_TRUE(way_156539492.auto_forward());
EXPECT_TRUE(way_156539492.bus_forward());
EXPECT_TRUE(way_156539492.moped_forward());
EXPECT_FALSE(way_156539492.bike_forward());
EXPECT_TRUE(way_156539492.pedestrian_forward());
EXPECT_TRUE(way_156539492.pedestrian_backward());
EXPECT_TRUE(way_156539492.auto_backward());
EXPECT_TRUE(way_156539492.bus_backward());
EXPECT_TRUE(way_156539492.moped_backward());
EXPECT_FALSE(way_156539492.bike_backward());
auto way_156539491 = GetWay(156539491, ways);
EXPECT_TRUE(way_156539491.auto_forward());
EXPECT_TRUE(way_156539491.bus_forward());
EXPECT_TRUE(way_156539491.moped_forward());
EXPECT_TRUE(way_156539491.bike_forward());
EXPECT_TRUE(way_156539492.pedestrian_forward());
EXPECT_TRUE(way_156539492.pedestrian_backward());
EXPECT_TRUE(way_156539491.auto_backward());
EXPECT_TRUE(way_156539491.bus_backward());
EXPECT_TRUE(way_156539491.moped_forward());
EXPECT_TRUE(way_156539491.bike_backward());
CleanUp();
}
void Bus(const std::string& config_file) {
boost::property_tree::ptree conf;
rapidjson::read_json(config_file, conf);
auto osmdata = PBFGraphParser::ParseWays(conf.get_child("mjolnir"),
{VALHALLA_SOURCE_DIR "test/data/bus.osm.pbf"}, ways_file,
way_nodes_file, access_file);
PBFGraphParser::ParseRelations(conf.get_child("mjolnir"),
{VALHALLA_SOURCE_DIR "test/data/bus.osm.pbf"}, from_restriction_file,
to_restriction_file, osmdata);
PBFGraphParser::ParseNodes(conf.get_child("mjolnir"), {VALHALLA_SOURCE_DIR "test/data/bus.osm.pbf"},
way_nodes_file, bss_nodes_file, linguistic_node_file, osmdata);
sequence<OSMWay> ways(ways_file, false);
ways.sort(way_predicate);
auto way_14327599 = GetWay(14327599, ways);
EXPECT_FALSE(way_14327599.auto_forward());
EXPECT_FALSE(way_14327599.moped_forward());
EXPECT_TRUE(way_14327599.bus_forward());
EXPECT_TRUE(way_14327599.bike_forward());
EXPECT_TRUE(way_14327599.pedestrian_forward());
EXPECT_TRUE(way_14327599.pedestrian_backward());
EXPECT_FALSE(way_14327599.auto_backward());
EXPECT_FALSE(way_14327599.moped_backward());
EXPECT_FALSE(way_14327599.bus_backward());
EXPECT_TRUE(way_14327599.bike_backward());
auto way_87358588 = GetWay(87358588, ways);
EXPECT_FALSE(way_87358588.auto_forward());
EXPECT_FALSE(way_87358588.moped_forward());
EXPECT_FALSE(way_87358588.bus_forward());
EXPECT_TRUE(way_87358588.bike_forward());
EXPECT_TRUE(way_87358588.pedestrian_forward());
EXPECT_TRUE(way_87358588.pedestrian_backward());
EXPECT_FALSE(way_87358588.auto_backward());
EXPECT_FALSE(way_87358588.moped_backward());
EXPECT_FALSE(way_87358588.bus_backward());
EXPECT_TRUE(way_87358588.bike_backward());
auto way_49771553 = GetWay(49771553, ways);
EXPECT_TRUE(way_49771553.auto_forward());
EXPECT_TRUE(way_49771553.moped_forward());
EXPECT_TRUE(way_49771553.bus_forward());
EXPECT_TRUE(way_49771553.bike_forward());
EXPECT_TRUE(way_49771553.pedestrian_forward());
EXPECT_TRUE(way_49771553.pedestrian_backward());
EXPECT_TRUE(way_49771553.auto_backward());
EXPECT_TRUE(way_49771553.moped_backward());
EXPECT_TRUE(way_49771553.bus_backward());
EXPECT_TRUE(way_49771553.bike_backward());
auto way_225895737 = GetWay(225895737, ways);
EXPECT_TRUE(way_225895737.auto_forward());
EXPECT_TRUE(way_225895737.moped_forward());
EXPECT_TRUE(way_225895737.bus_forward());
EXPECT_TRUE(way_225895737.bike_forward());
EXPECT_TRUE(way_225895737.pedestrian_forward());
EXPECT_TRUE(way_225895737.pedestrian_backward());
EXPECT_FALSE(way_225895737.auto_backward());
EXPECT_FALSE(way_225895737.moped_backward());
EXPECT_FALSE(way_225895737.bus_backward());
EXPECT_FALSE(way_225895737.bike_backward());
CleanUp();
}
void BicycleTrafficSignals(const std::string& config_file) {
boost::property_tree::ptree conf;
rapidjson::read_json(config_file, conf);
auto osmdata = PBFGraphParser::ParseWays(conf.get_child("mjolnir"),
{VALHALLA_SOURCE_DIR "test/data/nyc.osm.pbf"}, ways_file,
way_nodes_file, access_file);
PBFGraphParser::ParseRelations(conf.get_child("mjolnir"),
{VALHALLA_SOURCE_DIR "test/data/nyc.osm.pbf"}, from_restriction_file,
to_restriction_file, osmdata);
PBFGraphParser::ParseNodes(conf.get_child("mjolnir"), {VALHALLA_SOURCE_DIR "test/data/nyc.osm.pbf"},
way_nodes_file, bss_nodes_file, linguistic_node_file, osmdata);
sequence<OSMWayNode> way_nodes(way_nodes_file, false);
way_nodes.sort(node_predicate);
auto node = GetNode(42439096, way_nodes);
EXPECT_TRUE(node.intersection());
EXPECT_TRUE(node.traffic_signal());
/*
//When we support finding bike rentals, this test will need updated.
node = GetNode(3146484929, way_nodes);
EXPECT_FALSE(node.intersection())
<< "Bike rental not marked as intersection.";
//When we support finding shops that rent bikes, this test will need updated.
node = GetNode(2592264881, way_nodes);
EXPECT_FALSE(node.intersection())
<< "Bike rental at a shop not marked as intersection."
*/
CleanUp();
}
TEST(GraphParser, TestBollardsGatesAndAccess) {
// write the tiles with it
BollardsGatesAndAccess(config_file);
}
TEST(GraphParser, TestRemovableBollards) {
// write the tiles with it
RemovableBollards(config_file);
}
TEST(GraphParser, TestBicycleTrafficSignals) {
// write the tiles with it
BicycleTrafficSignals(config_file);
}
TEST(GraphParser, TestExits) {
// write the tiles with it
Exits(config_file);
}
TEST(GraphParser, TestBaltimoreArea) {
// write the tiles with it
Baltimore(config_file);
}
TEST(GraphParser, TestBike) {
// write the tiles with it
Bike(config_file);
}
TEST(GraphParser, TestBus) {
// write the tiles with it
Bus(config_file);
}
TEST(GraphParser, TestImportBssNode) {
boost::property_tree::ptree conf;
rapidjson::read_json(config_file, conf);
conf.put("mjolnir.import_bike_share_stations", true);
auto osmdata = PBFGraphParser::ParseWays(conf.get_child("mjolnir"),
{VALHALLA_SOURCE_DIR "test/data/rome.osm.pbf"}, ways_file,
way_nodes_file, access_file);
PBFGraphParser::ParseRelations(conf.get_child("mjolnir"),
{VALHALLA_SOURCE_DIR "test/data/rome.osm.pbf"},
from_restriction_file, to_restriction_file, osmdata);
PBFGraphParser::ParseNodes(conf.get_child("mjolnir"),
{VALHALLA_SOURCE_DIR "test/data/rome.osm.pbf"}, way_nodes_file,
bss_nodes_file, linguistic_node_file, osmdata);
GraphReader reader(conf.get_child("mjolnir"));
std::map<valhalla::baldr::GraphId, size_t> tiles =
GraphBuilder::BuildEdges(conf.get_child("mjolnir"), ways_file, way_nodes_file, nodes_file,
edges_file);
GraphBuilder::Build(conf, osmdata, ways_file, way_nodes_file, nodes_file, edges_file,
from_restriction_file, to_restriction_file, linguistic_node_file, tiles);
BssBuilder::Build(conf, osmdata, bss_nodes_file);
auto local_level = TileHierarchy::levels().back().level;
graph_tile_ptr local_tile = reader.GetGraphTile({759649, local_level, 0});
auto count = local_tile->header()->nodecount();
EXPECT_EQ(local_tile->node(count - 1)->type(), NodeType::kBikeShare)
<< "The added node is not bike share";
EXPECT_EQ(local_tile->node(count - 1)->edge_count(), 4)
<< "The bike share node must have 4 outbound edges";
auto check_edge_attribute = [&local_tile](const DirectedEdge* directededge, uint16_t forwardaccess,
uint16_t reverseaccess) {
EXPECT_TRUE(directededge->bss_connection())
<< "The bike share node's edges is not a bss connection";
EXPECT_TRUE(directededge->forwardaccess() & forwardaccess)
<< "The edge's forwardaccess is incorrect";
EXPECT_TRUE(directededge->reverseaccess() & reverseaccess)
<< "The edge's reverseaccess is incorrect";
EXPECT_EQ(directededge->surface(), Surface::kPavedRough) << "The edges' surface is incorrect";
EXPECT_EQ(directededge->cyclelane(), CycleLane::kNone) << "The edges' cyclelane is incorrect";
EXPECT_EQ(directededge->classification(), RoadClass::kResidential)
<< "The edges' road class is incorrect";
EXPECT_EQ(directededge->use(), Use::kRoad) << "The edges' use is incorrect";
EdgeInfo edgeinfo = local_tile->edgeinfo(directededge);
auto taggedValue = edgeinfo.GetTags();
auto search = taggedValue.equal_range(valhalla::baldr::TaggedValue::kBssInfo);
ASSERT_NE(search.first, search.second) << "BSS Tag TaggedValue::kBssInfo not found in EdgeInfo";
valhalla::BikeShareStationInfo bss_station_info;
bss_station_info.ParseFromString(search.first->second);
ASSERT_EQ(bss_station_info.ref(), "2");
ASSERT_EQ(bss_station_info.network(), "Atac Bikesharing");
ASSERT_EQ(bss_station_info.capacity(), 13);
ASSERT_EQ(bss_station_info.operator_(), "ATAC");
};
auto bss_edge_idx = local_tile->node(count - 1)->edge_index();
check_edge_attribute(local_tile->directededge(bss_edge_idx), kPedestrianAccess, kPedestrianAccess);
check_edge_attribute(local_tile->directededge(bss_edge_idx + 1), kPedestrianAccess,
kPedestrianAccess);
check_edge_attribute(local_tile->directededge(bss_edge_idx + 2), kPedestrianAccess, kBicycleAccess);
check_edge_attribute(local_tile->directededge(bss_edge_idx + 3), kBicycleAccess, kPedestrianAccess);
auto endnode_1 = local_tile->directededge(bss_edge_idx)->endnode();
auto count_1 = local_tile->node(endnode_1)->edge_count();
auto edge_idx_1 = local_tile->node(endnode_1)->edge_index();
// in this case the bike share edges should be the last two edges of this node
check_edge_attribute(local_tile->directededge(edge_idx_1 + count_1 - 1), kPedestrianAccess,
kPedestrianAccess);
check_edge_attribute(local_tile->directededge(edge_idx_1 + count_1 - 2), kBicycleAccess,
kPedestrianAccess);
auto endnode_2 = local_tile->directededge(bss_edge_idx + 1)->endnode();
auto count_2 = local_tile->node(endnode_2)->edge_count();
auto edge_idx_2 = local_tile->node(endnode_2)->edge_index();
// in this case the bike share edges should be the last two edges of this node
check_edge_attribute(local_tile->directededge(edge_idx_2 + count_2 - 1), kPedestrianAccess,
kPedestrianAccess);
check_edge_attribute(local_tile->directededge(edge_idx_2 + count_2 - 2), kPedestrianAccess,
kBicycleAccess);
CleanUp();
}
} // namespace
class GraphParserEnv : public ::testing::Environment {
public:
void SetUp() override {
DoConfig();
}
void TearDown() override {
}
};
int main(int argc, char* argv[]) {
// Test data BBs are as follows:
// Rome: <bounds minlat="41.8957000" minlon="12.4820400" maxlat="41.8973400"
// maxlon="12.4855600"/> NYC: <bounds minlat="40.7330200" minlon="-74.0136900"
// maxlat="40.7396900" maxlon="-73.9996000"/> Baltimore: <bounds minlat="39.2586000"
// minlon="-76.6081000" maxlat="39.3065000" maxlon="-76.5288000"/> Harrisburg: <bounds
// minlat="40.2075000" minlon="-76.8459000" maxlat="40.3136000" maxlon="-76.7474000"/>
// Liechtenstein: None
testing::AddGlobalTestEnvironment(new GraphParserEnv);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}