Compare commits
727 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 725b93a961 | |||
| a21e4c5a0b | |||
| 433db17083 | |||
| f8753fb9f1 | |||
| 25d5653f66 | |||
| 703a88a639 | |||
| 25326b571b | |||
| 5e2f4c9d2d | |||
| f43d380fe2 | |||
| 2240d3d0d1 | |||
| b6eea9a880 | |||
| 6bbd7c0c0b | |||
| 2caeb4008c | |||
| a4919ffb45 | |||
| b384340cbb | |||
| 061f46306f | |||
| fe1f11b071 | |||
| d3f5db576a | |||
| 0ca586e1c8 | |||
| a0b55f9df3 | |||
| 24943ccee6 | |||
| bcaaf34fa7 | |||
| ea17d1f6c7 | |||
| 3be734010c | |||
| e79787cc77 | |||
| 7de428233e | |||
| 9722f56be8 | |||
| e766d206f1 | |||
| 1fa9091239 | |||
| 04e1e5e3a2 | |||
| fa5c0560fa | |||
| 55d47b3e31 | |||
| 5bb96fd477 | |||
| 22b404a1b4 | |||
| 03dcf82602 | |||
| 95d1e8a4f1 | |||
| 67f68b47db | |||
| 593808f24d | |||
| 0a884cc64a | |||
| a54d4b98b1 | |||
| 23132e5292 | |||
| d741b624be | |||
| 00bc394bdb | |||
| d7215ad185 | |||
| 2b63eb8243 | |||
| 1bb3da0332 | |||
| c7d3d635f6 | |||
| f4c8db6105 | |||
| b2637b9a43 | |||
| 09d0ac3838 | |||
| f42cc848d5 | |||
| 4b1224f874 | |||
| 10bb2cce8e | |||
| 8174b3b85a | |||
| 71e2f2ed61 | |||
| 8d8724b3e1 | |||
| 47f65ccba6 | |||
| df0c1106ce | |||
| 47a2271e27 | |||
| ea367a7f37 | |||
| f4b192e33c | |||
| a5c824f694 | |||
| ccc4607d6d | |||
| 4ec41392f7 | |||
| 5f2b2cd0f7 | |||
| 361e3ca356 | |||
| 13bf4fab32 | |||
| 4b583e8ce9 | |||
| d31c6fe286 | |||
| 79de97d814 | |||
| 1c5d093b59 | |||
| ecff2beafa | |||
| 7e0b19c43d | |||
| 2ebe2faa74 | |||
| aec1451168 | |||
| 38251aa513 | |||
| d92e8ca8d2 | |||
| 2e5876d488 | |||
| 3dddd16ec7 | |||
| 40ff7ad999 | |||
| cb79f769c9 | |||
| e95feff016 | |||
| f65b32c1af | |||
| 46dd9b9887 | |||
| 4445f21e8a | |||
| 00d3676a20 | |||
| 0f7cb12e97 | |||
| 8485e02c00 | |||
| ae7300f9b4 | |||
| fc796539e8 | |||
| 1d8c43b445 | |||
| 58de37e822 | |||
| 7b3a0c5105 | |||
| 592034653c | |||
| 8d9f830c53 | |||
| d8eea0ce0e | |||
| c28c441e77 | |||
| 1391420699 | |||
| c0be751ef4 | |||
| 5e2462e061 | |||
| 5c0eb4772d | |||
| ef8706b4e1 | |||
| acd1919e8d | |||
| 459e2a322b | |||
| e62caf33aa | |||
| 72fd0f3d41 | |||
| 032c21c545 | |||
| b391daac6d | |||
| 8cb6959e3f | |||
| 49c817a60e | |||
| 6859b53155 | |||
| c581563230 | |||
| fc1db35f27 | |||
| 2734a4aee4 | |||
| 172f65969c | |||
| f0dbe0deb9 | |||
| 8f8d81f90c | |||
| 665523bc7e | |||
| 99e8fa70ba | |||
| 4c1d7c9d73 | |||
| d1cc8e7ad7 | |||
| 7629e44e4c | |||
| b62f6a6141 | |||
| 10d7a2396c | |||
| 007eced326 | |||
| 1128270d4b | |||
| c7d889bf9e | |||
| 7cb585c1a1 | |||
| 75157221b2 | |||
| 9807520ef0 | |||
| c658ee5c78 | |||
| cbfbcdcff5 | |||
| 9a0581ea7f | |||
| 60c268ddd6 | |||
| 0361e0204a | |||
| 2da427134b | |||
| 4fce0dadcf | |||
| 288c241fb4 | |||
| f3e3eda69e | |||
| 0f4dd8103d | |||
| 86ee05ee5e | |||
| 3b9c6a6465 | |||
| 8e73a4a19d | |||
| 428bb36ec6 | |||
| 0a24df6bd0 | |||
| d3ca080729 | |||
| 7658031784 | |||
| 710e74219a | |||
| 0249bed53a | |||
| 9d14f81b79 | |||
| a7c683a83c | |||
| 16631bf454 | |||
| 3c563f7073 | |||
| 344bdbb707 | |||
| a0256dfc60 | |||
| b131f27eb9 | |||
| 0d9b70552e | |||
| ea1a89290a | |||
| 59f1679d37 | |||
| 5121983218 | |||
| 0d7141ce5b | |||
| b4b753ce2e | |||
| 4f666e4d53 | |||
| 874a988527 | |||
| 51c79f9784 | |||
| 4d19811026 | |||
| d1454075ab | |||
| becb6cf5bf | |||
| a6f34d2044 | |||
| 7300024e13 | |||
| 282800e6b1 | |||
| e938bd3481 | |||
| 9b501276fb | |||
| 90d191f5f8 | |||
| f452e7f9d2 | |||
| 1d25f41122 | |||
| 5556785804 | |||
| 22ce4c24fb | |||
| d4d2d127d1 | |||
| 3c28932862 | |||
| 7e9177cb3c | |||
| f692103c81 | |||
| 5a1dfe9b89 | |||
| 7175180dc9 | |||
| f95d1fa8ba | |||
| 7b57068f6f | |||
| d79eac3e26 | |||
| 27c255c874 | |||
| bdc611b23a | |||
| 4cddf0bf5d | |||
| 462d4c99cc | |||
| 94a2188090 | |||
| ebcdcb5f00 | |||
| f9e780ed67 | |||
| 18f8ce69cd | |||
| dce665f14e | |||
| 80046b646b | |||
| 06ddceeac0 | |||
| b7ea1dfcd0 | |||
| 6d9598cd4c | |||
| 60c9701c3f | |||
| 2a8644b72c | |||
| b6e469abd1 | |||
| 004c237085 | |||
| 398e3bdf82 | |||
| 958350af82 | |||
| 2d677a8af9 | |||
| 05a79f5b55 | |||
| ac9566d3d7 | |||
| 8b7bf94aae | |||
| c4e785e523 | |||
| 2f6f883f7f | |||
| d071e92a1c | |||
| b18b4072e1 | |||
| 0a2898da17 | |||
| 73fb596973 | |||
| c3f9dc7400 | |||
| c75ce210ea | |||
| ffca6d8ba5 | |||
| 1ec35befc8 | |||
| 6080eaebbd | |||
| 41ea339053 | |||
| 75f9c08445 | |||
| cec3d1488a | |||
| ebec082da2 | |||
| bec585e382 | |||
| 2cc8ae875a | |||
| db8252e650 | |||
| e3cb26a1c4 | |||
| 44036ae26d | |||
| 5b5f871a6e | |||
| 9a8f9cae6d | |||
| 8f804581c0 | |||
| e26ef17545 | |||
| 800bb223b5 | |||
| 75606f2100 | |||
| a28928e6ca | |||
| 8700007025 | |||
| 520f7fa2de | |||
| 096208a154 | |||
| 27caab69ec | |||
| 3fe2b587cb | |||
| c791188811 | |||
| b227c90c18 | |||
| 8a5538356b | |||
| b257c881b5 | |||
| 0f5dffb1c3 | |||
| d2bd238274 | |||
| fed700440d | |||
| 32a9d42412 | |||
| efc938d870 | |||
| 369f669227 | |||
| 1c56671f01 | |||
| 4dbc1e0e96 | |||
| 94288843f1 | |||
| b12decc865 | |||
| 0fc944abf3 | |||
| 9f96c98f02 | |||
| 9805b05738 | |||
| 13ed186469 | |||
| 00a43221ac | |||
| edc39112e2 | |||
| 3b727dea99 | |||
| f16b2adec7 | |||
| 7d425aa76f | |||
| 651c07c724 | |||
| 4d27b75897 | |||
| 6f75d68d07 | |||
| ae269e12bb | |||
| 3a48929fe6 | |||
| be970326b6 | |||
| 463511871f | |||
| 002da1e02d | |||
| b095aae5ce | |||
| 511c21029e | |||
| 81b0447024 | |||
| d42772a261 | |||
| c1136099a9 | |||
| 06f8a975c0 | |||
| c8cd8775f6 | |||
| f9900c91bd | |||
| accaf6e77e | |||
| 8490e297a9 | |||
| 6d3a4b5f6c | |||
| 1f36206f45 | |||
| 952e10936c | |||
| 2b3093a687 | |||
| d7e25772b0 | |||
| c66c9b0353 | |||
| bbde0d75da | |||
| c3aec4f627 | |||
| 113852eed4 | |||
| 6b9b2c1468 | |||
| 2c87b295ff | |||
| 93767d68f8 | |||
| cc3646ca16 | |||
| 48333f73d5 | |||
| 1f4241a63d | |||
| 8eccfaa034 | |||
| 438d1af12a | |||
| 5be6ef380f | |||
| 76419ed2fc | |||
| 4684921e51 | |||
| edd8caa2bf | |||
| cb5575ae89 | |||
| 42e726dec5 | |||
| e3d33aa171 | |||
| f2ceeb35da | |||
| 577cf5ddc4 | |||
| 91ced39233 | |||
| 4b6cb0b8b8 | |||
| fb81302382 | |||
| dfc81f65ee | |||
| 909db4c861 | |||
| 4277eed1b6 | |||
| 6f5703a5fe | |||
| f7469f298d | |||
| b29d5df7a2 | |||
| 549ba65861 | |||
| a9d99cbe54 | |||
| 8438024370 | |||
| e6a00ddcfd | |||
| 71b967d243 | |||
| 1fc1e9590a | |||
| 0a0099fb41 | |||
| b890d394ad | |||
| a7fd37ae76 | |||
| 41fafae21d | |||
| a38c007f51 | |||
| c7ee402b0e | |||
| 1c19796e3e | |||
| 76fb0cb965 | |||
| 23c79f5cc9 | |||
| 14eac50261 | |||
| cf3eae1c91 | |||
| db06cdb4ce | |||
| 7ba8e51fa9 | |||
| bc6466cc36 | |||
| 4fbefaef9a | |||
| be11d3325d | |||
| 274140d309 | |||
| ed960ccc8d | |||
| f2b72113c1 | |||
| 67a8d30e87 | |||
| dafd0e5db7 | |||
| d6d10cbf06 | |||
| 3d3ba86be4 | |||
| 52ed8a7ed0 | |||
| 9449c99e25 | |||
| 4c0846734e | |||
| 4c64f5fe62 | |||
| 9455ea0547 | |||
| c3b54a63c3 | |||
| b9e1d3116c | |||
| 5bb7e62a7c | |||
| a443f3a0bb | |||
| 440244eed8 | |||
| 2b9e25300f | |||
| de264dbf94 | |||
| 848b773e24 | |||
| d92f022041 | |||
| 57fab61789 | |||
| ec8f977ebe | |||
| 8dc85e7641 | |||
| 4e00ebcd74 | |||
| 335e719b5d | |||
| 415f8ef2d8 | |||
| 17615d1d4a | |||
| 5072252c72 | |||
| 46e93770c9 | |||
| fe43734811 | |||
| 0df81c49d5 | |||
| 5653516b32 | |||
| 22da5be08e | |||
| 862656aecc | |||
| ec119a6d52 | |||
| 6b98b5f4c7 | |||
| 5effe95f2c | |||
| f22e3fd3ff | |||
| 0047040af9 | |||
| 60987e6b9b | |||
| 27d5e2b219 | |||
| 53fd0c3a55 | |||
| 63456a6d4f | |||
| d4cd3c2f7b | |||
| dbf7137a1a | |||
| 785891c315 | |||
| b7417ec954 | |||
| 61b861f0e5 | |||
| 0fea0738bf | |||
| 4f25d29815 | |||
| 28302a5040 | |||
| 9cc5ca5c58 | |||
| 4c4e60b3c9 | |||
| 5689a96602 | |||
| 8b57db467a | |||
| 50339e53e2 | |||
| bc9f5189a5 | |||
| fee83fee40 | |||
| cd5112ab0e | |||
| a43b88f9a2 | |||
| c20fd5dcaa | |||
| f12e296c09 | |||
| 9c3a572646 | |||
| 6175faa9a4 | |||
| af02fc6bbe | |||
| cc0bbc42a2 | |||
| fd747c7340 | |||
| bd33202972 | |||
| f6f0de0e38 | |||
| 881041800b | |||
| 11f3ac16f6 | |||
| 969bf95230 | |||
| abc6b4180c | |||
| f74d762a92 | |||
| f00892ed66 | |||
| f14c6e6845 | |||
| b1bbf2ef84 | |||
| 201062cade | |||
| 8cb9198bcf | |||
| f5e53c0452 | |||
| 41d9c00f70 | |||
| b52f392c92 | |||
| efaa3b5ab2 | |||
| 36f3d8d6ac | |||
| e469afa4a9 | |||
| 9d4b0caa5b | |||
| 392c07951e | |||
| 8e72c3d81e | |||
| 02428f1e06 | |||
| b3aa513563 | |||
| b8b08cb114 | |||
| ebbbf1059d | |||
| 37297076f8 | |||
| a75b2df6fe | |||
| 9ccd0f0282 | |||
| e57d9f2e2e | |||
| cf593ba9f9 | |||
| 9eb862a6a4 | |||
| bc84e08da5 | |||
| 24dae2f096 | |||
| ab24d6bd96 | |||
| 7782c80c4f | |||
| 994bd0a910 | |||
| bc9dcba4d4 | |||
| 85c244ed08 | |||
| 495196193c | |||
| def1e5e1d8 | |||
| 2727091e47 | |||
| d7fbd416ba | |||
| 6a09ce1613 | |||
| 774e6346e7 | |||
| 05b939760c | |||
| d6c6fbfe03 | |||
| bb3cbf2dda | |||
| 39d96a45aa | |||
| 6a8c5c8869 | |||
| 96318bbe11 | |||
| 00dd2463fd | |||
| bcd55626ef | |||
| 8f8cb6a52f | |||
| 2e3d33dfcd | |||
| 1e40cd6f0b | |||
| 6e2608b2f2 | |||
| 60d80cf261 | |||
| 9c23fd4a31 | |||
| fccb1aad32 | |||
| 2780ff31b5 | |||
| c37c8dc21d | |||
| 6ee7a81f10 | |||
| 3d94638d86 | |||
| 418ff95543 | |||
| 221113cbb7 | |||
| 13ea12cf6e | |||
| 1945aae4dc | |||
| 30362cfc0c | |||
| 6cdc590db5 | |||
| eb122a2b8c | |||
| feaf8711d3 | |||
| 6e364ff0ba | |||
| 6f6aff7493 | |||
| 207cddd50b | |||
| 35988d8f09 | |||
| bea63028c7 | |||
| 0244060806 | |||
| bfdc296f43 | |||
| 8e625a5d07 | |||
| 3460bd0ba9 | |||
| 4dd0377eb8 | |||
| 6e1ab9fe3a | |||
| 7a2d214cc4 | |||
| 62495a6de4 | |||
| 8ea88468f3 | |||
| 687892890b | |||
| ff0dfacc48 | |||
| 235a52032a | |||
| a5ee7e78f6 | |||
| 181dbe8493 | |||
| dae9c9a7ed | |||
| 6d6d299ea4 | |||
| 6fd615b9cd | |||
| d09394ed52 | |||
| 3e6f27d173 | |||
| 82c2ae5441 | |||
| 7edf2bb2c2 | |||
| c9607b99a3 | |||
| 2fe1a84dd4 | |||
| c63218a889 | |||
| 5efa9664db | |||
| dc75469e78 | |||
| 9d1e21b5ad | |||
| 27a367c733 | |||
| ffa0ace2a7 | |||
| 074e1e992c | |||
| cdd72c7e56 | |||
| a5e99a95a3 | |||
| 1de736019d | |||
| d6b2712070 | |||
| eda8f4ccec | |||
| 7e3f476407 | |||
| e10f36d5f0 | |||
| 1bfd9abda3 | |||
| 4a1a10fde8 | |||
| 4c3cb76ced | |||
| e2794e9f06 | |||
| 7d2c627ad2 | |||
| b310e0f718 | |||
| 18915ae2bd | |||
| 5dbda8f519 | |||
| 82ce9dfc04 | |||
| ad5cd564ab | |||
| 6f01f580ca | |||
| d5130d9fe4 | |||
| 0341a0d5e7 | |||
| 32191fb05a | |||
| 1592fe377a | |||
| 5add28410f | |||
| d54a55c12b | |||
| aab5e8430f | |||
| 2e20fdb462 | |||
| 2ac3da7a90 | |||
| 399b79bab2 | |||
| b9eb936cac | |||
| 38117df11b | |||
| 27d729baf0 | |||
| d408a64c8c | |||
| 9aeb28066d | |||
| 6fb7c8687e | |||
| d9666008e3 | |||
| e132230651 | |||
| c2877a0c22 | |||
| 251fc3ec68 | |||
| 287f0a3b68 | |||
| b03d9fe987 | |||
| 98372ef33f | |||
| d00f4afb84 | |||
| d4bf02c882 | |||
| 284e671163 | |||
| 0f112e5c9d | |||
| 759449b4be | |||
| 9c03f919a3 | |||
| c9afd9a281 | |||
| a999cb9db9 | |||
| fdc5bd6195 | |||
| e1d94eee21 | |||
| 885f237217 | |||
| 5860a4e28e | |||
| 2bebed44ff | |||
| 4990e544cf | |||
| 8010506d4e | |||
| f2f7abb9a8 | |||
| 85f6ab869e | |||
| fc87b0a11e | |||
| 79bc071754 | |||
| 797243fc9c | |||
| cc7c6b9ece | |||
| 279071e5bb | |||
| 426374ff8a | |||
| 1508874ebc | |||
| bbe440cacd | |||
| e647e73af9 | |||
| 696ddfde0e | |||
| 37d6257524 | |||
| faee894052 | |||
| 61f16b8c5e | |||
| 85eb38e755 | |||
| a87cf60dfc | |||
| 3b135447f3 | |||
| 0c3713f7e5 | |||
| 4d0571fd73 | |||
| 4722988bf0 | |||
| 61151535e6 | |||
| bcff6c192c | |||
| 020d0cfb49 | |||
| d38e3bd729 | |||
| 84a604f70b | |||
| 782baf54a3 | |||
| d754e4eeca | |||
| db98f6191e | |||
| b453a42f77 | |||
| 2a6585e664 | |||
| bc013925b8 | |||
| 8108ecc4d3 | |||
| 1c80584206 | |||
| a3dd9c3e57 | |||
| 8f05fc0a84 | |||
| 3c4feecda0 | |||
| e776a51c73 | |||
| 129e8ef98a | |||
| 69134f6d6a | |||
| b32062f875 | |||
| 8d46ee85f1 | |||
| 9f9fde1f2b | |||
| 2b041e09ac | |||
| 73b32bb45e | |||
| 11e6e74f09 | |||
| bf3e3f0c3d | |||
| 2656acc321 | |||
| e46c9be79f | |||
| 507167d5c1 | |||
| fc90162f69 | |||
| 1e8fb7a38c | |||
| afb6c5a09d | |||
| 2255ab0a37 | |||
| a6ab042078 | |||
| 480f70c049 | |||
| 0592897859 | |||
| d5a9f8e177 | |||
| 5840829cdc | |||
| fd0946b770 | |||
| 293b462fd2 | |||
| 3db50fdd54 | |||
| 1540e6518c | |||
| 8b30c13cd9 | |||
| a7eb89b2f0 | |||
| 53c102e1e9 | |||
| 7d90737921 | |||
| e281f88f2e | |||
| 16c5c7bbb4 | |||
| 7d4dfd87f1 | |||
| 6156bf0f9d | |||
| ee1fdca52e | |||
| 95b5bcbd49 | |||
| 0c529361a3 | |||
| 7110acc94f | |||
| 1188002bcb | |||
| b47a3f15ce | |||
| 695a2a2b6e | |||
| c8b4ef3eed | |||
| 6091248493 | |||
| 32fd507ad9 | |||
| 0ee77a37d1 | |||
| 05241544c5 | |||
| 495c872489 | |||
| 8c09edfdbd | |||
| 67722cf788 | |||
| 8e3484b873 | |||
| 4622aebabb | |||
| 96f29c27cd | |||
| 3de98f7a9d | |||
| 2b33fcd92d | |||
| b1ffcd4350 | |||
| fd500001fb | |||
| 54a757a917 | |||
| 98dfc218d9 | |||
| f6f0f1fb72 | |||
| 218c810860 | |||
| c836b6df3b | |||
| 637bab29c6 | |||
| 0061b3fcbf | |||
| 2a19ded9d5 | |||
| bda9de0775 | |||
| 7047610a45 | |||
| 903d6f9e12 | |||
| 7d61bb2868 | |||
| def7164cad | |||
| fc399e01fe | |||
| ffdc3eee2d | |||
| 1f6f44ab01 | |||
| 19740758c9 | |||
| f618660d24 | |||
| f50dbe298a | |||
| c324fbace4 | |||
| d05152af71 | |||
| bf228b4ae4 | |||
| ba0c17e287 | |||
| 6cfbd4cefe | |||
| e17a2e79a0 | |||
| 72d709ae6c | |||
| 08ca450c40 | |||
| a2951659ac | |||
| 3a6af3810f | |||
| 3973554f07 | |||
| 718cba2e36 | |||
| d2a70d1504 | |||
| 4bc847ac42 | |||
| c3621edf9c | |||
| a64f2de9e1 | |||
| ce684cf9d4 | |||
| 1d1be10f16 | |||
| a09f97c9d5 | |||
| 48da2d2dfb | |||
| 36c0edea2a | |||
| 3568dc2083 | |||
| 51ad72a432 | |||
| 9ce970df8f | |||
| cfa4d80dd7 | |||
| 885cd05f1a | |||
| 21188725d5 | |||
| 70f257b62f | |||
| e8fb8e13df | |||
| 7b7b93e9ba | |||
| 4014da3cc5 | |||
| 410120adee | |||
| a98e65aa1e | |||
| dba9998118 | |||
| 1c75ce5911 | |||
| 33b30aeb95 | |||
| abd8d3459a | |||
| 471698c59f | |||
| e67cf578ae | |||
| 186ad5d444 | |||
| 7eb810c34a | |||
| 7817384e3c | |||
| 34256ba358 | |||
| 08eb5aa7d1 | |||
| 1d3932e8c5 |
+5
-2
@@ -36,8 +36,9 @@ Thumbs.db
|
||||
# build related files #
|
||||
#######################
|
||||
/build/
|
||||
/Util/FingerPrint.cpp
|
||||
/Util/GitDescription.cpp
|
||||
/Util/finger_print.cpp
|
||||
/Util/git_sha.cpp
|
||||
/cmake/postinst
|
||||
|
||||
# Eclipse related files #
|
||||
#########################
|
||||
@@ -79,6 +80,8 @@ stxxl.errlog
|
||||
/osrm-prepare
|
||||
/osrm-unlock-all
|
||||
/osrm-cli
|
||||
/osrm-check-hsgr
|
||||
/osrm-springclean
|
||||
/nohup.out
|
||||
|
||||
# Sandbox folder #
|
||||
|
||||
+12
-6
@@ -7,13 +7,17 @@ install:
|
||||
- sudo apt-add-repository -y ppa:ubuntu-toolchain-r/test
|
||||
- sudo add-apt-repository -y ppa:boost-latest/ppa
|
||||
- sudo apt-get update >/dev/null
|
||||
- sudo apt-get -q install libprotoc-dev libprotobuf7 libprotobuf-dev libosmpbf-dev libbz2-dev libstxxl-dev libstxxl1 libxml2-dev libzip-dev lua5.1 liblua5.1-0-dev rubygems libtbb-dev
|
||||
- sudo apt-get -q install g++-4.7
|
||||
- sudo apt-get -q install protobuf-compiler libprotoc-dev libprotobuf7 libprotobuf-dev libbz2-dev libstxxl-dev libstxxl1 libxml2-dev libzip-dev lua5.1 liblua5.1-0-dev rubygems libtbb-dev
|
||||
- sudo apt-get -q install g++-4.8
|
||||
- sudo apt-get install libboost1.54-all-dev
|
||||
#luabind
|
||||
# luabind
|
||||
- curl https://gist.githubusercontent.com/DennisOSRM/f2eb7b948e6fe1ae319e/raw/install-luabind.sh | sudo bash
|
||||
#osmosis
|
||||
# osmosis
|
||||
- curl -s https://gist.githubusercontent.com/DennisOSRM/803a64a9178ec375069f/raw/ | sudo bash
|
||||
# cmake
|
||||
- curl -s https://gist.githubusercontent.com/DennisOSRM/5fad9bee5c7f09fd7fc9/raw/ | sudo bash
|
||||
# osmpbf library
|
||||
- curl -s https://gist.githubusercontent.com/DennisOSRM/13b1b4fe38a57ead850e/raw/install_osmpbf.sh | sudo bash
|
||||
before_script:
|
||||
- rvm use 1.9.3
|
||||
- gem install bundler
|
||||
@@ -23,6 +27,8 @@ before_script:
|
||||
- cmake .. $CMAKEOPTIONS
|
||||
script:
|
||||
- make -j 2
|
||||
- make -j 2 tests
|
||||
- ./datastructure-tests
|
||||
- cd ..
|
||||
- cucumber -p verify
|
||||
after_script:
|
||||
@@ -36,8 +42,8 @@ cache:
|
||||
- bundler
|
||||
- apt
|
||||
env:
|
||||
- CMAKEOPTIONS="-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++-4.7" OSRM_PORT=5000 OSRM_TIMEOUT=60
|
||||
- CMAKEOPTIONS="-DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=g++-4.7" OSRM_PORT=5010 OSRM_TIMEOUT=60
|
||||
- CMAKEOPTIONS="-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++-4.8" OSRM_PORT=5000 OSRM_TIMEOUT=60
|
||||
- CMAKEOPTIONS="-DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=g++-4.8" OSRM_PORT=5010 OSRM_TIMEOUT=60
|
||||
notifications:
|
||||
irc:
|
||||
channels:
|
||||
|
||||
@@ -1,148 +0,0 @@
|
||||
#ifndef __BFS_COMPONENT_EXPLORER_H__
|
||||
#define __BFS_COMPONENT_EXPLORER_H__
|
||||
|
||||
#include "../typedefs.h"
|
||||
#include "../DataStructures/DynamicGraph.h"
|
||||
#include "../DataStructures/RestrictionMap.h"
|
||||
|
||||
#include <queue>
|
||||
#include <unordered_set>
|
||||
|
||||
// Explores the components of the given graph while respecting turn restrictions
|
||||
// and barriers.
|
||||
template <typename GraphT> class BFSComponentExplorer
|
||||
{
|
||||
public:
|
||||
BFSComponentExplorer(const GraphT &dynamicGraph,
|
||||
const RestrictionMap &restrictions,
|
||||
const std::unordered_set<NodeID> &barrier_nodes)
|
||||
: m_graph(dynamicGraph), m_restriction_map(restrictions), m_barrier_nodes(barrier_nodes)
|
||||
{
|
||||
BOOST_ASSERT(m_graph.GetNumberOfNodes() > 0);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the size of the component that the node belongs to.
|
||||
*/
|
||||
inline unsigned int GetComponentSize(NodeID node)
|
||||
{
|
||||
BOOST_ASSERT(node < m_component_index_list.size());
|
||||
|
||||
return m_component_index_size[m_component_index_list[node]];
|
||||
}
|
||||
|
||||
inline unsigned int GetNumberOfComponents() { return m_component_index_size.size(); }
|
||||
|
||||
/*!
|
||||
* Computes the component sizes.
|
||||
*/
|
||||
void run()
|
||||
{
|
||||
std::queue<std::pair<NodeID, NodeID>> bfs_queue;
|
||||
unsigned current_component = 0;
|
||||
|
||||
BOOST_ASSERT(m_component_index_list.empty());
|
||||
BOOST_ASSERT(m_component_index_size.empty());
|
||||
|
||||
unsigned num_nodes = m_graph.GetNumberOfNodes();
|
||||
|
||||
m_component_index_list.resize(num_nodes, std::numeric_limits<unsigned>::max());
|
||||
|
||||
BOOST_ASSERT(num_nodes > 0);
|
||||
|
||||
// put unexplorered node with parent pointer into queue
|
||||
for (NodeID node = 0; node < num_nodes; ++node)
|
||||
{
|
||||
if (std::numeric_limits<unsigned>::max() == m_component_index_list[node])
|
||||
{
|
||||
unsigned size = ExploreComponent(bfs_queue, node, current_component);
|
||||
|
||||
// push size into vector
|
||||
m_component_index_size.emplace_back(size);
|
||||
++current_component;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
/*!
|
||||
* Explores the current component that starts at node using BFS.
|
||||
*/
|
||||
inline unsigned ExploreComponent(std::queue<std::pair<NodeID, NodeID>> &bfs_queue,
|
||||
NodeID node,
|
||||
unsigned current_component)
|
||||
{
|
||||
/*
|
||||
Graphical representation of variables:
|
||||
|
||||
u v w
|
||||
*---------->*---------->*
|
||||
e2
|
||||
*/
|
||||
|
||||
bfs_queue.emplace(node, node);
|
||||
// mark node as read
|
||||
m_component_index_list[node] = current_component;
|
||||
|
||||
unsigned current_component_size = 1;
|
||||
|
||||
while (!bfs_queue.empty())
|
||||
{
|
||||
// fetch element from BFS queue
|
||||
std::pair<NodeID, NodeID> current_queue_item = bfs_queue.front();
|
||||
bfs_queue.pop();
|
||||
|
||||
const NodeID v = current_queue_item.first; // current node
|
||||
const NodeID u = current_queue_item.second; // parent
|
||||
// increment size counter of current component
|
||||
++current_component_size;
|
||||
const bool is_barrier_node = (m_barrier_nodes.find(v) != m_barrier_nodes.end());
|
||||
if (!is_barrier_node)
|
||||
{
|
||||
const NodeID to_node_of_only_restriction =
|
||||
m_restriction_map.CheckForEmanatingIsOnlyTurn(u, v);
|
||||
|
||||
for (auto e2 : m_graph.GetAdjacentEdgeRange(v))
|
||||
{
|
||||
const NodeID w = m_graph.GetTarget(e2);
|
||||
|
||||
if (to_node_of_only_restriction != std::numeric_limits<unsigned>::max() &&
|
||||
w != to_node_of_only_restriction)
|
||||
{
|
||||
// At an only_-restriction but not at the right turn
|
||||
continue;
|
||||
}
|
||||
|
||||
if (u != w)
|
||||
{
|
||||
// only add an edge if turn is not a U-turn except
|
||||
// when it is at the end of a dead-end street.
|
||||
if (!m_restriction_map.CheckIfTurnIsRestricted(u, v, w))
|
||||
{
|
||||
// only add an edge if turn is not prohibited
|
||||
if (std::numeric_limits<unsigned>::max() == m_component_index_list[w])
|
||||
{
|
||||
// insert next (node, parent) only if w has
|
||||
// not yet been explored
|
||||
// mark node as read
|
||||
m_component_index_list[w] = current_component;
|
||||
bfs_queue.emplace(w, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return current_component_size;
|
||||
}
|
||||
|
||||
std::vector<unsigned> m_component_index_list;
|
||||
std::vector<NodeID> m_component_index_size;
|
||||
|
||||
const GraphT &m_graph;
|
||||
const RestrictionMap &m_restriction_map;
|
||||
const std::unordered_set<NodeID> &m_barrier_nodes;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef OBJECTTOBASE64_H_
|
||||
#define OBJECTTOBASE64_H_
|
||||
|
||||
#include "../Util/StringUtil.h"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/archive/iterators/base64_from_binary.hpp>
|
||||
#include <boost/archive/iterators/binary_from_base64.hpp>
|
||||
#include <boost/archive/iterators/transform_width.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
typedef
|
||||
boost::archive::iterators::base64_from_binary<
|
||||
boost::archive::iterators::transform_width<const char *, 6, 8>
|
||||
> base64_t;
|
||||
|
||||
typedef
|
||||
boost::archive::iterators::transform_width<
|
||||
boost::archive::iterators::binary_from_base64<
|
||||
std::string::const_iterator>, 8, 6
|
||||
> binary_t;
|
||||
|
||||
template<class ObjectT>
|
||||
static void EncodeObjectToBase64(const ObjectT & object, std::string& encoded) {
|
||||
const char * char_ptr_to_object = (const char *)&object;
|
||||
std::vector<unsigned char> data(sizeof(object));
|
||||
std::copy(
|
||||
char_ptr_to_object,
|
||||
char_ptr_to_object + sizeof(ObjectT),
|
||||
data.begin()
|
||||
);
|
||||
|
||||
unsigned char number_of_padded_chars = 0; // is in {0,1,2};
|
||||
while(data.size() % 3 != 0) {
|
||||
++number_of_padded_chars;
|
||||
data.push_back(0x00);
|
||||
}
|
||||
|
||||
BOOST_ASSERT_MSG(
|
||||
0 == data.size() % 3,
|
||||
"base64 input data size is not a multiple of 3!"
|
||||
);
|
||||
encoded.resize(sizeof(ObjectT));
|
||||
encoded.assign(
|
||||
base64_t( &data[0] ),
|
||||
base64_t( &data[0] + (data.size() - number_of_padded_chars) )
|
||||
);
|
||||
replaceAll(encoded, "+", "-");
|
||||
replaceAll(encoded, "/", "_");
|
||||
}
|
||||
|
||||
template<class ObjectT>
|
||||
static void DecodeObjectFromBase64(const std::string& input, ObjectT & object) {
|
||||
try {
|
||||
std::string encoded(input);
|
||||
//replace "-" with "+" and "_" with "/"
|
||||
replaceAll(encoded, "-", "+");
|
||||
replaceAll(encoded, "_", "/");
|
||||
|
||||
std::copy (
|
||||
binary_t( encoded.begin() ),
|
||||
binary_t( encoded.begin() + encoded.length() - 1),
|
||||
(char *)&object
|
||||
);
|
||||
|
||||
} catch(...) { }
|
||||
}
|
||||
|
||||
#endif /* OBJECTTOBASE64_H_ */
|
||||
@@ -1,447 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef STRONGLYCONNECTEDCOMPONENTS_H_
|
||||
#define STRONGLYCONNECTEDCOMPONENTS_H_
|
||||
|
||||
#include "../typedefs.h"
|
||||
#include "../DataStructures/DeallocatingVector.h"
|
||||
#include "../DataStructures/DynamicGraph.h"
|
||||
#include "../DataStructures/ImportEdge.h"
|
||||
#include "../DataStructures/QueryNode.h"
|
||||
#include "../DataStructures/Percent.h"
|
||||
#include "../DataStructures/Restriction.h"
|
||||
#include "../DataStructures/TurnInstructions.h"
|
||||
|
||||
#include "../Util/OSRMException.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
#include "../Util/StdHashExtensions.h"
|
||||
|
||||
#include <osrm/Coordinate.h>
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <gdal.h>
|
||||
#include <ogrsf_frmts.h>
|
||||
#else
|
||||
#include <gdal/gdal.h>
|
||||
#include <gdal/ogrsf_frmts.h>
|
||||
#endif
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include <memory>
|
||||
#include <stack>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
class TarjanSCC
|
||||
{
|
||||
private:
|
||||
struct TarjanNode
|
||||
{
|
||||
TarjanNode() : index(UINT_MAX), low_link(UINT_MAX), on_stack(false) {}
|
||||
unsigned index;
|
||||
unsigned low_link;
|
||||
bool on_stack;
|
||||
};
|
||||
|
||||
struct TarjanEdgeData
|
||||
{
|
||||
int distance;
|
||||
unsigned name_id : 31;
|
||||
bool shortcut : 1;
|
||||
short type;
|
||||
bool forward : 1;
|
||||
bool backward : 1;
|
||||
bool reversedEdge : 1;
|
||||
};
|
||||
|
||||
struct TarjanStackFrame
|
||||
{
|
||||
explicit TarjanStackFrame(NodeID v, NodeID parent) : v(v), parent(parent) {}
|
||||
NodeID v;
|
||||
NodeID parent;
|
||||
};
|
||||
|
||||
typedef DynamicGraph<TarjanEdgeData> TarjanDynamicGraph;
|
||||
typedef TarjanDynamicGraph::InputEdge TarjanEdge;
|
||||
typedef std::pair<NodeID, NodeID> RestrictionSource;
|
||||
typedef std::pair<NodeID, bool> restriction_target;
|
||||
typedef std::vector<restriction_target> EmanatingRestrictionsVector;
|
||||
typedef std::unordered_map<RestrictionSource, unsigned> RestrictionMap;
|
||||
|
||||
std::vector<NodeInfo> m_coordinate_list;
|
||||
std::vector<EmanatingRestrictionsVector> m_restriction_bucket_list;
|
||||
std::shared_ptr<TarjanDynamicGraph> m_node_based_graph;
|
||||
std::unordered_set<NodeID> m_barrier_node_list;
|
||||
std::unordered_set<NodeID> m_traffic_light_list;
|
||||
unsigned m_restriction_counter;
|
||||
RestrictionMap m_restriction_map;
|
||||
|
||||
public:
|
||||
TarjanSCC(int number_of_nodes,
|
||||
std::vector<NodeBasedEdge> &input_edges,
|
||||
std::vector<NodeID> &bn,
|
||||
std::vector<NodeID> &tl,
|
||||
std::vector<TurnRestriction> &irs,
|
||||
std::vector<NodeInfo> &nI)
|
||||
: m_coordinate_list(nI), m_restriction_counter(irs.size())
|
||||
{
|
||||
for (const TurnRestriction &restriction : irs)
|
||||
{
|
||||
std::pair<NodeID, NodeID> restrictionSource = {restriction.fromNode,
|
||||
restriction.viaNode};
|
||||
unsigned index;
|
||||
RestrictionMap::iterator restriction_iterator =
|
||||
m_restriction_map.find(restrictionSource);
|
||||
if (restriction_iterator == m_restriction_map.end())
|
||||
{
|
||||
index = m_restriction_bucket_list.size();
|
||||
m_restriction_bucket_list.resize(index + 1);
|
||||
m_restriction_map.emplace(restrictionSource, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
index = restriction_iterator->second;
|
||||
// Map already contains an is_only_*-restriction
|
||||
if (m_restriction_bucket_list.at(index).begin()->second)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (restriction.flags.isOnly)
|
||||
{
|
||||
// We are going to insert an is_only_*-restriction. There can be only one.
|
||||
m_restriction_bucket_list.at(index).clear();
|
||||
}
|
||||
}
|
||||
|
||||
m_restriction_bucket_list.at(index)
|
||||
.emplace_back(restriction.toNode, restriction.flags.isOnly);
|
||||
}
|
||||
|
||||
m_barrier_node_list.insert(bn.begin(), bn.end());
|
||||
m_traffic_light_list.insert(tl.begin(), tl.end());
|
||||
|
||||
DeallocatingVector<TarjanEdge> edge_list;
|
||||
for (const NodeBasedEdge &input_edge : input_edges)
|
||||
{
|
||||
if (input_edge.source == input_edge.target)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
TarjanEdge edge;
|
||||
if (input_edge.forward)
|
||||
{
|
||||
edge.source = input_edge.source;
|
||||
edge.target = input_edge.target;
|
||||
edge.data.forward = input_edge.forward;
|
||||
edge.data.backward = input_edge.backward;
|
||||
}
|
||||
else
|
||||
{
|
||||
edge.source = input_edge.target;
|
||||
edge.target = input_edge.source;
|
||||
edge.data.backward = input_edge.forward;
|
||||
edge.data.forward = input_edge.backward;
|
||||
}
|
||||
|
||||
edge.data.distance = (std::max)((int)input_edge.weight, 1);
|
||||
BOOST_ASSERT(edge.data.distance > 0);
|
||||
edge.data.shortcut = false;
|
||||
edge.data.name_id = input_edge.name_id;
|
||||
edge.data.type = input_edge.type;
|
||||
edge.data.reversedEdge = false;
|
||||
edge_list.push_back(edge);
|
||||
if (edge.data.backward)
|
||||
{
|
||||
std::swap(edge.source, edge.target);
|
||||
edge.data.forward = input_edge.backward;
|
||||
edge.data.backward = input_edge.forward;
|
||||
edge.data.reversedEdge = true;
|
||||
edge_list.push_back(edge);
|
||||
}
|
||||
}
|
||||
input_edges.shrink_to_fit();
|
||||
BOOST_ASSERT_MSG(0 == input_edges.size() && 0 == input_edges.capacity(),
|
||||
"input edge vector not properly deallocated");
|
||||
|
||||
std::sort(edge_list.begin(), edge_list.end());
|
||||
m_node_based_graph = std::make_shared<TarjanDynamicGraph>(number_of_nodes, edge_list);
|
||||
}
|
||||
|
||||
~TarjanSCC() { m_node_based_graph.reset(); }
|
||||
|
||||
void Run()
|
||||
{
|
||||
// remove files from previous run if exist
|
||||
DeleteFileIfExists("component.dbf");
|
||||
DeleteFileIfExists("component.shx");
|
||||
DeleteFileIfExists("component.shp");
|
||||
|
||||
Percent p(m_node_based_graph->GetNumberOfNodes());
|
||||
|
||||
OGRRegisterAll();
|
||||
|
||||
const char *pszDriverName = "ESRI Shapefile";
|
||||
OGRSFDriver *poDriver =
|
||||
OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(pszDriverName);
|
||||
if (nullptr == poDriver)
|
||||
{
|
||||
throw OSRMException("ESRI Shapefile driver not available");
|
||||
}
|
||||
OGRDataSource *poDS = poDriver->CreateDataSource("component.shp", nullptr);
|
||||
|
||||
if (nullptr == poDS)
|
||||
{
|
||||
throw OSRMException("Creation of output file failed");
|
||||
}
|
||||
|
||||
OGRLayer *poLayer = poDS->CreateLayer("component", nullptr, wkbLineString, nullptr);
|
||||
|
||||
if (nullptr == poLayer)
|
||||
{
|
||||
throw OSRMException("Layer creation failed.");
|
||||
}
|
||||
|
||||
// The following is a hack to distinguish between stuff that happens
|
||||
// before the recursive call and stuff that happens after
|
||||
std::stack<std::pair<bool, TarjanStackFrame>> recursion_stack;
|
||||
// true = stuff before, false = stuff after call
|
||||
std::stack<NodeID> tarjan_stack;
|
||||
std::vector<unsigned> components_index(m_node_based_graph->GetNumberOfNodes(), UINT_MAX);
|
||||
std::vector<NodeID> component_size_vector;
|
||||
std::vector<TarjanNode> tarjan_node_list(m_node_based_graph->GetNumberOfNodes());
|
||||
unsigned component_index = 0, size_of_current_component = 0;
|
||||
int index = 0;
|
||||
NodeID last_node = m_node_based_graph->GetNumberOfNodes();
|
||||
for (NodeID node = 0; node < last_node; ++node)
|
||||
{
|
||||
if (UINT_MAX == components_index[node])
|
||||
{
|
||||
recursion_stack.emplace(true, TarjanStackFrame(node, node));
|
||||
}
|
||||
|
||||
while (!recursion_stack.empty())
|
||||
{
|
||||
const bool before_recursion = recursion_stack.top().first;
|
||||
TarjanStackFrame currentFrame = recursion_stack.top().second;
|
||||
NodeID v = currentFrame.v;
|
||||
recursion_stack.pop();
|
||||
|
||||
if (before_recursion)
|
||||
{
|
||||
// Mark frame to handle tail of recursion
|
||||
recursion_stack.emplace(false, currentFrame);
|
||||
|
||||
// Mark essential information for SCC
|
||||
tarjan_node_list[v].index = index;
|
||||
tarjan_node_list[v].low_link = index;
|
||||
tarjan_stack.push(v);
|
||||
tarjan_node_list[v].on_stack = true;
|
||||
++index;
|
||||
|
||||
// Traverse outgoing edges
|
||||
for (auto e2 : m_node_based_graph->GetAdjacentEdgeRange(v))
|
||||
{
|
||||
const TarjanDynamicGraph::NodeIterator vprime =
|
||||
m_node_based_graph->GetTarget(e2);
|
||||
if (UINT_MAX == tarjan_node_list[vprime].index)
|
||||
{
|
||||
recursion_stack.emplace(true, TarjanStackFrame(vprime, v));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tarjan_node_list[vprime].on_stack &&
|
||||
tarjan_node_list[vprime].index < tarjan_node_list[v].low_link)
|
||||
{
|
||||
tarjan_node_list[v].low_link = tarjan_node_list[vprime].index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tarjan_node_list[currentFrame.parent].low_link =
|
||||
std::min(tarjan_node_list[currentFrame.parent].low_link,
|
||||
tarjan_node_list[v].low_link);
|
||||
// after recursion, lets do cycle checking
|
||||
// Check if we found a cycle. This is the bottom part of the recursion
|
||||
if (tarjan_node_list[v].low_link == tarjan_node_list[v].index)
|
||||
{
|
||||
NodeID vprime;
|
||||
do
|
||||
{
|
||||
vprime = tarjan_stack.top();
|
||||
tarjan_stack.pop();
|
||||
tarjan_node_list[vprime].on_stack = false;
|
||||
components_index[vprime] = component_index;
|
||||
++size_of_current_component;
|
||||
} while (v != vprime);
|
||||
|
||||
component_size_vector.emplace_back(size_of_current_component);
|
||||
|
||||
if (size_of_current_component > 1000)
|
||||
{
|
||||
SimpleLogger().Write() << "large component [" << component_index
|
||||
<< "]=" << size_of_current_component;
|
||||
}
|
||||
|
||||
++component_index;
|
||||
size_of_current_component = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SimpleLogger().Write() << "identified: " << component_size_vector.size()
|
||||
<< " many components, marking small components";
|
||||
|
||||
unsigned size_one_counter = std::count_if(component_size_vector.begin(),
|
||||
component_size_vector.end(),
|
||||
[] (unsigned value) { return 1 == value;});
|
||||
|
||||
SimpleLogger().Write() << "identified " << size_one_counter << " SCCs of size 1";
|
||||
|
||||
uint64_t total_network_distance = 0;
|
||||
p.reinit(m_node_based_graph->GetNumberOfNodes());
|
||||
NodeID last_u_node = m_node_based_graph->GetNumberOfNodes();
|
||||
for (NodeID u = 0; u < last_u_node; ++u)
|
||||
{
|
||||
p.printIncrement();
|
||||
for (auto e1 : m_node_based_graph->GetAdjacentEdgeRange(u))
|
||||
{
|
||||
if (!m_node_based_graph->GetEdgeData(e1).reversedEdge)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
const TarjanDynamicGraph::NodeIterator v = m_node_based_graph->GetTarget(e1);
|
||||
|
||||
total_network_distance +=
|
||||
100 * FixedPointCoordinate::ApproximateDistance(m_coordinate_list[u].lat,
|
||||
m_coordinate_list[u].lon,
|
||||
m_coordinate_list[v].lat,
|
||||
m_coordinate_list[v].lon);
|
||||
|
||||
if (SHRT_MAX != m_node_based_graph->GetEdgeData(e1).type)
|
||||
{
|
||||
BOOST_ASSERT(e1 != UINT_MAX);
|
||||
BOOST_ASSERT(u != UINT_MAX);
|
||||
BOOST_ASSERT(v != UINT_MAX);
|
||||
|
||||
const unsigned size_of_containing_component =
|
||||
std::min(component_size_vector[components_index[u]],
|
||||
component_size_vector[components_index[v]]);
|
||||
|
||||
// edges that end on bollard nodes may actually be in two distinct components
|
||||
if (size_of_containing_component < 10)
|
||||
{
|
||||
OGRLineString lineString;
|
||||
lineString.addPoint(m_coordinate_list[u].lon / COORDINATE_PRECISION,
|
||||
m_coordinate_list[u].lat / COORDINATE_PRECISION);
|
||||
lineString.addPoint(m_coordinate_list[v].lon / COORDINATE_PRECISION,
|
||||
m_coordinate_list[v].lat / COORDINATE_PRECISION);
|
||||
|
||||
OGRFeature *poFeature = OGRFeature::CreateFeature(poLayer->GetLayerDefn());
|
||||
|
||||
poFeature->SetGeometry(&lineString);
|
||||
if (OGRERR_NONE != poLayer->CreateFeature(poFeature))
|
||||
{
|
||||
throw OSRMException("Failed to create feature in shapefile.");
|
||||
}
|
||||
OGRFeature::DestroyFeature(poFeature);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
OGRDataSource::DestroyDataSource(poDS);
|
||||
std::vector<NodeID>().swap(component_size_vector);
|
||||
BOOST_ASSERT_MSG(0 == component_size_vector.size() && 0 == component_size_vector.capacity(),
|
||||
"component_size_vector not properly deallocated");
|
||||
|
||||
std::vector<NodeID>().swap(components_index);
|
||||
BOOST_ASSERT_MSG(0 == components_index.size() && 0 == components_index.capacity(),
|
||||
"icomponents_index not properly deallocated");
|
||||
|
||||
SimpleLogger().Write() << "total network distance: " << (uint64_t)total_network_distance /
|
||||
100 / 1000. << " km";
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned CheckForEmanatingIsOnlyTurn(const NodeID u, const NodeID v) const
|
||||
{
|
||||
std::pair<NodeID, NodeID> restriction_source = {u, v};
|
||||
RestrictionMap::const_iterator restriction_iterator =
|
||||
m_restriction_map.find(restriction_source);
|
||||
if (restriction_iterator != m_restriction_map.end())
|
||||
{
|
||||
const unsigned index = restriction_iterator->second;
|
||||
for (const RestrictionSource &restriction_target : m_restriction_bucket_list.at(index))
|
||||
{
|
||||
if (restriction_target.second)
|
||||
{
|
||||
return restriction_target.first;
|
||||
}
|
||||
}
|
||||
}
|
||||
return UINT_MAX;
|
||||
}
|
||||
|
||||
bool CheckIfTurnIsRestricted(const NodeID u, const NodeID v, const NodeID w) const
|
||||
{
|
||||
// only add an edge if turn is not a U-turn except it is the end of dead-end street.
|
||||
std::pair<NodeID, NodeID> restriction_source = {u, v};
|
||||
RestrictionMap::const_iterator restriction_iterator =
|
||||
m_restriction_map.find(restriction_source);
|
||||
if (restriction_iterator != m_restriction_map.end())
|
||||
{
|
||||
const unsigned index = restriction_iterator->second;
|
||||
for (const restriction_target &restriction_target : m_restriction_bucket_list.at(index))
|
||||
{
|
||||
if (w == restriction_target.first)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void DeleteFileIfExists(const std::string &file_name) const
|
||||
{
|
||||
if (boost::filesystem::exists(file_name))
|
||||
{
|
||||
boost::filesystem::remove(file_name);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* STRONGLYCONNECTEDCOMPONENTS_H_ */
|
||||
+121
-73
@@ -1,4 +1,11 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
cmake_minimum_required(VERSION 2.8.8)
|
||||
|
||||
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE)
|
||||
message(FATAL_ERROR "In-source builds are not allowed.
|
||||
Please create a directory and run cmake from there, passing the path to this source directory as the last argument.
|
||||
This process created the file `CMakeCache.txt' and the directory `CMakeFiles'. Please delete them.")
|
||||
endif()
|
||||
|
||||
project(OSRM)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
include(CheckCXXCompilerFlag)
|
||||
@@ -20,43 +27,56 @@ if (WIN32 AND MSVC_VERSION LESS 1800)
|
||||
message(FATAL_ERROR "Building with Microsoft compiler needs Visual Studio 2013 or later (Express version works too)")
|
||||
endif()
|
||||
|
||||
OPTION(WITH_TOOLS "Build ORSM tools" OFF)
|
||||
OPTION(WITH_TOOLS "Build OSRM tools" OFF)
|
||||
OPTION(BUILD_TOOLS "Build OSRM tools" OFF)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/Include/)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/third_party/)
|
||||
|
||||
add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/Util/FingerPrint.cpp FingerPrint.cpp.alwaysbuild
|
||||
add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/Util/finger_print.cpp finger_print.cpp.alwaysbuild
|
||||
COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_SOURCE_DIR}
|
||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/FingerPrint-Config.cmake
|
||||
DEPENDS
|
||||
${CMAKE_SOURCE_DIR}/Util/FingerPrint.cpp.in
|
||||
COMMENT "Configuring FingerPrint.cpp"
|
||||
${CMAKE_SOURCE_DIR}/Util/finger_print.cpp.in
|
||||
COMMENT "Configuring finger_print.cpp"
|
||||
VERBATIM)
|
||||
|
||||
add_custom_target(FingerPrintConfigure DEPENDS ${CMAKE_SOURCE_DIR}/Util/FingerPrint.cpp)
|
||||
add_custom_target(FingerPrintConfigure DEPENDS ${CMAKE_SOURCE_DIR}/Util/finger_print.cpp)
|
||||
add_custom_target(tests DEPENDS datastructure-tests algorithm-tests)
|
||||
add_custom_target(benchmarks DEPENDS rtree-bench)
|
||||
|
||||
set(BOOST_COMPONENTS date_time filesystem iostreams program_options regex system thread)
|
||||
set(BOOST_COMPONENTS date_time filesystem iostreams program_options regex system thread unit_test_framework)
|
||||
|
||||
configure_file(
|
||||
${CMAKE_SOURCE_DIR}/Util/GitDescription.cpp.in
|
||||
${CMAKE_SOURCE_DIR}/Util/GitDescription.cpp
|
||||
${CMAKE_SOURCE_DIR}/Util/git_sha.cpp.in
|
||||
${CMAKE_SOURCE_DIR}/Util/git_sha.cpp
|
||||
)
|
||||
file(GLOB ExtractorGlob Extractor/*.cpp)
|
||||
file(GLOB ImporterGlob DataStructures/Import*.cpp)
|
||||
add_library(IMPORT STATIC ${ImporterGlob})
|
||||
set(ExtractorSources extractor.cpp ${ExtractorGlob})
|
||||
add_executable(osrm-extract ${ExtractorSources})
|
||||
file(GLOB ExtractorGlob extractor/*.cpp)
|
||||
file(GLOB ImporterGlob data_structures/import_edge.cpp data_structures/external_memory_node.cpp)
|
||||
add_library(IMPORT OBJECT ${ImporterGlob})
|
||||
add_library(LOGGER OBJECT Util/simple_logger.cpp)
|
||||
add_library(PHANTOMNODE OBJECT data_structures/phantom_node.cpp)
|
||||
add_library(EXCEPTION OBJECT Util/osrm_exception.cpp)
|
||||
|
||||
file(GLOB PrepareGlob Contractor/*.cpp DataStructures/HilbertValue.cpp DataStructures/RestrictionMap.cpp)
|
||||
set(ExtractorSources extract.cpp ${ExtractorGlob})
|
||||
add_executable(osrm-extract ${ExtractorSources} $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:IMPORT> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:EXCEPTION>)
|
||||
|
||||
add_library(RESTRICTION OBJECT data_structures/restriction_map.cpp)
|
||||
|
||||
file(GLOB PrepareGlob contractor/*.cpp data_structures/hilbert_value.cpp Util/compute_angle.cpp {RestrictionMapGlob})
|
||||
set(PrepareSources prepare.cpp ${PrepareGlob})
|
||||
add_executable(osrm-prepare ${PrepareSources})
|
||||
add_executable(osrm-prepare ${PrepareSources} $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:IMPORT> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:RESTRICTION> $<TARGET_OBJECTS:EXCEPTION>)
|
||||
|
||||
file(GLOB ServerGlob Server/*.cpp)
|
||||
file(GLOB DescriptorGlob Descriptors/*.cpp)
|
||||
file(GLOB DatastructureGlob DataStructures/SearchEngineData.cpp DataStructures/RouteParameters.cpp)
|
||||
file(GLOB CoordinateGlob DataStructures/Coordinate.cpp)
|
||||
file(GLOB AlgorithmGlob Algorithms/*.cpp)
|
||||
file(GLOB DescriptorGlob descriptors/*.cpp)
|
||||
file(GLOB DatastructureGlob data_structures/search_engine_data.cpp data_structures/route_parameters.cpp Util/bearing.cpp)
|
||||
list(REMOVE_ITEM DatastructureGlob data_structures/Coordinate.cpp)
|
||||
file(GLOB CoordinateGlob data_structures/Coordinate.cpp)
|
||||
file(GLOB AlgorithmGlob algorithms/*.cpp)
|
||||
file(GLOB HttpGlob Server/Http/*.cpp)
|
||||
file(GLOB LibOSRMGlob Library/*.cpp)
|
||||
file(GLOB DataStructureTestsGlob UnitTests/data_structures/*.cpp data_structures/hilbert_value.cpp)
|
||||
file(GLOB AlgorithmTestsGlob UnitTests/Algorithms/*.cpp)
|
||||
|
||||
set(
|
||||
OSRMSources
|
||||
@@ -67,14 +87,21 @@ set(
|
||||
${AlgorithmGlob}
|
||||
${HttpGlob}
|
||||
)
|
||||
add_library(COORDLIB STATIC ${CoordinateGlob})
|
||||
add_library(FINGERPRINT STATIC Util/FingerPrint.cpp)
|
||||
add_library(OSRM ${OSRMSources} Util/GitDescription.cpp Util/FingerPrint.cpp)
|
||||
add_library(GITDESCRIPTION STATIC Util/GitDescription.cpp)
|
||||
add_library(COORDINATE OBJECT ${CoordinateGlob})
|
||||
add_library(FINGERPRINT OBJECT Util/finger_print.cpp)
|
||||
add_library(GITDESCRIPTION OBJECT Util/git_sha.cpp)
|
||||
add_library(OSRM ${OSRMSources} $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:PHANTOMNODE> $<TARGET_OBJECTS:EXCEPTION>)
|
||||
add_dependencies(FINGERPRINT FingerPrintConfigure)
|
||||
|
||||
add_executable(osrm-routed routed.cpp ${ServerGlob})
|
||||
add_executable(osrm-datastore datastore.cpp)
|
||||
add_executable(osrm-routed routed.cpp ${ServerGlob} $<TARGET_OBJECTS:EXCEPTION>)
|
||||
add_executable(osrm-datastore datastore.cpp $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:EXCEPTION>)
|
||||
|
||||
# Unit tests
|
||||
add_executable(datastructure-tests EXCLUDE_FROM_ALL UnitTests/datastructure_tests.cpp ${DataStructureTestsGlob} $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:PHANTOMNODE> $<TARGET_OBJECTS:EXCEPTION>)
|
||||
add_executable(algorithm-tests EXCLUDE_FROM_ALL UnitTests/algorithm_tests.cpp ${AlgorithmTestsGlob} $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:PHANTOMNODE> $<TARGET_OBJECTS:EXCEPTION>)
|
||||
|
||||
# Benchmarks
|
||||
add_executable(rtree-bench EXCLUDE_FROM_ALL benchmarks/static_rtree.cpp $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:PHANTOMNODE> $<TARGET_OBJECTS:EXCEPTION>)
|
||||
|
||||
# Check the release mode
|
||||
if(NOT CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
@@ -98,7 +125,7 @@ if(CMAKE_BUILD_TYPE MATCHES Release)
|
||||
|
||||
# Since gcc 4.9 the LTO format is non-standart ('slim'), so we need to use the build-in tools
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND
|
||||
NOT "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "4.9.0")
|
||||
NOT "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "4.9.0" AND NOT MINGW)
|
||||
message(STATUS "Using gcc specific binutils for LTO.")
|
||||
set(CMAKE_AR "/usr/bin/gcc-ar")
|
||||
set(CMAKE_RANLIB "/usr/bin/gcc-ranlib")
|
||||
@@ -106,18 +133,27 @@ if(CMAKE_BUILD_TYPE MATCHES Release)
|
||||
endif (HAS_LTO_FLAG)
|
||||
endif()
|
||||
|
||||
if (NOT WIN32)
|
||||
add_definitions(-DBOOST_TEST_DYN_LINK)
|
||||
endif()
|
||||
|
||||
# Configuring compilers
|
||||
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
# using Clang
|
||||
# -Weverything -Wno-c++98-compat -Wno-shadow -Wno-exit-time-destructors
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wunreachable-code -pedantic -fPIC")
|
||||
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
set(COLOR_FLAG "-fdiagnostics-color=auto")
|
||||
CHECK_CXX_COMPILER_FLAG("-fdiagnostics-color=auto" HAS_COLOR_FLAG)
|
||||
if(NOT HAS_COLOR_FLAG)
|
||||
set(COLOR_FLAG "")
|
||||
endif()
|
||||
# using GCC
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -fPIC")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -fPIC ${COLOR_FLAG}")
|
||||
if (WIN32) # using mingw
|
||||
add_definitions(-DM_PI=3.141592653589793238462643383) # define M_PI
|
||||
add_definitions(-D_USE_MATH_DEFINES) # define M_PI, M_1_PI etc.
|
||||
add_definitions(-DWIN32)
|
||||
SET(OPTIONAL_SOCKET_LIBS ws2_32 wsock32)
|
||||
SET(OPTIONAL_OMP_LIB gomp)
|
||||
endif()
|
||||
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
|
||||
# using Intel C++
|
||||
@@ -129,20 +165,11 @@ elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
add_definitions(-DNOMINMAX) # avoid min and max macros that can break compilation
|
||||
add_definitions(-D_USE_MATH_DEFINES) # define M_PI
|
||||
add_definitions(-D_WIN32_WINNT=0x0501)
|
||||
add_definitions(-DXML_STATIC)
|
||||
find_library(ws2_32_LIBRARY_PATH ws2_32)
|
||||
target_link_libraries(osrm-extract wsock32 ws2_32)
|
||||
endif()
|
||||
|
||||
# disable partitioning of LTO process when possible (fixes Debian issues)
|
||||
set(LTO_PARTITION_FLAGS "")
|
||||
CHECK_CXX_COMPILER_FLAG("-flto-partition=none" HAS_LTO_PARTITION_FLAG)
|
||||
if (HAS_LTO_PARTITION_FLAG)
|
||||
set(LTO_PARTITION_FLAGS "${LTO_PARTITION_FLAGS} -flto-partition=none")
|
||||
endif (HAS_LTO_PARTITION_FLAG)
|
||||
|
||||
# Add Link-Time-Optimization flags, if supported (GCC >= 4.7) and enabled
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LTO_FLAGS}")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LTO_FLAGS} ${LTO_PARTITION_FLAGS}")
|
||||
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${LTO_FLAGS} ${LTO_PARTITION_FLAGS}")
|
||||
|
||||
# Activate C++11
|
||||
if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
ADD_DEFINITIONS(-std=c++11)
|
||||
@@ -177,16 +204,23 @@ if(NOT Boost_FOUND)
|
||||
endif()
|
||||
include_directories(${Boost_INCLUDE_DIRS})
|
||||
|
||||
target_link_libraries(OSRM ${Boost_LIBRARIES} COORDLIB)
|
||||
target_link_libraries(osrm-extract ${Boost_LIBRARIES} FINGERPRINT GITDESCRIPTION COORDLIB IMPORT)
|
||||
target_link_libraries(osrm-prepare ${Boost_LIBRARIES} FINGERPRINT GITDESCRIPTION COORDLIB IMPORT)
|
||||
target_link_libraries(osrm-routed ${Boost_LIBRARIES} ${OPTIONAL_SOCKET_LIBS} OSRM FINGERPRINT GITDESCRIPTION)
|
||||
target_link_libraries(osrm-datastore ${Boost_LIBRARIES} FINGERPRINT GITDESCRIPTION COORDLIB)
|
||||
target_link_libraries(OSRM ${Boost_LIBRARIES})
|
||||
target_link_libraries(osrm-extract ${Boost_LIBRARIES})
|
||||
target_link_libraries(osrm-prepare ${Boost_LIBRARIES})
|
||||
target_link_libraries(osrm-routed ${Boost_LIBRARIES} ${OPTIONAL_SOCKET_LIBS} OSRM)
|
||||
target_link_libraries(osrm-datastore ${Boost_LIBRARIES})
|
||||
target_link_libraries(datastructure-tests ${Boost_LIBRARIES})
|
||||
target_link_libraries(algorithm-tests ${Boost_LIBRARIES} ${OPTIONAL_SOCKET_LIBS} OSRM)
|
||||
target_link_libraries(rtree-bench ${Boost_LIBRARIES})
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(osrm-extract ${CMAKE_THREAD_LIBS_INIT} ${OPTIONAL_OMP_LIB})
|
||||
target_link_libraries(osrm-extract ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(osrm-datastore ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(osrm-prepare ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(OSRM ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(datastructure-tests ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(algorithm-tests ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(rtree-bench ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
find_package(TBB REQUIRED)
|
||||
if(WIN32 AND CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
@@ -196,21 +230,14 @@ target_link_libraries(osrm-datastore ${TBB_LIBRARIES})
|
||||
target_link_libraries(osrm-extract ${TBB_LIBRARIES})
|
||||
target_link_libraries(osrm-prepare ${TBB_LIBRARIES})
|
||||
target_link_libraries(osrm-routed ${TBB_LIBRARIES})
|
||||
target_link_libraries(datastructure-tests ${TBB_LIBRARIES})
|
||||
target_link_libraries(algorithm-tests ${TBB_LIBRARIES})
|
||||
target_link_libraries(rtree-bench ${TBB_LIBRARIES})
|
||||
include_directories(${TBB_INCLUDE_DIR})
|
||||
|
||||
find_package(Lua52)
|
||||
if(NOT LUA52_FOUND)
|
||||
find_package(Lua51 REQUIRED)
|
||||
if(NOT APPLE)
|
||||
find_package(LuaJIT 5.1)
|
||||
endif()
|
||||
else()
|
||||
if(NOT APPLE)
|
||||
find_package(LuaJIT 5.2)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
find_package( Luabind REQUIRED )
|
||||
include(check_luabind)
|
||||
|
||||
include_directories(${LUABIND_INCLUDE_DIR})
|
||||
target_link_libraries(osrm-extract ${LUABIND_LIBRARY})
|
||||
target_link_libraries(osrm-prepare ${LUABIND_LIBRARY})
|
||||
@@ -224,9 +251,9 @@ else()
|
||||
endif()
|
||||
include_directories(${LUA_INCLUDE_DIR})
|
||||
|
||||
find_package(LibXml2 REQUIRED)
|
||||
include_directories(${LIBXML2_INCLUDE_DIR})
|
||||
target_link_libraries(osrm-extract ${LIBXML2_LIBRARIES})
|
||||
find_package(EXPAT REQUIRED)
|
||||
include_directories(${EXPAT_INCLUDE_DIRS})
|
||||
target_link_libraries(osrm-extract ${EXPAT_LIBRARIES})
|
||||
|
||||
find_package( STXXL REQUIRED )
|
||||
include_directories(${STXXL_INCLUDE_DIR})
|
||||
@@ -234,6 +261,11 @@ target_link_libraries(OSRM ${STXXL_LIBRARY})
|
||||
target_link_libraries(osrm-extract ${STXXL_LIBRARY})
|
||||
target_link_libraries(osrm-prepare ${STXXL_LIBRARY})
|
||||
|
||||
if(MINGW)
|
||||
# STXXL needs OpenMP library
|
||||
target_link_libraries(osrm-extract gomp)
|
||||
endif()
|
||||
|
||||
find_package( OSMPBF REQUIRED )
|
||||
include_directories(${OSMPBF_INCLUDE_DIR})
|
||||
target_link_libraries(osrm-extract ${OSMPBF_LIBRARY})
|
||||
@@ -253,29 +285,40 @@ include_directories(${ZLIB_INCLUDE_DIRS})
|
||||
target_link_libraries(osrm-extract ${ZLIB_LIBRARY})
|
||||
target_link_libraries(osrm-routed ${ZLIB_LIBRARY})
|
||||
|
||||
if(WITH_TOOLS)
|
||||
if(WITH_TOOLS OR BUILD_TOOLS)
|
||||
message(STATUS "Activating OSRM internal tools")
|
||||
find_package(GDAL)
|
||||
if(GDAL_FOUND)
|
||||
add_executable(osrm-components Tools/components.cpp)
|
||||
target_link_libraries(osrm-components ${TBB_LIBRARIES} IMPORT)
|
||||
add_executable(osrm-components tools/components.cpp $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:IMPORT> $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:RESTRICTION> $<TARGET_OBJECTS:EXCEPTION>)
|
||||
target_link_libraries(osrm-components ${TBB_LIBRARIES})
|
||||
include_directories(${GDAL_INCLUDE_DIR})
|
||||
target_link_libraries(
|
||||
osrm-components
|
||||
${GDAL_LIBRARIES} ${Boost_LIBRARIES} FINGERPRINT GITDESCRIPTION COORDLIB)
|
||||
${GDAL_LIBRARIES} ${Boost_LIBRARIES})
|
||||
install(TARGETS osrm-components DESTINATION bin)
|
||||
else()
|
||||
message(FATAL_ERROR "libgdal and/or development headers not found")
|
||||
endif()
|
||||
add_executable(osrm-cli Tools/simpleclient.cpp)
|
||||
target_link_libraries(osrm-cli ${Boost_LIBRARIES} ${OPTIONAL_SOCKET_LIBS} OSRM FINGERPRINT GITDESCRIPTION)
|
||||
add_executable(osrm-cli tools/simpleclient.cpp $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:LOGGER>)
|
||||
target_link_libraries(osrm-cli ${Boost_LIBRARIES} ${OPTIONAL_SOCKET_LIBS} OSRM)
|
||||
target_link_libraries(osrm-cli ${TBB_LIBRARIES})
|
||||
add_executable(osrm-io-benchmark Tools/io-benchmark.cpp)
|
||||
target_link_libraries(osrm-io-benchmark ${Boost_LIBRARIES} GITDESCRIPTION)
|
||||
add_executable(osrm-unlock-all Tools/unlock_all_mutexes.cpp)
|
||||
target_link_libraries(osrm-unlock-all ${Boost_LIBRARIES} GITDESCRIPTION)
|
||||
add_executable(osrm-io-benchmark tools/io-benchmark.cpp $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:LOGGER>)
|
||||
target_link_libraries(osrm-io-benchmark ${Boost_LIBRARIES})
|
||||
add_executable(osrm-unlock-all tools/unlock_all_mutexes.cpp $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:EXCEPTION>)
|
||||
target_link_libraries(osrm-unlock-all ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
|
||||
if(UNIX AND NOT APPLE)
|
||||
target_link_libraries(osrm-unlock-all rt)
|
||||
endif()
|
||||
add_executable(osrm-check-hsgr tools/check-hsgr.cpp $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:LOGGER>)
|
||||
target_link_libraries(osrm-check-hsgr ${Boost_LIBRARIES})
|
||||
add_executable(osrm-springclean tools/springclean.cpp $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:EXCEPTION>)
|
||||
target_link_libraries(osrm-springclean ${Boost_LIBRARIES})
|
||||
|
||||
install(TARGETS osrm-cli DESTINATION bin)
|
||||
install(TARGETS osrm-io-benchmark DESTINATION bin)
|
||||
install(TARGETS osrm-unlock-all DESTINATION bin)
|
||||
install(TARGETS osrm-check-hsgr DESTINATION bin)
|
||||
install(TARGETS osrm-springclean DESTINATION bin)
|
||||
endif()
|
||||
|
||||
file(GLOB InstallGlob Include/osrm/*.h Library/OSRM.h)
|
||||
@@ -305,3 +348,8 @@ endforeach ()
|
||||
|
||||
configure_file(${CMAKE_SOURCE_DIR}/cmake/pkgconfig.in libosrm.pc @ONLY)
|
||||
install(FILES ${PROJECT_BINARY_DIR}/libosrm.pc DESTINATION lib/pkgconfig)
|
||||
|
||||
if(BUILD_DEBIAN_PACKAGE)
|
||||
include(CPackDebianConfig)
|
||||
include(CPack)
|
||||
endif()
|
||||
|
||||
@@ -1,172 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "TemporaryStorage.h"
|
||||
|
||||
StreamData::StreamData()
|
||||
: write_mode(true),
|
||||
temp_path(boost::filesystem::unique_path(temp_directory / TemporaryFilePattern)),
|
||||
temp_file(new boost::filesystem::fstream(
|
||||
temp_path, std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary)),
|
||||
readWriteMutex(std::make_shared<boost::mutex>())
|
||||
{
|
||||
if (temp_file->fail())
|
||||
{
|
||||
throw OSRMException("temporary file could not be created");
|
||||
}
|
||||
}
|
||||
|
||||
TemporaryStorage::TemporaryStorage() { temp_directory = boost::filesystem::temp_directory_path(); }
|
||||
|
||||
TemporaryStorage &TemporaryStorage::GetInstance()
|
||||
{
|
||||
static TemporaryStorage static_instance;
|
||||
return static_instance;
|
||||
}
|
||||
|
||||
TemporaryStorage::~TemporaryStorage() { RemoveAll(); }
|
||||
|
||||
void TemporaryStorage::RemoveAll()
|
||||
{
|
||||
boost::mutex::scoped_lock lock(mutex);
|
||||
for (unsigned slot_id = 0; slot_id < stream_data_list.size(); ++slot_id)
|
||||
{
|
||||
DeallocateSlot(slot_id);
|
||||
}
|
||||
stream_data_list.clear();
|
||||
}
|
||||
|
||||
int TemporaryStorage::AllocateSlot()
|
||||
{
|
||||
boost::mutex::scoped_lock lock(mutex);
|
||||
try { stream_data_list.push_back(StreamData()); }
|
||||
catch (boost::filesystem::filesystem_error &e) { Abort(e); }
|
||||
CheckIfTemporaryDeviceFull();
|
||||
return stream_data_list.size() - 1;
|
||||
}
|
||||
|
||||
void TemporaryStorage::DeallocateSlot(const int slot_id)
|
||||
{
|
||||
try
|
||||
{
|
||||
StreamData &data = stream_data_list[slot_id];
|
||||
boost::mutex::scoped_lock lock(*data.readWriteMutex);
|
||||
if (!boost::filesystem::exists(data.temp_path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (data.temp_file->is_open())
|
||||
{
|
||||
data.temp_file->close();
|
||||
}
|
||||
|
||||
boost::filesystem::remove(data.temp_path);
|
||||
}
|
||||
catch (boost::filesystem::filesystem_error &e) { Abort(e); }
|
||||
}
|
||||
|
||||
void TemporaryStorage::WriteToSlot(const int slot_id, char *pointer, const std::size_t size)
|
||||
{
|
||||
try
|
||||
{
|
||||
StreamData &data = stream_data_list[slot_id];
|
||||
BOOST_ASSERT(data.write_mode);
|
||||
|
||||
boost::mutex::scoped_lock lock(*data.readWriteMutex);
|
||||
BOOST_ASSERT_MSG(data.write_mode, "Writing after first read is not allowed");
|
||||
if (1073741824 < data.buffer.size())
|
||||
{
|
||||
data.temp_file->write(&data.buffer[0], data.buffer.size());
|
||||
// data.temp_file->write(pointer, size);
|
||||
data.buffer.clear();
|
||||
CheckIfTemporaryDeviceFull();
|
||||
}
|
||||
data.buffer.insert(data.buffer.end(), pointer, pointer + size);
|
||||
}
|
||||
catch (boost::filesystem::filesystem_error &e) { Abort(e); }
|
||||
}
|
||||
void TemporaryStorage::ReadFromSlot(const int slot_id, char *pointer, const std::size_t size)
|
||||
{
|
||||
try
|
||||
{
|
||||
StreamData &data = stream_data_list[slot_id];
|
||||
boost::mutex::scoped_lock lock(*data.readWriteMutex);
|
||||
if (data.write_mode)
|
||||
{
|
||||
data.write_mode = false;
|
||||
data.temp_file->write(&data.buffer[0], data.buffer.size());
|
||||
data.buffer.clear();
|
||||
data.temp_file->seekg(data.temp_file->beg);
|
||||
BOOST_ASSERT(data.temp_file->beg == data.temp_file->tellg());
|
||||
}
|
||||
BOOST_ASSERT(!data.write_mode);
|
||||
data.temp_file->read(pointer, size);
|
||||
}
|
||||
catch (boost::filesystem::filesystem_error &error) { Abort(error); }
|
||||
}
|
||||
|
||||
uint64_t TemporaryStorage::GetFreeBytesOnTemporaryDevice()
|
||||
{
|
||||
uint64_t value = -1;
|
||||
try
|
||||
{
|
||||
boost::filesystem::path path = boost::filesystem::temp_directory_path();
|
||||
boost::filesystem::space_info space_info = boost::filesystem::space(path);
|
||||
value = space_info.free;
|
||||
}
|
||||
catch (boost::filesystem::filesystem_error &error) { Abort(error); }
|
||||
return value;
|
||||
}
|
||||
|
||||
void TemporaryStorage::CheckIfTemporaryDeviceFull()
|
||||
{
|
||||
boost::filesystem::path path = boost::filesystem::temp_directory_path();
|
||||
boost::filesystem::space_info space_info = boost::filesystem::space(path);
|
||||
if ((1024 * 1024) > space_info.free)
|
||||
{
|
||||
throw OSRMException("temporary device is full");
|
||||
}
|
||||
}
|
||||
|
||||
boost::filesystem::fstream::pos_type TemporaryStorage::Tell(const int slot_id)
|
||||
{
|
||||
boost::filesystem::fstream::pos_type position;
|
||||
try
|
||||
{
|
||||
StreamData &data = stream_data_list[slot_id];
|
||||
boost::mutex::scoped_lock lock(*data.readWriteMutex);
|
||||
position = data.temp_file->tellp();
|
||||
}
|
||||
catch (boost::filesystem::filesystem_error &e) { Abort(e); }
|
||||
return position;
|
||||
}
|
||||
|
||||
void TemporaryStorage::Abort(const boost::filesystem::filesystem_error &error)
|
||||
{
|
||||
RemoveAll();
|
||||
throw OSRMException(error.what());
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef TEMPORARYSTORAGE_H_
|
||||
#define TEMPORARYSTORAGE_H_
|
||||
|
||||
#include "../Util/BoostFileSystemFix.h"
|
||||
#include "../Util/OSRMException.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
|
||||
struct StreamData
|
||||
{
|
||||
bool write_mode;
|
||||
boost::filesystem::path temp_path;
|
||||
std::shared_ptr<boost::filesystem::fstream> temp_file;
|
||||
std::shared_ptr<boost::mutex> readWriteMutex;
|
||||
std::vector<char> buffer;
|
||||
|
||||
StreamData();
|
||||
};
|
||||
|
||||
// This class implements a singleton file storage for temporary data.
|
||||
// temporary slots can be accessed by other objects through an int
|
||||
// On deallocation every slot gets deallocated
|
||||
//
|
||||
// Access is sequential, which means, that there is no random access
|
||||
// -> Data is written in first phase and reread in second.
|
||||
|
||||
static boost::filesystem::path temp_directory;
|
||||
static std::string TemporaryFilePattern("OSRM-%%%%-%%%%-%%%%");
|
||||
class TemporaryStorage
|
||||
{
|
||||
public:
|
||||
static TemporaryStorage &GetInstance();
|
||||
virtual ~TemporaryStorage();
|
||||
|
||||
int AllocateSlot();
|
||||
void DeallocateSlot(const int slot_id);
|
||||
void WriteToSlot(const int slot_id, char *pointer, const std::size_t size);
|
||||
void ReadFromSlot(const int slot_id, char *pointer, const std::size_t size);
|
||||
// returns the number of free bytes
|
||||
uint64_t GetFreeBytesOnTemporaryDevice();
|
||||
boost::filesystem::fstream::pos_type Tell(const int slot_id);
|
||||
void RemoveAll();
|
||||
|
||||
private:
|
||||
TemporaryStorage();
|
||||
TemporaryStorage(TemporaryStorage const &) {};
|
||||
|
||||
TemporaryStorage &operator=(TemporaryStorage const &) { return *this; }
|
||||
|
||||
void Abort(const boost::filesystem::filesystem_error &e);
|
||||
void CheckIfTemporaryDeviceFull();
|
||||
|
||||
// vector of file streams that is used to store temporary data
|
||||
boost::mutex mutex;
|
||||
std::vector<StreamData> stream_data_list;
|
||||
};
|
||||
|
||||
#endif /* TEMPORARYSTORAGE_H_ */
|
||||
@@ -1,401 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef DEALLOCATINGVECTOR_H_
|
||||
#define DEALLOCATINGVECTOR_H_
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
template <typename ElementT,
|
||||
std::size_t bucketSizeC = 8388608 / sizeof(ElementT),
|
||||
bool DeallocateC = false>
|
||||
class DeallocatingVectorIterator : public std::iterator<std::random_access_iterator_tag, ElementT>
|
||||
{
|
||||
protected:
|
||||
class DeallocatingVectorIteratorState
|
||||
{
|
||||
private:
|
||||
// make constructors explicit, so we do not mix random access and deallocation iterators.
|
||||
DeallocatingVectorIteratorState();
|
||||
|
||||
public:
|
||||
explicit DeallocatingVectorIteratorState(const DeallocatingVectorIteratorState &r)
|
||||
: index(r.index), bucket_list(r.bucket_list)
|
||||
{
|
||||
}
|
||||
explicit DeallocatingVectorIteratorState(const std::size_t idx,
|
||||
std::vector<ElementT *> &input_list)
|
||||
: index(idx), bucket_list(input_list)
|
||||
{
|
||||
}
|
||||
std::size_t index;
|
||||
std::vector<ElementT *> &bucket_list;
|
||||
|
||||
inline bool operator!=(const DeallocatingVectorIteratorState &other)
|
||||
{
|
||||
return index != other.index;
|
||||
}
|
||||
|
||||
inline bool operator==(const DeallocatingVectorIteratorState &other)
|
||||
{
|
||||
return index == other.index;
|
||||
}
|
||||
|
||||
bool operator<(const DeallocatingVectorIteratorState &other) const
|
||||
{
|
||||
return index < other.index;
|
||||
}
|
||||
|
||||
bool operator>(const DeallocatingVectorIteratorState &other) const
|
||||
{
|
||||
return index > other.index;
|
||||
}
|
||||
|
||||
bool operator>=(const DeallocatingVectorIteratorState &other) const
|
||||
{
|
||||
return index >= other.index;
|
||||
}
|
||||
|
||||
// This is a hack to make assignment operator possible with reference member
|
||||
inline DeallocatingVectorIteratorState &operator=(const DeallocatingVectorIteratorState &a)
|
||||
{
|
||||
if (this != &a)
|
||||
{
|
||||
this->DeallocatingVectorIteratorState::
|
||||
~DeallocatingVectorIteratorState(); // explicit non-virtual destructor
|
||||
new (this) DeallocatingVectorIteratorState(a); // placement new
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
DeallocatingVectorIteratorState current_state;
|
||||
|
||||
public:
|
||||
typedef std::random_access_iterator_tag iterator_category;
|
||||
typedef typename std::iterator<std::random_access_iterator_tag, ElementT>::value_type
|
||||
value_type;
|
||||
typedef typename std::iterator<std::random_access_iterator_tag, ElementT>::difference_type
|
||||
difference_type;
|
||||
typedef typename std::iterator<std::random_access_iterator_tag, ElementT>::reference reference;
|
||||
typedef typename std::iterator<std::random_access_iterator_tag, ElementT>::pointer pointer;
|
||||
|
||||
DeallocatingVectorIterator() {}
|
||||
|
||||
template <typename T2>
|
||||
explicit DeallocatingVectorIterator(const DeallocatingVectorIterator<T2> &r)
|
||||
: current_state(r.current_state)
|
||||
{
|
||||
}
|
||||
|
||||
DeallocatingVectorIterator(std::size_t idx, std::vector<ElementT *> &input_list)
|
||||
: current_state(idx, input_list)
|
||||
{
|
||||
}
|
||||
explicit DeallocatingVectorIterator(const DeallocatingVectorIteratorState &r) : current_state(r) {}
|
||||
|
||||
template <typename T2>
|
||||
DeallocatingVectorIterator &operator=(const DeallocatingVectorIterator<T2> &r)
|
||||
{
|
||||
if (DeallocateC)
|
||||
{
|
||||
BOOST_ASSERT(false);
|
||||
}
|
||||
current_state = r.current_state;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline DeallocatingVectorIterator &operator++()
|
||||
{ // prefix
|
||||
++current_state.index;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline DeallocatingVectorIterator &operator--()
|
||||
{ // prefix
|
||||
if (DeallocateC)
|
||||
{
|
||||
BOOST_ASSERT(false);
|
||||
}
|
||||
--current_state.index;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline DeallocatingVectorIterator operator++(int)
|
||||
{ // postfix
|
||||
DeallocatingVectorIteratorState my_state(current_state);
|
||||
current_state.index++;
|
||||
return DeallocatingVectorIterator(my_state);
|
||||
}
|
||||
inline DeallocatingVectorIterator operator--(int)
|
||||
{ // postfix
|
||||
if (DeallocateC)
|
||||
{
|
||||
BOOST_ASSERT(false);
|
||||
}
|
||||
DeallocatingVectorIteratorState my_state(current_state);
|
||||
current_state.index--;
|
||||
return DeallocatingVectorIterator(my_state);
|
||||
}
|
||||
|
||||
inline DeallocatingVectorIterator operator+(const difference_type &n) const
|
||||
{
|
||||
DeallocatingVectorIteratorState my_state(current_state);
|
||||
my_state.index += n;
|
||||
return DeallocatingVectorIterator(my_state);
|
||||
}
|
||||
|
||||
inline DeallocatingVectorIterator &operator+=(const difference_type &n)
|
||||
{
|
||||
current_state.index += n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline DeallocatingVectorIterator operator-(const difference_type &n) const
|
||||
{
|
||||
if (DeallocateC)
|
||||
{
|
||||
BOOST_ASSERT(false);
|
||||
}
|
||||
DeallocatingVectorIteratorState my_state(current_state);
|
||||
my_state.index -= n;
|
||||
return DeallocatingVectorIterator(my_state);
|
||||
}
|
||||
|
||||
inline DeallocatingVectorIterator &operator-=(const difference_type &n) const
|
||||
{
|
||||
if (DeallocateC)
|
||||
{
|
||||
BOOST_ASSERT(false);
|
||||
}
|
||||
current_state.index -= n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline reference operator*() const
|
||||
{
|
||||
std::size_t current_bucket = current_state.index / bucketSizeC;
|
||||
std::size_t current_index = current_state.index % bucketSizeC;
|
||||
return (current_state.bucket_list[current_bucket][current_index]);
|
||||
}
|
||||
|
||||
inline pointer operator->() const
|
||||
{
|
||||
std::size_t current_bucket = current_state.index / bucketSizeC;
|
||||
std::size_t current_index = current_state.index % bucketSizeC;
|
||||
return &(current_state.bucket_list[current_bucket][current_index]);
|
||||
}
|
||||
|
||||
inline bool operator!=(const DeallocatingVectorIterator &other)
|
||||
{
|
||||
return current_state != other.current_state;
|
||||
}
|
||||
|
||||
inline bool operator==(const DeallocatingVectorIterator &other)
|
||||
{
|
||||
return current_state == other.current_state;
|
||||
}
|
||||
|
||||
inline bool operator<(const DeallocatingVectorIterator &other) const
|
||||
{
|
||||
return current_state < other.current_state;
|
||||
}
|
||||
|
||||
inline bool operator>(const DeallocatingVectorIterator &other) const
|
||||
{
|
||||
return current_state > other.current_state;
|
||||
}
|
||||
|
||||
inline bool operator>=(const DeallocatingVectorIterator &other) const
|
||||
{
|
||||
return current_state >= other.current_state;
|
||||
}
|
||||
|
||||
difference_type operator-(const DeallocatingVectorIterator &other)
|
||||
{
|
||||
if (DeallocateC)
|
||||
{
|
||||
BOOST_ASSERT(false);
|
||||
}
|
||||
return current_state.index - other.current_state.index;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ElementT, std::size_t bucketSizeC = 8388608 / sizeof(ElementT)>
|
||||
class DeallocatingVector
|
||||
{
|
||||
private:
|
||||
std::size_t current_size;
|
||||
std::vector<ElementT *> bucket_list;
|
||||
|
||||
public:
|
||||
typedef ElementT value_type;
|
||||
typedef DeallocatingVectorIterator<ElementT, bucketSizeC, false> iterator;
|
||||
typedef DeallocatingVectorIterator<ElementT, bucketSizeC, false> const_iterator;
|
||||
|
||||
// this iterator deallocates all buckets that have been visited. Iterators to visited objects
|
||||
// become invalid.
|
||||
typedef DeallocatingVectorIterator<ElementT, bucketSizeC, true> deallocation_iterator;
|
||||
|
||||
DeallocatingVector() : current_size(0)
|
||||
{
|
||||
// initial bucket
|
||||
bucket_list.emplace_back(new ElementT[bucketSizeC]);
|
||||
}
|
||||
|
||||
~DeallocatingVector() { clear(); }
|
||||
|
||||
inline void swap(DeallocatingVector<ElementT, bucketSizeC> &other)
|
||||
{
|
||||
std::swap(current_size, other.current_size);
|
||||
bucket_list.swap(other.bucket_list);
|
||||
}
|
||||
|
||||
inline void clear()
|
||||
{
|
||||
// Delete[]'ing ptr's to all Buckets
|
||||
for (unsigned i = 0; i < bucket_list.size(); ++i)
|
||||
{
|
||||
if (nullptr != bucket_list[i])
|
||||
{
|
||||
delete[] bucket_list[i];
|
||||
bucket_list[i] = nullptr;
|
||||
}
|
||||
}
|
||||
// Removing all ptrs from vector
|
||||
std::vector<ElementT *>().swap(bucket_list);
|
||||
current_size = 0;
|
||||
}
|
||||
|
||||
inline void push_back(const ElementT &element)
|
||||
{
|
||||
const std::size_t current_capacity = capacity();
|
||||
if (current_size == current_capacity)
|
||||
{
|
||||
bucket_list.push_back(new ElementT[bucketSizeC]);
|
||||
}
|
||||
|
||||
std::size_t current_index = size() % bucketSizeC;
|
||||
bucket_list.back()[current_index] = element;
|
||||
++current_size;
|
||||
}
|
||||
|
||||
inline void emplace_back(const ElementT &&element)
|
||||
{
|
||||
const std::size_t current_capacity = capacity();
|
||||
if (current_size == current_capacity)
|
||||
{
|
||||
bucket_list.push_back(new ElementT[bucketSizeC]);
|
||||
}
|
||||
|
||||
const std::size_t current_index = size() % bucketSizeC;
|
||||
bucket_list.back()[current_index] = element;
|
||||
++current_size;
|
||||
}
|
||||
|
||||
inline void reserve(const std::size_t) const
|
||||
{
|
||||
// don't do anything
|
||||
}
|
||||
|
||||
inline void resize(const std::size_t new_size)
|
||||
{
|
||||
if (new_size > current_size)
|
||||
{
|
||||
while (capacity() < new_size)
|
||||
{
|
||||
bucket_list.push_back(new ElementT[bucketSizeC]);
|
||||
}
|
||||
current_size = new_size;
|
||||
}
|
||||
if (new_size < current_size)
|
||||
{
|
||||
const std::size_t number_of_necessary_buckets = 1 + (new_size / bucketSizeC);
|
||||
|
||||
for (std::size_t i = number_of_necessary_buckets; i < bucket_list.size(); ++i)
|
||||
{
|
||||
delete[] bucket_list[i];
|
||||
}
|
||||
bucket_list.resize(number_of_necessary_buckets);
|
||||
current_size = new_size;
|
||||
}
|
||||
}
|
||||
|
||||
inline std::size_t size() const { return current_size; }
|
||||
|
||||
inline std::size_t capacity() const { return bucket_list.size() * bucketSizeC; }
|
||||
|
||||
inline iterator begin() { return iterator(static_cast<std::size_t>(0), bucket_list); }
|
||||
|
||||
inline iterator end() { return iterator(size(), bucket_list); }
|
||||
|
||||
inline deallocation_iterator dbegin()
|
||||
{
|
||||
return deallocation_iterator(static_cast<std::size_t>(0), bucket_list);
|
||||
}
|
||||
|
||||
inline deallocation_iterator dend() { return deallocation_iterator(size(), bucket_list); }
|
||||
|
||||
inline const_iterator begin() const
|
||||
{
|
||||
return const_iterator(static_cast<std::size_t>(0), bucket_list);
|
||||
}
|
||||
|
||||
inline const_iterator end() const { return const_iterator(size(), bucket_list); }
|
||||
|
||||
inline ElementT &operator[](const std::size_t index)
|
||||
{
|
||||
std::size_t _bucket = index / bucketSizeC;
|
||||
std::size_t _index = index % bucketSizeC;
|
||||
return (bucket_list[_bucket][_index]);
|
||||
}
|
||||
|
||||
const inline ElementT &operator[](const std::size_t index) const
|
||||
{
|
||||
std::size_t _bucket = index / bucketSizeC;
|
||||
std::size_t _index = index % bucketSizeC;
|
||||
return (bucket_list[_bucket][_index]);
|
||||
}
|
||||
|
||||
inline ElementT &back()
|
||||
{
|
||||
std::size_t _bucket = current_size / bucketSizeC;
|
||||
std::size_t _index = current_size % bucketSizeC;
|
||||
return (bucket_list[_bucket][_index]);
|
||||
}
|
||||
|
||||
const inline ElementT &back() const
|
||||
{
|
||||
std::size_t _bucket = current_size / bucketSizeC;
|
||||
std::size_t _index = current_size % bucketSizeC;
|
||||
return (bucket_list[_bucket][_index]);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* DEALLOCATINGVECTOR_H_ */
|
||||
@@ -1,166 +0,0 @@
|
||||
#ifndef __NODE_BASED_GRAPH_H__
|
||||
#define __NODE_BASED_GRAPH_H__
|
||||
|
||||
#include "DynamicGraph.h"
|
||||
#include "ImportEdge.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
|
||||
#include <tbb/parallel_sort.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
struct NodeBasedEdgeData
|
||||
{
|
||||
NodeBasedEdgeData()
|
||||
: distance(INVALID_EDGE_WEIGHT), edgeBasedNodeID(SPECIAL_NODEID),
|
||||
nameID(std::numeric_limits<unsigned>::max()), type(std::numeric_limits<short>::max()),
|
||||
isAccessRestricted(false), shortcut(false), forward(false), backward(false),
|
||||
roundabout(false), ignore_in_grid(false), contraFlow(false)
|
||||
{
|
||||
}
|
||||
|
||||
int distance;
|
||||
unsigned edgeBasedNodeID;
|
||||
unsigned nameID;
|
||||
short type;
|
||||
bool isAccessRestricted : 1;
|
||||
bool shortcut : 1;
|
||||
bool forward : 1;
|
||||
bool backward : 1;
|
||||
bool roundabout : 1;
|
||||
bool ignore_in_grid : 1;
|
||||
bool contraFlow : 1;
|
||||
|
||||
void SwapDirectionFlags()
|
||||
{
|
||||
bool temp_flag = forward;
|
||||
forward = backward;
|
||||
backward = temp_flag;
|
||||
}
|
||||
|
||||
bool IsEqualTo(const NodeBasedEdgeData &other) const
|
||||
{
|
||||
return (forward == other.forward) && (backward == other.backward) &&
|
||||
(nameID == other.nameID) && (ignore_in_grid == other.ignore_in_grid) &&
|
||||
(contraFlow == other.contraFlow);
|
||||
}
|
||||
};
|
||||
|
||||
typedef DynamicGraph<NodeBasedEdgeData> NodeBasedDynamicGraph;
|
||||
|
||||
// Factory method to create NodeBasedDynamicGraph from ImportEdges
|
||||
inline std::shared_ptr<NodeBasedDynamicGraph>
|
||||
NodeBasedDynamicGraphFromImportEdges(int number_of_nodes, std::vector<ImportEdge> &input_edge_list)
|
||||
{
|
||||
static_assert(sizeof(NodeBasedEdgeData) == 16, "changing node based edge data size changes memory consumption");
|
||||
// tbb::parallel_sort(input_edge_list.begin(), input_edge_list.end());
|
||||
|
||||
DeallocatingVector<NodeBasedDynamicGraph::InputEdge> edges_list;
|
||||
NodeBasedDynamicGraph::InputEdge edge;
|
||||
for (const ImportEdge &import_edge : input_edge_list)
|
||||
{
|
||||
if (import_edge.forward)
|
||||
{
|
||||
edge.source = import_edge.source;
|
||||
edge.target = import_edge.target;
|
||||
edge.data.forward = import_edge.forward;
|
||||
edge.data.backward = import_edge.backward;
|
||||
}
|
||||
else
|
||||
{
|
||||
edge.source = import_edge.target;
|
||||
edge.target = import_edge.source;
|
||||
edge.data.backward = import_edge.forward;
|
||||
edge.data.forward = import_edge.backward;
|
||||
}
|
||||
|
||||
if (edge.source == edge.target)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
edge.data.distance = (std::max)((int)import_edge.weight, 1);
|
||||
BOOST_ASSERT(edge.data.distance > 0);
|
||||
edge.data.shortcut = false;
|
||||
edge.data.roundabout = import_edge.roundabout;
|
||||
edge.data.ignore_in_grid = import_edge.in_tiny_cc;
|
||||
edge.data.nameID = import_edge.name_id;
|
||||
edge.data.type = import_edge.type;
|
||||
edge.data.isAccessRestricted = import_edge.access_restricted;
|
||||
edge.data.contraFlow = import_edge.contra_flow;
|
||||
edges_list.push_back(edge);
|
||||
|
||||
if (!import_edge.is_split)
|
||||
{
|
||||
using std::swap; // enable ADL
|
||||
swap(edge.source, edge.target);
|
||||
edge.data.SwapDirectionFlags();
|
||||
edges_list.push_back(edge);
|
||||
}
|
||||
}
|
||||
|
||||
// remove duplicate edges
|
||||
std::sort(edges_list.begin(), edges_list.end());
|
||||
NodeID edge_count = 0;
|
||||
for (NodeID i = 0; i < edges_list.size(); )
|
||||
{
|
||||
const NodeID source = edges_list[i].source;
|
||||
const NodeID target = edges_list[i].target;
|
||||
// remove eigenloops
|
||||
if (source == target)
|
||||
{
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
NodeBasedDynamicGraph::InputEdge forward_edge;
|
||||
NodeBasedDynamicGraph::InputEdge reverse_edge;
|
||||
forward_edge = reverse_edge = edges_list[i];
|
||||
forward_edge.data.forward = reverse_edge.data.backward = true;
|
||||
forward_edge.data.backward = reverse_edge.data.forward = false;
|
||||
forward_edge.data.shortcut = reverse_edge.data.shortcut = false;
|
||||
forward_edge.data.distance = reverse_edge.data.distance =
|
||||
std::numeric_limits<int>::max();
|
||||
// remove parallel edges
|
||||
while (i < edges_list.size() && edges_list[i].source == source && edges_list[i].target == target)
|
||||
{
|
||||
if (edges_list[i].data.forward)
|
||||
{
|
||||
forward_edge.data.distance =
|
||||
std::min(edges_list[i].data.distance, forward_edge.data.distance);
|
||||
}
|
||||
if (edges_list[i].data.backward)
|
||||
{
|
||||
reverse_edge.data.distance =
|
||||
std::min(edges_list[i].data.distance, reverse_edge.data.distance);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
// merge edges (s,t) and (t,s) into bidirectional edge
|
||||
if (forward_edge.data.distance == reverse_edge.data.distance)
|
||||
{
|
||||
if ((int)forward_edge.data.distance != std::numeric_limits<int>::max())
|
||||
{
|
||||
forward_edge.data.backward = true;
|
||||
edges_list[edge_count++] = forward_edge;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // insert seperate edges
|
||||
if (((int)forward_edge.data.distance) != std::numeric_limits<int>::max())
|
||||
{
|
||||
edges_list[edge_count++] = forward_edge;
|
||||
}
|
||||
if ((int)reverse_edge.data.distance != std::numeric_limits<int>::max())
|
||||
{
|
||||
edges_list[edge_count++] = reverse_edge;
|
||||
}
|
||||
}
|
||||
}
|
||||
edges_list.resize(edge_count);
|
||||
SimpleLogger().Write() << "merged " << edges_list.size() - edge_count << " edges out of " << edges_list.size();
|
||||
|
||||
auto graph = std::make_shared<NodeBasedDynamicGraph>(number_of_nodes, edges_list);
|
||||
return graph;
|
||||
}
|
||||
|
||||
#endif // __NODE_BASED_GRAPH_H__
|
||||
@@ -1,173 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef PHANTOM_NODES_H
|
||||
#define PHANTOM_NODES_H
|
||||
|
||||
#include <osrm/Coordinate.h>
|
||||
#include "../Util/SimpleLogger.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
struct PhantomNode
|
||||
{
|
||||
PhantomNode(NodeID forward_node_id, NodeID reverse_node_id, unsigned name_id,
|
||||
int forward_weight, int reverse_weight, int forward_offset, int reverse_offset,
|
||||
unsigned packed_geometry_id, FixedPointCoordinate &location,
|
||||
unsigned short fwd_segment_position) :
|
||||
forward_node_id(forward_node_id),
|
||||
reverse_node_id(reverse_node_id),
|
||||
name_id(name_id),
|
||||
forward_weight(forward_weight),
|
||||
reverse_weight(reverse_weight),
|
||||
forward_offset(forward_offset),
|
||||
reverse_offset(reverse_offset),
|
||||
packed_geometry_id(packed_geometry_id),
|
||||
location(location),
|
||||
fwd_segment_position(fwd_segment_position)
|
||||
{ }
|
||||
|
||||
PhantomNode() :
|
||||
forward_node_id(SPECIAL_NODEID),
|
||||
reverse_node_id(SPECIAL_NODEID),
|
||||
name_id(std::numeric_limits<unsigned>::max()),
|
||||
forward_weight(INVALID_EDGE_WEIGHT),
|
||||
reverse_weight(INVALID_EDGE_WEIGHT),
|
||||
forward_offset(0),
|
||||
reverse_offset(0),
|
||||
packed_geometry_id(SPECIAL_EDGEID),
|
||||
fwd_segment_position(0)
|
||||
{ }
|
||||
|
||||
NodeID forward_node_id;
|
||||
NodeID reverse_node_id;
|
||||
unsigned name_id;
|
||||
int forward_weight;
|
||||
int reverse_weight;
|
||||
int forward_offset;
|
||||
int reverse_offset;
|
||||
unsigned packed_geometry_id;
|
||||
FixedPointCoordinate location;
|
||||
unsigned short fwd_segment_position;
|
||||
|
||||
int GetForwardWeightPlusOffset() const
|
||||
{
|
||||
if (SPECIAL_NODEID == forward_node_id)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
const int result = (forward_offset + forward_weight);
|
||||
return result;
|
||||
}
|
||||
|
||||
int GetReverseWeightPlusOffset() const
|
||||
{
|
||||
if (SPECIAL_NODEID == reverse_node_id)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
const int result = (reverse_offset + reverse_weight);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool isBidirected() const
|
||||
{
|
||||
return (forward_node_id != SPECIAL_NODEID) &&
|
||||
(reverse_node_id != SPECIAL_NODEID);
|
||||
}
|
||||
|
||||
bool IsCompressed() const
|
||||
{
|
||||
return (forward_offset != 0) || (reverse_offset != 0);
|
||||
}
|
||||
|
||||
bool isValid(const unsigned numberOfNodes) const
|
||||
{
|
||||
return
|
||||
location.isValid() &&
|
||||
(
|
||||
(forward_node_id < numberOfNodes) ||
|
||||
(reverse_node_id < numberOfNodes)
|
||||
) &&
|
||||
(
|
||||
(forward_weight != INVALID_EDGE_WEIGHT) ||
|
||||
(reverse_weight != INVALID_EDGE_WEIGHT)
|
||||
) &&
|
||||
(name_id != std::numeric_limits<unsigned>::max()
|
||||
);
|
||||
}
|
||||
|
||||
bool isValid() const
|
||||
{
|
||||
return location.isValid() &&
|
||||
(name_id != std::numeric_limits<unsigned>::max());
|
||||
}
|
||||
|
||||
bool operator==(const PhantomNode & other) const
|
||||
{
|
||||
return location == other.location;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::vector<std::vector<PhantomNode>> PhantomNodeArray;
|
||||
|
||||
struct PhantomNodeLists
|
||||
{
|
||||
std::vector<PhantomNode> source_phantom_list;
|
||||
std::vector<PhantomNode> target_phantom_list;
|
||||
};
|
||||
|
||||
struct PhantomNodes
|
||||
{
|
||||
PhantomNode source_phantom;
|
||||
PhantomNode target_phantom;
|
||||
};
|
||||
|
||||
inline std::ostream& operator<<(std::ostream &out, const PhantomNodes & pn)
|
||||
{
|
||||
out << "source_coord: " << pn.source_phantom.location << "\n";
|
||||
out << "target_coord: " << pn.target_phantom.location << std::endl;
|
||||
return out;
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream &out, const PhantomNode & pn)
|
||||
{
|
||||
out << "node1: " << pn.forward_node_id << ", " <<
|
||||
"node2: " << pn.reverse_node_id << ", " <<
|
||||
"name: " << pn.name_id << ", " <<
|
||||
"fwd-w: " << pn.forward_weight << ", " <<
|
||||
"rev-w: " << pn.reverse_weight << ", " <<
|
||||
"fwd-o: " << pn.forward_offset << ", " <<
|
||||
"rev-o: " << pn.reverse_offset << ", " <<
|
||||
"geom: " << pn.packed_geometry_id << ", " <<
|
||||
"pos: " << pn.fwd_segment_position << ", " <<
|
||||
"loc: " << pn.location;
|
||||
return out;
|
||||
}
|
||||
|
||||
#endif // PHANTOM_NODES_H
|
||||
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef GPX_DESCRIPTOR_H
|
||||
#define GPX_DESCRIPTOR_H
|
||||
|
||||
#include "BaseDescriptor.h"
|
||||
|
||||
template <class DataFacadeT> class GPXDescriptor : public BaseDescriptor<DataFacadeT>
|
||||
{
|
||||
private:
|
||||
DescriptorConfig config;
|
||||
FixedPointCoordinate current;
|
||||
DataFacadeT * facade;
|
||||
|
||||
void AddRoutePoint(const FixedPointCoordinate & coordinate, std::vector<char> & output)
|
||||
{
|
||||
const std::string route_point_head = "<rtept lat=\"";
|
||||
const std::string route_point_middle = " lon=\"";
|
||||
const std::string route_point_tail = "\"></rtept>";
|
||||
|
||||
std::string tmp;
|
||||
|
||||
FixedPointCoordinate::convertInternalLatLonToString(coordinate.lat, tmp);
|
||||
output.insert(output.end(), route_point_head.begin(), route_point_head.end());
|
||||
output.insert(output.end(), tmp.begin(), tmp.end());
|
||||
output.push_back('\"');
|
||||
|
||||
FixedPointCoordinate::convertInternalLatLonToString(coordinate.lon, tmp);
|
||||
output.insert(output.end(), route_point_middle.begin(), route_point_middle.end());
|
||||
output.insert(output.end(), tmp.begin(), tmp.end());
|
||||
output.insert(output.end(), route_point_tail.begin(), route_point_tail.end());
|
||||
}
|
||||
|
||||
public:
|
||||
GPXDescriptor(DataFacadeT *facade) : facade(facade) {}
|
||||
|
||||
void SetConfig(const DescriptorConfig &c) { config = c; }
|
||||
|
||||
// TODO: reorder parameters
|
||||
void Run(const RawRouteData &raw_route, http::Reply &reply)
|
||||
{
|
||||
std::string header("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||
"<gpx creator=\"OSRM Routing Engine\" version=\"1.1\" "
|
||||
"xmlns=\"http://www.topografix.com/GPX/1/1\" "
|
||||
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
|
||||
"xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 gpx.xsd"
|
||||
"\">"
|
||||
"<metadata><copyright author=\"Project OSRM\"><license>Data (c)"
|
||||
" OpenStreetMap contributors (ODbL)</license></copyright>"
|
||||
"</metadata>"
|
||||
"<rte>");
|
||||
reply.content.insert(reply.content.end(), header.begin(), header.end());
|
||||
const bool found_route = (raw_route.shortest_path_length != INVALID_EDGE_WEIGHT) &&
|
||||
(!raw_route.unpacked_path_segments.front().empty());
|
||||
if (found_route)
|
||||
{
|
||||
AddRoutePoint(raw_route.segment_end_coordinates.front().source_phantom.location, reply.content);
|
||||
|
||||
for (const std::vector<PathData> &path_data_vector : raw_route.unpacked_path_segments)
|
||||
{
|
||||
for (const PathData &path_data : path_data_vector)
|
||||
{
|
||||
const FixedPointCoordinate current_coordinate =
|
||||
facade->GetCoordinateOfNode(path_data.node);
|
||||
AddRoutePoint(current_coordinate, reply.content);
|
||||
}
|
||||
}
|
||||
AddRoutePoint(raw_route.segment_end_coordinates.back().target_phantom.location, reply.content);
|
||||
|
||||
}
|
||||
std::string footer("</rte></gpx>");
|
||||
reply.content.insert(reply.content.end(), footer.begin(), footer.end());
|
||||
}
|
||||
};
|
||||
#endif // GPX_DESCRIPTOR_H
|
||||
@@ -1,3 +0,0 @@
|
||||
The javascript based web client is a seperate project available at
|
||||
|
||||
https://github.com/DennisSchiefer/Project-OSRM-Web
|
||||
@@ -1,139 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "BaseParser.h"
|
||||
#include "ExtractionWay.h"
|
||||
#include "ScriptingEnvironment.h"
|
||||
|
||||
#include "../DataStructures/ImportNode.h"
|
||||
#include "../Util/LuaUtil.h"
|
||||
#include "../Util/OSRMException.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/algorithm/string/regex.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
BaseParser::BaseParser(ExtractorCallbacks *extractor_callbacks,
|
||||
ScriptingEnvironment &scripting_environment)
|
||||
: extractor_callbacks(extractor_callbacks),
|
||||
lua_state(scripting_environment.getLuaState()),
|
||||
scripting_environment(scripting_environment), use_turn_restrictions(true)
|
||||
{
|
||||
ReadUseRestrictionsSetting();
|
||||
ReadRestrictionExceptions();
|
||||
}
|
||||
|
||||
void BaseParser::ReadUseRestrictionsSetting()
|
||||
{
|
||||
if (0 != luaL_dostring(lua_state, "return use_turn_restrictions\n"))
|
||||
{
|
||||
throw OSRMException("ERROR occured in scripting block");
|
||||
}
|
||||
if (lua_isboolean(lua_state, -1))
|
||||
{
|
||||
use_turn_restrictions = lua_toboolean(lua_state, -1);
|
||||
}
|
||||
if (use_turn_restrictions)
|
||||
{
|
||||
SimpleLogger().Write() << "Using turn restrictions";
|
||||
}
|
||||
else
|
||||
{
|
||||
SimpleLogger().Write() << "Ignoring turn restrictions";
|
||||
}
|
||||
}
|
||||
|
||||
void BaseParser::ReadRestrictionExceptions()
|
||||
{
|
||||
if (lua_function_exists(lua_state, "get_exceptions"))
|
||||
{
|
||||
// get list of turn restriction exceptions
|
||||
luabind::call_function<void>(
|
||||
lua_state, "get_exceptions", boost::ref(restriction_exceptions));
|
||||
const unsigned exception_count = restriction_exceptions.size();
|
||||
SimpleLogger().Write() << "Found " << exception_count
|
||||
<< " exceptions to turn restrictions:";
|
||||
for (const std::string &str : restriction_exceptions)
|
||||
{
|
||||
SimpleLogger().Write() << " " << str;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SimpleLogger().Write() << "Found no exceptions to turn restrictions";
|
||||
}
|
||||
}
|
||||
|
||||
void BaseParser::report_errors(lua_State *lua_state, const int status) const
|
||||
{
|
||||
if (0 != status)
|
||||
{
|
||||
std::cerr << "-- " << lua_tostring(lua_state, -1) << std::endl;
|
||||
lua_pop(lua_state, 1); // remove error message
|
||||
}
|
||||
}
|
||||
|
||||
void BaseParser::ParseNodeInLua(ImportNode &node, lua_State *local_lua_state)
|
||||
{
|
||||
luabind::call_function<void>(local_lua_state, "node_function", boost::ref(node));
|
||||
}
|
||||
|
||||
void BaseParser::ParseWayInLua(ExtractionWay &way, lua_State *local_lua_state)
|
||||
{
|
||||
luabind::call_function<void>(local_lua_state, "way_function", boost::ref(way));
|
||||
}
|
||||
|
||||
bool BaseParser::ShouldIgnoreRestriction(const std::string &except_tag_string) const
|
||||
{
|
||||
// should this restriction be ignored? yes if there's an overlap between:
|
||||
// a) the list of modes in the except tag of the restriction
|
||||
// (except_tag_string), eg: except=bus;bicycle
|
||||
// b) the lua profile defines a hierachy of modes,
|
||||
// eg: [access, vehicle, bicycle]
|
||||
|
||||
if (except_tag_string.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Be warned, this is quadratic work here, but we assume that
|
||||
// only a few exceptions are actually defined.
|
||||
std::vector<std::string> exceptions;
|
||||
boost::algorithm::split_regex(exceptions, except_tag_string, boost::regex("[;][ ]*"));
|
||||
for (std::string ¤t_string : exceptions)
|
||||
{
|
||||
const auto string_iterator =
|
||||
std::find(restriction_exceptions.begin(), restriction_exceptions.end(), current_string);
|
||||
if (restriction_exceptions.end() != string_iterator)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef BASEPARSER_H_
|
||||
#define BASEPARSER_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct lua_State;
|
||||
class ExtractorCallbacks;
|
||||
class ScriptingEnvironment;
|
||||
struct ExtractionWay;
|
||||
struct ImportNode;
|
||||
|
||||
class BaseParser
|
||||
{
|
||||
public:
|
||||
BaseParser() = delete;
|
||||
BaseParser(const BaseParser &) = delete;
|
||||
BaseParser(ExtractorCallbacks *extractor_callbacks,
|
||||
ScriptingEnvironment &scripting_environment);
|
||||
virtual ~BaseParser() {}
|
||||
virtual bool ReadHeader() = 0;
|
||||
virtual bool Parse() = 0;
|
||||
|
||||
virtual void ParseNodeInLua(ImportNode &node, lua_State *lua_state);
|
||||
virtual void ParseWayInLua(ExtractionWay &way, lua_State *lua_state);
|
||||
virtual void report_errors(lua_State *lua_state, const int status) const;
|
||||
|
||||
protected:
|
||||
virtual void ReadUseRestrictionsSetting();
|
||||
virtual void ReadRestrictionExceptions();
|
||||
virtual bool ShouldIgnoreRestriction(const std::string &except_tag_string) const;
|
||||
|
||||
ExtractorCallbacks *extractor_callbacks;
|
||||
lua_State *lua_state;
|
||||
ScriptingEnvironment &scripting_environment;
|
||||
std::vector<std::string> restriction_exceptions;
|
||||
bool use_turn_restrictions;
|
||||
};
|
||||
|
||||
#endif /* BASEPARSER_H_ */
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef EXTRACTION_WAY_H
|
||||
#define EXTRACTION_WAY_H
|
||||
|
||||
#include "../DataStructures/HashTable.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct ExtractionWay
|
||||
{
|
||||
ExtractionWay() { Clear(); }
|
||||
|
||||
inline void Clear()
|
||||
{
|
||||
id = SPECIAL_NODEID;
|
||||
nameID = INVALID_NAMEID;
|
||||
path.clear();
|
||||
keyVals.Clear();
|
||||
direction = ExtractionWay::notSure;
|
||||
speed = -1;
|
||||
backward_speed = -1;
|
||||
duration = -1;
|
||||
type = -1;
|
||||
access = true;
|
||||
roundabout = false;
|
||||
isAccessRestricted = false;
|
||||
ignoreInGrid = false;
|
||||
}
|
||||
|
||||
enum Directions
|
||||
{ notSure = 0,
|
||||
oneway,
|
||||
bidirectional,
|
||||
opposite };
|
||||
unsigned id;
|
||||
unsigned nameID;
|
||||
double speed;
|
||||
double backward_speed;
|
||||
double duration;
|
||||
Directions direction;
|
||||
std::string name;
|
||||
short type;
|
||||
bool access;
|
||||
bool roundabout;
|
||||
bool isAccessRestricted;
|
||||
bool ignoreInGrid;
|
||||
std::vector<NodeID> path;
|
||||
HashTable<std::string, std::string> keyVals;
|
||||
};
|
||||
|
||||
#endif // EXTRACTION_WAY_H
|
||||
@@ -1,171 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "ExtractorCallbacks.h"
|
||||
#include "ExtractionContainers.h"
|
||||
#include "ExtractionWay.h"
|
||||
|
||||
#include "../DataStructures/Restriction.h"
|
||||
#include "../DataStructures/ImportNode.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
|
||||
#include <osrm/Coordinate.h>
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
ExtractorCallbacks::ExtractorCallbacks(ExtractionContainers &extraction_containers,
|
||||
std::unordered_map<std::string, NodeID> &string_map)
|
||||
: string_map(string_map), external_memory(extraction_containers)
|
||||
{
|
||||
}
|
||||
|
||||
/** warning: caller needs to take care of synchronization! */
|
||||
void ExtractorCallbacks::ProcessNode(const ExternalMemoryNode &n)
|
||||
{
|
||||
if (n.lat <= 85 * COORDINATE_PRECISION && n.lat >= -85 * COORDINATE_PRECISION)
|
||||
{
|
||||
external_memory.all_nodes_list.push_back(n);
|
||||
}
|
||||
}
|
||||
|
||||
bool ExtractorCallbacks::ProcessRestriction(const InputRestrictionContainer &restriction)
|
||||
{
|
||||
external_memory.restrictions_list.push_back(restriction);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** warning: caller needs to take care of synchronization! */
|
||||
void ExtractorCallbacks::ProcessWay(ExtractionWay &parsed_way)
|
||||
{
|
||||
if ((0 >= parsed_way.speed) && (0 >= parsed_way.duration))
|
||||
{ // Only true if the way is specified by the speed profile
|
||||
return;
|
||||
}
|
||||
|
||||
if (parsed_way.path.size() <= 1)
|
||||
{ // safe-guard against broken data
|
||||
return;
|
||||
}
|
||||
|
||||
if (std::numeric_limits<unsigned>::max() == parsed_way.id)
|
||||
{
|
||||
SimpleLogger().Write(logDEBUG) << "found bogus way with id: " << parsed_way.id
|
||||
<< " of size " << parsed_way.path.size();
|
||||
return;
|
||||
}
|
||||
|
||||
if (0 < parsed_way.duration)
|
||||
{
|
||||
// TODO: iterate all way segments and set duration corresponding to the length of each
|
||||
// segment
|
||||
parsed_way.speed = parsed_way.duration / (parsed_way.path.size() - 1);
|
||||
}
|
||||
|
||||
if (std::numeric_limits<double>::epsilon() >= std::abs(-1. - parsed_way.speed))
|
||||
{
|
||||
SimpleLogger().Write(logDEBUG) << "found way with bogus speed, id: " << parsed_way.id;
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the unique identifier for the street name
|
||||
const auto &string_map_iterator = string_map.find(parsed_way.name);
|
||||
if (string_map.end() == string_map_iterator)
|
||||
{
|
||||
parsed_way.nameID = external_memory.name_list.size();
|
||||
external_memory.name_list.push_back(parsed_way.name);
|
||||
string_map.insert(std::make_pair(parsed_way.name, parsed_way.nameID));
|
||||
}
|
||||
else
|
||||
{
|
||||
parsed_way.nameID = string_map_iterator->second;
|
||||
}
|
||||
|
||||
if (ExtractionWay::opposite == parsed_way.direction)
|
||||
{
|
||||
std::reverse(parsed_way.path.begin(), parsed_way.path.end());
|
||||
parsed_way.direction = ExtractionWay::oneway;
|
||||
}
|
||||
|
||||
const bool split_edge =
|
||||
(parsed_way.backward_speed > 0) && (parsed_way.speed != parsed_way.backward_speed);
|
||||
|
||||
for (unsigned n = 0; n < (parsed_way.path.size() - 1); ++n)
|
||||
{
|
||||
external_memory.all_edges_list.push_back(InternalExtractorEdge(
|
||||
parsed_way.path[n],
|
||||
parsed_way.path[n + 1],
|
||||
parsed_way.type,
|
||||
(split_edge ? ExtractionWay::oneway : parsed_way.direction),
|
||||
parsed_way.speed,
|
||||
parsed_way.nameID,
|
||||
parsed_way.roundabout,
|
||||
parsed_way.ignoreInGrid,
|
||||
(0 < parsed_way.duration),
|
||||
parsed_way.isAccessRestricted,
|
||||
false,
|
||||
split_edge));
|
||||
external_memory.used_node_id_list.push_back(parsed_way.path[n]);
|
||||
}
|
||||
external_memory.used_node_id_list.push_back(parsed_way.path.back());
|
||||
|
||||
// The following information is needed to identify start and end segments of restrictions
|
||||
external_memory.way_start_end_id_list.push_back(
|
||||
WayIDStartAndEndEdge(parsed_way.id,
|
||||
parsed_way.path[0],
|
||||
parsed_way.path[1],
|
||||
parsed_way.path[parsed_way.path.size() - 2],
|
||||
parsed_way.path.back()));
|
||||
|
||||
if (split_edge)
|
||||
{ // Only true if the way should be split
|
||||
std::reverse(parsed_way.path.begin(), parsed_way.path.end());
|
||||
for (std::vector<NodeID>::size_type n = 0; n < parsed_way.path.size() - 1; ++n)
|
||||
{
|
||||
external_memory.all_edges_list.push_back(
|
||||
InternalExtractorEdge(parsed_way.path[n],
|
||||
parsed_way.path[n + 1],
|
||||
parsed_way.type,
|
||||
ExtractionWay::oneway,
|
||||
parsed_way.backward_speed,
|
||||
parsed_way.nameID,
|
||||
parsed_way.roundabout,
|
||||
parsed_way.ignoreInGrid,
|
||||
(0 < parsed_way.duration),
|
||||
parsed_way.isAccessRestricted,
|
||||
(ExtractionWay::oneway == parsed_way.direction),
|
||||
split_edge));
|
||||
}
|
||||
external_memory.way_start_end_id_list.push_back(
|
||||
WayIDStartAndEndEdge(parsed_way.id,
|
||||
parsed_way.path[0],
|
||||
parsed_way.path[1],
|
||||
parsed_way.path[parsed_way.path.size() - 2],
|
||||
parsed_way.path.back()));
|
||||
}
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef EXTRACTORSTRUCTS_H_
|
||||
#define EXTRACTORSTRUCTS_H_
|
||||
|
||||
#include "../DataStructures/HashTable.h"
|
||||
#include "../DataStructures/ImportNode.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
struct ExtractorRelation
|
||||
{
|
||||
ExtractorRelation() : type(unknown) {}
|
||||
enum
|
||||
{ unknown = 0,
|
||||
ferry,
|
||||
turnRestriction } type;
|
||||
HashTable<std::string, std::string> keyVals;
|
||||
};
|
||||
|
||||
struct WayIDStartAndEndEdge
|
||||
{
|
||||
unsigned wayID;
|
||||
NodeID firstStart;
|
||||
NodeID firstTarget;
|
||||
NodeID lastStart;
|
||||
NodeID lastTarget;
|
||||
WayIDStartAndEndEdge()
|
||||
: wayID(std::numeric_limits<unsigned>::max()), firstStart(std::numeric_limits<unsigned>::max()), firstTarget(std::numeric_limits<unsigned>::max()), lastStart(std::numeric_limits<unsigned>::max()),
|
||||
lastTarget(std::numeric_limits<unsigned>::max())
|
||||
{
|
||||
}
|
||||
|
||||
explicit WayIDStartAndEndEdge(unsigned w, NodeID fs, NodeID ft, NodeID ls, NodeID lt)
|
||||
: wayID(w), firstStart(fs), firstTarget(ft), lastStart(ls), lastTarget(lt)
|
||||
{
|
||||
}
|
||||
|
||||
static WayIDStartAndEndEdge min_value()
|
||||
{
|
||||
return WayIDStartAndEndEdge((std::numeric_limits<unsigned>::min)(),
|
||||
(std::numeric_limits<unsigned>::min)(),
|
||||
(std::numeric_limits<unsigned>::min)(),
|
||||
(std::numeric_limits<unsigned>::min)(),
|
||||
(std::numeric_limits<unsigned>::min)());
|
||||
}
|
||||
static WayIDStartAndEndEdge max_value()
|
||||
{
|
||||
return WayIDStartAndEndEdge((std::numeric_limits<unsigned>::max)(),
|
||||
(std::numeric_limits<unsigned>::max)(),
|
||||
(std::numeric_limits<unsigned>::max)(),
|
||||
(std::numeric_limits<unsigned>::max)(),
|
||||
(std::numeric_limits<unsigned>::max)());
|
||||
}
|
||||
};
|
||||
|
||||
struct CmpWayByID
|
||||
{
|
||||
typedef WayIDStartAndEndEdge value_type;
|
||||
bool operator()(const WayIDStartAndEndEdge &a, const WayIDStartAndEndEdge &b) const
|
||||
{
|
||||
return a.wayID < b.wayID;
|
||||
}
|
||||
value_type max_value() { return WayIDStartAndEndEdge::max_value(); }
|
||||
value_type min_value() { return WayIDStartAndEndEdge::min_value(); }
|
||||
};
|
||||
|
||||
struct Cmp
|
||||
{
|
||||
typedef NodeID value_type;
|
||||
bool operator()(const NodeID left, const NodeID right) const { return left < right; }
|
||||
value_type max_value() { return 0xffffffff; }
|
||||
value_type min_value() { return 0x0; }
|
||||
};
|
||||
|
||||
struct CmpNodeByID
|
||||
{
|
||||
typedef ExternalMemoryNode value_type;
|
||||
bool operator()(const ExternalMemoryNode &left, const ExternalMemoryNode &right) const
|
||||
{
|
||||
return left.node_id < right.node_id;
|
||||
}
|
||||
value_type max_value() { return ExternalMemoryNode::max_value(); }
|
||||
value_type min_value() { return ExternalMemoryNode::min_value(); }
|
||||
};
|
||||
|
||||
#endif /* EXTRACTORSTRUCTS_H_ */
|
||||
@@ -1,664 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "PBFParser.h"
|
||||
|
||||
#include "ExtractionWay.h"
|
||||
#include "ExtractorCallbacks.h"
|
||||
#include "ScriptingEnvironment.h"
|
||||
|
||||
#include "../DataStructures/HashTable.h"
|
||||
#include "../DataStructures/ImportNode.h"
|
||||
#include "../DataStructures/Restriction.h"
|
||||
#include "../Util/MachineInfo.h"
|
||||
#include "../Util/OSRMException.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <tbb/parallel_for.h>
|
||||
#include <tbb/task_scheduler_init.h>
|
||||
|
||||
#include <osrm/Coordinate.h>
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <thread>
|
||||
|
||||
PBFParser::PBFParser(const char *fileName,
|
||||
ExtractorCallbacks *extractor_callbacks,
|
||||
ScriptingEnvironment &scripting_environment,
|
||||
unsigned num_threads)
|
||||
: BaseParser(extractor_callbacks, scripting_environment)
|
||||
{
|
||||
if (0 == num_threads)
|
||||
{
|
||||
num_parser_threads = tbb::task_scheduler_init::default_num_threads();
|
||||
}
|
||||
else
|
||||
{
|
||||
num_parser_threads = num_threads;
|
||||
}
|
||||
|
||||
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
||||
// TODO: What is the bottleneck here? Filling the queue or reading the stuff from disk?
|
||||
// NOTE: With Lua scripting, it is parsing the stuff. I/O is virtually for free.
|
||||
|
||||
// Max 2500 items in queue, hardcoded.
|
||||
thread_data_queue = std::make_shared<ConcurrentQueue<ParserThreadData *>>(2500);
|
||||
input.open(fileName, std::ios::in | std::ios::binary);
|
||||
|
||||
if (!input)
|
||||
{
|
||||
throw OSRMException("pbf file not found.");
|
||||
}
|
||||
|
||||
block_count = 0;
|
||||
group_count = 0;
|
||||
}
|
||||
|
||||
PBFParser::~PBFParser()
|
||||
{
|
||||
if (input.is_open())
|
||||
{
|
||||
input.close();
|
||||
}
|
||||
|
||||
// Clean up any leftover ThreadData objects in the queue
|
||||
ParserThreadData *thread_data;
|
||||
while (thread_data_queue->try_pop(thread_data))
|
||||
{
|
||||
delete thread_data;
|
||||
}
|
||||
google::protobuf::ShutdownProtobufLibrary();
|
||||
|
||||
SimpleLogger().Write(logDEBUG) << "parsed " << block_count << " blocks from pbf with "
|
||||
<< group_count << " groups";
|
||||
}
|
||||
|
||||
inline bool PBFParser::ReadHeader()
|
||||
{
|
||||
ParserThreadData init_data;
|
||||
/** read Header */
|
||||
if (!readPBFBlobHeader(input, &init_data))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (readBlob(input, &init_data))
|
||||
{
|
||||
if (!init_data.PBFHeaderBlock.ParseFromArray(&(init_data.charBuffer[0]),
|
||||
static_cast<int>(init_data.charBuffer.size())))
|
||||
{
|
||||
std::cerr << "[error] Header not parseable!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto feature_size = init_data.PBFHeaderBlock.required_features_size();
|
||||
for (int i = 0; i < feature_size; ++i)
|
||||
{
|
||||
const std::string &feature = init_data.PBFHeaderBlock.required_features(i);
|
||||
bool supported = false;
|
||||
if ("OsmSchema-V0.6" == feature)
|
||||
{
|
||||
supported = true;
|
||||
}
|
||||
else if ("DenseNodes" == feature)
|
||||
{
|
||||
supported = true;
|
||||
}
|
||||
|
||||
if (!supported)
|
||||
{
|
||||
std::cerr << "[error] required feature not supported: " << feature.data()
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "[error] blob not loaded!" << std::endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void PBFParser::ReadData()
|
||||
{
|
||||
bool keep_running = true;
|
||||
do
|
||||
{
|
||||
ParserThreadData *thread_data = new ParserThreadData();
|
||||
keep_running = readNextBlock(input, thread_data);
|
||||
|
||||
if (keep_running)
|
||||
{
|
||||
thread_data_queue->push(thread_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No more data to read, parse stops when nullptr encountered
|
||||
thread_data_queue->push(nullptr);
|
||||
delete thread_data;
|
||||
}
|
||||
} while (keep_running);
|
||||
}
|
||||
|
||||
inline void PBFParser::ParseData()
|
||||
{
|
||||
tbb::task_scheduler_init init(num_parser_threads);
|
||||
|
||||
while (true)
|
||||
{
|
||||
ParserThreadData *thread_data;
|
||||
thread_data_queue->wait_and_pop(thread_data);
|
||||
if (nullptr == thread_data)
|
||||
{
|
||||
thread_data_queue->push(nullptr); // Signal end of data for other threads
|
||||
break;
|
||||
}
|
||||
|
||||
loadBlock(thread_data);
|
||||
|
||||
int group_size = thread_data->PBFprimitiveBlock.primitivegroup_size();
|
||||
for (int i = 0; i < group_size; ++i)
|
||||
{
|
||||
thread_data->currentGroupID = i;
|
||||
loadGroup(thread_data);
|
||||
|
||||
if (thread_data->entityTypeIndicator == TypeNode)
|
||||
{
|
||||
parseNode(thread_data);
|
||||
}
|
||||
if (thread_data->entityTypeIndicator == TypeWay)
|
||||
{
|
||||
parseWay(thread_data);
|
||||
}
|
||||
if (thread_data->entityTypeIndicator == TypeRelation)
|
||||
{
|
||||
parseRelation(thread_data);
|
||||
}
|
||||
if (thread_data->entityTypeIndicator == TypeDenseNode)
|
||||
{
|
||||
parseDenseNode(thread_data);
|
||||
}
|
||||
}
|
||||
|
||||
delete thread_data;
|
||||
thread_data = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool PBFParser::Parse()
|
||||
{
|
||||
// Start the read and parse threads
|
||||
std::thread read_thread(std::bind(&PBFParser::ReadData, this));
|
||||
|
||||
// Open several parse threads that are synchronized before call to
|
||||
std::thread parse_thread(std::bind(&PBFParser::ParseData, this));
|
||||
|
||||
// Wait for the threads to finish
|
||||
read_thread.join();
|
||||
parse_thread.join();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void PBFParser::parseDenseNode(ParserThreadData *thread_data)
|
||||
{
|
||||
const OSMPBF::DenseNodes &dense =
|
||||
thread_data->PBFprimitiveBlock.primitivegroup(thread_data->currentGroupID).dense();
|
||||
int denseTagIndex = 0;
|
||||
int64_t m_lastDenseID = 0;
|
||||
int64_t m_lastDenseLatitude = 0;
|
||||
int64_t m_lastDenseLongitude = 0;
|
||||
|
||||
const int number_of_nodes = dense.id_size();
|
||||
std::vector<ImportNode> extracted_nodes_vector(number_of_nodes);
|
||||
for (int i = 0; i < number_of_nodes; ++i)
|
||||
{
|
||||
m_lastDenseID += dense.id(i);
|
||||
m_lastDenseLatitude += dense.lat(i);
|
||||
m_lastDenseLongitude += dense.lon(i);
|
||||
extracted_nodes_vector[i].node_id = static_cast<NodeID>(m_lastDenseID);
|
||||
extracted_nodes_vector[i].lat = static_cast<int>(
|
||||
COORDINATE_PRECISION *
|
||||
((double)m_lastDenseLatitude * thread_data->PBFprimitiveBlock.granularity() +
|
||||
thread_data->PBFprimitiveBlock.lat_offset()) /
|
||||
NANO);
|
||||
extracted_nodes_vector[i].lon = static_cast<int>(
|
||||
COORDINATE_PRECISION *
|
||||
((double)m_lastDenseLongitude * thread_data->PBFprimitiveBlock.granularity() +
|
||||
thread_data->PBFprimitiveBlock.lon_offset()) /
|
||||
NANO);
|
||||
while (denseTagIndex < dense.keys_vals_size())
|
||||
{
|
||||
const int tagValue = dense.keys_vals(denseTagIndex);
|
||||
if (0 == tagValue)
|
||||
{
|
||||
++denseTagIndex;
|
||||
break;
|
||||
}
|
||||
const int keyValue = dense.keys_vals(denseTagIndex + 1);
|
||||
const std::string &key = thread_data->PBFprimitiveBlock.stringtable().s(tagValue);
|
||||
const std::string &value = thread_data->PBFprimitiveBlock.stringtable().s(keyValue);
|
||||
extracted_nodes_vector[i].keyVals.Add(std::move(key), std::move(value));
|
||||
denseTagIndex += 2;
|
||||
}
|
||||
}
|
||||
|
||||
tbb::parallel_for(tbb::blocked_range<size_t>(0, extracted_nodes_vector.size()),
|
||||
[this, &extracted_nodes_vector](const tbb::blocked_range<size_t> &range)
|
||||
{
|
||||
lua_State *lua_state = this->scripting_environment.getLuaState();
|
||||
for (size_t i = range.begin(); i != range.end(); ++i)
|
||||
{
|
||||
ImportNode &import_node = extracted_nodes_vector[i];
|
||||
ParseNodeInLua(import_node, lua_state);
|
||||
}
|
||||
});
|
||||
|
||||
for (const ImportNode &import_node : extracted_nodes_vector)
|
||||
{
|
||||
extractor_callbacks->ProcessNode(import_node);
|
||||
}
|
||||
}
|
||||
|
||||
inline void PBFParser::parseNode(ParserThreadData *)
|
||||
{
|
||||
throw OSRMException("Parsing of simple nodes not supported. PBF should use dense nodes");
|
||||
}
|
||||
|
||||
inline void PBFParser::parseRelation(ParserThreadData *thread_data)
|
||||
{
|
||||
// TODO: leave early, if relation is not a restriction
|
||||
// TODO: reuse rawRestriction container
|
||||
if (!use_turn_restrictions)
|
||||
{
|
||||
return;
|
||||
}
|
||||
const OSMPBF::PrimitiveGroup &group =
|
||||
thread_data->PBFprimitiveBlock.primitivegroup(thread_data->currentGroupID);
|
||||
|
||||
for (int i = 0, relation_size = group.relations_size(); i < relation_size; ++i)
|
||||
{
|
||||
std::string except_tag_string;
|
||||
const OSMPBF::Relation &inputRelation =
|
||||
thread_data->PBFprimitiveBlock.primitivegroup(thread_data->currentGroupID).relations(i);
|
||||
bool is_restriction = false;
|
||||
bool is_only_restriction = false;
|
||||
for (int k = 0, endOfKeys = inputRelation.keys_size(); k < endOfKeys; ++k)
|
||||
{
|
||||
const std::string &key =
|
||||
thread_data->PBFprimitiveBlock.stringtable().s(inputRelation.keys(k));
|
||||
const std::string &val =
|
||||
thread_data->PBFprimitiveBlock.stringtable().s(inputRelation.vals(k));
|
||||
if ("type" == key)
|
||||
{
|
||||
if ("restriction" == val)
|
||||
{
|
||||
is_restriction = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (("restriction" == key) && (val.find("only_") == 0))
|
||||
{
|
||||
is_only_restriction = true;
|
||||
}
|
||||
if ("except" == key)
|
||||
{
|
||||
except_tag_string = val;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_restriction && ShouldIgnoreRestriction(except_tag_string))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_restriction)
|
||||
{
|
||||
int64_t last_ref = 0;
|
||||
InputRestrictionContainer current_restriction_container(is_only_restriction);
|
||||
for (int rolesIndex = 0, last_role = inputRelation.roles_sid_size();
|
||||
rolesIndex < last_role;
|
||||
++rolesIndex)
|
||||
{
|
||||
const std::string &role = thread_data->PBFprimitiveBlock.stringtable().s(
|
||||
inputRelation.roles_sid(rolesIndex));
|
||||
last_ref += inputRelation.memids(rolesIndex);
|
||||
|
||||
if (!("from" == role || "to" == role || "via" == role))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (inputRelation.types(rolesIndex))
|
||||
{
|
||||
case 0: // node
|
||||
if ("from" == role || "to" == role)
|
||||
{ // Only via should be a node
|
||||
continue;
|
||||
}
|
||||
BOOST_ASSERT("via" == role);
|
||||
if (std::numeric_limits<unsigned>::max() !=
|
||||
current_restriction_container.viaNode)
|
||||
{
|
||||
current_restriction_container.viaNode =
|
||||
std::numeric_limits<unsigned>::max();
|
||||
}
|
||||
BOOST_ASSERT(std::numeric_limits<unsigned>::max() ==
|
||||
current_restriction_container.viaNode);
|
||||
current_restriction_container.restriction.viaNode =
|
||||
static_cast<NodeID>(last_ref);
|
||||
break;
|
||||
case 1: // way
|
||||
BOOST_ASSERT("from" == role || "to" == role || "via" == role);
|
||||
if ("from" == role)
|
||||
{
|
||||
current_restriction_container.fromWay = static_cast<EdgeID>(last_ref);
|
||||
}
|
||||
if ("to" == role)
|
||||
{
|
||||
current_restriction_container.toWay = static_cast<EdgeID>(last_ref);
|
||||
}
|
||||
if ("via" == role)
|
||||
{
|
||||
BOOST_ASSERT(current_restriction_container.restriction.toNode ==
|
||||
std::numeric_limits<unsigned>::max());
|
||||
current_restriction_container.viaNode = static_cast<NodeID>(last_ref);
|
||||
}
|
||||
break;
|
||||
case 2: // relation, not used. relations relating to relations are evil.
|
||||
continue;
|
||||
BOOST_ASSERT(false);
|
||||
break;
|
||||
|
||||
default: // should not happen
|
||||
BOOST_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!extractor_callbacks->ProcessRestriction(current_restriction_container))
|
||||
{
|
||||
std::cerr << "[PBFParser] relation not parsed" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void PBFParser::parseWay(ParserThreadData *thread_data)
|
||||
{
|
||||
const int number_of_ways =
|
||||
thread_data->PBFprimitiveBlock.primitivegroup(thread_data->currentGroupID).ways_size();
|
||||
std::vector<ExtractionWay> parsed_way_vector(number_of_ways);
|
||||
for (int i = 0; i < number_of_ways; ++i)
|
||||
{
|
||||
const OSMPBF::Way &input_way =
|
||||
thread_data->PBFprimitiveBlock.primitivegroup(thread_data->currentGroupID).ways(i);
|
||||
parsed_way_vector[i].id = static_cast<EdgeID>(input_way.id());
|
||||
unsigned node_id_in_path = 0;
|
||||
const auto number_of_referenced_nodes = input_way.refs_size();
|
||||
for (auto j = 0; j < number_of_referenced_nodes; ++j)
|
||||
{
|
||||
node_id_in_path += static_cast<NodeID>(input_way.refs(j));
|
||||
parsed_way_vector[i].path.push_back(node_id_in_path);
|
||||
}
|
||||
BOOST_ASSERT(input_way.keys_size() == input_way.vals_size());
|
||||
const auto number_of_keys = input_way.keys_size();
|
||||
for (auto j = 0; j < number_of_keys; ++j)
|
||||
{
|
||||
const std::string &key =
|
||||
thread_data->PBFprimitiveBlock.stringtable().s(input_way.keys(j));
|
||||
const std::string &val =
|
||||
thread_data->PBFprimitiveBlock.stringtable().s(input_way.vals(j));
|
||||
parsed_way_vector[i].keyVals.Add(std::move(key), std::move(val));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: investigate if schedule guided will be handled by tbb automatically
|
||||
tbb::parallel_for(tbb::blocked_range<size_t>(0, parsed_way_vector.size()),
|
||||
[this, &parsed_way_vector](const tbb::blocked_range<size_t> &range)
|
||||
{
|
||||
lua_State *lua_state = this->scripting_environment.getLuaState();
|
||||
for (size_t i = range.begin(); i != range.end(); i++)
|
||||
{
|
||||
ExtractionWay &extraction_way = parsed_way_vector[i];
|
||||
if (2 <= extraction_way.path.size())
|
||||
{
|
||||
ParseWayInLua(extraction_way, lua_state);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (ExtractionWay &extraction_way : parsed_way_vector)
|
||||
{
|
||||
if (2 <= extraction_way.path.size())
|
||||
{
|
||||
extractor_callbacks->ProcessWay(extraction_way);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void PBFParser::loadGroup(ParserThreadData *thread_data)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
++group_count;
|
||||
#endif
|
||||
|
||||
const OSMPBF::PrimitiveGroup &group =
|
||||
thread_data->PBFprimitiveBlock.primitivegroup(thread_data->currentGroupID);
|
||||
thread_data->entityTypeIndicator = TypeDummy;
|
||||
if (0 != group.nodes_size())
|
||||
{
|
||||
thread_data->entityTypeIndicator = TypeNode;
|
||||
}
|
||||
if (0 != group.ways_size())
|
||||
{
|
||||
thread_data->entityTypeIndicator = TypeWay;
|
||||
}
|
||||
if (0 != group.relations_size())
|
||||
{
|
||||
thread_data->entityTypeIndicator = TypeRelation;
|
||||
}
|
||||
if (group.has_dense())
|
||||
{
|
||||
thread_data->entityTypeIndicator = TypeDenseNode;
|
||||
BOOST_ASSERT(0 != group.dense().id_size());
|
||||
}
|
||||
BOOST_ASSERT(thread_data->entityTypeIndicator != TypeDummy);
|
||||
}
|
||||
|
||||
inline void PBFParser::loadBlock(ParserThreadData *thread_data)
|
||||
{
|
||||
++block_count;
|
||||
thread_data->currentGroupID = 0;
|
||||
thread_data->currentEntityID = 0;
|
||||
}
|
||||
|
||||
inline bool PBFParser::readPBFBlobHeader(std::fstream &stream, ParserThreadData *thread_data)
|
||||
{
|
||||
int size(0);
|
||||
stream.read((char *)&size, sizeof(int));
|
||||
size = SwapEndian(size);
|
||||
if (stream.eof())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (size > MAX_BLOB_HEADER_SIZE || size < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
char *data = new char[size];
|
||||
stream.read(data, size * sizeof(data[0]));
|
||||
|
||||
bool dataSuccessfullyParsed = (thread_data->PBFBlobHeader).ParseFromArray(data, size);
|
||||
delete[] data;
|
||||
return dataSuccessfullyParsed;
|
||||
}
|
||||
|
||||
inline bool PBFParser::unpackZLIB(ParserThreadData *thread_data)
|
||||
{
|
||||
auto raw_size = thread_data->PBFBlob.raw_size();
|
||||
char *unpacked_data_array = new char[raw_size];
|
||||
z_stream compressed_data_stream;
|
||||
compressed_data_stream.next_in = (unsigned char *)thread_data->PBFBlob.zlib_data().data();
|
||||
compressed_data_stream.avail_in = thread_data->PBFBlob.zlib_data().size();
|
||||
compressed_data_stream.next_out = (unsigned char *)unpacked_data_array;
|
||||
compressed_data_stream.avail_out = raw_size;
|
||||
compressed_data_stream.zalloc = Z_NULL;
|
||||
compressed_data_stream.zfree = Z_NULL;
|
||||
compressed_data_stream.opaque = Z_NULL;
|
||||
int return_code = inflateInit(&compressed_data_stream);
|
||||
if (return_code != Z_OK)
|
||||
{
|
||||
std::cerr << "[error] failed to init zlib stream" << std::endl;
|
||||
delete[] unpacked_data_array;
|
||||
return false;
|
||||
}
|
||||
|
||||
return_code = inflate(&compressed_data_stream, Z_FINISH);
|
||||
if (return_code != Z_STREAM_END)
|
||||
{
|
||||
std::cerr << "[error] failed to inflate zlib stream" << std::endl;
|
||||
std::cerr << "[error] Error type: " << return_code << std::endl;
|
||||
delete[] unpacked_data_array;
|
||||
return false;
|
||||
}
|
||||
|
||||
return_code = inflateEnd(&compressed_data_stream);
|
||||
if (return_code != Z_OK)
|
||||
{
|
||||
std::cerr << "[error] failed to deinit zlib stream" << std::endl;
|
||||
delete[] unpacked_data_array;
|
||||
return false;
|
||||
}
|
||||
|
||||
thread_data->charBuffer.clear();
|
||||
thread_data->charBuffer.resize(raw_size);
|
||||
std::copy(unpacked_data_array, unpacked_data_array + raw_size, thread_data->charBuffer.begin());
|
||||
delete[] unpacked_data_array;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool PBFParser::unpackLZMA(ParserThreadData *) { return false; }
|
||||
|
||||
inline bool PBFParser::readBlob(std::fstream &stream, ParserThreadData *thread_data)
|
||||
{
|
||||
if (stream.eof())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const int size = thread_data->PBFBlobHeader.datasize();
|
||||
if (size < 0 || size > MAX_BLOB_SIZE)
|
||||
{
|
||||
std::cerr << "[error] invalid Blob size:" << size << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
char *data = new char[size];
|
||||
stream.read(data, sizeof(data[0]) * size);
|
||||
|
||||
if (!thread_data->PBFBlob.ParseFromArray(data, size))
|
||||
{
|
||||
std::cerr << "[error] failed to parse blob" << std::endl;
|
||||
delete[] data;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (thread_data->PBFBlob.has_raw())
|
||||
{
|
||||
const std::string &data = thread_data->PBFBlob.raw();
|
||||
thread_data->charBuffer.clear();
|
||||
thread_data->charBuffer.resize(data.size());
|
||||
std::copy(data.begin(), data.end(), thread_data->charBuffer.begin());
|
||||
}
|
||||
else if (thread_data->PBFBlob.has_zlib_data())
|
||||
{
|
||||
if (!unpackZLIB(thread_data))
|
||||
{
|
||||
std::cerr << "[error] zlib data encountered that could not be unpacked" << std::endl;
|
||||
delete[] data;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (thread_data->PBFBlob.has_lzma_data())
|
||||
{
|
||||
if (!unpackLZMA(thread_data))
|
||||
{
|
||||
std::cerr << "[error] lzma data encountered that could not be unpacked" << std::endl;
|
||||
}
|
||||
delete[] data;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "[error] Blob contains no data" << std::endl;
|
||||
delete[] data;
|
||||
return false;
|
||||
}
|
||||
delete[] data;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PBFParser::readNextBlock(std::fstream &stream, ParserThreadData *thread_data)
|
||||
{
|
||||
if (stream.eof())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!readPBFBlobHeader(stream, thread_data))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (thread_data->PBFBlobHeader.type() != "OSMData")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!readBlob(stream, thread_data))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!thread_data->PBFprimitiveBlock.ParseFromArray(&(thread_data->charBuffer[0]),
|
||||
thread_data->charBuffer.size()))
|
||||
{
|
||||
std::cerr << "failed to parse PrimitiveBlock" << std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef PBFPARSER_H_
|
||||
#define PBFPARSER_H_
|
||||
|
||||
#include "BaseParser.h"
|
||||
#include "../DataStructures/ConcurrentQueue.h"
|
||||
|
||||
#include <osmpbf/fileformat.pb.h>
|
||||
#include <osmpbf/osmformat.pb.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
|
||||
class PBFParser : public BaseParser
|
||||
{
|
||||
|
||||
enum EntityType
|
||||
{ TypeDummy = 0,
|
||||
TypeNode = 1,
|
||||
TypeWay = 2,
|
||||
TypeRelation = 4,
|
||||
TypeDenseNode = 8 };
|
||||
|
||||
struct ParserThreadData
|
||||
{
|
||||
int currentGroupID;
|
||||
int currentEntityID;
|
||||
EntityType entityTypeIndicator;
|
||||
|
||||
OSMPBF::BlobHeader PBFBlobHeader;
|
||||
OSMPBF::Blob PBFBlob;
|
||||
|
||||
OSMPBF::HeaderBlock PBFHeaderBlock;
|
||||
OSMPBF::PrimitiveBlock PBFprimitiveBlock;
|
||||
|
||||
std::vector<char> charBuffer;
|
||||
};
|
||||
|
||||
public:
|
||||
PBFParser(const char *file_name,
|
||||
ExtractorCallbacks *extractor_callbacks,
|
||||
ScriptingEnvironment &scripting_environment,
|
||||
unsigned num_parser_threads = 0);
|
||||
virtual ~PBFParser();
|
||||
|
||||
inline bool ReadHeader();
|
||||
inline bool Parse();
|
||||
|
||||
private:
|
||||
inline void ReadData();
|
||||
inline void ParseData();
|
||||
inline void parseDenseNode(ParserThreadData *thread_data);
|
||||
inline void parseNode(ParserThreadData *thread_data);
|
||||
inline void parseRelation(ParserThreadData *thread_data);
|
||||
inline void parseWay(ParserThreadData *thread_data);
|
||||
|
||||
inline void loadGroup(ParserThreadData *thread_data);
|
||||
inline void loadBlock(ParserThreadData *thread_data);
|
||||
inline bool readPBFBlobHeader(std::fstream &stream, ParserThreadData *thread_data);
|
||||
inline bool unpackZLIB(ParserThreadData *thread_data);
|
||||
inline bool unpackLZMA(ParserThreadData *thread_data);
|
||||
inline bool readBlob(std::fstream &stream, ParserThreadData *thread_data);
|
||||
inline bool readNextBlock(std::fstream &stream, ParserThreadData *thread_data);
|
||||
|
||||
static const int NANO = 1000 * 1000 * 1000;
|
||||
static const int MAX_BLOB_HEADER_SIZE = 64 * 1024;
|
||||
static const int MAX_BLOB_SIZE = 32 * 1024 * 1024;
|
||||
|
||||
unsigned group_count;
|
||||
unsigned block_count;
|
||||
|
||||
std::fstream input; // the input stream to parse
|
||||
std::shared_ptr<ConcurrentQueue<ParserThreadData *>> thread_data_queue;
|
||||
unsigned num_parser_threads;
|
||||
};
|
||||
|
||||
#endif /* PBFPARSER_H_ */
|
||||
@@ -1,121 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "ScriptingEnvironment.h"
|
||||
|
||||
#include "ExtractionHelperFunctions.h"
|
||||
#include "ExtractionWay.h"
|
||||
#include "../DataStructures/ImportNode.h"
|
||||
#include "../Util/LuaUtil.h"
|
||||
#include "../Util/OSRMException.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
ScriptingEnvironment::ScriptingEnvironment() {}
|
||||
ScriptingEnvironment::ScriptingEnvironment(const char *file_name)
|
||||
: file_name(file_name)
|
||||
{
|
||||
SimpleLogger().Write() << "Using script " << file_name;
|
||||
}
|
||||
|
||||
void ScriptingEnvironment::initLuaState(lua_State* lua_state)
|
||||
{
|
||||
luabind::open(lua_state);
|
||||
// open utility libraries string library;
|
||||
luaL_openlibs(lua_state);
|
||||
|
||||
luaAddScriptFolderToLoadPath(lua_state, file_name.c_str());
|
||||
|
||||
// Add our function to the state's global scope
|
||||
luabind::module(lua_state)[
|
||||
luabind::def("print", LUA_print<std::string>),
|
||||
luabind::def("durationIsValid", durationIsValid),
|
||||
luabind::def("parseDuration", parseDuration)
|
||||
];
|
||||
|
||||
luabind::module(lua_state)[luabind::class_<HashTable<std::string, std::string>>("keyVals")
|
||||
.def("Add", &HashTable<std::string, std::string>::Add)
|
||||
.def("Find", &HashTable<std::string, std::string>::Find)
|
||||
.def("Holds", &HashTable<std::string, std::string>::Holds)];
|
||||
|
||||
luabind::module(lua_state)[luabind::class_<ImportNode>("Node")
|
||||
.def(luabind::constructor<>())
|
||||
.def_readwrite("lat", &ImportNode::lat)
|
||||
.def_readwrite("lon", &ImportNode::lon)
|
||||
.def_readonly("id", &ImportNode::node_id)
|
||||
.def_readwrite("bollard", &ImportNode::bollard)
|
||||
.def_readwrite("traffic_light", &ImportNode::trafficLight)
|
||||
.def_readwrite("tags", &ImportNode::keyVals)];
|
||||
|
||||
luabind::module(lua_state)
|
||||
[luabind::class_<ExtractionWay>("Way")
|
||||
.def(luabind::constructor<>())
|
||||
.def_readonly("id", &ExtractionWay::id)
|
||||
.def_readwrite("name", &ExtractionWay::name)
|
||||
.def_readwrite("speed", &ExtractionWay::speed)
|
||||
.def_readwrite("backward_speed", &ExtractionWay::backward_speed)
|
||||
.def_readwrite("duration", &ExtractionWay::duration)
|
||||
.def_readwrite("type", &ExtractionWay::type)
|
||||
.def_readwrite("access", &ExtractionWay::access)
|
||||
.def_readwrite("roundabout", &ExtractionWay::roundabout)
|
||||
.def_readwrite("is_access_restricted", &ExtractionWay::isAccessRestricted)
|
||||
.def_readwrite("ignore_in_grid", &ExtractionWay::ignoreInGrid)
|
||||
.def_readwrite("tags", &ExtractionWay::keyVals)
|
||||
.def_readwrite("direction", &ExtractionWay::direction)
|
||||
.enum_("constants")[
|
||||
luabind::value("notSure", 0),
|
||||
luabind::value("oneway", 1),
|
||||
luabind::value("bidirectional", 2),
|
||||
luabind::value("opposite", 3)
|
||||
]];
|
||||
|
||||
// fails on c++11/OS X 10.9
|
||||
luabind::module(lua_state)[luabind::class_<std::vector<std::string>>("vector").def(
|
||||
"Add",
|
||||
static_cast<void (std::vector<std::string>::*)(const std::string &)>(
|
||||
&std::vector<std::string>::push_back))];
|
||||
|
||||
if (0 != luaL_dofile(lua_state, file_name.c_str()))
|
||||
{
|
||||
throw OSRMException("ERROR occured in scripting block");
|
||||
}
|
||||
}
|
||||
|
||||
lua_State *ScriptingEnvironment::getLuaState()
|
||||
{
|
||||
bool initialized = false;
|
||||
auto& ref = script_contexts.local(initialized);
|
||||
if (!initialized)
|
||||
{
|
||||
std::shared_ptr<lua_State> state(luaL_newstate(), lua_close);
|
||||
ref = state;
|
||||
initLuaState(ref.get());
|
||||
}
|
||||
|
||||
return ref.get();
|
||||
}
|
||||
|
||||
@@ -1,353 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "XMLParser.h"
|
||||
|
||||
#include "ExtractionWay.h"
|
||||
#include "ExtractorCallbacks.h"
|
||||
|
||||
#include "../DataStructures/HashTable.h"
|
||||
#include "../DataStructures/ImportNode.h"
|
||||
#include "../DataStructures/InputReaderFactory.h"
|
||||
#include "../DataStructures/Restriction.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
#include "../Util/StringUtil.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <osrm/Coordinate.h>
|
||||
|
||||
XMLParser::XMLParser(const char *filename,
|
||||
ExtractorCallbacks *extractor_callbacks,
|
||||
ScriptingEnvironment &scripting_environment)
|
||||
: BaseParser(extractor_callbacks, scripting_environment)
|
||||
{
|
||||
inputReader = inputReaderFactory(filename);
|
||||
}
|
||||
|
||||
bool XMLParser::ReadHeader() { return xmlTextReaderRead(inputReader) == 1; }
|
||||
bool XMLParser::Parse()
|
||||
{
|
||||
while (xmlTextReaderRead(inputReader) == 1)
|
||||
{
|
||||
const int type = xmlTextReaderNodeType(inputReader);
|
||||
|
||||
// 1 is Element
|
||||
if (type != 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
xmlChar *currentName = xmlTextReaderName(inputReader);
|
||||
if (currentName == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (xmlStrEqual(currentName, (const xmlChar *)"node") == 1)
|
||||
{
|
||||
ImportNode current_node = ReadXMLNode();
|
||||
ParseNodeInLua(current_node, lua_state);
|
||||
extractor_callbacks->ProcessNode(current_node);
|
||||
}
|
||||
|
||||
if (xmlStrEqual(currentName, (const xmlChar *)"way") == 1)
|
||||
{
|
||||
ExtractionWay way = ReadXMLWay();
|
||||
ParseWayInLua(way, lua_state);
|
||||
extractor_callbacks->ProcessWay(way);
|
||||
}
|
||||
if (use_turn_restrictions && xmlStrEqual(currentName, (const xmlChar *)"relation") == 1)
|
||||
{
|
||||
InputRestrictionContainer current_restriction = ReadXMLRestriction();
|
||||
if ((UINT_MAX != current_restriction.fromWay) &&
|
||||
!extractor_callbacks->ProcessRestriction(current_restriction))
|
||||
{
|
||||
std::cerr << "[XMLParser] restriction not parsed" << std::endl;
|
||||
}
|
||||
}
|
||||
xmlFree(currentName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
InputRestrictionContainer XMLParser::ReadXMLRestriction()
|
||||
{
|
||||
|
||||
InputRestrictionContainer restriction;
|
||||
|
||||
if (xmlTextReaderIsEmptyElement(inputReader) == 1)
|
||||
{
|
||||
return restriction;
|
||||
}
|
||||
|
||||
std::string except_tag_string;
|
||||
const int depth = xmlTextReaderDepth(inputReader);
|
||||
while (xmlTextReaderRead(inputReader) == 1)
|
||||
{
|
||||
const int child_type = xmlTextReaderNodeType(inputReader);
|
||||
if (child_type != 1 && child_type != 15)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
const int child_depth = xmlTextReaderDepth(inputReader);
|
||||
xmlChar *child_name = xmlTextReaderName(inputReader);
|
||||
if (child_name == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (depth == child_depth && child_type == 15 &&
|
||||
xmlStrEqual(child_name, (const xmlChar *)"relation") == 1)
|
||||
{
|
||||
xmlFree(child_name);
|
||||
break;
|
||||
}
|
||||
if (child_type != 1)
|
||||
{
|
||||
xmlFree(child_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (xmlStrEqual(child_name, (const xmlChar *)"tag") == 1)
|
||||
{
|
||||
xmlChar *key = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"k");
|
||||
xmlChar *value = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"v");
|
||||
if (key != nullptr && value != nullptr)
|
||||
{
|
||||
if (xmlStrEqual(key, (const xmlChar *)"restriction") &&
|
||||
StringStartsWith((const char *)value, "only_"))
|
||||
{
|
||||
restriction.restriction.flags.isOnly = true;
|
||||
}
|
||||
if (xmlStrEqual(key, (const xmlChar *)"except"))
|
||||
{
|
||||
except_tag_string = (const char *)value;
|
||||
}
|
||||
}
|
||||
|
||||
if (key != nullptr)
|
||||
{
|
||||
xmlFree(key);
|
||||
}
|
||||
if (value != nullptr)
|
||||
{
|
||||
xmlFree(value);
|
||||
}
|
||||
}
|
||||
else if (xmlStrEqual(child_name, (const xmlChar *)"member") == 1)
|
||||
{
|
||||
xmlChar *ref = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"ref");
|
||||
if (ref != nullptr)
|
||||
{
|
||||
xmlChar *role = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"role");
|
||||
xmlChar *type = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"type");
|
||||
|
||||
if (xmlStrEqual(role, (const xmlChar *)"to") &&
|
||||
xmlStrEqual(type, (const xmlChar *)"way"))
|
||||
{
|
||||
restriction.toWay = StringToUint((const char *)ref);
|
||||
}
|
||||
if (xmlStrEqual(role, (const xmlChar *)"from") &&
|
||||
xmlStrEqual(type, (const xmlChar *)"way"))
|
||||
{
|
||||
restriction.fromWay = StringToUint((const char *)ref);
|
||||
}
|
||||
if (xmlStrEqual(role, (const xmlChar *)"via") &&
|
||||
xmlStrEqual(type, (const xmlChar *)"node"))
|
||||
{
|
||||
restriction.restriction.viaNode = StringToUint((const char *)ref);
|
||||
}
|
||||
|
||||
if (nullptr != type)
|
||||
{
|
||||
xmlFree(type);
|
||||
}
|
||||
if (nullptr != role)
|
||||
{
|
||||
xmlFree(role);
|
||||
}
|
||||
if (nullptr != ref)
|
||||
{
|
||||
xmlFree(ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
xmlFree(child_name);
|
||||
}
|
||||
|
||||
if (ShouldIgnoreRestriction(except_tag_string))
|
||||
{
|
||||
restriction.fromWay = UINT_MAX; // workaround to ignore the restriction
|
||||
}
|
||||
return restriction;
|
||||
}
|
||||
|
||||
ExtractionWay XMLParser::ReadXMLWay()
|
||||
{
|
||||
ExtractionWay way;
|
||||
if (xmlTextReaderIsEmptyElement(inputReader) == 1)
|
||||
{
|
||||
return way;
|
||||
}
|
||||
const int depth = xmlTextReaderDepth(inputReader);
|
||||
while (xmlTextReaderRead(inputReader) == 1)
|
||||
{
|
||||
const int child_type = xmlTextReaderNodeType(inputReader);
|
||||
if (child_type != 1 && child_type != 15)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
const int child_depth = xmlTextReaderDepth(inputReader);
|
||||
xmlChar *child_name = xmlTextReaderName(inputReader);
|
||||
if (child_name == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (depth == child_depth && child_type == 15 &&
|
||||
xmlStrEqual(child_name, (const xmlChar *)"way") == 1)
|
||||
{
|
||||
xmlChar *node_id = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"id");
|
||||
way.id = StringToUint((char *)node_id);
|
||||
xmlFree(node_id);
|
||||
xmlFree(child_name);
|
||||
break;
|
||||
}
|
||||
if (child_type != 1)
|
||||
{
|
||||
xmlFree(child_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (xmlStrEqual(child_name, (const xmlChar *)"tag") == 1)
|
||||
{
|
||||
xmlChar *key = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"k");
|
||||
xmlChar *value = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"v");
|
||||
|
||||
if (key != nullptr && value != nullptr)
|
||||
{
|
||||
way.keyVals.Add(std::string((char *)key), std::string((char *)value));
|
||||
}
|
||||
if (key != nullptr)
|
||||
{
|
||||
xmlFree(key);
|
||||
}
|
||||
if (value != nullptr)
|
||||
{
|
||||
xmlFree(value);
|
||||
}
|
||||
}
|
||||
else if (xmlStrEqual(child_name, (const xmlChar *)"nd") == 1)
|
||||
{
|
||||
xmlChar *ref = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"ref");
|
||||
if (ref != nullptr)
|
||||
{
|
||||
way.path.push_back(StringToUint((const char *)ref));
|
||||
xmlFree(ref);
|
||||
}
|
||||
}
|
||||
xmlFree(child_name);
|
||||
}
|
||||
return way;
|
||||
}
|
||||
|
||||
ImportNode XMLParser::ReadXMLNode()
|
||||
{
|
||||
ImportNode node;
|
||||
|
||||
xmlChar *attribute = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"lat");
|
||||
if (attribute != nullptr)
|
||||
{
|
||||
node.lat = static_cast<int>(COORDINATE_PRECISION * StringToDouble((const char *)attribute));
|
||||
xmlFree(attribute);
|
||||
}
|
||||
attribute = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"lon");
|
||||
if (attribute != nullptr)
|
||||
{
|
||||
node.lon = static_cast<int>(COORDINATE_PRECISION * StringToDouble((const char *)attribute));
|
||||
xmlFree(attribute);
|
||||
}
|
||||
attribute = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"id");
|
||||
if (attribute != nullptr)
|
||||
{
|
||||
node.node_id = StringToUint((const char *)attribute);
|
||||
xmlFree(attribute);
|
||||
}
|
||||
|
||||
if (xmlTextReaderIsEmptyElement(inputReader) == 1)
|
||||
{
|
||||
return node;
|
||||
}
|
||||
const int depth = xmlTextReaderDepth(inputReader);
|
||||
while (xmlTextReaderRead(inputReader) == 1)
|
||||
{
|
||||
const int child_type = xmlTextReaderNodeType(inputReader);
|
||||
// 1 = Element, 15 = EndElement
|
||||
if (child_type != 1 && child_type != 15)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
const int child_depth = xmlTextReaderDepth(inputReader);
|
||||
xmlChar *child_name = xmlTextReaderName(inputReader);
|
||||
if (child_name == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (depth == child_depth && child_type == 15 &&
|
||||
xmlStrEqual(child_name, (const xmlChar *)"node") == 1)
|
||||
{
|
||||
xmlFree(child_name);
|
||||
break;
|
||||
}
|
||||
if (child_type != 1)
|
||||
{
|
||||
xmlFree(child_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (xmlStrEqual(child_name, (const xmlChar *)"tag") == 1)
|
||||
{
|
||||
xmlChar *key = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"k");
|
||||
xmlChar *value = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"v");
|
||||
if (key != nullptr && value != nullptr)
|
||||
{
|
||||
node.keyVals.Add(std::string((char *)(key)), std::string((char *)(value)));
|
||||
}
|
||||
if (key != nullptr)
|
||||
{
|
||||
xmlFree(key);
|
||||
}
|
||||
if (value != nullptr)
|
||||
{
|
||||
xmlFree(value);
|
||||
}
|
||||
}
|
||||
|
||||
xmlFree(child_name);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
+21
-13
@@ -28,22 +28,32 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#ifndef FIXED_POINT_COORDINATE_H_
|
||||
#define FIXED_POINT_COORDINATE_H_
|
||||
|
||||
#include <functional>
|
||||
#include <iosfwd> //for std::ostream
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
const float COORDINATE_PRECISION = 1000000.f;
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr float COORDINATE_PRECISION = 1000000.f;
|
||||
}
|
||||
struct FixedPointCoordinate
|
||||
{
|
||||
int lat;
|
||||
int lon;
|
||||
|
||||
FixedPointCoordinate();
|
||||
explicit FixedPointCoordinate(int lat, int lon);
|
||||
FixedPointCoordinate(int lat, int lon);
|
||||
|
||||
template<class T>
|
||||
FixedPointCoordinate(const T &coordinate) : lat(coordinate.lat), lon(coordinate.lon)
|
||||
{
|
||||
static_assert(std::is_same<decltype(lat), decltype(coordinate.lat)>::value, "coordinate types incompatible");
|
||||
static_assert(std::is_same<decltype(lon), decltype(coordinate.lon)>::value, "coordinate types incompatible");
|
||||
}
|
||||
|
||||
void Reset();
|
||||
bool isSet() const;
|
||||
bool isValid() const;
|
||||
bool is_valid() const;
|
||||
bool operator==(const FixedPointCoordinate &other) const;
|
||||
|
||||
static double
|
||||
@@ -55,10 +65,8 @@ struct FixedPointCoordinate
|
||||
static float ApproximateEuclideanDistance(const FixedPointCoordinate &first_coordinate,
|
||||
const FixedPointCoordinate &second_coordinate);
|
||||
|
||||
static float ApproximateEuclideanDistance(const int lat1,
|
||||
const int lon1,
|
||||
const int lat2,
|
||||
const int lon2);
|
||||
static float
|
||||
ApproximateEuclideanDistance(const int lat1, const int lon1, const int lat2, const int lon2);
|
||||
|
||||
static float ApproximateSquaredEuclideanDistance(const FixedPointCoordinate &first_coordinate,
|
||||
const FixedPointCoordinate &second_coordinate);
|
||||
@@ -81,10 +89,10 @@ struct FixedPointCoordinate
|
||||
FixedPointCoordinate &nearest_location,
|
||||
float &ratio);
|
||||
|
||||
static int OrderedPerpendicularDistanceApproximation(const FixedPointCoordinate& segment_source,
|
||||
const FixedPointCoordinate& segment_target,
|
||||
const FixedPointCoordinate& query_location);
|
||||
|
||||
static int
|
||||
OrderedPerpendicularDistanceApproximation(const FixedPointCoordinate &segment_source,
|
||||
const FixedPointCoordinate &segment_target,
|
||||
const FixedPointCoordinate &query_location);
|
||||
|
||||
static float GetBearing(const FixedPointCoordinate &A, const FixedPointCoordinate &B);
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ struct Header
|
||||
{
|
||||
Header& operator=(const Header& other) = default;
|
||||
Header(const std::string & name, const std::string & value) : name(name), value(value) {}
|
||||
Header(const Header && other) : name(std::move(other.name)), value(std::move(other.value)) {}
|
||||
Header(Header && other) : name(std::move(other.name)), value(std::move(other.value)) {}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
|
||||
@@ -40,9 +40,15 @@ struct RouteParameters
|
||||
RouteParameters();
|
||||
|
||||
void setZoomLevel(const short level);
|
||||
|
||||
void setNumberOfResults(const short number);
|
||||
|
||||
void setAlternateRouteFlag(const bool flag);
|
||||
|
||||
void setUTurn(const bool flag);
|
||||
|
||||
void setAllUTurns(const bool flag);
|
||||
|
||||
void setDeprecatedAPIFlag(const std::string &);
|
||||
|
||||
void setChecksum(const unsigned check_sum);
|
||||
@@ -71,12 +77,15 @@ struct RouteParameters
|
||||
bool geometry;
|
||||
bool compression;
|
||||
bool deprecatedAPI;
|
||||
bool uturn_default;
|
||||
unsigned check_sum;
|
||||
short num_results;
|
||||
std::string service;
|
||||
std::string output_format;
|
||||
std::string jsonp_parameter;
|
||||
std::string language;
|
||||
std::vector<std::string> hints;
|
||||
std::vector<bool> uturns;
|
||||
std::vector<FixedPointCoordinate> coordinates;
|
||||
};
|
||||
|
||||
|
||||
+4
-2
@@ -30,6 +30,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <osrm/ServerPaths.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
class OSRM_impl;
|
||||
struct RouteParameters;
|
||||
|
||||
@@ -41,10 +43,10 @@ class Reply;
|
||||
class OSRM
|
||||
{
|
||||
private:
|
||||
OSRM_impl *OSRM_pimpl_;
|
||||
std::unique_ptr<OSRM_impl> OSRM_pimpl_;
|
||||
|
||||
public:
|
||||
explicit OSRM(const ServerPaths &paths, const bool use_shared_memory = false);
|
||||
explicit OSRM(ServerPaths paths, const bool use_shared_memory = false);
|
||||
~OSRM();
|
||||
void RunQuery(RouteParameters &route_parameters, http::Reply &reply);
|
||||
};
|
||||
|
||||
+19
-21
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -34,18 +34,19 @@ namespace boost { namespace interprocess { class named_mutex; } }
|
||||
#include <osrm/RouteParameters.h>
|
||||
#include <osrm/ServerPaths.h>
|
||||
|
||||
#include "../Plugins/BasePlugin.h"
|
||||
#include "../Plugins/DistanceTablePlugin.h"
|
||||
#include "../Plugins/HelloWorldPlugin.h"
|
||||
#include "../Plugins/LocatePlugin.h"
|
||||
#include "../Plugins/NearestPlugin.h"
|
||||
#include "../Plugins/TimestampPlugin.h"
|
||||
#include "../Plugins/ViaRoutePlugin.h"
|
||||
#include "../plugins/distance_table.hpp"
|
||||
#include "../plugins/hello_world.hpp"
|
||||
#include "../plugins/locate.hpp"
|
||||
#include "../plugins/nearest.hpp"
|
||||
#include "../plugins/timestamp.hpp"
|
||||
#include "../plugins/viaroute.hpp"
|
||||
#include "../Server/DataStructures/BaseDataFacade.h"
|
||||
#include "../Server/DataStructures/InternalDataFacade.h"
|
||||
#include "../Server/DataStructures/SharedBarriers.h"
|
||||
#include "../Server/DataStructures/SharedDataFacade.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
#include "../Util/make_unique.hpp"
|
||||
#include "../Util/ProgramOptions.h"
|
||||
#include "../Util/simple_logger.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/interprocess/sync/named_condition.hpp>
|
||||
@@ -56,16 +57,17 @@ namespace boost { namespace interprocess { class named_mutex; } }
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
OSRM_impl::OSRM_impl(const ServerPaths &server_paths, const bool use_shared_memory)
|
||||
: use_shared_memory(use_shared_memory)
|
||||
OSRM_impl::OSRM_impl(ServerPaths server_paths, const bool use_shared_memory)
|
||||
{
|
||||
if (use_shared_memory)
|
||||
{
|
||||
barrier = new SharedBarriers();
|
||||
barrier = osrm::make_unique<SharedBarriers>();
|
||||
query_data_facade = new SharedDataFacade<QueryEdge::EdgeData>();
|
||||
}
|
||||
else
|
||||
{
|
||||
// populate base path
|
||||
populate_base_path(server_paths);
|
||||
query_data_facade = new InternalDataFacade<QueryEdge::EdgeData>(server_paths);
|
||||
}
|
||||
|
||||
@@ -85,10 +87,6 @@ OSRM_impl::~OSRM_impl()
|
||||
{
|
||||
delete plugin_pointer.second;
|
||||
}
|
||||
if (use_shared_memory)
|
||||
{
|
||||
delete barrier;
|
||||
}
|
||||
}
|
||||
|
||||
void OSRM_impl::RegisterPlugin(BasePlugin *plugin)
|
||||
@@ -108,7 +106,7 @@ void OSRM_impl::RunQuery(RouteParameters &route_parameters, http::Reply &reply)
|
||||
if (plugin_map.end() != iter)
|
||||
{
|
||||
reply.status = http::Reply::ok;
|
||||
if (use_shared_memory)
|
||||
if (barrier)
|
||||
{
|
||||
// lock update pending
|
||||
boost::interprocess::scoped_lock<boost::interprocess::named_mutex> pending_lock(
|
||||
@@ -129,7 +127,7 @@ void OSRM_impl::RunQuery(RouteParameters &route_parameters, http::Reply &reply)
|
||||
}
|
||||
|
||||
iter->second->HandleRequest(route_parameters, reply);
|
||||
if (use_shared_memory)
|
||||
if (barrier)
|
||||
{
|
||||
// lock query
|
||||
boost::interprocess::scoped_lock<boost::interprocess::named_mutex> query_lock(
|
||||
@@ -154,12 +152,12 @@ void OSRM_impl::RunQuery(RouteParameters &route_parameters, http::Reply &reply)
|
||||
|
||||
// proxy code for compilation firewall
|
||||
|
||||
OSRM::OSRM(const ServerPaths &paths, const bool use_shared_memory)
|
||||
: OSRM_pimpl_(new OSRM_impl(paths, use_shared_memory))
|
||||
OSRM::OSRM(ServerPaths paths, const bool use_shared_memory)
|
||||
: OSRM_pimpl_(osrm::make_unique<OSRM_impl>(paths, use_shared_memory))
|
||||
{
|
||||
}
|
||||
|
||||
OSRM::~OSRM() { delete OSRM_pimpl_; }
|
||||
OSRM::~OSRM() { OSRM_pimpl_.reset(); }
|
||||
|
||||
void OSRM::RunQuery(RouteParameters &route_parameters, http::Reply &reply)
|
||||
{
|
||||
|
||||
+6
-5
@@ -34,8 +34,9 @@ struct RouteParameters;
|
||||
|
||||
#include <osrm/ServerPaths.h>
|
||||
|
||||
#include "../DataStructures/QueryEdge.h"
|
||||
#include "../data_structures/query_edge.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
|
||||
@@ -45,10 +46,10 @@ template <class EdgeDataT> class BaseDataFacade;
|
||||
class OSRM_impl
|
||||
{
|
||||
private:
|
||||
typedef std::unordered_map<std::string, BasePlugin *> PluginMap;
|
||||
using PluginMap = std::unordered_map<std::string, BasePlugin *>;
|
||||
|
||||
public:
|
||||
OSRM_impl(const ServerPaths &paths, const bool use_shared_memory);
|
||||
OSRM_impl(ServerPaths paths, const bool use_shared_memory);
|
||||
OSRM_impl(const OSRM_impl &) = delete;
|
||||
virtual ~OSRM_impl();
|
||||
void RunQuery(RouteParameters &route_parameters, http::Reply &reply);
|
||||
@@ -56,8 +57,8 @@ class OSRM_impl
|
||||
private:
|
||||
void RegisterPlugin(BasePlugin *plugin);
|
||||
PluginMap plugin_map;
|
||||
bool use_shared_memory;
|
||||
SharedBarriers *barrier;
|
||||
// will only be initialized if shared memory is used
|
||||
std::unique_ptr<SharedBarriers> barrier;
|
||||
// base class pointer to the objects
|
||||
BaseDataFacade<QueryEdge::EdgeData> *query_data_facade;
|
||||
};
|
||||
|
||||
@@ -1,173 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef VIA_ROUTE_PLUGIN_H
|
||||
#define VIA_ROUTE_PLUGIN_H
|
||||
|
||||
#include "BasePlugin.h"
|
||||
|
||||
#include "../Algorithms/ObjectToBase64.h"
|
||||
|
||||
#include "../DataStructures/QueryEdge.h"
|
||||
#include "../DataStructures/SearchEngine.h"
|
||||
#include "../Descriptors/BaseDescriptor.h"
|
||||
#include "../Descriptors/GPXDescriptor.h"
|
||||
#include "../Descriptors/JSONDescriptor.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
#include "../Util/StringUtil.h"
|
||||
#include "../Util/TimingUtil.h"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
template <class DataFacadeT> class ViaRoutePlugin : public BasePlugin
|
||||
{
|
||||
private:
|
||||
std::unordered_map<std::string, unsigned> descriptor_table;
|
||||
std::shared_ptr<SearchEngine<DataFacadeT>> search_engine_ptr;
|
||||
|
||||
public:
|
||||
explicit ViaRoutePlugin(DataFacadeT *facade) : descriptor_string("viaroute"), facade(facade)
|
||||
{
|
||||
search_engine_ptr = std::make_shared<SearchEngine<DataFacadeT>>(facade);
|
||||
|
||||
descriptor_table.emplace("json", 0);
|
||||
descriptor_table.emplace("gpx", 1);
|
||||
// descriptor_table.emplace("geojson", 2);
|
||||
}
|
||||
|
||||
virtual ~ViaRoutePlugin() {}
|
||||
|
||||
const std::string GetDescriptor() const { return descriptor_string; }
|
||||
|
||||
void HandleRequest(const RouteParameters &route_parameters, http::Reply &reply)
|
||||
{
|
||||
// check number of parameters
|
||||
if (2 > route_parameters.coordinates.size() ||
|
||||
std::any_of(begin(route_parameters.coordinates),
|
||||
end(route_parameters.coordinates),
|
||||
[&](FixedPointCoordinate coordinate)
|
||||
{ return !coordinate.isValid(); }))
|
||||
{
|
||||
reply = http::Reply::StockReply(http::Reply::badRequest);
|
||||
return;
|
||||
}
|
||||
|
||||
RawRouteData raw_route;
|
||||
raw_route.check_sum = facade->GetCheckSum();
|
||||
for (const FixedPointCoordinate &coordinate : route_parameters.coordinates)
|
||||
{
|
||||
raw_route.raw_via_node_coordinates.emplace_back(coordinate);
|
||||
}
|
||||
|
||||
std::vector<PhantomNode> phantom_node_vector(raw_route.raw_via_node_coordinates.size());
|
||||
const bool checksum_OK = (route_parameters.check_sum == raw_route.check_sum);
|
||||
|
||||
for (unsigned i = 0; i < raw_route.raw_via_node_coordinates.size(); ++i)
|
||||
{
|
||||
if (checksum_OK && i < route_parameters.hints.size() &&
|
||||
!route_parameters.hints[i].empty())
|
||||
{
|
||||
DecodeObjectFromBase64(route_parameters.hints[i], phantom_node_vector[i]);
|
||||
if (phantom_node_vector[i].isValid(facade->GetNumberOfNodes()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
facade->FindPhantomNodeForCoordinate(raw_route.raw_via_node_coordinates[i],
|
||||
phantom_node_vector[i],
|
||||
route_parameters.zoom_level);
|
||||
}
|
||||
|
||||
PhantomNodes current_phantom_node_pair;
|
||||
for (unsigned i = 0; i < phantom_node_vector.size() - 1; ++i)
|
||||
{
|
||||
current_phantom_node_pair.source_phantom = phantom_node_vector[i];
|
||||
current_phantom_node_pair.target_phantom = phantom_node_vector[i + 1];
|
||||
raw_route.segment_end_coordinates.emplace_back(current_phantom_node_pair);
|
||||
}
|
||||
|
||||
const bool is_alternate_requested = route_parameters.alternate_route;
|
||||
const bool is_only_one_segment = (1 == raw_route.segment_end_coordinates.size());
|
||||
if (is_alternate_requested && is_only_one_segment)
|
||||
{
|
||||
search_engine_ptr->alternative_path(raw_route.segment_end_coordinates.front(),
|
||||
raw_route);
|
||||
}
|
||||
else
|
||||
{
|
||||
search_engine_ptr->shortest_path(raw_route.segment_end_coordinates, raw_route);
|
||||
}
|
||||
|
||||
if (INVALID_EDGE_WEIGHT == raw_route.shortest_path_length)
|
||||
{
|
||||
SimpleLogger().Write(logDEBUG) << "Error occurred, single path not found";
|
||||
}
|
||||
reply.status = http::Reply::ok;
|
||||
|
||||
DescriptorConfig descriptor_config;
|
||||
|
||||
auto iter = descriptor_table.find(route_parameters.output_format);
|
||||
unsigned descriptor_type = (iter != descriptor_table.end() ? iter->second : 0);
|
||||
|
||||
descriptor_config.zoom_level = route_parameters.zoom_level;
|
||||
descriptor_config.instructions = route_parameters.print_instructions;
|
||||
descriptor_config.geometry = route_parameters.geometry;
|
||||
descriptor_config.encode_geometry = route_parameters.compression;
|
||||
|
||||
std::shared_ptr<BaseDescriptor<DataFacadeT>> descriptor;
|
||||
switch (descriptor_type)
|
||||
{
|
||||
// case 0:
|
||||
// descriptor = std::make_shared<JSONDescriptor<DataFacadeT>>();
|
||||
// break;
|
||||
case 1:
|
||||
descriptor = std::make_shared<GPXDescriptor<DataFacadeT>>(facade);
|
||||
break;
|
||||
// case 2:
|
||||
// descriptor = std::make_shared<GEOJSONDescriptor<DataFacadeT>>();
|
||||
// break;
|
||||
default:
|
||||
descriptor = std::make_shared<JSONDescriptor<DataFacadeT>>(facade);
|
||||
break;
|
||||
}
|
||||
|
||||
descriptor->SetConfig(descriptor_config);
|
||||
descriptor->Run(raw_route, reply);
|
||||
}
|
||||
|
||||
private:
|
||||
std::string descriptor_string;
|
||||
DataFacadeT *facade;
|
||||
};
|
||||
|
||||
#endif // VIA_ROUTE_PLUGIN_H
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
For instructions on how to compile and run OSRM, please consult the Wiki at
|
||||
|
||||
https://github.com/DennisOSRM/Project-OSRM/wiki
|
||||
https://github.com/Project-OSRM/osrm-backend/wiki
|
||||
|
||||
or use our free and daily updated online service at
|
||||
|
||||
@@ -35,6 +35,7 @@ When using the code in a (scientific) publication, please cite
|
||||
|
||||
| build config | branch | status |
|
||||
|:-------------|:--------|:------------|
|
||||
| Project OSRM | master | [](https://travis-ci.org/DennisOSRM/Project-OSRM) |
|
||||
| Project OSRM | develop | [](https://travis-ci.org/DennisOSRM/Project-OSRM) |
|
||||
| Linux | master | [](https://travis-ci.org/DennisOSRM/Project-OSRM) |
|
||||
| Linux | develop | [](https://travis-ci.org/DennisOSRM/Project-OSRM) |
|
||||
| Windows | master/develop | [](https://ci.appveyor.com/project/DennisOSRM/osrm-backend) |
|
||||
| LUAbind fork | master | [](https://travis-ci.org/DennisOSRM/luabind) |
|
||||
|
||||
@@ -6,7 +6,7 @@ require 'sys/proctable'
|
||||
|
||||
BUILD_FOLDER = 'build'
|
||||
DATA_FOLDER = 'sandbox'
|
||||
PROFILE = 'examples/postgis'
|
||||
PROFILE = 'bicycle'
|
||||
OSRM_PORT = 5000
|
||||
PROFILES_FOLDER = '../profiles'
|
||||
|
||||
@@ -181,3 +181,10 @@ end
|
||||
desc "Stop, reprocess and restart."
|
||||
task :update => [:down,:process,:up] do
|
||||
end
|
||||
|
||||
|
||||
desc "Remove test cache files."
|
||||
task :sweep do
|
||||
system "rm test/cache/*"
|
||||
end
|
||||
|
||||
|
||||
+6
-3
@@ -39,8 +39,8 @@ struct APIGrammar : qi::grammar<Iterator>
|
||||
{
|
||||
explicit APIGrammar(HandlerT * h) : APIGrammar::base_type(api_call), handler(h)
|
||||
{
|
||||
api_call = qi::lit('/') >> string[boost::bind(&HandlerT::setService, handler, ::_1)] >> *(query);
|
||||
query = ('?') >> (+(zoom | output | jsonp | checksum | location | hint | cmp | language | instruction | geometry | alt_route | old_API) ) ;
|
||||
api_call = qi::lit('/') >> string[boost::bind(&HandlerT::setService, handler, ::_1)] >> *(query) >> -(uturns);
|
||||
query = ('?') >> (+(zoom | output | jsonp | checksum | location | hint | u | cmp | language | instruction | geometry | alt_route | old_API | num_results) ) ;
|
||||
|
||||
zoom = (-qi::lit('&')) >> qi::lit('z') >> '=' >> qi::short_[boost::bind(&HandlerT::setZoomLevel, handler, ::_1)];
|
||||
output = (-qi::lit('&')) >> qi::lit("output") >> '=' >> string[boost::bind(&HandlerT::setOutputFormat, handler, ::_1)];
|
||||
@@ -51,9 +51,12 @@ struct APIGrammar : qi::grammar<Iterator>
|
||||
cmp = (-qi::lit('&')) >> qi::lit("compression") >> '=' >> qi::bool_[boost::bind(&HandlerT::setCompressionFlag, handler, ::_1)];
|
||||
location = (-qi::lit('&')) >> qi::lit("loc") >> '=' >> (qi::double_ >> qi::lit(',') >> qi::double_)[boost::bind(&HandlerT::addCoordinate, handler, ::_1)];
|
||||
hint = (-qi::lit('&')) >> qi::lit("hint") >> '=' >> stringwithDot[boost::bind(&HandlerT::addHint, handler, ::_1)];
|
||||
u = (-qi::lit('&')) >> qi::lit("u") >> '=' >> qi::bool_[boost::bind(&HandlerT::setUTurn, handler, ::_1)];
|
||||
uturns = (-qi::lit('&')) >> qi::lit("uturns") >> '=' >> qi::bool_[boost::bind(&HandlerT::setAllUTurns, handler, ::_1)];
|
||||
language = (-qi::lit('&')) >> qi::lit("hl") >> '=' >> string[boost::bind(&HandlerT::setLanguage, handler, ::_1)];
|
||||
alt_route = (-qi::lit('&')) >> qi::lit("alt") >> '=' >> qi::bool_[boost::bind(&HandlerT::setAlternateRouteFlag, handler, ::_1)];
|
||||
old_API = (-qi::lit('&')) >> qi::lit("geomformat") >> '=' >> string[boost::bind(&HandlerT::setDeprecatedAPIFlag, handler, ::_1)];
|
||||
num_results = (-qi::lit('&')) >> qi::lit("num_results") >> '=' >> qi::short_[boost::bind(&HandlerT::setNumberOfResults, handler, ::_1)];
|
||||
|
||||
string = +(qi::char_("a-zA-Z"));
|
||||
stringwithDot = +(qi::char_("a-zA-Z0-9_.-"));
|
||||
@@ -63,7 +66,7 @@ struct APIGrammar : qi::grammar<Iterator>
|
||||
qi::rule<Iterator> api_call, query;
|
||||
qi::rule<Iterator, std::string()> service, zoom, output, string, jsonp, checksum, location, hint,
|
||||
stringwithDot, stringwithPercent, language, instruction, geometry,
|
||||
cmp, alt_route, old_API;
|
||||
cmp, alt_route, u, uturns, old_API, num_results;
|
||||
|
||||
HandlerT * handler;
|
||||
};
|
||||
|
||||
@@ -69,10 +69,10 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t
|
||||
CompressionType compression_type(noCompression);
|
||||
boost::tribool result;
|
||||
boost::tie(result, boost::tuples::ignore) =
|
||||
request_parser.Parse(request,
|
||||
RequestParser().Parse(request,
|
||||
incoming_data_buffer.data(),
|
||||
incoming_data_buffer.data() + bytes_transferred,
|
||||
&compression_type);
|
||||
compression_type);
|
||||
|
||||
// the request has been parsed
|
||||
if (result)
|
||||
|
||||
+1
-3
@@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#ifndef CONNECTION_H
|
||||
#define CONNECTION_H
|
||||
|
||||
#include "RequestParser.h"
|
||||
// #include "RequestParser.h"
|
||||
#include "Http/CompressionType.h"
|
||||
#include "Http/Request.h"
|
||||
|
||||
@@ -40,7 +40,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <boost/version.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
//workaround for incomplete std::shared_ptr compatibility in old boost versions
|
||||
@@ -97,7 +96,6 @@ class Connection : public std::enable_shared_from_this<Connection>
|
||||
RequestHandler &request_handler;
|
||||
boost::array<char, 8192> incoming_data_buffer;
|
||||
Request request;
|
||||
RequestParser request_parser;
|
||||
Reply reply;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -30,21 +30,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Exposes all data access interfaces to the algorithms via base class ptr
|
||||
|
||||
#include "../../DataStructures/EdgeBasedNode.h"
|
||||
#include "../../DataStructures/ImportNode.h"
|
||||
#include "../../DataStructures/PhantomNodes.h"
|
||||
#include "../../DataStructures/TurnInstructions.h"
|
||||
#include "../../Util/OSRMException.h"
|
||||
#include "../../Util/StringUtil.h"
|
||||
#include "../../data_structures/edge_based_node.hpp"
|
||||
#include "../../data_structures/external_memory_node.hpp"
|
||||
#include "../../data_structures/phantom_node.hpp"
|
||||
#include "../../data_structures/turn_instructions.hpp"
|
||||
#include "../../Util/integer_range.hpp"
|
||||
#include "../../Util/osrm_exception.hpp"
|
||||
#include "../../Util/string_util.hpp"
|
||||
#include "../../typedefs.h"
|
||||
|
||||
#include <boost/range/irange.hpp>
|
||||
|
||||
#include <osrm/Coordinate.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
typedef decltype(boost::irange(0u,0u)) EdgeRange;
|
||||
typedef osrm::range<EdgeID> EdgeRange;
|
||||
|
||||
template <class EdgeDataT> class BaseDataFacade
|
||||
{
|
||||
@@ -63,9 +62,9 @@ template <class EdgeDataT> class BaseDataFacade
|
||||
|
||||
virtual NodeID GetTarget(const EdgeID e) const = 0;
|
||||
|
||||
virtual EdgeDataT &GetEdgeData(const EdgeID e) = 0;
|
||||
// virtual EdgeDataT &GetEdgeData(const EdgeID e) = 0;
|
||||
|
||||
// virtual const EdgeDataT &GetEdgeData( const EdgeID e ) const = 0;
|
||||
virtual const EdgeDataT &GetEdgeData(const EdgeID e) const = 0;
|
||||
|
||||
virtual EdgeID BeginEdges(const NodeID n) const = 0;
|
||||
|
||||
@@ -93,18 +92,20 @@ template <class EdgeDataT> class BaseDataFacade
|
||||
|
||||
virtual TurnInstruction GetTurnInstructionForEdgeID(const unsigned id) const = 0;
|
||||
|
||||
virtual TravelMode GetTravelModeForEdgeID(const unsigned id) const = 0;
|
||||
|
||||
virtual bool LocateClosestEndPointForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
FixedPointCoordinate &result,
|
||||
const unsigned zoom_level = 18) const = 0;
|
||||
const unsigned zoom_level = 18) = 0;
|
||||
|
||||
virtual bool FindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
PhantomNode &resulting_phantom_node,
|
||||
const unsigned zoom_level) const = 0;
|
||||
virtual bool
|
||||
IncrementalFindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
std::vector<PhantomNode> &resulting_phantom_node_vector,
|
||||
const unsigned number_of_results) = 0;
|
||||
|
||||
virtual bool IncrementalFindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
std::vector<PhantomNode> &resulting_phantom_node_vector,
|
||||
const unsigned zoom_level,
|
||||
const unsigned number_of_results) const = 0;
|
||||
virtual bool
|
||||
IncrementalFindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
PhantomNode &resulting_phantom_node) = 0;
|
||||
|
||||
virtual unsigned GetCheckSum() const = 0;
|
||||
|
||||
|
||||
@@ -32,19 +32,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "BaseDataFacade.h"
|
||||
|
||||
#include "../../DataStructures/OriginalEdgeData.h"
|
||||
#include "../../DataStructures/QueryNode.h"
|
||||
#include "../../DataStructures/QueryEdge.h"
|
||||
#include "../../DataStructures/SharedMemoryVectorWrapper.h"
|
||||
#include "../../DataStructures/StaticGraph.h"
|
||||
#include "../../DataStructures/StaticRTree.h"
|
||||
#include "../../DataStructures/RangeTable.h"
|
||||
#include "../../data_structures/original_edge_data.hpp"
|
||||
#include "../../data_structures/query_node.hpp"
|
||||
#include "../../data_structures/query_edge.hpp"
|
||||
#include "../../data_structures/shared_memory_vector_wrapper.hpp"
|
||||
#include "../../data_structures/static_graph.hpp"
|
||||
#include "../../data_structures/static_rtree.hpp"
|
||||
#include "../../data_structures/range_table.hpp"
|
||||
#include "../../Util/BoostFileSystemFix.h"
|
||||
#include "../../Util/GraphLoader.h"
|
||||
#include "../../Util/ProgramOptions.h"
|
||||
#include "../../Util/SimpleLogger.h"
|
||||
#include "../../Util/graph_loader.hpp"
|
||||
#include "../../Util/simple_logger.hpp"
|
||||
|
||||
#include <osrm/Coordinate.h>
|
||||
#include <osrm/ServerPaths.h>
|
||||
|
||||
template <class EdgeDataT> class InternalDataFacade : public BaseDataFacade<EdgeDataT>
|
||||
{
|
||||
@@ -66,13 +66,16 @@ template <class EdgeDataT> class InternalDataFacade : public BaseDataFacade<Edge
|
||||
ShM<NodeID, false>::vector m_via_node_list;
|
||||
ShM<unsigned, false>::vector m_name_ID_list;
|
||||
ShM<TurnInstruction, false>::vector m_turn_instruction_list;
|
||||
ShM<TravelMode, false>::vector m_travel_mode_list;
|
||||
ShM<char, false>::vector m_names_char_list;
|
||||
ShM<bool, false>::vector m_egde_is_compressed;
|
||||
ShM<bool, false>::vector m_edge_is_compressed;
|
||||
ShM<unsigned, false>::vector m_geometry_indices;
|
||||
ShM<unsigned, false>::vector m_geometry_list;
|
||||
|
||||
std::shared_ptr<StaticRTree<RTreeLeaf, ShM<FixedPointCoordinate, false>::vector, false>>
|
||||
m_static_rtree;
|
||||
boost::thread_specific_ptr<
|
||||
StaticRTree<RTreeLeaf, ShM<FixedPointCoordinate, false>::vector, false>> m_static_rtree;
|
||||
boost::filesystem::path ram_index_path;
|
||||
boost::filesystem::path file_index_path;
|
||||
RangeTable<16, false> m_name_table;
|
||||
|
||||
void LoadTimestamp(const boost::filesystem::path ×tamp_path)
|
||||
@@ -123,14 +126,14 @@ template <class EdgeDataT> class InternalDataFacade : public BaseDataFacade<Edge
|
||||
{
|
||||
boost::filesystem::ifstream nodes_input_stream(nodes_file, std::ios::binary);
|
||||
|
||||
NodeInfo current_node;
|
||||
QueryNode current_node;
|
||||
unsigned number_of_coordinates = 0;
|
||||
nodes_input_stream.read((char *)&number_of_coordinates, sizeof(unsigned));
|
||||
m_coordinate_list =
|
||||
std::make_shared<std::vector<FixedPointCoordinate>>(number_of_coordinates);
|
||||
for (unsigned i = 0; i < number_of_coordinates; ++i)
|
||||
{
|
||||
nodes_input_stream.read((char *)¤t_node, sizeof(NodeInfo));
|
||||
nodes_input_stream.read((char *)¤t_node, sizeof(QueryNode));
|
||||
m_coordinate_list->at(i) = FixedPointCoordinate(current_node.lat, current_node.lon);
|
||||
BOOST_ASSERT((std::abs(m_coordinate_list->at(i).lat) >> 30) == 0);
|
||||
BOOST_ASSERT((std::abs(m_coordinate_list->at(i).lon) >> 30) == 0);
|
||||
@@ -143,7 +146,8 @@ template <class EdgeDataT> class InternalDataFacade : public BaseDataFacade<Edge
|
||||
m_via_node_list.resize(number_of_edges);
|
||||
m_name_ID_list.resize(number_of_edges);
|
||||
m_turn_instruction_list.resize(number_of_edges);
|
||||
m_egde_is_compressed.resize(number_of_edges);
|
||||
m_travel_mode_list.resize(number_of_edges);
|
||||
m_edge_is_compressed.resize(number_of_edges);
|
||||
|
||||
unsigned compressed = 0;
|
||||
|
||||
@@ -154,8 +158,9 @@ template <class EdgeDataT> class InternalDataFacade : public BaseDataFacade<Edge
|
||||
m_via_node_list[i] = current_edge_data.via_node;
|
||||
m_name_ID_list[i] = current_edge_data.name_id;
|
||||
m_turn_instruction_list[i] = current_edge_data.turn_instruction;
|
||||
m_egde_is_compressed[i] = current_edge_data.compressed_geometry;
|
||||
if (m_egde_is_compressed[i])
|
||||
m_travel_mode_list[i] = current_edge_data.travel_mode;
|
||||
m_edge_is_compressed[i] = current_edge_data.compressed_geometry;
|
||||
if (m_edge_is_compressed[i])
|
||||
{
|
||||
++compressed;
|
||||
}
|
||||
@@ -192,13 +197,12 @@ template <class EdgeDataT> class InternalDataFacade : public BaseDataFacade<Edge
|
||||
geometry_stream.close();
|
||||
}
|
||||
|
||||
void LoadRTree(const boost::filesystem::path &ram_index_path,
|
||||
const boost::filesystem::path &file_index_path)
|
||||
void LoadRTree()
|
||||
{
|
||||
BOOST_ASSERT_MSG(!m_coordinate_list->empty(), "coordinates must be loaded before r-tree");
|
||||
|
||||
m_static_rtree = std::make_shared<StaticRTree<RTreeLeaf>>(
|
||||
ram_index_path, file_index_path, m_coordinate_list);
|
||||
m_static_rtree.reset(
|
||||
new StaticRTree<RTreeLeaf>(ram_index_path, file_index_path, m_coordinate_list));
|
||||
}
|
||||
|
||||
void LoadStreetNames(const boost::filesystem::path &names_file)
|
||||
@@ -220,7 +224,7 @@ template <class EdgeDataT> class InternalDataFacade : public BaseDataFacade<Edge
|
||||
}
|
||||
|
||||
public:
|
||||
~InternalDataFacade()
|
||||
virtual ~InternalDataFacade()
|
||||
{
|
||||
delete m_query_graph;
|
||||
m_static_rtree.reset();
|
||||
@@ -231,31 +235,31 @@ template <class EdgeDataT> class InternalDataFacade : public BaseDataFacade<Edge
|
||||
// generate paths of data files
|
||||
if (server_paths.find("hsgrdata") == server_paths.end())
|
||||
{
|
||||
throw OSRMException("no hsgr file given in ini file");
|
||||
throw osrm::exception("no hsgr file given in ini file");
|
||||
}
|
||||
if (server_paths.find("ramindex") == server_paths.end())
|
||||
{
|
||||
throw OSRMException("no ram index file given in ini file");
|
||||
throw osrm::exception("no ram index file given in ini file");
|
||||
}
|
||||
if (server_paths.find("fileindex") == server_paths.end())
|
||||
{
|
||||
throw OSRMException("no leaf index file given in ini file");
|
||||
throw osrm::exception("no leaf index file given in ini file");
|
||||
}
|
||||
if (server_paths.find("geometries") == server_paths.end())
|
||||
{
|
||||
throw OSRMException("no geometries file given in ini file");
|
||||
throw osrm::exception("no geometries file given in ini file");
|
||||
}
|
||||
if (server_paths.find("nodesdata") == server_paths.end())
|
||||
{
|
||||
throw OSRMException("no nodes file given in ini file");
|
||||
throw osrm::exception("no nodes file given in ini file");
|
||||
}
|
||||
if (server_paths.find("edgesdata") == server_paths.end())
|
||||
{
|
||||
throw OSRMException("no edges file given in ini file");
|
||||
throw osrm::exception("no edges file given in ini file");
|
||||
}
|
||||
if (server_paths.find("namesdata") == server_paths.end())
|
||||
{
|
||||
throw OSRMException("no names file given in ini file");
|
||||
throw osrm::exception("no names file given in ini file");
|
||||
}
|
||||
|
||||
ServerPaths::const_iterator paths_iterator = server_paths.find("hsgrdata");
|
||||
@@ -266,10 +270,10 @@ template <class EdgeDataT> class InternalDataFacade : public BaseDataFacade<Edge
|
||||
const boost::filesystem::path ×tamp_path = paths_iterator->second;
|
||||
paths_iterator = server_paths.find("ramindex");
|
||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||
const boost::filesystem::path &ram_index_path = paths_iterator->second;
|
||||
ram_index_path = paths_iterator->second;
|
||||
paths_iterator = server_paths.find("fileindex");
|
||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||
const boost::filesystem::path &file_index_path = paths_iterator->second;
|
||||
file_index_path = paths_iterator->second;
|
||||
paths_iterator = server_paths.find("nodesdata");
|
||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||
const boost::filesystem::path &nodes_data_path = paths_iterator->second;
|
||||
@@ -287,7 +291,7 @@ template <class EdgeDataT> class InternalDataFacade : public BaseDataFacade<Edge
|
||||
SimpleLogger().Write() << "loading graph data";
|
||||
AssertPathExists(hsgr_path);
|
||||
LoadGraph(hsgr_path);
|
||||
SimpleLogger().Write() << "loading egde information";
|
||||
SimpleLogger().Write() << "loading edge information";
|
||||
AssertPathExists(nodes_data_path);
|
||||
AssertPathExists(edges_data_path);
|
||||
LoadNodeAndEdgeInformation(nodes_data_path, edges_data_path);
|
||||
@@ -297,7 +301,6 @@ template <class EdgeDataT> class InternalDataFacade : public BaseDataFacade<Edge
|
||||
SimpleLogger().Write() << "loading r-tree";
|
||||
AssertPathExists(ram_index_path);
|
||||
AssertPathExists(file_index_path);
|
||||
LoadRTree(ram_index_path, file_index_path);
|
||||
SimpleLogger().Write() << "loading timestamp";
|
||||
LoadTimestamp(timestamp_path);
|
||||
SimpleLogger().Write() << "loading street names";
|
||||
@@ -306,90 +309,112 @@ template <class EdgeDataT> class InternalDataFacade : public BaseDataFacade<Edge
|
||||
}
|
||||
|
||||
// search graph access
|
||||
unsigned GetNumberOfNodes() const { return m_query_graph->GetNumberOfNodes(); }
|
||||
unsigned GetNumberOfNodes() const final { return m_query_graph->GetNumberOfNodes(); }
|
||||
|
||||
unsigned GetNumberOfEdges() const { return m_query_graph->GetNumberOfEdges(); }
|
||||
unsigned GetNumberOfEdges() const final { return m_query_graph->GetNumberOfEdges(); }
|
||||
|
||||
unsigned GetOutDegree(const NodeID n) const { return m_query_graph->GetOutDegree(n); }
|
||||
unsigned GetOutDegree(const NodeID n) const final { return m_query_graph->GetOutDegree(n); }
|
||||
|
||||
NodeID GetTarget(const EdgeID e) const { return m_query_graph->GetTarget(e); }
|
||||
NodeID GetTarget(const EdgeID e) const final { return m_query_graph->GetTarget(e); }
|
||||
|
||||
EdgeDataT &GetEdgeData(const EdgeID e) { return m_query_graph->GetEdgeData(e); }
|
||||
// EdgeDataT &GetEdgeData(const EdgeID e) final { return m_query_graph->GetEdgeData(e); }
|
||||
|
||||
const EdgeDataT &GetEdgeData(const EdgeID e) const { return m_query_graph->GetEdgeData(e); }
|
||||
EdgeDataT &GetEdgeData(const EdgeID e) const final { return m_query_graph->GetEdgeData(e); }
|
||||
|
||||
EdgeID BeginEdges(const NodeID n) const { return m_query_graph->BeginEdges(n); }
|
||||
EdgeID BeginEdges(const NodeID n) const final { return m_query_graph->BeginEdges(n); }
|
||||
|
||||
EdgeID EndEdges(const NodeID n) const { return m_query_graph->EndEdges(n); }
|
||||
EdgeID EndEdges(const NodeID n) const final { return m_query_graph->EndEdges(n); }
|
||||
|
||||
EdgeRange GetAdjacentEdgeRange(const NodeID node) const
|
||||
EdgeRange GetAdjacentEdgeRange(const NodeID node) const final
|
||||
{
|
||||
return m_query_graph->GetAdjacentEdgeRange(node);
|
||||
};
|
||||
|
||||
// searches for a specific edge
|
||||
EdgeID FindEdge(const NodeID from, const NodeID to) const
|
||||
EdgeID FindEdge(const NodeID from, const NodeID to) const final
|
||||
{
|
||||
return m_query_graph->FindEdge(from, to);
|
||||
}
|
||||
|
||||
EdgeID FindEdgeInEitherDirection(const NodeID from, const NodeID to) const
|
||||
EdgeID FindEdgeInEitherDirection(const NodeID from, const NodeID to) const final
|
||||
{
|
||||
return m_query_graph->FindEdgeInEitherDirection(from, to);
|
||||
}
|
||||
|
||||
EdgeID FindEdgeIndicateIfReverse(const NodeID from, const NodeID to, bool &result) const
|
||||
EdgeID FindEdgeIndicateIfReverse(const NodeID from, const NodeID to, bool &result) const final
|
||||
{
|
||||
return m_query_graph->FindEdgeIndicateIfReverse(from, to, result);
|
||||
}
|
||||
|
||||
// node and edge information access
|
||||
FixedPointCoordinate GetCoordinateOfNode(const unsigned id) const
|
||||
FixedPointCoordinate GetCoordinateOfNode(const unsigned id) const final
|
||||
{
|
||||
return m_coordinate_list->at(id);
|
||||
};
|
||||
|
||||
bool EdgeIsCompressed(const unsigned id) const { return m_egde_is_compressed.at(id); }
|
||||
bool EdgeIsCompressed(const unsigned id) const { return m_edge_is_compressed.at(id); }
|
||||
|
||||
TurnInstruction GetTurnInstructionForEdgeID(const unsigned id) const
|
||||
TurnInstruction GetTurnInstructionForEdgeID(const unsigned id) const final
|
||||
{
|
||||
return m_turn_instruction_list.at(id);
|
||||
}
|
||||
|
||||
TravelMode GetTravelModeForEdgeID(const unsigned id) const
|
||||
{
|
||||
return m_travel_mode_list.at(id);
|
||||
}
|
||||
|
||||
bool LocateClosestEndPointForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
FixedPointCoordinate &result,
|
||||
const unsigned zoom_level = 18) const
|
||||
const unsigned zoom_level = 18) final
|
||||
{
|
||||
if (!m_static_rtree.get())
|
||||
{
|
||||
LoadRTree();
|
||||
}
|
||||
|
||||
return m_static_rtree->LocateClosestEndPointForCoordinate(
|
||||
input_coordinate, result, zoom_level);
|
||||
}
|
||||
|
||||
bool FindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
PhantomNode &resulting_phantom_node,
|
||||
const unsigned zoom_level) const
|
||||
bool
|
||||
IncrementalFindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
PhantomNode &resulting_phantom_node) final
|
||||
{
|
||||
return m_static_rtree->FindPhantomNodeForCoordinate(
|
||||
input_coordinate, resulting_phantom_node, zoom_level);
|
||||
std::vector<PhantomNode> resulting_phantom_node_vector;
|
||||
auto result = IncrementalFindPhantomNodeForCoordinate(input_coordinate,
|
||||
resulting_phantom_node_vector,
|
||||
1);
|
||||
if (result)
|
||||
{
|
||||
BOOST_ASSERT(!resulting_phantom_node_vector.empty());
|
||||
resulting_phantom_node = resulting_phantom_node_vector.front();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool
|
||||
IncrementalFindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
std::vector<PhantomNode> &resulting_phantom_node_vector,
|
||||
const unsigned zoom_level,
|
||||
const unsigned number_of_results) const
|
||||
const unsigned number_of_results) final
|
||||
{
|
||||
if (!m_static_rtree.get())
|
||||
{
|
||||
LoadRTree();
|
||||
}
|
||||
|
||||
return m_static_rtree->IncrementalFindPhantomNodeForCoordinate(
|
||||
input_coordinate, resulting_phantom_node_vector, zoom_level, number_of_results);
|
||||
input_coordinate, resulting_phantom_node_vector, number_of_results);
|
||||
}
|
||||
|
||||
unsigned GetCheckSum() const { return m_check_sum; }
|
||||
unsigned GetCheckSum() const final { return m_check_sum; }
|
||||
|
||||
unsigned GetNameIndexFromEdgeID(const unsigned id) const
|
||||
unsigned GetNameIndexFromEdgeID(const unsigned id) const final
|
||||
{
|
||||
return m_name_ID_list.at(id);
|
||||
};
|
||||
|
||||
void GetName(const unsigned name_id, std::string &result) const
|
||||
void GetName(const unsigned name_id, std::string &result) const final
|
||||
{
|
||||
if (UINT_MAX == name_id)
|
||||
{
|
||||
@@ -408,13 +433,13 @@ template <class EdgeDataT> class InternalDataFacade : public BaseDataFacade<Edge
|
||||
}
|
||||
}
|
||||
|
||||
virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const
|
||||
virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const final
|
||||
{
|
||||
return m_via_node_list.at(id);
|
||||
}
|
||||
|
||||
virtual void GetUncompressedGeometry(const unsigned id, std::vector<unsigned> &result_nodes)
|
||||
const
|
||||
virtual void GetUncompressedGeometry(const unsigned id,
|
||||
std::vector<unsigned> &result_nodes) const final
|
||||
{
|
||||
const unsigned begin = m_geometry_indices.at(id);
|
||||
const unsigned end = m_geometry_indices.at(id + 1);
|
||||
@@ -424,7 +449,7 @@ template <class EdgeDataT> class InternalDataFacade : public BaseDataFacade<Edge
|
||||
result_nodes.begin(), m_geometry_list.begin() + begin, m_geometry_list.begin() + end);
|
||||
}
|
||||
|
||||
std::string GetTimestamp() const { return m_timestamp; }
|
||||
std::string GetTimestamp() const final { return m_timestamp; }
|
||||
};
|
||||
|
||||
#endif // INTERNAL_DATA_FACADE
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -33,12 +33,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "BaseDataFacade.h"
|
||||
#include "SharedDataType.h"
|
||||
|
||||
#include "../../DataStructures/RangeTable.h"
|
||||
#include "../../DataStructures/StaticGraph.h"
|
||||
#include "../../DataStructures/StaticRTree.h"
|
||||
#include "../../data_structures/range_table.hpp"
|
||||
#include "../../data_structures/static_graph.hpp"
|
||||
#include "../../data_structures/static_rtree.hpp"
|
||||
#include "../../Util/BoostFileSystemFix.h"
|
||||
#include "../../Util/ProgramOptions.h"
|
||||
#include "../../Util/SimpleLogger.h"
|
||||
#include "../../Util/make_unique.hpp"
|
||||
#include "../../Util/simple_logger.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
@@ -55,8 +55,9 @@ template <class EdgeDataT> class SharedDataFacade : public BaseDataFacade<EdgeDa
|
||||
typedef typename RangeTable<16, true>::BlockT NameIndexBlock;
|
||||
typedef typename QueryGraph::InputEdge InputEdge;
|
||||
typedef typename super::RTreeLeaf RTreeLeaf;
|
||||
typedef typename StaticRTree<RTreeLeaf, ShM<FixedPointCoordinate, true>::vector, true>::TreeNode
|
||||
RTreeNode;
|
||||
using SharedRTree = StaticRTree<RTreeLeaf, ShM<FixedPointCoordinate, true>::vector, true>;
|
||||
using TimeStampedRTreePair = std::pair<unsigned, std::shared_ptr<SharedRTree>>;
|
||||
using RTreeNode = typename SharedRTree::TreeNode;
|
||||
|
||||
SharedDataLayout *data_layout;
|
||||
char *shared_memory;
|
||||
@@ -67,24 +68,24 @@ template <class EdgeDataT> class SharedDataFacade : public BaseDataFacade<EdgeDa
|
||||
unsigned CURRENT_TIMESTAMP;
|
||||
|
||||
unsigned m_check_sum;
|
||||
unsigned m_number_of_nodes;
|
||||
std::shared_ptr<QueryGraph> m_query_graph;
|
||||
std::shared_ptr<SharedMemory> m_layout_memory;
|
||||
std::shared_ptr<SharedMemory> m_large_memory;
|
||||
std::unique_ptr<QueryGraph> m_query_graph;
|
||||
std::unique_ptr<SharedMemory> m_layout_memory;
|
||||
std::unique_ptr<SharedMemory> m_large_memory;
|
||||
std::string m_timestamp;
|
||||
|
||||
std::shared_ptr<ShM<FixedPointCoordinate, true>::vector> m_coordinate_list;
|
||||
ShM<NodeID, true>::vector m_via_node_list;
|
||||
ShM<unsigned, true>::vector m_name_ID_list;
|
||||
ShM<TurnInstruction, true>::vector m_turn_instruction_list;
|
||||
ShM<TravelMode, true>::vector m_travel_mode_list;
|
||||
ShM<char, true>::vector m_names_char_list;
|
||||
ShM<unsigned, true>::vector m_name_begin_indices;
|
||||
ShM<bool, true>::vector m_egde_is_compressed;
|
||||
ShM<bool, true>::vector m_edge_is_compressed;
|
||||
ShM<unsigned, true>::vector m_geometry_indices;
|
||||
ShM<unsigned, true>::vector m_geometry_list;
|
||||
|
||||
std::shared_ptr<StaticRTree<RTreeLeaf, ShM<FixedPointCoordinate, true>::vector, true>>
|
||||
m_static_rtree;
|
||||
boost::thread_specific_ptr<std::pair<unsigned, std::shared_ptr<SharedRTree>>> m_static_rtree;
|
||||
boost::filesystem::path file_index_path;
|
||||
|
||||
std::shared_ptr<RangeTable<16, true>> m_name_table;
|
||||
|
||||
@@ -105,23 +106,22 @@ template <class EdgeDataT> class SharedDataFacade : public BaseDataFacade<EdgeDa
|
||||
m_timestamp.begin());
|
||||
}
|
||||
|
||||
void LoadRTree(const boost::filesystem::path &file_index_path)
|
||||
void LoadRTree()
|
||||
{
|
||||
BOOST_ASSERT_MSG(!m_coordinate_list->empty(), "coordinates must be loaded before r-tree");
|
||||
|
||||
RTreeNode *tree_ptr =
|
||||
data_layout->GetBlockPtr<RTreeNode>(shared_memory, SharedDataLayout::R_SEARCH_TREE);
|
||||
m_static_rtree =
|
||||
std::make_shared<StaticRTree<RTreeLeaf, ShM<FixedPointCoordinate, true>::vector, true>>(
|
||||
m_static_rtree.reset(new TimeStampedRTreePair(CURRENT_TIMESTAMP,
|
||||
osrm::make_unique<SharedRTree>(
|
||||
tree_ptr,
|
||||
data_layout->num_entries[SharedDataLayout::R_SEARCH_TREE],
|
||||
file_index_path,
|
||||
m_coordinate_list);
|
||||
m_coordinate_list)));
|
||||
}
|
||||
|
||||
void LoadGraph()
|
||||
{
|
||||
m_number_of_nodes = data_layout->num_entries[SharedDataLayout::GRAPH_NODE_LIST];
|
||||
GraphNode *graph_nodes_ptr =
|
||||
data_layout->GetBlockPtr<GraphNode>(shared_memory, SharedDataLayout::GRAPH_NODE_LIST);
|
||||
|
||||
@@ -140,9 +140,16 @@ template <class EdgeDataT> class SharedDataFacade : public BaseDataFacade<EdgeDa
|
||||
|
||||
FixedPointCoordinate *coordinate_list_ptr = data_layout->GetBlockPtr<FixedPointCoordinate>(
|
||||
shared_memory, SharedDataLayout::COORDINATE_LIST);
|
||||
m_coordinate_list = std::make_shared<ShM<FixedPointCoordinate, true>::vector>(
|
||||
m_coordinate_list = osrm::make_unique<ShM<FixedPointCoordinate, true>::vector>(
|
||||
coordinate_list_ptr, data_layout->num_entries[SharedDataLayout::COORDINATE_LIST]);
|
||||
|
||||
TravelMode *travel_mode_list_ptr = data_layout->GetBlockPtr<TravelMode>(
|
||||
shared_memory, SharedDataLayout::TRAVEL_MODE);
|
||||
typename ShM<TravelMode, true>::vector travel_mode_list(
|
||||
travel_mode_list_ptr,
|
||||
data_layout->num_entries[SharedDataLayout::TRAVEL_MODE]);
|
||||
m_travel_mode_list.swap(travel_mode_list);
|
||||
|
||||
TurnInstruction *turn_instruction_list_ptr = data_layout->GetBlockPtr<TurnInstruction>(
|
||||
shared_memory, SharedDataLayout::TURN_INSTRUCTION);
|
||||
typename ShM<TurnInstruction, true>::vector turn_instruction_list(
|
||||
@@ -181,8 +188,8 @@ template <class EdgeDataT> class SharedDataFacade : public BaseDataFacade<EdgeDa
|
||||
data_layout->GetBlockPtr<char>(shared_memory, SharedDataLayout::NAME_CHAR_LIST);
|
||||
typename ShM<char, true>::vector names_char_list(
|
||||
names_list_ptr, data_layout->num_entries[SharedDataLayout::NAME_CHAR_LIST]);
|
||||
m_name_table = std::make_shared<RangeTable<16, true>>(
|
||||
name_offsets, name_blocks, names_char_list.size());
|
||||
m_name_table = osrm::make_unique<RangeTable<16, true>>(
|
||||
name_offsets, name_blocks, static_cast<unsigned>(names_char_list.size()));
|
||||
|
||||
m_names_char_list.swap(names_char_list);
|
||||
}
|
||||
@@ -191,10 +198,10 @@ template <class EdgeDataT> class SharedDataFacade : public BaseDataFacade<EdgeDa
|
||||
{
|
||||
unsigned *geometries_compressed_ptr = data_layout->GetBlockPtr<unsigned>(
|
||||
shared_memory, SharedDataLayout::GEOMETRIES_INDICATORS);
|
||||
typename ShM<bool, true>::vector egde_is_compressed(
|
||||
typename ShM<bool, true>::vector edge_is_compressed(
|
||||
geometries_compressed_ptr,
|
||||
data_layout->num_entries[SharedDataLayout::GEOMETRIES_INDICATORS]);
|
||||
m_egde_is_compressed.swap(egde_is_compressed);
|
||||
m_edge_is_compressed.swap(edge_is_compressed);
|
||||
|
||||
unsigned *geometries_index_ptr =
|
||||
data_layout->GetBlockPtr<unsigned>(shared_memory, SharedDataLayout::GEOMETRIES_INDEX);
|
||||
@@ -210,11 +217,12 @@ template <class EdgeDataT> class SharedDataFacade : public BaseDataFacade<EdgeDa
|
||||
}
|
||||
|
||||
public:
|
||||
virtual ~SharedDataFacade() {}
|
||||
|
||||
SharedDataFacade()
|
||||
{
|
||||
data_timestamp_ptr = (SharedDataTimestamp *)SharedMemoryFactory::Get(
|
||||
CURRENT_REGIONS, sizeof(SharedDataTimestamp), false, false)->Ptr();
|
||||
|
||||
CURRENT_LAYOUT = LAYOUT_NONE;
|
||||
CURRENT_DATA = DATA_NONE;
|
||||
CURRENT_TIMESTAMP = 0;
|
||||
@@ -244,17 +252,13 @@ template <class EdgeDataT> class SharedDataFacade : public BaseDataFacade<EdgeDa
|
||||
m_large_memory.reset(SharedMemoryFactory::Get(CURRENT_DATA));
|
||||
shared_memory = (char *)(m_large_memory->Ptr());
|
||||
|
||||
std::ofstream out("debug.bin");
|
||||
out.write(shared_memory, data_layout->GetSizeOfLayout());
|
||||
out.close();
|
||||
|
||||
const char *file_index_ptr =
|
||||
data_layout->GetBlockPtr<char>(shared_memory, SharedDataLayout::FILE_INDEX_PATH);
|
||||
boost::filesystem::path file_index_path(file_index_ptr);
|
||||
file_index_path = boost::filesystem::path(file_index_ptr);
|
||||
if (!boost::filesystem::exists(file_index_path))
|
||||
{
|
||||
SimpleLogger().Write(logDEBUG) << "Leaf file name " << file_index_path.string();
|
||||
throw OSRMException("Could not load leaf index file."
|
||||
throw osrm::exception("Could not load leaf index file."
|
||||
"Is any data loaded into shared memory?");
|
||||
}
|
||||
|
||||
@@ -262,65 +266,72 @@ template <class EdgeDataT> class SharedDataFacade : public BaseDataFacade<EdgeDa
|
||||
LoadChecksum();
|
||||
LoadNodeAndEdgeInformation();
|
||||
LoadGeometries();
|
||||
LoadRTree(file_index_path);
|
||||
LoadTimestamp();
|
||||
LoadViaNodeList();
|
||||
LoadNames();
|
||||
|
||||
data_layout->PrintInformation();
|
||||
|
||||
SimpleLogger().Write() << "number of geometries: " << m_coordinate_list->size();
|
||||
for (unsigned i = 0; i < m_coordinate_list->size(); ++i)
|
||||
{
|
||||
if (!GetCoordinateOfNode(i).is_valid())
|
||||
{
|
||||
SimpleLogger().Write() << "coordinate " << i << " not valid";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// search graph access
|
||||
unsigned GetNumberOfNodes() const { return m_query_graph->GetNumberOfNodes(); }
|
||||
unsigned GetNumberOfNodes() const final { return m_query_graph->GetNumberOfNodes(); }
|
||||
|
||||
unsigned GetNumberOfEdges() const { return m_query_graph->GetNumberOfEdges(); }
|
||||
unsigned GetNumberOfEdges() const final { return m_query_graph->GetNumberOfEdges(); }
|
||||
|
||||
unsigned GetOutDegree(const NodeID n) const { return m_query_graph->GetOutDegree(n); }
|
||||
unsigned GetOutDegree(const NodeID n) const final { return m_query_graph->GetOutDegree(n); }
|
||||
|
||||
NodeID GetTarget(const EdgeID e) const { return m_query_graph->GetTarget(e); }
|
||||
NodeID GetTarget(const EdgeID e) const final { return m_query_graph->GetTarget(e); }
|
||||
|
||||
EdgeDataT &GetEdgeData(const EdgeID e) { return m_query_graph->GetEdgeData(e); }
|
||||
EdgeDataT &GetEdgeData(const EdgeID e) const final { return m_query_graph->GetEdgeData(e); }
|
||||
|
||||
// const EdgeDataT &GetEdgeData( const EdgeID e ) const {
|
||||
// return m_query_graph->GetEdgeData(e);
|
||||
// }
|
||||
EdgeID BeginEdges(const NodeID n) const final { return m_query_graph->BeginEdges(n); }
|
||||
|
||||
EdgeID BeginEdges(const NodeID n) const { return m_query_graph->BeginEdges(n); }
|
||||
EdgeID EndEdges(const NodeID n) const final { return m_query_graph->EndEdges(n); }
|
||||
|
||||
EdgeID EndEdges(const NodeID n) const { return m_query_graph->EndEdges(n); }
|
||||
|
||||
EdgeRange GetAdjacentEdgeRange(const NodeID node) const
|
||||
EdgeRange GetAdjacentEdgeRange(const NodeID node) const final
|
||||
{
|
||||
return m_query_graph->GetAdjacentEdgeRange(node);
|
||||
};
|
||||
|
||||
// searches for a specific edge
|
||||
EdgeID FindEdge(const NodeID from, const NodeID to) const
|
||||
EdgeID FindEdge(const NodeID from, const NodeID to) const final
|
||||
{
|
||||
return m_query_graph->FindEdge(from, to);
|
||||
}
|
||||
|
||||
EdgeID FindEdgeInEitherDirection(const NodeID from, const NodeID to) const
|
||||
EdgeID FindEdgeInEitherDirection(const NodeID from, const NodeID to) const final
|
||||
{
|
||||
return m_query_graph->FindEdgeInEitherDirection(from, to);
|
||||
}
|
||||
|
||||
EdgeID FindEdgeIndicateIfReverse(const NodeID from, const NodeID to, bool &result) const
|
||||
EdgeID FindEdgeIndicateIfReverse(const NodeID from, const NodeID to, bool &result) const final
|
||||
{
|
||||
return m_query_graph->FindEdgeIndicateIfReverse(from, to, result);
|
||||
}
|
||||
|
||||
// node and edge information access
|
||||
FixedPointCoordinate GetCoordinateOfNode(const unsigned id) const
|
||||
FixedPointCoordinate GetCoordinateOfNode(const NodeID id) const final
|
||||
{
|
||||
return m_coordinate_list->at(id);
|
||||
};
|
||||
|
||||
virtual bool EdgeIsCompressed(const unsigned id) const { return m_egde_is_compressed.at(id); }
|
||||
virtual bool EdgeIsCompressed(const unsigned id) const final
|
||||
{
|
||||
return m_edge_is_compressed.at(id);
|
||||
}
|
||||
|
||||
virtual void GetUncompressedGeometry(const unsigned id, std::vector<unsigned> &result_nodes)
|
||||
const
|
||||
virtual void GetUncompressedGeometry(const unsigned id,
|
||||
std::vector<unsigned> &result_nodes) const final
|
||||
{
|
||||
const unsigned begin = m_geometry_indices.at(id);
|
||||
const unsigned end = m_geometry_indices.at(id + 1);
|
||||
@@ -330,50 +341,72 @@ template <class EdgeDataT> class SharedDataFacade : public BaseDataFacade<EdgeDa
|
||||
result_nodes.begin(), m_geometry_list.begin() + begin, m_geometry_list.begin() + end);
|
||||
}
|
||||
|
||||
virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const
|
||||
virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const final
|
||||
{
|
||||
return m_via_node_list.at(id);
|
||||
}
|
||||
|
||||
TurnInstruction GetTurnInstructionForEdgeID(const unsigned id) const
|
||||
TurnInstruction GetTurnInstructionForEdgeID(const unsigned id) const final
|
||||
{
|
||||
return m_turn_instruction_list.at(id);
|
||||
}
|
||||
|
||||
TravelMode GetTravelModeForEdgeID(const unsigned id) const
|
||||
{
|
||||
return m_travel_mode_list.at(id);
|
||||
}
|
||||
|
||||
bool LocateClosestEndPointForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
FixedPointCoordinate &result,
|
||||
const unsigned zoom_level = 18) const
|
||||
const unsigned zoom_level = 18) final
|
||||
{
|
||||
return m_static_rtree->LocateClosestEndPointForCoordinate(
|
||||
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
|
||||
{
|
||||
LoadRTree();
|
||||
}
|
||||
|
||||
return m_static_rtree->second->LocateClosestEndPointForCoordinate(
|
||||
input_coordinate, result, zoom_level);
|
||||
}
|
||||
|
||||
bool FindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
PhantomNode &resulting_phantom_node,
|
||||
const unsigned zoom_level) const
|
||||
bool
|
||||
IncrementalFindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
PhantomNode &resulting_phantom_node) final
|
||||
{
|
||||
return m_static_rtree->FindPhantomNodeForCoordinate(
|
||||
input_coordinate, resulting_phantom_node, zoom_level);
|
||||
std::vector<PhantomNode> resulting_phantom_node_vector;
|
||||
auto result = IncrementalFindPhantomNodeForCoordinate(input_coordinate,
|
||||
resulting_phantom_node_vector,
|
||||
1);
|
||||
if (result)
|
||||
{
|
||||
BOOST_ASSERT(!resulting_phantom_node_vector.empty());
|
||||
resulting_phantom_node = resulting_phantom_node_vector.front();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool
|
||||
IncrementalFindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
std::vector<PhantomNode> &resulting_phantom_node_vector,
|
||||
const unsigned zoom_level,
|
||||
const unsigned number_of_results) const
|
||||
const unsigned number_of_results) final
|
||||
{
|
||||
return m_static_rtree->IncrementalFindPhantomNodeForCoordinate(
|
||||
input_coordinate, resulting_phantom_node_vector, zoom_level, number_of_results);
|
||||
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
|
||||
{
|
||||
LoadRTree();
|
||||
}
|
||||
|
||||
return m_static_rtree->second->IncrementalFindPhantomNodeForCoordinate(
|
||||
input_coordinate, resulting_phantom_node_vector, number_of_results);
|
||||
}
|
||||
|
||||
unsigned GetCheckSum() const { return m_check_sum; }
|
||||
unsigned GetCheckSum() const final { return m_check_sum; }
|
||||
|
||||
unsigned GetNameIndexFromEdgeID(const unsigned id) const
|
||||
unsigned GetNameIndexFromEdgeID(const unsigned id) const final
|
||||
{
|
||||
return m_name_ID_list.at(id);
|
||||
};
|
||||
|
||||
void GetName(const unsigned name_id, std::string &result) const
|
||||
void GetName(const unsigned name_id, std::string &result) const final
|
||||
{
|
||||
if (UINT_MAX == name_id)
|
||||
{
|
||||
@@ -392,7 +425,7 @@ template <class EdgeDataT> class SharedDataFacade : public BaseDataFacade<EdgeDa
|
||||
}
|
||||
}
|
||||
|
||||
std::string GetTimestamp() const { return m_timestamp; }
|
||||
std::string GetTimestamp() const final { return m_timestamp; }
|
||||
};
|
||||
|
||||
#endif // SHARED_DATA_FACADE_H
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -28,15 +28,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#ifndef SHARED_DATA_TYPE_H_
|
||||
#define SHARED_DATA_TYPE_H_
|
||||
|
||||
#include "../../Util/OSRMException.h"
|
||||
#include "../../Util/SimpleLogger.h"
|
||||
#include "../../Util/osrm_exception.hpp"
|
||||
#include "../../Util/simple_logger.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include <array>
|
||||
|
||||
// Added at the start and end of each block as sanity check
|
||||
constexpr char CANARY[] = "OSRM";
|
||||
static const char CANARY[] = "OSRM";
|
||||
|
||||
struct SharedDataLayout
|
||||
{
|
||||
@@ -50,6 +50,7 @@ struct SharedDataLayout
|
||||
GRAPH_EDGE_LIST,
|
||||
COORDINATE_LIST,
|
||||
TURN_INSTRUCTION,
|
||||
TRAVEL_MODE,
|
||||
R_SEARCH_TREE,
|
||||
GEOMETRIES_INDEX,
|
||||
GEOMETRIES_LIST,
|
||||
@@ -82,6 +83,7 @@ struct SharedDataLayout
|
||||
SimpleLogger().Write(logDEBUG) << "timestamp_length: " << num_entries[TIMESTAMP];
|
||||
SimpleLogger().Write(logDEBUG) << "coordinate_list_size: " << num_entries[COORDINATE_LIST];
|
||||
SimpleLogger().Write(logDEBUG) << "turn_instruction_list_size: " << num_entries[TURN_INSTRUCTION];
|
||||
SimpleLogger().Write(logDEBUG) << "travel_mode_list_size: " << num_entries[TRAVEL_MODE];
|
||||
SimpleLogger().Write(logDEBUG) << "r_search_tree_size: " << num_entries[R_SEARCH_TREE];
|
||||
SimpleLogger().Write(logDEBUG) << "geometries_indicators: " << num_entries[GEOMETRIES_INDICATORS]
|
||||
<< "/" << ((num_entries[GEOMETRIES_INDICATORS] / 8) + 1);
|
||||
@@ -98,6 +100,7 @@ struct SharedDataLayout
|
||||
SimpleLogger().Write(logDEBUG) << "GRAPH_EDGE_LIST " << ": " << GetBlockSize(GRAPH_EDGE_LIST );
|
||||
SimpleLogger().Write(logDEBUG) << "COORDINATE_LIST " << ": " << GetBlockSize(COORDINATE_LIST );
|
||||
SimpleLogger().Write(logDEBUG) << "TURN_INSTRUCTION " << ": " << GetBlockSize(TURN_INSTRUCTION );
|
||||
SimpleLogger().Write(logDEBUG) << "TRAVEL_MODE " << ": " << GetBlockSize(TRAVEL_MODE );
|
||||
SimpleLogger().Write(logDEBUG) << "R_SEARCH_TREE " << ": " << GetBlockSize(R_SEARCH_TREE );
|
||||
SimpleLogger().Write(logDEBUG) << "GEOMETRIES_INDEX " << ": " << GetBlockSize(GEOMETRIES_INDEX );
|
||||
SimpleLogger().Write(logDEBUG) << "GEOMETRIES_LIST " << ": " << GetBlockSize(GEOMETRIES_LIST );
|
||||
@@ -159,11 +162,11 @@ struct SharedDataLayout
|
||||
bool end_canary_alive = std::equal(CANARY, CANARY + sizeof(CANARY), end_canary_ptr);
|
||||
if (!start_canary_alive)
|
||||
{
|
||||
throw OSRMException("Start canary of block corrupted.");
|
||||
throw osrm::exception("Start canary of block corrupted.");
|
||||
}
|
||||
if (!end_canary_alive)
|
||||
{
|
||||
throw OSRMException("End canary of block corrupted.");
|
||||
throw osrm::exception("End canary of block corrupted.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,6 @@ enum CompressionType
|
||||
gzipRFC1952,
|
||||
deflateRFC1951 };
|
||||
|
||||
} // namespace http
|
||||
}
|
||||
|
||||
#endif // COMPRESSION_TYPE_H
|
||||
|
||||
@@ -27,7 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <osrm/Reply.h>
|
||||
|
||||
#include "../../Util/StringUtil.h"
|
||||
#include "../../Util/cast.hpp"
|
||||
|
||||
namespace http
|
||||
{
|
||||
@@ -38,7 +38,7 @@ void Reply::SetSize(const unsigned size)
|
||||
{
|
||||
if ("Content-Length" == h.name)
|
||||
{
|
||||
h.value = UintToString(size);
|
||||
h.value = cast::integral_to_string(size);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,8 +87,7 @@ Reply Reply::StockReply(Reply::status_type status)
|
||||
const std::string status_string = reply.ToString(status);
|
||||
reply.content.insert(reply.content.end(), status_string.begin(), status_string.end());
|
||||
reply.headers.emplace_back("Access-Control-Allow-Origin", "*");
|
||||
reply.headers.emplace_back("Content-Length",
|
||||
UintToString(static_cast<unsigned>(reply.content.size())));
|
||||
reply.headers.emplace_back("Content-Length", cast::integral_to_string(reply.content.size()));
|
||||
reply.headers.emplace_back("Content-Type", "text/html");
|
||||
return reply;
|
||||
}
|
||||
|
||||
+16
-15
@@ -25,14 +25,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "APIGrammar.h"
|
||||
#include "RequestHandler.h"
|
||||
|
||||
#include "APIGrammar.h"
|
||||
#include "Http/Request.h"
|
||||
|
||||
#include "../DataStructures/JSONContainer.h"
|
||||
#include "../data_structures/json_container.hpp"
|
||||
#include "../Library/OSRM.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
#include "../Util/StringUtil.h"
|
||||
#include "../Util/json_renderer.hpp"
|
||||
#include "../Util/simple_logger.hpp"
|
||||
#include "../Util/string_util.hpp"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <osrm/Reply.h>
|
||||
@@ -61,17 +63,17 @@ void RequestHandler::handle_request(const http::Request &req, http::Reply &reply
|
||||
// req.agent << ( 0 == req.agent.length() ? "- " :" ") << request;
|
||||
|
||||
time_t ltime;
|
||||
struct tm *Tm;
|
||||
struct tm *time_stamp;
|
||||
|
||||
ltime = time(nullptr);
|
||||
Tm = localtime(<ime);
|
||||
time_stamp = localtime(<ime);
|
||||
|
||||
// log timestamp
|
||||
SimpleLogger().Write() << (Tm->tm_mday < 10 ? "0" : "") << Tm->tm_mday << "-"
|
||||
<< (Tm->tm_mon + 1 < 10 ? "0" : "") << (Tm->tm_mon + 1) << "-"
|
||||
<< 1900 + Tm->tm_year << " " << (Tm->tm_hour < 10 ? "0" : "")
|
||||
<< Tm->tm_hour << ":" << (Tm->tm_min < 10 ? "0" : "") << Tm->tm_min
|
||||
<< ":" << (Tm->tm_sec < 10 ? "0" : "") << Tm->tm_sec << " "
|
||||
SimpleLogger().Write() << (time_stamp->tm_mday < 10 ? "0" : "") << time_stamp->tm_mday << "-"
|
||||
<< (time_stamp->tm_mon + 1 < 10 ? "0" : "") << (time_stamp->tm_mon + 1) << "-"
|
||||
<< 1900 + time_stamp->tm_year << " " << (time_stamp->tm_hour < 10 ? "0" : "")
|
||||
<< time_stamp->tm_hour << ":" << (time_stamp->tm_min < 10 ? "0" : "") << time_stamp->tm_min
|
||||
<< ":" << (time_stamp->tm_sec < 10 ? "0" : "") << time_stamp->tm_sec << " "
|
||||
<< req.endpoint.to_string() << " " << req.referrer
|
||||
<< (0 == req.referrer.length() ? "- " : " ") << req.agent
|
||||
<< (0 == req.agent.length() ? "- " : " ") << request;
|
||||
@@ -87,11 +89,11 @@ void RequestHandler::handle_request(const http::Request &req, http::Reply &reply
|
||||
{
|
||||
reply = http::Reply::StockReply(http::Reply::badRequest);
|
||||
reply.content.clear();
|
||||
const unsigned position = static_cast<unsigned>(std::distance(request.begin(), iter));
|
||||
const auto position = std::distance(request.begin(), iter);
|
||||
JSON::Object json_result;
|
||||
json_result.values["status"] = 400;
|
||||
std::string message = "Query string malformed close to position ";
|
||||
message += UintToString(position);
|
||||
message += cast::integral_to_string(position);
|
||||
json_result.values["status_message"] = message;
|
||||
JSON::render(reply.content, json_result);
|
||||
return;
|
||||
@@ -112,8 +114,7 @@ void RequestHandler::handle_request(const http::Request &req, http::Reply &reply
|
||||
}
|
||||
|
||||
// set headers
|
||||
reply.headers.emplace_back("Content-Length",
|
||||
UintToString(static_cast<unsigned>(reply.content.size())));
|
||||
reply.headers.emplace_back("Content-Length", cast::integral_to_string(reply.content.size()));
|
||||
if ("gpx" == route_parameters.output_format)
|
||||
{ // gpx file
|
||||
reply.headers.emplace_back("Content-Type", "application/gpx+xml; charset=UTF-8");
|
||||
|
||||
@@ -44,7 +44,7 @@ class RequestHandler
|
||||
{
|
||||
|
||||
public:
|
||||
typedef APIGrammar<std::string::iterator, RouteParameters> APIGrammarParser;
|
||||
using APIGrammarParser = APIGrammar<std::string::iterator, RouteParameters>;
|
||||
|
||||
RequestHandler();
|
||||
RequestHandler(const RequestHandler &) = delete;
|
||||
|
||||
+17
-13
@@ -25,9 +25,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "Http/Request.h"
|
||||
#include "RequestParser.h"
|
||||
|
||||
#include "Http/Request.h"
|
||||
|
||||
namespace http
|
||||
{
|
||||
|
||||
@@ -36,7 +37,7 @@ RequestParser::RequestParser() : state_(method_start), header({"", ""}) {}
|
||||
void RequestParser::Reset() { state_ = method_start; }
|
||||
|
||||
boost::tuple<boost::tribool, char *>
|
||||
RequestParser::Parse(Request &req, char *begin, char *end, http::CompressionType *compression_type)
|
||||
RequestParser::Parse(Request &req, char *begin, char *end, http::CompressionType &compression_type)
|
||||
{
|
||||
while (begin != end)
|
||||
{
|
||||
@@ -51,7 +52,7 @@ RequestParser::Parse(Request &req, char *begin, char *end, http::CompressionType
|
||||
}
|
||||
|
||||
boost::tribool
|
||||
RequestParser::consume(Request &req, char input, http::CompressionType *compression_type)
|
||||
RequestParser::consume(Request &req, char input, http::CompressionType &compression_type)
|
||||
{
|
||||
switch (state_)
|
||||
{
|
||||
@@ -177,11 +178,11 @@ RequestParser::consume(Request &req, char input, http::CompressionType *compress
|
||||
/* giving gzip precedence over deflate */
|
||||
if (header.value.find("deflate") != std::string::npos)
|
||||
{
|
||||
*compression_type = deflateRFC1951;
|
||||
compression_type = deflateRFC1951;
|
||||
}
|
||||
if (header.value.find("gzip") != std::string::npos)
|
||||
{
|
||||
*compression_type = gzipRFC1952;
|
||||
compression_type = gzipRFC1952;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,18 +265,21 @@ RequestParser::consume(Request &req, char input, http::CompressionType *compress
|
||||
return false;
|
||||
default: // expecting_newline_3:
|
||||
return (input == '\n');
|
||||
// default:
|
||||
// return false;
|
||||
// default:
|
||||
// return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool RequestParser::isChar(int c) { return c >= 0 && c <= 127; }
|
||||
inline bool RequestParser::isChar(int character) { return character >= 0 && character <= 127; }
|
||||
|
||||
inline bool RequestParser::isCTL(int c) { return (c >= 0 && c <= 31) || (c == 127); }
|
||||
|
||||
inline bool RequestParser::isTSpecial(int c)
|
||||
inline bool RequestParser::isCTL(int character)
|
||||
{
|
||||
switch (c)
|
||||
return (character >= 0 && character <= 31) || (character == 127);
|
||||
}
|
||||
|
||||
inline bool RequestParser::isTSpecial(int character)
|
||||
{
|
||||
switch (character)
|
||||
{
|
||||
case '(':
|
||||
case ')':
|
||||
@@ -302,5 +306,5 @@ inline bool RequestParser::isTSpecial(int c)
|
||||
}
|
||||
}
|
||||
|
||||
inline bool RequestParser::isDigit(int c) { return c >= '0' && c <= '9'; }
|
||||
inline bool RequestParser::isDigit(int character) { return character >= '0' && character <= '9'; }
|
||||
}
|
||||
|
||||
@@ -46,10 +46,10 @@ class RequestParser
|
||||
void Reset();
|
||||
|
||||
boost::tuple<boost::tribool, char *>
|
||||
Parse(Request &req, char *begin, char *end, CompressionType *compressionType);
|
||||
Parse(Request &req, char *begin, char *end, CompressionType &compression_type);
|
||||
|
||||
private:
|
||||
boost::tribool consume(Request &req, char input, CompressionType *compressionType);
|
||||
boost::tribool consume(Request &req, char input, CompressionType &compression_type);
|
||||
|
||||
inline bool isChar(int c);
|
||||
|
||||
|
||||
+21
-10
@@ -28,14 +28,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#ifndef SERVER_H
|
||||
#define SERVER_H
|
||||
|
||||
#include "../Util/StringUtil.h"
|
||||
|
||||
#include "Connection.h"
|
||||
#include "RequestHandler.h"
|
||||
|
||||
#include "../Util/cast.hpp"
|
||||
#include "../Util/make_unique.hpp"
|
||||
#include "../Util/simple_logger.hpp"
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
@@ -44,11 +48,21 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
class Server
|
||||
{
|
||||
public:
|
||||
|
||||
// Note: returns a shared instead of a unique ptr as it is captured in a lambda somewhere else
|
||||
static std::shared_ptr<Server> CreateServer(std::string &ip_address, int ip_port, unsigned requested_num_threads)
|
||||
{
|
||||
SimpleLogger().Write() << "http 1.1 compression handled by zlib version " << zlibVersion();
|
||||
const unsigned hardware_threads = std::max(1u, std::thread::hardware_concurrency());
|
||||
const unsigned real_num_threads = std::min(hardware_threads, requested_num_threads);
|
||||
return std::make_shared<Server>(ip_address, ip_port, real_num_threads);
|
||||
}
|
||||
|
||||
explicit Server(const std::string &address, const int port, const unsigned thread_pool_size)
|
||||
: thread_pool_size(thread_pool_size), acceptor(io_service),
|
||||
new_connection(new http::Connection(io_service, request_handler)), request_handler()
|
||||
new_connection(std::make_shared<http::Connection>(io_service, request_handler)), request_handler()
|
||||
{
|
||||
const std::string port_string = IntToString(port);
|
||||
const std::string port_string = cast::integral_to_string(port);
|
||||
|
||||
boost::asio::ip::tcp::resolver resolver(io_service);
|
||||
boost::asio::ip::tcp::resolver::query query(address, port_string);
|
||||
@@ -63,9 +77,6 @@ class Server
|
||||
boost::bind(&Server::HandleAccept, this, boost::asio::placeholders::error));
|
||||
}
|
||||
|
||||
Server() = delete;
|
||||
Server(const Server &) = delete;
|
||||
|
||||
void Run()
|
||||
{
|
||||
std::vector<std::shared_ptr<std::thread>> threads;
|
||||
@@ -75,9 +86,9 @@ class Server
|
||||
boost::bind(&boost::asio::io_service::run, &io_service));
|
||||
threads.push_back(thread);
|
||||
}
|
||||
for (unsigned i = 0; i < threads.size(); ++i)
|
||||
for (auto thread : threads)
|
||||
{
|
||||
threads[i]->join();
|
||||
thread->join();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +102,7 @@ class Server
|
||||
if (!e)
|
||||
{
|
||||
new_connection->start();
|
||||
new_connection.reset(new http::Connection(io_service, request_handler));
|
||||
new_connection = std::make_shared<http::Connection>(io_service, request_handler);
|
||||
acceptor.async_accept(
|
||||
new_connection->socket(),
|
||||
boost::bind(&Server::HandleAccept, this, boost::asio::placeholders::error));
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef SERVER_FACTORY_H
|
||||
#define SERVER_FACTORY_H
|
||||
|
||||
#include "Server.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
struct ServerFactory
|
||||
{
|
||||
ServerFactory() = delete;
|
||||
ServerFactory(const ServerFactory &) = delete;
|
||||
static Server *CreateServer(std::string &ip_address, int ip_port, unsigned requested_num_threads)
|
||||
{
|
||||
SimpleLogger().Write() << "http 1.1 compression handled by zlib version " << zlibVersion();
|
||||
const unsigned hardware_threads = std::max(1u, std::thread::hardware_concurrency());
|
||||
const unsigned real_num_threads = std::min(hardware_threads, requested_num_threads);
|
||||
return new Server(ip_address, ip_port, real_num_threads);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // SERVER_FACTORY_H
|
||||
@@ -1,136 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "../typedefs.h"
|
||||
#include "../Algorithms/StronglyConnectedComponents.h"
|
||||
#include "../DataStructures/DynamicGraph.h"
|
||||
#include "../DataStructures/QueryEdge.h"
|
||||
#include "../DataStructures/TurnInstructions.h"
|
||||
#include "../Util/GraphLoader.h"
|
||||
#include "../Util/OSRMException.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
#include "../Util/FingerPrint.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
typedef QueryEdge::EdgeData EdgeData;
|
||||
typedef DynamicGraph<EdgeData>::InputEdge InputEdge;
|
||||
|
||||
std::vector<NodeInfo> internal_to_external_node_map;
|
||||
std::vector<TurnRestriction> restrictions_vector;
|
||||
std::vector<NodeID> bollard_node_IDs_vector;
|
||||
std::vector<NodeID> traffic_light_node_IDs_vector;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
if (argc < 3)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "usage:\n" << argv[0] << " <osrm> <osrm.restrictions>";
|
||||
return -1;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
SimpleLogger().Write() << "Using restrictions from file: " << argv[2];
|
||||
std::ifstream restriction_ifstream(argv[2], std::ios::binary);
|
||||
const FingerPrint fingerprint_orig;
|
||||
FingerPrint fingerprint_loaded;
|
||||
restriction_ifstream.read((char *)&fingerprint_loaded, sizeof(FingerPrint));
|
||||
|
||||
if (!fingerprint_loaded.TestGraphUtil(fingerprint_orig))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << argv[2] << " was prepared with a different build. "
|
||||
"Reprocess to get rid of this warning.";
|
||||
}
|
||||
|
||||
if (!restriction_ifstream.good())
|
||||
{
|
||||
throw OSRMException("Could not access <osrm-restrictions> files");
|
||||
}
|
||||
uint32_t usable_restriction_count = 0;
|
||||
restriction_ifstream.read((char *)&usable_restriction_count, sizeof(uint32_t));
|
||||
restrictions_vector.resize(usable_restriction_count);
|
||||
|
||||
if (usable_restriction_count>0)
|
||||
{
|
||||
restriction_ifstream.read((char *)&(restrictions_vector[0]),
|
||||
usable_restriction_count * sizeof(TurnRestriction));
|
||||
}
|
||||
restriction_ifstream.close();
|
||||
|
||||
std::ifstream input_stream;
|
||||
input_stream.open(argv[1], std::ifstream::in | std::ifstream::binary);
|
||||
|
||||
if (!input_stream.is_open())
|
||||
{
|
||||
throw OSRMException("Cannot open osrm file");
|
||||
}
|
||||
|
||||
std::vector<ImportEdge> edge_list;
|
||||
const NodeID number_of_nodes = readBinaryOSRMGraphFromStream(input_stream,
|
||||
edge_list,
|
||||
bollard_node_IDs_vector,
|
||||
traffic_light_node_IDs_vector,
|
||||
&internal_to_external_node_map,
|
||||
restrictions_vector);
|
||||
input_stream.close();
|
||||
|
||||
BOOST_ASSERT_MSG(restrictions_vector.size() == usable_restriction_count,
|
||||
"size of restrictions_vector changed");
|
||||
|
||||
SimpleLogger().Write() << restrictions_vector.size() << " restrictions, "
|
||||
<< bollard_node_IDs_vector.size() << " bollard nodes, "
|
||||
<< traffic_light_node_IDs_vector.size() << " traffic lights";
|
||||
|
||||
/***
|
||||
* Building an edge-expanded graph from node-based input an turn
|
||||
* restrictions
|
||||
*/
|
||||
|
||||
SimpleLogger().Write() << "Starting SCC graph traversal";
|
||||
std::shared_ptr<TarjanSCC> tarjan =
|
||||
std::make_shared<TarjanSCC>(number_of_nodes,
|
||||
edge_list,
|
||||
bollard_node_IDs_vector,
|
||||
traffic_light_node_IDs_vector,
|
||||
restrictions_vector,
|
||||
internal_to_external_node_map);
|
||||
std::vector<ImportEdge>().swap(edge_list);
|
||||
|
||||
tarjan->Run();
|
||||
SimpleLogger().Write() << "finished component analysis";
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "../../algorithms/douglas_peucker.hpp"
|
||||
#include "../../data_structures/segment_information.hpp"
|
||||
#include "../../Include/osrm/Coordinate.h"
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/test_case_template.hpp>
|
||||
#include <boost/mpl/list.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(douglas_peucker)
|
||||
|
||||
SegmentInformation getTestInfo(int lat, int lon, bool necessary)
|
||||
{
|
||||
return SegmentInformation(FixedPointCoordinate(lat, lon),
|
||||
0, 0, 0, TurnInstruction::HeadOn, necessary, false, 0);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(all_necessary_test)
|
||||
{
|
||||
/*
|
||||
* x
|
||||
* / \
|
||||
* x \
|
||||
* / \
|
||||
* x x
|
||||
*/
|
||||
std::vector<SegmentInformation> info = {
|
||||
getTestInfo(5, 5, true),
|
||||
getTestInfo(6, 6, true),
|
||||
getTestInfo(10, 10, true),
|
||||
getTestInfo(5, 15, true)
|
||||
};
|
||||
DouglasPeucker dp;
|
||||
for (unsigned z = 0; z < DOUGLAS_PEUCKER_THRESHOLDS.size(); z++)
|
||||
{
|
||||
dp.Run(info, z);
|
||||
for (const auto& i : info)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(i.necessary, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(remove_second_node_test)
|
||||
{
|
||||
DouglasPeucker dp;
|
||||
for (unsigned z = 0; z < DOUGLAS_PEUCKER_THRESHOLDS.size(); z++)
|
||||
{
|
||||
/*
|
||||
* x--x
|
||||
* | \
|
||||
* x-x x
|
||||
* |
|
||||
* x
|
||||
*/
|
||||
std::vector<SegmentInformation> info = {
|
||||
getTestInfo(5 * COORDINATE_PRECISION,
|
||||
5 * COORDINATE_PRECISION, true),
|
||||
getTestInfo(5 * COORDINATE_PRECISION,
|
||||
5 * COORDINATE_PRECISION + DOUGLAS_PEUCKER_THRESHOLDS[z], false),
|
||||
getTestInfo(10 * COORDINATE_PRECISION,
|
||||
10 * COORDINATE_PRECISION, false),
|
||||
getTestInfo(10 * COORDINATE_PRECISION,
|
||||
10 + COORDINATE_PRECISION + DOUGLAS_PEUCKER_THRESHOLDS[z] * 2, false),
|
||||
getTestInfo(5 * COORDINATE_PRECISION,
|
||||
15 * COORDINATE_PRECISION, false),
|
||||
getTestInfo(5 * COORDINATE_PRECISION + DOUGLAS_PEUCKER_THRESHOLDS[z],
|
||||
15 * COORDINATE_PRECISION, true),
|
||||
};
|
||||
BOOST_TEST_MESSAGE("Threshold (" << z << "): " << DOUGLAS_PEUCKER_THRESHOLDS[z]);
|
||||
dp.Run(info, z);
|
||||
BOOST_CHECK_EQUAL(info[0].necessary, true);
|
||||
BOOST_CHECK_EQUAL(info[1].necessary, false);
|
||||
BOOST_CHECK_EQUAL(info[2].necessary, true);
|
||||
BOOST_CHECK_EQUAL(info[3].necessary, true);
|
||||
BOOST_CHECK_EQUAL(info[4].necessary, false);
|
||||
BOOST_CHECK_EQUAL(info[5].necessary, true);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#define BOOST_TEST_MODULE algorithm tests
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
/*
|
||||
* This file will contain an automatically generated main function.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "../../data_structures/binary_heap.hpp"
|
||||
#include "../../typedefs.h"
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/test_case_template.hpp>
|
||||
#include <boost/mpl/list.hpp>
|
||||
|
||||
#include <random>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(binary_heap)
|
||||
|
||||
struct TestData
|
||||
{
|
||||
unsigned value;
|
||||
};
|
||||
|
||||
typedef NodeID TestNodeID;
|
||||
typedef int TestKey;
|
||||
typedef int TestWeight;
|
||||
typedef boost::mpl::list<ArrayStorage<TestNodeID, TestKey>,
|
||||
MapStorage<TestNodeID, TestKey>,
|
||||
UnorderedMapStorage<TestNodeID, TestKey>> storage_types;
|
||||
|
||||
template <unsigned NUM_ELEM> struct RandomDataFixture
|
||||
{
|
||||
RandomDataFixture()
|
||||
{
|
||||
for (unsigned i = 0; i < NUM_ELEM; i++)
|
||||
{
|
||||
data.push_back(TestData{i * 3});
|
||||
weights.push_back((i + 1) * 100);
|
||||
ids.push_back(i);
|
||||
order.push_back(i);
|
||||
}
|
||||
|
||||
// Choosen by a fair W20 dice roll
|
||||
std::mt19937 g(15);
|
||||
|
||||
std::shuffle(order.begin(), order.end(), g);
|
||||
}
|
||||
|
||||
std::vector<TestData> data;
|
||||
std::vector<TestWeight> weights;
|
||||
std::vector<TestNodeID> ids;
|
||||
std::vector<unsigned> order;
|
||||
};
|
||||
|
||||
constexpr unsigned NUM_NODES = 100;
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE_TEMPLATE(insert_test, T, storage_types, RandomDataFixture<NUM_NODES>)
|
||||
{
|
||||
BinaryHeap<TestNodeID, TestKey, TestWeight, TestData, T> heap(NUM_NODES);
|
||||
|
||||
TestWeight min_weight = std::numeric_limits<TestWeight>::max();
|
||||
TestNodeID min_id;
|
||||
|
||||
for (unsigned idx : order)
|
||||
{
|
||||
BOOST_CHECK(!heap.WasInserted(ids[idx]));
|
||||
|
||||
heap.Insert(ids[idx], weights[idx], data[idx]);
|
||||
|
||||
BOOST_CHECK(heap.WasInserted(ids[idx]));
|
||||
|
||||
if (weights[idx] < min_weight)
|
||||
{
|
||||
min_weight = weights[idx];
|
||||
min_id = ids[idx];
|
||||
}
|
||||
BOOST_CHECK_EQUAL(min_id, heap.Min());
|
||||
}
|
||||
|
||||
for (auto id : ids)
|
||||
{
|
||||
const auto &d = heap.GetData(id);
|
||||
BOOST_CHECK_EQUAL(d.value, data[id].value);
|
||||
|
||||
const auto &w = heap.GetKey(id);
|
||||
BOOST_CHECK_EQUAL(w, weights[id]);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE_TEMPLATE(delete_min_test, T, storage_types, RandomDataFixture<NUM_NODES>)
|
||||
{
|
||||
BinaryHeap<TestNodeID, TestKey, TestWeight, TestData, T> heap(NUM_NODES);
|
||||
|
||||
for (unsigned idx : order)
|
||||
{
|
||||
heap.Insert(ids[idx], weights[idx], data[idx]);
|
||||
}
|
||||
|
||||
for (auto id : ids)
|
||||
{
|
||||
BOOST_CHECK(!heap.WasRemoved(id));
|
||||
|
||||
BOOST_CHECK_EQUAL(heap.Min(), id);
|
||||
BOOST_CHECK_EQUAL(id, heap.DeleteMin());
|
||||
if (id + 1 < NUM_NODES)
|
||||
BOOST_CHECK_EQUAL(heap.Min(), id + 1);
|
||||
|
||||
BOOST_CHECK(heap.WasRemoved(id));
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE_TEMPLATE(delete_all_test, T, storage_types, RandomDataFixture<NUM_NODES>)
|
||||
{
|
||||
BinaryHeap<TestNodeID, TestKey, TestWeight, TestData, T> heap(NUM_NODES);
|
||||
|
||||
for (unsigned idx : order)
|
||||
{
|
||||
heap.Insert(ids[idx], weights[idx], data[idx]);
|
||||
}
|
||||
|
||||
heap.DeleteAll();
|
||||
|
||||
BOOST_CHECK(heap.Empty());
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE_TEMPLATE(decrease_key_test, T, storage_types, RandomDataFixture<10>)
|
||||
{
|
||||
BinaryHeap<TestNodeID, TestKey, TestWeight, TestData, T> heap(10);
|
||||
|
||||
for (unsigned idx : order)
|
||||
{
|
||||
heap.Insert(ids[idx], weights[idx], data[idx]);
|
||||
}
|
||||
|
||||
std::vector<TestNodeID> rids(ids);
|
||||
std::reverse(rids.begin(), rids.end());
|
||||
|
||||
for (auto id : rids)
|
||||
{
|
||||
TestNodeID min_id = heap.Min();
|
||||
TestWeight min_weight = heap.GetKey(min_id);
|
||||
|
||||
// decrease weight until we reach min weight
|
||||
while (weights[id] > min_weight)
|
||||
{
|
||||
heap.DecreaseKey(id, weights[id]);
|
||||
BOOST_CHECK_EQUAL(heap.Min(), min_id);
|
||||
weights[id]--;
|
||||
}
|
||||
|
||||
// make weight smaller than min
|
||||
weights[id] -= 2;
|
||||
heap.DecreaseKey(id, weights[id]);
|
||||
BOOST_CHECK_EQUAL(heap.Min(), id);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "../../data_structures/range_table.hpp"
|
||||
#include "../../typedefs.h"
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/test_case_template.hpp>
|
||||
|
||||
#include <numeric>
|
||||
|
||||
constexpr unsigned BLOCK_SIZE = 16;
|
||||
typedef RangeTable<BLOCK_SIZE, false> TestRangeTable;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(range_table)
|
||||
|
||||
void ConstructionTest(std::vector<unsigned> lengths, std::vector<unsigned> offsets)
|
||||
{
|
||||
BOOST_ASSERT(lengths.size() == offsets.size() - 1);
|
||||
|
||||
TestRangeTable table(lengths);
|
||||
|
||||
for (unsigned i = 0; i < lengths.size(); i++)
|
||||
{
|
||||
auto range = table.GetRange(i);
|
||||
BOOST_CHECK_EQUAL(range.front(), offsets[i]);
|
||||
BOOST_CHECK_EQUAL(range.back() + 1, offsets[i + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ComputeLengthsOffsets(std::vector<unsigned> &lengths, std::vector<unsigned> &offsets, unsigned num)
|
||||
{
|
||||
lengths.resize(num);
|
||||
offsets.resize(num + 1);
|
||||
std::iota(lengths.begin(), lengths.end(), 1);
|
||||
offsets[0] = 0;
|
||||
std::partial_sum(lengths.begin(), lengths.end(), offsets.begin() + 1);
|
||||
|
||||
std::stringstream l_ss;
|
||||
l_ss << "Lengths: ";
|
||||
for (auto l : lengths)
|
||||
l_ss << l << ", ";
|
||||
BOOST_TEST_MESSAGE(l_ss.str());
|
||||
std::stringstream o_ss;
|
||||
o_ss << "Offsets: ";
|
||||
for (auto o : offsets)
|
||||
o_ss << o << ", ";
|
||||
BOOST_TEST_MESSAGE(o_ss.str());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(serialization_test)
|
||||
{
|
||||
std::vector<unsigned> lengths;
|
||||
std::vector<unsigned> offsets;
|
||||
ComputeLengthsOffsets(lengths, offsets, (BLOCK_SIZE + 1) * 10);
|
||||
|
||||
TestRangeTable in_table(lengths);
|
||||
TestRangeTable out_table;
|
||||
|
||||
std::stringstream ss;
|
||||
ss << in_table;
|
||||
ss >> out_table;
|
||||
|
||||
for (unsigned i = 0; i < lengths.size(); i++)
|
||||
{
|
||||
auto range = out_table.GetRange(i);
|
||||
BOOST_CHECK_EQUAL(range.front(), offsets[i]);
|
||||
BOOST_CHECK_EQUAL(range.back() + 1, offsets[i + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(construction_test)
|
||||
{
|
||||
// only offset empty block
|
||||
ConstructionTest({1}, {0, 1});
|
||||
// first block almost full => sentinel is last element of block
|
||||
// [0] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, (16)}
|
||||
std::vector<unsigned> almost_full_lengths;
|
||||
std::vector<unsigned> almost_full_offsets;
|
||||
ComputeLengthsOffsets(almost_full_lengths, almost_full_offsets, BLOCK_SIZE);
|
||||
ConstructionTest(almost_full_lengths, almost_full_offsets);
|
||||
|
||||
// first block full => sentinel is offset of new block, next block empty
|
||||
// [0] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
|
||||
// [(153)] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||
std::vector<unsigned> full_lengths;
|
||||
std::vector<unsigned> full_offsets;
|
||||
ComputeLengthsOffsets(full_lengths, full_offsets, BLOCK_SIZE + 1);
|
||||
ConstructionTest(full_lengths, full_offsets);
|
||||
|
||||
// first block full and offset of next block not sentinel, but the first differential value
|
||||
// [0] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
|
||||
// [153] {(17), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||
std::vector<unsigned> over_full_lengths;
|
||||
std::vector<unsigned> over_full_offsets;
|
||||
ComputeLengthsOffsets(over_full_lengths, over_full_offsets, BLOCK_SIZE + 2);
|
||||
ConstructionTest(over_full_lengths, over_full_offsets);
|
||||
|
||||
// test multiple blocks
|
||||
std::vector<unsigned> multiple_lengths;
|
||||
std::vector<unsigned> multiple_offsets;
|
||||
ComputeLengthsOffsets(multiple_lengths, multiple_offsets, (BLOCK_SIZE + 1) * 10);
|
||||
ConstructionTest(multiple_lengths, multiple_offsets);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "../../data_structures/static_graph.hpp"
|
||||
#include "../../typedefs.h"
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/test_case_template.hpp>
|
||||
#include <boost/mpl/list.hpp>
|
||||
|
||||
#include <random>
|
||||
#include <unordered_map>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(static_graph)
|
||||
|
||||
struct TestData
|
||||
{
|
||||
EdgeID id;
|
||||
bool shortcut;
|
||||
unsigned distance;
|
||||
};
|
||||
|
||||
struct TestEdge
|
||||
{
|
||||
unsigned source;
|
||||
unsigned target;
|
||||
unsigned distance;
|
||||
};
|
||||
|
||||
typedef StaticGraph<TestData> TestStaticGraph;
|
||||
typedef TestStaticGraph::NodeArrayEntry TestNodeArrayEntry;
|
||||
typedef TestStaticGraph::EdgeArrayEntry TestEdgeArrayEntry;
|
||||
typedef TestStaticGraph::InputEdge TestInputEdge;
|
||||
|
||||
constexpr unsigned TEST_NUM_NODES = 100;
|
||||
constexpr unsigned TEST_NUM_EDGES = 500;
|
||||
// Choosen by a fair W20 dice roll (this value is completely arbitrary)
|
||||
constexpr unsigned RANDOM_SEED = 15;
|
||||
|
||||
template <unsigned NUM_NODES, unsigned NUM_EDGES> struct RandomArrayEntryFixture
|
||||
{
|
||||
RandomArrayEntryFixture()
|
||||
{
|
||||
std::mt19937 g(RANDOM_SEED);
|
||||
|
||||
std::uniform_int_distribution<> edge_udist(0, NUM_EDGES - 1);
|
||||
std::vector<unsigned> offsets;
|
||||
for (unsigned i = 0; i < NUM_NODES; i++)
|
||||
{
|
||||
offsets.push_back(edge_udist(g));
|
||||
}
|
||||
std::sort(offsets.begin(), offsets.end());
|
||||
// add sentinel
|
||||
offsets.push_back(offsets.back());
|
||||
|
||||
// extract interval lengths
|
||||
for (unsigned i = 0; i < offsets.size() - 1; i++)
|
||||
{
|
||||
lengths.push_back(offsets[i + 1] - offsets[i]);
|
||||
}
|
||||
lengths.push_back(NUM_EDGES - offsets[NUM_NODES - 1]);
|
||||
|
||||
for (auto offset : offsets)
|
||||
{
|
||||
nodes.emplace_back(TestNodeArrayEntry{offset});
|
||||
}
|
||||
|
||||
std::uniform_int_distribution<> lengths_udist(0, 100000);
|
||||
std::uniform_int_distribution<> node_udist(0, NUM_NODES - 1);
|
||||
for (unsigned i = 0; i < NUM_EDGES; i++)
|
||||
{
|
||||
edges.emplace_back(
|
||||
TestEdgeArrayEntry{static_cast<unsigned>(node_udist(g)),
|
||||
TestData{i, false, static_cast<unsigned>(lengths_udist(g))}});
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < NUM_NODES; i++)
|
||||
order.push_back(i);
|
||||
std::shuffle(order.begin(), order.end(), g);
|
||||
}
|
||||
|
||||
typename ShM<TestNodeArrayEntry, false>::vector nodes;
|
||||
typename ShM<TestEdgeArrayEntry, false>::vector edges;
|
||||
std::vector<unsigned> lengths;
|
||||
std::vector<unsigned> order;
|
||||
};
|
||||
|
||||
typedef RandomArrayEntryFixture<TEST_NUM_NODES, TEST_NUM_EDGES> TestRandomArrayEntryFixture;
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(array_test, TestRandomArrayEntryFixture)
|
||||
{
|
||||
auto nodes_copy = nodes;
|
||||
|
||||
TestStaticGraph graph(nodes, edges);
|
||||
|
||||
BOOST_CHECK_EQUAL(graph.GetNumberOfEdges(), TEST_NUM_EDGES);
|
||||
BOOST_CHECK_EQUAL(graph.GetNumberOfNodes(), TEST_NUM_NODES);
|
||||
|
||||
for (auto idx : order)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(graph.BeginEdges((NodeID)idx), nodes_copy[idx].first_edge);
|
||||
BOOST_CHECK_EQUAL(graph.EndEdges((NodeID)idx), nodes_copy[idx + 1].first_edge);
|
||||
BOOST_CHECK_EQUAL(graph.GetOutDegree((NodeID)idx), lengths[idx]);
|
||||
}
|
||||
}
|
||||
|
||||
TestStaticGraph GraphFromEdgeList(const std::vector<TestEdge> &edges)
|
||||
{
|
||||
std::vector<TestInputEdge> input_edges;
|
||||
unsigned i = 0;
|
||||
unsigned num_nodes = 0;
|
||||
for (const auto &e : edges)
|
||||
{
|
||||
input_edges.push_back(TestInputEdge{e.source, e.target, TestData{i++, false, e.distance}});
|
||||
|
||||
num_nodes = std::max(num_nodes, std::max(e.source, e.target));
|
||||
}
|
||||
|
||||
return TestStaticGraph(num_nodes, input_edges);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(find_test)
|
||||
{
|
||||
/*
|
||||
* (0) -1-> (1)
|
||||
* ^ ^
|
||||
* 2 1
|
||||
* | |
|
||||
* (3) -4-> (4)
|
||||
* <-3-
|
||||
*/
|
||||
TestStaticGraph simple_graph = GraphFromEdgeList({TestEdge{0, 1, 1},
|
||||
TestEdge{3, 0, 2},
|
||||
TestEdge{3, 4, 4},
|
||||
TestEdge{4, 3, 3},
|
||||
TestEdge{3, 0, 1}});
|
||||
|
||||
auto eit = simple_graph.FindEdge(0, 1);
|
||||
BOOST_CHECK_EQUAL(simple_graph.GetEdgeData(eit).id, 0);
|
||||
|
||||
eit = simple_graph.FindEdge(1, 0);
|
||||
BOOST_CHECK_EQUAL(eit, SPECIAL_EDGEID);
|
||||
|
||||
eit = simple_graph.FindEdgeInEitherDirection(1, 0);
|
||||
BOOST_CHECK_EQUAL(simple_graph.GetEdgeData(eit).id, 0);
|
||||
|
||||
bool reverse = false;
|
||||
eit = simple_graph.FindEdgeIndicateIfReverse(1, 0, reverse);
|
||||
BOOST_CHECK_EQUAL(simple_graph.GetEdgeData(eit).id, 0);
|
||||
BOOST_CHECK(reverse);
|
||||
|
||||
eit = simple_graph.FindEdge(3, 1);
|
||||
BOOST_CHECK_EQUAL(eit, SPECIAL_EDGEID);
|
||||
eit = simple_graph.FindEdge(0, 4);
|
||||
BOOST_CHECK_EQUAL(eit, SPECIAL_EDGEID);
|
||||
|
||||
eit = simple_graph.FindEdge(3, 4);
|
||||
BOOST_CHECK_EQUAL(simple_graph.GetEdgeData(eit).id, 2);
|
||||
eit = simple_graph.FindEdgeInEitherDirection(3, 4);
|
||||
// I think this is wrong behaviour! Should be 3.
|
||||
BOOST_CHECK_EQUAL(simple_graph.GetEdgeData(eit).id, 2);
|
||||
|
||||
eit = simple_graph.FindEdge(3, 0);
|
||||
BOOST_CHECK_EQUAL(simple_graph.GetEdgeData(eit).id, 4);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
@@ -0,0 +1,488 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "../../data_structures/static_rtree.hpp"
|
||||
#include "../../data_structures/query_node.hpp"
|
||||
#include "../../data_structures/edge_based_node.hpp"
|
||||
#include "../../Util/floating_point.hpp"
|
||||
#include "../../typedefs.h"
|
||||
|
||||
#include <osrm/Coordinate.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/test_case_template.hpp>
|
||||
#include <boost/mpl/list.hpp>
|
||||
|
||||
#include <random>
|
||||
#include <unordered_set>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(static_rtree)
|
||||
|
||||
constexpr uint32_t TEST_BRANCHING_FACTOR = 8;
|
||||
constexpr uint32_t TEST_LEAF_NODE_SIZE = 64;
|
||||
|
||||
typedef EdgeBasedNode TestData;
|
||||
typedef StaticRTree<TestData,
|
||||
std::vector<FixedPointCoordinate>,
|
||||
false,
|
||||
TEST_BRANCHING_FACTOR,
|
||||
TEST_LEAF_NODE_SIZE> TestStaticRTree;
|
||||
|
||||
// Choosen by a fair W20 dice roll (this value is completely arbitrary)
|
||||
constexpr unsigned RANDOM_SEED = 42;
|
||||
static const int32_t WORLD_MIN_LAT = -90 * COORDINATE_PRECISION;
|
||||
static const int32_t WORLD_MAX_LAT = 90 * COORDINATE_PRECISION;
|
||||
static const int32_t WORLD_MIN_LON = -180 * COORDINATE_PRECISION;
|
||||
static const int32_t WORLD_MAX_LON = 180 * COORDINATE_PRECISION;
|
||||
|
||||
class LinearSearchNN
|
||||
{
|
||||
public:
|
||||
LinearSearchNN(const std::shared_ptr<std::vector<FixedPointCoordinate>> &coords,
|
||||
const std::vector<TestData> &edges)
|
||||
: coords(coords), edges(edges)
|
||||
{
|
||||
}
|
||||
|
||||
bool LocateClosestEndPointForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
FixedPointCoordinate &result_coordinate)
|
||||
{
|
||||
float min_dist = std::numeric_limits<float>::max();
|
||||
FixedPointCoordinate min_coord;
|
||||
for (const TestData &e : edges)
|
||||
{
|
||||
const FixedPointCoordinate &start = coords->at(e.u);
|
||||
const FixedPointCoordinate &end = coords->at(e.v);
|
||||
float distance = FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
input_coordinate.lat, input_coordinate.lon, start.lat, start.lon);
|
||||
if (distance < min_dist)
|
||||
{
|
||||
min_coord = start;
|
||||
min_dist = distance;
|
||||
}
|
||||
|
||||
distance = FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
input_coordinate.lat, input_coordinate.lon, end.lat, end.lon);
|
||||
if (distance < min_dist)
|
||||
{
|
||||
min_coord = end;
|
||||
min_dist = distance;
|
||||
}
|
||||
}
|
||||
|
||||
result_coordinate = min_coord;
|
||||
return result_coordinate.is_valid();
|
||||
}
|
||||
|
||||
bool FindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate,
|
||||
PhantomNode &result_phantom_node,
|
||||
const unsigned zoom_level)
|
||||
{
|
||||
float min_dist = std::numeric_limits<float>::max();
|
||||
TestData nearest_edge;
|
||||
for (const TestData &e : edges)
|
||||
{
|
||||
if (e.component_id != 0)
|
||||
continue;
|
||||
|
||||
float current_ratio = 0.;
|
||||
FixedPointCoordinate nearest;
|
||||
const float current_perpendicular_distance =
|
||||
FixedPointCoordinate::ComputePerpendicularDistance(
|
||||
coords->at(e.u), coords->at(e.v), input_coordinate, nearest, current_ratio);
|
||||
|
||||
if ((current_perpendicular_distance < min_dist) &&
|
||||
!osrm::epsilon_compare(current_perpendicular_distance, min_dist))
|
||||
{ // found a new minimum
|
||||
min_dist = current_perpendicular_distance;
|
||||
result_phantom_node = {e.forward_edge_based_node_id,
|
||||
e.reverse_edge_based_node_id,
|
||||
e.name_id,
|
||||
e.forward_weight,
|
||||
e.reverse_weight,
|
||||
e.forward_offset,
|
||||
e.reverse_offset,
|
||||
e.packed_geometry_id,
|
||||
e.component_id,
|
||||
nearest,
|
||||
e.fwd_segment_position,
|
||||
e.forward_travel_mode,
|
||||
e.backward_travel_mode};
|
||||
nearest_edge = e;
|
||||
}
|
||||
}
|
||||
|
||||
if (result_phantom_node.location.is_valid())
|
||||
{
|
||||
// Hack to fix rounding errors and wandering via nodes.
|
||||
if (1 == std::abs(input_coordinate.lon - result_phantom_node.location.lon))
|
||||
{
|
||||
result_phantom_node.location.lon = input_coordinate.lon;
|
||||
}
|
||||
if (1 == std::abs(input_coordinate.lat - result_phantom_node.location.lat))
|
||||
{
|
||||
result_phantom_node.location.lat = input_coordinate.lat;
|
||||
}
|
||||
|
||||
const float distance_1 = FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
coords->at(nearest_edge.u), result_phantom_node.location);
|
||||
const float distance_2 = FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
coords->at(nearest_edge.u), coords->at(nearest_edge.v));
|
||||
const float ratio = std::min(1.f, distance_1 / distance_2);
|
||||
|
||||
if (SPECIAL_NODEID != result_phantom_node.forward_node_id)
|
||||
{
|
||||
result_phantom_node.forward_weight *= ratio;
|
||||
}
|
||||
if (SPECIAL_NODEID != result_phantom_node.reverse_node_id)
|
||||
{
|
||||
result_phantom_node.reverse_weight *= (1. - ratio);
|
||||
}
|
||||
}
|
||||
|
||||
return result_phantom_node.location.is_valid();
|
||||
}
|
||||
|
||||
private:
|
||||
const std::shared_ptr<std::vector<FixedPointCoordinate>> &coords;
|
||||
const std::vector<TestData> &edges;
|
||||
};
|
||||
|
||||
template <unsigned NUM_NODES, unsigned NUM_EDGES> struct RandomGraphFixture
|
||||
{
|
||||
struct TupleHash
|
||||
{
|
||||
typedef std::pair<unsigned, unsigned> argument_type;
|
||||
typedef std::size_t result_type;
|
||||
|
||||
result_type operator()(const argument_type &t) const
|
||||
{
|
||||
std::size_t val{0};
|
||||
boost::hash_combine(val, t.first);
|
||||
boost::hash_combine(val, t.second);
|
||||
return val;
|
||||
}
|
||||
};
|
||||
|
||||
RandomGraphFixture() : coords(std::make_shared<std::vector<FixedPointCoordinate>>())
|
||||
{
|
||||
BOOST_TEST_MESSAGE("Constructing " << NUM_NODES << " nodes and " << NUM_EDGES << " edges.");
|
||||
|
||||
std::mt19937 g(RANDOM_SEED);
|
||||
|
||||
std::uniform_int_distribution<> lat_udist(WORLD_MIN_LAT, WORLD_MAX_LAT);
|
||||
std::uniform_int_distribution<> lon_udist(WORLD_MIN_LON, WORLD_MAX_LON);
|
||||
|
||||
for (unsigned i = 0; i < NUM_NODES; i++)
|
||||
{
|
||||
int lat = lat_udist(g);
|
||||
int lon = lon_udist(g);
|
||||
nodes.emplace_back(QueryNode(lat, lon, i));
|
||||
coords->emplace_back(FixedPointCoordinate(lat, lon));
|
||||
}
|
||||
|
||||
std::uniform_int_distribution<> edge_udist(0, nodes.size() - 1);
|
||||
|
||||
std::unordered_set<std::pair<unsigned, unsigned>, TupleHash> used_edges;
|
||||
|
||||
while (edges.size() < NUM_EDGES)
|
||||
{
|
||||
TestData data;
|
||||
data.u = edge_udist(g);
|
||||
data.v = edge_udist(g);
|
||||
if (used_edges.find(std::pair<unsigned, unsigned>(
|
||||
std::min(data.u, data.v), std::max(data.u, data.v))) == used_edges.end())
|
||||
{
|
||||
data.component_id = 0;
|
||||
edges.emplace_back(data);
|
||||
used_edges.emplace(std::min(data.u, data.v), std::max(data.u, data.v));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<QueryNode> nodes;
|
||||
std::shared_ptr<std::vector<FixedPointCoordinate>> coords;
|
||||
std::vector<TestData> edges;
|
||||
};
|
||||
|
||||
struct GraphFixture
|
||||
{
|
||||
GraphFixture(const std::vector<std::pair<float, float>> &input_coords,
|
||||
const std::vector<std::pair<unsigned, unsigned>> &input_edges)
|
||||
: coords(std::make_shared<std::vector<FixedPointCoordinate>>())
|
||||
{
|
||||
|
||||
for (unsigned i = 0; i < input_coords.size(); i++)
|
||||
{
|
||||
FixedPointCoordinate c(input_coords[i].first * COORDINATE_PRECISION,
|
||||
input_coords[i].second * COORDINATE_PRECISION);
|
||||
coords->emplace_back(c);
|
||||
nodes.emplace_back(QueryNode(c.lat, c.lon, i));
|
||||
}
|
||||
|
||||
for (const auto &pair : input_edges)
|
||||
{
|
||||
TestData d;
|
||||
d.u = pair.first;
|
||||
d.v = pair.second;
|
||||
edges.emplace_back(d);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<QueryNode> nodes;
|
||||
std::shared_ptr<std::vector<FixedPointCoordinate>> coords;
|
||||
std::vector<TestData> edges;
|
||||
};
|
||||
|
||||
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE * 3, TEST_LEAF_NODE_SIZE / 2>
|
||||
TestRandomGraphFixture_LeafHalfFull;
|
||||
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE * 5, TEST_LEAF_NODE_SIZE>
|
||||
TestRandomGraphFixture_LeafFull;
|
||||
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE * 10, TEST_LEAF_NODE_SIZE * 2>
|
||||
TestRandomGraphFixture_TwoLeaves;
|
||||
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE * TEST_BRANCHING_FACTOR * 3,
|
||||
TEST_LEAF_NODE_SIZE * TEST_BRANCHING_FACTOR>
|
||||
TestRandomGraphFixture_Branch;
|
||||
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE * TEST_BRANCHING_FACTOR * 3,
|
||||
TEST_LEAF_NODE_SIZE * TEST_BRANCHING_FACTOR * 2>
|
||||
TestRandomGraphFixture_MultipleLevels;
|
||||
|
||||
template <typename RTreeT>
|
||||
void simple_verify_rtree(RTreeT &rtree,
|
||||
const std::shared_ptr<std::vector<FixedPointCoordinate>> &coords,
|
||||
const std::vector<TestData> &edges)
|
||||
{
|
||||
BOOST_TEST_MESSAGE("Verify end points");
|
||||
for (const auto &e : edges)
|
||||
{
|
||||
FixedPointCoordinate result_u, result_v;
|
||||
const FixedPointCoordinate &pu = coords->at(e.u);
|
||||
const FixedPointCoordinate &pv = coords->at(e.v);
|
||||
bool found_u = rtree.LocateClosestEndPointForCoordinate(pu, result_u, 1);
|
||||
bool found_v = rtree.LocateClosestEndPointForCoordinate(pv, result_v, 1);
|
||||
BOOST_CHECK(found_u && found_v);
|
||||
float dist_u = FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
result_u.lat, result_u.lon, pu.lat, pu.lon);
|
||||
BOOST_CHECK_LE(dist_u, std::numeric_limits<float>::epsilon());
|
||||
float dist_v = FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
result_v.lat, result_v.lon, pv.lat, pv.lon);
|
||||
BOOST_CHECK_LE(dist_v, std::numeric_limits<float>::epsilon());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename RTreeT>
|
||||
void sampling_verify_rtree(RTreeT &rtree, LinearSearchNN &lsnn, unsigned num_samples)
|
||||
{
|
||||
std::mt19937 g(RANDOM_SEED);
|
||||
std::uniform_int_distribution<> lat_udist(WORLD_MIN_LAT, WORLD_MAX_LAT);
|
||||
std::uniform_int_distribution<> lon_udist(WORLD_MIN_LON, WORLD_MAX_LON);
|
||||
std::vector<FixedPointCoordinate> queries;
|
||||
for (unsigned i = 0; i < num_samples; i++)
|
||||
{
|
||||
queries.emplace_back(FixedPointCoordinate(lat_udist(g), lon_udist(g)));
|
||||
}
|
||||
|
||||
BOOST_TEST_MESSAGE("Sampling queries");
|
||||
for (const auto &q : queries)
|
||||
{
|
||||
FixedPointCoordinate result_rtree;
|
||||
rtree.LocateClosestEndPointForCoordinate(q, result_rtree, 1);
|
||||
FixedPointCoordinate result_ln;
|
||||
lsnn.LocateClosestEndPointForCoordinate(q, result_ln);
|
||||
BOOST_CHECK_EQUAL(result_ln, result_rtree);
|
||||
|
||||
PhantomNode phantom_rtree;
|
||||
rtree.FindPhantomNodeForCoordinate(q, phantom_rtree, 1);
|
||||
PhantomNode phantom_ln;
|
||||
lsnn.FindPhantomNodeForCoordinate(q, phantom_ln, 1);
|
||||
BOOST_CHECK_EQUAL(phantom_rtree, phantom_ln);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename FixtureT, typename RTreeT = TestStaticRTree>
|
||||
void build_rtree(const std::string &prefix,
|
||||
FixtureT *fixture,
|
||||
std::string &leaves_path,
|
||||
std::string &nodes_path)
|
||||
{
|
||||
nodes_path = prefix + ".ramIndex";
|
||||
leaves_path = prefix + ".fileIndex";
|
||||
const std::string coords_path = prefix + ".nodes";
|
||||
|
||||
boost::filesystem::ofstream node_stream(coords_path, std::ios::binary);
|
||||
const unsigned num_nodes = fixture->nodes.size();
|
||||
node_stream.write((char *)&num_nodes, sizeof(unsigned));
|
||||
node_stream.write((char *)&(fixture->nodes[0]), num_nodes * sizeof(QueryNode));
|
||||
node_stream.close();
|
||||
|
||||
RTreeT r(fixture->edges, nodes_path, leaves_path, fixture->nodes);
|
||||
}
|
||||
|
||||
template <typename FixtureT, typename RTreeT = TestStaticRTree>
|
||||
void construction_test(const std::string &prefix, FixtureT *fixture)
|
||||
{
|
||||
std::string leaves_path;
|
||||
std::string nodes_path;
|
||||
build_rtree<FixtureT, RTreeT>(prefix, fixture, leaves_path, nodes_path);
|
||||
RTreeT rtree(nodes_path, leaves_path, fixture->coords);
|
||||
LinearSearchNN lsnn(fixture->coords, fixture->edges);
|
||||
|
||||
simple_verify_rtree(rtree, fixture->coords, fixture->edges);
|
||||
sampling_verify_rtree(rtree, lsnn, 100);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(construct_half_leaf_test, TestRandomGraphFixture_LeafHalfFull)
|
||||
{
|
||||
construction_test("test_1", this);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(construct_full_leaf_test, TestRandomGraphFixture_LeafFull)
|
||||
{
|
||||
construction_test("test_2", this);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(construct_two_leaves_test, TestRandomGraphFixture_TwoLeaves)
|
||||
{
|
||||
construction_test("test_3", this);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(construct_branch_test, TestRandomGraphFixture_Branch)
|
||||
{
|
||||
construction_test("test_4", this);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(construct_multiple_levels_test, TestRandomGraphFixture_MultipleLevels)
|
||||
{
|
||||
construction_test("test_5", this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Bug: If you querry a point that lies between two BBs that have a gap,
|
||||
* one BB will be pruned, even if it could contain a nearer match.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(regression_test)
|
||||
{
|
||||
typedef std::pair<float, float> Coord;
|
||||
typedef std::pair<unsigned, unsigned> Edge;
|
||||
GraphFixture fixture({
|
||||
Coord(40.0, 0.0),
|
||||
Coord(35.0, 5.0),
|
||||
|
||||
Coord(5.0, 5.0),
|
||||
Coord(0.0, 10.0),
|
||||
|
||||
Coord(20.0, 10.0),
|
||||
Coord(20.0, 5.0),
|
||||
|
||||
Coord(40.0, 100.0),
|
||||
Coord(35.0, 105.0),
|
||||
|
||||
Coord(5.0, 105.0),
|
||||
Coord(0.0, 110.0),
|
||||
},
|
||||
{Edge(0, 1), Edge(2, 3), Edge(4, 5), Edge(6, 7), Edge(8, 9)});
|
||||
|
||||
typedef StaticRTree<TestData, std::vector<FixedPointCoordinate>, false, 2, 3> MiniStaticRTree;
|
||||
|
||||
std::string leaves_path;
|
||||
std::string nodes_path;
|
||||
build_rtree<GraphFixture, MiniStaticRTree>(
|
||||
"test_regression", &fixture, leaves_path, nodes_path);
|
||||
MiniStaticRTree rtree(nodes_path, leaves_path, fixture.coords);
|
||||
|
||||
// query a node just right of the center of the gap
|
||||
FixedPointCoordinate input(20.0 * COORDINATE_PRECISION, 55.1 * COORDINATE_PRECISION);
|
||||
FixedPointCoordinate result;
|
||||
rtree.LocateClosestEndPointForCoordinate(input, result, 1);
|
||||
FixedPointCoordinate result_ln;
|
||||
LinearSearchNN lsnn(fixture.coords, fixture.edges);
|
||||
lsnn.LocateClosestEndPointForCoordinate(input, result_ln);
|
||||
|
||||
// TODO: reactivate
|
||||
// BOOST_CHECK_EQUAL(result_ln, result);
|
||||
}
|
||||
|
||||
void TestRectangle(double width, double height, double center_lat, double center_lon)
|
||||
{
|
||||
FixedPointCoordinate center(center_lat * COORDINATE_PRECISION,
|
||||
center_lon * COORDINATE_PRECISION);
|
||||
|
||||
TestStaticRTree::RectangleT rect;
|
||||
rect.min_lat = center.lat - height / 2.0 * COORDINATE_PRECISION;
|
||||
rect.max_lat = center.lat + height / 2.0 * COORDINATE_PRECISION;
|
||||
rect.min_lon = center.lon - width / 2.0 * COORDINATE_PRECISION;
|
||||
rect.max_lon = center.lon + width / 2.0 * COORDINATE_PRECISION;
|
||||
|
||||
unsigned offset = 5 * COORDINATE_PRECISION;
|
||||
FixedPointCoordinate north(rect.max_lat + offset, center.lon);
|
||||
FixedPointCoordinate south(rect.min_lat - offset, center.lon);
|
||||
FixedPointCoordinate west(center.lat, rect.min_lon - offset);
|
||||
FixedPointCoordinate east(center.lat, rect.max_lon + offset);
|
||||
FixedPointCoordinate north_east(rect.max_lat + offset, rect.max_lon + offset);
|
||||
FixedPointCoordinate north_west(rect.max_lat + offset, rect.min_lon - offset);
|
||||
FixedPointCoordinate south_east(rect.min_lat - offset, rect.max_lon + offset);
|
||||
FixedPointCoordinate south_west(rect.min_lat - offset, rect.min_lon - offset);
|
||||
|
||||
/* Distance to line segments of rectangle */
|
||||
BOOST_CHECK_EQUAL(rect.GetMinDist(north),
|
||||
FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
north, FixedPointCoordinate(rect.max_lat, north.lon)));
|
||||
BOOST_CHECK_EQUAL(rect.GetMinDist(south),
|
||||
FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
south, FixedPointCoordinate(rect.min_lat, south.lon)));
|
||||
BOOST_CHECK_EQUAL(rect.GetMinDist(west),
|
||||
FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
west, FixedPointCoordinate(west.lat, rect.min_lon)));
|
||||
BOOST_CHECK_EQUAL(rect.GetMinDist(east),
|
||||
FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
east, FixedPointCoordinate(east.lat, rect.max_lon)));
|
||||
|
||||
/* Distance to corner points */
|
||||
BOOST_CHECK_EQUAL(rect.GetMinDist(north_east),
|
||||
FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
north_east, FixedPointCoordinate(rect.max_lat, rect.max_lon)));
|
||||
BOOST_CHECK_EQUAL(rect.GetMinDist(north_west),
|
||||
FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
north_west, FixedPointCoordinate(rect.max_lat, rect.min_lon)));
|
||||
BOOST_CHECK_EQUAL(rect.GetMinDist(south_east),
|
||||
FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
south_east, FixedPointCoordinate(rect.min_lat, rect.max_lon)));
|
||||
BOOST_CHECK_EQUAL(rect.GetMinDist(south_west),
|
||||
FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
south_west, FixedPointCoordinate(rect.min_lat, rect.min_lon)));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(rectangle_test)
|
||||
{
|
||||
TestRectangle(10, 10, 5, 5);
|
||||
TestRectangle(10, 10, -5, 5);
|
||||
TestRectangle(10, 10, 5, -5);
|
||||
TestRectangle(10, 10, -5, -5);
|
||||
TestRectangle(10, 10, 0, 0);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#define BOOST_TEST_MODULE datastructure tests
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
/*
|
||||
* This file will contain an automatically generated main function.
|
||||
*/
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef AZIMUTH_H
|
||||
#define AZIMUTH_H
|
||||
|
||||
#include <string>
|
||||
|
||||
struct Azimuth
|
||||
{
|
||||
static std::string Get(const double heading)
|
||||
{
|
||||
if (heading <= 202.5)
|
||||
{
|
||||
if (heading >= 0 && heading <= 22.5)
|
||||
{
|
||||
return "N";
|
||||
}
|
||||
if (heading > 22.5 && heading <= 67.5)
|
||||
{
|
||||
return "NE";
|
||||
}
|
||||
if (heading > 67.5 && heading <= 112.5)
|
||||
{
|
||||
return "E";
|
||||
}
|
||||
if (heading > 112.5 && heading <= 157.5)
|
||||
{
|
||||
return "SE";
|
||||
}
|
||||
return "S";
|
||||
}
|
||||
if (heading > 202.5 && heading <= 247.5)
|
||||
{
|
||||
return "SW";
|
||||
}
|
||||
if (heading > 247.5 && heading <= 292.5)
|
||||
{
|
||||
return "W";
|
||||
}
|
||||
if (heading > 292.5 && heading <= 337.5)
|
||||
{
|
||||
return "NW";
|
||||
}
|
||||
return "N";
|
||||
}
|
||||
};
|
||||
|
||||
#endif // AZIMUTH_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -28,12 +28,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#ifndef BOOST_FILE_SYSTEM_FIX_H
|
||||
#define BOOST_FILE_SYSTEM_FIX_H
|
||||
|
||||
#include "OSRMException.h"
|
||||
#include "SimpleLogger.h"
|
||||
#include "osrm_exception.hpp"
|
||||
|
||||
#include <boost/any.hpp>
|
||||
// #include <boost/any.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
// #include <boost/program_options.hpp>
|
||||
|
||||
// This is one big workaround for latest boost renaming woes.
|
||||
|
||||
@@ -60,12 +59,10 @@ namespace filesystem
|
||||
// boost::program_options::validators::check_first_occurrence(v);
|
||||
// const std::string & input_string =
|
||||
// boost::program_options::validators::get_single_string(values);
|
||||
// // SimpleLogger().Write() << "validator called for " << input_string;
|
||||
// // SimpleLogger().Write() << "validator called for " << input_string;
|
||||
// if(boost::filesystem::is_regular_file(input_string)) {
|
||||
// v = boost::any(boost::filesystem::path(input_string));
|
||||
// } else {
|
||||
// throw OSRMException(input_string + " not found");
|
||||
// throw osrm::exception(input_string + " not found");
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -121,7 +118,7 @@ portable_canonical(const boost::filesystem::path &relative_path,
|
||||
inline path temp_directory_path()
|
||||
{
|
||||
char *buffer;
|
||||
buffer = tmpnam(NULL);
|
||||
buffer = tmpnam(nullptr);
|
||||
|
||||
return path(buffer);
|
||||
}
|
||||
@@ -140,7 +137,7 @@ inline void AssertPathExists(const boost::filesystem::path &path)
|
||||
{
|
||||
if (!boost::filesystem::is_regular_file(path))
|
||||
{
|
||||
throw OSRMException(path.string() + " not found.");
|
||||
throw osrm::exception(path.string() + " not found.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+13
-18
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -29,10 +29,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#define DATA_STORE_OPTIONS_H
|
||||
|
||||
#include "BoostFileSystemFix.h"
|
||||
#include "GitDescription.h"
|
||||
#include "git_sha.hpp"
|
||||
#include "IniFileUtil.h"
|
||||
#include "OSRMException.h"
|
||||
#include "SimpleLogger.h"
|
||||
#include "osrm_exception.hpp"
|
||||
#include "simple_logger.hpp"
|
||||
|
||||
#include <osrm/ServerPaths.h>
|
||||
|
||||
@@ -43,7 +43,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <string>
|
||||
|
||||
// generate boost::program_options object for the routing part
|
||||
inline bool GenerateDataStoreOptions(const int argc, const char *argv[], ServerPaths &paths, bool & springclean)
|
||||
bool GenerateDataStoreOptions(const int argc, const char *argv[], ServerPaths &paths)
|
||||
{
|
||||
// declare a group of options that will be allowed only on command line
|
||||
boost::program_options::options_description generic_options("Options");
|
||||
@@ -122,11 +122,6 @@ inline bool GenerateDataStoreOptions(const int argc, const char *argv[], ServerP
|
||||
return false;
|
||||
}
|
||||
|
||||
if (option_variables.count("springclean"))
|
||||
{
|
||||
springclean = true;
|
||||
return true;
|
||||
}
|
||||
boost::program_options::notify(option_variables);
|
||||
|
||||
const bool parameter_present = (paths.find("hsgrdata") != paths.end() &&
|
||||
@@ -226,56 +221,56 @@ inline bool GenerateDataStoreOptions(const int argc, const char *argv[], ServerP
|
||||
path_iterator = paths.find("hsgrdata");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||
{
|
||||
throw OSRMException(".hsgr file must be specified");
|
||||
throw osrm::exception(".hsgr file must be specified");
|
||||
}
|
||||
AssertPathExists(path_iterator->second);
|
||||
|
||||
path_iterator = paths.find("nodesdata");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||
{
|
||||
throw OSRMException(".nodes file must be specified");
|
||||
throw osrm::exception(".nodes file must be specified");
|
||||
}
|
||||
AssertPathExists(path_iterator->second);
|
||||
|
||||
path_iterator = paths.find("edgesdata");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||
{
|
||||
throw OSRMException(".edges file must be specified");
|
||||
throw osrm::exception(".edges file must be specified");
|
||||
}
|
||||
AssertPathExists(path_iterator->second);
|
||||
|
||||
path_iterator = paths.find("geometry");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||
{
|
||||
throw OSRMException(".geometry file must be specified");
|
||||
throw osrm::exception(".geometry file must be specified");
|
||||
}
|
||||
AssertPathExists(path_iterator->second);
|
||||
|
||||
path_iterator = paths.find("ramindex");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||
{
|
||||
throw OSRMException(".ramindex file must be specified");
|
||||
throw osrm::exception(".ramindex file must be specified");
|
||||
}
|
||||
AssertPathExists(path_iterator->second);
|
||||
|
||||
path_iterator = paths.find("fileindex");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||
{
|
||||
throw OSRMException(".fileindex file must be specified");
|
||||
throw osrm::exception(".fileindex file must be specified");
|
||||
}
|
||||
AssertPathExists(path_iterator->second);
|
||||
|
||||
path_iterator = paths.find("namesdata");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||
{
|
||||
throw OSRMException(".names file must be specified");
|
||||
throw osrm::exception(".names file must be specified");
|
||||
}
|
||||
AssertPathExists(path_iterator->second);
|
||||
|
||||
path_iterator = paths.find("timestamp");
|
||||
if (path_iterator == paths.end() || path_iterator->second.string().empty())
|
||||
{
|
||||
throw OSRMException(".timestamp file must be specified");
|
||||
throw osrm::exception(".timestamp file must be specified");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -42,7 +42,6 @@ class FingerPrint
|
||||
bool TestGraphUtil(const FingerPrint &other) const;
|
||||
bool TestPrepare(const FingerPrint &other) const;
|
||||
bool TestRTree(const FingerPrint &other) const;
|
||||
bool TestNodeInfo(const FingerPrint &other) const;
|
||||
bool TestQueryObjects(const FingerPrint &other) const;
|
||||
|
||||
private:
|
||||
|
||||
+4
-4
@@ -30,14 +30,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <cmath>
|
||||
|
||||
inline float y2lat(const float a)
|
||||
inline double y2lat(const double a)
|
||||
{
|
||||
return 180.f * static_cast<float>(M_1_PI) * (2.f * std::atan(std::exp(a * static_cast<float>(M_PI) / 180.f)) - static_cast<float>(M_PI_2));
|
||||
return 180. * M_1_PI * (2. * std::atan(std::exp(a * M_PI / 180.)) - M_PI_2);
|
||||
}
|
||||
|
||||
inline float lat2y(const float a)
|
||||
inline double lat2y(const double a)
|
||||
{
|
||||
return 180.f * static_cast<float>(M_1_PI) * std::log(std::tan(static_cast<float>(M_PI_4) + a * (static_cast<float>(M_PI) / 180.f) / 2.f));
|
||||
return 180. * M_1_PI * std::log(std::tan(M_PI_4 + a * (M_PI / 180.) / 2.));
|
||||
}
|
||||
|
||||
#endif // MERCATOR_UTIL_H
|
||||
|
||||
+103
-94
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -28,10 +28,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#ifndef PROGAM_OPTIONS_H
|
||||
#define PROGAM_OPTIONS_H
|
||||
|
||||
#include "GitDescription.h"
|
||||
#include "git_sha.hpp"
|
||||
#include "IniFileUtil.h"
|
||||
#include "OSRMException.h"
|
||||
#include "SimpleLogger.h"
|
||||
#include "osrm_exception.hpp"
|
||||
#include "simple_logger.hpp"
|
||||
|
||||
#include <osrm/ServerPaths.h>
|
||||
|
||||
@@ -45,6 +45,104 @@ const static unsigned INIT_OK_START_ENGINE = 0;
|
||||
const static unsigned INIT_OK_DO_NOT_START_ENGINE = 1;
|
||||
const static unsigned INIT_FAILED = -1;
|
||||
|
||||
inline void populate_base_path(ServerPaths &server_paths)
|
||||
{
|
||||
// populate the server_path object
|
||||
auto path_iterator = server_paths.find("base");
|
||||
|
||||
// if a base path has been set, we populate it.
|
||||
if (path_iterator != server_paths.end())
|
||||
{
|
||||
const std::string base_string = path_iterator->second.string();
|
||||
SimpleLogger().Write() << "populating base path: " << base_string;
|
||||
|
||||
server_paths["hsgrdata"] = base_string + ".hsgr";
|
||||
BOOST_ASSERT(server_paths.find("hsgrdata") != server_paths.end());
|
||||
server_paths["nodesdata"] = base_string + ".nodes";
|
||||
BOOST_ASSERT(server_paths.find("nodesdata") != server_paths.end());
|
||||
server_paths["edgesdata"] = base_string + ".edges";
|
||||
BOOST_ASSERT(server_paths.find("edgesdata") != server_paths.end());
|
||||
server_paths["geometries"] = base_string + ".geometry";
|
||||
BOOST_ASSERT(server_paths.find("geometries") != server_paths.end());
|
||||
server_paths["ramindex"] = base_string + ".ramIndex";
|
||||
BOOST_ASSERT(server_paths.find("ramindex") != server_paths.end());
|
||||
server_paths["fileindex"] = base_string + ".fileIndex";
|
||||
BOOST_ASSERT(server_paths.find("fileindex") != server_paths.end());
|
||||
server_paths["namesdata"] = base_string + ".names";
|
||||
BOOST_ASSERT(server_paths.find("namesdata") != server_paths.end());
|
||||
server_paths["timestamp"] = base_string + ".timestamp";
|
||||
BOOST_ASSERT(server_paths.find("timestamp") != server_paths.end());
|
||||
}
|
||||
|
||||
// check if files are give and whether they exist at all
|
||||
path_iterator = server_paths.find("hsgrdata");
|
||||
if (path_iterator == server_paths.end() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
if (path_iterator == server_paths.end())
|
||||
{
|
||||
SimpleLogger().Write() << "hsgrdata unset";
|
||||
}
|
||||
if (!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
SimpleLogger().Write() << "not a regular file";
|
||||
}
|
||||
|
||||
throw osrm::exception(".hsgr not found: " + path_iterator->second.string());
|
||||
}
|
||||
|
||||
path_iterator = server_paths.find("nodesdata");
|
||||
if (path_iterator == server_paths.end() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
throw osrm::exception(".nodes not found");
|
||||
}
|
||||
|
||||
path_iterator = server_paths.find("edgesdata");
|
||||
if (path_iterator == server_paths.end() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
throw osrm::exception(".edges not found");
|
||||
}
|
||||
|
||||
path_iterator = server_paths.find("geometries");
|
||||
if (path_iterator == server_paths.end() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
throw osrm::exception(".geometry not found");
|
||||
}
|
||||
|
||||
path_iterator = server_paths.find("ramindex");
|
||||
if (path_iterator == server_paths.end() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
throw osrm::exception(".ramIndex not found");
|
||||
}
|
||||
|
||||
path_iterator = server_paths.find("fileindex");
|
||||
if (path_iterator == server_paths.end() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
throw osrm::exception(".fileIndex not found");
|
||||
}
|
||||
|
||||
path_iterator = server_paths.find("namesdata");
|
||||
if (path_iterator == server_paths.end() ||
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
throw osrm::exception(".namesIndex not found");
|
||||
}
|
||||
|
||||
SimpleLogger().Write() << "HSGR file:\t" << server_paths["hsgrdata"];
|
||||
SimpleLogger().Write(logDEBUG) << "Nodes file:\t" << server_paths["nodesdata"];
|
||||
SimpleLogger().Write(logDEBUG) << "Edges file:\t" << server_paths["edgesdata"];
|
||||
SimpleLogger().Write(logDEBUG) << "Geometry file:\t" << server_paths["geometries"];
|
||||
SimpleLogger().Write(logDEBUG) << "RAM file:\t" << server_paths["ramindex"];
|
||||
SimpleLogger().Write(logDEBUG) << "Index file:\t" << server_paths["fileindex"];
|
||||
SimpleLogger().Write(logDEBUG) << "Names file:\t" << server_paths["namesdata"];
|
||||
SimpleLogger().Write(logDEBUG) << "Timestamp file:\t" << server_paths["timestamp"];
|
||||
}
|
||||
|
||||
// generate boost::program_options object for the routing part
|
||||
inline unsigned GenerateServerProgramOptions(const int argc,
|
||||
const char *argv[],
|
||||
@@ -55,7 +153,6 @@ inline unsigned GenerateServerProgramOptions(const int argc,
|
||||
bool &use_shared_memory,
|
||||
bool &trial)
|
||||
{
|
||||
|
||||
// declare a group of options that will be allowed only on command line
|
||||
boost::program_options::options_description generic_options("Options");
|
||||
generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")(
|
||||
@@ -164,99 +261,11 @@ inline unsigned GenerateServerProgramOptions(const int argc,
|
||||
|
||||
if (1 > requested_num_threads)
|
||||
{
|
||||
throw OSRMException("Number of threads must be a positive number");
|
||||
throw osrm::exception("Number of threads must be a positive number");
|
||||
}
|
||||
|
||||
if (!use_shared_memory && option_variables.count("base"))
|
||||
{
|
||||
path_iterator = paths.find("base");
|
||||
BOOST_ASSERT(paths.end() != path_iterator);
|
||||
std::string base_string = path_iterator->second.string();
|
||||
|
||||
path_iterator = paths.find("hsgrdata");
|
||||
if (path_iterator != paths.end() &&
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
path_iterator->second = base_string + ".hsgr";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw OSRMException(base_string + ".hsgr not found");
|
||||
}
|
||||
|
||||
path_iterator = paths.find("nodesdata");
|
||||
if (path_iterator != paths.end() &&
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
path_iterator->second = base_string + ".nodes";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw OSRMException(base_string + ".nodes not found");
|
||||
}
|
||||
|
||||
path_iterator = paths.find("edgesdata");
|
||||
if (path_iterator != paths.end() &&
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
path_iterator->second = base_string + ".edges";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw OSRMException(base_string + ".edges not found");
|
||||
}
|
||||
|
||||
path_iterator = paths.find("geometries");
|
||||
if (path_iterator != paths.end() &&
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
path_iterator->second = base_string + ".geometry";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw OSRMException(base_string + ".geometry not found");
|
||||
}
|
||||
|
||||
path_iterator = paths.find("ramindex");
|
||||
if (path_iterator != paths.end() &&
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
path_iterator->second = base_string + ".ramIndex";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw OSRMException(base_string + ".ramIndex not found");
|
||||
}
|
||||
|
||||
path_iterator = paths.find("fileindex");
|
||||
if (path_iterator != paths.end() &&
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
path_iterator->second = base_string + ".fileIndex";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw OSRMException(base_string + ".fileIndex not found");
|
||||
}
|
||||
|
||||
path_iterator = paths.find("namesdata");
|
||||
if (path_iterator != paths.end() &&
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
path_iterator->second = base_string + ".names";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw OSRMException(base_string + ".namesIndex not found");
|
||||
}
|
||||
|
||||
path_iterator = paths.find("timestamp");
|
||||
if (path_iterator != paths.end() &&
|
||||
!boost::filesystem::is_regular_file(path_iterator->second))
|
||||
{
|
||||
path_iterator->second = base_string + ".timestamp";
|
||||
}
|
||||
|
||||
return INIT_OK_START_ENGINE;
|
||||
}
|
||||
if (use_shared_memory && !option_variables.count("base"))
|
||||
|
||||
@@ -1,158 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef SIMPLE_LOGGER_H
|
||||
#define SIMPLE_LOGGER_H
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <io.h>
|
||||
#define isatty _isatty
|
||||
#define fileno _fileno
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <ostream>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
|
||||
enum LogLevel
|
||||
{ logINFO,
|
||||
logWARNING,
|
||||
logDEBUG };
|
||||
|
||||
const char COL_RESET[] = "\x1b[0m";
|
||||
const char RED[] = "\x1b[31m";
|
||||
const char GREEN[] = "\x1b[32m";
|
||||
const char YELLOW[] = "\x1b[33m";
|
||||
const char BLUE[] = "\x1b[34m";
|
||||
const char MAGENTA[] = "\x1b[35m";
|
||||
const char CYAN[] = "\x1b[36m";
|
||||
|
||||
class LogPolicy
|
||||
{
|
||||
public:
|
||||
void Unmute() { m_is_mute = false; }
|
||||
|
||||
void Mute() { m_is_mute = true; }
|
||||
|
||||
bool IsMute() const { return m_is_mute; }
|
||||
|
||||
static LogPolicy &GetInstance()
|
||||
{
|
||||
static LogPolicy runningInstance;
|
||||
return runningInstance;
|
||||
}
|
||||
|
||||
LogPolicy(const LogPolicy &) = delete;
|
||||
|
||||
private:
|
||||
LogPolicy() : m_is_mute(true) {}
|
||||
bool m_is_mute;
|
||||
};
|
||||
|
||||
class SimpleLogger
|
||||
{
|
||||
public:
|
||||
SimpleLogger() : level(logINFO) {}
|
||||
|
||||
std::mutex& get_mutex()
|
||||
{
|
||||
static std::mutex m;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
std::ostringstream &Write(LogLevel l = logINFO)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(get_mutex());
|
||||
try
|
||||
{
|
||||
level = l;
|
||||
os << "[";
|
||||
switch (level)
|
||||
{
|
||||
case logINFO:
|
||||
os << "info";
|
||||
break;
|
||||
case logWARNING:
|
||||
os << "warn";
|
||||
break;
|
||||
case logDEBUG:
|
||||
#ifndef NDEBUG
|
||||
os << "debug";
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
BOOST_ASSERT_MSG(false, "should not happen");
|
||||
break;
|
||||
}
|
||||
os << "] ";
|
||||
}
|
||||
catch (...) {}
|
||||
return os;
|
||||
}
|
||||
|
||||
virtual ~SimpleLogger()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(get_mutex());
|
||||
if (!LogPolicy::GetInstance().IsMute())
|
||||
{
|
||||
const bool is_terminal = ( 0 != isatty(fileno(stdout)) ? true : false);
|
||||
switch (level)
|
||||
{
|
||||
case logINFO:
|
||||
std::cout << os.str() << (is_terminal ? COL_RESET : "") << std::endl;
|
||||
break;
|
||||
case logWARNING:
|
||||
std::cerr << (is_terminal ? RED : "") << os.str() << (is_terminal ? COL_RESET : "")
|
||||
<< std::endl;
|
||||
break;
|
||||
case logDEBUG:
|
||||
#ifndef NDEBUG
|
||||
std::cout << (is_terminal ? YELLOW : "") << os.str()
|
||||
<< (is_terminal ? COL_RESET : "") << std::endl;
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
BOOST_ASSERT_MSG(false, "should not happen");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
LogLevel level;
|
||||
std::ostringstream os;
|
||||
};
|
||||
|
||||
#endif /* SIMPLE_LOGGER_H */
|
||||
@@ -1,318 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef STRINGUTIL_H
|
||||
#define STRINGUTIL_H
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/spirit/include/karma.hpp>
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
// precision: position after decimal point
|
||||
// length: maximum number of digits including comma and decimals
|
||||
// work with negative values to prevent overflowing when taking -value
|
||||
template <int length, int precision> static inline char *printInt(char *buffer, int value)
|
||||
{
|
||||
bool minus = true;
|
||||
if (value > 0)
|
||||
{
|
||||
minus = false;
|
||||
value = -value;
|
||||
}
|
||||
buffer += length - 1;
|
||||
for (int i = 0; i < precision; i++)
|
||||
{
|
||||
*buffer = '0' - (value % 10);
|
||||
value /= 10;
|
||||
buffer--;
|
||||
}
|
||||
*buffer = '.';
|
||||
buffer--;
|
||||
for (int i = precision + 1; i < length; i++)
|
||||
{
|
||||
*buffer = '0' - (value % 10);
|
||||
value /= 10;
|
||||
if (value == 0)
|
||||
break;
|
||||
buffer--;
|
||||
}
|
||||
if (minus)
|
||||
{
|
||||
buffer--;
|
||||
*buffer = '-';
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// convert scoped enums to integers
|
||||
template <typename Enumeration>
|
||||
auto as_integer(Enumeration const value)
|
||||
-> typename std::underlying_type<Enumeration>::type
|
||||
{
|
||||
return static_cast<typename std::underlying_type<Enumeration>::type>(value);
|
||||
}
|
||||
|
||||
static inline std::string IntToString(const int value)
|
||||
{
|
||||
std::string output;
|
||||
std::back_insert_iterator<std::string> sink(output);
|
||||
boost::spirit::karma::generate(sink, boost::spirit::karma::int_, value);
|
||||
return output;
|
||||
}
|
||||
|
||||
static inline std::string UintToString(const unsigned value)
|
||||
{
|
||||
std::string output;
|
||||
std::back_insert_iterator<std::string> sink(output);
|
||||
boost::spirit::karma::generate(sink, boost::spirit::karma::uint_, value);
|
||||
return output;
|
||||
}
|
||||
|
||||
static inline void int64ToString(const int64_t value, std::string &output)
|
||||
{
|
||||
output.clear();
|
||||
std::back_insert_iterator<std::string> sink(output);
|
||||
boost::spirit::karma::generate(sink, boost::spirit::karma::long_long, value);
|
||||
}
|
||||
|
||||
static inline int StringToInt(const std::string &input)
|
||||
{
|
||||
auto first_digit = input.begin();
|
||||
// Delete any trailing white-spaces
|
||||
while (first_digit != input.end() && std::isspace(*first_digit))
|
||||
{
|
||||
++first_digit;
|
||||
}
|
||||
int value = 0;
|
||||
boost::spirit::qi::parse(first_digit, input.end(), boost::spirit::int_, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
static inline unsigned StringToUint(const std::string &input)
|
||||
{
|
||||
auto first_digit = input.begin();
|
||||
// Delete any trailing white-spaces
|
||||
while (first_digit != input.end() && std::isspace(*first_digit))
|
||||
{
|
||||
++first_digit;
|
||||
}
|
||||
unsigned value = 0;
|
||||
boost::spirit::qi::parse(first_digit, input.end(), boost::spirit::uint_, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
static inline uint64_t StringToInt64(const std::string &input)
|
||||
{
|
||||
auto first_digit = input.begin();
|
||||
// Delete any trailing white-spaces
|
||||
while (first_digit != input.end() && std::isspace(*first_digit))
|
||||
{
|
||||
++first_digit;
|
||||
}
|
||||
uint64_t value = 0;
|
||||
boost::spirit::qi::parse(first_digit, input.end(), boost::spirit::long_long, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
// source: http://tinodidriksen.com/2011/05/28/cpp-convert-string-to-double-speed/
|
||||
static inline double StringToDouble(const char *p)
|
||||
{
|
||||
double r = 0.0;
|
||||
bool neg = false;
|
||||
if (*p == '-')
|
||||
{
|
||||
neg = true;
|
||||
++p;
|
||||
}
|
||||
while (*p >= '0' && *p <= '9')
|
||||
{
|
||||
r = (r * 10.0) + (*p - '0');
|
||||
++p;
|
||||
}
|
||||
if (*p == '.')
|
||||
{
|
||||
double f = 0.0;
|
||||
int n = 0;
|
||||
++p;
|
||||
while (*p >= '0' && *p <= '9')
|
||||
{
|
||||
f = (f * 10.0) + (*p - '0');
|
||||
++p;
|
||||
++n;
|
||||
}
|
||||
r += f / std::pow(10.0, n);
|
||||
}
|
||||
if (neg)
|
||||
{
|
||||
r = -r;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct scientific_policy : boost::spirit::karma::real_policies<T>
|
||||
{
|
||||
// we want the numbers always to be in fixed format
|
||||
static int floatfield(T n) { return boost::spirit::karma::real_policies<T>::fmtflags::fixed; }
|
||||
static unsigned int precision(T) { return 6; }
|
||||
};
|
||||
typedef
|
||||
boost::spirit::karma::real_generator<double, scientific_policy<double> >
|
||||
science_type;
|
||||
|
||||
static inline std::string FixedDoubleToString(const double value)
|
||||
{
|
||||
std::string output;
|
||||
std::back_insert_iterator<std::string> sink(output);
|
||||
boost::spirit::karma::generate(sink, science_type(), value);
|
||||
if (output.size() >= 2 && output[output.size()-2] == '.' && output[output.size()-1] == '0')
|
||||
{
|
||||
output.resize(output.size()-2);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
static inline std::string DoubleToString(const double value)
|
||||
{
|
||||
std::string output;
|
||||
std::back_insert_iterator<std::string> sink(output);
|
||||
boost::spirit::karma::generate(sink, value);
|
||||
return output;
|
||||
}
|
||||
|
||||
static inline void doubleToStringWithTwoDigitsBehindComma(const double value, std::string &output)
|
||||
{
|
||||
// The largest 32-bit integer is 4294967295, that is 10 chars
|
||||
// On the safe side, add 1 for sign, and 1 for trailing zero
|
||||
char buffer[12];
|
||||
sprintf(buffer, "%g", value);
|
||||
output = buffer;
|
||||
}
|
||||
|
||||
inline void replaceAll(std::string &s, const std::string &sub, const std::string &other)
|
||||
{
|
||||
boost::replace_all(s, sub, other);
|
||||
}
|
||||
|
||||
inline std::string EscapeJSONString(const std::string &input)
|
||||
{
|
||||
std::string output;
|
||||
output.reserve(input.size());
|
||||
for (auto iter = input.begin(); iter != input.end(); ++iter)
|
||||
{
|
||||
switch (iter[0])
|
||||
{
|
||||
case '\\':
|
||||
output += "\\\\";
|
||||
break;
|
||||
case '"':
|
||||
output += "\\\"";
|
||||
break;
|
||||
case '/':
|
||||
output += "\\/";
|
||||
break;
|
||||
case '\b':
|
||||
output += "\\b";
|
||||
break;
|
||||
case '\f':
|
||||
output += "\\f";
|
||||
break;
|
||||
case '\n':
|
||||
output += "\\n";
|
||||
break;
|
||||
case '\r':
|
||||
output += "\\r";
|
||||
break;
|
||||
case '\t':
|
||||
output += "\\t";
|
||||
break;
|
||||
default:
|
||||
output += *iter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
static std::string originals[] = {"&", "\"", "<", ">", "'", "[", "]", "\\"};
|
||||
static std::string entities[] = {"&", """, "<", ">",
|
||||
"'", "&91;", "&93;", " \"};
|
||||
|
||||
inline std::size_t URIDecode(const std::string &input, std::string &output)
|
||||
{
|
||||
auto src_iter = input.begin();
|
||||
output.resize(input.size() + 1);
|
||||
std::size_t decoded_length = 0;
|
||||
for (decoded_length = 0; src_iter != input.end(); ++decoded_length)
|
||||
{
|
||||
if (src_iter[0] == '%' && src_iter[1] && src_iter[2] && isxdigit(src_iter[1]) &&
|
||||
isxdigit(src_iter[2]))
|
||||
{
|
||||
std::string::value_type a = src_iter[1];
|
||||
std::string::value_type b = src_iter[2];
|
||||
a -= src_iter[1] < 58 ? 48 : src_iter[1] < 71 ? 55 : 87;
|
||||
b -= src_iter[2] < 58 ? 48 : src_iter[2] < 71 ? 55 : 87;
|
||||
output[decoded_length] = 16 * a + b;
|
||||
src_iter += 3;
|
||||
continue;
|
||||
}
|
||||
output[decoded_length] = *src_iter++;
|
||||
}
|
||||
output.resize(decoded_length);
|
||||
return decoded_length;
|
||||
}
|
||||
|
||||
inline std::size_t URIDecodeInPlace(std::string &URI) { return URIDecode(URI, URI); }
|
||||
|
||||
inline bool StringStartsWith(const std::string &input, const std::string &prefix)
|
||||
{
|
||||
return boost::starts_with(input, prefix);
|
||||
}
|
||||
|
||||
inline std::string GetRandomString()
|
||||
{
|
||||
std::string s;
|
||||
s.resize(128);
|
||||
static const char alphanum[] = "0123456789"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
for (int i = 0; i < 127; ++i)
|
||||
{
|
||||
s[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
|
||||
}
|
||||
s[127] = 0;
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif // STRINGUTIL_H
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef TIMINGUTIL_H
|
||||
#define TIMINGUTIL_H
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#define TIMER_START(_X) auto _X##_start = std::chrono::steady_clock::now(), _X##_stop = _X##_start
|
||||
#define TIMER_STOP(_X) _X##_stop = std::chrono::steady_clock::now()
|
||||
#define TIMER_MSEC(_X) std::chrono::duration_cast<std::chrono::milliseconds>(_X##_stop - _X##_start).count()
|
||||
#define TIMER_SEC(_X) (0.001*std::chrono::duration_cast<std::chrono::milliseconds>(_X##_stop - _X##_start).count())
|
||||
#define TIMER_MIN(_X) std::chrono::duration_cast<std::chrono::minutes>(_X##_stop - _X##_start).count()
|
||||
|
||||
#endif // TIMINGUTIL_H
|
||||
@@ -25,33 +25,41 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef MACHINE_INFO_H
|
||||
#define MACHINE_INFO_H
|
||||
#include "bearing.hpp"
|
||||
|
||||
enum Endianness
|
||||
{ LittleEndian = 1,
|
||||
BigEndian = 2 };
|
||||
|
||||
// Function is optimized to a single 'mov eax,1' on GCC, clang and icc using -O3
|
||||
inline Endianness GetMachineEndianness()
|
||||
std::string Bearing::Get(const double heading)
|
||||
{
|
||||
int i(1);
|
||||
char *p = (char *)&i;
|
||||
if (1 == p[0])
|
||||
if (heading <= 202.5)
|
||||
{
|
||||
return LittleEndian;
|
||||
if (heading >= 0. && heading <= 22.5)
|
||||
{
|
||||
return "N";
|
||||
}
|
||||
if (heading > 22.5 && heading <= 67.5)
|
||||
{
|
||||
return "NE";
|
||||
}
|
||||
if (heading > 67.5 && heading <= 112.5)
|
||||
{
|
||||
return "E";
|
||||
}
|
||||
if (heading > 112.5 && heading <= 157.5)
|
||||
{
|
||||
return "SE";
|
||||
}
|
||||
return "S";
|
||||
}
|
||||
return BigEndian;
|
||||
}
|
||||
|
||||
// Reverses Network Byte Order into something usable, compiles down to a bswap-mov combination
|
||||
inline unsigned SwapEndian(unsigned x)
|
||||
{
|
||||
if (GetMachineEndianness() == LittleEndian)
|
||||
if (heading > 202.5 && heading <= 247.5)
|
||||
{
|
||||
return ((x >> 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | (x << 24));
|
||||
return "SW";
|
||||
}
|
||||
return x;
|
||||
if (heading > 247.5 && heading <= 292.5)
|
||||
{
|
||||
return "W";
|
||||
}
|
||||
if (heading > 292.5 && heading <= 337.5)
|
||||
{
|
||||
return "NW";
|
||||
}
|
||||
return "N";
|
||||
}
|
||||
|
||||
#endif // MACHINE_INFO_H
|
||||
@@ -25,22 +25,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef OSRM_EXCEPTION_H
|
||||
#define OSRM_EXCEPTION_H
|
||||
#ifndef BEARING_HPP_
|
||||
#define BEARING_HPP_
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
class OSRMException : public std::exception
|
||||
struct Bearing
|
||||
{
|
||||
public:
|
||||
explicit OSRMException(const char *message) : message(message) {}
|
||||
explicit OSRMException(const std::string &message) : message(message) {}
|
||||
virtual ~OSRMException() throw() {}
|
||||
|
||||
private:
|
||||
virtual const char *what() const throw() { return message.c_str(); }
|
||||
const std::string message;
|
||||
static std::string Get(const double heading);
|
||||
};
|
||||
|
||||
#endif /* OSRM_EXCEPTION_H */
|
||||
#endif // BEARING_HPP_
|
||||
+188
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef CAST_HPP
|
||||
#define CAST_HPP
|
||||
|
||||
#include <boost/spirit/include/karma.hpp>
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
struct cast
|
||||
{
|
||||
// convert scoped enums to integers
|
||||
template <typename Enumeration>
|
||||
static auto enum_to_underlying(Enumeration const value) -> typename std::underlying_type<Enumeration>::type
|
||||
{
|
||||
return static_cast<typename std::underlying_type<Enumeration>::type>(value);
|
||||
}
|
||||
|
||||
template <typename Number>
|
||||
static typename std::enable_if<std::is_integral<Number>::value, std::string>::type
|
||||
integral_to_string(const Number value)
|
||||
{
|
||||
std::string output;
|
||||
std::back_insert_iterator<std::string> sink(output);
|
||||
|
||||
if (8 == sizeof(Number))
|
||||
{
|
||||
boost::spirit::karma::generate(sink, boost::spirit::karma::long_long, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (std::is_signed<Number>::value)
|
||||
{
|
||||
boost::spirit::karma::generate(sink, boost::spirit::karma::int_, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
boost::spirit::karma::generate(sink, boost::spirit::karma::uint_, value);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
static int string_to_int(const std::string &input)
|
||||
{
|
||||
auto first_digit = input.begin();
|
||||
// Delete any trailing white-spaces
|
||||
while (first_digit != input.end() && std::isspace(*first_digit))
|
||||
{
|
||||
++first_digit;
|
||||
}
|
||||
int value = 0;
|
||||
boost::spirit::qi::parse(first_digit, input.end(), boost::spirit::int_, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
static unsigned string_to_uint(const std::string &input)
|
||||
{
|
||||
auto first_digit = input.begin();
|
||||
// Delete any trailing white-spaces
|
||||
while (first_digit != input.end() && (std::isspace(*first_digit) || '-' == *first_digit))
|
||||
{
|
||||
++first_digit;
|
||||
}
|
||||
unsigned value = 0;
|
||||
boost::spirit::qi::parse(first_digit, input.end(), boost::spirit::uint_, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
static uint64_t string_to_uint64(const std::string &input)
|
||||
{
|
||||
auto first_digit = input.begin();
|
||||
// Delete any trailing white-spaces
|
||||
while (first_digit != input.end() && std::isspace(*first_digit))
|
||||
{
|
||||
++first_digit;
|
||||
}
|
||||
uint64_t value = 0;
|
||||
boost::spirit::qi::parse(first_digit, input.end(), boost::spirit::long_long, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
// source: http://tinodidriksen.com/2011/05/28/cpp-convert-string-to-double-speed/
|
||||
static double string_to_double(const char *p)
|
||||
{
|
||||
double r = 0.0;
|
||||
bool neg = false;
|
||||
if (*p == '-')
|
||||
{
|
||||
neg = true;
|
||||
++p;
|
||||
}
|
||||
while (*p >= '0' && *p <= '9')
|
||||
{
|
||||
r = (r * 10.0) + (*p - '0');
|
||||
++p;
|
||||
}
|
||||
if (*p == '.')
|
||||
{
|
||||
double f = 0.0;
|
||||
int n = 0;
|
||||
++p;
|
||||
while (*p >= '0' && *p <= '9')
|
||||
{
|
||||
f = (f * 10.0) + (*p - '0');
|
||||
++p;
|
||||
++n;
|
||||
}
|
||||
r += f / std::pow(10.0, n);
|
||||
}
|
||||
if (neg)
|
||||
{
|
||||
r = -r;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
template <typename T> struct scientific_policy : boost::spirit::karma::real_policies<T>
|
||||
{
|
||||
// we want the numbers always to be in fixed format
|
||||
static int floatfield(T)
|
||||
{
|
||||
return boost::spirit::karma::real_policies<T>::fmtflags::fixed;
|
||||
}
|
||||
static unsigned int precision(T) { return 6; }
|
||||
};
|
||||
typedef boost::spirit::karma::real_generator<double, scientific_policy<double>> science_type;
|
||||
|
||||
static std::string double_fixed_to_string(const double value)
|
||||
{
|
||||
std::string output;
|
||||
std::back_insert_iterator<std::string> sink(output);
|
||||
boost::spirit::karma::generate(sink, science_type(), value);
|
||||
if (output.size() >= 2 && output[output.size() - 2] == '.' &&
|
||||
output[output.size() - 1] == '0')
|
||||
{
|
||||
output.resize(output.size() - 2);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
static std::string double_to_string(const double value)
|
||||
{
|
||||
std::string output;
|
||||
std::back_insert_iterator<std::string> sink(output);
|
||||
boost::spirit::karma::generate(sink, value);
|
||||
return output;
|
||||
}
|
||||
|
||||
static void double_with_two_digits_to_string(const double value,
|
||||
std::string &output)
|
||||
{
|
||||
// The largest 32-bit integer is 4294967295, that is 10 chars
|
||||
// On the safe side, add 1 for sign, and 1 for trailing zero
|
||||
char buffer[12];
|
||||
sprintf(buffer, "%g", value);
|
||||
output = buffer;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CAST_HPP
|
||||
@@ -25,33 +25,27 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef COMPUTE_ANGLE_H
|
||||
#define COMPUTE_ANGLE_H
|
||||
#include "compute_angle.hpp"
|
||||
|
||||
#include "TrigonometryTables.h"
|
||||
#include "../Util/MercatorUtil.h"
|
||||
#include <osrm/Coordinate.h>
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <cmath>
|
||||
|
||||
/* Get angle of line segment (A,C)->(C,B), atan2 magic, formerly cosine theorem*/
|
||||
template <class CoordinateT>
|
||||
inline static double GetAngleBetweenThreeFixedPointCoordinates(const CoordinateT &A,
|
||||
const CoordinateT &C,
|
||||
const CoordinateT &B)
|
||||
double ComputeAngle::OfThreeFixedPointCoordinates(const FixedPointCoordinate &A,
|
||||
const FixedPointCoordinate &C,
|
||||
const FixedPointCoordinate &B)
|
||||
{
|
||||
const double v1x = (A.lon - C.lon) / COORDINATE_PRECISION;
|
||||
const double v1y = lat2y(A.lat / COORDINATE_PRECISION) - lat2y(C.lat / COORDINATE_PRECISION);
|
||||
const double v2x = (B.lon - C.lon) / COORDINATE_PRECISION;
|
||||
const double v2y = lat2y(B.lat / COORDINATE_PRECISION) - lat2y(C.lat / COORDINATE_PRECISION);
|
||||
|
||||
double angle = (atan2_lookup(v2y, v2x) - atan2_lookup(v1y, v1x)) * 180 / M_PI;
|
||||
while (angle < 0)
|
||||
double angle = (atan2_lookup(v2y, v2x) - atan2_lookup(v1y, v1x)) * 180. / M_PI;
|
||||
while (angle < 0.)
|
||||
{
|
||||
angle += 360;
|
||||
angle += 360.;
|
||||
}
|
||||
return angle;
|
||||
}
|
||||
|
||||
#endif // COMPUTE_ANGLE_H
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef COMPUTE_ANGLE_HPP
|
||||
#define COMPUTE_ANGLE_HPP
|
||||
|
||||
struct FixedPointCoordinate;
|
||||
struct NodeInfo;
|
||||
|
||||
struct ComputeAngle
|
||||
{
|
||||
/* Get angle of line segment (A,C)->(C,B), atan2 magic, formerly cosine theorem*/
|
||||
static double OfThreeFixedPointCoordinates(const FixedPointCoordinate &A,
|
||||
const FixedPointCoordinate &C,
|
||||
const FixedPointCoordinate &B);
|
||||
};
|
||||
#endif // COMPUTE_ANGLE_HPP
|
||||
@@ -25,47 +25,58 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef CONTAINERUTILS_H_
|
||||
#define CONTAINERUTILS_H_
|
||||
#ifndef CONTAINER_HPP_
|
||||
#define CONTAINER_HPP_
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <vector>
|
||||
|
||||
template <typename T> inline void sort_unique_resize(std::vector<T> &vector)
|
||||
namespace osrm
|
||||
{
|
||||
template <typename T> void sort_unique_resize(std::vector<T> &vector)
|
||||
{
|
||||
std::sort(vector.begin(), vector.end());
|
||||
const auto number_of_unique_elements = std::unique(vector.begin(), vector.end()) - vector.begin();
|
||||
vector.resize(number_of_unique_elements);
|
||||
}
|
||||
|
||||
template <typename T> inline void sort_unique_resize_shrink_vector(std::vector<T> &vector)
|
||||
{
|
||||
sort_unique_resize(vector);
|
||||
std::vector<T>().swap(vector);
|
||||
}
|
||||
// template <typename T> inline void sort_unique_resize_shrink_vector(std::vector<T> &vector)
|
||||
// {
|
||||
// sort_unique_resize(vector);
|
||||
// vector.shrink_to_fit();
|
||||
// }
|
||||
|
||||
template <typename T> inline void remove_consecutive_duplicates_from_vector(std::vector<T> &vector)
|
||||
{
|
||||
const auto number_of_unique_elements = std::unique(vector.begin(), vector.end()) - vector.begin();
|
||||
vector.resize(number_of_unique_elements);
|
||||
}
|
||||
// template <typename T> inline void remove_consecutive_duplicates_from_vector(std::vector<T> &vector)
|
||||
// {
|
||||
// const auto number_of_unique_elements = std::unique(vector.begin(), vector.end()) - vector.begin();
|
||||
// vector.resize(number_of_unique_elements);
|
||||
// }
|
||||
|
||||
template <typename FwdIter, typename Func>
|
||||
Func for_each_pair(FwdIter iter_begin, FwdIter iter_end, Func func)
|
||||
template <typename ForwardIterator, typename Function>
|
||||
Function for_each_pair(ForwardIterator begin, ForwardIterator end, Function function)
|
||||
{
|
||||
if (iter_begin == iter_end)
|
||||
if (begin == end)
|
||||
{
|
||||
return func;
|
||||
return function;
|
||||
}
|
||||
|
||||
FwdIter iter_next = iter_begin;
|
||||
++iter_next;
|
||||
auto next = begin;
|
||||
next = std::next(next);
|
||||
|
||||
for (; iter_next != iter_end; ++iter_begin, ++iter_next)
|
||||
while (next != end)
|
||||
{
|
||||
func(*iter_begin, *iter_next);
|
||||
function(*begin, *next);
|
||||
begin = std::next(begin); next = std::next(next);
|
||||
}
|
||||
return func;
|
||||
return function;
|
||||
}
|
||||
|
||||
#endif /* CONTAINERUTILS_H_ */
|
||||
template <class ContainerT, typename Function>
|
||||
Function for_each_pair(ContainerT &container, Function function)
|
||||
{
|
||||
return for_each_pair(std::begin(container), std::end(container), function);
|
||||
}
|
||||
|
||||
}
|
||||
#endif /* CONTAINER_HPP_ */
|
||||
@@ -27,12 +27,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "FingerPrint.h"
|
||||
|
||||
#include "OSRMException.h"
|
||||
#include "osrm_exception.hpp"
|
||||
|
||||
#include <boost/uuid/name_generator.hpp>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
@@ -47,8 +45,7 @@ FingerPrint::FingerPrint() : magic_number(1297240911)
|
||||
md5_prepare[32] = md5_tree[32] = md5_graph[32] = md5_objects[32] = '\0';
|
||||
|
||||
boost::uuids::name_generator gen(named_uuid);
|
||||
std::string temp_string(__DATE__);
|
||||
temp_string += __TIME__;
|
||||
std::string temp_string;
|
||||
|
||||
std::memcpy(md5_prepare, MD5PREPARE, strlen(MD5PREPARE));
|
||||
temp_string += md5_prepare;
|
||||
@@ -73,7 +70,7 @@ bool FingerPrint::TestGraphUtil(const FingerPrint &other) const
|
||||
{
|
||||
if (!other.IsMagicNumberOK())
|
||||
{
|
||||
throw OSRMException("hsgr input file misses magic number. Check or reprocess the file");
|
||||
throw osrm::exception("hsgr input file misses magic number. Check or reprocess the file");
|
||||
}
|
||||
return std::equal(md5_graph, md5_graph + 32, other.md5_graph);
|
||||
}
|
||||
@@ -82,7 +79,7 @@ bool FingerPrint::TestPrepare(const FingerPrint &other) const
|
||||
{
|
||||
if (!other.IsMagicNumberOK())
|
||||
{
|
||||
throw OSRMException("osrm input file misses magic number. Check or reprocess the file");
|
||||
throw osrm::exception("osrm input file misses magic number. Check or reprocess the file");
|
||||
}
|
||||
return std::equal(md5_prepare, md5_prepare + 32, other.md5_prepare);
|
||||
}
|
||||
@@ -91,7 +88,7 @@ bool FingerPrint::TestRTree(const FingerPrint &other) const
|
||||
{
|
||||
if (!other.IsMagicNumberOK())
|
||||
{
|
||||
throw OSRMException("r-tree input file misses magic number. Check or reprocess the file");
|
||||
throw osrm::exception("r-tree input file misses magic number. Check or reprocess the file");
|
||||
}
|
||||
return std::equal(md5_tree, md5_tree + 32, other.md5_tree);
|
||||
}
|
||||
@@ -100,7 +97,7 @@ bool FingerPrint::TestQueryObjects(const FingerPrint &other) const
|
||||
{
|
||||
if (!other.IsMagicNumberOK())
|
||||
{
|
||||
throw OSRMException("missing magic number. Check or reprocess the file");
|
||||
throw osrm::exception("missing magic number. Check or reprocess the file");
|
||||
}
|
||||
return std::equal(md5_objects, md5_objects + 32, other.md5_objects);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef FLOATING_POINT_HPP
|
||||
#define FLOATING_POINT_HPP
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
template <typename FloatT> bool epsilon_compare(const FloatT number1, const FloatT number2)
|
||||
{
|
||||
static_assert(std::is_floating_point<FloatT>::value, "type must be floating point");
|
||||
return (std::abs(number1 - number2) < std::numeric_limits<FloatT>::epsilon());
|
||||
}
|
||||
}
|
||||
|
||||
#endif // FLOATING_POINT_HPP
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -25,5 +25,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "git_sha.hpp"
|
||||
|
||||
#define GIT_DESCRIPTION "${GIT_DESCRIPTION}"
|
||||
char g_GIT_DESCRIPTION[] = GIT_DESCRIPTION;
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -25,9 +25,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef GIT_DESCRIPTION_H
|
||||
#define GIT_DESCRIPTION_H
|
||||
#ifndef GIT_SHA_HPP
|
||||
#define GIT_SHA_HPP
|
||||
|
||||
extern char g_GIT_DESCRIPTION[];
|
||||
|
||||
#endif //GIT_DESCRIPTION_H
|
||||
#endif //GIT_SHA_HPP
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -28,12 +28,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#ifndef GRAPHLOADER_H
|
||||
#define GRAPHLOADER_H
|
||||
|
||||
#include "OSRMException.h"
|
||||
#include "../DataStructures/ImportNode.h"
|
||||
#include "../DataStructures/ImportEdge.h"
|
||||
#include "../DataStructures/QueryNode.h"
|
||||
#include "../DataStructures/Restriction.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
#include "osrm_exception.hpp"
|
||||
#include "../data_structures/external_memory_node.hpp"
|
||||
#include "../data_structures/import_edge.hpp"
|
||||
#include "../data_structures/query_node.hpp"
|
||||
#include "../data_structures/restriction.hpp"
|
||||
#include "../Util/simple_logger.hpp"
|
||||
#include "../Util/FingerPrint.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
@@ -57,7 +57,7 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
|
||||
std::vector<EdgeT> &edge_list,
|
||||
std::vector<NodeID> &barrier_node_list,
|
||||
std::vector<NodeID> &traffic_light_node_list,
|
||||
std::vector<NodeInfo> *int_to_ext_node_id_map,
|
||||
std::vector<QueryNode> *int_to_ext_node_id_map,
|
||||
std::vector<TurnRestriction> &restriction_list)
|
||||
{
|
||||
const FingerPrint fingerprint_orig;
|
||||
@@ -70,23 +70,23 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
|
||||
"Reprocess to get rid of this warning.";
|
||||
}
|
||||
|
||||
NodeID n, source, target;
|
||||
EdgeID m;
|
||||
short dir; // direction (0 = open, 1 = forward, 2+ = open)
|
||||
std::unordered_map<NodeID, NodeID> ext_to_int_id_map;
|
||||
|
||||
NodeID n;
|
||||
input_stream.read((char *)&n, sizeof(NodeID));
|
||||
SimpleLogger().Write() << "Importing n = " << n << " nodes ";
|
||||
|
||||
ExternalMemoryNode current_node;
|
||||
for (NodeID i = 0; i < n; ++i)
|
||||
{
|
||||
input_stream.read((char *)¤t_node, sizeof(ExternalMemoryNode));
|
||||
int_to_ext_node_id_map->emplace_back(current_node.lat, current_node.lon, current_node.node_id);
|
||||
ext_to_int_id_map.emplace(current_node.node_id, i);
|
||||
if (current_node.bollard)
|
||||
if (current_node.barrier)
|
||||
{
|
||||
barrier_node_list.emplace_back(i);
|
||||
}
|
||||
if (current_node.trafficLight)
|
||||
if (current_node.traffic_lights)
|
||||
{
|
||||
traffic_light_node_list.emplace_back(i);
|
||||
}
|
||||
@@ -95,41 +95,47 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
|
||||
// tighten vector sizes
|
||||
barrier_node_list.shrink_to_fit();
|
||||
traffic_light_node_list.shrink_to_fit();
|
||||
input_stream.read((char *)&m, sizeof(unsigned));
|
||||
SimpleLogger().Write() << " and " << m << " edges ";
|
||||
|
||||
// renumber nodes in turn restrictions
|
||||
for (TurnRestriction ¤t_restriction : restriction_list)
|
||||
{
|
||||
auto internal_id_iter = ext_to_int_id_map.find(current_restriction.fromNode);
|
||||
auto internal_id_iter = ext_to_int_id_map.find(current_restriction.from.node);
|
||||
if (internal_id_iter == ext_to_int_id_map.end())
|
||||
{
|
||||
SimpleLogger().Write(logDEBUG) << "Unmapped from Node of restriction";
|
||||
continue;
|
||||
}
|
||||
current_restriction.fromNode = internal_id_iter->second;
|
||||
current_restriction.from.node = internal_id_iter->second;
|
||||
|
||||
internal_id_iter = ext_to_int_id_map.find(current_restriction.viaNode);
|
||||
internal_id_iter = ext_to_int_id_map.find(current_restriction.via.node);
|
||||
if (internal_id_iter == ext_to_int_id_map.end())
|
||||
{
|
||||
SimpleLogger().Write(logDEBUG) << "Unmapped via node of restriction";
|
||||
continue;
|
||||
}
|
||||
current_restriction.viaNode = internal_id_iter->second;
|
||||
current_restriction.via.node = internal_id_iter->second;
|
||||
|
||||
internal_id_iter = ext_to_int_id_map.find(current_restriction.toNode);
|
||||
internal_id_iter = ext_to_int_id_map.find(current_restriction.to.node);
|
||||
if (internal_id_iter == ext_to_int_id_map.end())
|
||||
{
|
||||
SimpleLogger().Write(logDEBUG) << "Unmapped to node of restriction";
|
||||
continue;
|
||||
}
|
||||
current_restriction.toNode = internal_id_iter->second;
|
||||
current_restriction.to.node = internal_id_iter->second;
|
||||
}
|
||||
|
||||
edge_list.reserve(m);
|
||||
EdgeWeight weight;
|
||||
short type;
|
||||
NodeID nameID;
|
||||
NodeID source, target;
|
||||
unsigned nameID;
|
||||
int length;
|
||||
bool is_roundabout, ignore_in_grid, is_access_restricted, is_contra_flow, is_split;
|
||||
short dir; // direction (0 = open, 1 = forward, 2+ = open)
|
||||
bool is_roundabout, ignore_in_grid, is_access_restricted, is_split;
|
||||
TravelMode travel_mode;
|
||||
|
||||
EdgeID m;
|
||||
input_stream.read((char *)&m, sizeof(unsigned));
|
||||
edge_list.reserve(m);
|
||||
SimpleLogger().Write() << " and " << m << " edges ";
|
||||
|
||||
for (EdgeID i = 0; i < m; ++i)
|
||||
{
|
||||
@@ -138,12 +144,11 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
|
||||
input_stream.read((char *)&length, sizeof(int));
|
||||
input_stream.read((char *)&dir, sizeof(short));
|
||||
input_stream.read((char *)&weight, sizeof(int));
|
||||
input_stream.read((char *)&type, sizeof(short));
|
||||
input_stream.read((char *)&nameID, sizeof(unsigned));
|
||||
input_stream.read((char *)&is_roundabout, sizeof(bool));
|
||||
input_stream.read((char *)&ignore_in_grid, sizeof(bool));
|
||||
input_stream.read((char *)&is_access_restricted, sizeof(bool));
|
||||
input_stream.read((char *)&is_contra_flow, sizeof(bool));
|
||||
input_stream.read((char *)&travel_mode, sizeof(TravelMode));
|
||||
input_stream.read((char *)&is_split, sizeof(bool));
|
||||
|
||||
BOOST_ASSERT_MSG(length > 0, "loaded null length edge");
|
||||
@@ -161,8 +166,6 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
|
||||
forward = false;
|
||||
}
|
||||
|
||||
BOOST_ASSERT(type >= 0);
|
||||
|
||||
// translate the external NodeIDs to internal IDs
|
||||
auto internal_id_iter = ext_to_int_id_map.find(source);
|
||||
if (ext_to_int_id_map.find(source) == ext_to_int_id_map.end())
|
||||
@@ -182,7 +185,8 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
|
||||
continue;
|
||||
}
|
||||
target = internal_id_iter->second;
|
||||
BOOST_ASSERT_MSG(source != UINT_MAX && target != UINT_MAX, "nonexisting source or target");
|
||||
BOOST_ASSERT_MSG(source != SPECIAL_NODEID && target != SPECIAL_NODEID,
|
||||
"nonexisting source or target");
|
||||
|
||||
if (source > target)
|
||||
{
|
||||
@@ -196,15 +200,16 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
|
||||
weight,
|
||||
forward,
|
||||
backward,
|
||||
type,
|
||||
is_roundabout,
|
||||
ignore_in_grid,
|
||||
is_access_restricted,
|
||||
is_contra_flow,
|
||||
travel_mode,
|
||||
is_split);
|
||||
}
|
||||
ext_to_int_id_map.clear();
|
||||
|
||||
tbb::parallel_sort(edge_list.begin(), edge_list.end());
|
||||
|
||||
for (unsigned i = 1; i < edge_list.size(); ++i)
|
||||
{
|
||||
if ((edge_list[i - 1].target == edge_list[i].target) &&
|
||||
@@ -215,22 +220,22 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
|
||||
(edge_list[i - 1].backward == edge_list[i].backward);
|
||||
const bool edge_flags_are_superset1 =
|
||||
(edge_list[i - 1].forward && edge_list[i - 1].backward) &&
|
||||
(edge_list[i].backward != edge_list[i].backward);
|
||||
(edge_list[i].forward != edge_list[i].backward);
|
||||
const bool edge_flags_are_superset_2 =
|
||||
(edge_list[i].forward && edge_list[i].backward) &&
|
||||
(edge_list[i - 1].backward != edge_list[i - 1].backward);
|
||||
(edge_list[i - 1].forward != edge_list[i - 1].backward);
|
||||
|
||||
if (edge_flags_equivalent)
|
||||
{
|
||||
edge_list[i].weight = std::min(edge_list[i - 1].weight, edge_list[i].weight);
|
||||
edge_list[i - 1].source = UINT_MAX;
|
||||
edge_list[i - 1].source = SPECIAL_NODEID;
|
||||
}
|
||||
else if (edge_flags_are_superset1)
|
||||
{
|
||||
if (edge_list[i - 1].weight <= edge_list[i].weight)
|
||||
{
|
||||
// edge i-1 is smaller and goes in both directions. Throw away the other edge
|
||||
edge_list[i].source = UINT_MAX;
|
||||
edge_list[i].source = SPECIAL_NODEID;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -252,16 +257,16 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
|
||||
else
|
||||
{
|
||||
// edge i is smaller and goes in both direction. Throw away edge i-1
|
||||
edge_list[i - 1].source = UINT_MAX;
|
||||
edge_list[i - 1].source = SPECIAL_NODEID;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const auto new_end_iter = std::remove_if(edge_list.begin(),
|
||||
edge_list.end(),
|
||||
[](const EdgeT &edge)
|
||||
{ return edge.source == SPECIAL_NODEID; });
|
||||
ext_to_int_id_map.clear();
|
||||
const auto new_end_iter = std::remove_if(edge_list.begin(), edge_list.end(), [] (const EdgeT &edge)
|
||||
{
|
||||
return edge.source == SPECIAL_NODEID ||
|
||||
edge.target == SPECIAL_NODEID;
|
||||
});
|
||||
edge_list.erase(new_end_iter, edge_list.end()); // remove excess candidates.
|
||||
edge_list.shrink_to_fit();
|
||||
SimpleLogger().Write() << "Graph loaded ok and has " << edge_list.size() << " edges";
|
||||
@@ -276,11 +281,11 @@ unsigned readHSGRFromStream(const boost::filesystem::path &hsgr_file,
|
||||
{
|
||||
if (!boost::filesystem::exists(hsgr_file))
|
||||
{
|
||||
throw OSRMException("hsgr file does not exist");
|
||||
throw osrm::exception("hsgr file does not exist");
|
||||
}
|
||||
if (0 == boost::filesystem::file_size(hsgr_file))
|
||||
{
|
||||
throw OSRMException("hsgr file is empty");
|
||||
throw osrm::exception("hsgr file is empty");
|
||||
}
|
||||
|
||||
boost::filesystem::ifstream hsgr_input_stream(hsgr_file, std::ios::binary);
|
||||
@@ -304,7 +309,7 @@ unsigned readHSGRFromStream(const boost::filesystem::path &hsgr_file,
|
||||
<< ", number_of_edges: " << number_of_edges;
|
||||
|
||||
// BOOST_ASSERT_MSG( 0 != number_of_edges, "number of edges is zero");
|
||||
node_list.resize(number_of_nodes + 1);
|
||||
node_list.resize(number_of_nodes);
|
||||
hsgr_input_stream.read((char *)&(node_list[0]), number_of_nodes * sizeof(NodeT));
|
||||
|
||||
edge_list.resize(number_of_edges);
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013,2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef INTEGER_RANGE_HPP
|
||||
#define INTEGER_RANGE_HPP
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
|
||||
template <typename Integer> class range
|
||||
{
|
||||
private:
|
||||
Integer last;
|
||||
Integer iter;
|
||||
|
||||
public:
|
||||
range(Integer start, Integer end) : last(end), iter(start)
|
||||
{
|
||||
static_assert(std::is_integral<Integer>::value, "range type must be integral");
|
||||
}
|
||||
|
||||
// Iterable functions
|
||||
const range &begin() const { return *this; }
|
||||
const range &end() const { return *this; }
|
||||
Integer front() const { return iter; }
|
||||
Integer back() const { return last - 1; }
|
||||
|
||||
// Iterator functions
|
||||
bool operator!=(const range &) const { return iter < last; }
|
||||
void operator++() { ++iter; }
|
||||
Integer operator*() const { return iter; }
|
||||
};
|
||||
|
||||
// convenience function to construct an integer range with type deduction
|
||||
template <typename Integer>
|
||||
range<Integer> irange(const Integer first,
|
||||
const Integer last,
|
||||
typename std::enable_if<std::is_integral<Integer>::value>::type * = 0)
|
||||
{
|
||||
return range<Integer>(first, last);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // INTEGER_RANGE_HPP
|
||||
@@ -25,54 +25,48 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef HASH_TABLE_H
|
||||
#define HASH_TABLE_H
|
||||
#ifndef RANGE_HPP_
|
||||
#define RANGE_HPP_
|
||||
|
||||
#include <vector>
|
||||
|
||||
template <typename Key, typename Value>
|
||||
class HashTable
|
||||
namespace osrm
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
template <typename Iterator> class Range
|
||||
{
|
||||
private:
|
||||
typedef std::pair<Key, Value> KeyValPair;
|
||||
std::vector<KeyValPair> table;
|
||||
|
||||
public:
|
||||
HashTable() {}
|
||||
Range(Iterator begin, Iterator end) : begin_(begin), end_(end) {}
|
||||
|
||||
inline void Add(Key const &key, Value const &value)
|
||||
{
|
||||
table.emplace_back(std::move(key), std::move(value));
|
||||
}
|
||||
Iterator begin() const { return begin_; }
|
||||
Iterator end() const { return end_; }
|
||||
|
||||
inline void Clear()
|
||||
{
|
||||
table.clear();
|
||||
}
|
||||
|
||||
inline const Value Find(Key const &key) const
|
||||
{
|
||||
for (const auto &key_val_pair : table)
|
||||
{
|
||||
if (key_val_pair.first == key)
|
||||
{
|
||||
return key_val_pair.second;
|
||||
}
|
||||
}
|
||||
return Value();
|
||||
}
|
||||
|
||||
inline const bool Holds(Key const &key) const
|
||||
{
|
||||
for (const auto &key_val_pair : table)
|
||||
{
|
||||
if (key_val_pair.first == key)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private:
|
||||
Iterator begin_;
|
||||
Iterator end_;
|
||||
};
|
||||
|
||||
#endif /* HASH_TABLE_H */
|
||||
// Convenience functions for template parameter inference,
|
||||
// akin to std::make_pair.
|
||||
|
||||
template <typename Iterator> Range<Iterator> range(Iterator begin, Iterator end)
|
||||
{
|
||||
return Range<Iterator>(begin, end);
|
||||
}
|
||||
|
||||
template <typename Reversable>
|
||||
Range<typename Reversable::reverse_iterator> reverse(Reversable *reversable)
|
||||
{
|
||||
return Range<typename Reversable::reverse_iterator>(reversable->rbegin(), reversable->rend());
|
||||
}
|
||||
|
||||
template <typename ConstReversable>
|
||||
Range<typename ConstReversable::const_reverse_iterator>
|
||||
const_reverse(const ConstReversable *const_reversable)
|
||||
{
|
||||
return Range<typename ConstReversable::const_reverse_iterator>(const_reversable->crbegin(),
|
||||
const_reversable->crend());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // RANGE_HPP_
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -25,79 +25,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
// based on https://svn.apache.org/repos/asf/mesos/tags/release-0.9.0-incubating-RC0/src/common/json.hpp
|
||||
// based on
|
||||
// https://svn.apache.org/repos/asf/mesos/tags/release-0.9.0-incubating-RC0/src/common/json.hpp
|
||||
|
||||
#ifndef JSON_CONTAINER_H
|
||||
#define JSON_CONTAINER_H
|
||||
#ifndef JSON_RENDERER_HPP
|
||||
#define JSON_RENDERER_HPP
|
||||
|
||||
#include "../Util/StringUtil.h"
|
||||
#include "../data_structures/json_container.hpp"
|
||||
#include "cast.hpp"
|
||||
|
||||
#include <boost/variant.hpp>
|
||||
namespace JSON {
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace JSON
|
||||
struct Renderer : mapbox::util::static_visitor<>
|
||||
{
|
||||
|
||||
struct String;
|
||||
struct Number;
|
||||
struct Object;
|
||||
struct Array;
|
||||
struct True;
|
||||
struct False;
|
||||
struct Null;
|
||||
|
||||
typedef boost::variant<boost::recursive_wrapper<String>,
|
||||
boost::recursive_wrapper<Number>,
|
||||
boost::recursive_wrapper<Object>,
|
||||
boost::recursive_wrapper<Array>,
|
||||
boost::recursive_wrapper<True>,
|
||||
boost::recursive_wrapper<False>,
|
||||
boost::recursive_wrapper<Null> > Value;
|
||||
|
||||
struct String
|
||||
{
|
||||
String() {}
|
||||
String(const char *value) : value(value) {}
|
||||
String(const std::string &value) : value(value) {}
|
||||
std::string value;
|
||||
};
|
||||
|
||||
struct Number
|
||||
{
|
||||
Number() {}
|
||||
Number(double value) : value(value) {}
|
||||
double value;
|
||||
};
|
||||
|
||||
struct Object
|
||||
{
|
||||
std::unordered_map<std::string, Value> values;
|
||||
};
|
||||
|
||||
struct Array
|
||||
{
|
||||
std::vector<Value> values;
|
||||
};
|
||||
|
||||
struct True
|
||||
{
|
||||
};
|
||||
|
||||
struct False
|
||||
{
|
||||
};
|
||||
|
||||
struct Null
|
||||
{
|
||||
};
|
||||
|
||||
struct Renderer : boost::static_visitor<>
|
||||
{
|
||||
Renderer(std::ostream &_out) : out(_out) {}
|
||||
explicit Renderer(std::ostream &_out) : out(_out) {}
|
||||
|
||||
void operator()(const String &string) const { out << "\"" << string.value << "\""; }
|
||||
|
||||
@@ -114,7 +55,7 @@ struct Renderer : boost::static_visitor<>
|
||||
while (iterator != object.values.end())
|
||||
{
|
||||
out << "\"" << (*iterator).first << "\":";
|
||||
boost::apply_visitor(Renderer(out), (*iterator).second);
|
||||
mapbox::util::apply_visitor(Renderer(out), (*iterator).second);
|
||||
if (++iterator != object.values.end())
|
||||
{
|
||||
out << ",";
|
||||
@@ -130,7 +71,7 @@ struct Renderer : boost::static_visitor<>
|
||||
iterator = array.values.begin();
|
||||
while (iterator != array.values.end())
|
||||
{
|
||||
boost::apply_visitor(Renderer(out), *iterator);
|
||||
mapbox::util::apply_visitor(Renderer(out), *iterator);
|
||||
if (++iterator != array.values.end())
|
||||
{
|
||||
out << ",";
|
||||
@@ -149,11 +90,12 @@ struct Renderer : boost::static_visitor<>
|
||||
std::ostream &out;
|
||||
};
|
||||
|
||||
struct ArrayRenderer : boost::static_visitor<>
|
||||
struct ArrayRenderer : mapbox::util::static_visitor<>
|
||||
{
|
||||
ArrayRenderer(std::vector<char> &_out) : out(_out) {}
|
||||
explicit ArrayRenderer(std::vector<char> &_out) : out(_out) {}
|
||||
|
||||
void operator()(const String &string) const {
|
||||
void operator()(const String &string) const
|
||||
{
|
||||
out.push_back('\"');
|
||||
out.insert(out.end(), string.value.begin(), string.value.end());
|
||||
out.push_back('\"');
|
||||
@@ -161,7 +103,7 @@ struct ArrayRenderer : boost::static_visitor<>
|
||||
|
||||
void operator()(const Number &number) const
|
||||
{
|
||||
const std::string number_string = FixedDoubleToString(number.value);
|
||||
const std::string number_string = cast::double_fixed_to_string(number.value);
|
||||
out.insert(out.end(), number_string.begin(), number_string.end());
|
||||
}
|
||||
|
||||
@@ -176,7 +118,7 @@ struct ArrayRenderer : boost::static_visitor<>
|
||||
out.push_back('\"');
|
||||
out.push_back(':');
|
||||
|
||||
boost::apply_visitor(ArrayRenderer(out), (*iterator).second);
|
||||
mapbox::util::apply_visitor(ArrayRenderer(out), (*iterator).second);
|
||||
if (++iterator != object.values.end())
|
||||
{
|
||||
out.push_back(',');
|
||||
@@ -192,7 +134,7 @@ struct ArrayRenderer : boost::static_visitor<>
|
||||
iterator = array.values.begin();
|
||||
while (iterator != array.values.end())
|
||||
{
|
||||
boost::apply_visitor(ArrayRenderer(out), *iterator);
|
||||
mapbox::util::apply_visitor(ArrayRenderer(out), *iterator);
|
||||
if (++iterator != array.values.end())
|
||||
{
|
||||
out.push_back(',');
|
||||
@@ -201,17 +143,20 @@ struct ArrayRenderer : boost::static_visitor<>
|
||||
out.push_back(']');
|
||||
}
|
||||
|
||||
void operator()(const True &) const {
|
||||
void operator()(const True &) const
|
||||
{
|
||||
const std::string temp("true");
|
||||
out.insert(out.end(), temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
void operator()(const False &) const {
|
||||
void operator()(const False &) const
|
||||
{
|
||||
const std::string temp("false");
|
||||
out.insert(out.end(), temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
void operator()(const Null &) const {
|
||||
void operator()(const Null &) const
|
||||
{
|
||||
const std::string temp("null");
|
||||
out.insert(out.end(), temp.begin(), temp.end());
|
||||
}
|
||||
@@ -223,15 +168,15 @@ struct ArrayRenderer : boost::static_visitor<>
|
||||
inline void render(std::ostream &out, const Object &object)
|
||||
{
|
||||
Value value = object;
|
||||
boost::apply_visitor(Renderer(out), value);
|
||||
mapbox::util::apply_visitor(Renderer(out), value);
|
||||
}
|
||||
|
||||
inline void render(std::vector<char> &out, const Object &object)
|
||||
{
|
||||
Value value = object;
|
||||
boost::apply_visitor(ArrayRenderer(out), value);
|
||||
mapbox::util::apply_visitor(ArrayRenderer(out), value);
|
||||
}
|
||||
|
||||
} // namespace JSON
|
||||
|
||||
#endif // JSON_CONTAINER_H
|
||||
#endif // JSON_RENDERER_HPP
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -25,8 +25,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef LUA_UTIL_H
|
||||
#define LUA_UTIL_H
|
||||
#ifndef LUA_UTIL_HPP
|
||||
#define LUA_UTIL_HPP
|
||||
|
||||
extern "C" {
|
||||
#include <lua.h>
|
||||
@@ -63,4 +63,4 @@ inline void luaAddScriptFolderToLoadPath(lua_State *lua_state, const char *file_
|
||||
luaL_dostring(lua_state, lua_code.c_str());
|
||||
}
|
||||
|
||||
#endif // LUA_UTIL_H
|
||||
#endif // LUA_UTIL_HPP
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef MAKE_UNIQUE_H_
|
||||
#define MAKE_UNIQUE_H_
|
||||
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
// Taken from http://msdn.microsoft.com/en-us/library/dn439780.asp
|
||||
// Note, that the snippet was broken there and needed minor massaging
|
||||
|
||||
// make_unique<T>
|
||||
template <class T, class... Types> std::unique_ptr<T> make_unique(Types &&... Args)
|
||||
{
|
||||
return (std::unique_ptr<T>(new T(std::forward<Types>(Args)...)));
|
||||
}
|
||||
|
||||
// make_unique<T[]>
|
||||
template <class T> std::unique_ptr<T[]> make_unique(std::size_t Size)
|
||||
{
|
||||
return (std::unique_ptr<T>(new T[Size]()));
|
||||
}
|
||||
|
||||
// make_unique<T[N]> disallowed
|
||||
template <class T, class... Types>
|
||||
typename std::enable_if<std::extent<T>::value != 0, void>::type make_unique(Types &&...) = delete;
|
||||
}
|
||||
|
||||
#endif //MAKE_UNIQUE_H_
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "osrm_exception.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
// This function exists to 'anchor' the class, and stop the compiler from
|
||||
// copying vtable and RTTI info into every object file that includes
|
||||
// this header. (Caught by -Wweak-vtables under Clang.)
|
||||
|
||||
// More information from the LLVM Coding Standards:
|
||||
// If a class is defined in a header file and has a vtable (either it has
|
||||
// virtual methods or it derives from classes with virtual methods), it must
|
||||
// always have at least one out-of-line virtual method in the class. Without
|
||||
// this, the compiler will copy the vtable and RTTI into every .o file that
|
||||
// #includes the header, bloating .o file sizes and increasing link times.
|
||||
void exception::anchor() const { }
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef OSRM_EXCEPTION_HPP
|
||||
#define OSRM_EXCEPTION_HPP
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
class exception final : public std::exception
|
||||
{
|
||||
public:
|
||||
explicit exception(const char *message) : message(message) {}
|
||||
explicit exception(const std::string &message) : message(message) {}
|
||||
|
||||
private:
|
||||
// This function exists to 'anchor' the class, and stop the compiler from
|
||||
// copying vtable and RTTI info into every object file that includes
|
||||
// this header. (Caught by -Wweak-vtables under Clang.)
|
||||
virtual void anchor() const;
|
||||
const char *what() const noexcept { return message.c_str(); }
|
||||
const std::string message;
|
||||
};
|
||||
}
|
||||
#endif /* OSRM_EXCEPTION_HPP */
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
open source routing machine
|
||||
Copyright (C) Dennis Luxen, others 2010
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
#ifndef RANGE_ALGORITHMS_HPP
|
||||
#define RANGE_ALGORITHMS_HPP
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace osrm {
|
||||
|
||||
template<class Container>
|
||||
auto max_element(const Container & c) -> decltype(std::max_element(c.begin(), c.end()))
|
||||
{
|
||||
return std::max_element(c.begin(), c.end());
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
auto max_element(const Container & c) -> decltype(std::max_element(c.cbegin(), c.cend()))
|
||||
{
|
||||
return std::max_element(c.cbegin(), c.cend());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // RANGE_ALGORITHMS_HPP
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "simple_logger.hpp"
|
||||
|
||||
#include "osrm_exception.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <io.h>
|
||||
#define isatty _isatty
|
||||
#define fileno _fileno
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <ostream>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
|
||||
namespace
|
||||
{
|
||||
static const char COL_RESET[] { "\x1b[0m"};
|
||||
static const char RED[] { "\x1b[31m"};
|
||||
#ifndef NDEBUG
|
||||
static const char YELLOW[] { "\x1b[33m"};
|
||||
#endif
|
||||
// static const char GREEN[] { "\x1b[32m"};
|
||||
// static const char BLUE[] { "\x1b[34m"};
|
||||
// static const char MAGENTA[] { "\x1b[35m"};
|
||||
// static const char CYAN[] { "\x1b[36m"};
|
||||
}
|
||||
|
||||
void LogPolicy::Unmute() { m_is_mute = false; }
|
||||
|
||||
void LogPolicy::Mute() { m_is_mute = true; }
|
||||
|
||||
bool LogPolicy::IsMute() const { return m_is_mute; }
|
||||
|
||||
LogPolicy &LogPolicy::GetInstance()
|
||||
{
|
||||
static LogPolicy runningInstance;
|
||||
return runningInstance;
|
||||
}
|
||||
|
||||
SimpleLogger::SimpleLogger() : level(logINFO) {}
|
||||
|
||||
std::mutex &SimpleLogger::get_mutex()
|
||||
{
|
||||
static std::mutex mtx;
|
||||
return mtx;
|
||||
}
|
||||
|
||||
std::ostringstream &SimpleLogger::Write(LogLevel lvl)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(get_mutex());
|
||||
try
|
||||
{
|
||||
level = lvl;
|
||||
os << "[";
|
||||
switch (level)
|
||||
{
|
||||
case logWARNING:
|
||||
os << "warn";
|
||||
break;
|
||||
case logDEBUG:
|
||||
#ifndef NDEBUG
|
||||
os << "debug";
|
||||
#endif
|
||||
break;
|
||||
default: //logINFO:
|
||||
os << "info";
|
||||
break;
|
||||
}
|
||||
os << "] ";
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
// encapsulate in osrm::exception
|
||||
throw osrm::exception(std::string(e.what()) + ", getting ostringstream");
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
SimpleLogger::~SimpleLogger()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(get_mutex());
|
||||
if (!LogPolicy::GetInstance().IsMute())
|
||||
{
|
||||
const bool is_terminal = static_cast<bool>(isatty(fileno(stdout)));
|
||||
switch (level)
|
||||
{
|
||||
case logWARNING:
|
||||
std::cerr << (is_terminal ? RED : "") << os.str() << (is_terminal ? COL_RESET : "")
|
||||
<< std::endl;
|
||||
break;
|
||||
case logDEBUG:
|
||||
#ifndef NDEBUG
|
||||
std::cout << (is_terminal ? YELLOW : "") << os.str() << (is_terminal ? COL_RESET : "")
|
||||
<< std::endl;
|
||||
#endif
|
||||
break;
|
||||
default: //logINFO:
|
||||
std::cout << os.str() << (is_terminal ? COL_RESET : "") << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,30 +25,50 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef XMLPARSER_H_
|
||||
#define XMLPARSER_H_
|
||||
#ifndef SIMPLE_LOGGER_HPP
|
||||
#define SIMPLE_LOGGER_HPP
|
||||
|
||||
#include "BaseParser.h"
|
||||
#include "../DataStructures/Restriction.h"
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
|
||||
#include <libxml/xmlreader.h>
|
||||
|
||||
class ExtractorCallbacks;
|
||||
|
||||
class XMLParser : public BaseParser
|
||||
enum LogLevel
|
||||
{
|
||||
public:
|
||||
XMLParser(const char *filename,
|
||||
ExtractorCallbacks *extractor_callbacks,
|
||||
ScriptingEnvironment &scripting_environment);
|
||||
bool ReadHeader();
|
||||
bool Parse();
|
||||
|
||||
private:
|
||||
InputRestrictionContainer ReadXMLRestriction();
|
||||
ExtractionWay ReadXMLWay();
|
||||
ImportNode ReadXMLNode();
|
||||
xmlTextReaderPtr inputReader;
|
||||
logINFO,
|
||||
logWARNING,
|
||||
logDEBUG
|
||||
};
|
||||
|
||||
#endif /* XMLPARSER_H_ */
|
||||
class LogPolicy
|
||||
{
|
||||
public:
|
||||
void Unmute();
|
||||
|
||||
void Mute();
|
||||
|
||||
bool IsMute() const;
|
||||
|
||||
static LogPolicy &GetInstance();
|
||||
|
||||
LogPolicy(const LogPolicy &) = delete;
|
||||
|
||||
private:
|
||||
LogPolicy() : m_is_mute(true) {}
|
||||
std::atomic<bool> m_is_mute;
|
||||
};
|
||||
|
||||
class SimpleLogger
|
||||
{
|
||||
public:
|
||||
SimpleLogger();
|
||||
|
||||
virtual ~SimpleLogger();
|
||||
std::mutex &get_mutex();
|
||||
std::ostringstream &Write(LogLevel l = logINFO);
|
||||
|
||||
private:
|
||||
std::ostringstream os;
|
||||
LogLevel level;
|
||||
};
|
||||
|
||||
#endif /* SIMPLE_LOGGER_HPP */
|
||||
@@ -25,39 +25,43 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef STD_HASH_EXTENSIONS_H
|
||||
#define STD_HASH_EXTENSIONS_H
|
||||
#ifndef STD_HASH_HPP
|
||||
#define STD_HASH_HPP
|
||||
|
||||
#include <functional>
|
||||
|
||||
// this is largely inspired by boost's hash combine as can be found in
|
||||
// "The C++ Standard Library" 2nd Edition. Nicolai M. Josuttis. 2012.
|
||||
|
||||
namespace {
|
||||
|
||||
template<typename T>
|
||||
inline void hash_combine(std::size_t &seed, const T& val)
|
||||
void hash_combine(std::size_t &seed, const T& val)
|
||||
{
|
||||
seed ^= std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void hash_val(std::size_t &seed, const T& val)
|
||||
void hash_val(std::size_t &seed, const T& val)
|
||||
{
|
||||
hash_combine(seed, val);
|
||||
}
|
||||
|
||||
template<typename T, typename ... Types>
|
||||
inline void hash_val(std::size_t &seed, const T& val, const Types& ... args)
|
||||
void hash_val(std::size_t &seed, const T& val, const Types& ... args)
|
||||
{
|
||||
hash_combine(seed, val);
|
||||
hash_val(seed, args ...);
|
||||
}
|
||||
|
||||
template<typename ... Types>
|
||||
inline std::size_t hash_val( const Types&... args)
|
||||
std::size_t hash_val(const Types&... args)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
hash_val(seed, args...);
|
||||
return seed;
|
||||
}
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
@@ -70,4 +74,4 @@ template <typename T1, typename T2> struct hash<std::pair<T1, T2>>
|
||||
};
|
||||
}
|
||||
|
||||
#endif // STD_HASH_EXTENSIONS_H
|
||||
#endif // STD_HASH_HPP
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef STRING_UTIL_HPP
|
||||
#define STRING_UTIL_HPP
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include <cctype>
|
||||
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// precision: position after decimal point
|
||||
// length: maximum number of digits including comma and decimals
|
||||
// work with negative values to prevent overflowing when taking -value
|
||||
template <int length, int precision> static inline char *printInt(char *buffer, int value)
|
||||
{
|
||||
bool minus = true;
|
||||
if (value > 0)
|
||||
{
|
||||
minus = false;
|
||||
value = -value;
|
||||
}
|
||||
buffer += length - 1;
|
||||
for (int i = 0; i < precision; i++)
|
||||
{
|
||||
*buffer = '0' - (value % 10);
|
||||
value /= 10;
|
||||
buffer--;
|
||||
}
|
||||
*buffer = '.';
|
||||
buffer--;
|
||||
for (int i = precision + 1; i < length; i++)
|
||||
{
|
||||
*buffer = '0' - (value % 10);
|
||||
value /= 10;
|
||||
if (value == 0)
|
||||
break;
|
||||
buffer--;
|
||||
}
|
||||
if (minus)
|
||||
{
|
||||
buffer--;
|
||||
*buffer = '-';
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
inline void replaceAll(std::string &s, const std::string &sub, const std::string &other)
|
||||
{
|
||||
boost::replace_all(s, sub, other);
|
||||
}
|
||||
|
||||
inline std::string EscapeJSONString(const std::string &input)
|
||||
{
|
||||
std::string output;
|
||||
output.reserve(input.size());
|
||||
for (auto iter = input.begin(); iter != input.end(); ++iter)
|
||||
{
|
||||
switch (iter[0])
|
||||
{
|
||||
case '\\':
|
||||
output += "\\\\";
|
||||
break;
|
||||
case '"':
|
||||
output += "\\\"";
|
||||
break;
|
||||
case '/':
|
||||
output += "\\/";
|
||||
break;
|
||||
case '\b':
|
||||
output += "\\b";
|
||||
break;
|
||||
case '\f':
|
||||
output += "\\f";
|
||||
break;
|
||||
case '\n':
|
||||
output += "\\n";
|
||||
break;
|
||||
case '\r':
|
||||
output += "\\r";
|
||||
break;
|
||||
case '\t':
|
||||
output += "\\t";
|
||||
break;
|
||||
default:
|
||||
output += *iter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
static std::string originals[] = {"&", "\"", "<", ">", "'", "[", "]", "\\"};
|
||||
static std::string entities[] = {
|
||||
"&", """, "<", ">", "'", "&91;", "&93;", " \"};
|
||||
|
||||
inline std::size_t URIDecode(const std::string &input, std::string &output)
|
||||
{
|
||||
auto src_iter = input.begin();
|
||||
output.resize(input.size() + 1);
|
||||
std::size_t decoded_length = 0;
|
||||
for (decoded_length = 0; src_iter != input.end(); ++decoded_length)
|
||||
{
|
||||
if (src_iter[0] == '%' && src_iter[1] && src_iter[2] && isxdigit(src_iter[1]) &&
|
||||
isxdigit(src_iter[2]))
|
||||
{
|
||||
std::string::value_type a = src_iter[1];
|
||||
std::string::value_type b = src_iter[2];
|
||||
a -= src_iter[1] < 58 ? 48 : src_iter[1] < 71 ? 55 : 87;
|
||||
b -= src_iter[2] < 58 ? 48 : src_iter[2] < 71 ? 55 : 87;
|
||||
output[decoded_length] = 16 * a + b;
|
||||
src_iter += 3;
|
||||
continue;
|
||||
}
|
||||
output[decoded_length] = *src_iter++;
|
||||
}
|
||||
output.resize(decoded_length);
|
||||
return decoded_length;
|
||||
}
|
||||
|
||||
inline std::size_t URIDecodeInPlace(std::string &URI) { return URIDecode(URI, URI); }
|
||||
|
||||
#endif // STRING_UTIL_HPP
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef TIMING_UTIL_HPP
|
||||
#define TIMING_UTIL_HPP
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
struct GlobalTimer
|
||||
{
|
||||
GlobalTimer() : time(0) {}
|
||||
std::atomic<uint64_t> time;
|
||||
};
|
||||
|
||||
class GlobalTimerFactory
|
||||
{
|
||||
public:
|
||||
static GlobalTimerFactory& get()
|
||||
{
|
||||
static GlobalTimerFactory instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
GlobalTimer& getGlobalTimer(const std::string& name)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(map_mutex);
|
||||
return timer_map[name];
|
||||
}
|
||||
|
||||
private:
|
||||
std::mutex map_mutex;
|
||||
std::unordered_map<std::string, GlobalTimer> timer_map;
|
||||
};
|
||||
|
||||
#define GLOBAL_TIMER_AQUIRE(_X) auto& _X##_global_timer = GlobalTimerFactory::get().getGlobalTimer(#_X)
|
||||
#define GLOBAL_TIMER_RESET(_X) _X##_global_timer.time = 0
|
||||
#define GLOBAL_TIMER_START(_X) TIMER_START(_X)
|
||||
#define GLOBAL_TIMER_STOP(_X) TIMER_STOP(_X); _X##_global_timer.time += TIMER_NSEC(_X)
|
||||
#define GLOBAL_TIMER_NSEC(_X) static_cast<double>(_X##_global_timer.time)
|
||||
#define GLOBAL_TIMER_USEC(_X) (_X##_global_timer.time / 1000.0)
|
||||
#define GLOBAL_TIMER_MSEC(_X) (_X##_global_timer.time / 1000.0 / 1000.0)
|
||||
#define GLOBAL_TIMER_SEC(_X) (_X##_global_timer.time / 1000.0 / 1000.0 / 1000.0)
|
||||
|
||||
#define TIMER_START(_X) auto _X##_start = std::chrono::steady_clock::now(), _X##_stop = _X##_start
|
||||
#define TIMER_STOP(_X) _X##_stop = std::chrono::steady_clock::now()
|
||||
#define TIMER_NSEC(_X) std::chrono::duration_cast<std::chrono::nanoseconds>(_X##_stop - _X##_start).count()
|
||||
#define TIMER_USEC(_X) std::chrono::duration_cast<std::chrono::microseconds>(_X##_stop - _X##_start).count()
|
||||
#define TIMER_MSEC(_X) (0.000001*std::chrono::duration_cast<std::chrono::nanoseconds>(_X##_stop - _X##_start).count())
|
||||
#define TIMER_SEC(_X) (0.000001*std::chrono::duration_cast<std::chrono::microseconds>(_X##_stop - _X##_start).count())
|
||||
#define TIMER_MIN(_X) std::chrono::duration_cast<std::chrono::minutes>(_X##_stop - _X##_start).count()
|
||||
|
||||
#endif // TIMING_UTIL_HPP
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef XML_RENDERER_HPP
|
||||
#define XML_RENDERER_HPP
|
||||
|
||||
#include "../data_structures/json_container.hpp"
|
||||
#include "cast.hpp"
|
||||
|
||||
namespace JSON {
|
||||
|
||||
struct XMLToArrayRenderer : mapbox::util::static_visitor<>
|
||||
{
|
||||
explicit XMLToArrayRenderer(std::vector<char> &_out) : out(_out) {}
|
||||
|
||||
void operator()(const String &string) const
|
||||
{
|
||||
out.push_back('\"');
|
||||
out.insert(out.end(), string.value.begin(), string.value.end());
|
||||
out.push_back('\"');
|
||||
}
|
||||
|
||||
void operator()(const Number &number) const
|
||||
{
|
||||
const std::string number_string = cast::double_fixed_to_string(number.value);
|
||||
out.insert(out.end(), number_string.begin(), number_string.end());
|
||||
}
|
||||
|
||||
void operator()(const Object &object) const
|
||||
{
|
||||
auto iterator = object.values.begin();
|
||||
while (iterator != object.values.end())
|
||||
{
|
||||
if (iterator->first.at(0) != '_')
|
||||
{
|
||||
out.push_back('<');
|
||||
out.insert(out.end(), (*iterator).first.begin(), (*iterator).first.end());
|
||||
}
|
||||
else
|
||||
{
|
||||
out.push_back(' ');
|
||||
out.insert(out.end(), ++(*iterator).first.begin(), (*iterator).first.end());
|
||||
out.push_back('=');
|
||||
|
||||
}
|
||||
mapbox::util::apply_visitor(XMLToArrayRenderer(out), (*iterator).second);
|
||||
if (iterator->first.at(0) != '_')
|
||||
{
|
||||
out.push_back('/');
|
||||
out.push_back('>');
|
||||
}
|
||||
++iterator;
|
||||
}
|
||||
}
|
||||
|
||||
void operator()(const Array &array) const
|
||||
{
|
||||
std::vector<Value>::const_iterator iterator;
|
||||
iterator = array.values.begin();
|
||||
while (iterator != array.values.end())
|
||||
{
|
||||
mapbox::util::apply_visitor(XMLToArrayRenderer(out), *iterator);
|
||||
++iterator;
|
||||
}
|
||||
}
|
||||
|
||||
void operator()(const True &) const
|
||||
{
|
||||
const std::string temp("true");
|
||||
out.insert(out.end(), temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
void operator()(const False &) const
|
||||
{
|
||||
const std::string temp("false");
|
||||
out.insert(out.end(), temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
void operator()(const Null &) const
|
||||
{
|
||||
const std::string temp("null");
|
||||
out.insert(out.end(), temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<char> &out;
|
||||
};
|
||||
|
||||
template<class JSONObject>
|
||||
inline void xml_render(std::vector<char> &out, const JSONObject &object)
|
||||
{
|
||||
Value value = object;
|
||||
mapbox::util::apply_visitor(XMLToArrayRenderer(out), value);
|
||||
}
|
||||
|
||||
template<class JSONObject>
|
||||
inline void gpx_render(std::vector<char> &out, const JSONObject &object)
|
||||
{
|
||||
// add header
|
||||
|
||||
const std::string header {"<?xml version=\"1.0\" encoding=\"UTF-8\"?><gpx creator=\"OSRM Routing Engine\""
|
||||
" version=\"1.1\" xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http:"
|
||||
"//www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topogr"
|
||||
"afix.com/GPX/1/1 gpx.xsd\"><metadata><copyright author=\"Project OSRM\"><lice"
|
||||
"nse>Data (c) OpenStreetMap contributors (ODbL)</license></copyright></metadat"
|
||||
"a><rte>"};
|
||||
out.insert(out.end(), header.begin(), header.end());
|
||||
|
||||
xml_render(out, object);
|
||||
|
||||
const std::string footer {"</rte></gpx>"};
|
||||
out.insert(out.end(), footer.begin(), footer.end());
|
||||
}
|
||||
} // namespace JSON
|
||||
|
||||
#endif // XML_RENDERER_HPP
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef BFS_COMPONENTS_HPP_
|
||||
#define BFS_COMPONENTS_HPP_
|
||||
|
||||
#include "../typedefs.h"
|
||||
#include "../data_structures/restriction_map.hpp"
|
||||
|
||||
#include <queue>
|
||||
#include <unordered_set>
|
||||
|
||||
// Explores the components of the given graph while respecting turn restrictions
|
||||
// and barriers.
|
||||
template <typename GraphT> class BFSComponentExplorer
|
||||
{
|
||||
public:
|
||||
BFSComponentExplorer(const GraphT &dynamic_graph,
|
||||
const RestrictionMap &restrictions,
|
||||
const std::unordered_set<NodeID> &barrier_nodes)
|
||||
: m_graph(dynamic_graph), m_restriction_map(restrictions), m_barrier_nodes(barrier_nodes)
|
||||
{
|
||||
BOOST_ASSERT(m_graph.GetNumberOfNodes() > 0);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the size of the component that the node belongs to.
|
||||
*/
|
||||
unsigned int GetComponentSize(const NodeID node) const
|
||||
{
|
||||
BOOST_ASSERT(node < m_component_index_list.size());
|
||||
|
||||
return m_component_index_size[m_component_index_list[node]];
|
||||
}
|
||||
|
||||
unsigned int GetNumberOfComponents() { return m_component_index_size.size(); }
|
||||
|
||||
/*!
|
||||
* Computes the component sizes.
|
||||
*/
|
||||
void run()
|
||||
{
|
||||
std::queue<std::pair<NodeID, NodeID>> bfs_queue;
|
||||
unsigned current_component = 0;
|
||||
|
||||
BOOST_ASSERT(m_component_index_list.empty());
|
||||
BOOST_ASSERT(m_component_index_size.empty());
|
||||
|
||||
unsigned num_nodes = m_graph.GetNumberOfNodes();
|
||||
|
||||
m_component_index_list.resize(num_nodes, std::numeric_limits<unsigned>::max());
|
||||
|
||||
BOOST_ASSERT(num_nodes > 0);
|
||||
|
||||
// put unexplorered node with parent pointer into queue
|
||||
for (NodeID node = 0; node < num_nodes; ++node)
|
||||
{
|
||||
if (std::numeric_limits<unsigned>::max() == m_component_index_list[node])
|
||||
{
|
||||
unsigned size = ExploreComponent(bfs_queue, node, current_component);
|
||||
|
||||
// push size into vector
|
||||
m_component_index_size.emplace_back(size);
|
||||
++current_component;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
/*!
|
||||
* Explores the current component that starts at node using BFS.
|
||||
*/
|
||||
unsigned ExploreComponent(std::queue<std::pair<NodeID, NodeID>> &bfs_queue,
|
||||
NodeID node,
|
||||
unsigned current_component)
|
||||
{
|
||||
/*
|
||||
Graphical representation of variables:
|
||||
|
||||
u v w
|
||||
*---------->*---------->*
|
||||
e2
|
||||
*/
|
||||
|
||||
bfs_queue.emplace(node, node);
|
||||
// mark node as read
|
||||
m_component_index_list[node] = current_component;
|
||||
|
||||
unsigned current_component_size = 1;
|
||||
|
||||
while (!bfs_queue.empty())
|
||||
{
|
||||
// fetch element from BFS queue
|
||||
std::pair<NodeID, NodeID> current_queue_item = bfs_queue.front();
|
||||
bfs_queue.pop();
|
||||
|
||||
const NodeID v = current_queue_item.first; // current node
|
||||
const NodeID u = current_queue_item.second; // parent
|
||||
// increment size counter of current component
|
||||
++current_component_size;
|
||||
if (m_barrier_nodes.find(v) != m_barrier_nodes.end())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
const NodeID to_node_of_only_restriction =
|
||||
m_restriction_map.CheckForEmanatingIsOnlyTurn(u, v);
|
||||
|
||||
for (auto e2 : m_graph.GetAdjacentEdgeRange(v))
|
||||
{
|
||||
const NodeID w = m_graph.GetTarget(e2);
|
||||
|
||||
if (to_node_of_only_restriction != std::numeric_limits<unsigned>::max() &&
|
||||
w != to_node_of_only_restriction)
|
||||
{
|
||||
// At an only_-restriction but not at the right turn
|
||||
continue;
|
||||
}
|
||||
|
||||
if (u != w)
|
||||
{
|
||||
// only add an edge if turn is not a U-turn except
|
||||
// when it is at the end of a dead-end street.
|
||||
if (!m_restriction_map.CheckIfTurnIsRestricted(u, v, w))
|
||||
{
|
||||
// only add an edge if turn is not prohibited
|
||||
if (std::numeric_limits<unsigned>::max() == m_component_index_list[w])
|
||||
{
|
||||
// insert next (node, parent) only if w has
|
||||
// not yet been explored
|
||||
// mark node as read
|
||||
m_component_index_list[w] = current_component;
|
||||
bfs_queue.emplace(w, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return current_component_size;
|
||||
}
|
||||
|
||||
std::vector<unsigned> m_component_index_list;
|
||||
std::vector<NodeID> m_component_index_size;
|
||||
|
||||
const GraphT &m_graph;
|
||||
const RestrictionMap &m_restriction_map;
|
||||
const std::unordered_set<NodeID> &m_barrier_nodes;
|
||||
};
|
||||
|
||||
#endif // BFS_COMPONENTS_HPP_
|
||||
@@ -28,44 +28,59 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#ifndef ITERATOR_BASED_CRC32_H
|
||||
#define ITERATOR_BASED_CRC32_H
|
||||
|
||||
#include "../Util/SimpleLogger.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#if defined(__x86_64__) && !defined(__MINGW64__)
|
||||
#include <cpuid.h>
|
||||
#else
|
||||
#endif
|
||||
|
||||
#include <boost/crc.hpp> // for boost::crc_32_type
|
||||
|
||||
inline void __get_cpuid(int param, unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx)
|
||||
#include <iterator>
|
||||
|
||||
class IteratorbasedCRC32
|
||||
{
|
||||
*ecx = 0;
|
||||
}
|
||||
#endif
|
||||
public:
|
||||
bool using_hardware() const { return use_hardware_implementation; }
|
||||
|
||||
template <class ContainerT> class IteratorbasedCRC32
|
||||
{
|
||||
private:
|
||||
typedef typename ContainerT::iterator IteratorType;
|
||||
unsigned crc;
|
||||
IteratorbasedCRC32() : crc(0) { use_hardware_implementation = detect_hardware_support(); }
|
||||
|
||||
bool use_SSE42_CRC_function;
|
||||
|
||||
#if !defined(__x86_64__)
|
||||
boost::crc_optimal<32, 0x1EDC6F41, 0x0, 0x0, true, true> CRC32_processor;
|
||||
#endif
|
||||
unsigned SoftwareBasedCRC32(char *str, unsigned len)
|
||||
template <class Iterator> unsigned operator()(Iterator iter, const Iterator end)
|
||||
{
|
||||
#if !defined(__x86_64__)
|
||||
CRC32_processor.process_bytes(str, len);
|
||||
return CRC32_processor.checksum();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
unsigned crc = 0;
|
||||
while (iter != end)
|
||||
{
|
||||
using value_type = typename std::iterator_traits<Iterator>::value_type;
|
||||
char *data = (char *)(&(*iter));
|
||||
|
||||
if (use_hardware_implementation)
|
||||
{
|
||||
crc = compute_in_hardware(data, sizeof(value_type));
|
||||
}
|
||||
else
|
||||
{
|
||||
crc = compute_in_software(data, sizeof(value_type));
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
private:
|
||||
bool detect_hardware_support() const
|
||||
{
|
||||
static const int sse42_bit = 0x00100000;
|
||||
const unsigned ecx = cpuid();
|
||||
const bool sse42_found = (ecx & sse42_bit) != 0;
|
||||
return sse42_found;
|
||||
}
|
||||
|
||||
unsigned compute_in_software(char *str, unsigned len)
|
||||
{
|
||||
crc_processor.process_bytes(str, len);
|
||||
return crc_processor.checksum();
|
||||
}
|
||||
|
||||
// adapted from http://byteworm.com/2010/10/13/crc32/
|
||||
unsigned SSE42BasedCRC32(char *str, unsigned len)
|
||||
unsigned compute_in_hardware(char *str, unsigned len)
|
||||
{
|
||||
#if defined(__x86_64__)
|
||||
unsigned q = len / sizeof(unsigned);
|
||||
@@ -101,44 +116,31 @@ template <class ContainerT> class IteratorbasedCRC32
|
||||
return ecx;
|
||||
}
|
||||
|
||||
bool DetectNativeCRC32Support()
|
||||
#if defined(__MINGW64__) || defined(_MSC_VER)
|
||||
inline void
|
||||
__get_cpuid(int param, unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx) const
|
||||
{
|
||||
static const int SSE42_BIT = 0x00100000;
|
||||
const unsigned ecx = cpuid();
|
||||
const bool has_SSE42 = (ecx & SSE42_BIT) != 0;
|
||||
if (has_SSE42)
|
||||
{
|
||||
SimpleLogger().Write() << "using hardware based CRC32 computation";
|
||||
}
|
||||
else
|
||||
{
|
||||
SimpleLogger().Write() << "using software based CRC32 computation";
|
||||
}
|
||||
return has_SSE42;
|
||||
*ecx = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
boost::crc_optimal<32, 0x1EDC6F41, 0x0, 0x0, true, true> crc_processor;
|
||||
unsigned crc;
|
||||
bool use_hardware_implementation;
|
||||
};
|
||||
|
||||
struct RangebasedCRC32
|
||||
{
|
||||
template<typename Iteratable>
|
||||
unsigned operator()(const Iteratable &iterable)
|
||||
{
|
||||
return crc32(std::begin(iterable), std::end(iterable));
|
||||
}
|
||||
|
||||
public:
|
||||
IteratorbasedCRC32() : crc(0) { use_SSE42_CRC_function = DetectNativeCRC32Support(); }
|
||||
bool using_hardware() const { return crc32.using_hardware(); }
|
||||
|
||||
unsigned operator()(IteratorType iter, const IteratorType end)
|
||||
{
|
||||
unsigned crc = 0;
|
||||
while (iter != end)
|
||||
{
|
||||
char *data = reinterpret_cast<char *>(&(*iter));
|
||||
|
||||
if (use_SSE42_CRC_function)
|
||||
{
|
||||
crc = SSE42BasedCRC32(data, sizeof(typename ContainerT::value_type));
|
||||
}
|
||||
else
|
||||
{
|
||||
crc = SoftwareBasedCRC32(data, sizeof(typename ContainerT::value_type));
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
private:
|
||||
IteratorbasedCRC32 crc32;
|
||||
};
|
||||
|
||||
#endif /* ITERATOR_BASED_CRC32_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -25,11 +25,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osrm/Coordinate.h>
|
||||
#include "douglas_peucker.hpp"
|
||||
|
||||
#include "DouglasPeucker.h"
|
||||
#include "../DataStructures/SegmentInformation.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
#include "../data_structures/segment_information.hpp"
|
||||
#include "../Util/integer_range.hpp"
|
||||
|
||||
#include <osrm/Coordinate.h>
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
@@ -37,6 +38,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct CoordinatePairCalculator
|
||||
{
|
||||
CoordinatePairCalculator() = delete;
|
||||
@@ -78,62 +81,42 @@ struct CoordinatePairCalculator
|
||||
float second_lat;
|
||||
float second_lon;
|
||||
};
|
||||
|
||||
DouglasPeucker::DouglasPeucker()
|
||||
: douglas_peucker_thresholds({512440, // z0
|
||||
256720, // z1
|
||||
122560, // z2
|
||||
56780, // z3
|
||||
28800, // z4
|
||||
14400, // z5
|
||||
7200, // z6
|
||||
3200, // z7
|
||||
2400, // z8
|
||||
1000, // z9
|
||||
600, // z10
|
||||
120, // z11
|
||||
60, // z12
|
||||
45, // z13
|
||||
36, // z14
|
||||
20, // z15
|
||||
8, // z16
|
||||
6, // z17
|
||||
4 // z18
|
||||
})
|
||||
{
|
||||
}
|
||||
|
||||
void DouglasPeucker::Run(std::vector<SegmentInformation> &input_geometry, const unsigned zoom_level)
|
||||
{
|
||||
// check if input data is invalid
|
||||
BOOST_ASSERT_MSG(!input_geometry.empty(), "geometry invalid");
|
||||
Run(std::begin(input_geometry), std::end(input_geometry), zoom_level);
|
||||
}
|
||||
|
||||
if (input_geometry.size() < 2)
|
||||
void DouglasPeucker::Run(RandomAccessIt begin, RandomAccessIt end, const unsigned zoom_level)
|
||||
{
|
||||
unsigned size = std::distance(begin, end);
|
||||
if (size < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
input_geometry.front().necessary = true;
|
||||
input_geometry.back().necessary = true;
|
||||
begin->necessary = true;
|
||||
std::prev(end)->necessary = true;
|
||||
|
||||
{
|
||||
BOOST_ASSERT_MSG(zoom_level < 19, "unsupported zoom level");
|
||||
unsigned left_border = 0;
|
||||
unsigned right_border = 1;
|
||||
BOOST_ASSERT_MSG(zoom_level < DOUGLAS_PEUCKER_THRESHOLDS.size(), "unsupported zoom level");
|
||||
RandomAccessIt left_border = begin;
|
||||
RandomAccessIt right_border = std::next(begin);
|
||||
// Sweep over array and identify those ranges that need to be checked
|
||||
do
|
||||
{
|
||||
// traverse list until new border element found
|
||||
if (input_geometry[right_border].necessary)
|
||||
if (right_border->necessary)
|
||||
{
|
||||
// sanity checks
|
||||
BOOST_ASSERT(input_geometry[left_border].necessary);
|
||||
BOOST_ASSERT(input_geometry[right_border].necessary);
|
||||
BOOST_ASSERT(left_border->necessary);
|
||||
BOOST_ASSERT(right_border->necessary);
|
||||
recursion_stack.emplace(left_border, right_border);
|
||||
left_border = right_border;
|
||||
}
|
||||
++right_border;
|
||||
} while (right_border < input_geometry.size());
|
||||
} while (right_border != end);
|
||||
}
|
||||
|
||||
// mark locations as 'necessary' by divide-and-conquer
|
||||
@@ -143,40 +126,40 @@ void DouglasPeucker::Run(std::vector<SegmentInformation> &input_geometry, const
|
||||
const GeometryRange pair = recursion_stack.top();
|
||||
recursion_stack.pop();
|
||||
// sanity checks
|
||||
BOOST_ASSERT_MSG(input_geometry[pair.first].necessary, "left border mus be necessary");
|
||||
BOOST_ASSERT_MSG(input_geometry[pair.second].necessary, "right border must be necessary");
|
||||
BOOST_ASSERT_MSG(pair.second < input_geometry.size(), "right border outside of geometry");
|
||||
BOOST_ASSERT_MSG(pair.first < pair.second, "left border on the wrong side");
|
||||
BOOST_ASSERT_MSG(pair.first->necessary, "left border must be necessary");
|
||||
BOOST_ASSERT_MSG(pair.second->necessary, "right border must be necessary");
|
||||
BOOST_ASSERT_MSG(std::distance(pair.second, end) > 0, "right border outside of geometry");
|
||||
BOOST_ASSERT_MSG(std::distance(pair.first, pair.second) >= 0,
|
||||
"left border on the wrong side");
|
||||
|
||||
int max_int_distance = 0;
|
||||
unsigned farthest_entry_index = pair.second;
|
||||
const CoordinatePairCalculator DistCalc(input_geometry[pair.first].location,
|
||||
input_geometry[pair.second].location);
|
||||
auto farthest_entry_it = pair.second;
|
||||
const CoordinatePairCalculator dist_calc(pair.first->location, pair.second->location);
|
||||
|
||||
// sweep over range to find the maximum
|
||||
for (unsigned i = pair.first + 1; i < pair.second; ++i)
|
||||
for (auto it = std::next(pair.first); it != pair.second; ++it)
|
||||
{
|
||||
const int distance = DistCalc(input_geometry[i].location);
|
||||
const int distance = dist_calc(it->location);
|
||||
// found new feasible maximum?
|
||||
if (distance > max_int_distance && distance > douglas_peucker_thresholds[zoom_level])
|
||||
if (distance > max_int_distance && distance > DOUGLAS_PEUCKER_THRESHOLDS[zoom_level])
|
||||
{
|
||||
farthest_entry_index = i;
|
||||
farthest_entry_it = it;
|
||||
max_int_distance = distance;
|
||||
}
|
||||
}
|
||||
|
||||
// check if maximum violates a zoom level dependent threshold
|
||||
if (max_int_distance > douglas_peucker_thresholds[zoom_level])
|
||||
if (max_int_distance > DOUGLAS_PEUCKER_THRESHOLDS[zoom_level])
|
||||
{
|
||||
// mark idx as necessary
|
||||
input_geometry[farthest_entry_index].necessary = true;
|
||||
if (1 < (farthest_entry_index - pair.first))
|
||||
farthest_entry_it->necessary = true;
|
||||
if (1 < std::distance(pair.first, farthest_entry_it))
|
||||
{
|
||||
recursion_stack.emplace(pair.first, farthest_entry_index);
|
||||
recursion_stack.emplace(pair.first, farthest_entry_it);
|
||||
}
|
||||
if (1 < (pair.second - farthest_entry_index))
|
||||
if (1 < std::distance(farthest_entry_it, pair.second))
|
||||
{
|
||||
recursion_stack.emplace(farthest_entry_index, pair.second);
|
||||
recursion_stack.emplace(farthest_entry_it, pair.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,12 +25,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef DOUGLASPEUCKER_H_
|
||||
#define DOUGLASPEUCKER_H_
|
||||
#ifndef DOUGLAS_PEUCKER_HPP_
|
||||
#define DOUGLAS_PEUCKER_HPP_
|
||||
|
||||
#include <stack>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
|
||||
/* This class object computes the bitvector of indicating generalized input
|
||||
* points according to the (Ramer-)Douglas-Peucker algorithm.
|
||||
@@ -41,18 +41,40 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
struct SegmentInformation;
|
||||
|
||||
static const std::array<int, 19> DOUGLAS_PEUCKER_THRESHOLDS {{
|
||||
512440, // z0
|
||||
256720, // z1
|
||||
122560, // z2
|
||||
56780, // z3
|
||||
28800, // z4
|
||||
14400, // z5
|
||||
7200, // z6
|
||||
3200, // z7
|
||||
2400, // z8
|
||||
1000, // z9
|
||||
600, // z10
|
||||
120, // z11
|
||||
60, // z12
|
||||
45, // z13
|
||||
36, // z14
|
||||
20, // z15
|
||||
8, // z16
|
||||
6, // z17
|
||||
4 // z18
|
||||
}};
|
||||
|
||||
class DouglasPeucker
|
||||
{
|
||||
private:
|
||||
std::vector<int> douglas_peucker_thresholds;
|
||||
public:
|
||||
using RandomAccessIt = std::vector<SegmentInformation>::iterator;
|
||||
|
||||
typedef std::pair<unsigned, unsigned> GeometryRange;
|
||||
using GeometryRange = std::pair<RandomAccessIt, RandomAccessIt>;
|
||||
// Stack to simulate the recursion
|
||||
std::stack<GeometryRange> recursion_stack;
|
||||
|
||||
public:
|
||||
DouglasPeucker();
|
||||
void Run(RandomAccessIt begin, RandomAccessIt end, const unsigned zoom_level);
|
||||
void Run(std::vector<SegmentInformation> &input_geometry, const unsigned zoom_level);
|
||||
};
|
||||
|
||||
#endif /* DOUGLASPEUCKER_H_ */
|
||||
#endif /* DOUGLAS_PEUCKER_HPP_ */
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ENCODER_HPP
|
||||
#define OBJECT_ENCODER_HPP
|
||||
|
||||
#include "../Util/string_util.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/archive/iterators/base64_from_binary.hpp>
|
||||
#include <boost/archive/iterators/binary_from_base64.hpp>
|
||||
#include <boost/archive/iterators/transform_width.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct ObjectEncoder
|
||||
{
|
||||
using base64_t = boost::archive::iterators::base64_from_binary<
|
||||
boost::archive::iterators::transform_width<const char *, 6, 8>>;
|
||||
|
||||
using binary_t = boost::archive::iterators::transform_width<
|
||||
boost::archive::iterators::binary_from_base64<std::string::const_iterator>,
|
||||
8,
|
||||
6>;
|
||||
|
||||
template <class ObjectT>
|
||||
static void EncodeToBase64(const ObjectT &object, std::string &encoded)
|
||||
{
|
||||
const char *char_ptr_to_object = (const char *)&object;
|
||||
std::vector<unsigned char> data(sizeof(object));
|
||||
std::copy(char_ptr_to_object, char_ptr_to_object + sizeof(ObjectT), data.begin());
|
||||
|
||||
unsigned char number_of_padded_chars = 0; // is in {0,1,2};
|
||||
while (data.size() % 3 != 0)
|
||||
{
|
||||
++number_of_padded_chars;
|
||||
data.push_back(0x00);
|
||||
}
|
||||
|
||||
BOOST_ASSERT_MSG(0 == data.size() % 3, "base64 input data size is not a multiple of 3!");
|
||||
encoded.resize(sizeof(ObjectT));
|
||||
encoded.assign(base64_t(&data[0]),
|
||||
base64_t(&data[0] + (data.size() - number_of_padded_chars)));
|
||||
replaceAll(encoded, "+", "-");
|
||||
replaceAll(encoded, "/", "_");
|
||||
}
|
||||
|
||||
template <class ObjectT>
|
||||
static void DecodeFromBase64(const std::string &input, ObjectT &object)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string encoded(input);
|
||||
// replace "-" with "+" and "_" with "/"
|
||||
replaceAll(encoded, "-", "+");
|
||||
replaceAll(encoded, "_", "/");
|
||||
|
||||
std::copy(binary_t(encoded.begin()),
|
||||
binary_t(encoded.begin() + encoded.length() - 1),
|
||||
(char *)&object);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* OBJECT_ENCODER_HPP */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -25,16 +25,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "PolylineCompressor.h"
|
||||
#include "../DataStructures/SegmentInformation.h"
|
||||
#include "polyline_compressor.hpp"
|
||||
#include "../data_structures/segment_information.hpp"
|
||||
|
||||
#include <osrm/Coordinate.h>
|
||||
|
||||
void PolylineCompressor::encodeVectorSignedNumber(std::vector<int> &numbers, std::string &output)
|
||||
const
|
||||
std::string PolylineCompressor::encode_vector(std::vector<int> &numbers) const
|
||||
{
|
||||
const unsigned end = static_cast<unsigned>(numbers.size());
|
||||
for (unsigned i = 0; i < end; ++i)
|
||||
std::string output;
|
||||
const auto end = numbers.size();
|
||||
for (std::size_t i = 0; i < end; ++i)
|
||||
{
|
||||
numbers[i] <<= 1;
|
||||
if (numbers[i] < 0)
|
||||
@@ -44,12 +44,14 @@ void PolylineCompressor::encodeVectorSignedNumber(std::vector<int> &numbers, std
|
||||
}
|
||||
for (const int number : numbers)
|
||||
{
|
||||
encodeNumber(number, output);
|
||||
output += encode_number(number);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
void PolylineCompressor::encodeNumber(int number_to_encode, std::string &output) const
|
||||
std::string PolylineCompressor::encode_number(int number_to_encode) const
|
||||
{
|
||||
std::string output;
|
||||
while (number_to_encode >= 0x20)
|
||||
{
|
||||
const int next_value = (0x20 | (number_to_encode & 0x1f)) + 63;
|
||||
@@ -67,52 +69,30 @@ void PolylineCompressor::encodeNumber(int number_to_encode, std::string &output)
|
||||
{
|
||||
output += static_cast<char>(number_to_encode);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
JSON::String PolylineCompressor::printEncodedString(const std::vector<SegmentInformation> &polyline)
|
||||
const
|
||||
std::string
|
||||
PolylineCompressor::get_encoded_string(const std::vector<SegmentInformation> &polyline) const
|
||||
{
|
||||
std::string output;
|
||||
std::vector<int> delta_numbers;
|
||||
if (!polyline.empty())
|
||||
if (polyline.empty())
|
||||
{
|
||||
FixedPointCoordinate last_coordinate = polyline[0].location;
|
||||
delta_numbers.emplace_back(last_coordinate.lat);
|
||||
delta_numbers.emplace_back(last_coordinate.lon);
|
||||
// iterate after skipping the first, already handled, segment
|
||||
for (auto it = ++polyline.cbegin(); it != polyline.cend(); ++it)
|
||||
{
|
||||
const auto &segment = *it;
|
||||
if (segment.necessary)
|
||||
{
|
||||
int lat_diff = segment.location.lat - last_coordinate.lat;
|
||||
int lon_diff = segment.location.lon - last_coordinate.lon;
|
||||
delta_numbers.emplace_back(lat_diff);
|
||||
delta_numbers.emplace_back(lon_diff);
|
||||
last_coordinate = segment.location;
|
||||
}
|
||||
}
|
||||
encodeVectorSignedNumber(delta_numbers, output);
|
||||
return {};
|
||||
}
|
||||
JSON::String return_value(output);
|
||||
return return_value;
|
||||
}
|
||||
|
||||
JSON::Array
|
||||
PolylineCompressor::printUnencodedString(const std::vector<SegmentInformation> &polyline) const
|
||||
{
|
||||
JSON::Array json_geometry_array;
|
||||
std::vector<int> delta_numbers;
|
||||
delta_numbers.reserve((polyline.size() - 1) * 2);
|
||||
FixedPointCoordinate previous_coordinate = {0, 0};
|
||||
for (const auto &segment : polyline)
|
||||
{
|
||||
if (segment.necessary)
|
||||
{
|
||||
std::string tmp, output;
|
||||
FixedPointCoordinate::convertInternalLatLonToString(segment.location.lat, tmp);
|
||||
output += (tmp + ",");
|
||||
FixedPointCoordinate::convertInternalLatLonToString(segment.location.lon, tmp);
|
||||
output += tmp;
|
||||
json_geometry_array.values.push_back(output);
|
||||
const int lat_diff = segment.location.lat - previous_coordinate.lat;
|
||||
const int lon_diff = segment.location.lon - previous_coordinate.lon;
|
||||
delta_numbers.emplace_back(lat_diff);
|
||||
delta_numbers.emplace_back(lon_diff);
|
||||
previous_coordinate = segment.location;
|
||||
}
|
||||
}
|
||||
return json_geometry_array;
|
||||
return encode_vector(delta_numbers);
|
||||
}
|
||||
@@ -30,22 +30,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
struct SegmentInformation;
|
||||
|
||||
#include "../DataStructures/JSONContainer.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class PolylineCompressor
|
||||
{
|
||||
private:
|
||||
void encodeVectorSignedNumber(std::vector<int> &numbers, std::string &output) const;
|
||||
std::string encode_vector(std::vector<int> &numbers) const;
|
||||
|
||||
void encodeNumber(int number_to_encode, std::string &output) const;
|
||||
std::string encode_number(const int number_to_encode) const;
|
||||
|
||||
public:
|
||||
JSON::String printEncodedString(const std::vector<SegmentInformation> &polyline) const;
|
||||
|
||||
JSON::Array printUnencodedString(const std::vector<SegmentInformation> &polyline) const;
|
||||
std::string get_encoded_string(const std::vector<SegmentInformation> &polyline) const;
|
||||
};
|
||||
|
||||
#endif /* POLYLINECOMPRESSOR_H_ */
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "polyline_formatter.hpp"
|
||||
|
||||
#include "polyline_compressor.hpp"
|
||||
#include "../data_structures/segment_information.hpp"
|
||||
|
||||
#include <osrm/Coordinate.h>
|
||||
|
||||
JSON::String
|
||||
PolylineFormatter::printEncodedString(const std::vector<SegmentInformation> &polyline) const
|
||||
{
|
||||
return JSON::String(PolylineCompressor().get_encoded_string(polyline));
|
||||
}
|
||||
|
||||
JSON::Array
|
||||
PolylineFormatter::printUnencodedString(const std::vector<SegmentInformation> &polyline) const
|
||||
{
|
||||
JSON::Array json_geometry_array;
|
||||
for (const auto &segment : polyline)
|
||||
{
|
||||
if (segment.necessary)
|
||||
{
|
||||
JSON::Array json_coordinate;
|
||||
json_coordinate.values.push_back(segment.location.lat / COORDINATE_PRECISION);
|
||||
json_coordinate.values.push_back(segment.location.lon / COORDINATE_PRECISION);
|
||||
json_geometry_array.values.push_back(json_coordinate);
|
||||
}
|
||||
}
|
||||
return json_geometry_array;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef POLYLINE_FORMATTER_HPP
|
||||
#define POLYLINE_FORMATTER_HPP
|
||||
|
||||
struct SegmentInformation;
|
||||
|
||||
#include "../data_structures/json_container.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct PolylineFormatter
|
||||
{
|
||||
JSON::String printEncodedString(const std::vector<SegmentInformation> &polyline) const;
|
||||
|
||||
JSON::Array printUnencodedString(const std::vector<SegmentInformation> &polyline) const;
|
||||
};
|
||||
|
||||
#endif /* POLYLINE_FORMATTER_HPP */
|
||||
@@ -54,7 +54,7 @@ template <class DataFacadeT, class SegmentT> struct ExtractRouteNames
|
||||
|
||||
for (const SegmentT &segment : segment_list)
|
||||
{
|
||||
if (segment.name_id != blocked_name_id && segment.length > result_segment.length)
|
||||
if (segment.name_id != blocked_name_id && segment.length > result_segment.length && segment.name_id != 0)
|
||||
{
|
||||
result_segment = segment;
|
||||
}
|
||||
@@ -111,7 +111,7 @@ template <class DataFacadeT, class SegmentT> struct ExtractRouteNames
|
||||
shortest_path_set_difference.end(),
|
||||
length_comperator);
|
||||
shortest_segment_2 =
|
||||
PickNextLongestSegment(shortest_path_set_difference, shortest_path_segments[0].name_id);
|
||||
PickNextLongestSegment(shortest_path_set_difference, shortest_segment_1.name_id);
|
||||
|
||||
// compute the set difference (for alternative path) depending on names between shortest and
|
||||
// alternative
|
||||
@@ -138,7 +138,7 @@ template <class DataFacadeT, class SegmentT> struct ExtractRouteNames
|
||||
if (!alternative_path_segments.empty())
|
||||
{
|
||||
alternative_segment_2 = PickNextLongestSegment(alternative_path_set_difference,
|
||||
alternative_path_segments[0].name_id);
|
||||
alternative_segment_1.name_id);
|
||||
}
|
||||
|
||||
// move the segments into the order in which they occur.
|
||||
@@ -0,0 +1,253 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef TINY_COMPONENTS_HPP
|
||||
#define TINY_COMPONENTS_HPP
|
||||
|
||||
#include "../typedefs.h"
|
||||
#include "../data_structures/deallocating_vector.hpp"
|
||||
#include "../data_structures/import_edge.hpp"
|
||||
#include "../data_structures/query_node.hpp"
|
||||
#include "../data_structures/percent.hpp"
|
||||
#include "../data_structures/restriction.hpp"
|
||||
#include "../data_structures/restriction_map.hpp"
|
||||
#include "../data_structures/turn_instructions.hpp"
|
||||
|
||||
#include "../Util/integer_range.hpp"
|
||||
#include "../Util/simple_logger.hpp"
|
||||
#include "../Util/std_hash.hpp"
|
||||
#include "../Util/timing_util.hpp"
|
||||
|
||||
#include <osrm/Coordinate.h>
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <tbb/parallel_sort.h>
|
||||
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include <memory>
|
||||
#include <stack>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
template <typename GraphT>
|
||||
class TarjanSCC
|
||||
{
|
||||
struct TarjanStackFrame
|
||||
{
|
||||
explicit TarjanStackFrame(NodeID v, NodeID parent) : v(v), parent(parent) {}
|
||||
NodeID v;
|
||||
NodeID parent;
|
||||
};
|
||||
|
||||
struct TarjanNode
|
||||
{
|
||||
TarjanNode() : index(SPECIAL_NODEID), low_link(SPECIAL_NODEID), on_stack(false) {}
|
||||
unsigned index;
|
||||
unsigned low_link;
|
||||
bool on_stack;
|
||||
};
|
||||
|
||||
std::vector<unsigned> components_index;
|
||||
std::vector<NodeID> component_size_vector;
|
||||
std::shared_ptr<GraphT> m_node_based_graph;
|
||||
std::unordered_set<NodeID> barrier_node_set;
|
||||
RestrictionMap m_restriction_map;
|
||||
unsigned size_one_counter;
|
||||
|
||||
public:
|
||||
template<class ContainerT>
|
||||
TarjanSCC(std::shared_ptr<GraphT> graph,
|
||||
const RestrictionMap &restrictions,
|
||||
const ContainerT &barrier_node_list)
|
||||
: components_index(graph->GetNumberOfNodes(), SPECIAL_NODEID),
|
||||
m_node_based_graph(graph), m_restriction_map(restrictions),
|
||||
size_one_counter(0)
|
||||
{
|
||||
barrier_node_set.insert(std::begin(barrier_node_list), std::end(barrier_node_list));
|
||||
BOOST_ASSERT(m_node_based_graph->GetNumberOfNodes() > 0);
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
TIMER_START(SCC_RUN);
|
||||
// The following is a hack to distinguish between stuff that happens
|
||||
// before the recursive call and stuff that happens after
|
||||
std::stack<TarjanStackFrame> recursion_stack;
|
||||
// true = stuff before, false = stuff after call
|
||||
std::stack<NodeID> tarjan_stack;
|
||||
std::vector<TarjanNode> tarjan_node_list(m_node_based_graph->GetNumberOfNodes());
|
||||
unsigned component_index = 0, size_of_current_component = 0;
|
||||
int index = 0;
|
||||
const NodeID last_node = m_node_based_graph->GetNumberOfNodes();
|
||||
std::vector<bool> processing_node_before_recursion(m_node_based_graph->GetNumberOfNodes(), true);
|
||||
for(const NodeID node : osrm::irange(0u, last_node))
|
||||
{
|
||||
if (SPECIAL_NODEID == components_index[node])
|
||||
{
|
||||
recursion_stack.emplace(TarjanStackFrame(node, node));
|
||||
}
|
||||
|
||||
while (!recursion_stack.empty())
|
||||
{
|
||||
TarjanStackFrame currentFrame = recursion_stack.top();
|
||||
const NodeID u = currentFrame.parent;
|
||||
const NodeID v = currentFrame.v;
|
||||
recursion_stack.pop();
|
||||
|
||||
const bool before_recursion = processing_node_before_recursion[v];
|
||||
|
||||
if (before_recursion && tarjan_node_list[v].index != UINT_MAX)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (before_recursion)
|
||||
{
|
||||
// Mark frame to handle tail of recursion
|
||||
recursion_stack.emplace(currentFrame);
|
||||
processing_node_before_recursion[v] = false;
|
||||
|
||||
// Mark essential information for SCC
|
||||
tarjan_node_list[v].index = index;
|
||||
tarjan_node_list[v].low_link = index;
|
||||
tarjan_stack.push(v);
|
||||
tarjan_node_list[v].on_stack = true;
|
||||
++index;
|
||||
|
||||
const NodeID to_node_of_only_restriction =
|
||||
m_restriction_map.CheckForEmanatingIsOnlyTurn(u, v);
|
||||
|
||||
for (const auto current_edge : m_node_based_graph->GetAdjacentEdgeRange(v))
|
||||
{
|
||||
const auto vprime = m_node_based_graph->GetTarget(current_edge);
|
||||
|
||||
// Traverse outgoing edges
|
||||
if (barrier_node_set.find(v) != barrier_node_set.end() &&
|
||||
u != vprime)
|
||||
{
|
||||
// continue;
|
||||
}
|
||||
|
||||
|
||||
if (to_node_of_only_restriction != std::numeric_limits<unsigned>::max() &&
|
||||
vprime == to_node_of_only_restriction)
|
||||
{
|
||||
// At an only_-restriction but not at the right turn
|
||||
// continue;
|
||||
}
|
||||
|
||||
if (m_restriction_map.CheckIfTurnIsRestricted(u, v, vprime))
|
||||
{
|
||||
// continue;
|
||||
}
|
||||
|
||||
if (SPECIAL_NODEID == tarjan_node_list[vprime].index)
|
||||
{
|
||||
recursion_stack.emplace(TarjanStackFrame(vprime, v));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tarjan_node_list[vprime].on_stack &&
|
||||
tarjan_node_list[vprime].index < tarjan_node_list[v].low_link)
|
||||
{
|
||||
tarjan_node_list[v].low_link = tarjan_node_list[vprime].index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
processing_node_before_recursion[v] = true;
|
||||
tarjan_node_list[currentFrame.parent].low_link =
|
||||
std::min(tarjan_node_list[currentFrame.parent].low_link,
|
||||
tarjan_node_list[v].low_link);
|
||||
// after recursion, lets do cycle checking
|
||||
// Check if we found a cycle. This is the bottom part of the recursion
|
||||
if (tarjan_node_list[v].low_link == tarjan_node_list[v].index)
|
||||
{
|
||||
NodeID vprime;
|
||||
do
|
||||
{
|
||||
vprime = tarjan_stack.top();
|
||||
tarjan_stack.pop();
|
||||
tarjan_node_list[vprime].on_stack = false;
|
||||
components_index[vprime] = component_index;
|
||||
++size_of_current_component;
|
||||
} while (v != vprime);
|
||||
|
||||
component_size_vector.emplace_back(size_of_current_component);
|
||||
|
||||
if (size_of_current_component > 1000)
|
||||
{
|
||||
SimpleLogger().Write() << "large component [" << component_index
|
||||
<< "]=" << size_of_current_component;
|
||||
}
|
||||
|
||||
++component_index;
|
||||
size_of_current_component = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TIMER_STOP(SCC_RUN);
|
||||
SimpleLogger().Write() << "SCC run took: " << TIMER_MSEC(SCC_RUN)/1000. << "s";
|
||||
|
||||
size_one_counter = std::count_if(component_size_vector.begin(),
|
||||
component_size_vector.end(),
|
||||
[](unsigned value)
|
||||
{
|
||||
return 1 == value;
|
||||
});
|
||||
}
|
||||
|
||||
std::size_t get_number_of_components() const
|
||||
{
|
||||
return component_size_vector.size();
|
||||
}
|
||||
|
||||
unsigned get_size_one_count() const
|
||||
{
|
||||
return size_one_counter;
|
||||
}
|
||||
|
||||
unsigned get_component_size(const NodeID node) const
|
||||
{
|
||||
return component_size_vector[components_index[node]];
|
||||
}
|
||||
|
||||
unsigned get_component_id(const NodeID node) const
|
||||
{
|
||||
return components_index[node];
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* TINY_COMPONENTS_HPP */
|
||||
+13
-2
@@ -23,6 +23,7 @@ platform: x64
|
||||
|
||||
install:
|
||||
# by default, all script lines are interpreted as batch
|
||||
- nuget install protobuf
|
||||
- cd c:\projects\osrm
|
||||
- curl -O http://build.project-osrm.org/libs_osrm_%Configuration%.7z
|
||||
- 7z x libs_osrm_%Configuration%.7z | find ":"
|
||||
@@ -33,12 +34,22 @@ build_script:
|
||||
- cd build
|
||||
- echo Running cmake...
|
||||
- call "%VS120COMNTOOLS%\..\..\VC\vcvarsall.bat" x86_amd64
|
||||
- SET PATH=C:\Program Files (x86)\MSBuild\12.0\bin\;%PATH%
|
||||
- SET P=c:/projects/osrm
|
||||
- set TBB_INSTALL_DIR=%P%/tbb
|
||||
- set TBB_ARCH_PLATFORM=intel64/vc12
|
||||
- cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=%Configuration% -DBZIP2_INCLUDE_DIR=%P%/libs/include -DBZIP2_LIBRARIES=%P%/libs/lib/libbz2.lib -DCMAKE_INSTALL_PREFIX=%P%/libs -DBOOST_ROOT=%P%/boost_min -DBoost_USE_STATIC_LIBS=ON
|
||||
- nmake
|
||||
- cmake .. -G "Visual Studio 12 Win64" -DCMAKE_BUILD_TYPE=%Configuration% -DCMAKE_INSTALL_PREFIX=%P%/libs -DBOOST_ROOT=%P%/boost_min -DBoost_ADDITIONAL_VERSIONS=1.57 -DBoost_USE_STATIC_LIBS=ON -T CTP_Nov2013
|
||||
- msbuild /clp:Verbosity=minimal /nologo OSRM.sln
|
||||
- msbuild /clp:Verbosity=minimal /nologo tests.vcxproj
|
||||
- cd %Configuration%
|
||||
- if "%APPVEYOR_REPO_BRANCH%"=="develop" (7z a %P%/osrm_%Configuration%.zip *.exe *.pdb %P%/libs/bin/*.dll -tzip)
|
||||
- cd ..\..\profiles
|
||||
- echo disk=c:\temp\stxxl,10000,wincall > .stxxl.txt
|
||||
- if "%APPVEYOR_REPO_BRANCH%"=="develop" (7z a %P%/osrm_%Configuration%.zip * -tzip)
|
||||
- set PATH=%PATH%;c:/projects/osrm/libs/bin
|
||||
- cd c:/projects/osrm/build/%Configuration%
|
||||
- datastructure-tests.exe
|
||||
- algorithm-tests.exe
|
||||
|
||||
test: off
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user