Compare commits
2040 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 966f1d654e | |||
| 02adaac468 | |||
| 2b2a0d685f | |||
| 6f2ec17640 | |||
| 6c158f5a1b | |||
| df83dfdfe8 | |||
| 165c252fc8 | |||
| d21f63d327 | |||
| 05c33bee78 | |||
| 762dd17512 | |||
| 5f7065848e | |||
| 65e020a627 | |||
| 793e477898 | |||
| a5232f857e | |||
| 0ef7a72b33 | |||
| 717787ff62 | |||
| 2d599a5190 | |||
| e73145d558 | |||
| 220e7748a9 | |||
| 72f41c5b4f | |||
| 775627473a | |||
| ba2356d2ba | |||
| 179f53b21b | |||
| 3ccd3b5650 | |||
| 224655f8cb | |||
| fd96c7c488 | |||
| 45c96f73c2 | |||
| c5893ef6e8 | |||
| 8b1f09d302 | |||
| cb1b824a75 | |||
| b0ce9e4af7 | |||
| aae3637e0c | |||
| 33faa2f252 | |||
| 482d79ef4b | |||
| 6bdd517c43 | |||
| a337109618 | |||
| 0ae5ace520 | |||
| a4306cddef | |||
| 1f97c5518e | |||
| 1823a4da36 | |||
| d60caf7095 | |||
| 9e10b94339 | |||
| 7048dd754d | |||
| de29e17d95 | |||
| c299989ff7 | |||
| 0b655ea6a1 | |||
| 538827942a | |||
| 8bd5f69e04 | |||
| c470ea9fa1 | |||
| c1806476af | |||
| af41c9f6e4 | |||
| 823e8d24b5 | |||
| 4028c0b24f | |||
| 2e4ff30103 | |||
| 121dcca7e3 | |||
| 5adfe2d46b | |||
| 03f4aaa2d6 | |||
| d67c3f36ff | |||
| e199d30beb | |||
| 27e2de2b1f | |||
| 8a6d07342e | |||
| ab39457fe1 | |||
| e6933ea413 | |||
| 422e0c44d5 | |||
| ad03b409ab | |||
| 38ae213260 | |||
| 6a0a59896e | |||
| 187cb56364 | |||
| 1fe96d0d22 | |||
| 52b859b3e6 | |||
| 9483b781e2 | |||
| 791f475168 | |||
| 6b69d6dce2 | |||
| 720abbc81e | |||
| e3183cfd16 | |||
| e07423f260 | |||
| ecfda146b2 | |||
| f923f508f5 | |||
| b465dabe77 | |||
| d8d6b91257 | |||
| 0946fac11f | |||
| c50b69c654 | |||
| 32bf99ba40 | |||
| 0baa8215ef | |||
| 85a007d87b | |||
| 7b14de13ec | |||
| 117ebe1c32 | |||
| 2b010811d8 | |||
| 4b94f1fa83 | |||
| d73f3ebd1b | |||
| 4c48cda4cd | |||
| 9e64ccdbf2 | |||
| aedf9d3a91 | |||
| 0ee94a5729 | |||
| 2130630293 | |||
| 445cf5d42c | |||
| 08f13a1776 | |||
| f406dc51fa | |||
| 7580777e43 | |||
| ea30005762 | |||
| 7794cd6274 | |||
| 45a4fe44f7 | |||
| 1d225078eb | |||
| 533caf8c0f | |||
| e6c25ae290 | |||
| 264077acac | |||
| 0ff18881b6 | |||
| 9e0e536dbc | |||
| 1a9e54ba33 | |||
| 9378af1057 | |||
| cd6075a884 | |||
| 1da3a00b92 | |||
| 275961f088 | |||
| f14fac3f7d | |||
| ce784e0491 | |||
| 65ad3bb941 | |||
| b5b4280c3b | |||
| 0649f6e607 | |||
| 22c2efded9 | |||
| 7825279405 | |||
| 2623c7023c | |||
| 2138fdfadf | |||
| 40517e3010 | |||
| 1341214044 | |||
| 34e2ef13cf | |||
| 058219528d | |||
| f4bd175616 | |||
| fea0c07e1c | |||
| f684fa9a7b | |||
| 2855b94aa8 | |||
| 9958aaae4f | |||
| 289e5ada2c | |||
| 648eed6532 | |||
| d94955d51e | |||
| 046fe93f1f | |||
| ce60af5029 | |||
| dbe70ffc8a | |||
| 8acf081be3 | |||
| c5f6065280 | |||
| 07509ba5c9 | |||
| 8b3c8f7093 | |||
| c3e0b68399 | |||
| f0dd1fdfc7 | |||
| 5fd8c0938a | |||
| b3f4aa4504 | |||
| 4718cf6cc0 | |||
| ac07c78664 | |||
| 4a3db7e2c3 | |||
| a23158f986 | |||
| 838322299a | |||
| 41f3f53540 | |||
| a26d982f52 | |||
| 5e4121ac58 | |||
| 81d8c8f9bf | |||
| 0c34addfa7 | |||
| 6a68fe6a4f | |||
| 0d246a4422 | |||
| 991c9f2f8b | |||
| ffd36b5489 | |||
| b9149658a8 | |||
| 21ff3fbccd | |||
| 90efbefbec | |||
| 8f89d75edc | |||
| 5d082f53ae | |||
| 591d79ba49 | |||
| 5ee6ede824 | |||
| 095a58b1bd | |||
| fd2f000075 | |||
| bb244646df | |||
| 238dd07cf6 | |||
| aea5e446e5 | |||
| 203beff4d2 | |||
| cb6f4ad646 | |||
| f7b72dd136 | |||
| 96aff57275 | |||
| 4b46d07380 | |||
| 204f7c918e | |||
| b1c83e6588 | |||
| c55bd11377 | |||
| 885a9df356 | |||
| 0a373018c6 | |||
| 8c4c1a56fd | |||
| de790c7c19 | |||
| 3c2bf76103 | |||
| 13bc41fc36 | |||
| 758027e2e0 | |||
| 25b352aeab | |||
| b030fe7db2 | |||
| 9b09c9f0c3 | |||
| de73809bb9 | |||
| 7144f69683 | |||
| c3396fa6fd | |||
| 924a41a2f4 | |||
| a492bf3885 | |||
| 662714fca3 | |||
| 4fc4e93ab5 | |||
| d0b5929a9e | |||
| 58dc98460b | |||
| e0dd4848b0 | |||
| cef01f5dbc | |||
| 88af9c545b | |||
| cd1f45e248 | |||
| d5eee3138f | |||
| fdfe0ce63d | |||
| ba6641ed9a | |||
| fb13e3ddb8 | |||
| ca17efd764 | |||
| dd104a49f6 | |||
| b849d008d2 | |||
| 1e09935501 | |||
| d7e558350b | |||
| 04afe8fbf1 | |||
| 392726bad3 | |||
| 19285d61ab | |||
| 015b29e8a3 | |||
| aff61dbc3e | |||
| 37f5d755f1 | |||
| 98cd3465d3 | |||
| 009f08dca3 | |||
| 2edf4906a4 | |||
| ee6c15b997 | |||
| 03df07e4b6 | |||
| 501f2f8267 | |||
| e949677c48 | |||
| b2512915ae | |||
| dc9db06cc8 | |||
| cb5931aaeb | |||
| da17e55657 | |||
| f47d944349 | |||
| 682079adc6 | |||
| f0fb97e67c | |||
| 6e5058f95f | |||
| 31b8997518 | |||
| 76a9723268 | |||
| 5fe79764de | |||
| 186859fcf0 | |||
| b545d60453 | |||
| f68a046080 | |||
| f77fa5b34c | |||
| 38bf0c276c | |||
| ef5c8c24a8 | |||
| 4e8fb92e07 | |||
| 4f1ff5b24c | |||
| 22abc27b6b | |||
| 19f6d885fe | |||
| b19a633441 | |||
| 997dcad799 | |||
| e35efd001c | |||
| 50d6b10be4 | |||
| 5ef7ea794a | |||
| e70485f1fd | |||
| f55f8a3629 | |||
| fbbd6caf97 | |||
| bde3f95ae9 | |||
| a5c406a4dd | |||
| 58a57543ce | |||
| e32bc5e186 | |||
| 7a5f45ac94 | |||
| 657f7577bf | |||
| 48355447f9 | |||
| c8f7e6331b | |||
| 40bb27c95f | |||
| 78f8124c63 | |||
| 94d5bcbf1c | |||
| ad5d8c6f9a | |||
| 4911601b24 | |||
| cb86d3d829 | |||
| 24c6314f1a | |||
| 02e2b3bd47 | |||
| ec84b3a0ca | |||
| 4455e816aa | |||
| 3df89c0dfe | |||
| f5d22c904f | |||
| 2233c44d36 | |||
| d5f6c1c15c | |||
| e36a27307b | |||
| cf527ed819 | |||
| a8e8833a8d | |||
| 349df0dc94 | |||
| 0e33f638e6 | |||
| 50ccfbf554 | |||
| e2c093856c | |||
| 992458ae4b | |||
| 8c16686150 | |||
| 7cbadfbd12 | |||
| 0e43697ee0 | |||
| 7de27df309 | |||
| b06db1ba39 | |||
| 5fe24cb689 | |||
| 733d1384a4 | |||
| 99e9d0d023 | |||
| 2bd1e46ab9 | |||
| cabaad4b17 | |||
| 8b6fe691ed | |||
| ccf9efdaa5 | |||
| bf66bec4c7 | |||
| 3319709526 | |||
| 7ceab5c88c | |||
| 94d4789e68 | |||
| b13985d550 | |||
| dc4a3e9b89 | |||
| d538c35532 | |||
| cfd26321b5 | |||
| 61d955f3de | |||
| a9f54c44e9 | |||
| 125877035f | |||
| 8f4b0c8078 | |||
| 1863e85bf5 | |||
| 488c6099fc | |||
| 67abc6d2cf | |||
| c56a57c0ba | |||
| 30b2c1ad61 | |||
| 5e279363e4 | |||
| abb7509f03 | |||
| 1cd60c05f3 | |||
| 510cc22484 | |||
| 3da664236c | |||
| 7e35a7fe0c | |||
| 58ef7db5d6 | |||
| f9de4a394c | |||
| dced5816df | |||
| 690ac740d2 | |||
| 89d0412e22 | |||
| a305752faf | |||
| 469b139e89 | |||
| 8f5d9c4816 | |||
| 7102c77e0b | |||
| 115ae21f1f | |||
| 8d3fdf45b9 | |||
| 1e7e5ea57c | |||
| 7c8b91456f | |||
| dc960f30f5 | |||
| ba12e31280 | |||
| 027a4081a2 | |||
| 190def17e5 | |||
| 9730526d33 | |||
| c87c843308 | |||
| 6453cdf0d6 | |||
| 5f80c33b24 | |||
| a33542c9b5 | |||
| 3a1d98648f | |||
| 4ec79d61d0 | |||
| b4f055f80c | |||
| 6bf35c679f | |||
| 3349d43c00 | |||
| ced961d24c | |||
| 419f708d87 | |||
| bbc1c04042 | |||
| 7a6865637d | |||
| ae96420925 | |||
| 2822812d0d | |||
| c8ab430491 | |||
| bb87f28e80 | |||
| 6db671215a | |||
| 64566ec6cf | |||
| faaf97ef62 | |||
| 67d6efed21 | |||
| 571d9bd610 | |||
| 4144698540 | |||
| 9bf6bf2c78 | |||
| cc9236b8db | |||
| 0103b59e61 | |||
| e9f6531db7 | |||
| 62c2c750ea | |||
| 3e5e3175e0 | |||
| 54c5af30d9 | |||
| ca4a3361c0 | |||
| 47d302221d | |||
| ed215657e6 | |||
| 3e63b14192 | |||
| 86433ab3a8 | |||
| 7214800d93 | |||
| 29f298fa4a | |||
| ef35bc77cb | |||
| 6ae880f61e | |||
| 0d1149310c | |||
| 51d32bb8d3 | |||
| 49a8980dea | |||
| 9fe1680c56 | |||
| b7db65a023 | |||
| 4c02002265 | |||
| d0198649f2 | |||
| 32c1fd082d | |||
| 363bf42b95 | |||
| a1ab2232f3 | |||
| cf69f43166 | |||
| 9833438733 | |||
| 67c5e3966a | |||
| aa0927911d | |||
| 13c9e1ed58 | |||
| 19a457ab7d | |||
| 0926bff0cc | |||
| 53a0bc963a | |||
| a2819d822a | |||
| 175112d97d | |||
| dced47024f | |||
| ffc361406e | |||
| 852c648235 | |||
| 1197b96c49 | |||
| f21fe81e16 | |||
| 593dfd0108 | |||
| aaf0fb9d12 | |||
| 02e9f8aef3 | |||
| 424055c04e | |||
| 02daf17326 | |||
| a666f0d52e | |||
| 27a760c58c | |||
| 0ba12f48c6 | |||
| eaaf54d886 | |||
| 4b3d634fe9 | |||
| f77a699ea4 | |||
| e989e38cc2 | |||
| 6a900ed6e7 | |||
| 29e6b85f79 | |||
| 2641408d53 | |||
| 5b79226183 | |||
| 98f9f0cd48 | |||
| cf7e107ad1 | |||
| ab66c1aa1b | |||
| 5b03366909 | |||
| 7824e1446a | |||
| 59cf1a4937 | |||
| 252113c838 | |||
| e2f84d1acd | |||
| 204dcecb28 | |||
| 70bbfbea12 | |||
| 2221a0a908 | |||
| 203b215093 | |||
| 76ee84dae8 | |||
| 79e1c87a01 | |||
| ed208114be | |||
| 7dd711b37c | |||
| 4852802d66 | |||
| c495b1faab | |||
| eb5bd8e6ac | |||
| ff7dcf9c17 | |||
| 2b12a16c84 | |||
| 4d00b2ebbb | |||
| 1ba5abbaef | |||
| b87a98bbda | |||
| f76361a345 | |||
| f25bab9555 | |||
| ed78b8429f | |||
| 94e9dd8f28 | |||
| 90215ca0dd | |||
| 34eb647fcb | |||
| 83205290de | |||
| 02fd528c32 | |||
| e05193f46d | |||
| 14e2d900b5 | |||
| ba4290340d | |||
| 5a04700bae | |||
| 999f50dce9 | |||
| 9522e6e714 | |||
| 7836ea4479 | |||
| 37e8ab8de1 | |||
| 34048497e7 | |||
| 5197422482 | |||
| d9987c2734 | |||
| c9671b4712 | |||
| bbf03e3060 | |||
| e35a78e3cf | |||
| e318be6a88 | |||
| 1dab0ebc25 | |||
| 687e58e9d4 | |||
| 993a4aa675 | |||
| c991510b0f | |||
| c8025bf004 | |||
| 9f5767a80c | |||
| ffb05d6271 | |||
| 2dd2d3dd7b | |||
| be29c7fca0 | |||
| 2c23a3c0b3 | |||
| 37e3ead8e9 | |||
| b018ea7b1b | |||
| d6cdca35d4 | |||
| a09d150b47 | |||
| 7cf46afc48 | |||
| 056c95670f | |||
| 35dffe43d9 | |||
| 19c26f0733 | |||
| 388ff10ff5 | |||
| 8c7be8e45f | |||
| 579aa67cde | |||
| 725f86a0d2 | |||
| 50a6ef18d2 | |||
| 1b3e924450 | |||
| a33e08e299 | |||
| 45dee5a666 | |||
| 642473244e | |||
| e92f344335 | |||
| 7951795ea4 | |||
| 101fbcca90 | |||
| d562132a4a | |||
| 7152ab39ff | |||
| 39c5279f5d | |||
| fef0e16f9c | |||
| fb1361b00d | |||
| 64c75c8b57 | |||
| f4e015a255 | |||
| 242b68c488 | |||
| 9452c7e0c7 | |||
| ab1d3d1ced | |||
| 41df92bb93 | |||
| 427db3f29a | |||
| b5600bdd7f | |||
| a2153b668a | |||
| 7d52c82c3b | |||
| 092f1a4959 | |||
| 21bee7e40c | |||
| a9ac0ac725 | |||
| 5dc1ed6696 | |||
| b55f66e69c | |||
| ab637e22b1 | |||
| fa665c5494 | |||
| e91b75a1bb | |||
| 4c6f85fd25 | |||
| f09e9b7790 | |||
| b51d3da7e5 | |||
| 861dbd5977 | |||
| 5001fcdd53 | |||
| eeb47dc724 | |||
| 5556dff11e | |||
| 18b57fa6aa | |||
| 12bb4d75fd | |||
| 411d8d4d98 | |||
| 748df0b21a | |||
| 8d98316a89 | |||
| c6b45a8e09 | |||
| d42920674a | |||
| c66fced161 | |||
| d3dee115ab | |||
| 77aa965533 | |||
| 29499f21c5 | |||
| 18d8968ae7 | |||
| 467cf73635 | |||
| 457519eae3 | |||
| 2a1c24763d | |||
| 92196dc207 | |||
| f73723f9af | |||
| 26ab8755b6 | |||
| d91382208d | |||
| 5f90ed8b3e | |||
| 644fad8355 | |||
| c4904cc365 | |||
| 613e38d7f8 | |||
| dee7c339b3 | |||
| b80cda66a9 | |||
| 411bcbcbde | |||
| 352bf8839b | |||
| 18f438a528 | |||
| 076944da5d | |||
| acbba95032 | |||
| 75f77783ff | |||
| 87e0f074e8 | |||
| 2211c69455 | |||
| a7449c913c | |||
| aaec0e641b | |||
| 5afed2d396 | |||
| 843348338a | |||
| 061ebc7942 | |||
| 822c1c97e3 | |||
| 65df6aa4a0 | |||
| 32719690ac | |||
| f83748fdc2 | |||
| a354d7c00b | |||
| 41f7312263 | |||
| d3804d2c2c | |||
| 96184b83a3 | |||
| 9bcc057176 | |||
| 20f3213477 | |||
| bf8505a285 | |||
| 770a07cc28 | |||
| 3f80f52ca5 | |||
| 52f6e149ec | |||
| 6893df9103 | |||
| 60546c9788 | |||
| 12f91564fb | |||
| ca448e682a | |||
| 2b077d140f | |||
| 0f58ff8356 | |||
| 940b740b24 | |||
| 0f258f94a8 | |||
| fd7b22f639 | |||
| ca3464512d | |||
| f59cb6417f | |||
| 74ccb53607 | |||
| e4c6e98099 | |||
| cfab0fa245 | |||
| 08d861e87c | |||
| 73234e7782 | |||
| de8d28ea5f | |||
| ed7b478ee0 | |||
| ff9a216990 | |||
| 58c94159b1 | |||
| 7a1bd4d53a | |||
| 5d7c23c62a | |||
| d91d911051 | |||
| cd0cab465d | |||
| a45b887c5b | |||
| f965b7129b | |||
| e894ce00c9 | |||
| 333aba8be6 | |||
| e9d93ae210 | |||
| 043c8be747 | |||
| 1be67518df | |||
| 4bf1987bb7 | |||
| ae45eed2b1 | |||
| 572a9393aa | |||
| 7579c41a35 | |||
| 4e589c2575 | |||
| 026da34ce9 | |||
| 0daf49a1da | |||
| f57e4c6c14 | |||
| 14bd1d01f2 | |||
| 918e20b164 | |||
| 6a0e90ef90 | |||
| 71fe8ed80d | |||
| 581c9c570b | |||
| b25fe3d127 | |||
| fc4aef6d89 | |||
| 6b4fa6a40d | |||
| 6756eea209 | |||
| bf3cd37b49 | |||
| cc7caa9e16 | |||
| 633060562f | |||
| cc48546f62 | |||
| 96cc44e521 | |||
| f2d9e4b2df | |||
| 049c7ad1f0 | |||
| 226dad651b | |||
| 0977cabc79 | |||
| 0b5e8a086e | |||
| e024ea5ee1 | |||
| 6f71092aa4 | |||
| edce44df97 | |||
| 54551d9f37 | |||
| 8521b5501f | |||
| 396dc21903 | |||
| 5e2b0ba46c | |||
| cce5d775de | |||
| 248a239c7b | |||
| 83655e9aef | |||
| 973d115edf | |||
| aaa9f89550 | |||
| 8afad5614a | |||
| a9fdabf926 | |||
| b5b262c722 | |||
| d1e1190cbd | |||
| 9812eaaca7 | |||
| 4520e04d37 | |||
| 5679b5862f | |||
| e72dc38d77 | |||
| 71fcfa4935 | |||
| c4463036c3 | |||
| b343a17b29 | |||
| 0b0fb249bf | |||
| 8d689974a7 | |||
| 375c81d38d | |||
| 0ef4f36d44 | |||
| c85f6c1228 | |||
| 0cabc81693 | |||
| 12b4fff81e | |||
| 27b6627110 | |||
| 387014dd37 | |||
| d5c91b9bda | |||
| 370f4f6257 | |||
| 49a665488e | |||
| 29da133726 | |||
| 1194bb8ae3 | |||
| 7599124aa0 | |||
| 01d2d91ecc | |||
| 6980d19214 | |||
| ac14a7b0da | |||
| 23f00ab533 | |||
| 39122bd61d | |||
| c5824765f9 | |||
| 547e942c66 | |||
| 2ab04e7e2f | |||
| a08fef172e | |||
| a04f77e7e0 | |||
| 4900f3e54d | |||
| 34ee6411d5 | |||
| 5abe7bc7e5 | |||
| a48aef4039 | |||
| e1198f29ce | |||
| 329e619c8c | |||
| 9a9e1b46ef | |||
| cc94ab6411 | |||
| e67541e82f | |||
| d907be264b | |||
| 003c1df53e | |||
| 6470838065 | |||
| a178555838 | |||
| f844e9e702 | |||
| 8753dbdb0f | |||
| 1bd24f7042 | |||
| 66d58bf047 | |||
| 1e5c4b0d79 | |||
| 711d402f17 | |||
| e19f54a378 | |||
| 5294fc4767 | |||
| 7ed3a1df04 | |||
| 2d45354f50 | |||
| 9f6d13f4c3 | |||
| 57a31d0ec9 | |||
| da277d9816 | |||
| 22dabc5180 | |||
| 47f11fc3a6 | |||
| 91a2e56215 | |||
| e6681af9d0 | |||
| d9e3c43c91 | |||
| f84de4ac21 | |||
| 3089231476 | |||
| 0f94fb9d6d | |||
| 01097f7225 | |||
| a25e4e1ed8 | |||
| 9e75595754 | |||
| f6d5945b59 | |||
| 250eb20851 | |||
| d2b00c4995 | |||
| 89c73d89b4 | |||
| fcd63bf9eb | |||
| 9a0cf6a609 | |||
| 6c32d97b23 | |||
| c9e40d3e59 | |||
| dc920a7e39 | |||
| 07262387e0 | |||
| 97e2ac689e | |||
| 286a80d03b | |||
| 3aaf31fdb9 | |||
| 71ae5764cc | |||
| 2e41ed153b | |||
| 9ee422e6ba | |||
| 8a008d1808 | |||
| d78faea737 | |||
| 3cf72e93e6 | |||
| caa02bbca1 | |||
| 33e64aee6f | |||
| d17150270e | |||
| 463a297f0c | |||
| 407d73a735 | |||
| b5bfdb56dc | |||
| 58b7ef8431 | |||
| 2211dfb741 | |||
| 1d6e602473 | |||
| a6c52fd154 | |||
| 7a5bceae4c | |||
| 6f3e7f9e56 | |||
| fb9822b507 | |||
| d0db09cb92 | |||
| 189fbb3f7e | |||
| 887c95fe2a | |||
| fdbeb951eb | |||
| 9d23dee3fc | |||
| 70b8cef318 | |||
| e1620b8fa2 | |||
| dabc9589e9 | |||
| da98900e3a | |||
| b584ba9149 | |||
| d24ba6d13d | |||
| aba078a9d8 | |||
| 161487d6c2 | |||
| d851dd7196 | |||
| cf29621aa7 | |||
| 9e46577f43 | |||
| b7980b83df | |||
| 0a0bed7ae0 | |||
| e42b8fc37d | |||
| b01e30acfd | |||
| 311c50df9f | |||
| c2f9467f61 | |||
| 06c8656b9e | |||
| 4748bca8a4 | |||
| 916387748c | |||
| 216d7dcb86 | |||
| 23f2c7e6f5 | |||
| c8e0e5eca2 | |||
| 3167d3f451 | |||
| beb9c1ba74 | |||
| dcd88260e9 | |||
| 5f4f631fc5 | |||
| dc6fda03a1 | |||
| 764ad81537 | |||
| e26c41095f | |||
| d7bd78d612 | |||
| c50b4c72d7 | |||
| 124e555ed0 | |||
| aeba3aa209 | |||
| e50b5202b8 | |||
| 32c7578629 | |||
| 5bc5e0e8e9 | |||
| 7ee4692e84 | |||
| 679688705d | |||
| 83f0a2c094 | |||
| 504817058b | |||
| 45754b27de | |||
| a75ae8bbef | |||
| c3e6dc69bb | |||
| 0285bb6ea5 | |||
| a542292ce2 | |||
| 0765ebf735 | |||
| e86e8c37a8 | |||
| 149a42cc94 | |||
| 8de4613a3e | |||
| 60950c57e3 | |||
| 4727bb5c9b | |||
| 1e1e254897 | |||
| df5455121c | |||
| 0e2570b204 | |||
| f57519b909 | |||
| 088393ca12 | |||
| 375dc63db3 | |||
| 503324162f | |||
| 5445b64376 | |||
| 7fe997d38c | |||
| d7673dad7b | |||
| 44eed9282b | |||
| 0eeb94b24c | |||
| ef221e1c6c | |||
| 75cdefa4fe | |||
| a609a1c6c2 | |||
| f4906a97b9 | |||
| 21ffd441fa | |||
| a82383d78e | |||
| b405029f0f | |||
| db7d4f56b3 | |||
| 3151197471 | |||
| e06fe6935a | |||
| e7cec83a4c | |||
| e5f0ad4f0b | |||
| cabbe70e47 | |||
| b86c3681bb | |||
| 0f8239bc8e | |||
| 13f5baf608 | |||
| 4f5d7f79bd | |||
| 23899613c3 | |||
| db46a915cc | |||
| b591aa013d | |||
| c0db8b71dd | |||
| 444bf41fa4 | |||
| 54302a53e1 | |||
| 63059cfab3 | |||
| ec7d3a9885 | |||
| 960b55fd6c | |||
| 3067ba60ae | |||
| c9a756eddc | |||
| d4ea5fc74f | |||
| 92e52f1a5d | |||
| ef1d75db83 | |||
| f03d1a5d27 | |||
| 8a55b706ca | |||
| 357133677a | |||
| 1b6c660a8f | |||
| 111e68831e | |||
| d9f6732ce2 | |||
| f2b81ba86c | |||
| 2542112301 | |||
| a45215ddf2 | |||
| cb28b2de07 | |||
| bf0b43aa24 | |||
| 811d6deb41 | |||
| bcdd9374c7 | |||
| f70174d1d1 | |||
| 4a39a4af1c | |||
| 0367399c89 | |||
| c5db4dc15f | |||
| 31fbfa3a70 | |||
| 3515ddcfe6 | |||
| 90303d5952 | |||
| 9a02421091 | |||
| 4961b819f3 | |||
| 61c2ea9225 | |||
| f5f7269f70 | |||
| 03f1430ddc | |||
| c3dab15eb6 | |||
| a4f6ec516b | |||
| 1ca213cec6 | |||
| b782c8560c | |||
| d2e68068bf | |||
| 129a846393 | |||
| 15308931e9 | |||
| 4dffeedd1c | |||
| d0c4111429 | |||
| f579b6f971 | |||
| f5124de327 | |||
| 9ab86ae2bf | |||
| 51a7d3ff50 | |||
| 80b9afc14d | |||
| 92ae8f37ba | |||
| df1f828488 | |||
| d8c97da087 | |||
| 9d29e5d87a | |||
| bf62147802 | |||
| 34735b8aad | |||
| 932b2b9acf | |||
| 7ab4472865 | |||
| e1e79206f9 | |||
| 7ebe6de022 | |||
| b234760e92 | |||
| 3119e4b82b | |||
| 2c3f05e6f1 | |||
| 5b5da8698e | |||
| c3c0c8d881 | |||
| 9de5e31a7a | |||
| dbf15c2db2 | |||
| c9c900b364 | |||
| 5c07204351 | |||
| 828b370ea1 | |||
| de947d8b17 | |||
| 8cb5e68b1a | |||
| 99aef2a178 | |||
| fff1460dfb | |||
| e3b619fd54 | |||
| 29e363e7fb | |||
| c209245b0e | |||
| 4194ce3095 | |||
| a0e9f59e04 | |||
| c940c2722e | |||
| 5c84c12f40 | |||
| 1bcacfab74 | |||
| 1f5f8a76fb | |||
| cfa8b1f0dd | |||
| aecbcdd390 | |||
| 74729a372b | |||
| 63d8abe32f | |||
| 2c397bfa0b | |||
| bfef8f39b7 | |||
| 4430cbc3cb | |||
| ae20bac3c5 | |||
| d9a26c4062 | |||
| 48cb374d94 | |||
| 9d6bd91279 | |||
| 163cfda282 | |||
| 72cda375c8 | |||
| ecb4a08655 | |||
| 05c50bc64f | |||
| 747e4a7061 | |||
| 2b8b876713 | |||
| f13694b539 | |||
| 648f9c9723 | |||
| 0a6c37b726 | |||
| b43a51f912 | |||
| fa328c5a78 | |||
| 728bcc2b10 | |||
| 941903a243 | |||
| 4c8579b340 | |||
| 17416a09f1 | |||
| fdda21b114 | |||
| c75ae957f1 | |||
| 8c678126f1 | |||
| 2b0590f9bd | |||
| a31992aac7 | |||
| 829d2505e3 | |||
| df30498365 | |||
| 5d553bf9f2 | |||
| 03e3673dbb | |||
| 25b8b37f00 | |||
| 665f97e782 | |||
| 48a007febd | |||
| 155e0fada6 | |||
| fe2f1d32b5 | |||
| 2fcbb19e72 | |||
| 06a50d637a | |||
| 811b33e31a | |||
| 54c83ee940 | |||
| 7406e83dde | |||
| dc2c7d5339 | |||
| aaa25e5d48 | |||
| b757bd0ea2 | |||
| dd971d6b7d | |||
| c07966408b | |||
| 2557956b68 | |||
| 735260d21b | |||
| e5b0e43e18 | |||
| aa42b2494c | |||
| f057054172 | |||
| c39314c643 | |||
| ae018b759c | |||
| 556b498e06 | |||
| 19f1110421 | |||
| cc73ed19b3 | |||
| ccb7cc40df | |||
| 6d61e950d6 | |||
| 438c6e616c | |||
| 8d2396b81f | |||
| 9588ef00a5 | |||
| 411603ea03 | |||
| 67addfdb37 | |||
| 3afcd31f61 | |||
| 7ac901cb08 | |||
| fcdee8f5d5 | |||
| a7c32dfa95 | |||
| 36f3c0f77a | |||
| dad4981a57 | |||
| df53357ef1 | |||
| 85e333127a | |||
| d52d86ae82 | |||
| f62293275f | |||
| af490bae8e | |||
| edf5a0f677 | |||
| 5eecd0a57d | |||
| 1fc11a6b06 | |||
| 3516538813 | |||
| e3af8cb2e8 | |||
| 16cd822555 | |||
| 5938368a09 | |||
| 50f865b81c | |||
| 96cd09471b | |||
| cf6c1e97bb | |||
| f557e1efb4 | |||
| 8893fd1656 | |||
| 081831e6ea | |||
| 46c3ce0e34 | |||
| 6031a45c68 | |||
| ca64887cba | |||
| 3f1d67ca4c | |||
| ff09af2812 | |||
| 42b68fa834 | |||
| 2cc2c967d1 | |||
| bec4e4437d | |||
| f9abfbf68a | |||
| 53af4ee39f | |||
| af5f2f85da | |||
| ea83231da5 | |||
| c4693602ef | |||
| 3c8dd85966 | |||
| 0399022d25 | |||
| c6840496c0 | |||
| f7657280b6 | |||
| f88a4baf79 | |||
| b051f715e6 | |||
| 81a05c89e4 | |||
| cc55b016e9 | |||
| ae8e51074e | |||
| 313b93169d | |||
| db148741e9 | |||
| 1ecad20a0d | |||
| 22c5c539c2 | |||
| d59e526e1e | |||
| 94fa0047db | |||
| 26e2f9ddd1 | |||
| 23254b4f24 | |||
| 9a44f16846 | |||
| cad0069be2 | |||
| f315a013b8 | |||
| f780aa6160 | |||
| 0f03beb2b5 | |||
| 7e39c43896 | |||
| 906d28fa5d | |||
| 4d017f5d49 | |||
| 6410314b0b | |||
| 1c0202e790 | |||
| 918c978551 | |||
| 3d1a85bbea | |||
| 1a442c36e9 | |||
| a4e322f085 | |||
| 0b1d268b09 | |||
| c2be6bc019 | |||
| 9e11e832da | |||
| 348e656671 | |||
| 54cdf6d6f2 | |||
| 7c5ca8f199 | |||
| ee42d94e2d | |||
| 91baa9dfd7 | |||
| 572b176401 | |||
| 97f1dc0749 | |||
| d67ac1a708 | |||
| 2707001a3a | |||
| bb1064ac42 | |||
| 436cc692da | |||
| 76decf2e8b | |||
| ccdd0f599a | |||
| c65fed1d38 | |||
| c36ec7c95b | |||
| 305ce04284 | |||
| 034ce137a9 | |||
| 73c81a0a6c | |||
| 7544727f7a | |||
| 961a379f79 | |||
| 9ffcaa5550 | |||
| 2dbae6ce51 | |||
| f7505e8877 | |||
| c453f8e7a9 | |||
| 3a4695713d | |||
| 7d9d0878de | |||
| 26729ca482 | |||
| 405600783e | |||
| 5b5e9296b3 | |||
| dd5d520b53 | |||
| b3d517943a | |||
| 59ca59d431 | |||
| 78c92be14b | |||
| adf0c726ef | |||
| 9ecfed4e56 | |||
| 9db884f371 | |||
| e0c211085c | |||
| 555bfaf37a | |||
| bcf4af4a2f | |||
| 6a71163912 | |||
| cb2fcf4f52 | |||
| 061d78c681 | |||
| 0ffa973ec6 | |||
| 03de87c213 | |||
| 59481dd762 | |||
| 86f4aebead | |||
| a92950d234 | |||
| ccdc6f1a63 | |||
| 62cc8f456c | |||
| f7c6b9a0f7 | |||
| 01a6e3c619 | |||
| 6948d56e5d | |||
| 6373b3e49c | |||
| 91dc1b6639 | |||
| 6317b08090 | |||
| aae0547cca | |||
| 4f9c422e2f | |||
| 3595ac08f7 | |||
| 5339f440bd | |||
| 86d7442a5f | |||
| e6e5626a2c | |||
| 4a52dd1c5b | |||
| dd1302e8b1 | |||
| 7b4b7232fc | |||
| b069725df0 | |||
| aa9d8c773f | |||
| c68a03d05c | |||
| cbea651cf8 | |||
| b4ee345966 | |||
| 296e7ccb08 | |||
| 43bb53e789 | |||
| 384be58230 | |||
| 46d1a87b89 | |||
| 7c8bf18cc6 | |||
| 35255d052d | |||
| cf5c776990 | |||
| 9961172d70 | |||
| c1c46544a6 | |||
| fc24dbf9b7 | |||
| 7f311551dd | |||
| 1a6c01769e | |||
| 9da4e18099 | |||
| b19e2fbafe | |||
| 7f69857376 | |||
| a64420d700 | |||
| 2ccd3da5b3 | |||
| 845c73af73 | |||
| f7d79209dc | |||
| 0017aef89a | |||
| 7449f81ed4 | |||
| 724e96f0c1 | |||
| 8158e7f1c5 | |||
| 7d7baa70a9 | |||
| 2e3947cc6d | |||
| 54774726b2 | |||
| 2af9fcad68 | |||
| fd79e81fe5 | |||
| 2b5e110719 | |||
| 864c2d9f49 | |||
| 764fe533e8 | |||
| f1f59d770e | |||
| 950baaa9fc | |||
| 5b3aacb4b2 | |||
| d6adc56b3a | |||
| dbe1a4255c | |||
| eed20b2271 | |||
| e70adbb1cb | |||
| 06c22a478f | |||
| 565b0e97d1 | |||
| 00168cb12f | |||
| ffdaa71086 | |||
| 5de2aa1cbf | |||
| 64988ed831 | |||
| fa050ad616 | |||
| d2458f3169 | |||
| 551af0e45a | |||
| 4ac5440a4a | |||
| 7c54d4e62f | |||
| 8ab5915983 | |||
| 877865a4b1 | |||
| 7cf4d37595 | |||
| 80add9f820 | |||
| 12a35c1214 | |||
| 9379d2462e | |||
| c5e8bed1fb | |||
| 4aa7ade32c | |||
| c4ed218a7a | |||
| ff417fac01 | |||
| 0f4207f85e | |||
| f4431ed837 | |||
| 0235cf5d8e | |||
| 8fc8a4e303 | |||
| 943c15927a | |||
| 28f0782b17 | |||
| 09e331a76b | |||
| ce43b09991 | |||
| f9ab8426ce | |||
| b869184c10 | |||
| 68e39b8053 | |||
| 6574436c33 | |||
| 8e023418e4 | |||
| bf94866ec0 | |||
| cba3c46820 | |||
| d4db5cca1c | |||
| e4fc633f68 | |||
| 9857fb7696 | |||
| 199b1cbcf8 | |||
| 1d38ba78e8 | |||
| c9ce018b9f | |||
| 9b4e31c5ea | |||
| 1e7a5e881e | |||
| 102e87bcc0 | |||
| 604043e3d8 | |||
| 10513784c7 | |||
| 5e3c8cdd8e | |||
| 5a5b4eb1f7 | |||
| e839cb4b8c | |||
| 5c3dad0c61 | |||
| f4a1d2df96 | |||
| cb6104e0ac | |||
| 00ed039621 | |||
| b247c20dbf | |||
| 81d26d7702 | |||
| 0f106c627b | |||
| ac06a2ef03 | |||
| 2ea5714d95 | |||
| a51c7416d5 | |||
| 2231765c9e | |||
| 18c948a211 | |||
| ec56478a3c | |||
| 7e9614b9ec | |||
| 7f7055a9e7 | |||
| ae106a3a90 | |||
| 29344f55ae | |||
| da6b750378 | |||
| 96c872ac37 | |||
| 51f67f3fa0 | |||
| d3dce3cc25 | |||
| 411d4331d4 | |||
| 18aff1ae40 | |||
| 3ff7febde0 | |||
| f7fdb8b54e | |||
| cc7f761c3e | |||
| b10b716733 | |||
| a255f222ef | |||
| b0f035bf3c | |||
| e41d52570e | |||
| 824724630f | |||
| 85c5da8512 | |||
| d79ebabe03 | |||
| f9cab44bc1 | |||
| 636f69b29f | |||
| 86a5bbac51 | |||
| b182cd1fa4 | |||
| 6f5fc14f59 | |||
| f1d47328e9 | |||
| 9a865384a1 | |||
| 7379c8c387 | |||
| 07f644f7d3 | |||
| 07302c3df8 | |||
| 33bd546588 | |||
| a790ffc2d1 | |||
| 6003ae7406 | |||
| 3c6121d192 | |||
| 12500e4721 | |||
| 166133a496 | |||
| 06914b13e0 | |||
| 36856fd646 | |||
| 870ed96c24 | |||
| aed5848f5a | |||
| 210f586d49 | |||
| 94657a3258 | |||
| 7e9eaaddc4 | |||
| bd3f069f47 | |||
| a2c9b5b6d1 | |||
| c4be1d1423 | |||
| f9d336ff88 | |||
| 2c08adab24 | |||
| 5faf8d6951 | |||
| b51f98fe0c | |||
| 0e3d2cf68d | |||
| 868d6ec776 | |||
| e45b7b4b14 | |||
| 3353e482ef | |||
| 11d4d3ec30 | |||
| 7fda7f1f9b | |||
| 7752f1ade0 | |||
| aeff6c8caa | |||
| 954710d6cc | |||
| 1c50c55a42 | |||
| 504368b293 | |||
| 03f8845998 | |||
| 7d0bd77643 | |||
| 07b6073dcf | |||
| 1ec49c3914 | |||
| f575da2ca8 | |||
| 591a06b25e | |||
| cbe48decd1 | |||
| 6f8148950e | |||
| ac68ff192e | |||
| 629cccc6e1 | |||
| 763cc86043 | |||
| a82c9d55b3 | |||
| 9fc3ed939a | |||
| 90b07cc6b0 | |||
| ac15c787cc | |||
| b5ed992e94 | |||
| 7493d8aa49 | |||
| 2c61d0a79e | |||
| 55e58375eb | |||
| 24321d860c | |||
| e8c7f7b5da | |||
| 263dcbd188 | |||
| 10cf41d138 | |||
| f4fd9dbd38 | |||
| 10b650caf4 | |||
| 75561b8278 | |||
| d89be86e4f | |||
| 6c218960e0 | |||
| 92d4b40379 | |||
| 4c0203c108 | |||
| 8b2629c273 | |||
| c19c97804a | |||
| 313466941b | |||
| 48c6145bdf | |||
| 9dd45cceab | |||
| b6303626b5 | |||
| d1d800025d | |||
| 57dc1e03b1 | |||
| ad5b96d6f2 | |||
| b5f2a98e89 | |||
| 3a706cade7 | |||
| d9af615db9 | |||
| f40550b18c | |||
| 3ec4a049c5 | |||
| dc86007fa9 | |||
| 64d14da0fa | |||
| c83ab666d7 | |||
| 599b96ed95 | |||
| 38ba10ddad | |||
| 8794db633b | |||
| c0287c0f2f | |||
| 6fe931fe4c | |||
| 680d3e7d92 | |||
| c5b1cea58e | |||
| 11d45f5a10 | |||
| 5c737709e2 | |||
| 7282e543ca | |||
| ea90627e02 | |||
| b95596d6b7 | |||
| 7400e60599 | |||
| 6eab47d768 | |||
| 3f039f59de | |||
| 2a89aeecd8 | |||
| 386d4c7e72 | |||
| df9a8a32eb | |||
| fa9eeb95b6 | |||
| 13069632be | |||
| a502da7c0f | |||
| 0b2df9892d | |||
| c6dc476704 | |||
| c5ebef3499 | |||
| 8e756a2476 | |||
| 5e1dc11000 | |||
| bcddc10b6b | |||
| 8e31b8860c | |||
| 794c3490fe | |||
| 216157e00d | |||
| 8e6b7766a1 | |||
| c1a08af00d | |||
| 59025ca2da | |||
| 17fab42f25 | |||
| 4b00557fda | |||
| 30465f08ac | |||
| 6fb2a41a0a | |||
| b70b74080e | |||
| 230fec9cdb | |||
| 17ca6b1e07 | |||
| 628f40f822 | |||
| 0994a7a20d | |||
| 66ff69355d | |||
| 04f71e65ee | |||
| 2b0e46caf2 | |||
| 549ce9a4d4 | |||
| 50d3c2c9d1 | |||
| 82caa357cd | |||
| 217fc4a0ae | |||
| ed8bc7ae58 | |||
| 87ff3f9b9b | |||
| 1bef65bf2c | |||
| b39507efc8 | |||
| 263409ed91 | |||
| 7610af3378 | |||
| 97f04eae91 | |||
| a14db578e2 | |||
| 62f31f3e2d | |||
| db9292ee86 | |||
| 1ad274ed2e | |||
| 57d6af5486 | |||
| 8b482e433a | |||
| d4352b84ac | |||
| b23a89d5a8 | |||
| 681d05f8f4 | |||
| 81b9e3b4cb | |||
| 2798c5a48d | |||
| 77c9f96f44 | |||
| 098454c875 | |||
| 6f00e8c936 | |||
| 3c32cafc9c | |||
| 585558a9ae | |||
| 6635d239b0 | |||
| f14c76dbca | |||
| 0fb747834b | |||
| 11175748bb | |||
| 49b7fffd66 | |||
| e69777d20a | |||
| dde4a496f6 | |||
| 48cb43cc79 | |||
| 4229b22f86 | |||
| 958e28050e | |||
| eae9e4bab7 | |||
| c6dfc7723b | |||
| 334f02d7f8 | |||
| 4c02542dc5 | |||
| 84ffec81ec | |||
| 3673b1a324 | |||
| 8cd28276ea | |||
| 2185bb3327 | |||
| 2d64dca565 | |||
| fad13506a7 | |||
| ffed740fdf | |||
| c0eb1d6967 | |||
| e2b208280e | |||
| f9279a3646 | |||
| e0ff8894a2 | |||
| c97d00c399 | |||
| c16c2adeda | |||
| c4326ffd0b | |||
| 85369d6310 | |||
| bd6f2db1d1 | |||
| 02c11caf7f | |||
| 0d087fcbce | |||
| 9a3735aa21 | |||
| 63229c9b3a | |||
| 17bc61767b | |||
| 5ec198b761 | |||
| 8e15a32229 | |||
| 3c903ddffd | |||
| 28f8edf459 | |||
| dc029ebefd | |||
| bb09cac7f4 | |||
| 937a3f88a4 | |||
| 352ee956cd | |||
| a735d467bf | |||
| 71d148caa8 | |||
| 01dc1af5f4 | |||
| dccb9f2424 | |||
| df819d20b5 | |||
| 518ea7ed01 | |||
| 8abbe8db4a | |||
| e36a517e86 | |||
| 7e5d5a6d90 | |||
| 51c0b129c9 | |||
| 96ba31cc2b | |||
| 74cc50f52b | |||
| 75cd287ab0 | |||
| 09088e71b5 | |||
| 6228c2c89b | |||
| 44b625520b | |||
| 1c415933da | |||
| ac588911ba | |||
| c14ceff9b3 | |||
| e3062cf3a2 | |||
| b448177278 | |||
| bcc7c41140 | |||
| 71d184c39b | |||
| 5423cff7a8 | |||
| aeb701f52e | |||
| b16db9fe68 | |||
| 2faf9ad1b6 | |||
| a8a0d1b216 | |||
| aef6d1795e | |||
| ae8dfcb55e | |||
| 9e6ac95e4f | |||
| 7965e29d49 | |||
| 6d823c62f4 | |||
| cc72409980 | |||
| beadb241a8 | |||
| 86dbcc8df2 | |||
| 4a89cfee3d | |||
| 837e91f56d | |||
| 8050fec64f | |||
| 3e0b4ee1e5 | |||
| eac900c6b8 | |||
| 117e8380e2 | |||
| 69f1bfb337 | |||
| b78e9ce02c | |||
| 3fd2725122 | |||
| 6f7cb3d9f2 | |||
| db0bb3d749 | |||
| e055211960 | |||
| 1b581b1c17 | |||
| d335e7d5e7 | |||
| f5857da6f4 | |||
| aad484b7f7 | |||
| b3ae4f5c7b | |||
| 428783e183 | |||
| d26d3bb574 | |||
| 7bd4e213c2 | |||
| bdcbb8670c | |||
| 3edf4799d3 | |||
| 62c12e7473 | |||
| e0f51dd5e9 | |||
| 7222231abf | |||
| 91080f0690 | |||
| 4c2c1f519c | |||
| 0eb5d8db4e | |||
| e43d27e86d | |||
| 87df312a9d | |||
| 1412c5db42 | |||
| 4c58674393 | |||
| 1fdfac4aaf | |||
| e1fe363268 | |||
| a127c705f2 | |||
| 827b9e4be2 | |||
| 417fcde9db | |||
| 818c66e774 | |||
| f69076f55c | |||
| ebafd25e77 | |||
| b055334e73 | |||
| f112f944aa | |||
| 62951f3ab9 | |||
| 3e25f85eb6 | |||
| e544233abb | |||
| d6fd898101 | |||
| ad610ac904 | |||
| 70c4b293ce | |||
| 41e7dbf205 | |||
| 2901e6891c | |||
| a911089913 | |||
| ac1925d4b9 | |||
| 5d2c2a3107 | |||
| bab2c80857 | |||
| d3d90e10a5 | |||
| 4336931f46 | |||
| 58dfd29a3a | |||
| 66c23b5843 | |||
| ea1fb0a078 | |||
| 0381e0dd9d | |||
| 595579a6c2 | |||
| 2143df2e4f | |||
| c86060f5bb | |||
| 4f2e9e8442 | |||
| 411803919d | |||
| ebc3d09f0f | |||
| c2ab16f984 | |||
| 3f3da4ee0b | |||
| 922c218394 | |||
| d5cb1fa15f | |||
| 2cf175cf91 | |||
| 0276cf579a | |||
| 5dd1211f46 | |||
| 1b98bd2c68 | |||
| 7261ce3b7f | |||
| 80a9317d8b | |||
| 7467e11147 | |||
| 6f78bd7a85 | |||
| 03276ad386 | |||
| 9c1caba2fa | |||
| 5ef3b12673 | |||
| cf1e2fa930 | |||
| 14e110178a | |||
| 4e2650d6e7 | |||
| f60f676563 | |||
| 7fddfd7a54 | |||
| fd88aba8a1 | |||
| f95c040bed | |||
| 459ebc7508 | |||
| 9b17543021 | |||
| 1326c5a01f | |||
| f01670db80 | |||
| bddac87321 | |||
| 176fa301d3 | |||
| f2ce4f0ff1 | |||
| a1affa6330 | |||
| 2c14d34f59 | |||
| 4a299fd4ff | |||
| cfec837278 | |||
| 1bf5ca2bec | |||
| 61efd41194 | |||
| 5ebc4b392f | |||
| 4236f92de2 | |||
| 7f0d40f459 | |||
| 6918c7fe1f | |||
| fa62f70cdf | |||
| 8ddb3fc6ad | |||
| df68c3ad48 | |||
| b7bcc401e7 | |||
| 82ead0a405 | |||
| 5ff2fc9250 | |||
| bbad30c6e0 | |||
| a962deaffd | |||
| b353df83ee | |||
| 134c02a762 | |||
| 63c6c06436 | |||
| 1b52f67e5d | |||
| e29b19805c | |||
| 7194fe02d1 | |||
| 863b9829ca | |||
| 666371099e | |||
| 0388860ea1 | |||
| eb90be2ec3 | |||
| 0d0a27d1c2 | |||
| 56c81dd890 | |||
| 00502e0476 | |||
| 2eb251bd7f | |||
| cbddbb598f | |||
| bb5b6fef26 | |||
| 4eb379a912 | |||
| 6769f83d5b | |||
| 358f12d910 | |||
| fe35fefc75 | |||
| 5ed9c41d5e | |||
| 9776158cac | |||
| 486eed4875 | |||
| f6225c0baa | |||
| db2047264c | |||
| 68f0cb7684 | |||
| 57b3f42b03 | |||
| a0a0caad38 | |||
| 30e76b4a32 | |||
| b474d7ec77 | |||
| ad3ec9d856 | |||
| 9f63e5da96 | |||
| 2e878d8f2e | |||
| bfaab86330 | |||
| 78b4d715d5 | |||
| 6dfea376ee | |||
| f0188c428f | |||
| 2987b1d425 | |||
| 86128892d7 | |||
| a8bdc59d5a | |||
| ac6ba24861 | |||
| 5b247a3699 | |||
| 580a760aa1 | |||
| f5da6a0e5f | |||
| a394973762 | |||
| 4f73b4725a | |||
| 71b90ab216 | |||
| c4f213f64e | |||
| cacf8f17d3 | |||
| 819c1729f1 | |||
| 765b1cb3a5 | |||
| 908d92fa5c | |||
| 98ef2e18d4 | |||
| f9e1657dcc | |||
| 0a4aa11d09 | |||
| 200028f328 | |||
| 276071b179 | |||
| 26662b7190 | |||
| 8fdfff3014 | |||
| 7e0fb433e4 | |||
| 0b83310100 | |||
| 8c2bd8bd88 | |||
| 44af60563d | |||
| bb98bc92ef | |||
| 3c08b89923 | |||
| 7baef59b79 | |||
| 6fe580bd75 | |||
| 91d875c157 | |||
| 7fa409a72f | |||
| d8927ec5f8 | |||
| 15751ae1a1 | |||
| bda8431d50 | |||
| 492cb727df | |||
| d4536ba242 | |||
| 876a551cd8 | |||
| 41eb07e35b | |||
| 231c593bb3 | |||
| 3b01d785a5 | |||
| 0c0049f8cc | |||
| d7c44e2bbd | |||
| 0504923689 | |||
| 7e47553c88 | |||
| f8761ecea0 | |||
| ff0eae40ea | |||
| 9d6402aad4 | |||
| 1173ac17ee | |||
| fed4a83a8f | |||
| 8343703115 | |||
| 85eb59eb40 | |||
| e11bd5d99f | |||
| f359927b09 | |||
| 70825abb1d | |||
| c4dc85f607 | |||
| 7e8de26657 | |||
| b3570f57ee | |||
| 3c62aa02d4 | |||
| 58e88d43a9 | |||
| 78ade5b7d7 | |||
| 969d5c8558 | |||
| 539199a7e9 | |||
| 60ffe55565 | |||
| dd03c6b168 | |||
| f53c0d7dfa | |||
| 7872354b49 | |||
| 1ee470f5b4 | |||
| 04e6ca9763 | |||
| 80219a31e2 | |||
| 0555dc4bc3 | |||
| 4401b58f45 | |||
| 8d2d3bd73c | |||
| c7dfed8f29 | |||
| 92f9a29de1 | |||
| ff50cfb4da | |||
| 086e10671f | |||
| 68c1c0a6a6 | |||
| 811d77eccb | |||
| f87450efd6 | |||
| e1a8cad552 | |||
| c0141a9744 | |||
| 221de3343a | |||
| 4c0a54f95f | |||
| 1ce21556a1 | |||
| e104017d4c | |||
| 8377e411cb | |||
| b16f3f91d9 | |||
| c669d46efb | |||
| 03deda313a | |||
| 7983063d05 | |||
| e412366bb2 | |||
| 7035d17290 | |||
| b9e0cb6be1 | |||
| 0a78a50eff | |||
| 323bf67037 | |||
| 9ffcec2fcb | |||
| 964c0425bf | |||
| 19208289dc | |||
| a5c5f4c02c | |||
| 53aede83dc | |||
| e4080aba05 | |||
| 2549f7254a | |||
| 87f4341866 | |||
| 3f6cc725d6 | |||
| a558f447cf | |||
| bd2c99d9ec | |||
| 1a224e2adc | |||
| c64aaab193 | |||
| 556e487a15 | |||
| 30d72543b9 | |||
| af0def36c2 | |||
| 6d8f99832f | |||
| 6a9b05e126 | |||
| c45e2cbb82 | |||
| 4d0c02de2d | |||
| e43019a1df | |||
| 4d19793d69 | |||
| 15358a2e72 | |||
| 73f0e6e825 | |||
| 17738c3861 | |||
| 3712868831 | |||
| a0a71d6e05 | |||
| 1116608389 | |||
| a9b9775fe4 | |||
| 75353852fd | |||
| 64ab2da43b | |||
| 6d74ae1b84 | |||
| 26f3c51cf0 | |||
| b192fb9403 | |||
| 24e72bc6cc | |||
| 9dfbd5f671 | |||
| a65339d011 | |||
| 88890a1914 | |||
| 3ea1461839 | |||
| 164e1be018 | |||
| fffb9c8a2c | |||
| f877788cf1 | |||
| 5940e40d22 | |||
| 9c894fb8b0 | |||
| 29b30bb69c | |||
| 9b340a507b | |||
| 0465753bdf | |||
| 08ebe94005 | |||
| 7afd6d32b7 | |||
| f41495dc7a | |||
| b253721df4 | |||
| 8200f889fb | |||
| ec9a7f8165 | |||
| e83891b4fc | |||
| 91c9cb2114 | |||
| 303d571d23 | |||
| f7cc34c807 | |||
| 8b2c0030d0 | |||
| c273351d4a | |||
| 0cd06be13a | |||
| ee64b2f5fd | |||
| f8499e1113 | |||
| 305f4dc5d0 | |||
| 3e73710245 | |||
| 77d5c44664 | |||
| 22e1e6c92f | |||
| e70bcfb343 | |||
| 93bccf36ba | |||
| 1720a2b123 | |||
| b0ecb869f2 | |||
| 58359fe4ac | |||
| 9fdb6eb2c5 | |||
| 9b80d44873 | |||
| 9673980fae | |||
| ec579fb6be | |||
| 3cc3d4fd3b | |||
| 63f4aaf7dd | |||
| 9776373784 | |||
| f8c0c468a9 | |||
| 3e3c5f72e9 | |||
| f332f39ea6 | |||
| 39be1ec116 | |||
| c3bab284ba | |||
| 28581de0ee | |||
| 2bd749b0f7 | |||
| 9586bc26c7 | |||
| e8ef6c8b8a | |||
| 300f7370c8 | |||
| 8d83ce47e9 | |||
| ade2ecdb8e | |||
| 8839a5eb3f | |||
| d61ece7891 | |||
| f736bb9c9a | |||
| f8fb79a838 | |||
| 5ad4992816 | |||
| 02e15bd3d2 | |||
| 25d15fe2af | |||
| fdb4198c0d | |||
| 3f7437fec2 | |||
| ed0733e125 | |||
| cc3255702f | |||
| b53f3b1b5c | |||
| 795d2b264c | |||
| ab961486d9 | |||
| f35a82e36a | |||
| f841a7a25a | |||
| d01f350e94 | |||
| 0e589ecbcd | |||
| 1f381d790f | |||
| e6ce9d3d29 | |||
| a88ad71be6 | |||
| 48daf38f2b | |||
| 7d42330352 | |||
| dfd227cfc9 | |||
| 568dd9bf3c | |||
| 3507a805a9 | |||
| e248517535 | |||
| 0984a669ce | |||
| 15f2b21b62 | |||
| 4aaecfb4f9 | |||
| e6941df981 | |||
| 632f344db5 | |||
| 1f1b472568 | |||
| 20fa2f8738 | |||
| d3bf394b16 | |||
| 887092bacd | |||
| 61aa095722 | |||
| 7aa2700d8f | |||
| e842c7b28b | |||
| 091cd57f68 | |||
| 045b1e0cb8 | |||
| e7bc232eb1 | |||
| 4eaaf91794 | |||
| 9542ab0482 | |||
| f427550bb7 | |||
| ef9c3c8431 | |||
| 9eef17506d | |||
| 801490b9fc | |||
| 169988b3c4 | |||
| 695fecddeb | |||
| 429eb316d0 | |||
| a99a26aeab | |||
| ae93423116 | |||
| b897b5d0e2 | |||
| 1744e69214 | |||
| e034733ac6 | |||
| ac41c3b06c | |||
| 3c8cea2af6 | |||
| 99e8f36901 | |||
| eeea5b0e81 | |||
| b210b22975 | |||
| 84b35f47a1 | |||
| 0727ff09fa | |||
| fe416526f2 | |||
| 3c10844067 | |||
| 94bd6e22ff | |||
| d11524781e | |||
| 8d16c047cc | |||
| f94ebf5296 | |||
| 8cddaf39c4 | |||
| 7ce75733d0 | |||
| e8af613aaa | |||
| 96f2358d28 | |||
| bb8645dd18 | |||
| 12c547126e | |||
| 78d6a25d98 | |||
| 2c4621011d | |||
| 7a6c36d43c | |||
| d9f0d92262 | |||
| cc91ee1c52 | |||
| 0dc77b056a | |||
| c793672d63 | |||
| 5136853ce0 | |||
| 9da873330a | |||
| bd67e7a4ed | |||
| 9eb73f9306 | |||
| 5e275b3935 | |||
| c98f19c5a6 | |||
| 66b4f65d84 | |||
| b85898c5da | |||
| f1332c7c6a | |||
| 8a47c87a8a | |||
| 88b2d8a8ef | |||
| 2fd3ebc8fb | |||
| 204f522ea4 | |||
| 1f986598f1 | |||
| 6996b24c44 | |||
| b44e36e7ba | |||
| 7c41206c6d | |||
| ea6c0353be | |||
| 8a665bc044 | |||
| f68d53ead6 | |||
| 93b1ff1c5d | |||
| d41b0f28b4 | |||
| c686d28675 | |||
| 448095ff98 | |||
| 835bf436e4 | |||
| 6da047005a | |||
| 571824415c | |||
| bef3aad423 | |||
| 7d21a4e0fb | |||
| e9258a238e | |||
| a21376f6ce | |||
| 664f133c4b | |||
| f4cf3596c5 | |||
| d4eebd7c0d | |||
| 70256146fc | |||
| 057e3a936e | |||
| 0aab2510d3 | |||
| ed826e4451 | |||
| 8efb9a38ea | |||
| 8e1d69ac8b | |||
| ee1b3afdcf | |||
| 62aab1cec6 | |||
| 44c07e9504 | |||
| 1c74f84647 | |||
| 1741ce7ec9 | |||
| 53d87eb9be | |||
| 6e7bb505c1 | |||
| e1f137d59a | |||
| 6d7dd2cf39 | |||
| ebf3eea004 | |||
| 913c2e5713 | |||
| d2b5b8d854 | |||
| 5c10d2fae0 | |||
| 738c3eae91 | |||
| 83968bc1cd | |||
| 4cd615ba2e | |||
| ac1908d464 | |||
| 95d8d44259 | |||
| d57be5244c | |||
| 5ef4909bdd | |||
| 83e160d14d | |||
| 9a2e11c0d7 | |||
| 41b381f567 | |||
| ecb979a14b | |||
| 84bba8aa20 | |||
| b133beed5e | |||
| 90502a0c15 | |||
| f5226b2228 | |||
| ad77d6cfec | |||
| a098e38c5a | |||
| a7e7773d85 | |||
| 0df0c85fea | |||
| fdd85a6328 | |||
| 1409d0e06e | |||
| 4765409fe7 | |||
| dad24f1106 | |||
| 9ea39d280c | |||
| a04eb2bba1 | |||
| e849d18c1b | |||
| 57868f38ef | |||
| 85f9b398da | |||
| e081cf1c3d | |||
| 7c85b2f85a | |||
| ec3bcb43a8 | |||
| 3a984668d6 | |||
| b08104367e | |||
| 1fb97f0080 | |||
| 79a989e504 | |||
| d7f8eafe2d | |||
| 6e74ac9bd2 | |||
| 82c2e9978f | |||
| e04ef5a030 | |||
| 0906a0fe1c | |||
| d07994bd73 | |||
| e8699d4337 | |||
| aa0ce0fb88 | |||
| 435efc9886 | |||
| e64e45015a | |||
| 8e9461ea6a | |||
| 1262600895 | |||
| 8589436158 | |||
| 3767ffd79a | |||
| d81c632ef2 | |||
| 18abdd0cd6 | |||
| 0cad039615 | |||
| abfb49818f | |||
| afe9157d65 | |||
| fe12ba23b0 | |||
| 4f54c90a95 | |||
| 045922fb56 | |||
| 4f5678fc95 | |||
| 3986b30b00 | |||
| 7be723782a | |||
| f601664620 | |||
| bd2080fdb5 | |||
| b4585f24bb | |||
| 21c9132902 | |||
| 9abb317e6d | |||
| 5236fb8c0e | |||
| fb661ab6f6 | |||
| 9d22fca5e7 | |||
| eb1d629ea7 | |||
| fd3ce305f4 | |||
| 928e1178b1 | |||
| ff5e34ee70 | |||
| e8d52c0f01 | |||
| 275808d0d5 | |||
| 55488b1fb6 | |||
| e50e6ada6b | |||
| f511af0f0c | |||
| f10bf842c6 | |||
| e3ad54996f | |||
| aac6f45f54 |
@@ -28,16 +28,16 @@
|
|||||||
|
|
||||||
# OS generated files #
|
# OS generated files #
|
||||||
######################
|
######################
|
||||||
.DS_Store?
|
.DS_Store
|
||||||
ehthumbs.db
|
ehthumbs.db
|
||||||
Icon?
|
Icon?
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|
||||||
# SCons related files #
|
# build related files #
|
||||||
#######################
|
#######################
|
||||||
SconsBuilder*
|
/build/
|
||||||
.scon*
|
/Util/UUID.cpp
|
||||||
.build
|
/Util/GitDescription.cpp
|
||||||
|
|
||||||
# Eclipse related files #
|
# Eclipse related files #
|
||||||
#########################
|
#########################
|
||||||
@@ -54,19 +54,39 @@ stxxl.errlog
|
|||||||
|
|
||||||
# compiled protobuffers #
|
# compiled protobuffers #
|
||||||
#########################
|
#########################
|
||||||
DataStructures/pbf-proto/*.pb.h
|
/DataStructures/pbf-proto/*.pb.h
|
||||||
DataStructures/pbf-proto/*.pb.cc
|
/DataStructures/pbf-proto/*.pb.cc
|
||||||
|
|
||||||
# External Libs #
|
# External Libs #
|
||||||
#################
|
#################
|
||||||
lib/
|
/lib/
|
||||||
|
/win/lib
|
||||||
|
|
||||||
# Visual Studio Temp + build Files #
|
# Visual Studio Temp + build Files #
|
||||||
####################################
|
####################################
|
||||||
vcprojects/*.user
|
/win/*.user
|
||||||
vcprojects/*.ncb
|
/win/*.ncb
|
||||||
vcprojects/*.suo
|
/win/*.suo
|
||||||
vcprojects/Debug/
|
/win/Debug/
|
||||||
vcprojects/Release/
|
/win/Release/
|
||||||
bin/
|
/win/bin/
|
||||||
bin-debug/
|
/win/bin-debug/
|
||||||
|
/osrm-extract
|
||||||
|
/osrm-io-benchmark
|
||||||
|
/osrm-components
|
||||||
|
/osrm-routed
|
||||||
|
/osrm-datastore
|
||||||
|
/osrm-prepare
|
||||||
|
/osrm-unlock-all
|
||||||
|
/osrm-cli
|
||||||
|
/nohup.out
|
||||||
|
|
||||||
|
# Sandbox folder #
|
||||||
|
###################
|
||||||
|
/sandbox/
|
||||||
|
|
||||||
|
/test/profile.lua
|
||||||
|
|
||||||
|
# Deprecated config file #
|
||||||
|
##########################
|
||||||
|
/server.ini
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
language: cpp
|
||||||
|
compiler:
|
||||||
|
- gcc
|
||||||
|
# - clang
|
||||||
|
# Make sure CMake is installed
|
||||||
|
install:
|
||||||
|
- 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 libboost1.46-all-dev lua5.1 liblua5.1-0-dev libluabind-dev rubygems
|
||||||
|
- curl -s https://gist.githubusercontent.com/DennisOSRM/803a64a9178ec375069f/raw/ | sudo bash
|
||||||
|
before_script:
|
||||||
|
- rvm use 1.9.3
|
||||||
|
- gem install bundler
|
||||||
|
- bundle install
|
||||||
|
- mkdir build
|
||||||
|
- cd build
|
||||||
|
- cmake .. $CMAKEOPTIONS
|
||||||
|
script:
|
||||||
|
- make -j 2
|
||||||
|
- cd ..
|
||||||
|
- cucumber -p verify
|
||||||
|
after_script:
|
||||||
|
# - cd ..
|
||||||
|
# - cucumber -p verify
|
||||||
|
branches:
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- develop
|
||||||
|
cache:
|
||||||
|
- bundler
|
||||||
|
- apt
|
||||||
|
env:
|
||||||
|
- CMAKEOPTIONS="-DCMAKE_BUILD_TYPE=Release" OSRM_PORT=5000 OSRM_TIMEOUT=60
|
||||||
|
- CMAKEOPTIONS="-DCMAKE_BUILD_TYPE=Debug" OSRM_PORT=5010 OSRM_TIMEOUT=60
|
||||||
|
notifications:
|
||||||
|
irc:
|
||||||
|
channels:
|
||||||
|
- irc.oftc.net#osrm
|
||||||
|
on_success: change
|
||||||
|
on_failure: always
|
||||||
|
use_notice: true
|
||||||
|
skip_join: false
|
||||||
|
|
||||||
|
recipients:
|
||||||
|
- dennis@mapbox.com
|
||||||
|
email:
|
||||||
|
on_success: change
|
||||||
|
on_failure: always
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
The following people contributed code to the Open Source Routing Machine:
|
|
||||||
|
|
||||||
Christian Vetter
|
|
||||||
Dennis Luxen
|
|
||||||
Ruslan Krenzler
|
|
||||||
Frederik Ramm
|
|
||||||
Bharath Vissapragada
|
|
||||||
Pascal Neis
|
|
||||||
Sasa Ivetic
|
|
||||||
Emil Tin
|
|
||||||
@@ -0,0 +1,198 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 "DouglasPeucker.h"
|
||||||
|
#include "../DataStructures/SegmentInformation.h"
|
||||||
|
#include "../Util/MercatorUtil.h"
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
|
//These thresholds are more or less heuristically chosen.
|
||||||
|
static double DouglasPeuckerThresholds[19] = {
|
||||||
|
262144., //z0
|
||||||
|
131072., //z1
|
||||||
|
65536., //z2
|
||||||
|
32768., //z3
|
||||||
|
16384., //z4
|
||||||
|
8192., //z5
|
||||||
|
4096., //z6
|
||||||
|
2048., //z7
|
||||||
|
960., //z8
|
||||||
|
480., //z9
|
||||||
|
240., //z10
|
||||||
|
90., //z11
|
||||||
|
50., //z12
|
||||||
|
25., //z13
|
||||||
|
15., //z14
|
||||||
|
5., //z15
|
||||||
|
.65, //z16
|
||||||
|
.5, //z17
|
||||||
|
.35 //z18
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Yuck! Code duplication. This function is also in EgdeBasedNode.h
|
||||||
|
*/
|
||||||
|
double DouglasPeucker::ComputeDistance(
|
||||||
|
const FixedPointCoordinate& point,
|
||||||
|
const FixedPointCoordinate& segA,
|
||||||
|
const FixedPointCoordinate& segB
|
||||||
|
) const {
|
||||||
|
const double x = lat2y(point.lat/COORDINATE_PRECISION);
|
||||||
|
const double y = point.lon/COORDINATE_PRECISION;
|
||||||
|
const double a = lat2y(segA.lat/COORDINATE_PRECISION);
|
||||||
|
const double b = segA.lon/COORDINATE_PRECISION;
|
||||||
|
const double c = lat2y(segB.lat/COORDINATE_PRECISION);
|
||||||
|
const double d = segB.lon/COORDINATE_PRECISION;
|
||||||
|
double p,q,nY;
|
||||||
|
if( std::abs(a-c) > std::numeric_limits<double>::epsilon() ){
|
||||||
|
const double m = (d-b)/(c-a); // slope
|
||||||
|
// Projection of (x,y) on line joining (a,b) and (c,d)
|
||||||
|
p = ((x + (m*y)) + (m*m*a - m*b))/(1. + m*m);
|
||||||
|
q = b + m*(p - a);
|
||||||
|
} else {
|
||||||
|
p = c;
|
||||||
|
q = y;
|
||||||
|
}
|
||||||
|
nY = (d*p - c*q)/(a*d - b*c);
|
||||||
|
|
||||||
|
//discretize the result to coordinate precision. it's a hack!
|
||||||
|
if( std::abs(nY) < (1./COORDINATE_PRECISION) ) {
|
||||||
|
nY = 0.;
|
||||||
|
}
|
||||||
|
|
||||||
|
double r = (p - nY*a)/c;
|
||||||
|
if( std::isnan(r) ) {
|
||||||
|
r = ((segB.lat == point.lat) && (segB.lon == point.lon)) ? 1. : 0.;
|
||||||
|
} else if( std::abs(r) <= std::numeric_limits<double>::epsilon() ) {
|
||||||
|
r = 0.;
|
||||||
|
} else if( std::abs(r-1.) <= std::numeric_limits<double>::epsilon() ) {
|
||||||
|
r = 1.;
|
||||||
|
}
|
||||||
|
FixedPointCoordinate nearest_location;
|
||||||
|
BOOST_ASSERT( !std::isnan(r) );
|
||||||
|
if( r <= 0. ){
|
||||||
|
nearest_location.lat = segA.lat;
|
||||||
|
nearest_location.lon = segA.lon;
|
||||||
|
} else if( r >= 1. ){
|
||||||
|
nearest_location.lat = segB.lat;
|
||||||
|
nearest_location.lon = segB.lon;
|
||||||
|
} else { // point lies in between
|
||||||
|
nearest_location.lat = y2lat(p)*COORDINATE_PRECISION;
|
||||||
|
nearest_location.lon = q*COORDINATE_PRECISION;
|
||||||
|
}
|
||||||
|
BOOST_ASSERT( nearest_location.isValid() );
|
||||||
|
const double approximated_distance = FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||||
|
point,
|
||||||
|
nearest_location
|
||||||
|
);
|
||||||
|
BOOST_ASSERT( 0. <= approximated_distance );
|
||||||
|
return approximated_distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DouglasPeucker::Run(
|
||||||
|
std::vector<SegmentInformation> & input_geometry,
|
||||||
|
const unsigned zoom_level
|
||||||
|
) {
|
||||||
|
{
|
||||||
|
BOOST_ASSERT_MSG(zoom_level < 19, "unsupported zoom level");
|
||||||
|
BOOST_ASSERT_MSG(1 < input_geometry.size(), "geometry invalid");
|
||||||
|
std::size_t left_border = 0;
|
||||||
|
std::size_t right_border = 1;
|
||||||
|
//Sweep over array and identify those ranges that need to be checked
|
||||||
|
do {
|
||||||
|
BOOST_ASSERT_MSG(
|
||||||
|
input_geometry[left_border].necessary,
|
||||||
|
"left border must be necessary"
|
||||||
|
);
|
||||||
|
BOOST_ASSERT_MSG(
|
||||||
|
input_geometry.back().necessary,
|
||||||
|
"right border must be necessary"
|
||||||
|
);
|
||||||
|
|
||||||
|
if(input_geometry[right_border].necessary) {
|
||||||
|
recursion_stack.push(std::make_pair(left_border, right_border));
|
||||||
|
left_border = right_border;
|
||||||
|
}
|
||||||
|
++right_border;
|
||||||
|
} while( right_border < input_geometry.size());
|
||||||
|
}
|
||||||
|
while( !recursion_stack.empty() ) {
|
||||||
|
//pop next element
|
||||||
|
const PairOfPoints pair = recursion_stack.top();
|
||||||
|
recursion_stack.pop();
|
||||||
|
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"
|
||||||
|
);
|
||||||
|
double max_distance = std::numeric_limits<double>::min();
|
||||||
|
|
||||||
|
std::size_t farthest_element_index = pair.second;
|
||||||
|
//find index idx of element with max_distance
|
||||||
|
for(std::size_t i = pair.first+1; i < pair.second; ++i){
|
||||||
|
const int temp_dist = ComputeDistance(
|
||||||
|
input_geometry[i].location,
|
||||||
|
input_geometry[pair.first].location,
|
||||||
|
input_geometry[pair.second].location
|
||||||
|
);
|
||||||
|
const double distance = std::abs(temp_dist);
|
||||||
|
if(
|
||||||
|
distance > DouglasPeuckerThresholds[zoom_level] &&
|
||||||
|
distance > max_distance
|
||||||
|
) {
|
||||||
|
farthest_element_index = i;
|
||||||
|
max_distance = distance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (max_distance > DouglasPeuckerThresholds[zoom_level]) {
|
||||||
|
// mark idx as necessary
|
||||||
|
input_geometry[farthest_element_index].necessary = true;
|
||||||
|
if (1 < (farthest_element_index - pair.first) ) {
|
||||||
|
recursion_stack.push(
|
||||||
|
std::make_pair(pair.first, farthest_element_index)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (1 < (pair.second - farthest_element_index) ) {
|
||||||
|
recursion_stack.push(
|
||||||
|
std::make_pair(farthest_element_index, pair.second)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,126 +1,72 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, others 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
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
|
Redistributions of source code must retain the above copyright notice, this list
|
||||||
along with this program; if not, write to the Free Software
|
of conditions and the following disclaimer.
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
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 DOUGLASPEUCKER_H_
|
#ifndef DOUGLASPEUCKER_H_
|
||||||
#define DOUGLASPEUCKER_H_
|
#define DOUGLASPEUCKER_H_
|
||||||
|
|
||||||
#include <cfloat>
|
#include "../Util/SimpleLogger.h"
|
||||||
#include <stack>
|
|
||||||
|
|
||||||
/*This class object computes the bitvector of indicating generalized input points
|
#include <osrm/Coordinate.h>
|
||||||
* according to the (Ramer-)Douglas-Peucker algorithm.
|
|
||||||
|
#include <boost/assert.hpp>
|
||||||
|
#include <boost/foreach.hpp>
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
|
#include <stack>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
/* This class object computes the bitvector of indicating generalized input
|
||||||
|
* points according to the (Ramer-)Douglas-Peucker algorithm.
|
||||||
*
|
*
|
||||||
* Input is vector of pairs. Each pair consists of the point information and a bit
|
* Input is vector of pairs. Each pair consists of the point information and a
|
||||||
* indicating if the points is present in the generalization.
|
* bit indicating if the points is present in the generalization.
|
||||||
* Note: points may also be pre-selected*/
|
* Note: points may also be pre-selected*/
|
||||||
|
|
||||||
//These thresholds are more or less heuristically chosen.
|
struct SegmentInformation;
|
||||||
static double DouglasPeuckerThresholds[19] = { 10240000., 512., 2560000., 1280000., 640000., 320000., 160000., 80000., 40000., 20000., 10000., 5000., 2400., 1200., 200, 16, 6, 3., 1. };
|
|
||||||
|
|
||||||
template<class PointT>
|
|
||||||
class DouglasPeucker {
|
class DouglasPeucker {
|
||||||
private:
|
private:
|
||||||
typedef std::pair<std::size_t, std::size_t> PairOfPoints;
|
typedef std::pair<std::size_t, std::size_t> PairOfPoints;
|
||||||
//Stack to simulate the recursion
|
//Stack to simulate the recursion
|
||||||
std::stack<PairOfPoints > recursionStack;
|
std::stack<PairOfPoints> recursion_stack;
|
||||||
|
|
||||||
double ComputeDistance(const _Coordinate& inputPoint, const _Coordinate& source, const _Coordinate& target) {
|
|
||||||
double r;
|
|
||||||
const double x = (double)inputPoint.lat;
|
|
||||||
const double y = (double)inputPoint.lon;
|
|
||||||
const double a = (double)source.lat;
|
|
||||||
const double b = (double)source.lon;
|
|
||||||
const double c = (double)target.lat;
|
|
||||||
const double d = (double)target.lon;
|
|
||||||
double p,q,mX,nY;
|
|
||||||
if(c != a) {
|
|
||||||
const double m = (d-b)/(c-a); // slope
|
|
||||||
// Projection of (x,y) on line joining (a,b) and (c,d)
|
|
||||||
p = ((x + (m*y)) + (m*m*a - m*b))/(1 + m*m);
|
|
||||||
q = b + m*(p - a);
|
|
||||||
} else {
|
|
||||||
p = c;
|
|
||||||
q = y;
|
|
||||||
}
|
|
||||||
nY = (d*p - c*q)/(a*d - b*c);
|
|
||||||
mX = (p - nY*a)/c;// These values are actually n/m+n and m/m+n , we neednot calculate the values of m an n as we are just interested in the ratio
|
|
||||||
r = mX;
|
|
||||||
if(r<=0){
|
|
||||||
return ((b - y)*(b - y) + (a - x)*(a - x));
|
|
||||||
}
|
|
||||||
else if(r >= 1){
|
|
||||||
return ((d - y)*(d - y) + (c - x)*(c - x));
|
|
||||||
|
|
||||||
}
|
|
||||||
// point lies in between
|
|
||||||
return (p-x)*(p-x) + (q-y)*(q-y);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
double ComputeDistance(
|
||||||
|
const FixedPointCoordinate& point,
|
||||||
|
const FixedPointCoordinate& segA,
|
||||||
|
const FixedPointCoordinate& segB
|
||||||
|
) const;
|
||||||
public:
|
public:
|
||||||
void Run(std::vector<PointT> & inputVector, const unsigned zoomLevel) {
|
void Run(
|
||||||
{
|
std::vector<SegmentInformation> & input_geometry,
|
||||||
assert(zoomLevel < 19);
|
const unsigned zoom_level
|
||||||
assert(1 < inputVector.size());
|
);
|
||||||
std::size_t leftBorderOfRange = 0;
|
|
||||||
std::size_t rightBorderOfRange = 1;
|
|
||||||
//Sweep linerarily over array and identify those ranges that need to be checked
|
|
||||||
do {
|
|
||||||
assert(inputVector[leftBorderOfRange].necessary);
|
|
||||||
assert(inputVector[inputVector.size()-1].necessary);
|
|
||||||
|
|
||||||
if(inputVector[rightBorderOfRange].necessary) {
|
|
||||||
recursionStack.push(std::make_pair(leftBorderOfRange, rightBorderOfRange));
|
|
||||||
leftBorderOfRange = rightBorderOfRange;
|
|
||||||
}
|
|
||||||
++rightBorderOfRange;
|
|
||||||
} while( rightBorderOfRange < inputVector.size());
|
|
||||||
}
|
|
||||||
while(!recursionStack.empty()) {
|
|
||||||
//pop next element
|
|
||||||
const PairOfPoints pair = recursionStack.top();
|
|
||||||
recursionStack.pop();
|
|
||||||
assert(inputVector[pair.first].necessary);
|
|
||||||
assert(inputVector[pair.second].necessary);
|
|
||||||
assert(pair.second < inputVector.size());
|
|
||||||
assert(pair.first < pair.second);
|
|
||||||
double maxDistance = -DBL_MAX;
|
|
||||||
std::size_t indexOfFarthestElement = pair.second;
|
|
||||||
//find index idx of element with maxDistance
|
|
||||||
for(std::size_t i = pair.first+1; i < pair.second; ++i){
|
|
||||||
double distance = std::fabs(ComputeDistance(inputVector[i].location, inputVector[pair.first].location, inputVector[pair.second].location));
|
|
||||||
if(distance > DouglasPeuckerThresholds[zoomLevel] && distance > maxDistance) {
|
|
||||||
indexOfFarthestElement = i;
|
|
||||||
maxDistance = distance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (maxDistance > DouglasPeuckerThresholds[zoomLevel]) {
|
|
||||||
// mark idx as necessary
|
|
||||||
inputVector[indexOfFarthestElement].necessary = true;
|
|
||||||
if (1 < indexOfFarthestElement - pair.first) {
|
|
||||||
recursionStack.push(std::make_pair(pair.first, indexOfFarthestElement) );
|
|
||||||
}
|
|
||||||
if (1 < pair.second - indexOfFarthestElement)
|
|
||||||
recursionStack.push(std::make_pair(indexOfFarthestElement, pair.second) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DOUGLASPEUCKER_H_ */
|
#endif /* DOUGLASPEUCKER_H_ */
|
||||||
|
|||||||
@@ -0,0 +1,148 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 ITERATOR_BASED_CRC32_H
|
||||||
|
#define ITERATOR_BASED_CRC32_H
|
||||||
|
|
||||||
|
#include "../Util/SimpleLogger.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#if defined(__x86_64__)
|
||||||
|
#include <cpuid.h>
|
||||||
|
#else
|
||||||
|
#include <boost/crc.hpp> // for boost::crc_32_type
|
||||||
|
|
||||||
|
inline void __get_cpuid(
|
||||||
|
int param,
|
||||||
|
unsigned *eax,
|
||||||
|
unsigned *ebx,
|
||||||
|
unsigned *ecx,
|
||||||
|
unsigned *edx
|
||||||
|
) { *ecx = 0; }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
template<class ContainerT>
|
||||||
|
class IteratorbasedCRC32 {
|
||||||
|
private:
|
||||||
|
typedef typename ContainerT::iterator IteratorType;
|
||||||
|
unsigned crc;
|
||||||
|
|
||||||
|
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 )
|
||||||
|
{
|
||||||
|
#if !defined(__x86_64__)
|
||||||
|
CRC32_processor.process_bytes( str, len);
|
||||||
|
return CRC32_processor.checksum();
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// adapted from http://byteworm.com/2010/10/13/crc32/
|
||||||
|
unsigned SSE42BasedCRC32( char *str, unsigned len )
|
||||||
|
{
|
||||||
|
#if defined(__x86_64__)
|
||||||
|
unsigned q = len/sizeof(unsigned);
|
||||||
|
unsigned r = len%sizeof(unsigned);
|
||||||
|
unsigned *p = (unsigned*)str;
|
||||||
|
|
||||||
|
//crc=0;
|
||||||
|
while (q--) {
|
||||||
|
__asm__ __volatile__(
|
||||||
|
".byte 0xf2, 0xf, 0x38, 0xf1, 0xf1;"
|
||||||
|
:"=S"(crc)
|
||||||
|
:"0"(crc), "c"(*p)
|
||||||
|
);
|
||||||
|
++p;
|
||||||
|
}
|
||||||
|
|
||||||
|
str=(char*)p;
|
||||||
|
while (r--) {
|
||||||
|
__asm__ __volatile__(
|
||||||
|
".byte 0xf2, 0xf, 0x38, 0xf1, 0xf1;"
|
||||||
|
:"=S"(crc)
|
||||||
|
:"0"(crc), "c"(*str)
|
||||||
|
);
|
||||||
|
++str;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned cpuid() const
|
||||||
|
{
|
||||||
|
unsigned eax = 0, ebx = 0, ecx = 0, edx = 0;
|
||||||
|
// on X64 this calls hardware cpuid(.) instr. otherwise a dummy impl.
|
||||||
|
__get_cpuid( 1, &eax, &ebx, &ecx, &edx );
|
||||||
|
return ecx;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DetectNativeCRC32Support()
|
||||||
|
{
|
||||||
|
static const int SSE42_BIT = 0x00100000;
|
||||||
|
const unsigned ecx = cpuid();
|
||||||
|
const bool has_SSE42 = ecx & SSE42_BIT;
|
||||||
|
if (has_SSE42) {
|
||||||
|
SimpleLogger().Write() << "using hardware based CRC32 computation";
|
||||||
|
} else {
|
||||||
|
SimpleLogger().Write() << "using software based CRC32 computation";
|
||||||
|
}
|
||||||
|
return has_SSE42;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
IteratorbasedCRC32() : crc(0)
|
||||||
|
{
|
||||||
|
use_SSE42_CRC_function = DetectNativeCRC32Support();
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* ITERATOR_BASED_CRC32_H */
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 <boost/foreach.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_ */
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 "PolylineCompressor.h"
|
||||||
|
|
||||||
|
void PolylineCompressor::encodeVectorSignedNumber(
|
||||||
|
std::vector<int> & numbers,
|
||||||
|
std::string & output
|
||||||
|
) const {
|
||||||
|
for(unsigned i = 0; i < numbers.size(); ++i) {
|
||||||
|
numbers[i] <<= 1;
|
||||||
|
if (numbers[i] < 0) {
|
||||||
|
numbers[i] = ~(numbers[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(unsigned i = 0; i < numbers.size(); ++i) {
|
||||||
|
encodeNumber(numbers[i], output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PolylineCompressor::encodeNumber(int number_to_encode, std::string & output) const {
|
||||||
|
while (number_to_encode >= 0x20) {
|
||||||
|
int nextValue = (0x20 | (number_to_encode & 0x1f)) + 63;
|
||||||
|
output += static_cast<char>(nextValue);
|
||||||
|
if(92 == nextValue) {
|
||||||
|
output += static_cast<char>(nextValue);
|
||||||
|
}
|
||||||
|
number_to_encode >>= 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
number_to_encode += 63;
|
||||||
|
output += static_cast<char>(number_to_encode);
|
||||||
|
if(92 == number_to_encode) {
|
||||||
|
output += static_cast<char>(number_to_encode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PolylineCompressor::printEncodedString(
|
||||||
|
const std::vector<SegmentInformation> & polyline,
|
||||||
|
std::string & output
|
||||||
|
) const {
|
||||||
|
std::vector<int> deltaNumbers;
|
||||||
|
output += "\"";
|
||||||
|
if(!polyline.empty()) {
|
||||||
|
FixedPointCoordinate lastCoordinate = polyline[0].location;
|
||||||
|
deltaNumbers.push_back( lastCoordinate.lat );
|
||||||
|
deltaNumbers.push_back( lastCoordinate.lon );
|
||||||
|
for(unsigned i = 1; i < polyline.size(); ++i) {
|
||||||
|
if(!polyline[i].necessary) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
deltaNumbers.push_back(polyline[i].location.lat - lastCoordinate.lat);
|
||||||
|
deltaNumbers.push_back(polyline[i].location.lon - lastCoordinate.lon);
|
||||||
|
lastCoordinate = polyline[i].location;
|
||||||
|
}
|
||||||
|
encodeVectorSignedNumber(deltaNumbers, output);
|
||||||
|
}
|
||||||
|
output += "\"";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void PolylineCompressor::printEncodedString(
|
||||||
|
const std::vector<FixedPointCoordinate>& polyline,
|
||||||
|
std::string &output
|
||||||
|
) const {
|
||||||
|
std::vector<int> deltaNumbers(2*polyline.size());
|
||||||
|
output += "\"";
|
||||||
|
if(!polyline.empty()) {
|
||||||
|
deltaNumbers[0] = polyline[0].lat;
|
||||||
|
deltaNumbers[1] = polyline[0].lon;
|
||||||
|
for(unsigned i = 1; i < polyline.size(); ++i) {
|
||||||
|
deltaNumbers[(2*i)] = (polyline[i].lat - polyline[i-1].lat);
|
||||||
|
deltaNumbers[(2*i)+1] = (polyline[i].lon - polyline[i-1].lon);
|
||||||
|
}
|
||||||
|
encodeVectorSignedNumber(deltaNumbers, output);
|
||||||
|
}
|
||||||
|
output += "\"";
|
||||||
|
}
|
||||||
|
|
||||||
|
void PolylineCompressor::printUnencodedString(
|
||||||
|
const std::vector<FixedPointCoordinate> & polyline,
|
||||||
|
std::string & output
|
||||||
|
) const {
|
||||||
|
output += "[";
|
||||||
|
std::string tmp;
|
||||||
|
for(unsigned i = 0; i < polyline.size(); i++) {
|
||||||
|
FixedPointCoordinate::convertInternalLatLonToString(polyline[i].lat, tmp);
|
||||||
|
output += "[";
|
||||||
|
output += tmp;
|
||||||
|
FixedPointCoordinate::convertInternalLatLonToString(polyline[i].lon, tmp);
|
||||||
|
output += ", ";
|
||||||
|
output += tmp;
|
||||||
|
output += "]";
|
||||||
|
if( i < polyline.size()-1 ) {
|
||||||
|
output += ",";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
output += "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
void PolylineCompressor::printUnencodedString(
|
||||||
|
const std::vector<SegmentInformation> & polyline,
|
||||||
|
std::string & output
|
||||||
|
) const {
|
||||||
|
output += "[";
|
||||||
|
std::string tmp;
|
||||||
|
for(unsigned i = 0; i < polyline.size(); i++) {
|
||||||
|
if(!polyline[i].necessary) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
FixedPointCoordinate::convertInternalLatLonToString(polyline[i].location.lat, tmp);
|
||||||
|
output += "[";
|
||||||
|
output += tmp;
|
||||||
|
FixedPointCoordinate::convertInternalLatLonToString(polyline[i].location.lon, tmp);
|
||||||
|
output += ", ";
|
||||||
|
output += tmp;
|
||||||
|
output += "]";
|
||||||
|
if( i < polyline.size()-1 ) {
|
||||||
|
output += ",";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
output += "]";
|
||||||
|
}
|
||||||
@@ -1,134 +1,69 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, others 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
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
|
Redistributions of source code must retain the above copyright notice, this list
|
||||||
along with this program; if not, write to the Free Software
|
of conditions and the following disclaimer.
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
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 POLYLINECOMPRESSOR_H_
|
#ifndef POLYLINECOMPRESSOR_H_
|
||||||
#define POLYLINECOMPRESSOR_H_
|
#define POLYLINECOMPRESSOR_H_
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "../DataStructures/ExtractorStructs.h"
|
|
||||||
#include "../DataStructures/SegmentInformation.h"
|
#include "../DataStructures/SegmentInformation.h"
|
||||||
#include "../Util/StringUtil.h"
|
#include "../Util/StringUtil.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class PolylineCompressor {
|
class PolylineCompressor {
|
||||||
private:
|
private:
|
||||||
inline void encodeVectorSignedNumber(vector<int> & numbers, string & output) {
|
void encodeVectorSignedNumber(
|
||||||
for(unsigned i = 0; i < numbers.size(); ++i) {
|
std::vector<int> & numbers,
|
||||||
numbers[i] <<= 1;
|
std::string & output
|
||||||
if (numbers[i] < 0) {
|
) const;
|
||||||
numbers[i] = ~(numbers[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(unsigned i = 0; i < numbers.size(); ++i) {
|
|
||||||
encodeNumber(numbers[i], output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void encodeNumber(int numberToEncode, string & output) {
|
void encodeNumber(int number_to_encode, std::string & output) const;
|
||||||
while (numberToEncode >= 0x20) {
|
|
||||||
int nextValue = (0x20 | (numberToEncode & 0x1f)) + 63;
|
|
||||||
output += (static_cast<char> (nextValue));
|
|
||||||
if(92 == nextValue)
|
|
||||||
output += (static_cast<char> (nextValue));
|
|
||||||
numberToEncode >>= 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
numberToEncode += 63;
|
|
||||||
output += (static_cast<char> (numberToEncode));
|
|
||||||
if(92 == numberToEncode)
|
|
||||||
output += (static_cast<char> (numberToEncode));
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline void printEncodedString(const vector<SegmentInformation>& polyline, string &output) {
|
void printEncodedString(
|
||||||
vector<int> deltaNumbers;
|
const std::vector<SegmentInformation> & polyline,
|
||||||
output += "\"";
|
std::string & output
|
||||||
if(!polyline.empty()) {
|
) const;
|
||||||
_Coordinate lastCoordinate = polyline[0].location;
|
|
||||||
deltaNumbers.push_back( lastCoordinate.lat );
|
|
||||||
deltaNumbers.push_back( lastCoordinate.lon );
|
|
||||||
for(unsigned i = 1; i < polyline.size(); ++i) {
|
|
||||||
if(!polyline[i].necessary)
|
|
||||||
continue;
|
|
||||||
deltaNumbers.push_back(polyline[i].location.lat - lastCoordinate.lat);
|
|
||||||
deltaNumbers.push_back(polyline[i].location.lon - lastCoordinate.lon);
|
|
||||||
lastCoordinate = polyline[i].location;
|
|
||||||
}
|
|
||||||
encodeVectorSignedNumber(deltaNumbers, output);
|
|
||||||
}
|
|
||||||
output += "\"";
|
|
||||||
|
|
||||||
}
|
void printEncodedString(
|
||||||
|
const std::vector<FixedPointCoordinate>& polyline,
|
||||||
|
std::string &output
|
||||||
|
) const;
|
||||||
|
|
||||||
inline void printEncodedString(const vector<_Coordinate>& polyline, string &output) {
|
void printUnencodedString(
|
||||||
vector<int> deltaNumbers(2*polyline.size());
|
const std::vector<FixedPointCoordinate> & polyline,
|
||||||
output += "\"";
|
std::string & output
|
||||||
if(!polyline.empty()) {
|
) const;
|
||||||
deltaNumbers[0] = polyline[0].lat;
|
|
||||||
deltaNumbers[1] = polyline[0].lon;
|
|
||||||
for(unsigned i = 1; i < polyline.size(); ++i) {
|
|
||||||
deltaNumbers[(2*i)] = (polyline[i].lat - polyline[i-1].lat);
|
|
||||||
deltaNumbers[(2*i)+1] = (polyline[i].lon - polyline[i-1].lon);
|
|
||||||
}
|
|
||||||
encodeVectorSignedNumber(deltaNumbers, output);
|
|
||||||
}
|
|
||||||
output += "\"";
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void printUnencodedString(vector<_Coordinate> & polyline, string & output) {
|
void printUnencodedString(
|
||||||
output += "[";
|
const std::vector<SegmentInformation> & polyline,
|
||||||
string tmp;
|
std::string & output
|
||||||
for(unsigned i = 0; i < polyline.size(); i++) {
|
) const;
|
||||||
convertInternalLatLonToString(polyline[i].lat, tmp);
|
|
||||||
output += "[";
|
|
||||||
output += tmp;
|
|
||||||
convertInternalLatLonToString(polyline[i].lon, tmp);
|
|
||||||
output += ", ";
|
|
||||||
output += tmp;
|
|
||||||
output += "]";
|
|
||||||
if( i < polyline.size()-1 ) {
|
|
||||||
output += ",";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
output += "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void printUnencodedString(vector<SegmentInformation> & polyline, string & output) {
|
|
||||||
output += "[";
|
|
||||||
string tmp;
|
|
||||||
for(unsigned i = 0; i < polyline.size(); i++) {
|
|
||||||
if(!polyline[i].necessary)
|
|
||||||
continue;
|
|
||||||
convertInternalLatLonToString(polyline[i].location.lat, tmp);
|
|
||||||
output += "[";
|
|
||||||
output += tmp;
|
|
||||||
convertInternalLatLonToString(polyline[i].location.lon, tmp);
|
|
||||||
output += ", ";
|
|
||||||
output += tmp;
|
|
||||||
output += "]";
|
|
||||||
if( i < polyline.size()-1 ) {
|
|
||||||
output += ",";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
output += "]";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* POLYLINECOMPRESSOR_H_ */
|
#endif /* POLYLINECOMPRESSOR_H_ */
|
||||||
|
|||||||
@@ -0,0 +1,501 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 "../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/SimpleLogger.h"
|
||||||
|
|
||||||
|
#include <osrm/Coordinate.h>
|
||||||
|
|
||||||
|
#include <boost/assert.hpp>
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <boost/foreach.hpp>
|
||||||
|
#include <boost/integer.hpp>
|
||||||
|
#include <boost/make_shared.hpp>
|
||||||
|
#include <boost/unordered_map.hpp>
|
||||||
|
#include <boost/unordered_set.hpp>
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <gdal.h>
|
||||||
|
#include <ogrsf_frmts.h>
|
||||||
|
#else
|
||||||
|
#include <gdal/gdal.h>
|
||||||
|
#include <gdal/ogrsf_frmts.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stack>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class TarjanSCC {
|
||||||
|
private:
|
||||||
|
|
||||||
|
struct TarjanNode {
|
||||||
|
TarjanNode() : index(UINT_MAX), lowlink(UINT_MAX), onStack(false) {}
|
||||||
|
unsigned index;
|
||||||
|
unsigned lowlink;
|
||||||
|
bool onStack;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TarjanEdgeData {
|
||||||
|
int distance;
|
||||||
|
unsigned nameID:31;
|
||||||
|
bool shortcut:1;
|
||||||
|
short type;
|
||||||
|
bool isAccessRestricted:1;
|
||||||
|
bool forward:1;
|
||||||
|
bool backward:1;
|
||||||
|
bool roundabout:1;
|
||||||
|
bool ignoreInGrid: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 boost::unordered_map<RestrictionSource, unsigned > RestrictionMap;
|
||||||
|
|
||||||
|
std::vector<NodeInfo> m_coordinate_list;
|
||||||
|
std::vector<EmanatingRestrictionsVector> m_restriction_bucket_list;
|
||||||
|
boost::shared_ptr<TarjanDynamicGraph> m_node_based_graph;
|
||||||
|
boost::unordered_set<NodeID> m_barrier_node_list;
|
||||||
|
boost::unordered_set<NodeID> m_traffic_light_list;
|
||||||
|
unsigned m_restriction_counter;
|
||||||
|
RestrictionMap m_restriction_map;
|
||||||
|
|
||||||
|
struct EdgeBasedNode {
|
||||||
|
bool operator<(const EdgeBasedNode & other) const {
|
||||||
|
return other.id < id;
|
||||||
|
}
|
||||||
|
bool operator==(const EdgeBasedNode & other) const {
|
||||||
|
return id == other.id;
|
||||||
|
}
|
||||||
|
NodeID id;
|
||||||
|
int lat1;
|
||||||
|
int lat2;
|
||||||
|
int lon1;
|
||||||
|
int lon2:31;
|
||||||
|
bool belongsToTinyComponent:1;
|
||||||
|
NodeID nameID;
|
||||||
|
unsigned weight:31;
|
||||||
|
bool ignoreInGrid:1;
|
||||||
|
};
|
||||||
|
|
||||||
|
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())
|
||||||
|
{
|
||||||
|
BOOST_FOREACH(const TurnRestriction & restriction, irs) {
|
||||||
|
std::pair<NodeID, NodeID> restrictionSource = std::make_pair(
|
||||||
|
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[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).push_back(
|
||||||
|
std::make_pair(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;
|
||||||
|
BOOST_FOREACH(const NodeBasedEdge & input_edge, input_edges) {
|
||||||
|
TarjanEdge edge;
|
||||||
|
if(!input_edge.isForward()) {
|
||||||
|
edge.source = input_edge.target();
|
||||||
|
edge.target = input_edge.source();
|
||||||
|
edge.data.backward = input_edge.isForward();
|
||||||
|
edge.data.forward = input_edge.isBackward();
|
||||||
|
} else {
|
||||||
|
edge.source = input_edge.source();
|
||||||
|
edge.target = input_edge.target();
|
||||||
|
edge.data.forward = input_edge.isForward();
|
||||||
|
edge.data.backward = input_edge.isBackward();
|
||||||
|
}
|
||||||
|
if(edge.source == edge.target) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
edge.data.distance = (std::max)((int)input_edge.weight(), 1 );
|
||||||
|
BOOST_ASSERT( edge.data.distance > 0 );
|
||||||
|
edge.data.shortcut = false;
|
||||||
|
edge.data.roundabout = input_edge.isRoundabout();
|
||||||
|
edge.data.ignoreInGrid = input_edge.ignoreInGrid();
|
||||||
|
edge.data.nameID = input_edge.name();
|
||||||
|
edge.data.type = input_edge.type();
|
||||||
|
edge.data.isAccessRestricted = input_edge.isAccessRestricted();
|
||||||
|
edge.data.reversedEdge = false;
|
||||||
|
edge_list.push_back( edge );
|
||||||
|
if( edge.data.backward ) {
|
||||||
|
std::swap( edge.source, edge.target );
|
||||||
|
edge.data.forward = input_edge.isBackward();
|
||||||
|
edge.data.backward = input_edge.isForward();
|
||||||
|
edge.data.reversedEdge = true;
|
||||||
|
edge_list.push_back( edge );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::vector<NodeBasedEdge>().swap(input_edges);
|
||||||
|
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 = boost::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( NULL == poDriver ) {
|
||||||
|
throw OSRMException("ESRI Shapefile driver not available");
|
||||||
|
}
|
||||||
|
OGRDataSource * poDS = poDriver->CreateDataSource(
|
||||||
|
"component.shp",
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
if( NULL == poDS ) {
|
||||||
|
throw OSRMException("Creation of output file failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
OGRLayer * poLayer = poDS->CreateLayer(
|
||||||
|
"component",
|
||||||
|
NULL,
|
||||||
|
wkbLineString,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
if( NULL == 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;
|
||||||
|
for(
|
||||||
|
NodeID node = 0, last_node = m_node_based_graph->GetNumberOfNodes();
|
||||||
|
node < last_node;
|
||||||
|
++node
|
||||||
|
) {
|
||||||
|
if(UINT_MAX == components_index[node]) {
|
||||||
|
recursion_stack.push(
|
||||||
|
std::make_pair(true, TarjanStackFrame(node,node))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
while(!recursion_stack.empty()) {
|
||||||
|
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.push(std::make_pair(false, currentFrame));
|
||||||
|
|
||||||
|
//Mark essential information for SCC
|
||||||
|
tarjan_node_list[v].index = index;
|
||||||
|
tarjan_node_list[v].lowlink = index;
|
||||||
|
tarjan_stack.push(v);
|
||||||
|
tarjan_node_list[v].onStack = true;
|
||||||
|
++index;
|
||||||
|
|
||||||
|
//Traverse outgoing edges
|
||||||
|
for(
|
||||||
|
TarjanDynamicGraph::EdgeIterator e2 = m_node_based_graph->BeginEdges(v);
|
||||||
|
e2 < m_node_based_graph->EndEdges(v);
|
||||||
|
++e2
|
||||||
|
) {
|
||||||
|
const TarjanDynamicGraph::NodeIterator vprime =
|
||||||
|
m_node_based_graph->GetTarget(e2);
|
||||||
|
if(UINT_MAX == tarjan_node_list[vprime].index) {
|
||||||
|
recursion_stack.push(
|
||||||
|
std::make_pair(
|
||||||
|
true,
|
||||||
|
TarjanStackFrame(vprime, v)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
if(
|
||||||
|
tarjan_node_list[vprime].onStack &&
|
||||||
|
tarjan_node_list[vprime].index < tarjan_node_list[v].lowlink
|
||||||
|
) {
|
||||||
|
tarjan_node_list[v].lowlink = tarjan_node_list[vprime].index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tarjan_node_list[currentFrame.parent].lowlink =
|
||||||
|
std::min(
|
||||||
|
tarjan_node_list[currentFrame.parent].lowlink,
|
||||||
|
tarjan_node_list[v].lowlink
|
||||||
|
);
|
||||||
|
//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].lowlink == tarjan_node_list[v].index) {
|
||||||
|
NodeID vprime;
|
||||||
|
do {
|
||||||
|
vprime = tarjan_stack.top(); tarjan_stack.pop();
|
||||||
|
tarjan_node_list[vprime].onStack = false;
|
||||||
|
components_index[vprime] = component_index;
|
||||||
|
++size_of_current_component;
|
||||||
|
} while( v != vprime);
|
||||||
|
|
||||||
|
component_size_vector.push_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 = 0;
|
||||||
|
for(unsigned i = 0, end = component_size_vector.size(); i < end; ++i){
|
||||||
|
if(1 == component_size_vector[i]) {
|
||||||
|
++size_one_counter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SimpleLogger().Write() <<
|
||||||
|
"identified " << size_one_counter << " SCCs of size 1";
|
||||||
|
|
||||||
|
uint64_t total_network_distance = 0;
|
||||||
|
p.reinit(m_node_based_graph->GetNumberOfNodes());
|
||||||
|
for(
|
||||||
|
TarjanDynamicGraph::NodeIterator u = 0, last_u_node = m_node_based_graph->GetNumberOfNodes();
|
||||||
|
u < last_u_node;
|
||||||
|
++u
|
||||||
|
) {
|
||||||
|
p.printIncrement();
|
||||||
|
for(
|
||||||
|
TarjanDynamicGraph::EdgeIterator e1 = m_node_based_graph->BeginEdges(u), last_edge = m_node_based_graph->EndEdges(u);
|
||||||
|
e1 < last_edge;
|
||||||
|
++e1
|
||||||
|
) {
|
||||||
|
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 = std::make_pair(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;
|
||||||
|
BOOST_FOREACH(
|
||||||
|
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 = std::make_pair(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;
|
||||||
|
BOOST_FOREACH(
|
||||||
|
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_ */
|
||||||
@@ -0,0 +1,269 @@
|
|||||||
|
cmake_minimum_required(VERSION 2.6)
|
||||||
|
project(OSRM)
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
include(CheckCXXCompilerFlag)
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
|
||||||
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
|
||||||
|
include(GetGitRevisionDescription)
|
||||||
|
git_describe(GIT_DESCRIPTION)
|
||||||
|
|
||||||
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||||
|
|
||||||
|
set(bitness 32)
|
||||||
|
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||||
|
set(bitness 64)
|
||||||
|
message(STATUS "Building on a 64 bit system")
|
||||||
|
else()
|
||||||
|
message(WARNING "Building on a 32 bit system is unsupported")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include_directories(${CMAKE_SOURCE_DIR}/Include/)
|
||||||
|
|
||||||
|
add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/Util/UUID.cpp UUID.cpp.alwaysbuild
|
||||||
|
COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_SOURCE_DIR}
|
||||||
|
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/UUID-Config.cmake
|
||||||
|
DEPENDS
|
||||||
|
${CMAKE_SOURCE_DIR}/Util/UUID.cpp.in
|
||||||
|
${CMAKE_SOURCE_DIR}/cmake/UUID-Config.cmake
|
||||||
|
COMMENT "Configuring UUID.cpp"
|
||||||
|
VERBATIM)
|
||||||
|
|
||||||
|
add_custom_target(UUIDConfigure DEPENDS ${CMAKE_SOURCE_DIR}/Util/UUID.cpp)
|
||||||
|
|
||||||
|
set(BOOST_COMPONENTS date_time filesystem iostreams program_options regex system thread)
|
||||||
|
|
||||||
|
configure_file(
|
||||||
|
${CMAKE_SOURCE_DIR}/Util/GitDescription.cpp.in
|
||||||
|
${CMAKE_SOURCE_DIR}/Util/GitDescription.cpp
|
||||||
|
)
|
||||||
|
file(GLOB ExtractorGlob Extractor/*.cpp)
|
||||||
|
set(ExtractorSources extractor.cpp ${ExtractorGlob})
|
||||||
|
add_executable(osrm-extract ${ExtractorSources})
|
||||||
|
|
||||||
|
file(GLOB PrepareGlob Contractor/*.cpp DataStructures/HilbertValue.cpp)
|
||||||
|
set(PrepareSources prepare.cpp ${PrepareGlob})
|
||||||
|
add_executable(osrm-prepare ${PrepareSources})
|
||||||
|
|
||||||
|
file(GLOB ServerGlob Server/*.cpp)
|
||||||
|
file(GLOB DescriptorGlob Descriptors/*.cpp)
|
||||||
|
file(GLOB DatastructureGlob DataStructures/SearchEngineData.cpp)
|
||||||
|
file(GLOB CoordinateGlob DataStructures/Coordinate.cpp)
|
||||||
|
file(GLOB AlgorithmGlob Algorithms/*.cpp)
|
||||||
|
file(GLOB HttpGlob Server/Http/*.cpp)
|
||||||
|
file(GLOB LibOSRMGlob Library/*.cpp)
|
||||||
|
|
||||||
|
set(
|
||||||
|
OSRMSources
|
||||||
|
${LibOSRMGlob}
|
||||||
|
${DescriptorGlob}
|
||||||
|
${DatastructureGlob}
|
||||||
|
${CoordinateGlob}
|
||||||
|
${AlgorithmGlob}
|
||||||
|
${HttpGlob}
|
||||||
|
)
|
||||||
|
add_library(COORDLIB STATIC ${CoordinateGlob})
|
||||||
|
add_library(OSRM ${OSRMSources} Util/GitDescription.cpp Util/UUID.cpp)
|
||||||
|
add_library(UUID STATIC Util/UUID.cpp)
|
||||||
|
add_library(GITDESCRIPTION STATIC Util/GitDescription.cpp)
|
||||||
|
add_dependencies(UUID UUIDConfigure)
|
||||||
|
add_dependencies(GITDESCRIPTION GIT_DESCRIPTION)
|
||||||
|
|
||||||
|
add_executable(osrm-routed routed.cpp ${ServerGlob})
|
||||||
|
set_target_properties(osrm-routed PROPERTIES COMPILE_FLAGS -DROUTED)
|
||||||
|
add_executable(osrm-datastore datastore.cpp)
|
||||||
|
|
||||||
|
# Check the release mode
|
||||||
|
if(NOT CMAKE_BUILD_TYPE MATCHES Debug)
|
||||||
|
set(CMAKE_BUILD_TYPE Release)
|
||||||
|
endif()
|
||||||
|
if(CMAKE_BUILD_TYPE MATCHES Debug)
|
||||||
|
message(STATUS "Configuring OSRM in debug mode")
|
||||||
|
if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||||
|
message(STATUS "adding profiling flags")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage -fno-inline")
|
||||||
|
set(CMAKE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -fno-inline")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
if(CMAKE_BUILD_TYPE MATCHES Release)
|
||||||
|
message(STATUS "Configuring OSRM in release mode")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Configuring compilers
|
||||||
|
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||||
|
# using Clang
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unknown-pragmas -Wno-unneeded-internal-declaration -pedantic -fPIC")
|
||||||
|
message(STATUS "OpenMP parallelization not available using clang++")
|
||||||
|
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||||
|
# using GCC
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fopenmp -pedantic -fPIC")
|
||||||
|
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
|
||||||
|
# using Intel C++
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-intel -wd10237 -Wall -openmp -ipo -fPIC")
|
||||||
|
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||||
|
# using Visual Studio C++
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Check if LTO is available
|
||||||
|
set(LTO_FLAGS "")
|
||||||
|
CHECK_CXX_COMPILER_FLAG("-flto" HAS_LTO_FLAG)
|
||||||
|
if (HAS_LTO_FLAG)
|
||||||
|
set(LTO_FLAGS "${LTO_FLAGS} -flto")
|
||||||
|
endif (HAS_LTO_FLAG)
|
||||||
|
|
||||||
|
# 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.5) 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}")
|
||||||
|
|
||||||
|
# Configuring other platform dependencies
|
||||||
|
if(APPLE)
|
||||||
|
set(CMAKE_OSX_ARCHITECTURES "x86_64")
|
||||||
|
message(STATUS "Set Architecture to x64 on OS X")
|
||||||
|
exec_program(uname ARGS -v OUTPUT_VARIABLE DARWIN_VERSION)
|
||||||
|
string(REGEX MATCH "[0-9]+" DARWIN_VERSION ${DARWIN_VERSION})
|
||||||
|
if(DARWIN_VERSION GREATER 12 AND NOT OSXLIBSTD)
|
||||||
|
message(STATUS "Activating -std=c++11 flag for >= OS X 10.9")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||||
|
endif()
|
||||||
|
if(OSXLIBSTD)
|
||||||
|
message(STATUS "linking against ${OSXLIBSTD}")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=${OSXLIBSTD}")
|
||||||
|
elseif(DARWIN_VERSION GREATER 12)
|
||||||
|
message(STATUS "linking against libc++")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(UNIX AND NOT APPLE)
|
||||||
|
target_link_libraries(osrm-datastore rt)
|
||||||
|
target_link_libraries(OSRM rt)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
#Check Boost
|
||||||
|
set(BOOST_MIN_VERSION "1.46.0")
|
||||||
|
find_package(Boost ${BOOST_MIN_VERSION} COMPONENTS ${BOOST_COMPONENTS} REQUIRED)
|
||||||
|
if(NOT Boost_FOUND)
|
||||||
|
message(FATAL_ERROR "Fatal error: Boost (version >= 1.46.0) required.\n")
|
||||||
|
endif()
|
||||||
|
include_directories(${Boost_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
target_link_libraries(OSRM ${Boost_LIBRARIES} COORDLIB)
|
||||||
|
target_link_libraries(osrm-extract ${Boost_LIBRARIES} UUID GITDESCRIPTION COORDLIB)
|
||||||
|
target_link_libraries(osrm-prepare ${Boost_LIBRARIES} UUID GITDESCRIPTION COORDLIB)
|
||||||
|
target_link_libraries(osrm-routed ${Boost_LIBRARIES} OSRM UUID GITDESCRIPTION)
|
||||||
|
target_link_libraries(osrm-datastore ${Boost_LIBRARIES} UUID GITDESCRIPTION COORDLIB)
|
||||||
|
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
|
target_link_libraries(osrm-extract ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
if( LUAJIT_FOUND )
|
||||||
|
target_link_libraries(osrm-extract ${LUAJIT_LIBRARIES})
|
||||||
|
target_link_libraries(osrm-prepare ${LUAJIT_LIBRARIES})
|
||||||
|
else()
|
||||||
|
target_link_libraries(osrm-extract ${LUA_LIBRARY})
|
||||||
|
target_link_libraries(osrm-prepare ${LUA_LIBRARY})
|
||||||
|
endif()
|
||||||
|
include_directories(${LUA_INCLUDE_DIR})
|
||||||
|
|
||||||
|
find_package(LibXml2 REQUIRED)
|
||||||
|
include_directories(${LIBXML2_INCLUDE_DIR})
|
||||||
|
target_link_libraries(osrm-extract ${LIBXML2_LIBRARIES})
|
||||||
|
|
||||||
|
find_package( Luabind REQUIRED )
|
||||||
|
include_directories(${LUABIND_INCLUDE_DIR})
|
||||||
|
target_link_libraries(osrm-extract ${LUABIND_LIBRARY})
|
||||||
|
target_link_libraries(osrm-prepare ${LUABIND_LIBRARY})
|
||||||
|
|
||||||
|
find_package( STXXL REQUIRED )
|
||||||
|
include_directories(${STXXL_INCLUDE_DIR})
|
||||||
|
target_link_libraries(OSRM ${STXXL_LIBRARY})
|
||||||
|
target_link_libraries(osrm-extract ${STXXL_LIBRARY})
|
||||||
|
target_link_libraries(osrm-prepare ${STXXL_LIBRARY})
|
||||||
|
|
||||||
|
find_package( OSMPBF REQUIRED )
|
||||||
|
include_directories(${OSMPBF_INCLUDE_DIR})
|
||||||
|
target_link_libraries(osrm-extract ${OSMPBF_LIBRARY})
|
||||||
|
target_link_libraries(osrm-prepare ${OSMPBF_LIBRARY})
|
||||||
|
|
||||||
|
find_package(Protobuf REQUIRED)
|
||||||
|
include_directories(${PROTOBUF_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(osrm-extract ${PROTOBUF_LIBRARY})
|
||||||
|
target_link_libraries(osrm-prepare ${PROTOBUF_LIBRARY})
|
||||||
|
|
||||||
|
find_package(BZip2 REQUIRED)
|
||||||
|
include_directories(${BZIP_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(osrm-extract ${BZIP2_LIBRARIES})
|
||||||
|
|
||||||
|
find_package(ZLIB REQUIRED)
|
||||||
|
include_directories(${ZLIB_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(osrm-extract ${ZLIB_LIBRARY})
|
||||||
|
target_link_libraries(osrm-routed ${ZLIB_LIBRARY})
|
||||||
|
|
||||||
|
if(WITH_TOOLS)
|
||||||
|
message(STATUS "Activating OSRM internal tools")
|
||||||
|
find_package(GDAL)
|
||||||
|
if(GDAL_FOUND)
|
||||||
|
add_executable(osrm-components Tools/componentAnalysis.cpp)
|
||||||
|
include_directories(${GDAL_INCLUDE_DIR})
|
||||||
|
target_link_libraries(
|
||||||
|
osrm-components
|
||||||
|
${GDAL_LIBRARIES} ${Boost_LIBRARIES} UUID GITDESCRIPTION COORDLIB)
|
||||||
|
endif()
|
||||||
|
add_executable(osrm-cli Tools/simpleclient.cpp)
|
||||||
|
target_link_libraries(osrm-cli ${Boost_LIBRARIES} OSRM UUID GITDESCRIPTION)
|
||||||
|
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)
|
||||||
|
if(UNIX AND NOT APPLE)
|
||||||
|
target_link_libraries(osrm-unlock-all rt)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
file(GLOB InstallGlob Include/osrm/*.h Library/OSRM.h)
|
||||||
|
|
||||||
|
# Add RPATH info to executables so that when they are run after being installed
|
||||||
|
# (i.e., from /usr/local/bin/) the linker can find library dependencies. For
|
||||||
|
# more info see http://www.cmake.org/Wiki/CMake_RPATH_handling
|
||||||
|
set_property(TARGET osrm-extract PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||||
|
set_property(TARGET osrm-prepare PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||||
|
set_property(TARGET osrm-datastore PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||||
|
set_property(TARGET osrm-routed PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||||
|
|
||||||
|
install(FILES ${InstallGlob} DESTINATION include/osrm)
|
||||||
|
install(TARGETS osrm-extract DESTINATION bin)
|
||||||
|
install(TARGETS osrm-prepare DESTINATION bin)
|
||||||
|
install(TARGETS osrm-datastore DESTINATION bin)
|
||||||
|
install(TARGETS osrm-routed DESTINATION bin)
|
||||||
|
install(TARGETS OSRM DESTINATION lib)
|
||||||
|
list(GET Boost_LIBRARIES 1 BOOST_LIBRARY_FIRST)
|
||||||
|
get_filename_component(BOOST_LIBRARY_LISTING "${BOOST_LIBRARY_FIRST}" PATH)
|
||||||
|
set(BOOST_LIBRARY_LISTING "-L${BOOST_LIBRARY_LISTING}")
|
||||||
|
foreach (lib ${Boost_LIBRARIES})
|
||||||
|
get_filename_component(BOOST_LIBRARY_NAME "${lib}" NAME_WE)
|
||||||
|
string(REPLACE "lib" "" BOOST_LIBRARY_NAME ${BOOST_LIBRARY_NAME})
|
||||||
|
set(BOOST_LIBRARY_LISTING "${BOOST_LIBRARY_LISTING} -l${BOOST_LIBRARY_NAME}")
|
||||||
|
endforeach ()
|
||||||
|
|
||||||
|
configure_file(${CMAKE_SOURCE_DIR}/cmake/pkgconfig.in libosrm.pc @ONLY)
|
||||||
|
install(FILES ${PROJECT_BINARY_DIR}/libosrm.pc DESTINATION lib/pkgconfig)
|
||||||
@@ -1,290 +0,0 @@
|
|||||||
/*
|
|
||||||
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 CONTRACTIONCLEANUP_H_INCLUDED
|
|
||||||
#define CONTRACTIONCLEANUP_H_INCLUDED
|
|
||||||
|
|
||||||
#ifdef _GLIBCXX_PARALLEL
|
|
||||||
#include <parallel/algorithm>
|
|
||||||
#else
|
|
||||||
#include <algorithm>
|
|
||||||
#endif
|
|
||||||
#ifndef _WIN32
|
|
||||||
#include <sys/time.h>
|
|
||||||
#endif
|
|
||||||
#include "Contractor.h"
|
|
||||||
|
|
||||||
#ifdef _OPENMP
|
|
||||||
#include <omp.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class ContractionCleanup {
|
|
||||||
private:
|
|
||||||
|
|
||||||
struct _CleanupHeapData {
|
|
||||||
NodeID parent;
|
|
||||||
_CleanupHeapData( NodeID p ) {
|
|
||||||
parent = p;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#ifdef _MANYCORES
|
|
||||||
typedef BinaryHeap< NodeID, NodeID, int, _HeapData, DenseStorage<NodeID, NodeID> > _Heap;
|
|
||||||
#else
|
|
||||||
typedef BinaryHeap< NodeID, NodeID, int, _CleanupHeapData > _Heap;
|
|
||||||
#endif
|
|
||||||
struct _ThreadData {
|
|
||||||
_Heap* _heapForward;
|
|
||||||
_Heap* _heapBackward;
|
|
||||||
_ThreadData( NodeID nodes ) {
|
|
||||||
_heapBackward = new _Heap(nodes);
|
|
||||||
_heapForward = new _Heap(nodes);
|
|
||||||
}
|
|
||||||
~_ThreadData()
|
|
||||||
{
|
|
||||||
delete _heapBackward;
|
|
||||||
delete _heapForward;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
struct Edge {
|
|
||||||
NodeID source;
|
|
||||||
NodeID target;
|
|
||||||
struct EdgeData {
|
|
||||||
NodeID via;
|
|
||||||
unsigned nameID1;
|
|
||||||
unsigned nameID2;
|
|
||||||
int distance;
|
|
||||||
bool shortcut;
|
|
||||||
bool forward;
|
|
||||||
bool backward;
|
|
||||||
short turnInstruction;
|
|
||||||
} data;
|
|
||||||
|
|
||||||
//sorts by source and other attributes
|
|
||||||
static bool CompareBySource( const Edge& left, const Edge& right ) {
|
|
||||||
if ( left.source != right.source )
|
|
||||||
return left.source < right.source;
|
|
||||||
int l = ( left.data.forward ? -1 : 0 ) + ( left.data.backward ? -1 : 0 );
|
|
||||||
int r = ( right.data.forward ? -1 : 0 ) + ( right.data.backward ? -1 : 0 );
|
|
||||||
if ( l != r )
|
|
||||||
return l < r;
|
|
||||||
if ( left.target != right.target )
|
|
||||||
return left.target < right.target;
|
|
||||||
return left.data.distance < right.data.distance;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator== ( const Edge& right ) const {
|
|
||||||
return ( source == right.source && target == right.target && data.distance == right.data.distance &&
|
|
||||||
data.shortcut == right.data.shortcut && data.forward == right.data.forward && data.backward == right.data.backward
|
|
||||||
&& data.via == right.data.via && data.nameID1 == right.data.nameID1 && data.nameID2 == right.data.nameID2
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ContractionCleanup( int numNodes, const std::vector< Edge >& edges ) {
|
|
||||||
_graph = edges;
|
|
||||||
_numNodes = numNodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
~ContractionCleanup() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Run() {
|
|
||||||
RemoveUselessShortcuts();
|
|
||||||
}
|
|
||||||
|
|
||||||
template< class EdgeT >
|
|
||||||
void GetData( std::vector< EdgeT >& edges ) {
|
|
||||||
for ( int edge = 0, endEdges = ( int ) _graph.size(); edge != endEdges; ++edge ) {
|
|
||||||
if(_graph[edge].data.forward || _graph[edge].data.backward) {
|
|
||||||
EdgeT newEdge;
|
|
||||||
newEdge.source = _graph[edge].source;
|
|
||||||
newEdge.target = _graph[edge].target;
|
|
||||||
newEdge.data = _graph[edge].data;
|
|
||||||
edges.push_back( newEdge );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#ifdef _GLIBCXX_PARALLEL
|
|
||||||
__gnu_parallel::sort( edges.begin(), edges.end() );
|
|
||||||
#else
|
|
||||||
sort( edges.begin(), edges.end() );
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
double _Timestamp() {
|
|
||||||
struct timeval tp;
|
|
||||||
gettimeofday(&tp, NULL);
|
|
||||||
return double(tp.tv_sec) + tp.tv_usec / 1000000.;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BuildOutgoingGraph() {
|
|
||||||
//sort edges by source
|
|
||||||
#ifdef _GLIBCXX_PARALLEL
|
|
||||||
__gnu_parallel::sort( _graph.begin(), _graph.end(), Edge::CompareBySource );
|
|
||||||
#else
|
|
||||||
sort( _graph.begin(), _graph.end(), Edge::CompareBySource );
|
|
||||||
#endif
|
|
||||||
try {
|
|
||||||
_firstEdge.resize( _numNodes + 1 );
|
|
||||||
} catch(...) {
|
|
||||||
cerr << "Not enough RAM on machine" << endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_firstEdge[0] = 0;
|
|
||||||
for ( NodeID i = 0, node = 0; i < ( NodeID ) _graph.size(); i++ ) {
|
|
||||||
while ( _graph[i].source != node )
|
|
||||||
_firstEdge[++node] = i;
|
|
||||||
if ( i == ( NodeID ) _graph.size() - 1 )
|
|
||||||
while ( node < _numNodes )
|
|
||||||
_firstEdge[++node] = ( int ) _graph.size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RemoveUselessShortcuts() {
|
|
||||||
int maxThreads = omp_get_max_threads();
|
|
||||||
std::vector < _ThreadData* > threadData;
|
|
||||||
for ( int threadNum = 0; threadNum < maxThreads; ++threadNum ) {
|
|
||||||
threadData.push_back( new _ThreadData( _numNodes ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Scanning for useless shortcuts" << endl;
|
|
||||||
BuildOutgoingGraph();
|
|
||||||
#pragma omp parallel for
|
|
||||||
for ( int i = 0; i < ( int ) _graph.size(); i++ ) {
|
|
||||||
for ( unsigned edge = _firstEdge[_graph[i].source]; edge < _firstEdge[_graph[i].source + 1]; ++edge ) {
|
|
||||||
if ( edge == (unsigned)i )
|
|
||||||
continue;
|
|
||||||
if ( _graph[edge].target != _graph[i].target )
|
|
||||||
continue;
|
|
||||||
if ( _graph[edge].data.distance < _graph[i].data.distance )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
_graph[edge].data.forward &= !_graph[i].data.forward;
|
|
||||||
_graph[edge].data.backward &= !_graph[i].data.backward;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !_graph[i].data.forward && !_graph[i].data.backward )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
//only remove shortcuts
|
|
||||||
if ( !_graph[i].data.shortcut )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if ( _graph[i].data.forward ) {
|
|
||||||
int result = _ComputeDistance( _graph[i].source, _graph[i].target, threadData[omp_get_thread_num()] );
|
|
||||||
if ( result < _graph[i].data.distance ) {
|
|
||||||
_graph[i].data.forward = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( _graph[i].data.backward ) {
|
|
||||||
int result = _ComputeDistance( _graph[i].target, _graph[i].source, threadData[omp_get_thread_num()] );
|
|
||||||
|
|
||||||
if ( result < _graph[i].data.distance ) {
|
|
||||||
_graph[i].data.backward = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Removing edges" << endl;
|
|
||||||
int useful = 0;
|
|
||||||
for ( int i = 0; i < ( int ) _graph.size(); i++ ) {
|
|
||||||
if ( !_graph[i].data.forward && !_graph[i].data.backward && _graph[i].data.shortcut )
|
|
||||||
continue;
|
|
||||||
_graph[useful] = _graph[i];
|
|
||||||
useful++;
|
|
||||||
}
|
|
||||||
cout << "Removed " << _graph.size() - useful << " useless shortcuts" << endl;
|
|
||||||
_graph.resize( useful );
|
|
||||||
|
|
||||||
for ( int threadNum = 0; threadNum < maxThreads; ++threadNum ) {
|
|
||||||
delete threadData[threadNum];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _ComputeStep( _Heap* heapForward, _Heap* heapBackward, bool forwardDirection, NodeID* middle, int* targetDistance ) {
|
|
||||||
|
|
||||||
const NodeID node = heapForward->DeleteMin();
|
|
||||||
const int distance = heapForward->GetKey( node );
|
|
||||||
|
|
||||||
if ( heapBackward->WasInserted( node ) ) {
|
|
||||||
const int newDistance = heapBackward->GetKey( node ) + distance;
|
|
||||||
if ( newDistance < *targetDistance ) {
|
|
||||||
*middle = node;
|
|
||||||
*targetDistance = newDistance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( distance > *targetDistance ) {
|
|
||||||
heapForward->DeleteAll();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for ( int edge = _firstEdge[node], endEdges = _firstEdge[node + 1]; edge != endEdges; ++edge ) {
|
|
||||||
const NodeID to = _graph[edge].target;
|
|
||||||
const int edgeWeight = _graph[edge].data.distance;
|
|
||||||
assert( edgeWeight > 0 );
|
|
||||||
const int toDistance = distance + edgeWeight;
|
|
||||||
|
|
||||||
if ( (forwardDirection ? _graph[edge].data.forward : _graph[edge].data.backward ) ) {
|
|
||||||
//New Node discovered -> Add to Heap + Node Info Storage
|
|
||||||
if ( !heapForward->WasInserted( to ) )
|
|
||||||
heapForward->Insert( to, toDistance, node );
|
|
||||||
|
|
||||||
//Found a shorter Path -> Update distance
|
|
||||||
else if ( toDistance < heapForward->GetKey( to ) ) {
|
|
||||||
heapForward->DecreaseKey( to, toDistance );
|
|
||||||
//new parent
|
|
||||||
heapForward->GetData( to ) = node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int _ComputeDistance( NodeID source, NodeID target, _ThreadData * data, std::vector< NodeID >* path = NULL ) {
|
|
||||||
data->_heapForward->Clear();
|
|
||||||
data->_heapBackward->Clear();
|
|
||||||
//insert source into heap
|
|
||||||
data->_heapForward->Insert( source, 0, source );
|
|
||||||
data->_heapBackward->Insert( target, 0, target );
|
|
||||||
|
|
||||||
int targetDistance = (std::numeric_limits< int >::max)();
|
|
||||||
NodeID middle = (std::numeric_limits<NodeID>::max)();
|
|
||||||
|
|
||||||
while ( data->_heapForward->Size() + data->_heapBackward->Size() > 0 ) {
|
|
||||||
if ( data->_heapForward->Size() > 0 ) {
|
|
||||||
_ComputeStep( data->_heapForward, data->_heapBackward, true, &middle, &targetDistance );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( data->_heapBackward->Size() > 0 ) {
|
|
||||||
_ComputeStep( data->_heapBackward, data->_heapForward, false, &middle, &targetDistance );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return targetDistance;
|
|
||||||
}
|
|
||||||
NodeID _numNodes;
|
|
||||||
std::vector< Edge > _graph;
|
|
||||||
std::vector< unsigned > _firstEdge;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // CONTRACTIONCLEANUP_H_INCLUDED
|
|
||||||
@@ -1,82 +1,93 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, others 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
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
|
Redistributions of source code must retain the above copyright notice, this list
|
||||||
along with this program; if not, write to the Free Software
|
of conditions and the following disclaimer.
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
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 CONTRACTOR_H_INCLUDED
|
#ifndef CONTRACTOR_H_INCLUDED
|
||||||
#define CONTRACTOR_H_INCLUDED
|
#define CONTRACTOR_H_INCLUDED
|
||||||
#ifdef _GLIBCXX_PARALLEL
|
|
||||||
#include <parallel/algorithm>
|
|
||||||
#else
|
|
||||||
#include <algorithm>
|
|
||||||
#endif
|
|
||||||
#include <boost/shared_ptr.hpp>
|
|
||||||
|
|
||||||
|
#include "TemporaryStorage.h"
|
||||||
|
#include "../DataStructures/BinaryHeap.h"
|
||||||
|
#include "../DataStructures/DeallocatingVector.h"
|
||||||
#include "../DataStructures/DynamicGraph.h"
|
#include "../DataStructures/DynamicGraph.h"
|
||||||
#include "../DataStructures/Percent.h"
|
#include "../DataStructures/Percent.h"
|
||||||
#include "../DataStructures/BinaryHeap.h"
|
#include "../DataStructures/XORFastHash.h"
|
||||||
#include <ctime>
|
#include "../DataStructures/XORFastHashStorage.h"
|
||||||
#include <vector>
|
#include "../Util/OpenMPWrapper.h"
|
||||||
#include <queue>
|
#include "../Util/SimpleLogger.h"
|
||||||
#include <set>
|
#include "../Util/StringUtil.h"
|
||||||
#include <stack>
|
|
||||||
|
#include <boost/assert.hpp>
|
||||||
|
#include <boost/foreach.hpp>
|
||||||
|
#include <boost/lambda/lambda.hpp>
|
||||||
|
#include <boost/make_shared.hpp>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#ifdef _OPEMP
|
#include <vector>
|
||||||
#include <omp.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class Contractor {
|
class Contractor {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct ContractorEdgeData {
|
||||||
struct _EdgeBasedContractorEdgeData {
|
ContractorEdgeData() :
|
||||||
|
distance(0), id(0), originalEdges(0), shortcut(0), forward(0), backward(0), originalViaNodeID(false) {}
|
||||||
|
ContractorEdgeData( unsigned _distance, unsigned _originalEdges, unsigned _id, bool _shortcut, bool _forward, bool _backward) :
|
||||||
|
distance(_distance), id(_id), originalEdges(std::min((unsigned)1<<28, _originalEdges) ), shortcut(_shortcut), forward(_forward), backward(_backward), originalViaNodeID(false) {}
|
||||||
unsigned distance;
|
unsigned distance;
|
||||||
unsigned originalEdges;
|
unsigned id;
|
||||||
unsigned via;
|
unsigned originalEdges:28;
|
||||||
unsigned nameID;
|
bool shortcut:1;
|
||||||
bool shortcut;
|
bool forward:1;
|
||||||
bool forward;
|
bool backward:1;
|
||||||
bool backward;
|
bool originalViaNodeID:1;
|
||||||
short turnInstruction;
|
|
||||||
} data;
|
} data;
|
||||||
|
|
||||||
struct _HeapData {
|
struct _HeapData {
|
||||||
|
short hop;
|
||||||
bool target;
|
bool target;
|
||||||
_HeapData() : target(false) {}
|
_HeapData() : hop(0), target(false) {}
|
||||||
_HeapData( bool t ) : target(t) {}
|
_HeapData( short h, bool t ) : hop(h), target(t) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef DynamicGraph< _EdgeBasedContractorEdgeData > _DynamicGraph;
|
typedef DynamicGraph< ContractorEdgeData > _DynamicGraph;
|
||||||
typedef BinaryHeap< NodeID, NodeID, int, _HeapData> _Heap;
|
// typedef BinaryHeap< NodeID, NodeID, int, _HeapData, ArrayStorage<NodeID, NodeID> > _Heap;
|
||||||
typedef _DynamicGraph::InputEdge _ImportEdge;
|
typedef BinaryHeap< NodeID, NodeID, int, _HeapData, XORFastHashStorage<NodeID, NodeID> > _Heap;
|
||||||
|
typedef _DynamicGraph::InputEdge _ContractorEdge;
|
||||||
|
|
||||||
struct _ThreadData {
|
struct _ThreadData {
|
||||||
_Heap heap;
|
_Heap heap;
|
||||||
std::vector< _ImportEdge > insertedEdges;
|
std::vector< _ContractorEdge > insertedEdges;
|
||||||
std::vector< NodeID > neighbours;
|
std::vector< NodeID > neighbours;
|
||||||
_ThreadData( NodeID nodes ): heap( nodes ) {
|
_ThreadData( NodeID nodes ): heap( nodes ) { }
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _PriorityData {
|
struct _PriorityData {
|
||||||
int depth;
|
int depth;
|
||||||
NodeID bias;
|
_PriorityData() : depth(0) { }
|
||||||
_PriorityData() : depth(0), bias(0) { }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _ContractionInformation {
|
struct _ContractionInformation {
|
||||||
@@ -84,89 +95,84 @@ private:
|
|||||||
int edgesAdded;
|
int edgesAdded;
|
||||||
int originalEdgesDeleted;
|
int originalEdgesDeleted;
|
||||||
int originalEdgesAdded;
|
int originalEdgesAdded;
|
||||||
_ContractionInformation() {
|
_ContractionInformation() : edgesDeleted(0), edgesAdded(0), originalEdgesDeleted(0), originalEdgesAdded(0) {}
|
||||||
edgesAdded = edgesDeleted = originalEdgesAdded = originalEdgesDeleted = 0;
|
};
|
||||||
}
|
|
||||||
|
struct _RemainingNodeData {
|
||||||
|
_RemainingNodeData() : id (0), isIndependent(false) {}
|
||||||
|
NodeID id:31;
|
||||||
|
bool isIndependent:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _NodePartitionor {
|
struct _NodePartitionor {
|
||||||
bool operator()( std::pair< NodeID, bool > nodeData ) {
|
inline bool operator()(_RemainingNodeData & nodeData ) const {
|
||||||
return !nodeData.second;
|
return !nodeData.isIndependent;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
template< class InputEdge >
|
template<class ContainerT >
|
||||||
Contractor( int nodes, std::vector< InputEdge >& inputEdges, unsigned eqf = 2, unsigned oqf = 1, unsigned df = 1) : edgeQuotionFactor(eqf), originalQuotientFactor(oqf), depthFactor(df) {
|
Contractor( int nodes, ContainerT& inputEdges) {
|
||||||
|
std::vector< _ContractorEdge > edges;
|
||||||
|
edges.reserve(inputEdges.size()*2);
|
||||||
|
temp_edge_counter = 0;
|
||||||
|
|
||||||
std::vector< _ImportEdge > edges;
|
typename ContainerT::deallocation_iterator diter = inputEdges.dbegin();
|
||||||
edges.reserve( 2 * inputEdges.size() );
|
typename ContainerT::deallocation_iterator dend = inputEdges.dend();
|
||||||
for ( typename std::vector< InputEdge >::const_iterator i = inputEdges.begin(), e = inputEdges.end(); i != e; ++i ) {
|
|
||||||
_ImportEdge edge;
|
|
||||||
edge.source = i->source();
|
|
||||||
edge.target = i->target();
|
|
||||||
|
|
||||||
edge.data.distance = (std::max)((int)i->weight(), 1 );
|
_ContractorEdge newEdge;
|
||||||
assert( edge.data.distance > 0 );
|
while(diter!=dend) {
|
||||||
|
newEdge.source = diter->source();
|
||||||
|
newEdge.target = diter->target();
|
||||||
|
newEdge.data = ContractorEdgeData( (std::max)((int)diter->weight(), 1 ), 1, diter->id(), false, diter->isForward(), diter->isBackward());
|
||||||
|
|
||||||
|
BOOST_ASSERT_MSG( newEdge.data.distance > 0, "edge distance < 1" );
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if ( edge.data.distance > 24 * 60 * 60 * 10 ) {
|
if ( newEdge.data.distance > 24 * 60 * 60 * 10 ) {
|
||||||
std::cout << "Edge Weight too large -> May lead to invalid CH" << std::endl;
|
SimpleLogger().Write(logWARNING) <<
|
||||||
continue;
|
"Edge weight large -> " << newEdge.data.distance;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
edge.data.shortcut = false;
|
edges.push_back( newEdge );
|
||||||
edge.data.nameID = i->getNameIDOfTurnTarget();
|
std::swap( newEdge.source, newEdge.target );
|
||||||
edge.data.via = i->via();
|
newEdge.data.forward = diter->isBackward();
|
||||||
edge.data.turnInstruction = i->turnInstruction();
|
newEdge.data.backward = diter->isForward();
|
||||||
edge.data.forward = i->isForward();
|
edges.push_back( newEdge );
|
||||||
edge.data.backward = i->isBackward();
|
++diter;
|
||||||
edge.data.originalEdges = 1;
|
|
||||||
edges.push_back( edge );
|
|
||||||
std::swap( edge.source, edge.target );
|
|
||||||
edge.data.forward = i->isBackward();
|
|
||||||
edge.data.backward = i->isForward();
|
|
||||||
edges.push_back( edge );
|
|
||||||
}
|
}
|
||||||
//remove data from memory
|
//clear input vector and trim the current set of edges with the well-known swap trick
|
||||||
inputEdges.clear();
|
inputEdges.clear();
|
||||||
std::vector< InputEdge >().swap( inputEdges );
|
|
||||||
|
|
||||||
#ifdef _GLIBCXX_PARALLEL
|
|
||||||
__gnu_parallel::sort( edges.begin(), edges.end() );
|
|
||||||
#else
|
|
||||||
sort( edges.begin(), edges.end() );
|
sort( edges.begin(), edges.end() );
|
||||||
#endif
|
|
||||||
NodeID edge = 0;
|
NodeID edge = 0;
|
||||||
for ( NodeID i = 0; i < edges.size(); ) {
|
for ( NodeID i = 0; i < edges.size(); ) {
|
||||||
const NodeID source = edges[i].source;
|
const NodeID source = edges[i].source;
|
||||||
const NodeID target = edges[i].target;
|
const NodeID target = edges[i].target;
|
||||||
const NodeID via = edges[i].data.via;
|
const NodeID id = edges[i].data.id;
|
||||||
const short turnType = edges[i].data.turnInstruction;
|
|
||||||
//remove eigenloops
|
//remove eigenloops
|
||||||
if ( source == target ) {
|
if ( source == target ) {
|
||||||
i++;
|
i++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
_ImportEdge forwardEdge;
|
_ContractorEdge forwardEdge;
|
||||||
_ImportEdge backwardEdge;
|
_ContractorEdge backwardEdge;
|
||||||
forwardEdge.source = backwardEdge.source = source;
|
forwardEdge.source = backwardEdge.source = source;
|
||||||
forwardEdge.target = backwardEdge.target = target;
|
forwardEdge.target = backwardEdge.target = target;
|
||||||
forwardEdge.data.forward = backwardEdge.data.backward = true;
|
forwardEdge.data.forward = backwardEdge.data.backward = true;
|
||||||
forwardEdge.data.backward = backwardEdge.data.forward = false;
|
forwardEdge.data.backward = backwardEdge.data.forward = false;
|
||||||
forwardEdge.data.turnInstruction = backwardEdge.data.turnInstruction = turnType;
|
|
||||||
forwardEdge.data.nameID = backwardEdge.data.nameID = edges[i].data.nameID;
|
|
||||||
forwardEdge.data.shortcut = backwardEdge.data.shortcut = false;
|
forwardEdge.data.shortcut = backwardEdge.data.shortcut = false;
|
||||||
forwardEdge.data.via = backwardEdge.data.via = via;
|
forwardEdge.data.id = backwardEdge.data.id = id;
|
||||||
forwardEdge.data.originalEdges = backwardEdge.data.originalEdges = 1;
|
forwardEdge.data.originalEdges = backwardEdge.data.originalEdges = 1;
|
||||||
forwardEdge.data.distance = backwardEdge.data.distance = std::numeric_limits< int >::max();
|
forwardEdge.data.distance = backwardEdge.data.distance = std::numeric_limits< int >::max();
|
||||||
//remove parallel edges
|
//remove parallel edges
|
||||||
while ( i < edges.size() && edges[i].source == source && edges[i].target == target ) {
|
while ( i < edges.size() && edges[i].source == source && edges[i].target == target ) {
|
||||||
if ( edges[i].data.forward )
|
if ( edges[i].data.forward) {
|
||||||
forwardEdge.data.distance = std::min( edges[i].data.distance, forwardEdge.data.distance );
|
forwardEdge.data.distance = std::min( edges[i].data.distance, forwardEdge.data.distance );
|
||||||
if ( edges[i].data.backward )
|
}
|
||||||
|
if ( edges[i].data.backward) {
|
||||||
backwardEdge.data.distance = std::min( edges[i].data.distance, backwardEdge.data.distance );
|
backwardEdge.data.distance = std::min( edges[i].data.distance, backwardEdge.data.distance );
|
||||||
i++;
|
}
|
||||||
|
++i;
|
||||||
}
|
}
|
||||||
//merge edges (s,t) and (t,s) into bidirectional edge
|
//merge edges (s,t) and (t,s) into bidirectional edge
|
||||||
if ( forwardEdge.data.distance == backwardEdge.data.distance ) {
|
if ( forwardEdge.data.distance == backwardEdge.data.distance ) {
|
||||||
@@ -183,37 +189,62 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << "ok" << std::endl << "merged " << edges.size() - edge << " edges out of " << edges.size() << std::endl;
|
std::cout << "merged " << edges.size() - edge << " edges out of " << edges.size() << std::endl;
|
||||||
edges.resize( edge );
|
edges.resize( edge );
|
||||||
_graph.reset( new _DynamicGraph( nodes, edges ) );
|
_graph = boost::make_shared<_DynamicGraph>( nodes, edges );
|
||||||
std::vector< _ImportEdge >().swap( edges );
|
edges.clear();
|
||||||
|
std::vector<_ContractorEdge>().swap(edges);
|
||||||
|
BOOST_ASSERT( 0 == edges.capacity() );
|
||||||
|
// unsigned maxdegree = 0;
|
||||||
|
// NodeID highestNode = 0;
|
||||||
|
//
|
||||||
|
// for(unsigned i = 0; i < _graph->GetNumberOfNodes(); ++i) {
|
||||||
|
// unsigned degree = _graph->EndEdges(i) - _graph->BeginEdges(i);
|
||||||
|
// if(degree > maxdegree) {
|
||||||
|
// maxdegree = degree;
|
||||||
|
// highestNode = i;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// SimpleLogger().Write() << "edges at node with id " << highestNode << " has degree " << maxdegree;
|
||||||
|
// for(unsigned i = _graph->BeginEdges(highestNode); i < _graph->EndEdges(highestNode); ++i) {
|
||||||
|
// SimpleLogger().Write() << " ->(" << highestNode << "," << _graph->GetTarget(i) << "); via: " << _graph->GetEdgeData(i).via;
|
||||||
|
// }
|
||||||
|
|
||||||
|
//Create temporary file
|
||||||
|
|
||||||
|
// GetTemporaryFileName(temporaryEdgeStorageFilename);
|
||||||
|
edge_storage_slot = TemporaryStorage::GetInstance().AllocateSlot();
|
||||||
|
std::cout << "contractor finished initalization" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
~Contractor() { }
|
~Contractor() {
|
||||||
|
//Delete temporary file
|
||||||
|
// remove(temporaryEdgeStorageFilename.c_str());
|
||||||
|
TemporaryStorage::GetInstance().DeallocateSlot(edge_storage_slot);
|
||||||
|
}
|
||||||
|
|
||||||
void Run() {
|
void Run() {
|
||||||
const NodeID numberOfNodes = _graph->GetNumberOfNodes();
|
const NodeID numberOfNodes = _graph->GetNumberOfNodes();
|
||||||
Percent p (numberOfNodes);
|
Percent p (numberOfNodes);
|
||||||
|
|
||||||
unsigned maxThreads = omp_get_max_threads();
|
const unsigned maxThreads = omp_get_max_threads();
|
||||||
std::vector < _ThreadData* > threadData;
|
std::vector < _ThreadData* > threadData;
|
||||||
for ( unsigned threadNum = 0; threadNum < maxThreads; ++threadNum ) {
|
for ( unsigned threadNum = 0; threadNum < maxThreads; ++threadNum ) {
|
||||||
threadData.push_back( new _ThreadData( numberOfNodes ) );
|
threadData.push_back( new _ThreadData( numberOfNodes ) );
|
||||||
}
|
}
|
||||||
std::cout << "Contractor is using " << maxThreads << " threads" << std::endl;
|
std::cout << "Contractor is using " << maxThreads << " threads" << std::endl;
|
||||||
|
|
||||||
NodeID levelID = 0;
|
NodeID numberOfContractedNodes = 0;
|
||||||
std::vector< std::pair< NodeID, bool > > remainingNodes( numberOfNodes );
|
std::vector< _RemainingNodeData > remainingNodes( numberOfNodes );
|
||||||
std::vector< double > nodePriority( numberOfNodes );
|
std::vector< float > nodePriority( numberOfNodes );
|
||||||
std::vector< _PriorityData > nodeData( numberOfNodes );
|
std::vector< _PriorityData > nodeData( numberOfNodes );
|
||||||
|
|
||||||
//initialize the variables
|
//initialize the variables
|
||||||
#pragma omp parallel for schedule ( guided )
|
#pragma omp parallel for schedule ( guided )
|
||||||
for ( int x = 0; x < ( int ) numberOfNodes; ++x )
|
for ( int x = 0; x < ( int ) numberOfNodes; ++x ) {
|
||||||
remainingNodes[x].first = x;
|
remainingNodes[x].id = x;
|
||||||
std::random_shuffle( remainingNodes.begin(), remainingNodes.end() );
|
}
|
||||||
for ( int x = 0; x < ( int ) numberOfNodes; ++x )
|
|
||||||
nodeData[remainingNodes[x].first].bias = x;
|
|
||||||
|
|
||||||
std::cout << "initializing elimination PQ ..." << std::flush;
|
std::cout << "initializing elimination PQ ..." << std::flush;
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
@@ -224,9 +255,93 @@ public:
|
|||||||
nodePriority[x] = _Evaluate( data, &nodeData[x], x );
|
nodePriority[x] = _Evaluate( data, &nodeData[x], x );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << "ok" << std::endl << "preprocessing ..." << std::flush;
|
std::cout << "ok" << std::endl << "preprocessing " << numberOfNodes << " nodes ..." << std::flush;
|
||||||
|
|
||||||
|
bool flushedContractor = false;
|
||||||
|
while ( numberOfNodes > 2 && numberOfContractedNodes < numberOfNodes ) {
|
||||||
|
if(!flushedContractor && (numberOfContractedNodes > (numberOfNodes*0.65) ) ){
|
||||||
|
DeallocatingVector<_ContractorEdge> newSetOfEdges; //this one is not explicitely cleared since it goes out of scope anywa
|
||||||
|
std::cout << " [flush " << numberOfContractedNodes << " nodes] " << std::flush;
|
||||||
|
|
||||||
|
//Delete old heap data to free memory that we need for the coming operations
|
||||||
|
BOOST_FOREACH(_ThreadData * data, threadData) {
|
||||||
|
delete data;
|
||||||
|
}
|
||||||
|
threadData.clear();
|
||||||
|
|
||||||
|
//Create new priority array
|
||||||
|
std::vector<float> newNodePriority(remainingNodes.size());
|
||||||
|
//this map gives the old IDs from the new ones, necessary to get a consistent graph at the end of contraction
|
||||||
|
oldNodeIDFromNewNodeIDMap.resize(remainingNodes.size());
|
||||||
|
//this map gives the new IDs from the old ones, necessary to remap targets from the remaining graph
|
||||||
|
std::vector<NodeID> newNodeIDFromOldNodeIDMap(numberOfNodes, UINT_MAX);
|
||||||
|
|
||||||
|
//build forward and backward renumbering map and remap ids in remainingNodes and Priorities.
|
||||||
|
for(unsigned newNodeID = 0; newNodeID < remainingNodes.size(); ++newNodeID) {
|
||||||
|
//create renumbering maps in both directions
|
||||||
|
oldNodeIDFromNewNodeIDMap[newNodeID] = remainingNodes[newNodeID].id;
|
||||||
|
newNodeIDFromOldNodeIDMap[remainingNodes[newNodeID].id] = newNodeID;
|
||||||
|
newNodePriority[newNodeID] = nodePriority[remainingNodes[newNodeID].id];
|
||||||
|
remainingNodes[newNodeID].id = newNodeID;
|
||||||
|
}
|
||||||
|
TemporaryStorage & tempStorage = TemporaryStorage::GetInstance();
|
||||||
|
//walk over all nodes
|
||||||
|
for(unsigned i = 0; i < _graph->GetNumberOfNodes(); ++i) {
|
||||||
|
const NodeID start = i;
|
||||||
|
for(_DynamicGraph::EdgeIterator currentEdge = _graph->BeginEdges(start); currentEdge < _graph->EndEdges(start); ++currentEdge) {
|
||||||
|
_DynamicGraph::EdgeData & data = _graph->GetEdgeData(currentEdge);
|
||||||
|
const NodeID target = _graph->GetTarget(currentEdge);
|
||||||
|
if(UINT_MAX == newNodeIDFromOldNodeIDMap[i] ){
|
||||||
|
//Save edges of this node w/o renumbering.
|
||||||
|
tempStorage.WriteToSlot(edge_storage_slot, (char*)&start, sizeof(NodeID));
|
||||||
|
tempStorage.WriteToSlot(edge_storage_slot, (char*)&target, sizeof(NodeID));
|
||||||
|
tempStorage.WriteToSlot(edge_storage_slot, (char*)&data, sizeof(_DynamicGraph::EdgeData));
|
||||||
|
++temp_edge_counter;
|
||||||
|
} else {
|
||||||
|
//node is not yet contracted.
|
||||||
|
//add (renumbered) outgoing edges to new DynamicGraph.
|
||||||
|
_ContractorEdge newEdge;
|
||||||
|
newEdge.source = newNodeIDFromOldNodeIDMap[start];
|
||||||
|
newEdge.target = newNodeIDFromOldNodeIDMap[target];
|
||||||
|
newEdge.data = data;
|
||||||
|
newEdge.data.originalViaNodeID = true;
|
||||||
|
BOOST_ASSERT_MSG(
|
||||||
|
UINT_MAX != newNodeIDFromOldNodeIDMap[start],
|
||||||
|
"new start id not resolveable"
|
||||||
|
);
|
||||||
|
BOOST_ASSERT_MSG(
|
||||||
|
UINT_MAX != newNodeIDFromOldNodeIDMap[target],
|
||||||
|
"new target id not resolveable"
|
||||||
|
);
|
||||||
|
newSetOfEdges.push_back(newEdge);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Delete map from old NodeIDs to new ones.
|
||||||
|
std::vector<NodeID>().swap(newNodeIDFromOldNodeIDMap);
|
||||||
|
|
||||||
|
//Replace old priorities array by new one
|
||||||
|
nodePriority.swap(newNodePriority);
|
||||||
|
//Delete old nodePriority vector
|
||||||
|
std::vector<float>().swap(newNodePriority);
|
||||||
|
//old Graph is removed
|
||||||
|
_graph.reset();
|
||||||
|
|
||||||
|
//create new graph
|
||||||
|
std::sort(newSetOfEdges.begin(), newSetOfEdges.end());
|
||||||
|
_graph = boost::make_shared<_DynamicGraph>(remainingNodes.size(), newSetOfEdges);
|
||||||
|
|
||||||
|
newSetOfEdges.clear();
|
||||||
|
flushedContractor = true;
|
||||||
|
|
||||||
|
//INFO: MAKE SURE THIS IS THE LAST OPERATION OF THE FLUSH!
|
||||||
|
//reinitialize heaps and ThreadData objects with appropriate size
|
||||||
|
for ( unsigned threadNum = 0; threadNum < maxThreads; ++threadNum ) {
|
||||||
|
threadData.push_back( new _ThreadData( _graph->GetNumberOfNodes() ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while ( levelID < numberOfNodes ) {
|
|
||||||
const int last = ( int ) remainingNodes.size();
|
const int last = ( int ) remainingNodes.size();
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
{
|
{
|
||||||
@@ -234,12 +349,12 @@ public:
|
|||||||
_ThreadData* const data = threadData[omp_get_thread_num()];
|
_ThreadData* const data = threadData[omp_get_thread_num()];
|
||||||
#pragma omp for schedule ( guided )
|
#pragma omp for schedule ( guided )
|
||||||
for ( int i = 0; i < last; ++i ) {
|
for ( int i = 0; i < last; ++i ) {
|
||||||
const NodeID node = remainingNodes[i].first;
|
const NodeID node = remainingNodes[i].id;
|
||||||
remainingNodes[i].second = _IsIndependent( nodePriority, nodeData, data, node );
|
remainingNodes[i].isIndependent = _IsIndependent( nodePriority/*, nodeData*/, data, node );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_NodePartitionor functor;
|
_NodePartitionor functor;
|
||||||
const std::vector < std::pair < NodeID, bool > >::const_iterator first = stable_partition( remainingNodes.begin(), remainingNodes.end(), functor );
|
const std::vector < _RemainingNodeData >::const_iterator first = stable_partition( remainingNodes.begin(), remainingNodes.end(), functor );
|
||||||
const int firstIndependent = first - remainingNodes.begin();
|
const int firstIndependent = first - remainingNodes.begin();
|
||||||
//contract independent nodes
|
//contract independent nodes
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
@@ -247,10 +362,11 @@ public:
|
|||||||
_ThreadData* data = threadData[omp_get_thread_num()];
|
_ThreadData* data = threadData[omp_get_thread_num()];
|
||||||
#pragma omp for schedule ( guided ) nowait
|
#pragma omp for schedule ( guided ) nowait
|
||||||
for ( int position = firstIndependent ; position < last; ++position ) {
|
for ( int position = firstIndependent ; position < last; ++position ) {
|
||||||
NodeID x = remainingNodes[position].first;
|
NodeID x = remainingNodes[position].id;
|
||||||
_Contract< false > ( data, x );
|
_Contract< false > ( data, x );
|
||||||
nodePriority[x] = -1;
|
//nodePriority[x] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::sort( data->insertedEdges.begin(), data->insertedEdges.end() );
|
std::sort( data->insertedEdges.begin(), data->insertedEdges.end() );
|
||||||
}
|
}
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
@@ -258,18 +374,31 @@ public:
|
|||||||
_ThreadData* data = threadData[omp_get_thread_num()];
|
_ThreadData* data = threadData[omp_get_thread_num()];
|
||||||
#pragma omp for schedule ( guided ) nowait
|
#pragma omp for schedule ( guided ) nowait
|
||||||
for ( int position = firstIndependent ; position < last; ++position ) {
|
for ( int position = firstIndependent ; position < last; ++position ) {
|
||||||
NodeID x = remainingNodes[position].first;
|
NodeID x = remainingNodes[position].id;
|
||||||
_DeleteIncomingEdges( data, x );
|
_DeleteIncomingEdges( data, x );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//insert new edges
|
//insert new edges
|
||||||
for ( unsigned threadNum = 0; threadNum < maxThreads; ++threadNum ) {
|
for ( unsigned threadNum = 0; threadNum < maxThreads; ++threadNum ) {
|
||||||
_ThreadData& data = *threadData[threadNum];
|
_ThreadData& data = *threadData[threadNum];
|
||||||
for ( int i = 0; i < ( int ) data.insertedEdges.size(); ++i ) {
|
BOOST_FOREACH(const _ContractorEdge& edge, data.insertedEdges) {
|
||||||
const _ImportEdge& edge = data.insertedEdges[i];
|
_DynamicGraph::EdgeIterator currentEdgeID = _graph->FindEdge(edge.source, edge.target);
|
||||||
|
if(currentEdgeID < _graph->EndEdges(edge.source) ) {
|
||||||
|
_DynamicGraph::EdgeData & currentEdgeData = _graph->GetEdgeData(currentEdgeID);
|
||||||
|
if( currentEdgeData.shortcut &&
|
||||||
|
edge.data.forward == currentEdgeData.forward &&
|
||||||
|
edge.data.backward == currentEdgeData.backward &&
|
||||||
|
edge.data.distance < currentEdgeData.distance
|
||||||
|
) {
|
||||||
|
// found a duplicate edge with smaller weight, update it.
|
||||||
|
currentEdgeData = edge.data;
|
||||||
|
// currentEdgeData.distance = std::min(currentEdgeData.distance, edge.data.distance);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
_graph->InsertEdge( edge.source, edge.target, edge.data );
|
_graph->InsertEdge( edge.source, edge.target, edge.data );
|
||||||
}
|
}
|
||||||
std::vector< _ImportEdge >().swap( data.insertedEdges );
|
data.insertedEdges.clear();
|
||||||
}
|
}
|
||||||
//update priorities
|
//update priorities
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
@@ -277,46 +406,119 @@ public:
|
|||||||
_ThreadData* data = threadData[omp_get_thread_num()];
|
_ThreadData* data = threadData[omp_get_thread_num()];
|
||||||
#pragma omp for schedule ( guided ) nowait
|
#pragma omp for schedule ( guided ) nowait
|
||||||
for ( int position = firstIndependent ; position < last; ++position ) {
|
for ( int position = firstIndependent ; position < last; ++position ) {
|
||||||
NodeID x = remainingNodes[position].first;
|
NodeID x = remainingNodes[position].id;
|
||||||
_UpdateNeighbours( &nodePriority, &nodeData, data, x );
|
_UpdateNeighbours( nodePriority, nodeData, data, x );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//remove contracted nodes from the pool
|
//remove contracted nodes from the pool
|
||||||
levelID += last - firstIndependent;
|
numberOfContractedNodes += last - firstIndependent;
|
||||||
remainingNodes.resize( firstIndependent );
|
remainingNodes.resize( firstIndependent );
|
||||||
std::vector< std::pair< NodeID, bool > >( remainingNodes ).swap( remainingNodes );
|
std::vector< _RemainingNodeData>( remainingNodes ).swap( remainingNodes );
|
||||||
p.printStatus(levelID);
|
// unsigned maxdegree = 0;
|
||||||
}
|
// unsigned avgdegree = 0;
|
||||||
|
// unsigned mindegree = UINT_MAX;
|
||||||
|
// unsigned quaddegree = 0;
|
||||||
|
//
|
||||||
|
// for(unsigned i = 0; i < remainingNodes.size(); ++i) {
|
||||||
|
// unsigned degree = _graph->EndEdges(remainingNodes[i].first) - _graph->BeginEdges(remainingNodes[i].first);
|
||||||
|
// if(degree > maxdegree)
|
||||||
|
// maxdegree = degree;
|
||||||
|
// if(degree < mindegree)
|
||||||
|
// mindegree = degree;
|
||||||
|
//
|
||||||
|
// avgdegree += degree;
|
||||||
|
// quaddegree += (degree*degree);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// avgdegree /= std::max((unsigned)1,(unsigned)remainingNodes.size() );
|
||||||
|
// quaddegree /= std::max((unsigned)1,(unsigned)remainingNodes.size() );
|
||||||
|
//
|
||||||
|
// SimpleLogger().Write() << "rest: " << remainingNodes.size() << ", max: " << maxdegree << ", min: " << mindegree << ", avg: " << avgdegree << ", quad: " << quaddegree;
|
||||||
|
|
||||||
for ( unsigned threadNum = 0; threadNum < maxThreads; threadNum++ ) {
|
p.printStatus(numberOfContractedNodes);
|
||||||
delete threadData[threadNum];
|
|
||||||
}
|
}
|
||||||
|
BOOST_FOREACH(_ThreadData * data, threadData) {
|
||||||
|
delete data;
|
||||||
|
}
|
||||||
|
threadData.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class Edge >
|
template< class Edge >
|
||||||
void GetEdges( std::vector< Edge >& edges ) {
|
inline void GetEdges( DeallocatingVector< Edge >& edges ) {
|
||||||
|
Percent p (_graph->GetNumberOfNodes());
|
||||||
|
SimpleLogger().Write() << "Getting edges of minimized graph";
|
||||||
NodeID numberOfNodes = _graph->GetNumberOfNodes();
|
NodeID numberOfNodes = _graph->GetNumberOfNodes();
|
||||||
for ( NodeID node = 0; node < numberOfNodes; ++node ) {
|
if(_graph->GetNumberOfNodes()) {
|
||||||
for ( _DynamicGraph::EdgeIterator edge = _graph->BeginEdges( node ), endEdges = _graph->EndEdges( node ); edge < endEdges; edge++ ) {
|
Edge newEdge;
|
||||||
const NodeID target = _graph->GetTarget( edge );
|
for ( NodeID node = 0; node < numberOfNodes; ++node ) {
|
||||||
const _EdgeBasedContractorEdgeData& data = _graph->GetEdgeData( edge );
|
p.printStatus(node);
|
||||||
Edge newEdge;
|
for ( _DynamicGraph::EdgeIterator edge = _graph->BeginEdges( node ), endEdges = _graph->EndEdges( node ); edge < endEdges; ++edge ) {
|
||||||
newEdge.source = node;
|
const NodeID target = _graph->GetTarget( edge );
|
||||||
newEdge.target = target;
|
const _DynamicGraph::EdgeData& data = _graph->GetEdgeData( edge );
|
||||||
newEdge.data.distance = data.distance;
|
if( !oldNodeIDFromNewNodeIDMap.empty() ) {
|
||||||
newEdge.data.shortcut = data.shortcut;
|
newEdge.source = oldNodeIDFromNewNodeIDMap[node];
|
||||||
newEdge.data.via = data.via;
|
newEdge.target = oldNodeIDFromNewNodeIDMap[target];
|
||||||
newEdge.data.nameID1 = data.nameID;
|
} else {
|
||||||
newEdge.data.turnInstruction = data.turnInstruction;
|
newEdge.source = node;
|
||||||
newEdge.data.forward = data.forward;
|
newEdge.target = target;
|
||||||
newEdge.data.backward = data.backward;
|
}
|
||||||
edges.push_back( newEdge );
|
BOOST_ASSERT_MSG(
|
||||||
|
UINT_MAX != newEdge.source,
|
||||||
|
"Source id invalid"
|
||||||
|
);
|
||||||
|
BOOST_ASSERT_MSG(
|
||||||
|
UINT_MAX != newEdge.target,
|
||||||
|
"Target id invalid"
|
||||||
|
);
|
||||||
|
newEdge.data.distance = data.distance;
|
||||||
|
newEdge.data.shortcut = data.shortcut;
|
||||||
|
if(
|
||||||
|
!data.originalViaNodeID &&
|
||||||
|
!oldNodeIDFromNewNodeIDMap.empty()
|
||||||
|
) {
|
||||||
|
newEdge.data.id = oldNodeIDFromNewNodeIDMap[data.id];
|
||||||
|
} else {
|
||||||
|
newEdge.data.id = data.id;
|
||||||
|
}
|
||||||
|
BOOST_ASSERT_MSG(
|
||||||
|
newEdge.data.id != INT_MAX, //2^31
|
||||||
|
"edge id invalid"
|
||||||
|
);
|
||||||
|
newEdge.data.forward = data.forward;
|
||||||
|
newEdge.data.backward = data.backward;
|
||||||
|
edges.push_back( newEdge );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_graph.reset();
|
||||||
|
std::vector<NodeID>().swap(oldNodeIDFromNewNodeIDMap);
|
||||||
|
BOOST_ASSERT( 0 == oldNodeIDFromNewNodeIDMap.capacity() );
|
||||||
|
|
||||||
|
TemporaryStorage & tempStorage = TemporaryStorage::GetInstance();
|
||||||
|
//loads edges of graph before renumbering, no need for further numbering action.
|
||||||
|
NodeID start;
|
||||||
|
NodeID target;
|
||||||
|
_DynamicGraph::EdgeData data;
|
||||||
|
|
||||||
|
Edge restored_edge;
|
||||||
|
for(unsigned i = 0; i < temp_edge_counter; ++i) {
|
||||||
|
tempStorage.ReadFromSlot(edge_storage_slot, (char*)&start, sizeof(NodeID));
|
||||||
|
tempStorage.ReadFromSlot(edge_storage_slot, (char*)&target, sizeof(NodeID));
|
||||||
|
tempStorage.ReadFromSlot(edge_storage_slot, (char*)&data, sizeof(_DynamicGraph::EdgeData));
|
||||||
|
restored_edge.source = start;
|
||||||
|
restored_edge.target = target;
|
||||||
|
restored_edge.data.distance = data.distance;
|
||||||
|
restored_edge.data.shortcut = data.shortcut;
|
||||||
|
restored_edge.data.id = data.id;
|
||||||
|
restored_edge.data.forward = data.forward;
|
||||||
|
restored_edge.data.backward = data.backward;
|
||||||
|
edges.push_back( restored_edge );
|
||||||
|
}
|
||||||
|
tempStorage.DeallocateSlot(edge_storage_slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _Dijkstra( const int maxDistance, const unsigned numTargets, const int maxNodes, _ThreadData* data ){
|
inline void _Dijkstra( const int maxDistance, const unsigned numTargets, const int maxNodes, _ThreadData* const data, const NodeID middleNode ){
|
||||||
|
|
||||||
_Heap& heap = data->heap;
|
_Heap& heap = data->heap;
|
||||||
|
|
||||||
@@ -325,62 +527,74 @@ private:
|
|||||||
while ( heap.Size() > 0 ) {
|
while ( heap.Size() > 0 ) {
|
||||||
const NodeID node = heap.DeleteMin();
|
const NodeID node = heap.DeleteMin();
|
||||||
const int distance = heap.GetKey( node );
|
const int distance = heap.GetKey( node );
|
||||||
if ( nodes++ > maxNodes )
|
const short currentHop = heap.GetData( node ).hop+1;
|
||||||
|
|
||||||
|
if ( ++nodes > maxNodes )
|
||||||
return;
|
return;
|
||||||
//Destination settled?
|
//Destination settled?
|
||||||
if ( distance > maxDistance )
|
if ( distance > maxDistance )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( heap.GetData( node ).target ) {
|
if ( heap.GetData( node ).target ) {
|
||||||
targetsFound++;
|
++targetsFound;
|
||||||
if ( targetsFound >= numTargets )
|
if ( targetsFound >= numTargets ) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//iterate over all edges of node
|
//iterate over all edges of node
|
||||||
for ( _DynamicGraph::EdgeIterator edge = _graph->BeginEdges( node ), endEdges = _graph->EndEdges( node ); edge != endEdges; ++edge ) {
|
for ( _DynamicGraph::EdgeIterator edge = _graph->BeginEdges( node ), endEdges = _graph->EndEdges( node ); edge != endEdges; ++edge ) {
|
||||||
const _EdgeBasedContractorEdgeData& data = _graph->GetEdgeData( edge );
|
const ContractorEdgeData& data = _graph->GetEdgeData( edge );
|
||||||
if ( !data.forward )
|
if ( !data.forward ){
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
const NodeID to = _graph->GetTarget( edge );
|
const NodeID to = _graph->GetTarget( edge );
|
||||||
|
if(middleNode == to) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const int toDistance = distance + data.distance;
|
const int toDistance = distance + data.distance;
|
||||||
|
|
||||||
//New Node discovered -> Add to Heap + Node Info Storage
|
//New Node discovered -> Add to Heap + Node Info Storage
|
||||||
if ( !heap.WasInserted( to ) )
|
if ( !heap.WasInserted( to ) ) {
|
||||||
heap.Insert( to, toDistance, _HeapData() );
|
heap.Insert( to, toDistance, _HeapData(currentHop, false) );
|
||||||
|
}
|
||||||
//Found a shorter Path -> Update distance
|
//Found a shorter Path -> Update distance
|
||||||
else if ( toDistance < heap.GetKey( to ) ) {
|
else if ( toDistance < heap.GetKey( to ) ) {
|
||||||
heap.DecreaseKey( to, toDistance );
|
heap.DecreaseKey( to, toDistance );
|
||||||
//heap.GetData( to ).hops = hops + 1;
|
heap.GetData( to ).hop = currentHop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double _Evaluate( _ThreadData* const data, _PriorityData* const nodeData, NodeID node ){
|
inline float _Evaluate( _ThreadData* const data, _PriorityData* const nodeData, const NodeID node){
|
||||||
_ContractionInformation stats;
|
_ContractionInformation stats;
|
||||||
|
|
||||||
//perform simulated contraction
|
//perform simulated contraction
|
||||||
_Contract< true > ( data, node, &stats );
|
_Contract< true> ( data, node, &stats );
|
||||||
|
|
||||||
// Result will contain the priority
|
// Result will contain the priority
|
||||||
if ( stats.edgesDeleted == 0 || stats.originalEdgesDeleted == 0 )
|
float result;
|
||||||
return depthFactor * nodeData->depth;
|
if ( 0 == (stats.edgesDeleted*stats.originalEdgesDeleted) )
|
||||||
return edgeQuotionFactor * ((( double ) stats.edgesAdded ) / stats.edgesDeleted ) + originalQuotientFactor * ((( double ) stats.originalEdgesAdded ) / stats.originalEdgesDeleted ) + depthFactor * nodeData->depth;
|
result = 1 * nodeData->depth;
|
||||||
|
else
|
||||||
|
result = 2 * ((( float ) stats.edgesAdded ) / stats.edgesDeleted ) + 4 * ((( float ) stats.originalEdgesAdded ) / stats.originalEdgesDeleted ) + 1 * nodeData->depth;
|
||||||
|
assert( result >= 0 );
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template< bool Simulate > bool _Contract( _ThreadData* data, NodeID node, _ContractionInformation* stats = NULL ) {
|
template< bool Simulate >
|
||||||
|
inline bool _Contract( _ThreadData* data, NodeID node, _ContractionInformation* stats = NULL ) {
|
||||||
_Heap& heap = data->heap;
|
_Heap& heap = data->heap;
|
||||||
int insertedEdgesSize = data->insertedEdges.size();
|
int insertedEdgesSize = data->insertedEdges.size();
|
||||||
std::vector< _ImportEdge >& insertedEdges = data->insertedEdges;
|
std::vector< _ContractorEdge >& insertedEdges = data->insertedEdges;
|
||||||
|
|
||||||
for ( _DynamicGraph::EdgeIterator inEdge = _graph->BeginEdges( node ), endInEdges = _graph->EndEdges( node ); inEdge != endInEdges; ++inEdge ) {
|
for ( _DynamicGraph::EdgeIterator inEdge = _graph->BeginEdges( node ), endInEdges = _graph->EndEdges( node ); inEdge != endInEdges; ++inEdge ) {
|
||||||
const _EdgeBasedContractorEdgeData& inData = _graph->GetEdgeData( inEdge );
|
const ContractorEdgeData& inData = _graph->GetEdgeData( inEdge );
|
||||||
const NodeID source = _graph->GetTarget( inEdge );
|
const NodeID source = _graph->GetTarget( inEdge );
|
||||||
if ( Simulate ) {
|
if ( Simulate ) {
|
||||||
assert( stats != NULL );
|
assert( stats != NULL );
|
||||||
stats->edgesDeleted++;
|
++stats->edgesDeleted;
|
||||||
stats->originalEdgesDeleted += inData.originalEdges;
|
stats->originalEdgesDeleted += inData.originalEdges;
|
||||||
}
|
}
|
||||||
if ( !inData.backward )
|
if ( !inData.backward )
|
||||||
@@ -388,55 +602,46 @@ private:
|
|||||||
|
|
||||||
heap.Clear();
|
heap.Clear();
|
||||||
heap.Insert( source, 0, _HeapData() );
|
heap.Insert( source, 0, _HeapData() );
|
||||||
if ( node != source )
|
|
||||||
heap.Insert( node, inData.distance, _HeapData() );
|
|
||||||
int maxDistance = 0;
|
int maxDistance = 0;
|
||||||
unsigned numTargets = 0;
|
unsigned numTargets = 0;
|
||||||
|
|
||||||
for ( _DynamicGraph::EdgeIterator outEdge = _graph->BeginEdges( node ), endOutEdges = _graph->EndEdges( node ); outEdge != endOutEdges; ++outEdge ) {
|
for ( _DynamicGraph::EdgeIterator outEdge = _graph->BeginEdges( node ), endOutEdges = _graph->EndEdges( node ); outEdge != endOutEdges; ++outEdge ) {
|
||||||
const _EdgeBasedContractorEdgeData& outData = _graph->GetEdgeData( outEdge );
|
const ContractorEdgeData& outData = _graph->GetEdgeData( outEdge );
|
||||||
if ( !outData.forward )
|
if ( !outData.forward ) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
const NodeID target = _graph->GetTarget( outEdge );
|
const NodeID target = _graph->GetTarget( outEdge );
|
||||||
const int pathDistance = inData.distance + outData.distance;
|
const int pathDistance = inData.distance + outData.distance;
|
||||||
maxDistance = std::max( maxDistance, pathDistance );
|
maxDistance = std::max( maxDistance, pathDistance );
|
||||||
if ( !heap.WasInserted( target ) ) {
|
if ( !heap.WasInserted( target ) ) {
|
||||||
heap.Insert( target, pathDistance, _HeapData( true ) );
|
heap.Insert( target, INT_MAX, _HeapData( 0, true ) );
|
||||||
numTargets++;
|
++numTargets;
|
||||||
} else if ( pathDistance < heap.GetKey( target ) ) {
|
|
||||||
heap.DecreaseKey( target, pathDistance );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( Simulate )
|
if( Simulate ) {
|
||||||
_Dijkstra( maxDistance, numTargets, 500, data );
|
_Dijkstra( maxDistance, numTargets, 1000, data, node );
|
||||||
else
|
} else {
|
||||||
_Dijkstra( maxDistance, numTargets, 1000, data );
|
_Dijkstra( maxDistance, numTargets, 2000, data, node );
|
||||||
|
}
|
||||||
for ( _DynamicGraph::EdgeIterator outEdge = _graph->BeginEdges( node ), endOutEdges = _graph->EndEdges( node ); outEdge != endOutEdges; ++outEdge ) {
|
for ( _DynamicGraph::EdgeIterator outEdge = _graph->BeginEdges( node ), endOutEdges = _graph->EndEdges( node ); outEdge != endOutEdges; ++outEdge ) {
|
||||||
const _EdgeBasedContractorEdgeData& outData = _graph->GetEdgeData( outEdge );
|
const ContractorEdgeData& outData = _graph->GetEdgeData( outEdge );
|
||||||
if ( !outData.forward )
|
if ( !outData.forward ) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
const NodeID target = _graph->GetTarget( outEdge );
|
const NodeID target = _graph->GetTarget( outEdge );
|
||||||
const int pathDistance = inData.distance + outData.distance;
|
const int pathDistance = inData.distance + outData.distance;
|
||||||
const int distance = heap.GetKey( target );
|
const int distance = heap.GetKey( target );
|
||||||
|
if ( pathDistance < distance ) {
|
||||||
if ( pathDistance <= distance ) {
|
|
||||||
if ( Simulate ) {
|
if ( Simulate ) {
|
||||||
assert( stats != NULL );
|
assert( stats != NULL );
|
||||||
stats->edgesAdded+=2;
|
stats->edgesAdded+=2;
|
||||||
stats->originalEdgesAdded += 2* ( outData.originalEdges + inData.originalEdges );
|
stats->originalEdgesAdded += 2* ( outData.originalEdges + inData.originalEdges );
|
||||||
} else {
|
} else {
|
||||||
_ImportEdge newEdge;
|
_ContractorEdge newEdge;
|
||||||
newEdge.source = source;
|
newEdge.source = source;
|
||||||
newEdge.target = target;
|
newEdge.target = target;
|
||||||
newEdge.data.distance = pathDistance;
|
newEdge.data = ContractorEdgeData( pathDistance, outData.originalEdges + inData.originalEdges, node/*, 0, inData.turnInstruction*/, true, true, false);;
|
||||||
newEdge.data.forward = true;
|
|
||||||
newEdge.data.backward = false;
|
|
||||||
newEdge.data.via = node;
|
|
||||||
newEdge.data.shortcut = true;
|
|
||||||
newEdge.data.turnInstruction = inData.turnInstruction;
|
|
||||||
newEdge.data.originalEdges = outData.originalEdges + inData.originalEdges;
|
|
||||||
insertedEdges.push_back( newEdge );
|
insertedEdges.push_back( newEdge );
|
||||||
std::swap( newEdge.source, newEdge.target );
|
std::swap( newEdge.source, newEdge.target );
|
||||||
newEdge.data.forward = false;
|
newEdge.data.forward = false;
|
||||||
@@ -447,7 +652,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( !Simulate ) {
|
if ( !Simulate ) {
|
||||||
for ( int i = insertedEdgesSize, iend = insertedEdges.size(); i < iend; i++ ) {
|
for ( int i = insertedEdgesSize, iend = insertedEdges.size(); i < iend; ++i ) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for ( int other = i + 1 ; other < iend ; ++other ) {
|
for ( int other = i + 1 ; other < iend ; ++other ) {
|
||||||
if ( insertedEdges[other].source != insertedEdges[i].source )
|
if ( insertedEdges[other].source != insertedEdges[i].source )
|
||||||
@@ -463,62 +668,57 @@ private:
|
|||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ( !found )
|
if ( !found ) {
|
||||||
insertedEdges[insertedEdgesSize++] = insertedEdges[i];
|
insertedEdges[insertedEdgesSize++] = insertedEdges[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
insertedEdges.resize( insertedEdgesSize );
|
insertedEdges.resize( insertedEdgesSize );
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _DeleteIncomingEdges( _ThreadData* data, NodeID node ) {
|
inline void _DeleteIncomingEdges( _ThreadData* data, const NodeID node ) {
|
||||||
std::vector< NodeID >& neighbours = data->neighbours;
|
std::vector< NodeID >& neighbours = data->neighbours;
|
||||||
neighbours.clear();
|
neighbours.clear();
|
||||||
|
|
||||||
//find all neighbours
|
//find all neighbours
|
||||||
for ( _DynamicGraph::EdgeIterator e = _graph->BeginEdges( node ) ; e < _graph->EndEdges( node ) ; ++e ) {
|
for ( _DynamicGraph::EdgeIterator e = _graph->BeginEdges( node ) ; e < _graph->EndEdges( node ) ; ++e ) {
|
||||||
const NodeID u = _graph->GetTarget( e );
|
const NodeID u = _graph->GetTarget( e );
|
||||||
if ( u == node )
|
if ( u != node )
|
||||||
continue;
|
neighbours.push_back( u );
|
||||||
neighbours.push_back( u );
|
|
||||||
}
|
}
|
||||||
//eliminate duplicate entries ( forward + backward edges )
|
//eliminate duplicate entries ( forward + backward edges )
|
||||||
std::sort( neighbours.begin(), neighbours.end() );
|
std::sort( neighbours.begin(), neighbours.end() );
|
||||||
neighbours.resize( std::unique( neighbours.begin(), neighbours.end() ) - neighbours.begin() );
|
neighbours.resize( std::unique( neighbours.begin(), neighbours.end() ) - neighbours.begin() );
|
||||||
|
|
||||||
for ( int i = 0, e = ( int ) neighbours.size(); i < e; ++i ) {
|
for ( int i = 0, e = ( int ) neighbours.size(); i < e; ++i ) {
|
||||||
const NodeID u = neighbours[i];
|
_graph->DeleteEdgesTo( neighbours[i], node );
|
||||||
_graph->DeleteEdgesTo( u, node );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _UpdateNeighbours( std::vector< double >* priorities, std::vector< _PriorityData >* const nodeData, _ThreadData* const data, NodeID node ) {
|
inline bool _UpdateNeighbours( std::vector< float > & priorities, std::vector< _PriorityData > & nodeData, _ThreadData* const data, const NodeID node) {
|
||||||
std::vector< NodeID >& neighbours = data->neighbours;
|
std::vector< NodeID >& neighbours = data->neighbours;
|
||||||
neighbours.clear();
|
neighbours.clear();
|
||||||
|
|
||||||
//find all neighbours
|
//find all neighbours
|
||||||
for ( _DynamicGraph::EdgeIterator e = _graph->BeginEdges( node ) ; e < _graph->EndEdges( node ) ; ++e ) {
|
for ( _DynamicGraph::EdgeIterator e = _graph->BeginEdges( node ), endEdges = _graph->EndEdges( node ) ; e < endEdges ; ++e ) {
|
||||||
const NodeID u = _graph->GetTarget( e );
|
const NodeID u = _graph->GetTarget( e );
|
||||||
if ( u == node )
|
if ( u == node )
|
||||||
continue;
|
continue;
|
||||||
neighbours.push_back( u );
|
neighbours.push_back( u );
|
||||||
( *nodeData )[u].depth = (std::max)(( *nodeData )[node].depth + 1, ( *nodeData )[u].depth );
|
nodeData[u].depth = (std::max)(nodeData[node].depth + 1, nodeData[u].depth );
|
||||||
}
|
}
|
||||||
//eliminate duplicate entries ( forward + backward edges )
|
//eliminate duplicate entries ( forward + backward edges )
|
||||||
std::sort( neighbours.begin(), neighbours.end() );
|
std::sort( neighbours.begin(), neighbours.end() );
|
||||||
neighbours.resize( std::unique( neighbours.begin(), neighbours.end() ) - neighbours.begin() );
|
neighbours.resize( std::unique( neighbours.begin(), neighbours.end() ) - neighbours.begin() );
|
||||||
|
|
||||||
for ( int i = 0, e = ( int ) neighbours.size(); i < e; ++i ) {
|
BOOST_FOREACH(const NodeID u, neighbours) {
|
||||||
const NodeID u = neighbours[i];
|
priorities[u] = _Evaluate( data, &( nodeData )[u], u );
|
||||||
( *priorities )[u] = _Evaluate( data, &( *nodeData )[u], u );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _IsIndependent( const std::vector< double >& priorities, const std::vector< _PriorityData >& nodeData, _ThreadData* const data, NodeID node ) {
|
inline bool _IsIndependent( const std::vector< float >& priorities/*, const std::vector< _PriorityData >& nodeData*/, _ThreadData* const data, NodeID node ) const {
|
||||||
const double priority = priorities[node];
|
const double priority = priorities[node];
|
||||||
|
|
||||||
std::vector< NodeID >& neighbours = data->neighbours;
|
std::vector< NodeID >& neighbours = data->neighbours;
|
||||||
@@ -526,14 +726,17 @@ private:
|
|||||||
|
|
||||||
for ( _DynamicGraph::EdgeIterator e = _graph->BeginEdges( node ) ; e < _graph->EndEdges( node ) ; ++e ) {
|
for ( _DynamicGraph::EdgeIterator e = _graph->BeginEdges( node ) ; e < _graph->EndEdges( node ) ; ++e ) {
|
||||||
const NodeID target = _graph->GetTarget( e );
|
const NodeID target = _graph->GetTarget( e );
|
||||||
|
if(node==target)
|
||||||
|
continue;
|
||||||
const double targetPriority = priorities[target];
|
const double targetPriority = priorities[target];
|
||||||
assert( targetPriority >= 0 );
|
assert( targetPriority >= 0 );
|
||||||
//found a neighbour with lower priority?
|
//found a neighbour with lower priority?
|
||||||
if ( priority > targetPriority )
|
if ( priority > targetPriority )
|
||||||
return false;
|
return false;
|
||||||
//tie breaking
|
//tie breaking
|
||||||
if ( priority == targetPriority && nodeData[node].bias < nodeData[target].bias )
|
if ( std::abs(priority - targetPriority) < std::numeric_limits<double>::epsilon() && bias(node, target) ) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
neighbours.push_back( target );
|
neighbours.push_back( target );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -541,30 +744,46 @@ private:
|
|||||||
neighbours.resize( std::unique( neighbours.begin(), neighbours.end() ) - neighbours.begin() );
|
neighbours.resize( std::unique( neighbours.begin(), neighbours.end() ) - neighbours.begin() );
|
||||||
|
|
||||||
//examine all neighbours that are at most 2 hops away
|
//examine all neighbours that are at most 2 hops away
|
||||||
for ( std::vector< NodeID >::const_iterator i = neighbours.begin(), lastNode = neighbours.end(); i != lastNode; ++i ) {
|
BOOST_FOREACH(const NodeID u, neighbours) {
|
||||||
const NodeID u = *i;
|
|
||||||
|
|
||||||
for ( _DynamicGraph::EdgeIterator e = _graph->BeginEdges( u ) ; e < _graph->EndEdges( u ) ; ++e ) {
|
for ( _DynamicGraph::EdgeIterator e = _graph->BeginEdges( u ) ; e < _graph->EndEdges( u ) ; ++e ) {
|
||||||
const NodeID target = _graph->GetTarget( e );
|
const NodeID target = _graph->GetTarget( e );
|
||||||
|
if(node==target)
|
||||||
|
continue;
|
||||||
|
|
||||||
const double targetPriority = priorities[target];
|
const double targetPriority = priorities[target];
|
||||||
assert( targetPriority >= 0 );
|
assert( targetPriority >= 0 );
|
||||||
//found a neighbour with lower priority?
|
//found a neighbour with lower priority?
|
||||||
if ( priority > targetPriority )
|
if ( priority > targetPriority)
|
||||||
return false;
|
return false;
|
||||||
//tie breaking
|
//tie breaking
|
||||||
if ( priority == targetPriority && nodeData[node].bias < nodeData[target].bias )
|
if ( std::abs(priority - targetPriority) < std::numeric_limits<double>::epsilon() && bias(node, target) ) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This bias function takes up 22 assembly instructions in total on X86
|
||||||
|
*/
|
||||||
|
inline bool bias(const NodeID a, const NodeID b) const {
|
||||||
|
unsigned short hasha = fastHash(a);
|
||||||
|
unsigned short hashb = fastHash(b);
|
||||||
|
|
||||||
|
//The compiler optimizes that to conditional register flags but without branching statements!
|
||||||
|
if(hasha != hashb)
|
||||||
|
return hasha < hashb;
|
||||||
|
return a < b;
|
||||||
|
}
|
||||||
|
|
||||||
boost::shared_ptr<_DynamicGraph> _graph;
|
boost::shared_ptr<_DynamicGraph> _graph;
|
||||||
unsigned edgeQuotionFactor;
|
std::vector<_DynamicGraph::InputEdge> contractedEdges;
|
||||||
unsigned originalQuotientFactor;
|
unsigned edge_storage_slot;
|
||||||
unsigned depthFactor;
|
uint64_t temp_edge_counter;
|
||||||
|
std::vector<NodeID> oldNodeIDFromNewNodeIDMap;
|
||||||
|
XORFastHash fastHash;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONTRACTOR_H_INCLUDED
|
#endif // CONTRACTOR_H_INCLUDED
|
||||||
|
|||||||
@@ -1,234 +1,628 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, others 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
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
|
Redistributions of source code must retain the above copyright notice, this list
|
||||||
along with this program; if not, write to the Free Software
|
of conditions and the following disclaimer.
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
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.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef _GLIBCXX_PARALLEL
|
|
||||||
#include <parallel/algorithm>
|
|
||||||
#else
|
|
||||||
#include <algorithm>
|
|
||||||
#endif
|
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
|
|
||||||
#include "EdgeBasedGraphFactory.h"
|
#include "EdgeBasedGraphFactory.h"
|
||||||
|
#include "../Util/ComputeAngle.h"
|
||||||
|
|
||||||
template<>
|
#include <boost/assert.hpp>
|
||||||
EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector<NodeBasedEdge> & inputEdges, std::vector<_Restriction> & irs, std::vector<NodeInfo> & nI)
|
#include <boost/foreach.hpp>
|
||||||
: inputRestrictions(irs), inputNodeInfoList(nI) {
|
#include <boost/make_shared.hpp>
|
||||||
|
|
||||||
#ifdef _GLIBCXX_PARALLEL
|
//TODO: CompressionWorker
|
||||||
__gnu_parallel::sort(inputRestrictions.begin(), inputRestrictions.end(), CmpRestrictionByFrom);
|
//TODO: EdgeBasedEdgeGenerator
|
||||||
#else
|
|
||||||
std::sort(inputRestrictions.begin(), inputRestrictions.end(), CmpRestrictionByFrom);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::vector< _NodeBasedEdge > edges;
|
// template<class Work>
|
||||||
edges.reserve( 2 * inputEdges.size() );
|
// inline static void TraverseGraph(NodeBasedDynamicGraph & graph, Work & work) {
|
||||||
for ( typename std::vector< NodeBasedEdge >::const_iterator i = inputEdges.begin(), e = inputEdges.end(); i != e; ++i ) {
|
|
||||||
_NodeBasedEdge edge;
|
|
||||||
edge.source = i->source();
|
|
||||||
edge.target = i->target();
|
|
||||||
|
|
||||||
if(edge.source == edge.target)
|
// }
|
||||||
continue;
|
|
||||||
|
|
||||||
edge.data.distance = (std::max)((int)i->weight(), 1 );
|
EdgeBasedGraphFactory::EdgeBasedGraphFactory(
|
||||||
assert( edge.data.distance > 0 );
|
int number_of_nodes,
|
||||||
|
std::vector<ImportEdge> & input_edge_list,
|
||||||
|
std::vector<NodeID> & barrier_node_list,
|
||||||
|
std::vector<NodeID> & traffic_light_node_list,
|
||||||
|
std::vector<TurnRestriction> & input_restrictions_list,
|
||||||
|
std::vector<NodeInfo> & m_node_info_list,
|
||||||
|
SpeedProfileProperties speed_profile
|
||||||
|
) : speed_profile(speed_profile),
|
||||||
|
m_turn_restrictions_count(0),
|
||||||
|
m_node_info_list(m_node_info_list)
|
||||||
|
{
|
||||||
|
BOOST_FOREACH(const TurnRestriction & restriction, input_restrictions_list) {
|
||||||
|
std::pair<NodeID, NodeID> restriction_source =
|
||||||
|
std::make_pair(restriction.fromNode, restriction.viaNode);
|
||||||
|
unsigned index;
|
||||||
|
RestrictionMap::iterator restriction_iter;
|
||||||
|
restriction_iter = m_restriction_map.find(restriction_source);
|
||||||
|
if(restriction_iter == m_restriction_map.end()) {
|
||||||
|
index = m_restriction_bucket_list.size();
|
||||||
|
m_restriction_bucket_list.resize(index+1);
|
||||||
|
m_restriction_map.emplace(restriction_source, index);
|
||||||
|
} else {
|
||||||
|
index = restriction_iter->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_turn_restrictions_count -= m_restriction_bucket_list.at(index).size();
|
||||||
|
m_restriction_bucket_list.at(index).clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++m_turn_restrictions_count;
|
||||||
|
m_restriction_bucket_list.at(index).push_back(
|
||||||
|
std::make_pair( restriction.toNode, restriction.flags.isOnly)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_barrier_nodes.insert(
|
||||||
|
barrier_node_list.begin(),
|
||||||
|
barrier_node_list.end()
|
||||||
|
);
|
||||||
|
|
||||||
|
m_traffic_lights.insert(
|
||||||
|
traffic_light_node_list.begin(),
|
||||||
|
traffic_light_node_list.end()
|
||||||
|
);
|
||||||
|
|
||||||
|
DeallocatingVector< NodeBasedEdge > edges_list;
|
||||||
|
NodeBasedEdge edge;
|
||||||
|
BOOST_FOREACH(const ImportEdge & import_edge, input_edge_list) {
|
||||||
|
if(!import_edge.isForward()) {
|
||||||
|
edge.source = import_edge.target();
|
||||||
|
edge.target = import_edge.source();
|
||||||
|
edge.data.backward = import_edge.isForward();
|
||||||
|
edge.data.forward = import_edge.isBackward();
|
||||||
|
} else {
|
||||||
|
edge.source = import_edge.source();
|
||||||
|
edge.target = import_edge.target();
|
||||||
|
edge.data.forward = import_edge.isForward();
|
||||||
|
edge.data.backward = import_edge.isBackward();
|
||||||
|
}
|
||||||
|
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.shortcut = false;
|
||||||
edge.data.roundabout = i->isRoundabout();
|
edge.data.roundabout = import_edge.isRoundabout();
|
||||||
edge.data.nameID = i->name();
|
edge.data.ignoreInGrid = import_edge.ignoreInGrid();
|
||||||
edge.data.type = i->type();
|
edge.data.nameID = import_edge.name();
|
||||||
edge.data.forward = i->isForward();
|
edge.data.type = import_edge.type();
|
||||||
edge.data.backward = i->isBackward();
|
edge.data.isAccessRestricted = import_edge.isAccessRestricted();
|
||||||
edge.data.edgeBasedNodeID = edges.size();
|
edge.data.edgeBasedNodeID = edges_list.size();
|
||||||
edges.push_back( edge );
|
edge.data.contraFlow = import_edge.isContraFlow();
|
||||||
std::swap( edge.source, edge.target );
|
edges_list.push_back( edge );
|
||||||
if( edge.data.backward ) {
|
if( edge.data.backward ) {
|
||||||
edge.data.forward = i->isBackward();
|
std::swap( edge.source, edge.target );
|
||||||
edge.data.backward = i->isForward();
|
edge.data.forward = import_edge.isBackward();
|
||||||
edge.data.edgeBasedNodeID = edges.size();
|
edge.data.backward = import_edge.isForward();
|
||||||
edges.push_back( edge );
|
edge.data.edgeBasedNodeID = edges_list.size();
|
||||||
|
edges_list.push_back( edge );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::vector<ImportEdge>().swap(input_edge_list);
|
||||||
|
std::sort( edges_list.begin(), edges_list.end() );
|
||||||
|
m_node_based_graph = boost::make_shared<NodeBasedDynamicGraph>(
|
||||||
|
number_of_nodes, edges_list
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EdgeBasedGraphFactory::GetEdgeBasedEdges(
|
||||||
|
DeallocatingVector< EdgeBasedEdge >& output_edge_list
|
||||||
|
) {
|
||||||
|
BOOST_ASSERT_MSG(
|
||||||
|
0 == output_edge_list.size(),
|
||||||
|
"Vector is not empty"
|
||||||
|
);
|
||||||
|
m_edge_based_edge_list.swap(output_edge_list);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EdgeBasedGraphFactory::GetEdgeBasedNodes( std::vector<EdgeBasedNode> & nodes) {
|
||||||
|
#ifndef NDEBUG
|
||||||
|
BOOST_FOREACH(const EdgeBasedNode & node, m_edge_based_node_list){
|
||||||
|
BOOST_ASSERT(node.lat1 != INT_MAX); BOOST_ASSERT(node.lon1 != INT_MAX);
|
||||||
|
BOOST_ASSERT(node.lat2 != INT_MAX); BOOST_ASSERT(node.lon2 != INT_MAX);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
nodes.swap(m_edge_based_node_list);
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeID EdgeBasedGraphFactory::CheckForEmanatingIsOnlyTurn(
|
||||||
|
const NodeID u,
|
||||||
|
const NodeID v
|
||||||
|
) const {
|
||||||
|
const std::pair < NodeID, NodeID > restriction_source = std::make_pair(u, v);
|
||||||
|
RestrictionMap::const_iterator restriction_iter;
|
||||||
|
restriction_iter = m_restriction_map.find(restriction_source);
|
||||||
|
if (restriction_iter != m_restriction_map.end()) {
|
||||||
|
const unsigned index = restriction_iter->second;
|
||||||
|
BOOST_FOREACH(
|
||||||
|
const RestrictionSource & restriction_target,
|
||||||
|
m_restriction_bucket_list.at(index)
|
||||||
|
) {
|
||||||
|
if(restriction_target.second) {
|
||||||
|
return restriction_target.first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return UINT_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EdgeBasedGraphFactory::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.
|
||||||
|
const std::pair < NodeID, NodeID > restriction_source = std::make_pair(u, v);
|
||||||
|
RestrictionMap::const_iterator restriction_iter;
|
||||||
|
restriction_iter = m_restriction_map.find(restriction_source);
|
||||||
|
if (restriction_iter != m_restriction_map.end()) {
|
||||||
|
const unsigned index = restriction_iter->second;
|
||||||
|
BOOST_FOREACH(
|
||||||
|
const RestrictionTarget & restriction_target,
|
||||||
|
m_restriction_bucket_list.at(index)
|
||||||
|
) {
|
||||||
|
if(w == restriction_target.first) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EdgeBasedGraphFactory::InsertEdgeBasedNode(
|
||||||
|
EdgeIterator e1,
|
||||||
|
NodeIterator u,
|
||||||
|
NodeIterator v,
|
||||||
|
bool belongsToTinyComponent) {
|
||||||
|
EdgeData & data = m_node_based_graph->GetEdgeData(e1);
|
||||||
|
EdgeBasedNode currentNode;
|
||||||
|
currentNode.nameID = data.nameID;
|
||||||
|
currentNode.lat1 = m_node_info_list[u].lat;
|
||||||
|
currentNode.lon1 = m_node_info_list[u].lon;
|
||||||
|
currentNode.lat2 = m_node_info_list[v].lat;
|
||||||
|
currentNode.lon2 = m_node_info_list[v].lon;
|
||||||
|
currentNode.belongsToTinyComponent = belongsToTinyComponent;
|
||||||
|
currentNode.id = data.edgeBasedNodeID;
|
||||||
|
currentNode.ignoreInGrid = data.ignoreInGrid;
|
||||||
|
currentNode.weight = data.distance;
|
||||||
|
m_edge_based_node_list.push_back(currentNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void EdgeBasedGraphFactory::FlushVectorToStream(
|
||||||
|
std::ofstream & edge_data_file,
|
||||||
|
std::vector<OriginalEdgeData> & original_edge_data_vector
|
||||||
|
) const {
|
||||||
|
edge_data_file.write(
|
||||||
|
(char*)&(original_edge_data_vector[0]),
|
||||||
|
original_edge_data_vector.size()*sizeof(OriginalEdgeData)
|
||||||
|
);
|
||||||
|
original_edge_data_vector.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EdgeBasedGraphFactory::Run(
|
||||||
|
const char * original_edge_data_filename,
|
||||||
|
lua_State *lua_state
|
||||||
|
) {
|
||||||
|
SimpleLogger().Write() << "Compressing geometry of input graph";
|
||||||
|
//TODO: iterate over all turns
|
||||||
|
|
||||||
|
//TODO: compress geometries
|
||||||
|
|
||||||
|
//TODO: update turn restrictions if concerned by compression
|
||||||
|
|
||||||
|
//TODO: do some compression statistics
|
||||||
|
|
||||||
|
|
||||||
|
SimpleLogger().Write() << "Identifying components of the road network";
|
||||||
|
|
||||||
|
unsigned skipped_turns_counter = 0;
|
||||||
|
unsigned node_based_edge_counter = 0;
|
||||||
|
unsigned original_edges_counter = 0;
|
||||||
|
|
||||||
|
std::ofstream edge_data_file(
|
||||||
|
original_edge_data_filename,
|
||||||
|
std::ios::binary
|
||||||
|
);
|
||||||
|
|
||||||
|
//writes a dummy value that is updated later
|
||||||
|
edge_data_file.write(
|
||||||
|
(char*)&original_edges_counter,
|
||||||
|
sizeof(unsigned)
|
||||||
|
);
|
||||||
|
|
||||||
|
//Run a BFS on the undirected graph and identify small components
|
||||||
|
std::vector<unsigned> component_index_list;
|
||||||
|
std::vector<NodeID> component_index_size;
|
||||||
|
BFSCompentExplorer( component_index_list, component_index_size);
|
||||||
|
|
||||||
|
SimpleLogger().Write() <<
|
||||||
|
"identified: " << component_index_size.size() << " many components";
|
||||||
|
SimpleLogger().Write() <<
|
||||||
|
"generating edge-expanded nodes";
|
||||||
|
|
||||||
|
Percent p(m_node_based_graph->GetNumberOfNodes());
|
||||||
|
//loop over all edges and generate new set of nodes.
|
||||||
|
for(
|
||||||
|
NodeIterator u = 0, end = m_node_based_graph->GetNumberOfNodes();
|
||||||
|
u < end;
|
||||||
|
++u
|
||||||
|
) {
|
||||||
|
p.printIncrement();
|
||||||
|
for(
|
||||||
|
EdgeIterator e1 = m_node_based_graph->BeginEdges(u),
|
||||||
|
last_edge = m_node_based_graph->EndEdges(u);
|
||||||
|
e1 < last_edge;
|
||||||
|
++e1
|
||||||
|
) {
|
||||||
|
NodeIterator v = m_node_based_graph->GetTarget(e1);
|
||||||
|
|
||||||
|
if(m_node_based_graph->GetEdgeData(e1).type != SHRT_MAX) {
|
||||||
|
BOOST_ASSERT_MSG(e1 != UINT_MAX, "edge id invalid");
|
||||||
|
BOOST_ASSERT_MSG(u != UINT_MAX, "souce node invalid");
|
||||||
|
BOOST_ASSERT_MSG(v != UINT_MAX, "target node invalid");
|
||||||
|
//Note: edges that end on barrier nodes or on a turn restriction
|
||||||
|
//may actually be in two distinct components. We choose the smallest
|
||||||
|
const unsigned size_of_component = std::min(
|
||||||
|
component_index_size[component_index_list[u]],
|
||||||
|
component_index_size[component_index_list[v]]
|
||||||
|
);
|
||||||
|
|
||||||
|
InsertEdgeBasedNode( e1, u, v, size_of_component < 1000 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SimpleLogger().Write()
|
||||||
|
<< "Generated " << m_edge_based_node_list.size() << " nodes in " <<
|
||||||
|
"edge-expanded graph";
|
||||||
|
SimpleLogger().Write() << "generating edge-expanded edges";
|
||||||
|
|
||||||
#ifdef _GLIBCXX_PARALLEL
|
std::vector<NodeID>().swap(component_index_size);
|
||||||
__gnu_parallel::sort( edges.begin(), edges.end() );
|
BOOST_ASSERT_MSG(
|
||||||
#else
|
0 == component_index_size.capacity(),
|
||||||
sort( edges.begin(), edges.end() );
|
"component size vector not deallocated"
|
||||||
#endif
|
);
|
||||||
|
std::vector<NodeID>().swap(component_index_list);
|
||||||
|
BOOST_ASSERT_MSG(
|
||||||
|
0 == component_index_list.capacity(),
|
||||||
|
"component index vector not deallocated"
|
||||||
|
);
|
||||||
|
std::vector<OriginalEdgeData> original_edge_data_vector;
|
||||||
|
original_edge_data_vector.reserve(10000);
|
||||||
|
|
||||||
_nodeBasedGraph.reset(new _NodeBasedDynamicGraph( nodes, edges ));
|
//Loop over all turns and generate new set of edges.
|
||||||
INFO("Converted " << inputEdges.size() << " node-based edges into " << _nodeBasedGraph->GetNumberOfEdges() << " edge-based nodes.");
|
//Three nested loop look super-linear, but we are dealing with a (kind of)
|
||||||
}
|
//linear number of turns only.
|
||||||
|
p.reinit(m_node_based_graph->GetNumberOfNodes());
|
||||||
|
for(
|
||||||
|
NodeIterator u = 0, end = m_node_based_graph->GetNumberOfNodes();
|
||||||
|
u < end;
|
||||||
|
++u
|
||||||
|
) {
|
||||||
|
for(
|
||||||
|
EdgeIterator e1 = m_node_based_graph->BeginEdges(u),
|
||||||
|
last_edge_u = m_node_based_graph->EndEdges(u);
|
||||||
|
e1 < last_edge_u;
|
||||||
|
++e1
|
||||||
|
) {
|
||||||
|
++node_based_edge_counter;
|
||||||
|
const NodeIterator v = m_node_based_graph->GetTarget(e1);
|
||||||
|
const NodeID to_node_of_only_restriction = CheckForEmanatingIsOnlyTurn(u, v);
|
||||||
|
const bool is_barrier_node = ( m_barrier_nodes.find(v) != m_barrier_nodes.end() );
|
||||||
|
|
||||||
template<>
|
for(
|
||||||
void EdgeBasedGraphFactory::GetEdgeBasedEdges( std::vector< EdgeBasedEdge >& outputEdgeList ) {
|
EdgeIterator e2 = m_node_based_graph->BeginEdges(v),
|
||||||
|
last_edge_v = m_node_based_graph->EndEdges(v);
|
||||||
|
e2 < last_edge_v;
|
||||||
|
++e2
|
||||||
|
) {
|
||||||
|
const NodeIterator w = m_node_based_graph->GetTarget(e2);
|
||||||
|
if(
|
||||||
|
to_node_of_only_restriction != UINT_MAX &&
|
||||||
|
w != to_node_of_only_restriction
|
||||||
|
) {
|
||||||
|
//We are at an only_-restriction but not at the right turn.
|
||||||
|
++skipped_turns_counter;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
GUARANTEE(0 == outputEdgeList.size(), "Vector passed to EdgeBasedGraphFactory::GetEdgeBasedEdges(..) is not empty");
|
if( is_barrier_node) {
|
||||||
GUARANTEE(0 != edgeBasedEdges.size(), "No edges in edge based graph");
|
if(u != w) {
|
||||||
|
++skipped_turns_counter;
|
||||||
edgeBasedEdges.swap(outputEdgeList);
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
void EdgeBasedGraphFactory::GetEdgeBasedNodes( std::vector< EdgeBasedNode> & nodes) {
|
|
||||||
for(unsigned i = 0; i < edgeBasedNodes.size(); ++i)
|
|
||||||
nodes.push_back(edgeBasedNodes[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void EdgeBasedGraphFactory::Run() {
|
|
||||||
INFO("Generating Edge based representation of input data");
|
|
||||||
|
|
||||||
std::vector<_Restriction>::iterator restrictionIterator = inputRestrictions.begin();
|
|
||||||
Percent p(_nodeBasedGraph->GetNumberOfNodes());
|
|
||||||
int numberOfResolvedRestrictions(0);
|
|
||||||
int nodeBasedEdgeCounter(0);
|
|
||||||
|
|
||||||
//Loop over all nodes u. Three nested loop look super-linear, but we are dealing with a number linear in the turns only.
|
|
||||||
for(_NodeBasedDynamicGraph::NodeIterator u = 0; u < _nodeBasedGraph->GetNumberOfNodes(); ++u ) {
|
|
||||||
//loop over all adjacent edge (u,v)
|
|
||||||
while(restrictionIterator->fromNode < u && inputRestrictions.end() != restrictionIterator) {
|
|
||||||
++restrictionIterator;
|
|
||||||
}
|
|
||||||
for(_NodeBasedDynamicGraph::EdgeIterator e1 = _nodeBasedGraph->BeginEdges(u); e1 < _nodeBasedGraph->EndEdges(u); ++e1) {
|
|
||||||
++nodeBasedEdgeCounter;
|
|
||||||
_NodeBasedDynamicGraph::NodeIterator v = _nodeBasedGraph->GetTarget(e1);
|
|
||||||
//loop over all reachable edges (v,w)
|
|
||||||
for(_NodeBasedDynamicGraph::EdgeIterator e2 = _nodeBasedGraph->BeginEdges(v); e2 < _nodeBasedGraph->EndEdges(v); ++e2) {
|
|
||||||
_NodeBasedDynamicGraph::NodeIterator w = _nodeBasedGraph->GetTarget(e2);
|
|
||||||
//if (u,v,w) is a forbidden turn, continue
|
|
||||||
bool isTurnProhibited = false;
|
|
||||||
if( u != w ) { //only add an edge if turn is not a U-turn
|
|
||||||
if(u == restrictionIterator->fromNode) {
|
|
||||||
std::vector<_Restriction>::iterator secondRestrictionIterator = restrictionIterator;
|
|
||||||
do {
|
|
||||||
if( v == secondRestrictionIterator->viaNode && w == secondRestrictionIterator->toNode) {
|
|
||||||
isTurnProhibited = true;
|
|
||||||
}
|
|
||||||
++secondRestrictionIterator;
|
|
||||||
} while(u == secondRestrictionIterator->fromNode);
|
|
||||||
}
|
}
|
||||||
if( !isTurnProhibited ) { //only add an edge if turn is not prohibited
|
} else {
|
||||||
//new costs for edge based edge (e1, e2) = cost (e1) + tc(e1,e2)
|
if ( (u == w) && (m_node_based_graph->GetOutDegree(v) > 1) ) {
|
||||||
const _NodeBasedDynamicGraph::NodeIterator edgeBasedSource = _nodeBasedGraph->GetEdgeData(e1).edgeBasedNodeID;
|
++skipped_turns_counter;
|
||||||
// INFO("edgeBasedSource: " << edgeBasedSource);
|
continue;
|
||||||
if(edgeBasedSource > _nodeBasedGraph->GetNumberOfEdges()) {
|
|
||||||
ERR("edgeBasedTarget" << edgeBasedSource << ">" << _nodeBasedGraph->GetNumberOfEdges());
|
|
||||||
}
|
|
||||||
const _NodeBasedDynamicGraph::NodeIterator edgeBasedTarget = _nodeBasedGraph->GetEdgeData(e2).edgeBasedNodeID;
|
|
||||||
// INFO("edgeBasedTarget: " << edgeBasedTarget);
|
|
||||||
if(edgeBasedTarget > _nodeBasedGraph->GetNumberOfEdges()) {
|
|
||||||
ERR("edgeBasedTarget" << edgeBasedTarget << ">" << _nodeBasedGraph->GetNumberOfEdges());
|
|
||||||
}
|
|
||||||
|
|
||||||
//incorporate turn costs, this is just a simple model and can (read: must) be extended
|
|
||||||
double angle = GetAngleBetweenTwoEdges(inputNodeInfoList[u], inputNodeInfoList[v], inputNodeInfoList[w]);
|
|
||||||
|
|
||||||
unsigned distance = (int)( _nodeBasedGraph->GetEdgeData(e1).distance *(1+std::abs((angle-180.)/180.)));
|
|
||||||
unsigned nameID = _nodeBasedGraph->GetEdgeData(e2).nameID;
|
|
||||||
short turnInstruction = AnalyzeTurn(u, v, w);
|
|
||||||
|
|
||||||
//create edge-based graph edge
|
|
||||||
//EdgeBasedEdge(NodeID s, NodeID t, NodeID v, unsigned n1, EdgeWeight w, bool f, bool b, short ty)
|
|
||||||
EdgeBasedEdge newEdge(edgeBasedSource, edgeBasedTarget, v, nameID, distance, true, false, turnInstruction);
|
|
||||||
edgeBasedEdges.push_back(newEdge);
|
|
||||||
EdgeBasedNode currentNode;
|
|
||||||
|
|
||||||
if(_nodeBasedGraph->GetEdgeData(e1).type != 14) {
|
|
||||||
currentNode.nameID = _nodeBasedGraph->GetEdgeData(e1).nameID;
|
|
||||||
currentNode.lat1 = inputNodeInfoList[u].lat;
|
|
||||||
currentNode.lon1 = inputNodeInfoList[u].lon;
|
|
||||||
currentNode.lat2 = inputNodeInfoList[v].lat;
|
|
||||||
currentNode.lon2 = inputNodeInfoList[v].lon;
|
|
||||||
currentNode.id = edgeBasedSource;
|
|
||||||
currentNode.weight = _nodeBasedGraph->GetEdgeData(e1).distance;
|
|
||||||
edgeBasedNodes.push_back(currentNode);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
++numberOfResolvedRestrictions;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//only add an edge if turn is not a U-turn except when it is
|
||||||
|
//at the end of a dead-end street
|
||||||
|
if (
|
||||||
|
CheckIfTurnIsRestricted(u, v, w) &&
|
||||||
|
(to_node_of_only_restriction == UINT_MAX) &&
|
||||||
|
(w != to_node_of_only_restriction)
|
||||||
|
) {
|
||||||
|
++skipped_turns_counter;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//only add an edge if turn is not prohibited
|
||||||
|
const EdgeData edge_data1 = m_node_based_graph->GetEdgeData(e1);
|
||||||
|
const EdgeData edge_data2 = m_node_based_graph->GetEdgeData(e2);
|
||||||
|
|
||||||
|
BOOST_ASSERT(
|
||||||
|
edge_data1.edgeBasedNodeID < m_node_based_graph->GetNumberOfEdges()
|
||||||
|
);
|
||||||
|
BOOST_ASSERT(
|
||||||
|
edge_data2.edgeBasedNodeID < m_node_based_graph->GetNumberOfEdges()
|
||||||
|
);
|
||||||
|
BOOST_ASSERT(
|
||||||
|
edge_data1.edgeBasedNodeID != edge_data2.edgeBasedNodeID
|
||||||
|
);
|
||||||
|
BOOST_ASSERT( edge_data1.forward );
|
||||||
|
BOOST_ASSERT( edge_data2.forward );
|
||||||
|
|
||||||
|
// the following is the core of the loop.
|
||||||
|
unsigned distance = edge_data1.distance;
|
||||||
|
if( m_traffic_lights.find(v) != m_traffic_lights.end() ) {
|
||||||
|
distance += speed_profile.trafficSignalPenalty;
|
||||||
|
}
|
||||||
|
const int turn_penalty = GetTurnPenalty(u, v, w, lua_state);
|
||||||
|
TurnInstruction turnInstruction = AnalyzeTurn(u, v, w);
|
||||||
|
if(turnInstruction == TurnInstructions.UTurn){
|
||||||
|
distance += speed_profile.uTurnPenalty;
|
||||||
|
}
|
||||||
|
distance += turn_penalty;
|
||||||
|
|
||||||
|
original_edge_data_vector.push_back(
|
||||||
|
OriginalEdgeData(
|
||||||
|
v,
|
||||||
|
edge_data2.nameID,
|
||||||
|
turnInstruction
|
||||||
|
)
|
||||||
|
);
|
||||||
|
++original_edges_counter;
|
||||||
|
|
||||||
|
if(original_edge_data_vector.size() > 100000) {
|
||||||
|
FlushVectorToStream(
|
||||||
|
edge_data_file,
|
||||||
|
original_edge_data_vector
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_edge_based_edge_list.push_back(
|
||||||
|
EdgeBasedEdge(
|
||||||
|
edge_data1.edgeBasedNodeID,
|
||||||
|
edge_data2.edgeBasedNodeID,
|
||||||
|
m_edge_based_edge_list.size(),
|
||||||
|
distance,
|
||||||
|
true,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.printIncrement();
|
p.printIncrement();
|
||||||
}
|
}
|
||||||
std::sort(edgeBasedNodes.begin(), edgeBasedNodes.end());
|
FlushVectorToStream( edge_data_file, original_edge_data_vector );
|
||||||
edgeBasedNodes.erase( std::unique(edgeBasedNodes.begin(), edgeBasedNodes.end()), edgeBasedNodes.end() );
|
|
||||||
INFO("Node-based graph contains " << nodeBasedEdgeCounter << " edges");
|
edge_data_file.seekp( std::ios::beg );
|
||||||
INFO("Edge-based graph contains " << edgeBasedEdges.size() << " edges, blowup is " << (double)edgeBasedEdges.size()/(double)nodeBasedEdgeCounter);
|
edge_data_file.write( (char*)&original_edges_counter, sizeof(unsigned) );
|
||||||
INFO("Edge-based graph obeys " << numberOfResolvedRestrictions << " turn restrictions, " << (inputRestrictions.size() - numberOfResolvedRestrictions )<< " skipped.");
|
edge_data_file.close();
|
||||||
INFO("Generated " << edgeBasedNodes.size() << " edge based nodes");
|
|
||||||
|
SimpleLogger().Write() <<
|
||||||
|
"Generated " << m_edge_based_node_list.size() << " edge based nodes";
|
||||||
|
SimpleLogger().Write() <<
|
||||||
|
"Node-based graph contains " << node_based_edge_counter << " edges";
|
||||||
|
SimpleLogger().Write() <<
|
||||||
|
"Edge-expanded graph ...";
|
||||||
|
SimpleLogger().Write() <<
|
||||||
|
" contains " << m_edge_based_edge_list.size() << " edges";
|
||||||
|
SimpleLogger().Write() <<
|
||||||
|
" skips " << skipped_turns_counter << " turns, "
|
||||||
|
"defined by " << m_turn_restrictions_count << " restrictions";
|
||||||
}
|
}
|
||||||
|
|
||||||
short EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w) const {
|
int EdgeBasedGraphFactory::GetTurnPenalty(
|
||||||
_NodeBasedDynamicGraph::EdgeIterator edge1 = _nodeBasedGraph->FindEdge(u, v);
|
const NodeID u,
|
||||||
_NodeBasedDynamicGraph::EdgeIterator edge2 = _nodeBasedGraph->FindEdge(v, w);
|
const NodeID v,
|
||||||
|
const NodeID w,
|
||||||
|
lua_State *lua_state
|
||||||
|
) const {
|
||||||
|
const double angle = GetAngleBetweenThreeFixedPointCoordinates (
|
||||||
|
m_node_info_list[u],
|
||||||
|
m_node_info_list[v],
|
||||||
|
m_node_info_list[w]
|
||||||
|
);
|
||||||
|
|
||||||
_NodeBasedDynamicGraph::EdgeData & data1 = _nodeBasedGraph->GetEdgeData(edge1);
|
if( speed_profile.has_turn_penalty_function ) {
|
||||||
_NodeBasedDynamicGraph::EdgeData & data2 = _nodeBasedGraph->GetEdgeData(edge2);
|
try {
|
||||||
|
//call lua profile to compute turn penalty
|
||||||
|
return luabind::call_function<int>(
|
||||||
|
lua_state,
|
||||||
|
"turn_function",
|
||||||
|
180.-angle
|
||||||
|
);
|
||||||
|
} catch (const luabind::error &er) {
|
||||||
|
SimpleLogger().Write(logWARNING) << er.what();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
double angle = GetAngleBetweenTwoEdges(inputNodeInfoList[u], inputNodeInfoList[v], inputNodeInfoList[w]);
|
TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(
|
||||||
|
const NodeID u,
|
||||||
|
const NodeID v,
|
||||||
|
const NodeID w
|
||||||
|
) const {
|
||||||
|
if(u == w) {
|
||||||
|
return TurnInstructions.UTurn;
|
||||||
|
}
|
||||||
|
|
||||||
|
const EdgeIterator edge1 = m_node_based_graph->FindEdge(u, v);
|
||||||
|
const EdgeIterator edge2 = m_node_based_graph->FindEdge(v, w);
|
||||||
|
|
||||||
|
const EdgeData & data1 = m_node_based_graph->GetEdgeData(edge1);
|
||||||
|
const EdgeData & data2 = m_node_based_graph->GetEdgeData(edge2);
|
||||||
|
|
||||||
|
if(!data1.contraFlow && data2.contraFlow) {
|
||||||
|
return TurnInstructions.EnterAgainstAllowedDirection;
|
||||||
|
}
|
||||||
|
if(data1.contraFlow && !data2.contraFlow) {
|
||||||
|
return TurnInstructions.LeaveAgainstAllowedDirection;
|
||||||
|
}
|
||||||
|
|
||||||
//roundabouts need to be handled explicitely
|
//roundabouts need to be handled explicitely
|
||||||
if(data1.roundabout && data2.roundabout) {
|
if(data1.roundabout && data2.roundabout) {
|
||||||
//Is a turn possible? If yes, we stay on the roundabout!
|
//Is a turn possible? If yes, we stay on the roundabout!
|
||||||
if( 1 == (_nodeBasedGraph->EndEdges(v) - _nodeBasedGraph->BeginEdges(v)) ) {
|
if( 1 == m_node_based_graph->GetOutDegree(v) ) {
|
||||||
//No turn possible.
|
//No turn possible.
|
||||||
return TurnInstructions.NoTurn;
|
return TurnInstructions.NoTurn;
|
||||||
} else {
|
|
||||||
return TurnInstructions.StayOnRoundAbout;
|
|
||||||
}
|
}
|
||||||
|
return TurnInstructions.StayOnRoundAbout;
|
||||||
}
|
}
|
||||||
//Does turn start or end on roundabout?
|
//Does turn start or end on roundabout?
|
||||||
if(data1.roundabout || data2.roundabout) {
|
if(data1.roundabout || data2.roundabout) {
|
||||||
//We are entering the roundabout
|
//We are entering the roundabout
|
||||||
if( (!data1.roundabout) && data2.roundabout)
|
if( (!data1.roundabout) && data2.roundabout) {
|
||||||
return TurnInstructions.EnterRoundAbout;
|
return TurnInstructions.EnterRoundAbout;
|
||||||
|
}
|
||||||
//We are leaving the roundabout
|
//We are leaving the roundabout
|
||||||
if(data1.roundabout && (!data2.roundabout) )
|
if(data1.roundabout && (!data2.roundabout) ) {
|
||||||
return TurnInstructions.LeaveRoundAbout;
|
return TurnInstructions.LeaveRoundAbout;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//If street names stay the same and if we are certain that it is not a roundabout, we skip it.
|
//If street names stay the same and if we are certain that it is not a
|
||||||
if(data1.nameID == data2.nameID)
|
//a segment of a roundabout, we skip it.
|
||||||
return TurnInstructions.NoTurn;
|
if( data1.nameID == data2.nameID ) {
|
||||||
|
//TODO: Here we should also do a small graph exploration to check for
|
||||||
|
// more complex situations
|
||||||
|
if( 0 != data1.nameID ) {
|
||||||
|
return TurnInstructions.NoTurn;
|
||||||
|
} else if (m_node_based_graph->GetOutDegree(v) <= 2) {
|
||||||
|
return TurnInstructions.NoTurn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const double angle = GetAngleBetweenThreeFixedPointCoordinates (
|
||||||
|
m_node_info_list[u],
|
||||||
|
m_node_info_list[v],
|
||||||
|
m_node_info_list[w]
|
||||||
|
);
|
||||||
return TurnInstructions.GetTurnDirectionOfInstruction(angle);
|
return TurnInstructions.GetTurnDirectionOfInstruction(angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned EdgeBasedGraphFactory::GetNumberOfNodes() const {
|
unsigned EdgeBasedGraphFactory::GetNumberOfNodes() const {
|
||||||
return edgeBasedEdges.size();
|
return m_node_based_graph->GetNumberOfEdges();
|
||||||
}
|
}
|
||||||
|
|
||||||
EdgeBasedGraphFactory::~EdgeBasedGraphFactory() {
|
void EdgeBasedGraphFactory::BFSCompentExplorer(
|
||||||
}
|
std::vector<unsigned> & component_index_list,
|
||||||
|
std::vector<unsigned> & component_index_size
|
||||||
/* Get angle of line segment (A,C)->(C,B), atan2 magic, formerly cosine theorem*/
|
) const {
|
||||||
template<class CoordinateT>
|
std::queue<std::pair<NodeID, NodeID> > bfs_queue;
|
||||||
double EdgeBasedGraphFactory::GetAngleBetweenTwoEdges(const CoordinateT& A, const CoordinateT& C, const CoordinateT& B) const {
|
Percent p( m_node_based_graph->GetNumberOfNodes() );
|
||||||
const int v1x = A.lon - C.lon;
|
unsigned current_component, current_component_size;
|
||||||
const int v1y = A.lat - C.lat;
|
current_component = current_component_size = 0;
|
||||||
const int v2x = B.lon - C.lon;
|
|
||||||
const int v2y = B.lat - C.lat;
|
BOOST_ASSERT( component_index_list.empty() );
|
||||||
|
BOOST_ASSERT( component_index_size.empty() );
|
||||||
double angle = (atan2((double)v2y,v2x) - atan2((double)v1y,v1x) )*180/M_PI;
|
|
||||||
while(angle < 0)
|
component_index_list.resize(
|
||||||
angle += 360;
|
m_node_based_graph->GetNumberOfNodes(),
|
||||||
|
UINT_MAX
|
||||||
return angle;
|
);
|
||||||
|
|
||||||
|
//put unexplorered node with parent pointer into queue
|
||||||
|
for( NodeID node = 0, end = m_node_based_graph->GetNumberOfNodes(); node < end; ++node) {
|
||||||
|
if(UINT_MAX == component_index_list[node]) {
|
||||||
|
bfs_queue.push(std::make_pair(node, node));
|
||||||
|
//mark node as read
|
||||||
|
component_index_list[node] = current_component;
|
||||||
|
p.printIncrement();
|
||||||
|
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 = CheckForEmanatingIsOnlyTurn(u, v);
|
||||||
|
|
||||||
|
for(
|
||||||
|
EdgeIterator e2 = m_node_based_graph->BeginEdges(v);
|
||||||
|
e2 < m_node_based_graph->EndEdges(v);
|
||||||
|
++e2
|
||||||
|
) {
|
||||||
|
NodeIterator w = m_node_based_graph->GetTarget(e2);
|
||||||
|
|
||||||
|
if(
|
||||||
|
to_node_of_only_restriction != UINT_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 (!CheckIfTurnIsRestricted(u, v, w) ) {
|
||||||
|
//only add an edge if turn is not prohibited
|
||||||
|
if(UINT_MAX == component_index_list[w]) {
|
||||||
|
//insert next (node, parent) only if w has
|
||||||
|
//not yet been explored
|
||||||
|
//mark node as read
|
||||||
|
component_index_list[w] = current_component;
|
||||||
|
bfs_queue.push(std::make_pair(w,v));
|
||||||
|
p.printIncrement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//push size into vector
|
||||||
|
component_index_size.push_back(current_component_size);
|
||||||
|
//reset counters;
|
||||||
|
current_component_size = 0;
|
||||||
|
++current_component;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,104 +1,172 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, others 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
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
|
Redistributions of source code must retain the above copyright notice, this list
|
||||||
along with this program; if not, write to the Free Software
|
of conditions and the following disclaimer.
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
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
|
||||||
* This class constructs the edge base representation of a graph from a given node based edge list
|
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.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// This class constructs the edge-expanded routing graph
|
||||||
|
|
||||||
#ifndef EDGEBASEDGRAPHFACTORY_H_
|
#ifndef EDGEBASEDGRAPHFACTORY_H_
|
||||||
#define EDGEBASEDGRAPHFACTORY_H_
|
#define EDGEBASEDGRAPHFACTORY_H_
|
||||||
|
|
||||||
|
#include "../typedefs.h"
|
||||||
|
#include "../DataStructures/DeallocatingVector.h"
|
||||||
|
#include "../DataStructures/DynamicGraph.h"
|
||||||
|
#include "../DataStructures/EdgeBasedNode.h"
|
||||||
|
#include "../DataStructures/HashTable.h"
|
||||||
|
#include "../DataStructures/ImportEdge.h"
|
||||||
|
#include "../DataStructures/OriginalEdgeData.h"
|
||||||
|
#include "../DataStructures/Percent.h"
|
||||||
|
#include "../DataStructures/QueryEdge.h"
|
||||||
|
#include "../DataStructures/QueryNode.h"
|
||||||
|
#include "../DataStructures/TurnInstructions.h"
|
||||||
|
#include "../DataStructures/Restriction.h"
|
||||||
|
#include "../Util/LuaUtil.h"
|
||||||
|
#include "../Util/SimpleLogger.h"
|
||||||
|
|
||||||
|
#include "GeometryCompressor.h"
|
||||||
|
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <boost/unordered_map.hpp>
|
||||||
|
#include <boost/unordered_set.hpp>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <fstream>
|
||||||
|
#include <queue>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "../typedefs.h"
|
class EdgeBasedGraphFactory : boost::noncopyable {
|
||||||
#include "../DataStructures/DynamicGraph.h"
|
public:
|
||||||
#include "../DataStructures/ExtractorStructs.h"
|
struct SpeedProfileProperties{
|
||||||
#include "../DataStructures/ImportEdge.h"
|
SpeedProfileProperties() :
|
||||||
#include "../DataStructures/Percent.h"
|
trafficSignalPenalty(0),
|
||||||
#include "../DataStructures/TurnInstructions.h"
|
uTurnPenalty(0),
|
||||||
|
has_turn_penalty_function(false)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
int trafficSignalPenalty;
|
||||||
|
int uTurnPenalty;
|
||||||
|
bool has_turn_penalty_function;
|
||||||
|
} speed_profile;
|
||||||
|
|
||||||
|
explicit EdgeBasedGraphFactory(
|
||||||
|
int number_of_nodes,
|
||||||
|
std::vector<ImportEdge> & input_edge_list,
|
||||||
|
std::vector<NodeID> & barrier_node_list,
|
||||||
|
std::vector<NodeID> & traffic_light_node_list,
|
||||||
|
std::vector<TurnRestriction> & input_restrictions_list,
|
||||||
|
std::vector<NodeInfo> & m_node_info_list,
|
||||||
|
SpeedProfileProperties speed_profile
|
||||||
|
);
|
||||||
|
|
||||||
|
void Run(const char * originalEdgeDataFilename, lua_State *myLuaState);
|
||||||
|
|
||||||
|
void GetEdgeBasedEdges( DeallocatingVector< EdgeBasedEdge >& edges );
|
||||||
|
|
||||||
|
void GetEdgeBasedNodes( std::vector< EdgeBasedNode> & nodes);
|
||||||
|
|
||||||
|
TurnInstruction AnalyzeTurn(
|
||||||
|
const NodeID u,
|
||||||
|
const NodeID v,
|
||||||
|
const NodeID w
|
||||||
|
) const;
|
||||||
|
|
||||||
|
int GetTurnPenalty(
|
||||||
|
const NodeID u,
|
||||||
|
const NodeID v,
|
||||||
|
const NodeID w,
|
||||||
|
lua_State *myLuaState
|
||||||
|
) const;
|
||||||
|
|
||||||
|
unsigned GetNumberOfNodes() const;
|
||||||
|
|
||||||
class EdgeBasedGraphFactory {
|
|
||||||
private:
|
private:
|
||||||
struct _NodeBasedEdgeData {
|
struct NodeBasedEdgeData {
|
||||||
int distance;
|
int distance;
|
||||||
unsigned edgeBasedNodeID;
|
unsigned edgeBasedNodeID;
|
||||||
unsigned nameID;
|
unsigned nameID;
|
||||||
|
short type;
|
||||||
|
bool isAccessRestricted:1;
|
||||||
bool shortcut:1;
|
bool shortcut:1;
|
||||||
bool forward:1;
|
bool forward:1;
|
||||||
bool backward:1;
|
bool backward:1;
|
||||||
bool roundabout:1;
|
bool roundabout:1;
|
||||||
short type;
|
bool ignoreInGrid:1;
|
||||||
} data;
|
bool contraFlow:1;
|
||||||
|
|
||||||
struct _EdgeBasedEdgeData {
|
|
||||||
int distance;
|
|
||||||
unsigned via;
|
|
||||||
unsigned nameID;
|
|
||||||
bool forward;
|
|
||||||
bool backward;
|
|
||||||
short turnInstruction;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef DynamicGraph< _NodeBasedEdgeData > _NodeBasedDynamicGraph;
|
unsigned m_turn_restrictions_count;
|
||||||
typedef _NodeBasedDynamicGraph::InputEdge _NodeBasedEdge;
|
|
||||||
|
|
||||||
public:
|
typedef DynamicGraph<NodeBasedEdgeData> NodeBasedDynamicGraph;
|
||||||
struct EdgeBasedNode {
|
typedef NodeBasedDynamicGraph::InputEdge NodeBasedEdge;
|
||||||
bool operator<(const EdgeBasedNode & other) const {
|
typedef NodeBasedDynamicGraph::NodeIterator NodeIterator;
|
||||||
return other.id < id;
|
typedef NodeBasedDynamicGraph::EdgeIterator EdgeIterator;
|
||||||
}
|
typedef NodeBasedDynamicGraph::EdgeData EdgeData;
|
||||||
bool operator==(const EdgeBasedNode & other) const {
|
typedef std::pair<NodeID, NodeID> RestrictionSource;
|
||||||
return id == other.id;
|
typedef std::pair<NodeID, bool> RestrictionTarget;
|
||||||
}
|
typedef std::vector<RestrictionTarget> EmanatingRestrictionsVector;
|
||||||
int lat1;
|
typedef boost::unordered_map<RestrictionSource, unsigned > RestrictionMap;
|
||||||
int lat2;
|
|
||||||
int lon1;
|
|
||||||
int lon2;
|
|
||||||
NodeID id;
|
|
||||||
NodeID nameID;
|
|
||||||
unsigned weight;
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
std::vector<NodeInfo> m_node_info_list;
|
||||||
boost::shared_ptr<_NodeBasedDynamicGraph> _nodeBasedGraph;
|
std::vector<EmanatingRestrictionsVector> m_restriction_bucket_list;
|
||||||
|
std::vector<EdgeBasedNode> m_edge_based_node_list;
|
||||||
|
DeallocatingVector<EdgeBasedEdge> m_edge_based_edge_list;
|
||||||
|
|
||||||
std::vector<_Restriction> & inputRestrictions;
|
boost::shared_ptr<NodeBasedDynamicGraph> m_node_based_graph;
|
||||||
std::vector<NodeInfo> & inputNodeInfoList;
|
boost::unordered_set<NodeID> m_barrier_nodes;
|
||||||
|
boost::unordered_set<NodeID> m_traffic_lights;
|
||||||
|
|
||||||
std::vector<EdgeBasedEdge> edgeBasedEdges;
|
RestrictionMap m_restriction_map;
|
||||||
std::vector<EdgeBasedNode> edgeBasedNodes;
|
|
||||||
|
|
||||||
template<class CoordinateT>
|
NodeID CheckForEmanatingIsOnlyTurn(
|
||||||
double GetAngleBetweenTwoEdges(const CoordinateT& A, const CoordinateT& C, const CoordinateT& B) const;
|
const NodeID u,
|
||||||
public:
|
const NodeID v
|
||||||
template< class InputEdgeT >
|
) const;
|
||||||
explicit EdgeBasedGraphFactory(int nodes, std::vector<InputEdgeT> & inputEdges, std::vector<_Restriction> & inputRestrictions, std::vector<NodeInfo> & nI);
|
|
||||||
virtual ~EdgeBasedGraphFactory();
|
|
||||||
|
|
||||||
void Run();
|
bool CheckIfTurnIsRestricted(
|
||||||
template< class ImportEdgeT >
|
const NodeID u,
|
||||||
void GetEdgeBasedEdges( std::vector< ImportEdgeT >& edges );
|
const NodeID v,
|
||||||
void GetEdgeBasedNodes( std::vector< EdgeBasedNode> & nodes);
|
const NodeID w
|
||||||
short AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w) const;
|
) const;
|
||||||
unsigned GetNumberOfNodes() const;
|
|
||||||
|
void InsertEdgeBasedNode(
|
||||||
|
NodeBasedDynamicGraph::EdgeIterator e1,
|
||||||
|
NodeBasedDynamicGraph::NodeIterator u,
|
||||||
|
NodeBasedDynamicGraph::NodeIterator v,
|
||||||
|
bool belongsToTinyComponent
|
||||||
|
);
|
||||||
|
|
||||||
|
void BFSCompentExplorer(
|
||||||
|
std::vector<unsigned> & component_index_list,
|
||||||
|
std::vector<unsigned> & component_index_size
|
||||||
|
) const;
|
||||||
|
|
||||||
|
void FlushVectorToStream(
|
||||||
|
std::ofstream & edge_data_file,
|
||||||
|
std::vector<OriginalEdgeData> & original_edge_data_vector
|
||||||
|
) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* EDGEBASEDGRAPHFACTORY_H_ */
|
#endif /* EDGEBASEDGRAPHFACTORY_H_ */
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "GeometryCompressor.h"
|
||||||
|
|
||||||
|
int current_free_list_maximum = 0;
|
||||||
|
int UniqueNumber () { return ++current_free_list_maximum; }
|
||||||
|
|
||||||
|
GeometryCompressor::GeometryCompressor() {
|
||||||
|
m_free_list.resize(100);
|
||||||
|
IncreaseFreeList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeometryCompressor::IncreaseFreeList() {
|
||||||
|
m_compressed_geometries.resize(m_compressed_geometries.size() + 100);
|
||||||
|
std::generate_n (m_free_list.rend(), 100, UniqueNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeometryCompressor::AppendNodeIDsToGeomtry( NodeID node_id, NodeID contracted_node_id ) {
|
||||||
|
//check if node_id already has a list
|
||||||
|
boost::unordered_map<unsigned, unsigned>::const_iterator map_iterator;
|
||||||
|
map_iterator = m_node_id_to_index_map.find( node_id );
|
||||||
|
|
||||||
|
unsigned geometry_bucket_index = std::numeric_limits<unsigned>::max();
|
||||||
|
if( m_node_id_to_index_map.end() == map_iterator ) {
|
||||||
|
//if not, create one
|
||||||
|
if( m_free_list.empty() ) {
|
||||||
|
IncreaseFreeList();
|
||||||
|
}
|
||||||
|
geometry_bucket_index = m_free_list.back();
|
||||||
|
m_free_list.pop_back();
|
||||||
|
} else {
|
||||||
|
geometry_bucket_index = map_iterator->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_ASSERT( std::numeric_limits<unsigned>::max() != geometry_bucket_index );
|
||||||
|
BOOST_ASSERT( geometry_bucket_index < m_compressed_geometries.size() );
|
||||||
|
|
||||||
|
//append contracted_node_id to m_compressed_geometries[node_id]
|
||||||
|
m_compressed_geometries[geometry_bucket_index].push_back(contracted_node_id);
|
||||||
|
|
||||||
|
//append m_compressed_geometries[contracted_node_id] to m_compressed_geometries[node_id]
|
||||||
|
map_iterator = m_node_id_to_index_map.find(contracted_node_id);
|
||||||
|
if ( m_node_id_to_index_map.end() != map_iterator) {
|
||||||
|
const unsigned bucket_index_to_remove = map_iterator->second;
|
||||||
|
BOOST_ASSERT( bucket_index_to_remove < m_compressed_geometries.size() );
|
||||||
|
|
||||||
|
m_compressed_geometries[geometry_bucket_index].insert(
|
||||||
|
m_compressed_geometries[geometry_bucket_index].end(),
|
||||||
|
m_compressed_geometries[bucket_index_to_remove].begin(),
|
||||||
|
m_compressed_geometries[bucket_index_to_remove].end()
|
||||||
|
);
|
||||||
|
//remove m_compressed_geometries[contracted_node_id], add to free list
|
||||||
|
m_compressed_geometries[bucket_index_to_remove].clear();
|
||||||
|
m_free_list.push_back(bucket_index_to_remove);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeometryCompressor::PrintStatistics() const {
|
||||||
|
unsigned compressed_node_count = 0;
|
||||||
|
const unsigned surviving_node_count = m_compressed_geometries.size();
|
||||||
|
|
||||||
|
BOOST_FOREACH(const std::vector<unsigned> & current_vector, m_compressed_geometries) {
|
||||||
|
compressed_node_count += current_vector.size();
|
||||||
|
}
|
||||||
|
SimpleLogger().Write() <<
|
||||||
|
"surv: " << surviving_node_count <<
|
||||||
|
", comp: " << compressed_node_count <<
|
||||||
|
", comp ratio: " << ((float)surviving_node_count/std::max(compressed_node_count, 1u) );
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 "../Util/SimpleLogger.h"
|
||||||
|
#include "../typedefs.h"
|
||||||
|
|
||||||
|
#include <boost/assert.hpp>
|
||||||
|
#include <boost/foreach.hpp>
|
||||||
|
#include <boost/unordered_map.hpp>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <limits>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#ifndef GEOMETRY_COMPRESSOR_H
|
||||||
|
#define GEOMETRY_COMPRESSOR_H
|
||||||
|
|
||||||
|
class GeometryCompressor {
|
||||||
|
public:
|
||||||
|
GeometryCompressor();
|
||||||
|
void AppendNodeIDsToGeomtry( NodeID node_id, NodeID contracted_node_id );
|
||||||
|
void PrintStatistics() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void IncreaseFreeList();
|
||||||
|
|
||||||
|
std::vector<std::vector<unsigned> > m_compressed_geometries;
|
||||||
|
std::vector<unsigned> m_free_list;
|
||||||
|
boost::unordered_map<unsigned, unsigned> m_node_id_to_index_map;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //GEOMETRY_COMPRESSOR_H
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
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 & e) {
|
||||||
|
Abort(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t TemporaryStorage::GetFreeBytesOnTemporaryDevice() {
|
||||||
|
uint64_t value = -1;
|
||||||
|
try {
|
||||||
|
boost::filesystem::path p = boost::filesystem::temp_directory_path();
|
||||||
|
boost::filesystem::space_info s = boost::filesystem::space( p );
|
||||||
|
value = s.free;
|
||||||
|
} catch(boost::filesystem::filesystem_error & e) {
|
||||||
|
Abort(e);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemporaryStorage::CheckIfTemporaryDeviceFull() {
|
||||||
|
boost::filesystem::path p = boost::filesystem::temp_directory_path();
|
||||||
|
boost::filesystem::space_info s = boost::filesystem::space( p );
|
||||||
|
if( (1024*1024) > s.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& e) {
|
||||||
|
RemoveAll();
|
||||||
|
throw OSRMException(e.what());
|
||||||
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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/foreach.hpp>
|
||||||
|
#include <boost/integer.hpp>
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <boost/filesystem/fstream.hpp>
|
||||||
|
#include <boost/make_shared.hpp>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <boost/thread/mutex.hpp>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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();
|
||||||
|
|
||||||
|
struct StreamData {
|
||||||
|
bool write_mode;
|
||||||
|
boost::filesystem::path temp_path;
|
||||||
|
boost::shared_ptr<boost::filesystem::fstream> temp_file;
|
||||||
|
boost::shared_ptr<boost::mutex> readWriteMutex;
|
||||||
|
std::vector<char> buffer;
|
||||||
|
|
||||||
|
StreamData() :
|
||||||
|
write_mode(true),
|
||||||
|
temp_path(
|
||||||
|
boost::filesystem::unique_path(
|
||||||
|
temp_directory.append(
|
||||||
|
TemporaryFilePattern.begin(),
|
||||||
|
TemporaryFilePattern.end()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
temp_file(
|
||||||
|
new boost::filesystem::fstream(
|
||||||
|
temp_path,
|
||||||
|
std::ios::in|std::ios::out|std::ios::trunc|std::ios::binary
|
||||||
|
)
|
||||||
|
),
|
||||||
|
readWriteMutex(boost::make_shared<boost::mutex>())
|
||||||
|
{
|
||||||
|
if( temp_file->fail() ) {
|
||||||
|
throw OSRMException("temporary file could not be created");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
//vector of file streams that is used to store temporary data
|
||||||
|
boost::mutex mutex;
|
||||||
|
std::vector<StreamData> stream_data_list;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* TEMPORARYSTORAGE_H_ */
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
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 BASEPARSER_H_
|
|
||||||
#define BASEPARSER_H_
|
|
||||||
|
|
||||||
template<typename NodeT, typename RestrictionT, typename WayT>
|
|
||||||
class BaseParser {
|
|
||||||
public:
|
|
||||||
virtual ~BaseParser() {}
|
|
||||||
virtual bool Init() = 0;
|
|
||||||
virtual bool RegisterCallbacks(bool (*nodeCallbackPointer)(NodeT), bool (*restrictionCallbackPointer)(RestrictionT), bool (*wayCallbackPointer)(WayT), bool (*addressCallbackPointer)(NodeT, HashTable<std::string, std::string>)) = 0;
|
|
||||||
virtual bool Parse() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* BASEPARSER_H_ */
|
|
||||||
@@ -1,36 +1,43 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, others 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
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
|
Redistributions of source code must retain the above copyright notice, this list
|
||||||
along with this program; if not, write to the Free Software
|
of conditions and the following disclaimer.
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
list of conditions and the following disclaimer in the documentation and/or
|
||||||
*/
|
other materials provided with the distribution.
|
||||||
|
|
||||||
#ifndef BINARYHEAP_H_INCLUDED
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
#define BINARYHEAP_H_INCLUDED
|
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 BINARY_HEAP_H
|
||||||
|
#define BINARY_HEAP_H
|
||||||
|
|
||||||
//Not compatible with non contiguous node ids
|
//Not compatible with non contiguous node ids
|
||||||
|
|
||||||
#include <cassert>
|
#include <boost/unordered_map.hpp>
|
||||||
#include <limits>
|
|
||||||
#include <vector>
|
#include <boost/assert.hpp>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <limits>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <google/dense_hash_map>
|
#include <vector>
|
||||||
#include <google/sparse_hash_map>
|
|
||||||
#include <google/sparsetable>
|
|
||||||
|
|
||||||
template< typename NodeID, typename Key >
|
template< typename NodeID, typename Key >
|
||||||
class ArrayStorage {
|
class ArrayStorage {
|
||||||
@@ -58,7 +65,7 @@ template< typename NodeID, typename Key >
|
|||||||
class MapStorage {
|
class MapStorage {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MapStorage( size_t size = 0 ) {}
|
MapStorage( size_t ) {}
|
||||||
|
|
||||||
Key &operator[]( NodeID node ) {
|
Key &operator[]( NodeID node ) {
|
||||||
return nodes[node];
|
return nodes[node];
|
||||||
@@ -74,12 +81,18 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template< typename NodeID, typename Key >
|
template< typename NodeID, typename Key >
|
||||||
class DenseStorage {
|
class UnorderedMapStorage {
|
||||||
|
typedef boost::unordered_map<NodeID, Key> UnorderedMapType;
|
||||||
|
typedef typename UnorderedMapType::iterator UnorderedMapIterator;
|
||||||
|
typedef typename UnorderedMapType::const_iterator UnorderedMapConstIterator;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
DenseStorage( size_t size = 0 ) { nodes.set_empty_key(UINT_MAX); }
|
UnorderedMapStorage( size_t ) {
|
||||||
|
//hash table gets 1000 Buckets
|
||||||
|
nodes.rehash(1000);
|
||||||
|
}
|
||||||
|
|
||||||
Key &operator[]( NodeID node ) {
|
Key & operator[]( const NodeID node ) {
|
||||||
return nodes[node];
|
return nodes[node];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,43 +101,16 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
google::dense_hash_map< NodeID, Key > nodes;
|
boost::unordered_map< NodeID, Key > nodes;
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename NodeID, typename Key >
|
template<
|
||||||
class SparseStorage {
|
typename NodeID,
|
||||||
public:
|
typename Key,
|
||||||
|
typename Weight,
|
||||||
SparseStorage( size_t size = 0 ) { }
|
typename Data,
|
||||||
|
typename IndexStorage = ArrayStorage<NodeID, NodeID>
|
||||||
Key &operator[]( NodeID node ) {
|
>
|
||||||
return nodes[node];
|
|
||||||
}
|
|
||||||
|
|
||||||
void Clear() {
|
|
||||||
nodes.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
google::sparse_hash_map< NodeID, Key > nodes;
|
|
||||||
};
|
|
||||||
|
|
||||||
template< typename NodeID, typename Key >
|
|
||||||
class SparseTableStorage : public google::sparsetable<NodeID> {
|
|
||||||
public:
|
|
||||||
SparseTableStorage(size_t n) : google::sparsetable<NodeID>(n){ }
|
|
||||||
void Clear() {
|
|
||||||
google::sparsetable<NodeID>::clear();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename NodeID = unsigned>
|
|
||||||
struct _SimpleHeapData {
|
|
||||||
NodeID parent;
|
|
||||||
_SimpleHeapData( NodeID p ) : parent(p) { }
|
|
||||||
};
|
|
||||||
|
|
||||||
template < typename NodeID, typename Key, typename Weight, typename Data, typename IndexStorage = ArrayStorage<NodeID, NodeID> >
|
|
||||||
class BinaryHeap {
|
class BinaryHeap {
|
||||||
private:
|
private:
|
||||||
BinaryHeap( const BinaryHeap& right );
|
BinaryHeap( const BinaryHeap& right );
|
||||||
@@ -134,7 +120,9 @@ public:
|
|||||||
typedef Data DataType;
|
typedef Data DataType;
|
||||||
|
|
||||||
BinaryHeap( size_t maxID )
|
BinaryHeap( size_t maxID )
|
||||||
: nodeIndex( maxID ) {
|
:
|
||||||
|
nodeIndex( maxID )
|
||||||
|
{
|
||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,14 +134,18 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
Key Size() const {
|
Key Size() const {
|
||||||
return ( Key )( heap.size() - 1 );
|
return static_cast<Key>( heap.size() - 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Empty() const {
|
||||||
|
return 0 == Size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Insert( NodeID node, Weight weight, const Data &data ) {
|
void Insert( NodeID node, Weight weight, const Data &data ) {
|
||||||
HeapElement element;
|
HeapElement element;
|
||||||
element.index = ( NodeID ) insertedNodes.size();
|
element.index = static_cast<NodeID>(insertedNodes.size());
|
||||||
element.weight = weight;
|
element.weight = weight;
|
||||||
const Key key = ( Key ) heap.size();
|
const Key key = static_cast<Key>(heap.size());
|
||||||
heap.push_back( element );
|
heap.push_back( element );
|
||||||
insertedNodes.push_back( HeapNode( node, key, weight, data ) );
|
insertedNodes.push_back( HeapNode( node, key, weight, data ) );
|
||||||
nodeIndex[node] = element.index;
|
nodeIndex[node] = element.index;
|
||||||
@@ -171,26 +163,26 @@ public:
|
|||||||
return insertedNodes[index].weight;
|
return insertedNodes[index].weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WasRemoved( NodeID node ) {
|
bool WasRemoved( const NodeID node ) {
|
||||||
assert( WasInserted( node ) );
|
BOOST_ASSERT( WasInserted( node ) );
|
||||||
const Key index = nodeIndex[node];
|
const Key index = nodeIndex[node];
|
||||||
return insertedNodes[index].key == 0;
|
return insertedNodes[index].key == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WasInserted( NodeID node ) {
|
bool WasInserted( const NodeID node ) {
|
||||||
const Key index = nodeIndex[node];
|
const Key index = nodeIndex[node];
|
||||||
if ( index >= ( Key ) insertedNodes.size() )
|
if ( index >= static_cast<Key> (insertedNodes.size()) )
|
||||||
return false;
|
return false;
|
||||||
return insertedNodes[index].node == node;
|
return insertedNodes[index].node == node;
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID Min() const {
|
NodeID Min() const {
|
||||||
assert( heap.size() > 1 );
|
BOOST_ASSERT( heap.size() > 1 );
|
||||||
return insertedNodes[heap[1].index].node;
|
return insertedNodes[heap[1].index].node;
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID DeleteMin() {
|
NodeID DeleteMin() {
|
||||||
assert( heap.size() > 1 );
|
BOOST_ASSERT( heap.size() > 1 );
|
||||||
const Key removedIndex = heap[1].index;
|
const Key removedIndex = heap[1].index;
|
||||||
heap[1] = heap[heap.size()-1];
|
heap[1] = heap[heap.size()-1];
|
||||||
heap.pop_back();
|
heap.pop_back();
|
||||||
@@ -209,10 +201,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DecreaseKey( NodeID node, Weight weight ) {
|
void DecreaseKey( NodeID node, Weight weight ) {
|
||||||
assert( UINT_MAX != node );
|
BOOST_ASSERT( UINT_MAX != node );
|
||||||
const Key index = nodeIndex[node];
|
const Key & index = nodeIndex[node];
|
||||||
Key key = insertedNodes[index].key;
|
Key & key = insertedNodes[index].key;
|
||||||
assert ( key >= 0 );
|
BOOST_ASSERT ( key >= 0 );
|
||||||
|
|
||||||
insertedNodes[index].weight = weight;
|
insertedNodes[index].weight = weight;
|
||||||
heap[key].weight = weight;
|
heap[key].weight = weight;
|
||||||
@@ -223,11 +215,13 @@ public:
|
|||||||
private:
|
private:
|
||||||
class HeapNode {
|
class HeapNode {
|
||||||
public:
|
public:
|
||||||
HeapNode() {
|
|
||||||
}
|
|
||||||
HeapNode( NodeID n, Key k, Weight w, Data d )
|
HeapNode( NodeID n, Key k, Weight w, Data d )
|
||||||
: node( n ), key( k ), weight( w ), data( d ) {
|
:
|
||||||
}
|
node(n),
|
||||||
|
key(k),
|
||||||
|
weight(w),
|
||||||
|
data(d)
|
||||||
|
{ }
|
||||||
|
|
||||||
NodeID node;
|
NodeID node;
|
||||||
Key key;
|
Key key;
|
||||||
@@ -247,14 +241,17 @@ private:
|
|||||||
const Key droppingIndex = heap[key].index;
|
const Key droppingIndex = heap[key].index;
|
||||||
const Weight weight = heap[key].weight;
|
const Weight weight = heap[key].weight;
|
||||||
Key nextKey = key << 1;
|
Key nextKey = key << 1;
|
||||||
while ( nextKey < ( Key ) heap.size() ) {
|
while( nextKey < static_cast<Key>( heap.size() ) ){
|
||||||
const Key nextKeyOther = nextKey + 1;
|
const Key nextKeyOther = nextKey + 1;
|
||||||
if ( ( nextKeyOther < ( Key ) heap.size() )&& ( heap[nextKey].weight > heap[nextKeyOther].weight) )
|
if (
|
||||||
|
( nextKeyOther < static_cast<Key>( heap.size() ) ) &&
|
||||||
|
( heap[nextKey].weight > heap[nextKeyOther].weight )
|
||||||
|
) {
|
||||||
nextKey = nextKeyOther;
|
nextKey = nextKeyOther;
|
||||||
|
}
|
||||||
if ( weight <= heap[nextKey].weight )
|
if ( weight <= heap[nextKey].weight ){
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
heap[key] = heap[nextKey];
|
heap[key] = heap[nextKey];
|
||||||
insertedNodes[heap[key].index].key = key;
|
insertedNodes[heap[key].index].key = key;
|
||||||
key = nextKey;
|
key = nextKey;
|
||||||
@@ -270,7 +267,7 @@ private:
|
|||||||
const Weight weight = heap[key].weight;
|
const Weight weight = heap[key].weight;
|
||||||
Key nextKey = key >> 1;
|
Key nextKey = key >> 1;
|
||||||
while ( heap[nextKey].weight > weight ) {
|
while ( heap[nextKey].weight > weight ) {
|
||||||
assert( nextKey != 0 );
|
BOOST_ASSERT( nextKey != 0 );
|
||||||
heap[key] = heap[nextKey];
|
heap[key] = heap[nextKey];
|
||||||
insertedNodes[heap[key].index].key = key;
|
insertedNodes[heap[key].index].key = key;
|
||||||
key = nextKey;
|
key = nextKey;
|
||||||
@@ -284,10 +281,10 @@ private:
|
|||||||
void CheckHeap() {
|
void CheckHeap() {
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
for ( Key i = 2; i < (Key) heap.size(); ++i ) {
|
for ( Key i = 2; i < (Key) heap.size(); ++i ) {
|
||||||
assert( heap[i].weight >= heap[i >> 1].weight );
|
BOOST_ASSERT( heap[i].weight >= heap[i >> 1].weight );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //#ifndef BINARYHEAP_H_INCLUDED
|
#endif //BINARY_HEAP_H
|
||||||
|
|||||||
@@ -1,98 +1,99 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, others 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
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
|
Redistributions of source code must retain the above copyright notice, this list
|
||||||
along with this program; if not, write to the Free Software
|
of conditions and the following disclaimer.
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
list of conditions and the following disclaimer in the documentation and/or
|
||||||
*/
|
other materials provided with the distribution.
|
||||||
|
|
||||||
#ifndef CONCURRENTQUEUE_H_INCLUDED
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
#define CONCURRENTQUEUE_H_INCLUDED
|
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 <queue>
|
*/
|
||||||
#include <boost/signals2/mutex.hpp>
|
|
||||||
|
#ifndef CONCURRENTQUEUE_H_
|
||||||
|
#define CONCURRENTQUEUE_H_
|
||||||
|
|
||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
|
|
||||||
/*
|
#include <boost/bind.hpp>
|
||||||
Concurrent Queue written by Anthony Williams:
|
#include <boost/circular_buffer.hpp>
|
||||||
http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html
|
#include <boost/thread/condition.hpp>
|
||||||
*/
|
#include <boost/thread/mutex.hpp>
|
||||||
|
#include <boost/thread/thread.hpp>
|
||||||
|
|
||||||
template<typename Data>
|
template<typename Data>
|
||||||
class ConcurrentQueue {
|
class ConcurrentQueue {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ConcurrentQueue(const size_t max_size)
|
ConcurrentQueue(const size_t max_size) : m_internal_queue(max_size) { }
|
||||||
: max_queue_size(max_size) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void push(Data const& data) {
|
inline void push(const Data & data) {
|
||||||
if (size_exceeded()) {
|
boost::mutex::scoped_lock lock(m_mutex);
|
||||||
boost::mutex::scoped_lock qf_lock(queue_full_mutex);
|
m_not_full.wait(
|
||||||
queue_full_cv.wait(qf_lock);
|
lock,
|
||||||
}
|
boost::bind(&ConcurrentQueue<Data>::is_not_full, this)
|
||||||
|
);
|
||||||
boost::mutex::scoped_lock lock(queue_mutex);
|
m_internal_queue.push_back(data);
|
||||||
internal_queue.push(data);
|
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
queue_cv.notify_one();
|
m_not_empty.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool empty() const {
|
inline bool empty() const {
|
||||||
return internal_queue.empty();
|
return m_internal_queue.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool try_pop(Data& popped_value) {
|
inline void wait_and_pop(Data & popped_value) {
|
||||||
boost::mutex::scoped_lock lock(queue_mutex);
|
boost::mutex::scoped_lock lock(m_mutex);
|
||||||
if(internal_queue.empty()) {
|
m_not_empty.wait(
|
||||||
|
lock,
|
||||||
|
boost::bind(&ConcurrentQueue<Data>::is_not_empty, this)
|
||||||
|
);
|
||||||
|
popped_value = m_internal_queue.front();
|
||||||
|
m_internal_queue.pop_front();
|
||||||
|
lock.unlock();
|
||||||
|
m_not_full.notify_one();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool try_pop(Data& popped_value) {
|
||||||
|
boost::mutex::scoped_lock lock(m_mutex);
|
||||||
|
if(m_internal_queue.empty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
popped_value=m_internal_queue.front();
|
||||||
popped_value=internal_queue.front();
|
m_internal_queue.pop_front();
|
||||||
internal_queue.pop();
|
lock.unlock();
|
||||||
queue_full_cv.notify_one();
|
m_not_full.notify_one();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wait_and_pop(Data& popped_value) {
|
|
||||||
boost::mutex::scoped_lock lock(queue_mutex);
|
|
||||||
while(internal_queue.empty()) {
|
|
||||||
queue_cv.wait(lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
popped_value=internal_queue.front();
|
|
||||||
internal_queue.pop();
|
|
||||||
queue_full_cv.notify_one();
|
|
||||||
}
|
|
||||||
|
|
||||||
int size() const {
|
|
||||||
return static_cast<int>(internal_queue.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::queue<Data> internal_queue;
|
inline bool is_not_empty() const {
|
||||||
mutable boost::mutex queue_mutex;
|
return !m_internal_queue.empty();
|
||||||
mutable boost::mutex queue_full_mutex;
|
|
||||||
boost::condition_variable queue_cv;
|
|
||||||
boost::condition_variable queue_full_cv;
|
|
||||||
const size_t max_queue_size;
|
|
||||||
|
|
||||||
bool size_exceeded() const {
|
|
||||||
return internal_queue.size() >= max_queue_size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool is_not_full() const {
|
||||||
|
return m_internal_queue.size() < m_internal_queue.capacity();
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::circular_buffer<Data> m_internal_queue;
|
||||||
|
boost::mutex m_mutex;
|
||||||
|
boost::condition m_not_empty;
|
||||||
|
boost::condition m_not_full;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //#ifndef CONCURRENTQUEUE_H_INCLUDED
|
#endif /* CONCURRENTQUEUE_H_ */
|
||||||
|
|||||||
@@ -0,0 +1,162 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 <osrm/Coordinate.h>
|
||||||
|
#include "../Util/StringUtil.h"
|
||||||
|
|
||||||
|
#include <boost/assert.hpp>
|
||||||
|
#include <cmath>
|
||||||
|
#include <climits>
|
||||||
|
|
||||||
|
FixedPointCoordinate::FixedPointCoordinate()
|
||||||
|
: lat(INT_MIN),
|
||||||
|
lon(INT_MIN)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
FixedPointCoordinate::FixedPointCoordinate(int lat, int lon)
|
||||||
|
: lat(lat),
|
||||||
|
lon(lon)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void FixedPointCoordinate::Reset() {
|
||||||
|
lat = INT_MIN;
|
||||||
|
lon = INT_MIN;
|
||||||
|
}
|
||||||
|
bool FixedPointCoordinate::isSet() const {
|
||||||
|
return (INT_MIN != lat) && (INT_MIN != lon);
|
||||||
|
}
|
||||||
|
bool FixedPointCoordinate::isValid() const {
|
||||||
|
if(
|
||||||
|
lat > 90*COORDINATE_PRECISION ||
|
||||||
|
lat < -90*COORDINATE_PRECISION ||
|
||||||
|
lon > 180*COORDINATE_PRECISION ||
|
||||||
|
lon < -180*COORDINATE_PRECISION
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool FixedPointCoordinate::operator==(const FixedPointCoordinate & other) const {
|
||||||
|
return lat == other.lat && lon == other.lon;
|
||||||
|
}
|
||||||
|
|
||||||
|
double FixedPointCoordinate::ApproximateDistance(
|
||||||
|
const int lat1,
|
||||||
|
const int lon1,
|
||||||
|
const int lat2,
|
||||||
|
const int lon2
|
||||||
|
) {
|
||||||
|
BOOST_ASSERT(lat1 != INT_MIN);
|
||||||
|
BOOST_ASSERT(lon1 != INT_MIN);
|
||||||
|
BOOST_ASSERT(lat2 != INT_MIN);
|
||||||
|
BOOST_ASSERT(lon2 != INT_MIN);
|
||||||
|
double RAD = 0.017453292519943295769236907684886;
|
||||||
|
double lt1 = lat1/COORDINATE_PRECISION;
|
||||||
|
double ln1 = lon1/COORDINATE_PRECISION;
|
||||||
|
double lt2 = lat2/COORDINATE_PRECISION;
|
||||||
|
double ln2 = lon2/COORDINATE_PRECISION;
|
||||||
|
double dlat1=lt1*(RAD);
|
||||||
|
|
||||||
|
double dlong1=ln1*(RAD);
|
||||||
|
double dlat2=lt2*(RAD);
|
||||||
|
double dlong2=ln2*(RAD);
|
||||||
|
|
||||||
|
double dLong=dlong1-dlong2;
|
||||||
|
double dLat=dlat1-dlat2;
|
||||||
|
|
||||||
|
double aHarv= pow(sin(dLat/2.0),2.0)+cos(dlat1)*cos(dlat2)*pow(sin(dLong/2.),2);
|
||||||
|
double cHarv=2.*atan2(sqrt(aHarv),sqrt(1.0-aHarv));
|
||||||
|
//earth radius varies between 6,356.750-6,378.135 km (3,949.901-3,963.189mi)
|
||||||
|
//The IUGG value for the equatorial radius is 6378.137 km (3963.19 miles)
|
||||||
|
const double earth=6372797.560856;
|
||||||
|
double distance=earth*cHarv;
|
||||||
|
return distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
double FixedPointCoordinate::ApproximateDistance(
|
||||||
|
const FixedPointCoordinate &c1,
|
||||||
|
const FixedPointCoordinate &c2
|
||||||
|
) {
|
||||||
|
return ApproximateDistance( c1.lat, c1.lon, c2.lat, c2.lon );
|
||||||
|
}
|
||||||
|
|
||||||
|
double FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||||
|
const FixedPointCoordinate &c1,
|
||||||
|
const FixedPointCoordinate &c2
|
||||||
|
) {
|
||||||
|
BOOST_ASSERT(c1.lat != INT_MIN);
|
||||||
|
BOOST_ASSERT(c1.lon != INT_MIN);
|
||||||
|
BOOST_ASSERT(c2.lat != INT_MIN);
|
||||||
|
BOOST_ASSERT(c2.lon != INT_MIN);
|
||||||
|
const double RAD = 0.017453292519943295769236907684886;
|
||||||
|
const double lat1 = (c1.lat/COORDINATE_PRECISION)*RAD;
|
||||||
|
const double lon1 = (c1.lon/COORDINATE_PRECISION)*RAD;
|
||||||
|
const double lat2 = (c2.lat/COORDINATE_PRECISION)*RAD;
|
||||||
|
const double lon2 = (c2.lon/COORDINATE_PRECISION)*RAD;
|
||||||
|
|
||||||
|
const double x = (lon2-lon1) * cos((lat1+lat2)/2.);
|
||||||
|
const double y = (lat2-lat1);
|
||||||
|
const double earthRadius = 6372797.560856;
|
||||||
|
const double d = sqrt(x*x + y*y) * earthRadius;
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FixedPointCoordinate::convertInternalLatLonToString(
|
||||||
|
const int value,
|
||||||
|
std::string & output
|
||||||
|
) {
|
||||||
|
char buffer[100];
|
||||||
|
buffer[11] = 0; // zero termination
|
||||||
|
char* string = printInt< 11, 6 >( buffer, value );
|
||||||
|
output = string;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FixedPointCoordinate::convertInternalCoordinateToString(
|
||||||
|
const FixedPointCoordinate & coord,
|
||||||
|
std::string & output
|
||||||
|
) {
|
||||||
|
std::string tmp;
|
||||||
|
tmp.reserve(23);
|
||||||
|
convertInternalLatLonToString(coord.lon, tmp);
|
||||||
|
output = tmp;
|
||||||
|
output += ",";
|
||||||
|
convertInternalLatLonToString(coord.lat, tmp);
|
||||||
|
output += tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FixedPointCoordinate::convertInternalReversedCoordinateToString(
|
||||||
|
const FixedPointCoordinate & coord,
|
||||||
|
std::string & output
|
||||||
|
) {
|
||||||
|
std::string tmp;
|
||||||
|
tmp.reserve(23);
|
||||||
|
convertInternalLatLonToString(coord.lat, tmp);
|
||||||
|
output = tmp;
|
||||||
|
output += ",";
|
||||||
|
convertInternalLatLonToString(coord.lon, tmp);
|
||||||
|
output += tmp;
|
||||||
|
}
|
||||||
@@ -0,0 +1,324 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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>
|
||||||
|
|
||||||
|
#if __cplusplus > 199711L
|
||||||
|
#define DEALLOCATION_VECTOR_NULL_PTR nullptr
|
||||||
|
#else
|
||||||
|
#define DEALLOCATION_VECTOR_NULL_PTR NULL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
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) : /*mData(r.mData),*/ mIndex(r.mIndex), mBucketList(r.mBucketList) {}
|
||||||
|
explicit DeallocatingVectorIteratorState(const std::size_t idx, std::vector<ElementT *> & input_list) : /*mData(DEALLOCATION_VECTOR_NULL_PTR),*/ mIndex(idx), mBucketList(input_list) {
|
||||||
|
}
|
||||||
|
std::size_t mIndex;
|
||||||
|
std::vector<ElementT *> & mBucketList;
|
||||||
|
|
||||||
|
inline bool operator!=(const DeallocatingVectorIteratorState &other) {
|
||||||
|
return mIndex != other.mIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator==(const DeallocatingVectorIteratorState &other) {
|
||||||
|
return mIndex == other.mIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator<(const DeallocatingVectorIteratorState &other) const {
|
||||||
|
return mIndex < other.mIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator>(const DeallocatingVectorIteratorState &other) const {
|
||||||
|
return mIndex > other.mIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator>=(const DeallocatingVectorIteratorState &other) const {
|
||||||
|
return mIndex >= other.mIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
//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 mState;
|
||||||
|
|
||||||
|
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>
|
||||||
|
DeallocatingVectorIterator(const DeallocatingVectorIterator<T2> & r) : mState(r.mState) {}
|
||||||
|
|
||||||
|
DeallocatingVectorIterator(std::size_t idx, std::vector<ElementT *> & input_list) : mState(idx, input_list) {}
|
||||||
|
DeallocatingVectorIterator(const DeallocatingVectorIteratorState & r) : mState(r) {}
|
||||||
|
|
||||||
|
template<typename T2>
|
||||||
|
DeallocatingVectorIterator& operator=(const DeallocatingVectorIterator<T2> &r) {
|
||||||
|
if(DeallocateC) BOOST_ASSERT(false);
|
||||||
|
mState = r.mState; return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline DeallocatingVectorIterator& operator++() { //prefix
|
||||||
|
++mState.mIndex;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline DeallocatingVectorIterator& operator--() { //prefix
|
||||||
|
if(DeallocateC) BOOST_ASSERT(false);
|
||||||
|
--mState.mIndex;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline DeallocatingVectorIterator operator++(int) { //postfix
|
||||||
|
DeallocatingVectorIteratorState _myState(mState);
|
||||||
|
mState.mIndex++;
|
||||||
|
return DeallocatingVectorIterator(_myState);
|
||||||
|
}
|
||||||
|
inline DeallocatingVectorIterator operator--(int) { //postfix
|
||||||
|
if(DeallocateC) BOOST_ASSERT(false);
|
||||||
|
DeallocatingVectorIteratorState _myState(mState);
|
||||||
|
mState.mIndex--;
|
||||||
|
return DeallocatingVectorIterator(_myState);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline DeallocatingVectorIterator operator+(const difference_type& n) const {
|
||||||
|
DeallocatingVectorIteratorState _myState(mState);
|
||||||
|
_myState.mIndex+=n;
|
||||||
|
return DeallocatingVectorIterator(_myState);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline DeallocatingVectorIterator& operator+=(const difference_type& n) {
|
||||||
|
mState.mIndex+=n; return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline DeallocatingVectorIterator operator-(const difference_type& n) const {
|
||||||
|
if(DeallocateC) BOOST_ASSERT(false);
|
||||||
|
DeallocatingVectorIteratorState _myState(mState);
|
||||||
|
_myState.mIndex-=n;
|
||||||
|
return DeallocatingVectorIterator(_myState);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline DeallocatingVectorIterator& operator-=(const difference_type &n) const {
|
||||||
|
if(DeallocateC) BOOST_ASSERT(false);
|
||||||
|
mState.mIndex-=n; return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline reference operator*() const {
|
||||||
|
std::size_t _bucket = mState.mIndex/bucketSizeC;
|
||||||
|
std::size_t _index = mState.mIndex%bucketSizeC;
|
||||||
|
return (mState.mBucketList[_bucket][_index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline pointer operator->() const {
|
||||||
|
std::size_t _bucket = mState.mIndex/bucketSizeC;
|
||||||
|
std::size_t _index = mState.mIndex%bucketSizeC;
|
||||||
|
return &(mState.mBucketList[_bucket][_index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator!=(const DeallocatingVectorIterator & other) {
|
||||||
|
return mState != other.mState;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator==(const DeallocatingVectorIterator & other) {
|
||||||
|
return mState == other.mState;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator<(const DeallocatingVectorIterator & other) const {
|
||||||
|
return mState < other.mState;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator>(const DeallocatingVectorIterator & other) const {
|
||||||
|
return mState > other.mState;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator>=(const DeallocatingVectorIterator & other) const {
|
||||||
|
return mState >= other.mState;
|
||||||
|
}
|
||||||
|
|
||||||
|
difference_type operator-(const DeallocatingVectorIterator & other) {
|
||||||
|
if(DeallocateC) BOOST_ASSERT(false);
|
||||||
|
return mState.mIndex-other.mState.mIndex;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename ElementT, std::size_t bucketSizeC = 8388608/sizeof(ElementT) >
|
||||||
|
class DeallocatingVector {
|
||||||
|
private:
|
||||||
|
std::size_t mCurrentSize;
|
||||||
|
std::vector<ElementT *> mBucketList;
|
||||||
|
|
||||||
|
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() : mCurrentSize(0) {
|
||||||
|
//initial bucket
|
||||||
|
mBucketList.push_back(new ElementT[bucketSizeC]);
|
||||||
|
}
|
||||||
|
|
||||||
|
~DeallocatingVector() {
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void swap(DeallocatingVector<ElementT, bucketSizeC> & other) {
|
||||||
|
std::swap(mCurrentSize, other.mCurrentSize);
|
||||||
|
mBucketList.swap(other.mBucketList);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void clear() {
|
||||||
|
//Delete[]'ing ptr's to all Buckets
|
||||||
|
for(unsigned i = 0; i < mBucketList.size(); ++i) {
|
||||||
|
if(DEALLOCATION_VECTOR_NULL_PTR != mBucketList[i]) {
|
||||||
|
delete[] mBucketList[i];
|
||||||
|
mBucketList[i] = DEALLOCATION_VECTOR_NULL_PTR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Removing all ptrs from vector
|
||||||
|
std::vector<ElementT *>().swap(mBucketList);
|
||||||
|
mCurrentSize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void push_back(const ElementT & element) {
|
||||||
|
std::size_t _capacity = capacity();
|
||||||
|
if(mCurrentSize == _capacity) {
|
||||||
|
mBucketList.push_back(new ElementT[bucketSizeC]);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t _index = size()%bucketSizeC;
|
||||||
|
mBucketList.back()[_index] = element;
|
||||||
|
++mCurrentSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void reserve(const std::size_t) const {
|
||||||
|
//don't do anything
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void resize(const std::size_t new_size) {
|
||||||
|
if(new_size > mCurrentSize) {
|
||||||
|
while(capacity() < new_size) {
|
||||||
|
mBucketList.push_back(new ElementT[bucketSizeC]);
|
||||||
|
}
|
||||||
|
mCurrentSize = new_size;
|
||||||
|
}
|
||||||
|
if(new_size < mCurrentSize) {
|
||||||
|
std::size_t number_of_necessary_buckets = 1+(new_size / bucketSizeC);
|
||||||
|
|
||||||
|
for(unsigned i = number_of_necessary_buckets; i < mBucketList.size(); ++i) {
|
||||||
|
delete[] mBucketList[i];
|
||||||
|
}
|
||||||
|
mBucketList.resize(number_of_necessary_buckets);
|
||||||
|
mCurrentSize = new_size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::size_t size() const {
|
||||||
|
return mCurrentSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::size_t capacity() const {
|
||||||
|
return mBucketList.size() * bucketSizeC;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline iterator begin() {
|
||||||
|
return iterator(static_cast<std::size_t>(0), mBucketList);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline iterator end() {
|
||||||
|
return iterator(size(), mBucketList);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline deallocation_iterator dbegin() {
|
||||||
|
return deallocation_iterator(static_cast<std::size_t>(0), mBucketList);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline deallocation_iterator dend() {
|
||||||
|
return deallocation_iterator(size(), mBucketList);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const_iterator begin() const {
|
||||||
|
return const_iterator(static_cast<std::size_t>(0), mBucketList);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const_iterator end() const {
|
||||||
|
return const_iterator(size(), mBucketList);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline ElementT & operator[](const std::size_t index) {
|
||||||
|
std::size_t _bucket = index / bucketSizeC;
|
||||||
|
std::size_t _index = index % bucketSizeC;
|
||||||
|
return (mBucketList[_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 (mBucketList[_bucket][_index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline ElementT & back() {
|
||||||
|
std::size_t _bucket = mCurrentSize / bucketSizeC;
|
||||||
|
std::size_t _index = mCurrentSize % bucketSizeC;
|
||||||
|
return (mBucketList[_bucket][_index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const inline ElementT & back() const {
|
||||||
|
std::size_t _bucket = mCurrentSize / bucketSizeC;
|
||||||
|
std::size_t _index = mCurrentSize % bucketSizeC;
|
||||||
|
return (mBucketList[_bucket][_index]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* DEALLOCATINGVECTOR_H_ */
|
||||||
@@ -1,29 +1,41 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, others 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
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
|
Redistributions of source code must retain the above copyright notice, this list
|
||||||
along with this program; if not, write to the Free Software
|
of conditions and the following disclaimer.
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
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 DYNAMICGRAPH_H_INCLUDED
|
#ifndef DYNAMICGRAPH_H_INCLUDED
|
||||||
#define DYNAMICGRAPH_H_INCLUDED
|
#define DYNAMICGRAPH_H_INCLUDED
|
||||||
|
|
||||||
#include <vector>
|
#include "../DataStructures/DeallocatingVector.h"
|
||||||
|
|
||||||
|
#include <boost/assert.hpp>
|
||||||
|
#include <boost/integer.hpp>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
template< typename EdgeDataT>
|
template< typename EdgeDataT>
|
||||||
class DynamicGraph {
|
class DynamicGraph {
|
||||||
@@ -45,19 +57,20 @@ class DynamicGraph {
|
|||||||
};
|
};
|
||||||
|
|
||||||
//Constructs an empty graph with a given number of nodes.
|
//Constructs an empty graph with a given number of nodes.
|
||||||
DynamicGraph( int nodes ) : m_numNodes(nodes), m_numEdges(0) {
|
DynamicGraph( int32_t nodes ) : m_numNodes(nodes), m_numEdges(0) {
|
||||||
m_nodes.reserve( m_numNodes );
|
m_nodes.reserve( m_numNodes );
|
||||||
m_nodes.resize( m_numNodes );
|
m_nodes.resize( m_numNodes );
|
||||||
|
|
||||||
m_edges.reserve( m_numNodes * 1.2 );
|
m_edges.reserve( m_numNodes * 1.1 );
|
||||||
m_edges.resize( m_numNodes );
|
m_edges.resize( m_numNodes );
|
||||||
}
|
}
|
||||||
DynamicGraph( int nodes, const std::vector< InputEdge > &graph )
|
|
||||||
{
|
template<class ContainerT>
|
||||||
|
DynamicGraph( const int32_t nodes, const ContainerT &graph ) {
|
||||||
m_numNodes = nodes;
|
m_numNodes = nodes;
|
||||||
m_numEdges = ( EdgeIterator ) graph.size();
|
m_numEdges = ( EdgeIterator ) graph.size();
|
||||||
m_nodes.reserve( m_numNodes );
|
m_nodes.reserve( m_numNodes +1);
|
||||||
m_nodes.resize( m_numNodes );
|
m_nodes.resize( m_numNodes +1);
|
||||||
EdgeIterator edge = 0;
|
EdgeIterator edge = 0;
|
||||||
EdgeIterator position = 0;
|
EdgeIterator position = 0;
|
||||||
for ( NodeIterator node = 0; node < m_numNodes; ++node ) {
|
for ( NodeIterator node = 0; node < m_numNodes; ++node ) {
|
||||||
@@ -69,65 +82,63 @@ class DynamicGraph {
|
|||||||
m_nodes[node].edges = edge - lastEdge;
|
m_nodes[node].edges = edge - lastEdge;
|
||||||
position += m_nodes[node].edges;
|
position += m_nodes[node].edges;
|
||||||
}
|
}
|
||||||
m_edges.reserve( position * 1.2 );
|
m_nodes.back().firstEdge = position;
|
||||||
|
m_edges.reserve( position * 1.1 );
|
||||||
m_edges.resize( position );
|
m_edges.resize( position );
|
||||||
edge = 0;
|
edge = 0;
|
||||||
for ( NodeIterator node = 0; node < m_numNodes; ++node ) {
|
for ( NodeIterator node = 0; node < m_numNodes; ++node ) {
|
||||||
for ( EdgeIterator i = m_nodes[node].firstEdge, e = m_nodes[node].firstEdge + m_nodes[node].edges; i != e; ++i ) {
|
for ( EdgeIterator i = m_nodes[node].firstEdge, e = m_nodes[node].firstEdge + m_nodes[node].edges; i != e; ++i ) {
|
||||||
m_edges[i].target = graph[edge].target;
|
m_edges[i].target = graph[edge].target;
|
||||||
m_edges[i].data = graph[edge].data;
|
m_edges[i].data = graph[edge].data;
|
||||||
GUARANTEE(graph[edge].data.distance > 0, "edge: " << edge << "(" << graph[edge].source << "," << graph[edge].target << ")=" << graph[edge].data.distance);
|
BOOST_ASSERT_MSG(
|
||||||
edge++;
|
graph[edge].data.distance > 0,
|
||||||
|
"edge distance invalid"
|
||||||
|
);
|
||||||
|
++edge;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~DynamicGraph(){ }
|
~DynamicGraph(){ }
|
||||||
|
|
||||||
unsigned GetNumberOfNodes() const
|
unsigned GetNumberOfNodes() const {
|
||||||
{
|
|
||||||
return m_numNodes;
|
return m_numNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned GetNumberOfEdges() const
|
unsigned GetNumberOfEdges() const {
|
||||||
{
|
|
||||||
return m_numEdges;
|
return m_numEdges;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned GetOutDegree( const NodeIterator &n ) const
|
unsigned GetOutDegree( const NodeIterator n ) const {
|
||||||
{
|
|
||||||
return m_nodes[n].edges;
|
return m_nodes[n].edges;
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeIterator GetTarget( const EdgeIterator &e ) const
|
NodeIterator GetTarget( const EdgeIterator e ) const {
|
||||||
{
|
|
||||||
return NodeIterator( m_edges[e].target );
|
return NodeIterator( m_edges[e].target );
|
||||||
}
|
}
|
||||||
|
|
||||||
EdgeDataT &GetEdgeData( const EdgeIterator &e )
|
void SetTarget( const EdgeIterator e, const NodeIterator n ) {
|
||||||
{
|
m_edges[e].target = n;
|
||||||
|
}
|
||||||
|
|
||||||
|
EdgeDataT &GetEdgeData( const EdgeIterator e ) {
|
||||||
return m_edges[e].data;
|
return m_edges[e].data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const EdgeDataT &GetEdgeData( const EdgeIterator &e ) const
|
const EdgeDataT &GetEdgeData( const EdgeIterator e ) const {
|
||||||
{
|
|
||||||
return m_edges[e].data;
|
return m_edges[e].data;
|
||||||
}
|
}
|
||||||
|
|
||||||
EdgeIterator BeginEdges( const NodeIterator &n ) const
|
EdgeIterator BeginEdges( const NodeIterator n ) const {
|
||||||
{
|
|
||||||
//assert( EndEdges( n ) - EdgeIterator( _nodes[n].firstEdge ) <= 100 );
|
|
||||||
return EdgeIterator( m_nodes[n].firstEdge );
|
return EdgeIterator( m_nodes[n].firstEdge );
|
||||||
}
|
}
|
||||||
|
|
||||||
EdgeIterator EndEdges( const NodeIterator &n ) const
|
EdgeIterator EndEdges( const NodeIterator n ) const {
|
||||||
{
|
|
||||||
return EdgeIterator( m_nodes[n].firstEdge + m_nodes[n].edges );
|
return EdgeIterator( m_nodes[n].firstEdge + m_nodes[n].edges );
|
||||||
}
|
}
|
||||||
|
|
||||||
//adds an edge. Invalidates edge iterators for the source node
|
//adds an edge. Invalidates edge iterators for the source node
|
||||||
EdgeIterator InsertEdge( const NodeIterator &from, const NodeIterator &to, const EdgeDataT &data )
|
EdgeIterator InsertEdge( const NodeIterator from, const NodeIterator to, const EdgeDataT &data ) {
|
||||||
{
|
|
||||||
Node &node = m_nodes[from];
|
Node &node = m_nodes[from];
|
||||||
EdgeIterator newFirstEdge = node.edges + node.firstEdge;
|
EdgeIterator newFirstEdge = node.edges + node.firstEdge;
|
||||||
if ( newFirstEdge >= m_edges.size() || !isDummy( newFirstEdge ) ) {
|
if ( newFirstEdge >= m_edges.size() || !isDummy( newFirstEdge ) ) {
|
||||||
@@ -136,7 +147,7 @@ class DynamicGraph {
|
|||||||
m_edges[node.firstEdge] = m_edges[node.firstEdge + node.edges];
|
m_edges[node.firstEdge] = m_edges[node.firstEdge + node.edges];
|
||||||
} else {
|
} else {
|
||||||
EdgeIterator newFirstEdge = ( EdgeIterator ) m_edges.size();
|
EdgeIterator newFirstEdge = ( EdgeIterator ) m_edges.size();
|
||||||
unsigned newSize = node.edges * 1.2 + 2;
|
unsigned newSize = node.edges * 1.1 + 2;
|
||||||
EdgeIterator requiredCapacity = newSize + m_edges.size();
|
EdgeIterator requiredCapacity = newSize + m_edges.size();
|
||||||
EdgeIterator oldCapacity = m_edges.capacity();
|
EdgeIterator oldCapacity = m_edges.capacity();
|
||||||
if ( requiredCapacity >= oldCapacity ) {
|
if ( requiredCapacity >= oldCapacity ) {
|
||||||
@@ -147,7 +158,7 @@ class DynamicGraph {
|
|||||||
m_edges[newFirstEdge + i ] = m_edges[node.firstEdge + i];
|
m_edges[newFirstEdge + i ] = m_edges[node.firstEdge + i];
|
||||||
makeDummy( node.firstEdge + i );
|
makeDummy( node.firstEdge + i );
|
||||||
}
|
}
|
||||||
for ( EdgeIterator i = node.edges + 1; i < newSize; i++ )
|
for ( EdgeIterator i = node.edges + 1; i < newSize; ++i )
|
||||||
makeDummy( newFirstEdge + i );
|
makeDummy( newFirstEdge + i );
|
||||||
node.firstEdge = newFirstEdge;
|
node.firstEdge = newFirstEdge;
|
||||||
}
|
}
|
||||||
@@ -155,26 +166,28 @@ class DynamicGraph {
|
|||||||
Edge &edge = m_edges[node.firstEdge + node.edges];
|
Edge &edge = m_edges[node.firstEdge + node.edges];
|
||||||
edge.target = to;
|
edge.target = to;
|
||||||
edge.data = data;
|
edge.data = data;
|
||||||
m_numEdges++;
|
++m_numEdges;
|
||||||
node.edges++;
|
++node.edges;
|
||||||
return EdgeIterator( node.firstEdge + node.edges );
|
return EdgeIterator( node.firstEdge + node.edges );
|
||||||
}
|
}
|
||||||
|
|
||||||
//removes an edge. Invalidates edge iterators for the source node
|
//removes an edge. Invalidates edge iterators for the source node
|
||||||
void DeleteEdge( const NodeIterator source, const EdgeIterator &e ) {
|
void DeleteEdge( const NodeIterator source, const EdgeIterator e ) {
|
||||||
Node &node = m_nodes[source];
|
Node &node = m_nodes[source];
|
||||||
|
#pragma omp atomic
|
||||||
--m_numEdges;
|
--m_numEdges;
|
||||||
--node.edges;
|
--node.edges;
|
||||||
|
BOOST_ASSERT(UINT_MAX != node.edges);
|
||||||
const unsigned last = node.firstEdge + node.edges;
|
const unsigned last = node.firstEdge + node.edges;
|
||||||
|
BOOST_ASSERT( UINT_MAX != last);
|
||||||
//swap with last edge
|
//swap with last edge
|
||||||
m_edges[e] = m_edges[last];
|
m_edges[e] = m_edges[last];
|
||||||
makeDummy( last );
|
makeDummy( last );
|
||||||
}
|
}
|
||||||
|
|
||||||
//removes all edges (source,target)
|
//removes all edges (source,target)
|
||||||
int DeleteEdgesTo( const NodeIterator source, const NodeIterator target )
|
int32_t DeleteEdgesTo( const NodeIterator source, const NodeIterator target ) {
|
||||||
{
|
int32_t deleted = 0;
|
||||||
int deleted = 0;
|
|
||||||
for ( EdgeIterator i = BeginEdges( source ), iend = EndEdges( source ); i < iend - deleted; ++i ) {
|
for ( EdgeIterator i = BeginEdges( source ), iend = EndEdges( source ); i < iend - deleted; ++i ) {
|
||||||
if ( m_edges[i].target == target ) {
|
if ( m_edges[i].target == target ) {
|
||||||
do {
|
do {
|
||||||
@@ -193,10 +206,9 @@ class DynamicGraph {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//searches for a specific edge
|
//searches for a specific edge
|
||||||
EdgeIterator FindEdge( const NodeIterator &from, const NodeIterator &to ) const
|
EdgeIterator FindEdge( const NodeIterator from, const NodeIterator to ) const {
|
||||||
{
|
|
||||||
for ( EdgeIterator i = BeginEdges( from ), iend = EndEdges( from ); i != iend; ++i ) {
|
for ( EdgeIterator i = BeginEdges( from ), iend = EndEdges( from ); i != iend; ++i ) {
|
||||||
if ( m_edges[i].target == to ) {
|
if ( to == m_edges[i].target ) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,13 +217,11 @@ class DynamicGraph {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
bool isDummy( EdgeIterator edge ) const
|
bool isDummy( const EdgeIterator edge ) const {
|
||||||
{
|
|
||||||
return m_edges[edge].target == (std::numeric_limits< NodeIterator >::max)();
|
return m_edges[edge].target == (std::numeric_limits< NodeIterator >::max)();
|
||||||
}
|
}
|
||||||
|
|
||||||
void makeDummy( EdgeIterator edge )
|
void makeDummy( const EdgeIterator edge ) {
|
||||||
{
|
|
||||||
m_edges[edge].target = (std::numeric_limits< NodeIterator >::max)();
|
m_edges[edge].target = (std::numeric_limits< NodeIterator >::max)();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,7 +241,7 @@ class DynamicGraph {
|
|||||||
EdgeIterator m_numEdges;
|
EdgeIterator m_numEdges;
|
||||||
|
|
||||||
std::vector< Node > m_nodes;
|
std::vector< Node > m_nodes;
|
||||||
std::vector< Edge > m_edges;
|
DeallocatingVector< Edge > m_edges;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DYNAMICGRAPH_H_INCLUDED
|
#endif // DYNAMICGRAPH_H_INCLUDED
|
||||||
|
|||||||
@@ -0,0 +1,176 @@
|
|||||||
|
#ifndef EDGE_BASED_NODE_H
|
||||||
|
#define EDGE_BASED_NODE_H
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
#include <boost/assert.hpp>
|
||||||
|
|
||||||
|
#include "../Util/MercatorUtil.h"
|
||||||
|
#include "../typedefs.h"
|
||||||
|
|
||||||
|
#include <osrm/Coordinate.h>
|
||||||
|
|
||||||
|
// An EdgeBasedNode represents a node in the edge-expanded graph.
|
||||||
|
struct EdgeBasedNode {
|
||||||
|
|
||||||
|
EdgeBasedNode() :
|
||||||
|
id(INT_MAX),
|
||||||
|
lat1(INT_MAX),
|
||||||
|
lat2(INT_MAX),
|
||||||
|
lon1(INT_MAX),
|
||||||
|
lon2(INT_MAX >> 1),
|
||||||
|
belongsToTinyComponent(false),
|
||||||
|
nameID(UINT_MAX),
|
||||||
|
weight(UINT_MAX >> 1),
|
||||||
|
ignoreInGrid(false)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
// Computes:
|
||||||
|
// - the distance from the given query location to nearest point on this edge (and returns it)
|
||||||
|
// - the location on this edge which is nearest to the query location
|
||||||
|
// - the ratio ps:pq, where p and q are the end points of this edge, and s is the perpendicular foot of
|
||||||
|
// the query location on the line defined by p and q.
|
||||||
|
double ComputePerpendicularDistance(
|
||||||
|
const FixedPointCoordinate& query_location,
|
||||||
|
FixedPointCoordinate & nearest_location,
|
||||||
|
double & ratio,
|
||||||
|
double precision = COORDINATE_PRECISION
|
||||||
|
) const {
|
||||||
|
BOOST_ASSERT( query_location.isValid() );
|
||||||
|
|
||||||
|
const double epsilon = 1.0/precision;
|
||||||
|
|
||||||
|
if( ignoreInGrid ) {
|
||||||
|
return std::numeric_limits<double>::max();
|
||||||
|
}
|
||||||
|
|
||||||
|
// p, q : the end points of the underlying edge
|
||||||
|
const Point p(lat2y(lat1/COORDINATE_PRECISION), lon1/COORDINATE_PRECISION);
|
||||||
|
const Point q(lat2y(lat2/COORDINATE_PRECISION), lon2/COORDINATE_PRECISION);
|
||||||
|
|
||||||
|
// r : query location
|
||||||
|
const Point r(lat2y(query_location.lat/COORDINATE_PRECISION),
|
||||||
|
query_location.lon/COORDINATE_PRECISION);
|
||||||
|
|
||||||
|
const Point foot = ComputePerpendicularFoot(p, q, r, epsilon);
|
||||||
|
ratio = ComputeRatio(p, q, foot, epsilon);
|
||||||
|
|
||||||
|
BOOST_ASSERT( !std::isnan(ratio) );
|
||||||
|
|
||||||
|
nearest_location = ComputeNearestPointOnSegment(foot, ratio);
|
||||||
|
|
||||||
|
BOOST_ASSERT( nearest_location.isValid() );
|
||||||
|
|
||||||
|
// TODO: Replace with euclidean approximation when k-NN search is done
|
||||||
|
// const double approximated_distance = FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||||
|
const double approximated_distance = FixedPointCoordinate::ApproximateDistance(query_location, nearest_location);
|
||||||
|
|
||||||
|
BOOST_ASSERT( 0.0 <= approximated_distance );
|
||||||
|
return approximated_distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator<(const EdgeBasedNode & other) const {
|
||||||
|
return other.id < id;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const EdgeBasedNode & other) const {
|
||||||
|
return id == other.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the midpoint of the underlying edge.
|
||||||
|
inline FixedPointCoordinate Centroid() const {
|
||||||
|
return FixedPointCoordinate((lat1+lat2)/2, (lon1+lon2)/2);
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeID id;
|
||||||
|
|
||||||
|
// The coordinates of the end-points of the underlying edge.
|
||||||
|
int lat1;
|
||||||
|
int lat2;
|
||||||
|
int lon1;
|
||||||
|
int lon2:31;
|
||||||
|
|
||||||
|
bool belongsToTinyComponent:1;
|
||||||
|
NodeID nameID;
|
||||||
|
|
||||||
|
// The weight of the underlying edge.
|
||||||
|
unsigned weight:31;
|
||||||
|
|
||||||
|
bool ignoreInGrid:1;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
typedef std::pair<double,double> Point;
|
||||||
|
|
||||||
|
// Compute the perpendicular foot of point r on the line defined by p and q.
|
||||||
|
Point ComputePerpendicularFoot(const Point &p, const Point &q, const Point &r, double epsilon) const {
|
||||||
|
|
||||||
|
// the projection of r onto the line pq
|
||||||
|
double foot_x, foot_y;
|
||||||
|
|
||||||
|
const bool is_parallel_to_y_axis = std::abs(q.first - p.first) < epsilon;
|
||||||
|
|
||||||
|
if( is_parallel_to_y_axis ) {
|
||||||
|
foot_x = q.first;
|
||||||
|
foot_y = r.second;
|
||||||
|
} else {
|
||||||
|
// the slope of the line through (a|b) and (c|d)
|
||||||
|
const double m = (q.second - p.second) / (q.first - p.first);
|
||||||
|
|
||||||
|
// Projection of (x|y) onto the line joining (a|b) and (c|d).
|
||||||
|
foot_x = ((r.first + (m*r.second)) + (m*m*p.first - m*p.second))/(1.0 + m*m);
|
||||||
|
foot_y = p.second + m*(foot_x - p.first);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Point(foot_x, foot_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute the ratio of the line segment pr to line segment pq.
|
||||||
|
double ComputeRatio(const Point & p, const Point & q, const Point & r, double epsilon) const {
|
||||||
|
|
||||||
|
const bool is_parallel_to_x_axis = std::abs(q.second-p.second) < epsilon;
|
||||||
|
const bool is_parallel_to_y_axis = std::abs(q.first -p.first ) < epsilon;
|
||||||
|
|
||||||
|
double ratio;
|
||||||
|
|
||||||
|
if( !is_parallel_to_y_axis ) {
|
||||||
|
ratio = (r.first - p.first)/(q.first - p.first);
|
||||||
|
} else if( !is_parallel_to_x_axis ) {
|
||||||
|
ratio = (r.second - p.second)/(q.second - p.second);
|
||||||
|
} else {
|
||||||
|
// (a|b) and (c|d) are essentially the same point
|
||||||
|
// by convention, we set the ratio to 0 in this case
|
||||||
|
//ratio = ((lat2 == query_location.lat) && (lon2 == query_location.lon)) ? 1. : 0.;
|
||||||
|
ratio = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Round to integer if the ratio is close to 0 or 1.
|
||||||
|
if( std::abs(ratio) <= epsilon ) {
|
||||||
|
ratio = 0.0;
|
||||||
|
} else if( std::abs(ratio-1.0) <= epsilon ) {
|
||||||
|
ratio = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ratio;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Computes the point on the segment pq which is nearest to a point r = p + lambda * (q-p).
|
||||||
|
// p and q are the end points of the underlying edge.
|
||||||
|
FixedPointCoordinate ComputeNearestPointOnSegment(const Point & r, double lambda) const {
|
||||||
|
|
||||||
|
if( lambda <= 0.0 ) {
|
||||||
|
return FixedPointCoordinate(lat1, lon1);
|
||||||
|
} else if( lambda >= 1.0 ) {
|
||||||
|
return FixedPointCoordinate(lat2, lon2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// r lies between p and q
|
||||||
|
return FixedPointCoordinate(
|
||||||
|
y2lat(r.first)*COORDINATE_PRECISION,
|
||||||
|
r.second*COORDINATE_PRECISION
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //EDGE_BASED_NODE_H
|
||||||
@@ -1,196 +0,0 @@
|
|||||||
/*
|
|
||||||
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 EXTRACTORCALLBACKS_H_
|
|
||||||
#define EXTRACTORCALLBACKS_H_
|
|
||||||
|
|
||||||
#include <stxxl.h>
|
|
||||||
#include <vector>
|
|
||||||
#include "ExtractorStructs.h"
|
|
||||||
|
|
||||||
typedef stxxl::vector<NodeID> STXXLNodeIDVector;
|
|
||||||
typedef stxxl::vector<_Node> STXXLNodeVector;
|
|
||||||
typedef stxxl::vector<_Edge> STXXLEdgeVector;
|
|
||||||
typedef stxxl::vector<_Address> STXXLAddressVector;
|
|
||||||
typedef stxxl::vector<string> STXXLStringVector;
|
|
||||||
typedef stxxl::vector<_RawRestrictionContainer> STXXLRestrictionsVector;
|
|
||||||
typedef stxxl::vector<_WayIDStartAndEndEdge> STXXLWayIDStartEndVector;
|
|
||||||
|
|
||||||
|
|
||||||
struct STXXLContainers {
|
|
||||||
STXXLNodeIDVector usedNodeIDs;
|
|
||||||
STXXLNodeVector allNodes;
|
|
||||||
STXXLEdgeVector allEdges;
|
|
||||||
STXXLAddressVector adressVector;
|
|
||||||
STXXLStringVector nameVector;
|
|
||||||
STXXLRestrictionsVector restrictionsVector;
|
|
||||||
STXXLWayIDStartEndVector wayStartEndVector;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ExtractorCallbacks{
|
|
||||||
private:
|
|
||||||
Settings settings;
|
|
||||||
StringMap * stringMap;
|
|
||||||
STXXLContainers * externalMemory;
|
|
||||||
|
|
||||||
public:
|
|
||||||
ExtractorCallbacks(STXXLContainers * ext, Settings set, StringMap * strMap){
|
|
||||||
externalMemory = ext;
|
|
||||||
settings = set;
|
|
||||||
stringMap = strMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
~ExtractorCallbacks() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** warning: caller needs to take care of synchronization! */
|
|
||||||
inline bool adressFunction(_Node n, HashTable<std::string, std::string> &keyVals) {
|
|
||||||
/*
|
|
||||||
std::string housenumber(keyVals.Find("addr:housenumber"));
|
|
||||||
std::string housename(keyVals.Find("addr:housename"));
|
|
||||||
std::string street(keyVals.Find("addr:street"));
|
|
||||||
std::string state(keyVals.Find("addr:state"));
|
|
||||||
std::string country(keyVals.Find("addr:country"));
|
|
||||||
std::string postcode(keyVals.Find("addr:postcode"));
|
|
||||||
std::string city(keyVals.Find("addr:city"));
|
|
||||||
|
|
||||||
if(housenumber != "" || housename != "" || street != "") {
|
|
||||||
if(housenumber == "")
|
|
||||||
housenumber = housename;
|
|
||||||
addressVector->push_back(_Address(n, housenumber, street, state, country, postcode, city));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** warning: caller needs to take care of synchronization! */
|
|
||||||
inline bool nodeFunction(_Node &n) {
|
|
||||||
externalMemory->allNodes.push_back(n);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool restrictionFunction(_RawRestrictionContainer &r) {
|
|
||||||
externalMemory->restrictionsVector.push_back(r);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** warning: caller needs to take care of synchronization! */
|
|
||||||
inline bool wayFunction(_Way &w) {
|
|
||||||
|
|
||||||
//Get the properties of the way.
|
|
||||||
std::string highway( w.keyVals.Find("highway") );
|
|
||||||
std::string name( w.keyVals.Find("name") );
|
|
||||||
std::string ref( w.keyVals.Find("ref"));
|
|
||||||
std::string oneway( w.keyVals.Find("oneway"));
|
|
||||||
std::string junction( w.keyVals.Find("junction") );
|
|
||||||
std::string route( w.keyVals.Find("route") );
|
|
||||||
double maxspeed( atoi(w.keyVals.Find("maxspeed").c_str()) );
|
|
||||||
std::string access( w.keyVals.Find("access") );
|
|
||||||
std::string accessClass( w.keyVals.Find(settings.accessTag) );
|
|
||||||
std::string man_made( w.keyVals.Find("man_made") );
|
|
||||||
std::string barrier( w.keyVals.Find("barrier") );
|
|
||||||
|
|
||||||
//Save the name of the way if it has one, ref has precedence over name tag.
|
|
||||||
if ( 0 < ref.length() )
|
|
||||||
w.name = ref;
|
|
||||||
else
|
|
||||||
if ( 0 < name.length() )
|
|
||||||
w.name = name;
|
|
||||||
|
|
||||||
if(junction == "roundabout") {
|
|
||||||
w.roundabout = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Is the highway tag listed as usable way?
|
|
||||||
if(0 < settings[highway]) {
|
|
||||||
|
|
||||||
if(0 != maxspeed)
|
|
||||||
w.speed = maxspeed;
|
|
||||||
else
|
|
||||||
w.speed = settings[highway];
|
|
||||||
w.useful = true;
|
|
||||||
|
|
||||||
//Okay, do we have access to that way?
|
|
||||||
if(0 < access.size()) { //fastest way to check for non-empty string
|
|
||||||
//If access is forbidden, we don't want to route there.
|
|
||||||
if(access == "private" || access == "no" || access == "agricultural" || access == "forestry" || access == "delivery") { //Todo: this is still hard coded
|
|
||||||
w.access = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if("yes" == accessClass)
|
|
||||||
w.access = true;
|
|
||||||
else if("no" == accessClass)
|
|
||||||
w.access = false;
|
|
||||||
|
|
||||||
//Let's process oneway property, if speed profile obeys to it
|
|
||||||
if(oneway != "no" && oneway != "false" && oneway != "0" && settings.obeyOneways) {
|
|
||||||
//if oneway tag is in forward direction or if actually roundabout
|
|
||||||
if(junction == "roundabout" || oneway == "yes" || oneway == "true" || oneway == "1") {
|
|
||||||
w.direction = _Way::oneway;
|
|
||||||
} else {
|
|
||||||
if( oneway == "-1")
|
|
||||||
w.direction = _Way::opposite;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//Is the route tag listed as usable way in the profile?
|
|
||||||
if(settings[route] > 0 || settings[man_made] > 0) {
|
|
||||||
w.useful = true;
|
|
||||||
w.direction = _Way::oneway;
|
|
||||||
w.speed = settings[route];
|
|
||||||
w.direction = _Way::bidirectional;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( w.useful && w.access && (1 < w.path.size()) ) { //Only true if the way is specified by the speed profile
|
|
||||||
//TODO: type is not set, perhaps use a bimap'ed speed profile to do set the type correctly?
|
|
||||||
w.type = 1;
|
|
||||||
|
|
||||||
//Get the unique identifier for the street name
|
|
||||||
StringMap::const_iterator strit = stringMap->find(w.name);
|
|
||||||
if(strit == stringMap->end()) {
|
|
||||||
w.nameID = externalMemory->nameVector.size();
|
|
||||||
externalMemory->nameVector.push_back(w.name);
|
|
||||||
stringMap->insert(StringMap::value_type(w.name, w.nameID));
|
|
||||||
} else {
|
|
||||||
w.nameID = strit->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
GUARANTEE(w.id != UINT_MAX, "found way with unknown type");
|
|
||||||
GUARANTEE(-1 != w.speed, "found way with unknown speed");
|
|
||||||
|
|
||||||
if ( w.direction == _Way::opposite ){
|
|
||||||
std::reverse( w.path.begin(), w.path.end() );
|
|
||||||
}
|
|
||||||
|
|
||||||
for(vector< NodeID >::size_type n = 0; n < w.path.size()-1; ++n) {
|
|
||||||
externalMemory->allEdges.push_back(_Edge(w.path[n], w.path[n+1], w.type, w.direction, w.speed, w.nameID, w.roundabout));
|
|
||||||
externalMemory->usedNodeIDs.push_back(w.path[n]);
|
|
||||||
}
|
|
||||||
externalMemory->usedNodeIDs.push_back(w.path[w.path.size()-1]);
|
|
||||||
|
|
||||||
//The following information is needed to identify start and end segments of restrictions
|
|
||||||
externalMemory->wayStartEndVector.push_back(_WayIDStartAndEndEdge(w.id, w.path[0], w.path[1], w.path[w.path.size()-2], w.path[w.path.size()-1]));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* EXTRACTORCALLBACKS_H_ */
|
|
||||||
@@ -1,359 +0,0 @@
|
|||||||
/*
|
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, 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 EXTRACTORSTRUCTS_H_
|
|
||||||
#define EXTRACTORSTRUCTS_H_
|
|
||||||
|
|
||||||
#include <climits>
|
|
||||||
#include <string>
|
|
||||||
#include <boost/unordered_map.hpp>
|
|
||||||
#include "../typedefs.h"
|
|
||||||
#include "Util.h"
|
|
||||||
|
|
||||||
struct _PathData {
|
|
||||||
_PathData(NodeID no, unsigned na, unsigned tu, unsigned dur) : node(no), nameID(na), durationOfSegment(dur), turnInstruction(tu) { }
|
|
||||||
NodeID node;
|
|
||||||
unsigned nameID;
|
|
||||||
unsigned durationOfSegment;
|
|
||||||
short turnInstruction;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef boost::unordered_map<std::string, NodeID> StringMap;
|
|
||||||
|
|
||||||
struct _Node : NodeInfo{
|
|
||||||
_Node(int _lat, int _lon, unsigned int _id) : NodeInfo(_lat, _lon, _id) {}
|
|
||||||
_Node() {}
|
|
||||||
|
|
||||||
static _Node min_value() {
|
|
||||||
return _Node(0,0,0);
|
|
||||||
}
|
|
||||||
static _Node max_value() {
|
|
||||||
return _Node((numeric_limits<int>::max)(), (numeric_limits<int>::max)(), (numeric_limits<unsigned int>::max)());
|
|
||||||
}
|
|
||||||
NodeID key() const {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _Coordinate {
|
|
||||||
int lat;
|
|
||||||
int lon;
|
|
||||||
_Coordinate () : lat(INT_MIN), lon(INT_MIN) {}
|
|
||||||
_Coordinate (int t, int n) : lat(t) , lon(n) {}
|
|
||||||
void Reset() {
|
|
||||||
lat = INT_MIN;
|
|
||||||
lon = INT_MIN;
|
|
||||||
}
|
|
||||||
bool isSet() const {
|
|
||||||
return (INT_MIN != lat) && (INT_MIN != lon);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
inline ostream & operator<<(ostream & out, const _Coordinate & c){
|
|
||||||
out << "(" << c.lat << "," << c.lon << ")";
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct _Way {
|
|
||||||
_Way() : id(UINT_MAX), nameID(UINT_MAX) {
|
|
||||||
|
|
||||||
direction = _Way::notSure;
|
|
||||||
speed = -1;
|
|
||||||
type = -1;
|
|
||||||
useful = false;
|
|
||||||
access = true;
|
|
||||||
roundabout = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum {
|
|
||||||
notSure = 0, oneway, bidirectional, opposite
|
|
||||||
} direction;
|
|
||||||
unsigned id;
|
|
||||||
unsigned nameID;
|
|
||||||
std::string name;
|
|
||||||
double speed;
|
|
||||||
short type;
|
|
||||||
bool useful;
|
|
||||||
bool access;
|
|
||||||
bool roundabout;
|
|
||||||
std::vector< NodeID > path;
|
|
||||||
HashTable<std::string, std::string> keyVals;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _Address {
|
|
||||||
_Address() {}
|
|
||||||
_Address(_Node n, std::string h, std::string str, std::string sta, std::string p, std::string ci, std::string co) {
|
|
||||||
node = n;
|
|
||||||
housenumber = h;
|
|
||||||
street = str;
|
|
||||||
state = sta;
|
|
||||||
postcode = p;
|
|
||||||
city = ci;
|
|
||||||
country = co;
|
|
||||||
}
|
|
||||||
_Node node;
|
|
||||||
std::string housenumber;
|
|
||||||
std::string street;
|
|
||||||
std::string state;
|
|
||||||
std::string postcode;
|
|
||||||
std::string city;
|
|
||||||
std::string country;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _Relation {
|
|
||||||
_Relation() : type(unknown){}
|
|
||||||
enum {
|
|
||||||
unknown = 0, ferry, turnRestriction
|
|
||||||
} type;
|
|
||||||
HashTable<std::string, std::string> keyVals;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _Edge {
|
|
||||||
_Edge() : start(0), target(0), type(0), direction(0), speed(0), nameID(0), isRoundabout(false) {};
|
|
||||||
_Edge(NodeID s, NodeID t) : start(s), target(t), type(0), direction(0), speed(0), nameID(0), isRoundabout(false) { }
|
|
||||||
_Edge(NodeID s, NodeID t, short tp, short d, double sp): start(s), target(t), type(tp), direction(d), speed(sp), nameID(0), isRoundabout(false) { }
|
|
||||||
_Edge(NodeID s, NodeID t, short tp, short d, double sp, unsigned nid, bool isra): start(s), target(t), type(tp), direction(d), speed(sp), nameID(nid), isRoundabout(isra) { }
|
|
||||||
NodeID start;
|
|
||||||
NodeID target;
|
|
||||||
short type;
|
|
||||||
short direction;
|
|
||||||
double speed;
|
|
||||||
unsigned nameID;
|
|
||||||
bool isRoundabout;
|
|
||||||
|
|
||||||
_Coordinate startCoord;
|
|
||||||
_Coordinate targetCoord;
|
|
||||||
|
|
||||||
static _Edge min_value() {
|
|
||||||
return _Edge(0,0);
|
|
||||||
}
|
|
||||||
static _Edge max_value() {
|
|
||||||
return _Edge((numeric_limits<unsigned>::max)(), (numeric_limits<unsigned>::max)());
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _Restriction {
|
|
||||||
NodeID viaNode;
|
|
||||||
NodeID fromNode;
|
|
||||||
NodeID toNode;
|
|
||||||
struct bits { //mostly unused
|
|
||||||
char isOnly:1;
|
|
||||||
char unused1:1;
|
|
||||||
char unused2:1;
|
|
||||||
char unused3:1;
|
|
||||||
char unused4:1;
|
|
||||||
char unused5:1;
|
|
||||||
char unused6:1;
|
|
||||||
char unused7:1;
|
|
||||||
} flags;
|
|
||||||
|
|
||||||
_Restriction(NodeID vn) : viaNode(vn), fromNode(UINT_MAX), toNode(UINT_MAX) { }
|
|
||||||
_Restriction(bool isOnly = false) : viaNode(UINT_MAX), fromNode(UINT_MAX), toNode(UINT_MAX) {
|
|
||||||
flags.isOnly = isOnly;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
inline bool CmpRestrictionByFrom ( _Restriction a, _Restriction b) { return (a.fromNode < b.fromNode); }
|
|
||||||
|
|
||||||
struct _RawRestrictionContainer {
|
|
||||||
_Restriction restriction;
|
|
||||||
EdgeID fromWay;
|
|
||||||
EdgeID toWay;
|
|
||||||
unsigned viaWay;
|
|
||||||
|
|
||||||
_RawRestrictionContainer(EdgeID f, EdgeID t, NodeID vn, unsigned vw) : fromWay(f), toWay(t), viaWay(vw) { restriction.viaNode = vn;}
|
|
||||||
_RawRestrictionContainer(bool isOnly = false) : fromWay(UINT_MAX), toWay(UINT_MAX), viaWay(UINT_MAX) { restriction.flags.isOnly = isOnly;}
|
|
||||||
|
|
||||||
static _RawRestrictionContainer min_value() {
|
|
||||||
return _RawRestrictionContainer((numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)());
|
|
||||||
}
|
|
||||||
static _RawRestrictionContainer max_value() {
|
|
||||||
return _RawRestrictionContainer((numeric_limits<unsigned>::max)(), (numeric_limits<unsigned>::max)(), (numeric_limits<unsigned>::max)(), (numeric_limits<unsigned>::max)());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CmpRestrictionContainerByFrom: public std::binary_function<_RawRestrictionContainer, _RawRestrictionContainer, bool> {
|
|
||||||
typedef _RawRestrictionContainer value_type;
|
|
||||||
bool operator () (const _RawRestrictionContainer & a, const _RawRestrictionContainer & b) const {
|
|
||||||
return a.fromWay < b.fromWay;
|
|
||||||
}
|
|
||||||
value_type max_value() {
|
|
||||||
return _RawRestrictionContainer::max_value();
|
|
||||||
}
|
|
||||||
value_type min_value() {
|
|
||||||
return _RawRestrictionContainer::min_value();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CmpRestrictionContainerByTo: public std::binary_function<_RawRestrictionContainer, _RawRestrictionContainer, bool> {
|
|
||||||
typedef _RawRestrictionContainer value_type;
|
|
||||||
bool operator () (const _RawRestrictionContainer & a, const _RawRestrictionContainer & b) const {
|
|
||||||
return a.toWay < b.toWay;
|
|
||||||
}
|
|
||||||
value_type max_value() {
|
|
||||||
return _RawRestrictionContainer::max_value();
|
|
||||||
}
|
|
||||||
value_type min_value() {
|
|
||||||
return _RawRestrictionContainer::min_value();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _WayIDStartAndEndEdge {
|
|
||||||
unsigned wayID;
|
|
||||||
NodeID firstStart;
|
|
||||||
NodeID firstTarget;
|
|
||||||
NodeID lastStart;
|
|
||||||
NodeID lastTarget;
|
|
||||||
_WayIDStartAndEndEdge() : wayID(UINT_MAX), firstStart(UINT_MAX), firstTarget(UINT_MAX), lastStart(UINT_MAX), lastTarget(UINT_MAX) {}
|
|
||||||
_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((numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)());
|
|
||||||
}
|
|
||||||
static _WayIDStartAndEndEdge max_value() {
|
|
||||||
return _WayIDStartAndEndEdge((numeric_limits<unsigned>::max)(), (numeric_limits<unsigned>::max)(), (numeric_limits<unsigned>::max)(), (numeric_limits<unsigned>::max)(), (numeric_limits<unsigned>::max)());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CmpWayStartAndEnd : public std::binary_function<_WayIDStartAndEndEdge, _WayIDStartAndEndEdge, bool> {
|
|
||||||
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 Settings {
|
|
||||||
Settings() : obeyPollards(true), obeyOneways(true), useRestrictions(true), accessTag("motorcar") {}
|
|
||||||
StringMap speedProfile;
|
|
||||||
int operator[](const string & param) const {
|
|
||||||
if(speedProfile.find(param) == speedProfile.end())
|
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return speedProfile.at(param);
|
|
||||||
}
|
|
||||||
bool obeyPollards;
|
|
||||||
bool obeyOneways;
|
|
||||||
bool useRestrictions;
|
|
||||||
string accessTag;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Cmp : public std::binary_function<NodeID, NodeID, bool> {
|
|
||||||
typedef NodeID value_type;
|
|
||||||
bool operator () (const NodeID & a, const NodeID & b) const {
|
|
||||||
return a < b;
|
|
||||||
}
|
|
||||||
value_type max_value() {
|
|
||||||
return 0xffffffff;
|
|
||||||
}
|
|
||||||
value_type min_value() {
|
|
||||||
return 0x0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CmpNodeByID : public std::binary_function<_Node, _Node, bool> {
|
|
||||||
typedef _Node value_type;
|
|
||||||
bool operator () (const _Node & a, const _Node & b) const {
|
|
||||||
return a.id < b.id;
|
|
||||||
}
|
|
||||||
value_type max_value() {
|
|
||||||
return _Node::max_value();
|
|
||||||
}
|
|
||||||
value_type min_value() {
|
|
||||||
return _Node::min_value();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CmpEdgeByStartID : public std::binary_function<_Edge, _Edge, bool>
|
|
||||||
{
|
|
||||||
typedef _Edge value_type;
|
|
||||||
bool operator () (const _Edge & a, const _Edge & b) const {
|
|
||||||
return a.start < b.start;
|
|
||||||
}
|
|
||||||
value_type max_value() {
|
|
||||||
return _Edge::max_value();
|
|
||||||
}
|
|
||||||
value_type min_value() {
|
|
||||||
return _Edge::min_value();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CmpEdgeByTargetID : public std::binary_function<_Edge, _Edge, bool>
|
|
||||||
{
|
|
||||||
typedef _Edge value_type;
|
|
||||||
bool operator () (const _Edge & a, const _Edge & b) const
|
|
||||||
{
|
|
||||||
return a.target < b.target;
|
|
||||||
}
|
|
||||||
value_type max_value()
|
|
||||||
{
|
|
||||||
return _Edge::max_value();
|
|
||||||
}
|
|
||||||
value_type min_value()
|
|
||||||
{
|
|
||||||
return _Edge::min_value();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
inline double ApproximateDistance( const int lat1, const int lon1, const int lat2, const int lon2 ) {
|
|
||||||
assert(lat1 != INT_MIN);
|
|
||||||
assert(lon1 != INT_MIN);
|
|
||||||
assert(lat2 != INT_MIN);
|
|
||||||
assert(lon2 != INT_MIN);
|
|
||||||
static const double DEG_TO_RAD = 0.017453292519943295769236907684886;
|
|
||||||
///Earth's quatratic mean radius for WGS-84
|
|
||||||
static const double EARTH_RADIUS_IN_METERS = 6372797.560856;
|
|
||||||
double latitudeArc = ( lat1/100000. - lat2/100000. ) * DEG_TO_RAD;
|
|
||||||
double longitudeArc = ( lon1/100000. - lon2/100000. ) * DEG_TO_RAD;
|
|
||||||
double latitudeH = sin( latitudeArc * 0.5 );
|
|
||||||
latitudeH *= latitudeH;
|
|
||||||
double lontitudeH = sin( longitudeArc * 0.5 );
|
|
||||||
lontitudeH *= lontitudeH;
|
|
||||||
double tmp = cos( lat1/100000. * DEG_TO_RAD ) * cos( lat2/100000. * DEG_TO_RAD );
|
|
||||||
double distanceArc = 2.0 * asin( sqrt( latitudeH + tmp * lontitudeH ) );
|
|
||||||
return EARTH_RADIUS_IN_METERS * distanceArc;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline double ApproximateDistance(const _Coordinate &c1, const _Coordinate &c2) {
|
|
||||||
return ApproximateDistance( c1.lat, c1.lon, c2.lat, c2.lon );
|
|
||||||
}
|
|
||||||
|
|
||||||
inline string GetRandomString() {
|
|
||||||
char s[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 string(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* EXTRACTORSTRUCTS_H_ */
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
/*
|
|
||||||
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 GRIDEDGE_H_
|
|
||||||
#define GRIDEDGE_H_
|
|
||||||
|
|
||||||
struct _GridEdge {
|
|
||||||
_GridEdge(NodeID n, NodeID na, int w, _Coordinate sc, _Coordinate tc) : edgeBasedNode(n), nameID(na), weight(w), startCoord(sc), targetCoord(tc) {}
|
|
||||||
_GridEdge() : edgeBasedNode(UINT_MAX), nameID(UINT_MAX), weight(INT_MAX) {}
|
|
||||||
NodeID edgeBasedNode;
|
|
||||||
NodeID nameID;
|
|
||||||
int weight;
|
|
||||||
_Coordinate startCoord;
|
|
||||||
_Coordinate targetCoord;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct GridEntry {
|
|
||||||
GridEntry() : fileIndex(UINT_MAX), ramIndex(UINT_MAX){}
|
|
||||||
GridEntry(_GridEdge e, unsigned f, unsigned r) : edge(e), fileIndex(f), ramIndex(r) {}
|
|
||||||
_GridEdge edge;
|
|
||||||
unsigned fileIndex;
|
|
||||||
unsigned ramIndex;
|
|
||||||
bool operator< ( const GridEntry& right ) const {
|
|
||||||
return (edge.edgeBasedNode < right.edge.edgeBasedNode);
|
|
||||||
}
|
|
||||||
bool operator==( const GridEntry& right ) const {
|
|
||||||
return right.edge.edgeBasedNode == edge.edgeBasedNode;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CompareGridEdgeDataByFileIndex
|
|
||||||
{
|
|
||||||
bool operator () (const GridEntry & a, const GridEntry & b) const
|
|
||||||
{
|
|
||||||
return a.fileIndex < b.fileIndex;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CompareGridEdgeDataByRamIndex
|
|
||||||
{
|
|
||||||
typedef GridEntry value_type;
|
|
||||||
|
|
||||||
bool operator () (const GridEntry & a, const GridEntry & b) const
|
|
||||||
{
|
|
||||||
return a.ramIndex < b.ramIndex;
|
|
||||||
}
|
|
||||||
value_type max_value()
|
|
||||||
{
|
|
||||||
GridEntry e;
|
|
||||||
e.ramIndex = (1024*1024) - 1;
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
value_type min_value()
|
|
||||||
{
|
|
||||||
GridEntry e;
|
|
||||||
e.ramIndex = 0;
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* GRIDEDGE_H_ */
|
|
||||||
@@ -1,78 +1,68 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, others 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
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
|
Redistributions of source code must retain the above copyright notice, this list
|
||||||
along with this program; if not, write to the Free Software
|
of conditions and the following disclaimer.
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
list of conditions and the following disclaimer in the documentation and/or
|
||||||
|
other materials provided with the distribution.
|
||||||
|
|
||||||
Created on: 18.11.2010
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
Author: dennis
|
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 HASHTABLE_H_
|
*/
|
||||||
#define HASHTABLE_H_
|
|
||||||
|
|
||||||
|
#ifndef HASH_TABLE_H
|
||||||
|
#define HASH_TABLE_H
|
||||||
|
|
||||||
|
#include <boost/ref.hpp>
|
||||||
#include <boost/unordered_map.hpp>
|
#include <boost/unordered_map.hpp>
|
||||||
|
|
||||||
template<typename keyT, typename valueT>
|
template<typename KeyT, typename ValueT>
|
||||||
class HashTable {
|
class HashTable : public boost::unordered_map<KeyT, ValueT> {
|
||||||
typedef boost::unordered_map<keyT, valueT> MyHashTable;
|
private:
|
||||||
|
typedef boost::unordered_map<KeyT, ValueT> super;
|
||||||
public:
|
public:
|
||||||
typedef typename boost::unordered_map<keyT, valueT>::const_iterator MyIterator;
|
static ValueT default_value;
|
||||||
typedef MyIterator iterator;
|
|
||||||
HashTable() { }
|
HashTable() : super() { }
|
||||||
HashTable(const unsigned size) {
|
|
||||||
table.resize(size);
|
HashTable(const unsigned size) : super(size) { }
|
||||||
}
|
|
||||||
void Add(const keyT& key, const valueT& value){
|
inline void Add( KeyT const & key, ValueT const & value) {
|
||||||
table[key] = value;
|
super::emplace(std::make_pair(key, value));
|
||||||
}
|
|
||||||
void Set(const keyT& key, const valueT& value){
|
|
||||||
table[key] = value;
|
|
||||||
}
|
|
||||||
valueT Find(const keyT& key) {
|
|
||||||
if(table.find(key) == table.end())
|
|
||||||
return valueT();
|
|
||||||
return table.find(key)->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Holds(const keyT& key) {
|
inline const ValueT Find(KeyT const & key) const {
|
||||||
if(table.find(key) == table.end())
|
typename super::const_iterator iter = super::find(key);
|
||||||
|
if( iter == super::end() ) {
|
||||||
|
return boost::cref(default_value);
|
||||||
|
}
|
||||||
|
return boost::cref(iter->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool Holds( KeyT const & key) const {
|
||||||
|
if( super::find(key) == super::end() ) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
void EraseAll() {
|
|
||||||
if(table.size() > 0)
|
|
||||||
table.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline
|
|
||||||
valueT & operator[] (keyT key) {
|
|
||||||
return table[key];
|
|
||||||
}
|
|
||||||
unsigned Size() const {
|
|
||||||
return table.size();
|
|
||||||
}
|
|
||||||
MyIterator begin() const {
|
|
||||||
return table.begin();
|
|
||||||
}
|
|
||||||
MyIterator end() const {
|
|
||||||
return table.end();
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
MyHashTable table;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* HASHTABLE_H_ */
|
template<typename KeyT, typename ValueT>
|
||||||
|
ValueT HashTable<KeyT, ValueT>::default_value;
|
||||||
|
|
||||||
|
#endif /* HASH_TABLE_H */
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 "HilbertValue.h"
|
||||||
|
|
||||||
|
uint64_t HilbertCode::operator() (
|
||||||
|
const FixedPointCoordinate & current_coordinate
|
||||||
|
) const {
|
||||||
|
unsigned location[2];
|
||||||
|
location[0] = current_coordinate.lat+( 90*COORDINATE_PRECISION);
|
||||||
|
location[1] = current_coordinate.lon+(180*COORDINATE_PRECISION);
|
||||||
|
|
||||||
|
TransposeCoordinate(location);
|
||||||
|
return BitInterleaving(location[0], location[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t HilbertCode::BitInterleaving(const uint32_t latitude, const uint32_t longitude) const
|
||||||
|
{
|
||||||
|
uint64_t result = 0;
|
||||||
|
for(int8_t index = 31; index >= 0; --index){
|
||||||
|
result |= (latitude >> index) & 1;
|
||||||
|
result <<= 1;
|
||||||
|
result |= (longitude >> index) & 1;
|
||||||
|
if(0 != index){
|
||||||
|
result <<= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HilbertCode::TransposeCoordinate( uint32_t * X) const
|
||||||
|
{
|
||||||
|
uint32_t M = 1 << (32-1), P, Q, t;
|
||||||
|
int i;
|
||||||
|
// Inverse undo
|
||||||
|
for( Q = M; Q > 1; Q >>= 1 ) {
|
||||||
|
P=Q-1;
|
||||||
|
for( i = 0; i < 2; ++i ) {
|
||||||
|
|
||||||
|
const bool condition = (X[i] & Q);
|
||||||
|
if( condition ) {
|
||||||
|
X[0] ^= P; // invert
|
||||||
|
} else {
|
||||||
|
t = (X[0]^X[i]) & P;
|
||||||
|
X[0] ^= t;
|
||||||
|
X[i] ^= t;
|
||||||
|
}
|
||||||
|
} // exchange
|
||||||
|
}
|
||||||
|
// Gray encode
|
||||||
|
for( i = 1; i < 2; ++i ) {
|
||||||
|
X[i] ^= X[i-1];
|
||||||
|
}
|
||||||
|
t=0;
|
||||||
|
for( Q = M; Q > 1; Q >>= 1 ) {
|
||||||
|
const bool condition = (X[2-1] & Q);
|
||||||
|
if( condition ) {
|
||||||
|
t ^= Q-1;
|
||||||
|
}
|
||||||
|
} //check if this for loop is wrong
|
||||||
|
for( i = 0; i < 2; ++i ) {
|
||||||
|
X[i] ^= t;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 HILBERTVALUE_H_
|
||||||
|
#define HILBERTVALUE_H_
|
||||||
|
|
||||||
|
#include <osrm/Coordinate.h>
|
||||||
|
|
||||||
|
#include <boost/integer.hpp>
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
|
|
||||||
|
// computes a 64 bit value that corresponds to the hilbert space filling curve
|
||||||
|
|
||||||
|
class HilbertCode : boost::noncopyable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
uint64_t operator()
|
||||||
|
(
|
||||||
|
const FixedPointCoordinate & current_coordinate
|
||||||
|
) const;
|
||||||
|
private:
|
||||||
|
inline uint64_t BitInterleaving( const uint32_t a, const uint32_t b) const;
|
||||||
|
inline void TransposeCoordinate( uint32_t * X) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* HILBERTVALUE_H_ */
|
||||||
@@ -1,31 +1,41 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, others 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
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.
|
||||||
|
|
||||||
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 EDGE_H
|
#ifndef IMPORT_EDGE_H
|
||||||
#define EDGE_H
|
#define IMPORT_EDGE_H
|
||||||
|
|
||||||
#include <cassert>
|
#include "../Util/OSRMException.h"
|
||||||
|
#include "../typedefs.h"
|
||||||
|
|
||||||
|
#include <boost/assert.hpp>
|
||||||
|
|
||||||
class NodeBasedEdge {
|
class NodeBasedEdge {
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
bool operator< (const NodeBasedEdge& e) const {
|
bool operator< (const NodeBasedEdge& e) const {
|
||||||
if (source() == e.source()) {
|
if (source() == e.source()) {
|
||||||
if (target() == e.target()) {
|
if (target() == e.target()) {
|
||||||
@@ -40,37 +50,70 @@ public:
|
|||||||
return (source() < e.source());
|
return (source() < e.source());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Default constructor. target and weight are set to 0.*/
|
explicit NodeBasedEdge(
|
||||||
NodeBasedEdge() :
|
NodeID s,
|
||||||
_source(0), _target(0), _name(0), _weight(0), forward(0), backward(0), _type(0), _roundabout(false) { assert(false); } //shall not be used.
|
NodeID t,
|
||||||
|
NodeID n,
|
||||||
|
EdgeWeight w,
|
||||||
|
bool f,
|
||||||
|
bool b,
|
||||||
|
short ty,
|
||||||
|
bool ra,
|
||||||
|
bool ig,
|
||||||
|
bool ar,
|
||||||
|
bool cf
|
||||||
|
) : _source(s),
|
||||||
|
_target(t),
|
||||||
|
_name(n),
|
||||||
|
_weight(w),
|
||||||
|
_type(ty),
|
||||||
|
forward(f),
|
||||||
|
backward(b),
|
||||||
|
_roundabout(ra),
|
||||||
|
_ignoreInGrid(ig),
|
||||||
|
_accessRestricted(ar),
|
||||||
|
_contraFlow(cf)
|
||||||
|
{
|
||||||
|
if(ty < 0) {
|
||||||
|
throw OSRMException("negative edge type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
explicit NodeBasedEdge(NodeID s, NodeID t, NodeID n, EdgeWeight w, bool f, bool b, short ty, bool ra) :
|
NodeID target() const {return _target; }
|
||||||
_source(s), _target(t), _name(n), _weight(w), forward(f), backward(b), _type(ty), _roundabout(ra) { assert(ty >= 0); }
|
NodeID source() const {return _source; }
|
||||||
|
NodeID name() const { return _name; }
|
||||||
|
EdgeWeight weight() const {return _weight; }
|
||||||
|
short type() const {
|
||||||
|
BOOST_ASSERT_MSG(_type >= 0, "type of ImportEdge invalid");
|
||||||
|
return _type; }
|
||||||
|
bool isBackward() const { return backward; }
|
||||||
|
bool isForward() const { return forward; }
|
||||||
|
bool isLocatable() const { return _type != 14; }
|
||||||
|
bool isRoundabout() const { return _roundabout; }
|
||||||
|
bool ignoreInGrid() const { return _ignoreInGrid; }
|
||||||
|
bool isAccessRestricted() const { return _accessRestricted; }
|
||||||
|
bool isContraFlow() const { return _contraFlow; }
|
||||||
|
|
||||||
NodeID target() const {return _target; }
|
//TODO: names need to be fixed.
|
||||||
NodeID source() const {return _source; }
|
NodeID _source;
|
||||||
NodeID name() const { return _name; }
|
NodeID _target;
|
||||||
EdgeWeight weight() const {return _weight; }
|
NodeID _name;
|
||||||
|
EdgeWeight _weight;
|
||||||
|
short _type;
|
||||||
|
bool forward:1;
|
||||||
|
bool backward:1;
|
||||||
|
bool _roundabout:1;
|
||||||
|
bool _ignoreInGrid:1;
|
||||||
|
bool _accessRestricted:1;
|
||||||
|
bool _contraFlow:1;
|
||||||
|
|
||||||
short type() const { assert(_type >= 0); return _type; }
|
private:
|
||||||
bool isBackward() const { return backward; }
|
NodeBasedEdge() { }
|
||||||
bool isForward() const { return forward; }
|
|
||||||
bool isLocatable() const { return _type != 14; }
|
|
||||||
bool isRoundabout() const { return _roundabout; }
|
|
||||||
|
|
||||||
NodeID _source;
|
|
||||||
NodeID _target;
|
|
||||||
NodeID _name;
|
|
||||||
EdgeWeight _weight;
|
|
||||||
bool forward;
|
|
||||||
bool backward;
|
|
||||||
short _type;
|
|
||||||
bool _roundabout;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class EdgeBasedEdge {
|
class EdgeBasedEdge {
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
bool operator< (const EdgeBasedEdge& e) const {
|
bool operator< (const EdgeBasedEdge& e) const {
|
||||||
if (source() == e.source()) {
|
if (source() == e.source()) {
|
||||||
if (target() == e.target()) {
|
if (target() == e.target()) {
|
||||||
@@ -87,50 +130,56 @@ public:
|
|||||||
|
|
||||||
template<class EdgeT>
|
template<class EdgeT>
|
||||||
EdgeBasedEdge(const EdgeT & myEdge ) :
|
EdgeBasedEdge(const EdgeT & myEdge ) :
|
||||||
_source(myEdge.source),
|
m_source(myEdge.source),
|
||||||
_target(myEdge.target),
|
m_target(myEdge.target),
|
||||||
_via(myEdge.data.via),
|
m_edgeID(myEdge.data.via),
|
||||||
_nameID1(myEdge.data.nameID),
|
m_weight(myEdge.data.distance),
|
||||||
_weight(myEdge.data.distance),
|
m_forward(myEdge.data.forward),
|
||||||
_forward(myEdge.data.forward),
|
m_backward(myEdge.data.backward)
|
||||||
_backward(myEdge.data.backward),
|
{ }
|
||||||
_turnInstruction(myEdge.data.turnInstruction) { }
|
|
||||||
|
|
||||||
/** Default constructor. target and weight are set to 0.*/
|
/** Default constructor. target and weight are set to 0.*/
|
||||||
EdgeBasedEdge() :
|
EdgeBasedEdge() :
|
||||||
_source(0), _target(0), _via(0), _nameID1(0), _weight(0), _forward(0), _backward(0), _turnInstruction(0) { assert(false); } //shall not be used.
|
m_source(0),
|
||||||
|
m_target(0),
|
||||||
|
m_edgeID(0),
|
||||||
|
m_weight(0),
|
||||||
|
m_forward(false),
|
||||||
|
m_backward(false)
|
||||||
|
{ }
|
||||||
|
|
||||||
explicit EdgeBasedEdge(NodeID s, NodeID t, NodeID v, unsigned n1, EdgeWeight w, bool f, bool b, short ty) :
|
explicit EdgeBasedEdge(
|
||||||
_source(s), _target(t), _via(v), _nameID1(n1), _weight(w), _forward(f), _backward(b), _turnInstruction(ty) { assert(ty >= 0); }
|
const NodeID s,
|
||||||
|
const NodeID t,
|
||||||
|
const NodeID v,
|
||||||
|
const EdgeWeight w,
|
||||||
|
const bool f,
|
||||||
|
const bool b
|
||||||
|
) :
|
||||||
|
m_source(s),
|
||||||
|
m_target(t),
|
||||||
|
m_edgeID(v),
|
||||||
|
m_weight(w),
|
||||||
|
m_forward(f),
|
||||||
|
m_backward(b)
|
||||||
|
{}
|
||||||
|
|
||||||
NodeID target() const {return _target; }
|
NodeID target() const { return m_target; }
|
||||||
NodeID source() const {return _source; }
|
NodeID source() const { return m_source; }
|
||||||
EdgeWeight weight() const {return _weight; }
|
EdgeWeight weight() const { return m_weight; }
|
||||||
NodeID via() const { return _via; }
|
NodeID id() const { return m_edgeID; }
|
||||||
short turnInstruction() const { assert(_turnInstruction >= 0); return _turnInstruction; }
|
bool isBackward() const { return m_backward; }
|
||||||
bool isBackward() const { return _backward; }
|
bool isForward() const { return m_forward; }
|
||||||
bool isForward() const { return _forward; }
|
|
||||||
|
|
||||||
unsigned getNameIDOfTurnTarget() const { return _nameID1; }
|
private:
|
||||||
|
NodeID m_source;
|
||||||
NodeID _source;
|
NodeID m_target;
|
||||||
NodeID _target;
|
NodeID m_edgeID;
|
||||||
NodeID _via;
|
EdgeWeight m_weight:30;
|
||||||
unsigned _nameID1;
|
bool m_forward:1;
|
||||||
EdgeWeight _weight;
|
bool m_backward:1;
|
||||||
bool _forward;
|
|
||||||
bool _backward;
|
|
||||||
short _turnInstruction;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
struct MinimalEdgeData {
|
|
||||||
public:
|
|
||||||
EdgeWeight distance;
|
|
||||||
bool forward;
|
|
||||||
bool backward;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef NodeBasedEdge ImportEdge;
|
typedef NodeBasedEdge ImportEdge;
|
||||||
|
|
||||||
#endif // EDGE_H
|
#endif /* IMPORT_EDGE_H */
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 IMPORTNODE_H_
|
||||||
|
#define IMPORTNODE_H_
|
||||||
|
|
||||||
|
#include "QueryNode.h"
|
||||||
|
#include "../DataStructures/HashTable.h"
|
||||||
|
|
||||||
|
|
||||||
|
struct ExternalMemoryNode : NodeInfo {
|
||||||
|
ExternalMemoryNode(
|
||||||
|
int lat,
|
||||||
|
int lon,
|
||||||
|
unsigned int id,
|
||||||
|
bool bollard,
|
||||||
|
bool traffic_light
|
||||||
|
) :
|
||||||
|
NodeInfo(lat, lon, id),
|
||||||
|
bollard(bollard),
|
||||||
|
trafficLight(traffic_light)
|
||||||
|
{ }
|
||||||
|
ExternalMemoryNode() : bollard(false), trafficLight(false) {}
|
||||||
|
|
||||||
|
static ExternalMemoryNode min_value() {
|
||||||
|
return ExternalMemoryNode(0,0,0, false, false);
|
||||||
|
}
|
||||||
|
static ExternalMemoryNode max_value() {
|
||||||
|
return ExternalMemoryNode(
|
||||||
|
std::numeric_limits<int>::max(),
|
||||||
|
std::numeric_limits<int>::max(),
|
||||||
|
std::numeric_limits<unsigned>::max(),
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
NodeID key() const {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
bool bollard;
|
||||||
|
bool trafficLight;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ImportNode : public ExternalMemoryNode {
|
||||||
|
HashTable<std::string, std::string> keyVals;
|
||||||
|
|
||||||
|
inline void Clear() {
|
||||||
|
keyVals.clear();
|
||||||
|
lat = 0; lon = 0; id = 0; bollard = false; trafficLight = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* IMPORTNODE_H_ */
|
||||||
@@ -1,22 +1,30 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, others 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
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.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
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 INPUTREADERFACTORY_H
|
#ifndef INPUTREADERFACTORY_H
|
||||||
#define INPUTREADERFACTORY_H
|
#define INPUTREADERFACTORY_H
|
||||||
@@ -43,21 +51,21 @@ int readFromBz2Stream( void* pointer, char* buffer, int len ) {
|
|||||||
return read;
|
return read;
|
||||||
} else if(BZ_STREAM_END == context->error) {
|
} else if(BZ_STREAM_END == context->error) {
|
||||||
BZ2_bzReadGetUnused(&context->error, context->bz2, &unusedTmpVoid, &context->nUnused);
|
BZ2_bzReadGetUnused(&context->error, context->bz2, &unusedTmpVoid, &context->nUnused);
|
||||||
if(BZ_OK != context->error) { cerr << "Could not BZ2_bzReadGetUnused" << endl; exit(-1);};
|
if(BZ_OK != context->error) {std::cerr << "Could not BZ2_bzReadGetUnused" <<std::endl; exit(-1);};
|
||||||
unusedTmp = (char*)unusedTmpVoid;
|
unusedTmp = (char*)unusedTmpVoid;
|
||||||
for(int i=0;i<context->nUnused;i++) {
|
for(int i=0;i<context->nUnused;i++) {
|
||||||
context->unused[i] = unusedTmp[i];
|
context->unused[i] = unusedTmp[i];
|
||||||
}
|
}
|
||||||
BZ2_bzReadClose(&context->error, context->bz2);
|
BZ2_bzReadClose(&context->error, context->bz2);
|
||||||
if(BZ_OK != context->error) { cerr << "Could not BZ2_bzReadClose" << endl; exit(-1);};
|
if(BZ_OK != context->error) {std::cerr << "Could not BZ2_bzReadClose" <<std::endl; exit(-1);};
|
||||||
context->error = BZ_STREAM_END; // set to the stream end for next call to this function
|
context->error = BZ_STREAM_END; // set to the stream end for next call to this function
|
||||||
if(0 == context->nUnused && feof(context->file)) {
|
if(0 == context->nUnused && feof(context->file)) {
|
||||||
return read;
|
return read;
|
||||||
} else {
|
} else {
|
||||||
context->bz2 = BZ2_bzReadOpen(&context->error, context->file, 0, 0, context->unused, context->nUnused);
|
context->bz2 = BZ2_bzReadOpen(&context->error, context->file, 0, 0, context->unused, context->nUnused);
|
||||||
if(NULL == context->bz2){ cerr << "Could not open file" << endl; exit(-1);};
|
if(NULL == context->bz2){std::cerr << "Could not open file" <<std::endl; exit(-1);};
|
||||||
}
|
}
|
||||||
} else { cerr << "Could not read bz2 file" << endl; exit(-1); }
|
} else { std::cerr << "Could not read bz2 file" << std::endl; exit(-1); }
|
||||||
}
|
}
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
@@ -74,7 +82,7 @@ xmlTextReaderPtr inputReaderFactory( const char* name )
|
|||||||
{
|
{
|
||||||
std::string inputName(name);
|
std::string inputName(name);
|
||||||
|
|
||||||
if(inputName.find(".osm.bz2")!=string::npos)
|
if(inputName.find(".osm.bz2")!=std::string::npos)
|
||||||
{
|
{
|
||||||
BZ2Context* context = new BZ2Context();
|
BZ2Context* context = new BZ2Context();
|
||||||
context->error = false;
|
context->error = false;
|
||||||
|
|||||||
@@ -1,128 +1,89 @@
|
|||||||
#include <climits>
|
/*
|
||||||
#include <google/sparse_hash_map>
|
|
||||||
#include <iostream>
|
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 LRUCACHE_H
|
||||||
|
#define LRUCACHE_H
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <boost/unordered_map.hpp>
|
||||||
|
|
||||||
template < class T >
|
|
||||||
struct Countfn {
|
|
||||||
unsigned long operator()( const T &x ) { return 1; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template< class Key, class Data, class Sizefn = Countfn< Data > > class LRUCache {
|
|
||||||
public:
|
|
||||||
typedef std::list< std::pair< Key, Data > > List; ///< Main cache storage typedef
|
|
||||||
typedef typename List::iterator List_Iter; ///< Main cache iterator
|
|
||||||
typedef typename List::const_iterator List_cIter; ///< Main cache iterator (const)
|
|
||||||
typedef std::vector< Key > Key_List; ///< List of keys
|
|
||||||
typedef typename Key_List::iterator Key_List_Iter; ///< Main cache iterator
|
|
||||||
typedef typename Key_List::const_iterator Key_List_cIter; ///< Main cache iterator (const)
|
|
||||||
typedef google::sparse_hash_map< Key, List_Iter > Map; ///< Index typedef
|
|
||||||
typedef std::pair< Key, List_Iter > Pair; ///< Pair of Map elements
|
|
||||||
typedef typename Map::iterator Map_Iter; ///< Index iterator
|
|
||||||
typedef typename Map::const_iterator Map_cIter; ///< Index iterator (const)
|
|
||||||
|
|
||||||
|
template<typename KeyT, typename ValueT>
|
||||||
|
class LRUCache {
|
||||||
private:
|
private:
|
||||||
List _list; ///< Main cache storage
|
struct CacheEntry {
|
||||||
Map _index; ///< Cache storage index
|
CacheEntry(KeyT k, ValueT v) : key(k), value(v) {}
|
||||||
unsigned long _max_size; ///< Maximum abstract size of the cache
|
KeyT key;
|
||||||
unsigned long _curr_size; ///< Current abstract size of the cache
|
ValueT value;
|
||||||
|
|
||||||
public:
|
|
||||||
LRUCache( const unsigned long Size ) : _max_size( Size ), _curr_size( 0 ) {
|
|
||||||
_index.set_deleted_key(UINT_MAX);
|
|
||||||
}
|
|
||||||
|
|
||||||
~LRUCache() { clear(); }
|
|
||||||
|
|
||||||
inline const unsigned long size( void ) const { return _curr_size; }
|
|
||||||
|
|
||||||
inline const unsigned long max_size( void ) const { return _max_size; }
|
|
||||||
|
|
||||||
/// Clears all storage and indices.
|
|
||||||
void clear( void ) {
|
|
||||||
_list.clear();
|
|
||||||
_index.clear();
|
|
||||||
};
|
};
|
||||||
|
unsigned capacity;
|
||||||
|
std::list<CacheEntry> itemsInCache;
|
||||||
|
boost::unordered_map<KeyT, typename std::list<CacheEntry>::iterator > positionMap;
|
||||||
|
public:
|
||||||
|
LRUCache(unsigned c) : capacity(c) {}
|
||||||
|
|
||||||
inline bool exists( const Key &key ) const {
|
bool Holds(KeyT key) {
|
||||||
return _index.find( key ) != _index.end();
|
if(positionMap.find(key) != positionMap.end()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void remove( const Key &key ) {
|
void Insert(const KeyT key, ValueT &value) {
|
||||||
Map_Iter miter = _index.find( key );
|
itemsInCache.push_front(CacheEntry(key, value));
|
||||||
if( miter == _index.end() ) return;
|
positionMap.insert(std::make_pair(key, itemsInCache.begin()));
|
||||||
_remove( miter );
|
if(itemsInCache.size() > capacity) {
|
||||||
}
|
positionMap.erase(itemsInCache.back().key);
|
||||||
|
itemsInCache.pop_back();
|
||||||
inline void touch( const Key &key ) {
|
|
||||||
_touch( key );
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Data *fetch_ptr( const Key &key, bool touch = true ) {
|
|
||||||
Map_Iter miter = _index.find( key );
|
|
||||||
if( miter == _index.end() ) return NULL;
|
|
||||||
_touch( key );
|
|
||||||
return &(miter->second->second);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool fetch( const Key &key, Data &data, bool touch_data = true ) {
|
|
||||||
Map_Iter miter = _index.find( key );
|
|
||||||
if( miter == _index.end() ) return false;
|
|
||||||
if( touch_data )
|
|
||||||
_touch( key );
|
|
||||||
data = miter->second->second;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void insert( const Key &key, const Data data ) {
|
|
||||||
// Touch the key, if it exists, then replace the content.
|
|
||||||
Map_Iter miter = _touch( key );
|
|
||||||
if( miter != _index.end() )
|
|
||||||
_remove( miter );
|
|
||||||
|
|
||||||
// Ok, do the actual insert at the head of the list
|
|
||||||
_list.push_front( std::make_pair( key, data ) );
|
|
||||||
List_Iter liter = _list.begin();
|
|
||||||
|
|
||||||
// Store the index
|
|
||||||
_index.insert( std::make_pair( key, liter ) );
|
|
||||||
_curr_size += Sizefn()( data );
|
|
||||||
|
|
||||||
// Check to see if we need to remove an element due to exceeding max_size
|
|
||||||
while( _curr_size > _max_size ) {
|
|
||||||
std::cout << "removing element " << std::endl;
|
|
||||||
// Remove the last element.
|
|
||||||
liter = _list.end();
|
|
||||||
--liter;
|
|
||||||
_remove( liter->first );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const Key_List get_all_keys( void ) {
|
void Insert(const KeyT key, ValueT value) {
|
||||||
Key_List ret;
|
itemsInCache.push_front(CacheEntry(key, value));
|
||||||
for( List_cIter liter = _list.begin(); liter != _list.end(); liter++ )
|
positionMap.insert(std::make_pair(key, itemsInCache.begin()));
|
||||||
ret.push_back( liter->first );
|
if(itemsInCache.size() > capacity) {
|
||||||
return ret;
|
positionMap.erase(itemsInCache.back().key);
|
||||||
|
itemsInCache.pop_back();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
bool Fetch(const KeyT key, ValueT& result) {
|
||||||
inline Map_Iter _touch( const Key &key ) {
|
if(Holds(key)) {
|
||||||
Map_Iter miter = _index.find( key );
|
CacheEntry e = *(positionMap.find(key)->second);
|
||||||
if( miter == _index.end() ) return miter;
|
result = e.value;
|
||||||
// Move the found node to the head of the list.
|
|
||||||
_list.splice( _list.begin(), _list, miter->second );
|
|
||||||
return miter;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void _remove( const Map_Iter &miter ) {
|
//move to front
|
||||||
_curr_size -= Sizefn()( miter->second->second );
|
itemsInCache.splice(positionMap.find(key)->second, itemsInCache, itemsInCache.begin());
|
||||||
_list.erase( miter->second );
|
positionMap.find(key)->second = itemsInCache.begin();
|
||||||
_index.erase( miter );
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
unsigned Size() const {
|
||||||
inline void _remove( const Key &key ) {
|
return itemsInCache.size();
|
||||||
Map_Iter miter = _index.find( key );
|
|
||||||
_remove( miter );
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
#endif //LRUCACHE_H
|
||||||
|
|||||||
@@ -1,635 +0,0 @@
|
|||||||
/*
|
|
||||||
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 NNGRID_H_
|
|
||||||
#define NNGRID_H_
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cassert>
|
|
||||||
#include <cmath>
|
|
||||||
#include <fstream>
|
|
||||||
#include <limits>
|
|
||||||
#include <vector>
|
|
||||||
#include <stxxl.h>
|
|
||||||
#ifdef _OPENMP
|
|
||||||
#include <omp.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include <math.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <boost/thread.hpp>
|
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
#include <google/dense_hash_map>
|
|
||||||
|
|
||||||
#include "ExtractorStructs.h"
|
|
||||||
#include "GridEdge.h"
|
|
||||||
#include "LRUCache.h"
|
|
||||||
#include "Percent.h"
|
|
||||||
#include "PhantomNodes.h"
|
|
||||||
#include "Util.h"
|
|
||||||
#include "StaticGraph.h"
|
|
||||||
|
|
||||||
static const unsigned MAX_CACHE_ELEMENTS = 1000;
|
|
||||||
|
|
||||||
namespace NNGrid{
|
|
||||||
static unsigned GetFileIndexForLatLon(const int lt, const int ln) {
|
|
||||||
double lat = lt/100000.;
|
|
||||||
double lon = ln/100000.;
|
|
||||||
|
|
||||||
double x = ( lon + 180.0 ) / 360.0;
|
|
||||||
double y = ( lat + 180.0 ) / 360.0;
|
|
||||||
|
|
||||||
assert( x<=1.0 && x >= 0);
|
|
||||||
assert( y<=1.0 && y >= 0);
|
|
||||||
|
|
||||||
unsigned line = 1073741824.0*y;
|
|
||||||
line = line - (line % 32768);
|
|
||||||
assert(line % 32768 == 0);
|
|
||||||
unsigned column = 32768.*x;
|
|
||||||
unsigned fileIndex = line+column;
|
|
||||||
return fileIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsigned GetRAMIndexFromFileIndex(const int fileIndex) {
|
|
||||||
unsigned fileLine = fileIndex / 32768;
|
|
||||||
fileLine = fileLine / 32;
|
|
||||||
fileLine = fileLine * 1024;
|
|
||||||
unsigned fileColumn = (fileIndex % 32768);
|
|
||||||
fileColumn = fileColumn / 32;
|
|
||||||
unsigned ramIndex = fileLine + fileColumn;
|
|
||||||
assert(ramIndex < 1024*1024);
|
|
||||||
return ramIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int signum(int x){
|
|
||||||
return (x > 0) ? 1 : (x < 0) ? -1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void GetIndicesByBresenhamsAlgorithm(int xstart,int ystart,int xend,int yend, std::vector<std::pair<unsigned, unsigned> > &indexList) {
|
|
||||||
int x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
|
|
||||||
|
|
||||||
dx = xend - xstart;
|
|
||||||
dy = yend - ystart;
|
|
||||||
|
|
||||||
incx = signum(dx);
|
|
||||||
incy = signum(dy);
|
|
||||||
if(dx<0) dx = -dx;
|
|
||||||
if(dy<0) dy = -dy;
|
|
||||||
|
|
||||||
if (dx>dy) {
|
|
||||||
pdx=incx; pdy=0;
|
|
||||||
ddx=incx; ddy=incy;
|
|
||||||
es =dy; el =dx;
|
|
||||||
} else {
|
|
||||||
pdx=0; pdy=incy;
|
|
||||||
ddx=incx; ddy=incy;
|
|
||||||
es =dx; el =dy;
|
|
||||||
}
|
|
||||||
x = xstart;
|
|
||||||
y = ystart;
|
|
||||||
err = el/2;
|
|
||||||
{
|
|
||||||
int fileIndex = (y-1)*32768 + x;
|
|
||||||
int ramIndex = GetRAMIndexFromFileIndex(fileIndex);
|
|
||||||
indexList.push_back(std::make_pair(fileIndex, ramIndex));
|
|
||||||
}
|
|
||||||
|
|
||||||
for(t=0; t<el; ++t) {
|
|
||||||
err -= es;
|
|
||||||
if(err<0) {
|
|
||||||
err += el;
|
|
||||||
x += ddx;
|
|
||||||
y += ddy;
|
|
||||||
} else {
|
|
||||||
x += pdx;
|
|
||||||
y += pdy;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
int fileIndex = (y-1)*32768 + x;
|
|
||||||
int ramIndex = GetRAMIndexFromFileIndex(fileIndex);
|
|
||||||
indexList.push_back(std::make_pair(fileIndex, ramIndex));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void GetListOfIndexesForEdgeAndGridSize(_Coordinate& start, _Coordinate& target, std::vector<std::pair<unsigned, unsigned> > &indexList) {
|
|
||||||
double lat1 = start.lat/100000.;
|
|
||||||
double lon1 = start.lon/100000.;
|
|
||||||
|
|
||||||
double x1 = ( lon1 + 180.0 ) / 360.0;
|
|
||||||
double y1 = ( lat1 + 180.0 ) / 360.0;
|
|
||||||
|
|
||||||
double lat2 = target.lat/100000.;
|
|
||||||
double lon2 = target.lon/100000.;
|
|
||||||
|
|
||||||
double x2 = ( lon2 + 180.0 ) / 360.0;
|
|
||||||
double y2 = ( lat2 + 180.0 ) / 360.0;
|
|
||||||
|
|
||||||
GetIndicesByBresenhamsAlgorithm(x1*32768, y1*32768, x2*32768, y2*32768, indexList);
|
|
||||||
}
|
|
||||||
|
|
||||||
static boost::thread_specific_ptr<std::ifstream> localStream;
|
|
||||||
|
|
||||||
template<bool WriteAccess = false>
|
|
||||||
class NNGrid {
|
|
||||||
public:
|
|
||||||
NNGrid() /*: cellCache(500), fileCache(500)*/ {
|
|
||||||
ramIndexTable.resize((1024*1024), UINT_MAX);
|
|
||||||
if( WriteAccess) {
|
|
||||||
entries = new stxxl::vector<GridEntry>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NNGrid(const char* rif, const char* _i, unsigned numberOfThreads = omp_get_num_procs()) /*: cellCache(500), fileCache(500) */{
|
|
||||||
if(WriteAccess) {
|
|
||||||
ERR("Not available in Write mode");
|
|
||||||
}
|
|
||||||
iif = std::string(_i);
|
|
||||||
ramIndexTable.resize((1024*1024), UINT_MAX);
|
|
||||||
ramInFile.open(rif, std::ios::in | std::ios::binary);
|
|
||||||
entries = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
~NNGrid() {
|
|
||||||
if(ramInFile.is_open()) ramInFile.close();
|
|
||||||
|
|
||||||
if (WriteAccess) {
|
|
||||||
delete entries;
|
|
||||||
}
|
|
||||||
if(localStream.get() && localStream->is_open()) {
|
|
||||||
localStream->close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenIndexFiles() {
|
|
||||||
assert(ramInFile.is_open());
|
|
||||||
|
|
||||||
for(int i = 0; i < 1024*1024; ++i) {
|
|
||||||
unsigned temp;
|
|
||||||
ramInFile.read((char*)&temp, sizeof(unsigned));
|
|
||||||
ramIndexTable[i] = temp;
|
|
||||||
}
|
|
||||||
ramInFile.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename EdgeT, typename NodeInfoT>
|
|
||||||
void ConstructGrid(std::vector<EdgeT> & edgeList, vector<NodeInfoT> * int2ExtNodeMap, char * ramIndexOut, char * fileIndexOut) {
|
|
||||||
Percent p(edgeList.size());
|
|
||||||
for(NodeID i = 0; i < edgeList.size(); ++i) {
|
|
||||||
p.printIncrement();
|
|
||||||
EdgeT & edge = edgeList[i];
|
|
||||||
|
|
||||||
int slat = 100000*lat2y(edge.lat1/100000.);
|
|
||||||
int slon = edge.lon1;
|
|
||||||
int tlat = 100000*lat2y(edge.lat2/100000.);
|
|
||||||
int tlon = edge.lon2;
|
|
||||||
AddEdge( _GridEdge(
|
|
||||||
edge.id, edge.nameID, edge.weight,
|
|
||||||
_Coordinate(slat, slon),
|
|
||||||
_Coordinate(tlat, tlon) )
|
|
||||||
);
|
|
||||||
}
|
|
||||||
double timestamp = get_timestamp();
|
|
||||||
//create index file on disk, old one is over written
|
|
||||||
indexOutFile.open(fileIndexOut, std::ios::out | std::ios::binary | std::ios::trunc);
|
|
||||||
cout << "sorting grid data consisting of " << entries->size() << " edges..." << flush;
|
|
||||||
//sort entries
|
|
||||||
stxxl::sort(entries->begin(), entries->end(), CompareGridEdgeDataByRamIndex(), 1024*1024*1024);
|
|
||||||
cout << "ok in " << (get_timestamp() - timestamp) << "s" << endl;
|
|
||||||
std::vector<GridEntry> entriesInFileWithRAMSameIndex;
|
|
||||||
unsigned indexInRamTable = entries->begin()->ramIndex;
|
|
||||||
unsigned lastPositionInIndexFile = 0;
|
|
||||||
unsigned numberOfUsedCells = 0;
|
|
||||||
unsigned maxNumberOfRAMCellElements = 0;
|
|
||||||
cout << "writing data ..." << flush;
|
|
||||||
p.reinit(entries->size());
|
|
||||||
for(stxxl::vector<GridEntry>::iterator vt = entries->begin(); vt != entries->end(); ++vt) {
|
|
||||||
p.printIncrement();
|
|
||||||
if(vt->ramIndex != indexInRamTable) {
|
|
||||||
unsigned numberOfBytesInCell = FillCell(entriesInFileWithRAMSameIndex, lastPositionInIndexFile);
|
|
||||||
if(entriesInFileWithRAMSameIndex.size() > maxNumberOfRAMCellElements)
|
|
||||||
maxNumberOfRAMCellElements = entriesInFileWithRAMSameIndex.size();
|
|
||||||
|
|
||||||
ramIndexTable[indexInRamTable] = lastPositionInIndexFile;
|
|
||||||
lastPositionInIndexFile += numberOfBytesInCell;
|
|
||||||
entriesInFileWithRAMSameIndex.clear();
|
|
||||||
indexInRamTable = vt->ramIndex;
|
|
||||||
numberOfUsedCells++;
|
|
||||||
}
|
|
||||||
entriesInFileWithRAMSameIndex.push_back(*vt);
|
|
||||||
}
|
|
||||||
/*unsigned numberOfBytesInCell = */FillCell(entriesInFileWithRAMSameIndex, lastPositionInIndexFile);
|
|
||||||
ramIndexTable[indexInRamTable] = lastPositionInIndexFile;
|
|
||||||
numberOfUsedCells++;
|
|
||||||
entriesInFileWithRAMSameIndex.clear();
|
|
||||||
|
|
||||||
assert(entriesInFileWithRAMSameIndex.size() == 0);
|
|
||||||
|
|
||||||
for(int i = 0; i < 1024*1024; ++i) {
|
|
||||||
if(ramIndexTable[i] != UINT_MAX) {
|
|
||||||
numberOfUsedCells--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assert(numberOfUsedCells == 0);
|
|
||||||
|
|
||||||
//close index file
|
|
||||||
indexOutFile.close();
|
|
||||||
//Serialize RAM Index
|
|
||||||
ofstream ramFile(ramIndexOut, std::ios::out | std::ios::binary | std::ios::trunc);
|
|
||||||
//write 4 MB of index Table in RAM
|
|
||||||
for(int i = 0; i < 1024*1024; ++i)
|
|
||||||
ramFile.write((char *)&ramIndexTable[i], sizeof(unsigned) );
|
|
||||||
//close ram index file
|
|
||||||
ramFile.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GetEdgeBasedStartNode(const _Coordinate& coord, NodesOfEdge& nodesOfEdge) {
|
|
||||||
_Coordinate startCoord(100000*(lat2y(static_cast<double>(coord.lat)/100000.)), coord.lon);
|
|
||||||
/** search for point on edge next to source */
|
|
||||||
unsigned fileIndex = GetFileIndexForLatLon(startCoord.lat, startCoord.lon);
|
|
||||||
std::vector<_GridEdge> candidates;
|
|
||||||
|
|
||||||
for(int j = -32768; j < (32768+1); j+=32768) {
|
|
||||||
for(int i = -1; i < 2; i++){
|
|
||||||
GetContentsOfFileBucket(fileIndex+i+j, candidates);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_Coordinate tmp;
|
|
||||||
double dist = numeric_limits<double>::max();
|
|
||||||
BOOST_FOREACH(_GridEdge candidate, candidates) {
|
|
||||||
double r = 0.;
|
|
||||||
double tmpDist = ComputeDistance(startCoord, candidate.startCoord, candidate.targetCoord, tmp, &r);
|
|
||||||
if(tmpDist < dist) {
|
|
||||||
nodesOfEdge.edgeBasedNode = candidate.edgeBasedNode;
|
|
||||||
nodesOfEdge.ratio = r;
|
|
||||||
dist = tmpDist;
|
|
||||||
nodesOfEdge.projectedPoint.lat = round(100000*(y2lat(static_cast<double>(tmp.lat)/100000.)));
|
|
||||||
nodesOfEdge.projectedPoint.lon = tmp.lon;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(dist != (numeric_limits<double>::max)()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FindPhantomNodeForCoordinate( const _Coordinate & location, PhantomNode & resultNode) {
|
|
||||||
bool foundNode = false;
|
|
||||||
_Coordinate startCoord(100000*(lat2y(static_cast<double>(location.lat)/100000.)), location.lon);
|
|
||||||
/** search for point on edge close to source */
|
|
||||||
unsigned fileIndex = GetFileIndexForLatLon(startCoord.lat, startCoord.lon);
|
|
||||||
std::vector<_GridEdge> candidates;
|
|
||||||
|
|
||||||
for(int j = -32768; j < (32768+1); j+=32768) {
|
|
||||||
for(int i = -1; i < 2; i++){
|
|
||||||
GetContentsOfFileBucket(fileIndex+i+j, candidates);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_GridEdge smallestEdge;
|
|
||||||
_Coordinate tmp, newEndpoint;
|
|
||||||
double dist = (numeric_limits<double>::max)();
|
|
||||||
BOOST_FOREACH(_GridEdge candidate, candidates) {
|
|
||||||
double r = 0.;
|
|
||||||
double tmpDist = ComputeDistance(startCoord, candidate.startCoord, candidate.targetCoord, tmp, &r);
|
|
||||||
if(DoubleEpsilonCompare(dist, tmpDist) && 1 == std::abs((int)candidate.edgeBasedNode-(int)resultNode.edgeBasedNode)) {
|
|
||||||
resultNode.weight2 = candidate.weight;
|
|
||||||
/* if(resultNode.weight1 != resultNode.weight2) {
|
|
||||||
ERR("w1: " << resultNode.weight1 << ", w2: " << resultNode.weight2);
|
|
||||||
assert(false);
|
|
||||||
}*/
|
|
||||||
if(candidate.edgeBasedNode < resultNode.edgeBasedNode) {
|
|
||||||
resultNode.edgeBasedNode = candidate.edgeBasedNode;
|
|
||||||
std::swap(resultNode.weight1, resultNode.weight2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(tmpDist < dist) {
|
|
||||||
resultNode.Reset();
|
|
||||||
resultNode.edgeBasedNode = candidate.edgeBasedNode;
|
|
||||||
resultNode.nodeBasedEdgeNameID = candidate.nameID;
|
|
||||||
resultNode.weight1 = candidate.weight;
|
|
||||||
dist = tmpDist;
|
|
||||||
resultNode.location.lat = round(100000*(y2lat(static_cast<double>(tmp.lat)/100000.)));
|
|
||||||
resultNode.location.lon = tmp.lon;
|
|
||||||
foundNode = true;
|
|
||||||
smallestEdge = candidate;
|
|
||||||
newEndpoint = tmp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// INFO("startcoord: " << smallestEdge.startCoord << ", tgtcoord" << smallestEdge.targetCoord << "result: " << newEndpoint);
|
|
||||||
// INFO("length of old edge: " << LengthOfVector(smallestEdge.startCoord, smallestEdge.targetCoord));
|
|
||||||
// INFO("Length of new edge: " << LengthOfVector(smallestEdge.startCoord, newEndpoint));
|
|
||||||
// assert(!resultNode.isBidirected || (resultNode.weight1 == resultNode.weight2));
|
|
||||||
// if(resultNode.weight1 != resultNode.weight2) {
|
|
||||||
// INFO("-> Weight1: " << resultNode.weight1 << ", weight2: " << resultNode.weight2);
|
|
||||||
// INFO("-> node: " << resultNode.edgeBasedNode << ", bidir: " << (resultNode.isBidirected ? "yes" : "no"));
|
|
||||||
// }
|
|
||||||
|
|
||||||
double ratio = std::min(1., LengthOfVector(smallestEdge.startCoord, newEndpoint)/LengthOfVector(smallestEdge.startCoord, smallestEdge.targetCoord) );
|
|
||||||
assert(ratio >= 0 && ratio <=1);
|
|
||||||
// INFO("Old weight1: " << resultNode.weight1 << ", old weight2: " << resultNode.weight2);
|
|
||||||
resultNode.weight1 *= ratio;
|
|
||||||
if(INT_MAX != resultNode.weight2) {
|
|
||||||
resultNode.weight2 *= (1-ratio);
|
|
||||||
// INFO("New weight1: " << resultNode.weight1 << ", new weight2: " << resultNode.weight2);
|
|
||||||
}
|
|
||||||
return foundNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FindRoutingStarts(const _Coordinate& start, const _Coordinate& target, PhantomNodes & routingStarts) {
|
|
||||||
routingStarts.Reset();
|
|
||||||
return (FindPhantomNodeForCoordinate( start, routingStarts.startPhantom) &&
|
|
||||||
FindPhantomNodeForCoordinate( target, routingStarts.targetPhantom) );
|
|
||||||
}
|
|
||||||
|
|
||||||
void FindNearestCoordinateOnEdgeInNodeBasedGraph(const _Coordinate& inputCoordinate, _Coordinate& outputCoordinate) {
|
|
||||||
unsigned fileIndex = GetFileIndexForLatLon(100000*(lat2y(static_cast<double>(inputCoordinate.lat)/100000.)), inputCoordinate.lon);
|
|
||||||
std::vector<_GridEdge> candidates;
|
|
||||||
for(int j = -32768; j < (32768+1); j+=32768) {
|
|
||||||
for(int i = -1; i < 2; i++) {
|
|
||||||
GetContentsOfFileBucket(fileIndex+i+j, candidates);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_Coordinate tmp;
|
|
||||||
double dist = (numeric_limits<double>::max)();
|
|
||||||
BOOST_FOREACH(_GridEdge candidate, candidates) {
|
|
||||||
double r = 0.;
|
|
||||||
double tmpDist = ComputeDistance(inputCoordinate, candidate.startCoord, candidate.targetCoord, tmp, &r);
|
|
||||||
if(tmpDist < dist) {
|
|
||||||
dist = tmpDist;
|
|
||||||
outputCoordinate = tmp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
outputCoordinate.lat = 100000*(y2lat(static_cast<double>(outputCoordinate.lat)/100000.));
|
|
||||||
}
|
|
||||||
|
|
||||||
void FindNearestPointOnEdge(const _Coordinate& inputCoordinate, _Coordinate& outputCoordinate) {
|
|
||||||
_Coordinate startCoord(100000*(lat2y(static_cast<double>(inputCoordinate.lat)/100000.)), inputCoordinate.lon);
|
|
||||||
unsigned fileIndex = GetFileIndexForLatLon(startCoord.lat, startCoord.lon);
|
|
||||||
|
|
||||||
std::vector<_GridEdge> candidates;
|
|
||||||
for(int j = -32768; j < (32768+1); j+=32768) {
|
|
||||||
for(int i = -1; i < 2; i++) {
|
|
||||||
GetContentsOfFileBucket(fileIndex+i+j, candidates);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_Coordinate tmp;
|
|
||||||
double dist = (numeric_limits<double>::max)();
|
|
||||||
BOOST_FOREACH(_GridEdge candidate, candidates) {
|
|
||||||
double r = 0.;
|
|
||||||
double tmpDist = ComputeDistance(startCoord, candidate.startCoord, candidate.targetCoord, tmp, &r);
|
|
||||||
if(tmpDist < dist) {
|
|
||||||
dist = tmpDist;
|
|
||||||
outputCoordinate.lat = round(100000*(y2lat(static_cast<double>(tmp.lat)/100000.)));
|
|
||||||
outputCoordinate.lon = tmp.lon;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
inline double LengthOfVector(const _Coordinate & c1, const _Coordinate & c2) {
|
|
||||||
double length1 = std::sqrt(c1.lat/100000.*c1.lat/100000. + c1.lon/100000.*c1.lon/100000.);
|
|
||||||
double length2 = std::sqrt(c2.lat/100000.*c2.lat/100000. + c2.lon/100000.*c2.lon/100000.);
|
|
||||||
return std::fabs(length1-length2);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool DoubleEpsilonCompare(const double d1, const double d2) {
|
|
||||||
return (std::fabs(d1 - d2) < 0.000000001);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned FillCell(std::vector<GridEntry>& entriesWithSameRAMIndex, unsigned fileOffset ) {
|
|
||||||
vector<char> * tmpBuffer = new vector<char>();
|
|
||||||
tmpBuffer->resize(32*32*4096,0);
|
|
||||||
unsigned indexIntoTmpBuffer = 0;
|
|
||||||
unsigned numberOfWrittenBytes = 0;
|
|
||||||
assert(indexOutFile.is_open());
|
|
||||||
|
|
||||||
vector<unsigned> cellIndex;
|
|
||||||
cellIndex.resize(32*32,UINT_MAX);
|
|
||||||
google::dense_hash_map< unsigned, unsigned > * cellMap = new google::dense_hash_map< unsigned, unsigned >(1024);
|
|
||||||
cellMap->set_empty_key(UINT_MAX);
|
|
||||||
|
|
||||||
unsigned ramIndex = entriesWithSameRAMIndex.begin()->ramIndex;
|
|
||||||
unsigned lineBase = ramIndex/1024;
|
|
||||||
lineBase = lineBase*32*32768;
|
|
||||||
unsigned columnBase = ramIndex%1024;
|
|
||||||
columnBase=columnBase*32;
|
|
||||||
|
|
||||||
for(int i = 0; i < 32; i++) {
|
|
||||||
for(int j = 0; j < 32; j++) {
|
|
||||||
unsigned fileIndex = lineBase + i*32768 + columnBase+j;
|
|
||||||
unsigned cellIndex = i*32+j;
|
|
||||||
cellMap->insert(std::make_pair(fileIndex, cellIndex));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(unsigned i = 0; i < entriesWithSameRAMIndex.size() -1; ++i) {
|
|
||||||
assert(entriesWithSameRAMIndex[i].ramIndex== entriesWithSameRAMIndex[i+1].ramIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
//sort & unique
|
|
||||||
std::sort(entriesWithSameRAMIndex.begin(), entriesWithSameRAMIndex.end(), CompareGridEdgeDataByFileIndex());
|
|
||||||
std::vector<GridEntry>::iterator uniqueEnd = std::unique(entriesWithSameRAMIndex.begin(), entriesWithSameRAMIndex.end());
|
|
||||||
|
|
||||||
//traverse each file bucket and write its contents to disk
|
|
||||||
std::vector<GridEntry> entriesWithSameFileIndex;
|
|
||||||
unsigned fileIndex = entriesWithSameRAMIndex.begin()->fileIndex;
|
|
||||||
|
|
||||||
for(std::vector<GridEntry>::iterator it = entriesWithSameRAMIndex.begin(); it != uniqueEnd; it++) {
|
|
||||||
assert(cellMap->find(it->fileIndex) != cellMap->end() ); //asserting that file index belongs to cell index
|
|
||||||
if(it->fileIndex != fileIndex) {
|
|
||||||
// start in cellIndex vermerken
|
|
||||||
int localFileIndex = entriesWithSameFileIndex.begin()->fileIndex;
|
|
||||||
int localCellIndex = cellMap->find(localFileIndex)->second;
|
|
||||||
/*int localRamIndex = */GetRAMIndexFromFileIndex(localFileIndex);
|
|
||||||
assert(cellMap->find(entriesWithSameFileIndex.begin()->fileIndex) != cellMap->end());
|
|
||||||
|
|
||||||
cellIndex[localCellIndex] = indexIntoTmpBuffer + fileOffset;
|
|
||||||
indexIntoTmpBuffer += FlushEntriesWithSameFileIndexToBuffer(entriesWithSameFileIndex, tmpBuffer, indexIntoTmpBuffer);
|
|
||||||
}
|
|
||||||
GridEntry data = *it;
|
|
||||||
entriesWithSameFileIndex.push_back(data);
|
|
||||||
fileIndex = it->fileIndex;
|
|
||||||
}
|
|
||||||
assert(cellMap->find(entriesWithSameFileIndex.begin()->fileIndex) != cellMap->end());
|
|
||||||
int localFileIndex = entriesWithSameFileIndex.begin()->fileIndex;
|
|
||||||
int localCellIndex = cellMap->find(localFileIndex)->second;
|
|
||||||
/*int localRamIndex = */GetRAMIndexFromFileIndex(localFileIndex);
|
|
||||||
|
|
||||||
cellIndex[localCellIndex] = indexIntoTmpBuffer + fileOffset;
|
|
||||||
indexIntoTmpBuffer += FlushEntriesWithSameFileIndexToBuffer(entriesWithSameFileIndex, tmpBuffer, indexIntoTmpBuffer);
|
|
||||||
|
|
||||||
assert(entriesWithSameFileIndex.size() == 0);
|
|
||||||
|
|
||||||
for(int i = 0; i < 32*32; i++) {
|
|
||||||
indexOutFile.write((char *)&cellIndex[i], sizeof(unsigned));
|
|
||||||
numberOfWrittenBytes += sizeof(unsigned);
|
|
||||||
}
|
|
||||||
|
|
||||||
//write contents of tmpbuffer to disk
|
|
||||||
for(unsigned i = 0; i < indexIntoTmpBuffer; i++) {
|
|
||||||
indexOutFile.write(&(tmpBuffer->at(i)), sizeof(char));
|
|
||||||
numberOfWrittenBytes += sizeof(char);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete tmpBuffer;
|
|
||||||
delete cellMap;
|
|
||||||
return numberOfWrittenBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned FlushEntriesWithSameFileIndexToBuffer( std::vector<GridEntry> &vectorWithSameFileIndex, vector<char> * tmpBuffer, const unsigned index) {
|
|
||||||
tmpBuffer->resize(tmpBuffer->size()+(sizeof(_GridEdge)*vectorWithSameFileIndex.size()) );
|
|
||||||
unsigned counter = 0;
|
|
||||||
unsigned max = UINT_MAX;
|
|
||||||
|
|
||||||
for(unsigned i = 0; i < vectorWithSameFileIndex.size()-1; i++) {
|
|
||||||
assert( vectorWithSameFileIndex[i].fileIndex == vectorWithSameFileIndex[i+1].fileIndex );
|
|
||||||
assert( vectorWithSameFileIndex[i].ramIndex == vectorWithSameFileIndex[i+1].ramIndex );
|
|
||||||
}
|
|
||||||
|
|
||||||
sort( vectorWithSameFileIndex.begin(), vectorWithSameFileIndex.end() );
|
|
||||||
vectorWithSameFileIndex.erase(unique(vectorWithSameFileIndex.begin(), vectorWithSameFileIndex.end()), vectorWithSameFileIndex.end());
|
|
||||||
BOOST_FOREACH(GridEntry entry, vectorWithSameFileIndex) {
|
|
||||||
char * data = (char *)&(entry.edge);
|
|
||||||
for(unsigned i = 0; i < sizeof(_GridEdge); ++i) {
|
|
||||||
tmpBuffer->at(index+counter) = data[i];
|
|
||||||
++counter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
char * umax = (char *) &max;
|
|
||||||
for(unsigned i = 0; i < sizeof(unsigned); i++) {
|
|
||||||
tmpBuffer->at(index+counter) = umax[i];
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
vectorWithSameFileIndex.clear();
|
|
||||||
std::vector<GridEntry>().swap(vectorWithSameFileIndex);
|
|
||||||
return counter;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GetContentsOfFileBucket(const unsigned fileIndex, std::vector<_GridEdge>& result) {
|
|
||||||
unsigned ramIndex = GetRAMIndexFromFileIndex(fileIndex);
|
|
||||||
unsigned startIndexInFile = ramIndexTable[ramIndex];
|
|
||||||
if(startIndexInFile == UINT_MAX) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<unsigned> cellIndex;
|
|
||||||
cellIndex.resize(32*32);
|
|
||||||
google::dense_hash_map< unsigned, unsigned > cellMap(1024);
|
|
||||||
cellMap.set_empty_key(UINT_MAX);
|
|
||||||
|
|
||||||
unsigned lineBase = ramIndex/1024;
|
|
||||||
lineBase = lineBase*32*32768;
|
|
||||||
unsigned columnBase = ramIndex%1024;
|
|
||||||
columnBase=columnBase*32;
|
|
||||||
|
|
||||||
for(int i = 0; i < 32; i++) {
|
|
||||||
for(int j = 0; j < 32; j++) {
|
|
||||||
unsigned fileIndex = lineBase + i*32768 + columnBase+j;
|
|
||||||
unsigned cellIndex = i*32+j;
|
|
||||||
cellMap.insert(std::make_pair(fileIndex, cellIndex));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!localStream.get() || !localStream->is_open()) {
|
|
||||||
localStream.reset(new std::ifstream(iif.c_str(), std::ios::in | std::ios::binary));
|
|
||||||
}
|
|
||||||
localStream->seekg(startIndexInFile);
|
|
||||||
localStream->read((char*) &cellIndex[0], 32*32*sizeof(unsigned));
|
|
||||||
assert(cellMap.find(fileIndex) != cellMap.end());
|
|
||||||
if(cellIndex[cellMap.find(fileIndex)->second] == UINT_MAX) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const unsigned position = cellIndex[cellMap.find(fileIndex)->second] + 32*32*sizeof(unsigned) ;
|
|
||||||
|
|
||||||
localStream->seekg(position);
|
|
||||||
_GridEdge gridEdge;
|
|
||||||
do {
|
|
||||||
localStream->read((char *)&(gridEdge), sizeof(_GridEdge));
|
|
||||||
if(localStream->eof() || gridEdge.edgeBasedNode == UINT_MAX)
|
|
||||||
break;
|
|
||||||
result.push_back(gridEdge);
|
|
||||||
} while(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AddEdge(_GridEdge edge) {
|
|
||||||
std::vector<std::pair<unsigned, unsigned> > indexList;
|
|
||||||
GetListOfIndexesForEdgeAndGridSize(edge.startCoord, edge.targetCoord, indexList);
|
|
||||||
for(unsigned i = 0; i < indexList.size(); ++i) {
|
|
||||||
entries->push_back(GridEntry(edge, indexList[i].first, indexList[i].second));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double ComputeDistance(const _Coordinate& inputPoint, const _Coordinate& source, const _Coordinate& target, _Coordinate& nearest, double *r) {
|
|
||||||
|
|
||||||
const double x = (double)inputPoint.lat;
|
|
||||||
const double y = (double)inputPoint.lon;
|
|
||||||
const double a = (double)source.lat;
|
|
||||||
const double b = (double)source.lon;
|
|
||||||
const double c = (double)target.lat;
|
|
||||||
const double d = (double)target.lon;
|
|
||||||
double p,q,mX,nY;
|
|
||||||
if(c != a){
|
|
||||||
const double m = (d-b)/(c-a); // slope
|
|
||||||
// Projection of (x,y) on line joining (a,b) and (c,d)
|
|
||||||
p = ((x + (m*y)) + (m*m*a - m*b))/(1 + m*m);
|
|
||||||
q = b + m*(p - a);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
p = c;
|
|
||||||
q = y;
|
|
||||||
}
|
|
||||||
nY = (d*p - c*q)/(a*d - b*c);
|
|
||||||
mX = (p - nY*a)/c;// These values are actually n/m+n and m/m+n , we neednot calculate the values of m an n as we are just interested in the ratio
|
|
||||||
*r = mX;
|
|
||||||
if(*r<=0){
|
|
||||||
nearest.lat = source.lat;
|
|
||||||
nearest.lon = source.lon;
|
|
||||||
return ((b - y)*(b - y) + (a - x)*(a - x));
|
|
||||||
}
|
|
||||||
else if(*r >= 1){
|
|
||||||
nearest.lat = target.lat;
|
|
||||||
nearest.lon = target.lon;
|
|
||||||
return ((d - y)*(d - y) + (c - x)*(c - x));
|
|
||||||
|
|
||||||
}
|
|
||||||
// point lies in between
|
|
||||||
nearest.lat = p;
|
|
||||||
nearest.lon = q;
|
|
||||||
return (p-x)*(p-x) + (q-y)*(q-y);
|
|
||||||
}
|
|
||||||
|
|
||||||
ofstream indexOutFile;
|
|
||||||
ifstream ramInFile;
|
|
||||||
stxxl::vector<GridEntry> * entries;
|
|
||||||
std::vector<unsigned> ramIndexTable; //4 MB for first level index in RAM
|
|
||||||
std::string iif;
|
|
||||||
// LRUCache<int,std::vector<unsigned> > cellCache;
|
|
||||||
// LRUCache<int,std::vector<_Edge> > fileCache;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef NNGrid::NNGrid<false> ReadOnlyGrid;
|
|
||||||
typedef NNGrid::NNGrid<true > WritableGrid;
|
|
||||||
|
|
||||||
#endif /* NNGRID_H_ */
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
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 _NODE_COORDS_H
|
|
||||||
#define _NODE_COORDS_H
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <cstddef>
|
|
||||||
#include <climits>
|
|
||||||
|
|
||||||
#include "../typedefs.h"
|
|
||||||
|
|
||||||
template<typename NodeT>
|
|
||||||
struct NodeCoords {
|
|
||||||
typedef unsigned key_type; //type of NodeID
|
|
||||||
typedef int value_type; //type of lat,lons
|
|
||||||
|
|
||||||
NodeCoords(int _lat, int _lon, NodeT _id) : lat(_lat), lon(_lon), id(_id) {}
|
|
||||||
NodeCoords() : lat(INT_MAX), lon(INT_MAX), id(UINT_MAX) {}
|
|
||||||
int lat;
|
|
||||||
int lon;
|
|
||||||
NodeT id;
|
|
||||||
|
|
||||||
static NodeCoords<NodeT> min_value()
|
|
||||||
{
|
|
||||||
return NodeCoords<NodeT>(-90*100000,-180*100000,numeric_limits<NodeT>::min());
|
|
||||||
}
|
|
||||||
static NodeCoords<NodeT> max_value()
|
|
||||||
{
|
|
||||||
return NodeCoords<NodeT>(90*100000, 180*100000, numeric_limits<NodeT>::max());
|
|
||||||
}
|
|
||||||
|
|
||||||
value_type operator[](size_t n) const {
|
|
||||||
switch(n) {
|
|
||||||
case 1:
|
|
||||||
return lat;
|
|
||||||
break;
|
|
||||||
case 0:
|
|
||||||
return lon;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
return UINT_MAX;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
assert(false);
|
|
||||||
return UINT_MAX;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif //_NODE_COORDS_H
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
/*
|
|
||||||
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 NODEINFORMATIONHELPDESK_H_
|
|
||||||
#define NODEINFORMATIONHELPDESK_H_
|
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "../typedefs.h"
|
|
||||||
#include "NNGrid.h"
|
|
||||||
#include "PhantomNodes.h"
|
|
||||||
|
|
||||||
class NodeInformationHelpDesk{
|
|
||||||
public:
|
|
||||||
NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, unsigned _numberOfNodes) : numberOfNodes(_numberOfNodes) {
|
|
||||||
readOnlyGrid = new ReadOnlyGrid(ramIndexInput,fileIndexInput);
|
|
||||||
int2ExtNodeMap = new vector<_Coordinate>();
|
|
||||||
int2ExtNodeMap->reserve(numberOfNodes);
|
|
||||||
assert(0 == int2ExtNodeMap->size());
|
|
||||||
}
|
|
||||||
|
|
||||||
~NodeInformationHelpDesk() {
|
|
||||||
delete int2ExtNodeMap;
|
|
||||||
delete readOnlyGrid;
|
|
||||||
}
|
|
||||||
void initNNGrid(ifstream& in) {
|
|
||||||
while(!in.eof()) {
|
|
||||||
NodeInfo b;
|
|
||||||
in.read((char *)&b, sizeof(b));
|
|
||||||
int2ExtNodeMap->push_back(_Coordinate(b.lat, b.lon));
|
|
||||||
}
|
|
||||||
in.close();
|
|
||||||
readOnlyGrid->OpenIndexFiles();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int getLatitudeOfNode(const NodeID node) const {
|
|
||||||
return int2ExtNodeMap->at(node).lat;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int getLongitudeOfNode(const NodeID node) const { return int2ExtNodeMap->at(node).lon; }
|
|
||||||
|
|
||||||
NodeID getNumberOfNodes() const { return numberOfNodes; }
|
|
||||||
NodeID getNumberOfNodes2() const { return int2ExtNodeMap->size(); }
|
|
||||||
|
|
||||||
inline void FindNearestNodeCoordForLatLon(const _Coordinate& coord, _Coordinate& result) {
|
|
||||||
readOnlyGrid->FindNearestCoordinateOnEdgeInNodeBasedGraph(coord, result);
|
|
||||||
}
|
|
||||||
bool FindPhantomNodeForCoordinate( const _Coordinate & location, PhantomNode & resultNode) {
|
|
||||||
return readOnlyGrid->FindPhantomNodeForCoordinate(location, resultNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool FindRoutingStarts(const _Coordinate &start, const _Coordinate &target, PhantomNodes & phantomNodes) {
|
|
||||||
readOnlyGrid->FindRoutingStarts(start, target, phantomNodes);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool GetStartAndDestNodesOfEdge(const _Coordinate& coord, NodesOfEdge& nodesOfEdge) {
|
|
||||||
return readOnlyGrid->GetEdgeBasedStartNode(coord, nodesOfEdge);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void FindNearestPointOnEdge(const _Coordinate & input, _Coordinate& output){
|
|
||||||
readOnlyGrid->FindNearestPointOnEdge(input, output);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
vector<_Coordinate> * int2ExtNodeMap;
|
|
||||||
ReadOnlyGrid * readOnlyGrid;
|
|
||||||
unsigned numberOfNodes;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /*NODEINFORMATIONHELPDESK_H_*/
|
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 ORIGINAL_EDGE_DATA_H
|
||||||
|
#define ORIGINAL_EDGE_DATA_H
|
||||||
|
|
||||||
|
#include "TurnInstructions.h"
|
||||||
|
#include "../typedefs.h"
|
||||||
|
|
||||||
|
#include <climits>
|
||||||
|
|
||||||
|
struct OriginalEdgeData{
|
||||||
|
explicit OriginalEdgeData(
|
||||||
|
NodeID via_node,
|
||||||
|
unsigned name_id,
|
||||||
|
TurnInstruction turn_instruction
|
||||||
|
) :
|
||||||
|
via_node(via_node),
|
||||||
|
name_id(name_id),
|
||||||
|
turn_instruction(turn_instruction)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
OriginalEdgeData() :
|
||||||
|
via_node(UINT_MAX),
|
||||||
|
name_id(UINT_MAX),
|
||||||
|
turn_instruction(UCHAR_MAX)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
NodeID via_node;
|
||||||
|
unsigned name_id;
|
||||||
|
TurnInstruction turn_instruction;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //ORIGINAL_EDGE_DATA_H
|
||||||
@@ -1,535 +0,0 @@
|
|||||||
/*
|
|
||||||
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 PBFPARSER_H_
|
|
||||||
#define PBFPARSER_H_
|
|
||||||
|
|
||||||
#include <zlib.h>
|
|
||||||
|
|
||||||
#include "BaseParser.h"
|
|
||||||
|
|
||||||
#include "pbf-proto/fileformat.pb.h"
|
|
||||||
#include "pbf-proto/osmformat.pb.h"
|
|
||||||
#include "../typedefs.h"
|
|
||||||
#include "HashTable.h"
|
|
||||||
#include "ExtractorStructs.h"
|
|
||||||
#include "ConcurrentQueue.h"
|
|
||||||
|
|
||||||
class PBFParser : public BaseParser<_Node, _RawRestrictionContainer, _Way> {
|
|
||||||
|
|
||||||
enum EntityType {
|
|
||||||
TypeNode = 1,
|
|
||||||
TypeWay = 2,
|
|
||||||
TypeRelation = 4,
|
|
||||||
TypeDenseNode = 8
|
|
||||||
} ;
|
|
||||||
|
|
||||||
enum Endianness {
|
|
||||||
LittleEndian = 1,
|
|
||||||
BigEndian = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _ThreadData {
|
|
||||||
int currentGroupID;
|
|
||||||
int currentEntityID;
|
|
||||||
short entityTypeIndicator;
|
|
||||||
|
|
||||||
OSMPBF::BlobHeader PBFBlobHeader;
|
|
||||||
OSMPBF::Blob PBFBlob;
|
|
||||||
|
|
||||||
OSMPBF::HeaderBlock PBFHeaderBlock;
|
|
||||||
OSMPBF::PrimitiveBlock PBFprimitiveBlock;
|
|
||||||
|
|
||||||
std::vector<char> charBuffer;
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
|
||||||
PBFParser(const char * fileName)
|
|
||||||
: threadDataQueue( new ConcurrentQueue<_ThreadData*>(25) ) { /* Max 25 items in queue */
|
|
||||||
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
|
||||||
input.open(fileName, std::ios::in | std::ios::binary);
|
|
||||||
|
|
||||||
if (!input) {
|
|
||||||
std::cerr << fileName << ": File not found." << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
blockCount = 0;
|
|
||||||
groupCount = 0;
|
|
||||||
|
|
||||||
//Dummy initialization
|
|
||||||
wayCallback = NULL; nodeCallback = NULL;
|
|
||||||
addressCallback = NULL; restrictionCallback = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RegisterCallbacks(bool (*nodeCallbackPointer)(_Node), bool (*restrictionCallbackPointer)(_RawRestrictionContainer), bool (*wayCallbackPointer)(_Way),bool (*addressCallbackPointer)(_Node, HashTable<std::string, std::string>) ) {
|
|
||||||
nodeCallback = *nodeCallbackPointer;
|
|
||||||
wayCallback = *wayCallbackPointer;
|
|
||||||
restrictionCallback = *restrictionCallbackPointer;
|
|
||||||
addressCallback = *addressCallbackPointer;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
~PBFParser() {
|
|
||||||
if(input.is_open())
|
|
||||||
input.close();
|
|
||||||
|
|
||||||
// Clean up any leftover ThreadData objects in the queue
|
|
||||||
_ThreadData* td;
|
|
||||||
while (threadDataQueue->try_pop(td)) {
|
|
||||||
delete td;
|
|
||||||
}
|
|
||||||
delete threadDataQueue;
|
|
||||||
|
|
||||||
google::protobuf::ShutdownProtobufLibrary();
|
|
||||||
|
|
||||||
#ifndef NDEBUG
|
|
||||||
std::cout << "[info] blocks: " << blockCount << std::endl;
|
|
||||||
std::cout << "[info] groups: " << groupCount << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Init() {
|
|
||||||
_ThreadData initData;
|
|
||||||
/** read Header */
|
|
||||||
if(!readPBFBlobHeader(input, &initData)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(readBlob(input, &initData)) {
|
|
||||||
if(!initData.PBFHeaderBlock.ParseFromArray(&(initData.charBuffer[0]), initData.charBuffer.size() ) ) {
|
|
||||||
std::cerr << "[error] Header not parseable!" << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < initData.PBFHeaderBlock.required_features_size(); i++) {
|
|
||||||
const std::string& feature = initData.PBFHeaderBlock.required_features( i );
|
|
||||||
bool supported = false;
|
|
||||||
if ( feature == "OsmSchema-V0.6" )
|
|
||||||
supported = true;
|
|
||||||
else if ( feature == "DenseNodes" )
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ReadData() {
|
|
||||||
bool keepRunning = true;
|
|
||||||
do {
|
|
||||||
_ThreadData *threadData = new _ThreadData();
|
|
||||||
keepRunning = readNextBlock(input, threadData);
|
|
||||||
|
|
||||||
if (keepRunning)
|
|
||||||
threadDataQueue->push(threadData);
|
|
||||||
else
|
|
||||||
threadDataQueue->push(NULL); // No more data to read, parse stops when NULL encountered
|
|
||||||
} while(keepRunning);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ParseData() {
|
|
||||||
while (1) {
|
|
||||||
_ThreadData *threadData;
|
|
||||||
threadDataQueue->wait_and_pop(threadData);
|
|
||||||
if (threadData == NULL) {
|
|
||||||
cout << "Parse Data Thread Finished" << endl;
|
|
||||||
threadDataQueue->push(NULL); // Signal end of data for other threads
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
loadBlock(threadData);
|
|
||||||
for(int i = 0; i < threadData->PBFprimitiveBlock.primitivegroup_size(); i++) {
|
|
||||||
threadData->currentGroupID = i;
|
|
||||||
loadGroup(threadData);
|
|
||||||
|
|
||||||
if(threadData->entityTypeIndicator == TypeNode)
|
|
||||||
parseNode(threadData);
|
|
||||||
if(threadData->entityTypeIndicator == TypeWay)
|
|
||||||
parseWay(threadData);
|
|
||||||
if(threadData->entityTypeIndicator == TypeRelation)
|
|
||||||
parseRelation(threadData);
|
|
||||||
if(threadData->entityTypeIndicator == TypeDenseNode)
|
|
||||||
parseDenseNode(threadData);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete threadData;
|
|
||||||
threadData = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Parse() {
|
|
||||||
// Start the read and parse threads
|
|
||||||
boost::thread readThread(boost::bind(&PBFParser::ReadData, this));
|
|
||||||
boost::thread parseThread(boost::bind(&PBFParser::ParseData, this));
|
|
||||||
|
|
||||||
// Wait for the threads to finish
|
|
||||||
readThread.join();
|
|
||||||
parseThread.join();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void parseDenseNode(_ThreadData * threadData) {
|
|
||||||
const OSMPBF::DenseNodes& dense = threadData->PBFprimitiveBlock.primitivegroup( threadData->currentGroupID ).dense();
|
|
||||||
int denseTagIndex = 0;
|
|
||||||
int m_lastDenseID = 0;
|
|
||||||
int m_lastDenseLatitude = 0;
|
|
||||||
int m_lastDenseLongitude = 0;
|
|
||||||
|
|
||||||
for(int i = 0; i < dense.id_size(); i++) {
|
|
||||||
HashTable<std::string, std::string> keyVals;
|
|
||||||
m_lastDenseID += dense.id( i );
|
|
||||||
m_lastDenseLatitude += dense.lat( i );
|
|
||||||
m_lastDenseLongitude += dense.lon( i );
|
|
||||||
_Node n;
|
|
||||||
n.id = m_lastDenseID;
|
|
||||||
n.lat = 100000*( ( double ) m_lastDenseLatitude * threadData->PBFprimitiveBlock.granularity() +threadData-> PBFprimitiveBlock.lat_offset() ) / NANO;
|
|
||||||
n.lon = 100000*( ( double ) m_lastDenseLongitude * threadData->PBFprimitiveBlock.granularity() + threadData->PBFprimitiveBlock.lon_offset() ) / NANO;
|
|
||||||
while (denseTagIndex < dense.keys_vals_size()) {
|
|
||||||
int tagValue = dense.keys_vals( denseTagIndex );
|
|
||||||
if(tagValue == 0) {
|
|
||||||
denseTagIndex++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
int keyValue = dense.keys_vals ( denseTagIndex+1 );
|
|
||||||
std::string key = threadData->PBFprimitiveBlock.stringtable().s(tagValue).data();
|
|
||||||
std::string value = threadData->PBFprimitiveBlock.stringtable().s(keyValue).data();
|
|
||||||
keyVals.Add(key, value);
|
|
||||||
denseTagIndex += 2;
|
|
||||||
}
|
|
||||||
if(!(*addressCallback)(n, keyVals))
|
|
||||||
std::cerr << "[PBFParser] adress not parsed" << std::endl;
|
|
||||||
|
|
||||||
if(!(*nodeCallback)(n))
|
|
||||||
std::cerr << "[PBFParser] dense node not parsed" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void parseNode(_ThreadData * threadData) {
|
|
||||||
_Node n;
|
|
||||||
if(!(*nodeCallback)(n))
|
|
||||||
std::cerr << "[PBFParser] simple node not parsed" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void parseRelation(_ThreadData * threadData) {
|
|
||||||
const OSMPBF::PrimitiveGroup& group = threadData->PBFprimitiveBlock.primitivegroup( threadData->currentGroupID );
|
|
||||||
for(int i = 0; i < group.relations_size(); i++ ) {
|
|
||||||
const OSMPBF::Relation& inputRelation = threadData->PBFprimitiveBlock.primitivegroup( threadData->currentGroupID ).relations(i);
|
|
||||||
bool isRestriction = false;
|
|
||||||
bool isOnlyRestriction = false;
|
|
||||||
for(int k = 0; k < inputRelation.keys_size(); k++) {
|
|
||||||
const std::string key = threadData->PBFprimitiveBlock.stringtable().s(inputRelation.keys(k));
|
|
||||||
const std::string val = threadData->PBFprimitiveBlock.stringtable().s(inputRelation.vals(k));
|
|
||||||
if ("type" == key && "restriction" == val) {
|
|
||||||
isRestriction = true;
|
|
||||||
}
|
|
||||||
if ("restriction" == key) {
|
|
||||||
if(val.find("only_") == 0)
|
|
||||||
isOnlyRestriction = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if(isRestriction) {
|
|
||||||
long long lastRef = 0;
|
|
||||||
_RawRestrictionContainer currentRestrictionContainer(isOnlyRestriction);
|
|
||||||
for(int rolesIndex = 0; rolesIndex < inputRelation.roles_sid_size(); rolesIndex++) {
|
|
||||||
string role(threadData->PBFprimitiveBlock.stringtable().s( inputRelation.roles_sid( rolesIndex ) ).data());
|
|
||||||
lastRef += inputRelation.memids(rolesIndex);
|
|
||||||
|
|
||||||
if(false == ("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;
|
|
||||||
assert("via" == role);
|
|
||||||
if(UINT_MAX != currentRestrictionContainer.viaWay)
|
|
||||||
currentRestrictionContainer.viaWay = UINT_MAX;
|
|
||||||
assert(UINT_MAX == currentRestrictionContainer.viaWay);
|
|
||||||
currentRestrictionContainer.restriction.viaNode = lastRef;
|
|
||||||
break;
|
|
||||||
case 1: //way
|
|
||||||
assert("from" == role || "to" == role || "via" == role);
|
|
||||||
if("from" == role) {
|
|
||||||
currentRestrictionContainer.fromWay = lastRef;
|
|
||||||
}
|
|
||||||
if ("to" == role) {
|
|
||||||
currentRestrictionContainer.toWay = lastRef;
|
|
||||||
}
|
|
||||||
if ("via" == role) {
|
|
||||||
assert(currentRestrictionContainer.restriction.toNode == UINT_MAX);
|
|
||||||
currentRestrictionContainer.viaWay = lastRef;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 2: //relation, not used. relations relating to relations are evil.
|
|
||||||
continue;
|
|
||||||
assert(false);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: //should not happen
|
|
||||||
cout << "unknown";
|
|
||||||
assert(false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// if(UINT_MAX != currentRestriction.viaNode) {
|
|
||||||
// cout << "restr from " << currentRestriction.from << " via ";
|
|
||||||
// cout << "node " << currentRestriction.viaNode;
|
|
||||||
// cout << " to " << currentRestriction.to << endl;
|
|
||||||
// }
|
|
||||||
if(!(*restrictionCallback)(currentRestrictionContainer))
|
|
||||||
std::cerr << "[PBFParser] relation not parsed" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void parseWay(_ThreadData * threadData) {
|
|
||||||
if( threadData->PBFprimitiveBlock.primitivegroup( threadData->currentGroupID ).ways_size() > 0) {
|
|
||||||
for(int i = 0; i < threadData->PBFprimitiveBlock.primitivegroup( threadData->currentGroupID ).ways_size(); i++) {
|
|
||||||
const OSMPBF::Way& inputWay = threadData->PBFprimitiveBlock.primitivegroup( threadData->currentGroupID ).ways( i );
|
|
||||||
_Way w;
|
|
||||||
w.id = inputWay.id();
|
|
||||||
unsigned pathNode(0);
|
|
||||||
for(int i = 0; i < inputWay.refs_size(); i++) {
|
|
||||||
pathNode += inputWay.refs(i);
|
|
||||||
w.path.push_back(pathNode);
|
|
||||||
}
|
|
||||||
assert(inputWay.keys_size() == inputWay.vals_size());
|
|
||||||
for(int i = 0; i < inputWay.keys_size(); i++) {
|
|
||||||
const std::string key = threadData->PBFprimitiveBlock.stringtable().s(inputWay.keys(i));
|
|
||||||
const std::string val = threadData->PBFprimitiveBlock.stringtable().s(inputWay.vals(i));
|
|
||||||
w.keyVals.Add(key, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!(*wayCallback)(w)) {
|
|
||||||
std::cerr << "[PBFParser] way not parsed" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void loadGroup(_ThreadData * threadData) {
|
|
||||||
groupCount++;
|
|
||||||
|
|
||||||
const OSMPBF::PrimitiveGroup& group = threadData->PBFprimitiveBlock.primitivegroup( threadData->currentGroupID );
|
|
||||||
threadData->entityTypeIndicator = 0;
|
|
||||||
if ( group.nodes_size() != 0 ) {
|
|
||||||
threadData->entityTypeIndicator = TypeNode;
|
|
||||||
}
|
|
||||||
if ( group.ways_size() != 0 ) {
|
|
||||||
threadData->entityTypeIndicator = TypeWay;
|
|
||||||
}
|
|
||||||
if ( group.relations_size() != 0 ) {
|
|
||||||
threadData->entityTypeIndicator = TypeRelation;
|
|
||||||
}
|
|
||||||
if ( group.has_dense() ) {
|
|
||||||
threadData->entityTypeIndicator = TypeDenseNode;
|
|
||||||
assert( group.dense().id_size() != 0 );
|
|
||||||
}
|
|
||||||
assert( threadData->entityTypeIndicator != 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
void loadBlock(_ThreadData * threadData) {
|
|
||||||
blockCount++;
|
|
||||||
threadData->currentGroupID = 0;
|
|
||||||
threadData->currentEntityID = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Reverses Network Byte Order into something usable */
|
|
||||||
inline unsigned swapEndian(unsigned x) {
|
|
||||||
if(getMachineEndianness() == LittleEndian)
|
|
||||||
return ( (x>>24) | ((x<<8) & 0x00FF0000) | ((x>>8) & 0x0000FF00) | (x<<24) );
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool readPBFBlobHeader(std::fstream& stream, _ThreadData * threadData) {
|
|
||||||
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 = (char*)malloc(size);
|
|
||||||
stream.read(data, size*sizeof(data[0]));
|
|
||||||
|
|
||||||
if ( !(threadData->PBFBlobHeader).ParseFromArray( data, size ) ){
|
|
||||||
free(data);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
free(data);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool unpackZLIB(std::fstream & stream, _ThreadData * threadData) {
|
|
||||||
unsigned rawSize = threadData->PBFBlob.raw_size();
|
|
||||||
char* unpackedDataArray = (char*)malloc(rawSize);
|
|
||||||
z_stream compressedDataStream;
|
|
||||||
compressedDataStream.next_in = ( unsigned char* ) threadData->PBFBlob.zlib_data().data();
|
|
||||||
compressedDataStream.avail_in = threadData->PBFBlob.zlib_data().size();
|
|
||||||
compressedDataStream.next_out = ( unsigned char* ) unpackedDataArray;
|
|
||||||
compressedDataStream.avail_out = rawSize;
|
|
||||||
compressedDataStream.zalloc = Z_NULL;
|
|
||||||
compressedDataStream.zfree = Z_NULL;
|
|
||||||
compressedDataStream.opaque = Z_NULL;
|
|
||||||
int ret = inflateInit( &compressedDataStream );
|
|
||||||
if ( ret != Z_OK ) {
|
|
||||||
std::cerr << "[error] failed to init zlib stream" << std::endl;
|
|
||||||
free(unpackedDataArray);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = inflate( &compressedDataStream, Z_FINISH );
|
|
||||||
if ( ret != Z_STREAM_END ) {
|
|
||||||
std::cerr << "[error] failed to inflate zlib stream" << std::endl;
|
|
||||||
std::cerr << "[error] Error type: " << ret << std::endl;
|
|
||||||
free(unpackedDataArray);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = inflateEnd( &compressedDataStream );
|
|
||||||
if ( ret != Z_OK ) {
|
|
||||||
std::cerr << "[error] failed to deinit zlib stream" << std::endl;
|
|
||||||
free(unpackedDataArray);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
threadData->charBuffer.clear(); threadData->charBuffer.resize(rawSize);
|
|
||||||
for(unsigned i = 0; i < rawSize; i++) {
|
|
||||||
threadData->charBuffer[i] = unpackedDataArray[i];
|
|
||||||
}
|
|
||||||
free(unpackedDataArray);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool unpackLZMA(std::fstream & stream, _ThreadData * threadData) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool readBlob(std::fstream& stream, _ThreadData * threadData) {
|
|
||||||
if(stream.eof())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
int size = threadData->PBFBlobHeader.datasize();
|
|
||||||
if ( size < 0 || size > MAX_BLOB_SIZE ) {
|
|
||||||
std::cerr << "[error] invalid Blob size:" << size << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* data = (char*)malloc(size);
|
|
||||||
stream.read(data, sizeof(data[0])*size);
|
|
||||||
|
|
||||||
if ( !threadData->PBFBlob.ParseFromArray( data, size ) ) {
|
|
||||||
std::cerr << "[error] failed to parse blob" << std::endl;
|
|
||||||
free(data);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( threadData->PBFBlob.has_raw() ) {
|
|
||||||
const std::string& data = threadData->PBFBlob.raw();
|
|
||||||
threadData->charBuffer.clear();
|
|
||||||
threadData->charBuffer.resize( data.size() );
|
|
||||||
for ( unsigned i = 0; i < data.size(); i++ ) {
|
|
||||||
threadData->charBuffer[i] = data[i];
|
|
||||||
}
|
|
||||||
} else if ( threadData->PBFBlob.has_zlib_data() ) {
|
|
||||||
if ( !unpackZLIB(stream, threadData) ) {
|
|
||||||
std::cerr << "[error] zlib data encountered that could not be unpacked" << std::endl;
|
|
||||||
free(data);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if ( threadData->PBFBlob.has_lzma_data() ) {
|
|
||||||
if ( !unpackLZMA(stream, threadData) )
|
|
||||||
std::cerr << "[error] lzma data encountered that could not be unpacked" << std::endl;
|
|
||||||
free(data);
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
std::cerr << "[error] Blob contains no data" << std::endl;
|
|
||||||
free(data);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
free(data);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool readNextBlock(std::fstream& stream, _ThreadData * threadData) {
|
|
||||||
if(stream.eof()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !readPBFBlobHeader(stream, threadData) )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if ( threadData->PBFBlobHeader.type() != "OSMData" ) {
|
|
||||||
std::cerr << "[error] invalid block type, found" << threadData->PBFBlobHeader.type().data() << "instead of OSMData" << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !readBlob(stream, threadData) )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if ( !threadData->PBFprimitiveBlock.ParseFromArray( &(threadData->charBuffer[0]), threadData-> charBuffer.size() ) ) {
|
|
||||||
std::cerr << "[error] failed to parse PrimitiveBlock" << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Endianness getMachineEndianness() {
|
|
||||||
int i(1);
|
|
||||||
char *p = (char *) &i;
|
|
||||||
if (p[0] == 1)
|
|
||||||
return LittleEndian;
|
|
||||||
return BigEndian;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
/* counting the number of read blocks and groups */
|
|
||||||
unsigned groupCount;
|
|
||||||
unsigned blockCount;
|
|
||||||
|
|
||||||
/* Function pointer for nodes */
|
|
||||||
bool (*nodeCallback)(_Node);
|
|
||||||
bool (*wayCallback)(_Way);
|
|
||||||
bool (*restrictionCallback)(_RawRestrictionContainer);
|
|
||||||
bool (*addressCallback)(_Node, HashTable<std::string, std::string>);
|
|
||||||
/* the input stream to parse */
|
|
||||||
std::fstream input;
|
|
||||||
|
|
||||||
/* ThreadData Queue */
|
|
||||||
ConcurrentQueue < _ThreadData* >* threadDataQueue;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* PBFPARSER_H_ */
|
|
||||||
@@ -1,33 +1,37 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, others 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
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
|
Redistributions of source code must retain the above copyright notice, this list
|
||||||
along with this program; if not, write to the Free Software
|
of conditions and the following disclaimer.
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
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 PERCENT_H
|
#ifndef PERCENT_H
|
||||||
#define PERCENT_H
|
#define PERCENT_H
|
||||||
|
|
||||||
|
#include "../Util/OpenMPWrapper.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#ifdef _OPENMP
|
|
||||||
#include <omp.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class Percent
|
class Percent {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -58,10 +62,15 @@ public:
|
|||||||
std::cout << " 100%" << std::endl;
|
std::cout << " 100%" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printIncrement()
|
void printIncrement() {
|
||||||
{
|
|
||||||
#pragma omp atomic
|
#pragma omp atomic
|
||||||
_current_value++;
|
++_current_value;
|
||||||
|
printStatus(_current_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printAddition(const unsigned addition) {
|
||||||
|
#pragma omp atomic
|
||||||
|
_current_value += addition;
|
||||||
printStatus(_current_value);
|
printStatus(_current_value);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -1,45 +1,70 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
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
|
Redistributions of source code must retain the above copyright notice, this list
|
||||||
along with this program; if not, write to the Free Software
|
of conditions and the following disclaimer.
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
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 PHANTOMNODES_H_
|
#ifndef PHANTOMNODES_H_
|
||||||
#define PHANTOMNODES_H_
|
#define PHANTOMNODES_H_
|
||||||
|
|
||||||
#include "ExtractorStructs.h"
|
#include <osrm/Coordinate.h>
|
||||||
|
|
||||||
|
#include "../typedefs.h"
|
||||||
|
|
||||||
struct PhantomNode {
|
struct PhantomNode {
|
||||||
PhantomNode() : edgeBasedNode(UINT_MAX), nodeBasedEdgeNameID(UINT_MAX), weight1(INT_MAX), weight2(INT_MAX) {}
|
PhantomNode() :
|
||||||
|
edgeBasedNode(UINT_MAX),
|
||||||
|
nodeBasedEdgeNameID(UINT_MAX),
|
||||||
|
weight1(INT_MAX),
|
||||||
|
weight2(INT_MAX),
|
||||||
|
ratio(0.)
|
||||||
|
{ }
|
||||||
|
|
||||||
NodeID edgeBasedNode;
|
NodeID edgeBasedNode;
|
||||||
unsigned nodeBasedEdgeNameID;
|
unsigned nodeBasedEdgeNameID;
|
||||||
int weight1;
|
int weight1;
|
||||||
int weight2;
|
int weight2;
|
||||||
_Coordinate location;
|
double ratio;
|
||||||
|
FixedPointCoordinate location;
|
||||||
void Reset() {
|
void Reset() {
|
||||||
edgeBasedNode = UINT_MAX;
|
edgeBasedNode = UINT_MAX;
|
||||||
nodeBasedEdgeNameID = UINT_MAX;
|
nodeBasedEdgeNameID = UINT_MAX;
|
||||||
weight1 = INT_MAX;
|
weight1 = INT_MAX;
|
||||||
weight2 = INT_MAX;
|
weight2 = INT_MAX;
|
||||||
|
ratio = 0.;
|
||||||
location.Reset();
|
location.Reset();
|
||||||
}
|
}
|
||||||
bool isBidirected() const {
|
bool isBidirected() const {
|
||||||
return weight2 != INT_MAX;
|
return weight2 != INT_MAX;
|
||||||
}
|
}
|
||||||
|
bool isValid(const unsigned numberOfNodes) const {
|
||||||
|
return location.isValid() && (edgeBasedNode < numberOfNodes) && (weight1 != INT_MAX) && (ratio >= 0.) && (ratio <= 1.) && (nodeBasedEdgeNameID != UINT_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const PhantomNode & other) const {
|
||||||
|
return location == other.location;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PhantomNodes {
|
struct PhantomNodes {
|
||||||
@@ -57,6 +82,10 @@ struct PhantomNodes {
|
|||||||
bool AtLeastOnePhantomNodeIsUINTMAX() const {
|
bool AtLeastOnePhantomNodeIsUINTMAX() const {
|
||||||
return !(startPhantom.edgeBasedNode == UINT_MAX || targetPhantom.edgeBasedNode == UINT_MAX);
|
return !(startPhantom.edgeBasedNode == UINT_MAX || targetPhantom.edgeBasedNode == UINT_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PhantomNodesHaveEqualLocation() const {
|
||||||
|
return startPhantom == targetPhantom;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::ostream& operator<<(std::ostream &out, const PhantomNodes & pn){
|
inline std::ostream& operator<<(std::ostream &out, const PhantomNodes & pn){
|
||||||
@@ -67,10 +96,9 @@ inline std::ostream& operator<<(std::ostream &out, const PhantomNodes & pn){
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct NodesOfEdge {
|
inline std::ostream& operator<<(std::ostream &out, const PhantomNode & pn){
|
||||||
NodeID edgeBasedNode;
|
out << "node: " << pn.edgeBasedNode << ", name: " << pn.nodeBasedEdgeNameID << ", w1: " << pn.weight1 << ", w2: " << pn.weight2 << ", ratio: " << pn.ratio << ", loc: " << pn.location;
|
||||||
double ratio;
|
return out;
|
||||||
_Coordinate projectedPoint;
|
}
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* PHANTOMNODES_H_ */
|
#endif /* PHANTOMNODES_H_ */
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 QUERYEDGE_H_
|
||||||
|
#define QUERYEDGE_H_
|
||||||
|
|
||||||
|
#include "../typedefs.h"
|
||||||
|
|
||||||
|
#include <climits>
|
||||||
|
|
||||||
|
struct QueryEdge {
|
||||||
|
NodeID source;
|
||||||
|
NodeID target;
|
||||||
|
struct EdgeData {
|
||||||
|
NodeID id:31;
|
||||||
|
bool shortcut:1;
|
||||||
|
int distance:30;
|
||||||
|
bool forward:1;
|
||||||
|
bool backward:1;
|
||||||
|
} data;
|
||||||
|
|
||||||
|
bool operator<( const QueryEdge& right ) const {
|
||||||
|
if ( source != right.source ) {
|
||||||
|
return source < right.source;
|
||||||
|
}
|
||||||
|
return target < right.target;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator== ( const QueryEdge& right ) const {
|
||||||
|
return (
|
||||||
|
source == right.source &&
|
||||||
|
target == right.target &&
|
||||||
|
data.distance == right.data.distance &&
|
||||||
|
data.shortcut == right.data.shortcut &&
|
||||||
|
data.forward == right.data.forward &&
|
||||||
|
data.backward == right.data.backward &&
|
||||||
|
data.id == right.data.id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* QUERYEDGE_H_ */
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 _NODE_COORDS_H
|
||||||
|
#define _NODE_COORDS_H
|
||||||
|
|
||||||
|
#include "../typedefs.h"
|
||||||
|
|
||||||
|
#include <osrm/Coordinate.h>
|
||||||
|
|
||||||
|
#include <boost/assert.hpp>
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <climits>
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
|
struct NodeInfo {
|
||||||
|
typedef NodeID key_type; //type of NodeID
|
||||||
|
typedef int value_type; //type of lat,lons
|
||||||
|
|
||||||
|
NodeInfo(int _lat, int _lon, NodeID _id) : lat(_lat), lon(_lon), id(_id) {}
|
||||||
|
NodeInfo() : lat(INT_MAX), lon(INT_MAX), id(UINT_MAX) {}
|
||||||
|
int lat;
|
||||||
|
int lon;
|
||||||
|
NodeID id;
|
||||||
|
|
||||||
|
static NodeInfo min_value() {
|
||||||
|
return NodeInfo(
|
||||||
|
-90*COORDINATE_PRECISION,
|
||||||
|
-180*COORDINATE_PRECISION,
|
||||||
|
std::numeric_limits<NodeID>::min()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static NodeInfo max_value() {
|
||||||
|
return NodeInfo(
|
||||||
|
90*COORDINATE_PRECISION,
|
||||||
|
180*COORDINATE_PRECISION,
|
||||||
|
std::numeric_limits<NodeID>::max()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
value_type operator[](const std::size_t n) const {
|
||||||
|
switch(n) {
|
||||||
|
case 1:
|
||||||
|
return lat;
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
return lon;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
BOOST_ASSERT_MSG(false, "should not happen");
|
||||||
|
return UINT_MAX;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
BOOST_ASSERT_MSG(false, "should not happen");
|
||||||
|
return UINT_MAX;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //_NODE_COORDS_H
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 RAWROUTEDATA_H_
|
||||||
|
#define RAWROUTEDATA_H_
|
||||||
|
|
||||||
|
#include "../DataStructures/PhantomNodes.h"
|
||||||
|
#include "../typedefs.h"
|
||||||
|
|
||||||
|
#include <osrm/Coordinate.h>
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
struct PathData {
|
||||||
|
PathData() :
|
||||||
|
node(UINT_MAX),
|
||||||
|
name_id(UINT_MAX),
|
||||||
|
durationOfSegment(UINT_MAX),
|
||||||
|
turnInstruction(UCHAR_MAX)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
PathData(
|
||||||
|
NodeID no,
|
||||||
|
unsigned na,
|
||||||
|
unsigned tu,
|
||||||
|
unsigned dur
|
||||||
|
) :
|
||||||
|
node(no),
|
||||||
|
name_id(na),
|
||||||
|
durationOfSegment(dur),
|
||||||
|
turnInstruction(tu)
|
||||||
|
{ }
|
||||||
|
NodeID node;
|
||||||
|
unsigned name_id;
|
||||||
|
unsigned durationOfSegment;
|
||||||
|
short turnInstruction;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RawRouteData {
|
||||||
|
std::vector< std::vector<PathData> > unpacked_path_segments;
|
||||||
|
std::vector< PathData > unpacked_alternative;
|
||||||
|
std::vector< PhantomNodes > segmentEndCoordinates;
|
||||||
|
std::vector< FixedPointCoordinate > rawViaNodeCoordinates;
|
||||||
|
unsigned checkSum;
|
||||||
|
int lengthOfShortestPath;
|
||||||
|
int lengthOfAlternativePath;
|
||||||
|
RawRouteData() :
|
||||||
|
checkSum(UINT_MAX),
|
||||||
|
lengthOfShortestPath(INT_MAX),
|
||||||
|
lengthOfAlternativePath(INT_MAX)
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* RAWROUTEDATA_H_ */
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 RESTRICTION_H_
|
||||||
|
#define RESTRICTION_H_
|
||||||
|
|
||||||
|
#include "../typedefs.h"
|
||||||
|
#include <climits>
|
||||||
|
|
||||||
|
struct TurnRestriction {
|
||||||
|
NodeID viaNode;
|
||||||
|
NodeID fromNode;
|
||||||
|
NodeID toNode;
|
||||||
|
struct Bits { //mostly unused
|
||||||
|
Bits()
|
||||||
|
:
|
||||||
|
isOnly(false),
|
||||||
|
unused1(false),
|
||||||
|
unused2(false),
|
||||||
|
unused3(false),
|
||||||
|
unused4(false),
|
||||||
|
unused5(false),
|
||||||
|
unused6(false),
|
||||||
|
unused7(false)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
bool isOnly:1;
|
||||||
|
bool unused1:1;
|
||||||
|
bool unused2:1;
|
||||||
|
bool unused3:1;
|
||||||
|
bool unused4:1;
|
||||||
|
bool unused5:1;
|
||||||
|
bool unused6:1;
|
||||||
|
bool unused7:1;
|
||||||
|
} flags;
|
||||||
|
|
||||||
|
TurnRestriction(NodeID viaNode) :
|
||||||
|
viaNode(viaNode),
|
||||||
|
fromNode(UINT_MAX),
|
||||||
|
toNode(UINT_MAX) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TurnRestriction(const bool isOnly = false) :
|
||||||
|
viaNode(UINT_MAX),
|
||||||
|
fromNode(UINT_MAX),
|
||||||
|
toNode(UINT_MAX) {
|
||||||
|
flags.isOnly = isOnly;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct InputRestrictionContainer {
|
||||||
|
EdgeID fromWay;
|
||||||
|
EdgeID toWay;
|
||||||
|
unsigned viaNode;
|
||||||
|
TurnRestriction restriction;
|
||||||
|
|
||||||
|
InputRestrictionContainer(
|
||||||
|
EdgeID fromWay,
|
||||||
|
EdgeID toWay,
|
||||||
|
NodeID vn,
|
||||||
|
unsigned vw
|
||||||
|
) :
|
||||||
|
fromWay(fromWay),
|
||||||
|
toWay(toWay),
|
||||||
|
viaNode(vw)
|
||||||
|
{
|
||||||
|
restriction.viaNode = vn;
|
||||||
|
}
|
||||||
|
InputRestrictionContainer(
|
||||||
|
bool isOnly = false
|
||||||
|
) :
|
||||||
|
fromWay(UINT_MAX),
|
||||||
|
toWay(UINT_MAX),
|
||||||
|
viaNode(UINT_MAX)
|
||||||
|
{
|
||||||
|
restriction.flags.isOnly = isOnly;
|
||||||
|
}
|
||||||
|
|
||||||
|
static InputRestrictionContainer min_value() {
|
||||||
|
return InputRestrictionContainer(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
static InputRestrictionContainer max_value() {
|
||||||
|
return InputRestrictionContainer(
|
||||||
|
UINT_MAX,
|
||||||
|
UINT_MAX,
|
||||||
|
UINT_MAX,
|
||||||
|
UINT_MAX
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CmpRestrictionContainerByFrom {
|
||||||
|
typedef InputRestrictionContainer value_type;
|
||||||
|
inline bool operator()(
|
||||||
|
const InputRestrictionContainer & a,
|
||||||
|
const InputRestrictionContainer & b
|
||||||
|
) const {
|
||||||
|
return a.fromWay < b.fromWay;
|
||||||
|
}
|
||||||
|
inline value_type max_value() const {
|
||||||
|
return InputRestrictionContainer::max_value();
|
||||||
|
}
|
||||||
|
inline value_type min_value() const {
|
||||||
|
return InputRestrictionContainer::min_value();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CmpRestrictionContainerByTo {
|
||||||
|
typedef InputRestrictionContainer value_type;
|
||||||
|
inline bool operator()(
|
||||||
|
const InputRestrictionContainer & a,
|
||||||
|
const InputRestrictionContainer & b
|
||||||
|
) const {
|
||||||
|
return a.toWay < b.toWay;
|
||||||
|
}
|
||||||
|
value_type max_value() const {
|
||||||
|
return InputRestrictionContainer::max_value();
|
||||||
|
}
|
||||||
|
value_type min_value() const {
|
||||||
|
return InputRestrictionContainer::min_value();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* RESTRICTION_H_ */
|
||||||
@@ -1,267 +1,68 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, others 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
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
|
Redistributions of source code must retain the above copyright notice, this list
|
||||||
along with this program; if not, write to the Free Software
|
of conditions and the following disclaimer.
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
list of conditions and the following disclaimer in the documentation and/or
|
||||||
*/
|
other materials provided with the distribution.
|
||||||
|
|
||||||
#ifndef SEARCHENGINE_H_
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
#define SEARCHENGINE_H_
|
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 <climits>
|
*/
|
||||||
#include <deque>
|
|
||||||
|
|
||||||
#include <boost/thread.hpp>
|
#ifndef SEARCHENGINE_H
|
||||||
|
#define SEARCHENGINE_H
|
||||||
|
|
||||||
#include "BinaryHeap.h"
|
#include "SearchEngineData.h"
|
||||||
#include "PhantomNodes.h"
|
#include "PhantomNodes.h"
|
||||||
|
#include "QueryEdge.h"
|
||||||
|
#include "../RoutingAlgorithms/AlternativePathRouting.h"
|
||||||
|
#include "../RoutingAlgorithms/ShortestPathRouting.h"
|
||||||
|
|
||||||
#include "../Util/StringUtil.h"
|
#include "../Util/StringUtil.h"
|
||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
|
|
||||||
struct _HeapData {
|
#include <osrm/Coordinate.h>
|
||||||
NodeID parent;
|
|
||||||
_HeapData( NodeID p ) : parent(p) { }
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef boost::thread_specific_ptr<BinaryHeap< NodeID, NodeID, int, _HeapData > > HeapPtr;
|
#include <boost/assert.hpp>
|
||||||
|
|
||||||
template<class EdgeData, class GraphT>
|
#include <climits>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
template<class DataFacadeT>
|
||||||
class SearchEngine {
|
class SearchEngine {
|
||||||
private:
|
private:
|
||||||
const GraphT * _graph;
|
DataFacadeT * facade;
|
||||||
NodeInformationHelpDesk * nodeHelpDesk;
|
SearchEngineData engine_working_data;
|
||||||
std::vector<string> * _names;
|
|
||||||
static HeapPtr _forwardHeap;
|
|
||||||
static HeapPtr _backwardHeap;
|
|
||||||
inline double absDouble(double input) { if(input < 0) return input*(-1); else return input;}
|
|
||||||
public:
|
public:
|
||||||
SearchEngine(GraphT * g, NodeInformationHelpDesk * nh, std::vector<string> * n = new std::vector<string>()) : _graph(g), nodeHelpDesk(nh), _names(n) {}
|
ShortestPathRouting<DataFacadeT> shortest_path;
|
||||||
|
AlternativeRouting <DataFacadeT> alternative_path;
|
||||||
|
|
||||||
|
SearchEngine( DataFacadeT * facade )
|
||||||
|
:
|
||||||
|
facade (facade),
|
||||||
|
shortest_path (facade, engine_working_data),
|
||||||
|
alternative_path (facade, engine_working_data)
|
||||||
|
{}
|
||||||
|
|
||||||
~SearchEngine() {}
|
~SearchEngine() {}
|
||||||
|
|
||||||
inline const void GetCoordinatesForNodeID(NodeID id, _Coordinate& result) const {
|
|
||||||
result.lat = nodeHelpDesk->getLatitudeOfNode(id);
|
|
||||||
result.lon = nodeHelpDesk->getLongitudeOfNode(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void InitializeThreadLocalStorageIfNecessary() {
|
|
||||||
if(!_forwardHeap.get())
|
|
||||||
_forwardHeap.reset(new BinaryHeap< NodeID, NodeID, int, _HeapData >(nodeHelpDesk->getNumberOfNodes()));
|
|
||||||
else
|
|
||||||
_forwardHeap->Clear();
|
|
||||||
|
|
||||||
if(!_backwardHeap.get())
|
|
||||||
_backwardHeap.reset(new BinaryHeap< NodeID, NodeID, int, _HeapData >(nodeHelpDesk->getNumberOfNodes()));
|
|
||||||
else
|
|
||||||
_backwardHeap->Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
int ComputeRoute(PhantomNodes & phantomNodes, std::vector<_PathData> & path) {
|
|
||||||
int _upperbound = INT_MAX;
|
|
||||||
if(!phantomNodes.AtLeastOnePhantomNodeIsUINTMAX())
|
|
||||||
return _upperbound;
|
|
||||||
|
|
||||||
InitializeThreadLocalStorageIfNecessary();
|
|
||||||
NodeID middle = ( NodeID ) UINT_MAX;
|
|
||||||
bool stOnSameEdge = false;
|
|
||||||
//Handling the special case that origin and destination are on same edge and that the order is correct.
|
|
||||||
if(phantomNodes.PhantomsAreOnSameNodeBasedEdge()){
|
|
||||||
if(phantomNodes.startPhantom.isBidirected() && phantomNodes.targetPhantom.isBidirected()) {
|
|
||||||
int weight = std::abs(phantomNodes.startPhantom.weight1 - phantomNodes.targetPhantom.weight1);
|
|
||||||
return weight;
|
|
||||||
} else if(phantomNodes.startPhantom.weight1 <= phantomNodes.targetPhantom.weight1){
|
|
||||||
int weight = std::abs(phantomNodes.startPhantom.weight1 - phantomNodes.targetPhantom.weight1);
|
|
||||||
return weight;
|
|
||||||
} else {
|
|
||||||
stOnSameEdge = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//insert start and/or target node of start edge
|
|
||||||
_forwardHeap->Insert(phantomNodes.startPhantom.edgeBasedNode, -phantomNodes.startPhantom.weight1, phantomNodes.startPhantom.edgeBasedNode);
|
|
||||||
if(phantomNodes.startPhantom.isBidirected() ) {
|
|
||||||
_forwardHeap->Insert(phantomNodes.startPhantom.edgeBasedNode+1, -phantomNodes.startPhantom.weight2, phantomNodes.startPhantom.edgeBasedNode+1);
|
|
||||||
}
|
|
||||||
//insert start and/or target node of target edge id
|
|
||||||
_backwardHeap->Insert(phantomNodes.targetPhantom.edgeBasedNode, -phantomNodes.targetPhantom.weight1, phantomNodes.targetPhantom.edgeBasedNode);
|
|
||||||
if(phantomNodes.targetPhantom.isBidirected() ) {
|
|
||||||
_backwardHeap->Insert(phantomNodes.targetPhantom.edgeBasedNode+1, -phantomNodes.targetPhantom.weight2, phantomNodes.targetPhantom.edgeBasedNode+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
while(_forwardHeap->Size() + _backwardHeap->Size() > 0){
|
|
||||||
if(_forwardHeap->Size() > 0){
|
|
||||||
_RoutingStep(_forwardHeap, _backwardHeap, true, &middle, &_upperbound, stOnSameEdge);
|
|
||||||
}
|
|
||||||
if(_backwardHeap->Size() > 0){
|
|
||||||
_RoutingStep(_backwardHeap, _forwardHeap, false, &middle, &_upperbound, stOnSameEdge);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( _upperbound == INT_MAX ) {
|
|
||||||
return _upperbound;
|
|
||||||
}
|
|
||||||
NodeID pathNode = middle;
|
|
||||||
deque<NodeID> packedPath;
|
|
||||||
while(phantomNodes.startPhantom.edgeBasedNode != pathNode && (!phantomNodes.startPhantom.isBidirected() || phantomNodes.startPhantom.edgeBasedNode+1 != pathNode) ) {
|
|
||||||
pathNode = _forwardHeap->GetData(pathNode).parent;
|
|
||||||
packedPath.push_front(pathNode);
|
|
||||||
}
|
|
||||||
packedPath.push_back(middle);
|
|
||||||
pathNode = middle;
|
|
||||||
while(phantomNodes.targetPhantom.edgeBasedNode != pathNode && (!phantomNodes.targetPhantom.isBidirected() || phantomNodes.targetPhantom.edgeBasedNode+1 != pathNode)) {
|
|
||||||
pathNode = _backwardHeap->GetData(pathNode).parent;
|
|
||||||
packedPath.push_back(pathNode);
|
|
||||||
}
|
|
||||||
for(deque<NodeID>::size_type i = 0;i < packedPath.size() - 1;i++){
|
|
||||||
_UnpackEdge(packedPath[i], packedPath[i + 1], path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return _upperbound;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool FindRoutingStarts(const _Coordinate & start, const _Coordinate & target, PhantomNodes & routingStarts) const {
|
|
||||||
nodeHelpDesk->FindRoutingStarts(start, target, routingStarts);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool FindPhantomNodeForCoordinate(const _Coordinate & location, PhantomNode & result) const {
|
|
||||||
return nodeHelpDesk->FindPhantomNodeForCoordinate(location, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline NodeID GetNameIDForOriginDestinationNodeID(NodeID s, NodeID t) const {
|
|
||||||
if(s == t)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
EdgeID e = _graph->FindEdge(s, t);
|
|
||||||
if(e == UINT_MAX)
|
|
||||||
e = _graph->FindEdge( t, s );
|
|
||||||
if(UINT_MAX == e) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
assert(e != UINT_MAX);
|
|
||||||
const EdgeData ed = _graph->GetEdgeData(e);
|
|
||||||
return ed.via;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::string GetEscapedNameForNameID(const NodeID nameID) const {
|
|
||||||
return ((nameID >= _names->size() || nameID == 0) ? std::string("") : HTMLEntitize(_names->at(nameID)));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::string GetEscapedNameForEdgeBasedEdgeID(const unsigned edgeID) const {
|
|
||||||
|
|
||||||
const unsigned nameID = _graph->GetEdgeData(edgeID).nameID1;
|
|
||||||
return GetEscapedNameForNameID(nameID);
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
inline void _RoutingStep(HeapPtr & _forwardHeap, HeapPtr & _backwardHeap, const bool & forwardDirection, NodeID *middle, int *_upperbound, const bool stOnSameEdge) const {
|
|
||||||
const NodeID node = _forwardHeap->DeleteMin();
|
|
||||||
const int distance = _forwardHeap->GetKey(node);
|
|
||||||
if(_backwardHeap->WasInserted(node) && (!stOnSameEdge || distance > 0) ){
|
|
||||||
const int newDistance = _backwardHeap->GetKey(node) + distance;
|
|
||||||
if(newDistance < *_upperbound){
|
|
||||||
*middle = node;
|
|
||||||
*_upperbound = newDistance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(distance > *_upperbound){
|
|
||||||
_forwardHeap->DeleteAll();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( typename GraphT::EdgeIterator edge = _graph->BeginEdges( node ); edge < _graph->EndEdges(node); edge++ ) {
|
|
||||||
const EdgeData & data = _graph->GetEdgeData(edge);
|
|
||||||
bool backwardDirectionFlag = (!forwardDirection) ? data.forward : data.backward;
|
|
||||||
if(backwardDirectionFlag) {
|
|
||||||
const NodeID to = _graph->GetTarget(edge);
|
|
||||||
const int edgeWeight = data.distance;
|
|
||||||
|
|
||||||
assert( edgeWeight > 0 );
|
|
||||||
|
|
||||||
//Stalling
|
|
||||||
if(_forwardHeap->WasInserted( to )) {
|
|
||||||
if(_forwardHeap->GetKey( to ) + edgeWeight < distance) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( typename GraphT::EdgeIterator edge = _graph->BeginEdges( node ); edge < _graph->EndEdges(node); edge++ ) {
|
|
||||||
const EdgeData & data = _graph->GetEdgeData(edge);
|
|
||||||
bool forwardDirectionFlag = (forwardDirection ? data.forward : data.backward );
|
|
||||||
if(forwardDirectionFlag) {
|
|
||||||
|
|
||||||
const NodeID to = _graph->GetTarget(edge);
|
|
||||||
const int edgeWeight = data.distance;
|
|
||||||
|
|
||||||
assert( edgeWeight > 0 );
|
|
||||||
const int toDistance = distance + edgeWeight;
|
|
||||||
|
|
||||||
//New Node discovered -> Add to Heap + Node Info Storage
|
|
||||||
if ( !_forwardHeap->WasInserted( to ) ) {
|
|
||||||
_forwardHeap->Insert( to, toDistance, node );
|
|
||||||
}
|
|
||||||
//Found a shorter Path -> Update distance
|
|
||||||
else if ( toDistance < _forwardHeap->GetKey( to ) ) {
|
|
||||||
_forwardHeap->GetData( to ).parent = node;
|
|
||||||
_forwardHeap->DecreaseKey( to, toDistance );
|
|
||||||
//new parent
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool _UnpackEdge(const NodeID source, const NodeID target, std::vector<_PathData> & path) const {
|
|
||||||
assert(source != target);
|
|
||||||
//find edge first.
|
|
||||||
typename GraphT::EdgeIterator smallestEdge = SPECIAL_EDGEID;
|
|
||||||
int smallestWeight = INT_MAX;
|
|
||||||
for(typename GraphT::EdgeIterator eit = _graph->BeginEdges(source);eit < _graph->EndEdges(source);eit++){
|
|
||||||
const int weight = _graph->GetEdgeData(eit).distance;
|
|
||||||
if(_graph->GetTarget(eit) == target && weight < smallestWeight && _graph->GetEdgeData(eit).forward){
|
|
||||||
smallestEdge = eit;
|
|
||||||
smallestWeight = weight;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(smallestEdge == SPECIAL_EDGEID){
|
|
||||||
for(typename GraphT::EdgeIterator eit = _graph->BeginEdges(target);eit < _graph->EndEdges(target);eit++){
|
|
||||||
const int weight = _graph->GetEdgeData(eit).distance;
|
|
||||||
if(_graph->GetTarget(eit) == source && weight < smallestWeight && _graph->GetEdgeData(eit).backward){
|
|
||||||
smallestEdge = eit;
|
|
||||||
smallestWeight = weight;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(smallestWeight != INT_MAX);
|
|
||||||
|
|
||||||
const EdgeData& ed = _graph->GetEdgeData(smallestEdge);
|
|
||||||
if(ed.shortcut) {//unpack
|
|
||||||
const NodeID middle = ed.via;
|
|
||||||
_UnpackEdge(source, middle, path);
|
|
||||||
_UnpackEdge(middle, target, path);
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
assert(!ed.shortcut);
|
|
||||||
path.push_back(_PathData(ed.via, ed.nameID1, ed.turnInstruction, ed.distance) );
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
template<class EdgeData, class GraphT> HeapPtr SearchEngine<EdgeData, GraphT>::_forwardHeap;
|
|
||||||
template<class EdgeData, class GraphT> HeapPtr SearchEngine<EdgeData, GraphT>::_backwardHeap;
|
|
||||||
|
|
||||||
#endif /* SEARCHENGINE_H_ */
|
#endif // SEARCHENGINE_H
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 "SearchEngineData.h"
|
||||||
|
|
||||||
|
void SearchEngineData::InitializeOrClearFirstThreadLocalStorage(const unsigned number_of_nodes)
|
||||||
|
{
|
||||||
|
if (forwardHeap.get())
|
||||||
|
{
|
||||||
|
forwardHeap->Clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
forwardHeap.reset(new QueryHeap(number_of_nodes));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (backwardHeap.get())
|
||||||
|
{
|
||||||
|
backwardHeap->Clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
backwardHeap.reset(new QueryHeap(number_of_nodes));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SearchEngineData::InitializeOrClearSecondThreadLocalStorage(const unsigned number_of_nodes)
|
||||||
|
{
|
||||||
|
if (forwardHeap2.get())
|
||||||
|
{
|
||||||
|
forwardHeap2->Clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
forwardHeap2.reset(new QueryHeap(number_of_nodes));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (backwardHeap2.get())
|
||||||
|
{
|
||||||
|
backwardHeap2->Clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
backwardHeap2.reset(new QueryHeap(number_of_nodes));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SearchEngineData::InitializeOrClearThirdThreadLocalStorage(const unsigned number_of_nodes)
|
||||||
|
{
|
||||||
|
if (forwardHeap3.get())
|
||||||
|
{
|
||||||
|
forwardHeap3->Clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
forwardHeap3.reset(new QueryHeap(number_of_nodes));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (backwardHeap3.get())
|
||||||
|
{
|
||||||
|
backwardHeap3->Clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
backwardHeap3.reset(new QueryHeap(number_of_nodes));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 SEARCH_ENGINE_DATA_H
|
||||||
|
#define SEARCH_ENGINE_DATA_H
|
||||||
|
|
||||||
|
#include "BinaryHeap.h"
|
||||||
|
#include "QueryEdge.h"
|
||||||
|
#include "StaticGraph.h"
|
||||||
|
|
||||||
|
#include "../typedefs.h"
|
||||||
|
|
||||||
|
#include <boost/thread.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
struct _HeapData {
|
||||||
|
NodeID parent;
|
||||||
|
_HeapData( NodeID p ) : parent(p) { }
|
||||||
|
};
|
||||||
|
|
||||||
|
// typedef StaticGraph<QueryEdge::EdgeData> QueryGraph;
|
||||||
|
|
||||||
|
struct SearchEngineData {
|
||||||
|
typedef BinaryHeap< NodeID, NodeID, int, _HeapData, UnorderedMapStorage<NodeID, int> > QueryHeap;
|
||||||
|
typedef boost::thread_specific_ptr<QueryHeap> SearchEngineHeapPtr;
|
||||||
|
|
||||||
|
static SearchEngineHeapPtr forwardHeap;
|
||||||
|
static SearchEngineHeapPtr backwardHeap;
|
||||||
|
static SearchEngineHeapPtr forwardHeap2;
|
||||||
|
static SearchEngineHeapPtr backwardHeap2;
|
||||||
|
static SearchEngineHeapPtr forwardHeap3;
|
||||||
|
static SearchEngineHeapPtr backwardHeap3;
|
||||||
|
|
||||||
|
void InitializeOrClearFirstThreadLocalStorage(const unsigned number_of_nodes);
|
||||||
|
|
||||||
|
void InitializeOrClearSecondThreadLocalStorage(const unsigned number_of_nodes);
|
||||||
|
|
||||||
|
void InitializeOrClearThirdThreadLocalStorage(const unsigned number_of_nodes);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SEARCH_ENGINE_DATA_H
|
||||||
@@ -1,39 +1,81 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, others 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
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
|
Redistributions of source code must retain the above copyright notice, this list
|
||||||
along with this program; if not, write to the Free Software
|
of conditions and the following disclaimer.
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
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 SEGMENTINFORMATION_H_
|
#ifndef SEGMENTINFORMATION_H_
|
||||||
#define SEGMENTINFORMATION_H_
|
#define SEGMENTINFORMATION_H_
|
||||||
|
|
||||||
#include <climits>
|
#include "TurnInstructions.h"
|
||||||
|
|
||||||
|
#include "../typedefs.h"
|
||||||
|
|
||||||
|
#include <osrm/Coordinate.h>
|
||||||
|
|
||||||
|
// Struct fits everything in one cache line
|
||||||
struct SegmentInformation {
|
struct SegmentInformation {
|
||||||
_Coordinate location;
|
FixedPointCoordinate location;
|
||||||
NodeID nameID;
|
NodeID name_id;
|
||||||
unsigned length;
|
|
||||||
unsigned duration;
|
unsigned duration;
|
||||||
short turnInstruction;
|
double length;
|
||||||
|
short bearing; //more than enough [0..3600] fits into 12 bits
|
||||||
|
TurnInstruction turn_instruction;
|
||||||
bool necessary;
|
bool necessary;
|
||||||
SegmentInformation(const _Coordinate & loc, const NodeID nam, const unsigned len, const unsigned dur, const short tInstr, const bool nec) :
|
|
||||||
location(loc), nameID(nam), length(len), duration(dur), turnInstruction(tInstr), necessary(nec) {}
|
explicit SegmentInformation(
|
||||||
SegmentInformation(const _Coordinate & loc, const NodeID nam, const unsigned len, const unsigned dur, const short tInstr) :
|
const FixedPointCoordinate & location,
|
||||||
location(loc), nameID(nam), length(len), duration(dur), turnInstruction(tInstr), necessary(tInstr != 0) {}
|
const NodeID name_id,
|
||||||
|
const unsigned duration,
|
||||||
|
const double length,
|
||||||
|
const TurnInstruction turn_instruction,
|
||||||
|
const bool necessary
|
||||||
|
) :
|
||||||
|
location(location),
|
||||||
|
name_id(name_id),
|
||||||
|
duration(duration),
|
||||||
|
length(length),
|
||||||
|
bearing(0),
|
||||||
|
turn_instruction(turn_instruction),
|
||||||
|
necessary(necessary)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
explicit SegmentInformation(
|
||||||
|
const FixedPointCoordinate & location,
|
||||||
|
const NodeID name_id,
|
||||||
|
const unsigned duration,
|
||||||
|
const double length,
|
||||||
|
const TurnInstruction turn_instruction
|
||||||
|
) :
|
||||||
|
location(location),
|
||||||
|
name_id(name_id),
|
||||||
|
duration(duration),
|
||||||
|
length(length),
|
||||||
|
bearing(0),
|
||||||
|
turn_instruction(turn_instruction),
|
||||||
|
necessary(turn_instruction != 0)
|
||||||
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SEGMENTINFORMATION_H_ */
|
#endif /* SEGMENTINFORMATION_H_ */
|
||||||
|
|||||||
@@ -0,0 +1,250 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 SHARED_MEMORY_FACTORY_H
|
||||||
|
#define SHARED_MEMORY_FACTORY_H
|
||||||
|
|
||||||
|
#include "../Util/OSRMException.h"
|
||||||
|
#include "../Util/SimpleLogger.h"
|
||||||
|
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <boost/filesystem/fstream.hpp>
|
||||||
|
#include <boost/integer.hpp>
|
||||||
|
#include <boost/interprocess/mapped_region.hpp>
|
||||||
|
#include <boost/interprocess/xsi_shared_memory.hpp>
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
#include <sys/ipc.h>
|
||||||
|
#include <sys/shm.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <exception>
|
||||||
|
|
||||||
|
struct OSRMLockFile {
|
||||||
|
boost::filesystem::path operator()() {
|
||||||
|
boost::filesystem::path temp_dir =
|
||||||
|
boost::filesystem::temp_directory_path();
|
||||||
|
boost::filesystem::path lock_file = temp_dir / "osrm.lock";
|
||||||
|
return lock_file;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class SharedMemory : boost::noncopyable {
|
||||||
|
|
||||||
|
//Remove shared memory on destruction
|
||||||
|
class shm_remove : boost::noncopyable {
|
||||||
|
private:
|
||||||
|
int m_shmid;
|
||||||
|
bool m_initialized;
|
||||||
|
public:
|
||||||
|
void SetID(int shmid) {
|
||||||
|
m_shmid = shmid;
|
||||||
|
m_initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
shm_remove() : m_shmid(INT_MIN), m_initialized(false) {}
|
||||||
|
|
||||||
|
~shm_remove(){
|
||||||
|
if(m_initialized) {
|
||||||
|
SimpleLogger().Write(logDEBUG) <<
|
||||||
|
"automatic memory deallocation";
|
||||||
|
if(!boost::interprocess::xsi_shared_memory::remove(m_shmid)) {
|
||||||
|
SimpleLogger().Write(logDEBUG) << "could not deallocate id " << m_shmid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
void * Ptr() const {
|
||||||
|
return region.get_address();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename IdentifierT >
|
||||||
|
SharedMemory(
|
||||||
|
const boost::filesystem::path & lock_file,
|
||||||
|
const IdentifierT id,
|
||||||
|
const uint64_t size = 0,
|
||||||
|
bool read_write = false,
|
||||||
|
bool remove_prev = true
|
||||||
|
) : key(
|
||||||
|
lock_file.string().c_str(),
|
||||||
|
id
|
||||||
|
) {
|
||||||
|
if( 0 == size ){ //read_only
|
||||||
|
shm = boost::interprocess::xsi_shared_memory (
|
||||||
|
boost::interprocess::open_only,
|
||||||
|
key
|
||||||
|
);
|
||||||
|
|
||||||
|
region = boost::interprocess::mapped_region (
|
||||||
|
shm,
|
||||||
|
(
|
||||||
|
read_write ?
|
||||||
|
boost::interprocess::read_write :
|
||||||
|
boost::interprocess::read_only
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else { //writeable pointer
|
||||||
|
//remove previously allocated mem
|
||||||
|
if( remove_prev ) {
|
||||||
|
Remove(key);
|
||||||
|
}
|
||||||
|
shm = boost::interprocess::xsi_shared_memory (
|
||||||
|
boost::interprocess::open_or_create,
|
||||||
|
key,
|
||||||
|
size
|
||||||
|
);
|
||||||
|
#ifdef __linux__
|
||||||
|
if( -1 == shmctl(shm.get_shmid(), SHM_LOCK, 0) ) {
|
||||||
|
if( ENOMEM == errno ) {
|
||||||
|
SimpleLogger().Write(logWARNING) <<
|
||||||
|
"could not lock shared memory to RAM";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
region = boost::interprocess::mapped_region (
|
||||||
|
shm,
|
||||||
|
boost::interprocess::read_write
|
||||||
|
);
|
||||||
|
|
||||||
|
remover.SetID( shm.get_shmid() );
|
||||||
|
SimpleLogger().Write(logDEBUG) <<
|
||||||
|
"writeable memory allocated " << size << " bytes";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename IdentifierT >
|
||||||
|
static bool RegionExists(
|
||||||
|
const IdentifierT id
|
||||||
|
) {
|
||||||
|
bool result = true;
|
||||||
|
try {
|
||||||
|
OSRMLockFile lock_file;
|
||||||
|
boost::interprocess::xsi_key key( lock_file().string().c_str(), id );
|
||||||
|
result = RegionExists(key);
|
||||||
|
} catch(...) {
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename IdentifierT >
|
||||||
|
static bool Remove(
|
||||||
|
const IdentifierT id
|
||||||
|
) {
|
||||||
|
OSRMLockFile lock_file;
|
||||||
|
boost::interprocess::xsi_key key( lock_file().string().c_str(), id );
|
||||||
|
return Remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static bool RegionExists( const boost::interprocess::xsi_key &key ) {
|
||||||
|
bool result = true;
|
||||||
|
try {
|
||||||
|
boost::interprocess::xsi_shared_memory shm(
|
||||||
|
boost::interprocess::open_only,
|
||||||
|
key
|
||||||
|
);
|
||||||
|
} catch(...) {
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool Remove(
|
||||||
|
const boost::interprocess::xsi_key &key
|
||||||
|
) {
|
||||||
|
bool ret = false;
|
||||||
|
try{
|
||||||
|
SimpleLogger().Write(logDEBUG) << "deallocating prev memory";
|
||||||
|
boost::interprocess::xsi_shared_memory xsi(
|
||||||
|
boost::interprocess::open_only,
|
||||||
|
key
|
||||||
|
);
|
||||||
|
ret = boost::interprocess::xsi_shared_memory::remove(xsi.get_shmid());
|
||||||
|
} catch(const boost::interprocess::interprocess_exception &e){
|
||||||
|
if(e.get_error_code() != boost::interprocess::not_found_error) {
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::interprocess::xsi_key key;
|
||||||
|
boost::interprocess::xsi_shared_memory shm;
|
||||||
|
boost::interprocess::mapped_region region;
|
||||||
|
shm_remove remover;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class LockFileT = OSRMLockFile>
|
||||||
|
class SharedMemoryFactory_tmpl : boost::noncopyable {
|
||||||
|
public:
|
||||||
|
|
||||||
|
template<typename IdentifierT >
|
||||||
|
static SharedMemory * Get(
|
||||||
|
const IdentifierT & id,
|
||||||
|
const uint64_t size = 0,
|
||||||
|
bool read_write = false,
|
||||||
|
bool remove_prev = true
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
LockFileT lock_file;
|
||||||
|
if(!boost::filesystem::exists(lock_file()) ) {
|
||||||
|
if( 0 == size ) {
|
||||||
|
throw OSRMException("lock file does not exist, exiting");
|
||||||
|
} else {
|
||||||
|
boost::filesystem::ofstream ofs(lock_file());
|
||||||
|
ofs.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SharedMemory(
|
||||||
|
lock_file(),
|
||||||
|
id,
|
||||||
|
size,
|
||||||
|
read_write,
|
||||||
|
remove_prev
|
||||||
|
);
|
||||||
|
} catch(const boost::interprocess::interprocess_exception &e){
|
||||||
|
SimpleLogger().Write(logWARNING) <<
|
||||||
|
"caught exception: " << e.what() <<
|
||||||
|
", code " << e.get_error_code();
|
||||||
|
throw OSRMException(e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
SharedMemoryFactory_tmpl() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef SharedMemoryFactory_tmpl<> SharedMemoryFactory;
|
||||||
|
|
||||||
|
#endif /* SHARED_MEMORY_POINTER_FACTORY_H */
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 SHARED_MEMORY_VECTOR_WRAPPER_H
|
||||||
|
#define SHARED_MEMORY_VECTOR_WRAPPER_H
|
||||||
|
|
||||||
|
#include "../Util/SimpleLogger.h"
|
||||||
|
|
||||||
|
#include <boost/assert.hpp>
|
||||||
|
#include <boost/type_traits.hpp>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <iterator>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
template<typename DataT>
|
||||||
|
class ShMemIterator : public std::iterator<std::input_iterator_tag, DataT> {
|
||||||
|
DataT * p;
|
||||||
|
public:
|
||||||
|
ShMemIterator(DataT * x) : p(x) {}
|
||||||
|
ShMemIterator(const ShMemIterator & mit) : p(mit.p) {}
|
||||||
|
ShMemIterator& operator++() {
|
||||||
|
++p;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
ShMemIterator operator++(int) {
|
||||||
|
ShMemIterator tmp(*this);
|
||||||
|
operator++();
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
ShMemIterator operator+(std::ptrdiff_t diff) {
|
||||||
|
ShMemIterator tmp(p+diff);
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
bool operator==(const ShMemIterator& rhs) {
|
||||||
|
return p==rhs.p;
|
||||||
|
}
|
||||||
|
bool operator!=(const ShMemIterator& rhs) {
|
||||||
|
return p!=rhs.p;
|
||||||
|
}
|
||||||
|
DataT& operator*() {
|
||||||
|
return *p;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename DataT>
|
||||||
|
class SharedMemoryWrapper {
|
||||||
|
private:
|
||||||
|
DataT * m_ptr;
|
||||||
|
std::size_t m_size;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SharedMemoryWrapper() :
|
||||||
|
m_ptr(NULL),
|
||||||
|
m_size(0)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
SharedMemoryWrapper(DataT * ptr, std::size_t size) :
|
||||||
|
m_ptr(ptr),
|
||||||
|
m_size(size)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void swap( SharedMemoryWrapper<DataT> & other ) {
|
||||||
|
BOOST_ASSERT_MSG(m_size != 0 || other.size() != 0, "size invalid");
|
||||||
|
std::swap( m_size, other.m_size);
|
||||||
|
std::swap( m_ptr , other.m_ptr );
|
||||||
|
}
|
||||||
|
|
||||||
|
// void SetData(const DataT * ptr, const std::size_t size) {
|
||||||
|
// BOOST_ASSERT_MSG( 0 == m_size, "vector not empty");
|
||||||
|
// BOOST_ASSERT_MSG( 0 < size , "new vector empty");
|
||||||
|
// m_ptr.reset(ptr);
|
||||||
|
// m_size = size;
|
||||||
|
// }
|
||||||
|
|
||||||
|
DataT & at(const std::size_t index) {
|
||||||
|
return m_ptr[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
const DataT & at(const std::size_t index) const {
|
||||||
|
return m_ptr[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
ShMemIterator<DataT> begin() const {
|
||||||
|
return ShMemIterator<DataT>(m_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
ShMemIterator<DataT> end() const {
|
||||||
|
return ShMemIterator<DataT>(m_ptr+m_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t size() const { return m_size; }
|
||||||
|
|
||||||
|
DataT & operator[](const unsigned index) {
|
||||||
|
BOOST_ASSERT_MSG(index < m_size, "invalid size");
|
||||||
|
return m_ptr[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
const DataT & operator[](const unsigned index) const {
|
||||||
|
BOOST_ASSERT_MSG(index < m_size, "invalid size");
|
||||||
|
return m_ptr[index];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename DataT, bool UseSharedMemory>
|
||||||
|
struct ShM {
|
||||||
|
typedef typename boost::conditional<
|
||||||
|
UseSharedMemory,
|
||||||
|
SharedMemoryWrapper<DataT>,
|
||||||
|
std::vector<DataT>
|
||||||
|
>::type vector;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //SHARED_MEMORY_VECTOR_WRAPPER_H
|
||||||
@@ -1,37 +1,42 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, others 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
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
|
Redistributions of source code must retain the above copyright notice, this list
|
||||||
along with this program; if not, write to the Free Software
|
of conditions and the following disclaimer.
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
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 STATICGRAPH_H_INCLUDED
|
#ifndef STATICGRAPH_H_INCLUDED
|
||||||
#define STATICGRAPH_H_INCLUDED
|
#define STATICGRAPH_H_INCLUDED
|
||||||
|
|
||||||
#include <vector>
|
#include "../DataStructures/Percent.h"
|
||||||
#ifdef _GLIBCXX_PARALLEL
|
#include "../DataStructures/SharedMemoryVectorWrapper.h"
|
||||||
#include <parallel/algorithm>
|
#include "../Util/SimpleLogger.h"
|
||||||
#else
|
|
||||||
#include <algorithm>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
#include "ImportEdge.h"
|
|
||||||
|
|
||||||
template< typename EdgeDataT>
|
#include <algorithm>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
template< typename EdgeDataT, bool UseSharedMemory = false>
|
||||||
class StaticGraph {
|
class StaticGraph {
|
||||||
public:
|
public:
|
||||||
typedef NodeID NodeIterator;
|
typedef NodeID NodeIterator;
|
||||||
@@ -43,18 +48,25 @@ public:
|
|||||||
NodeIterator source;
|
NodeIterator source;
|
||||||
NodeIterator target;
|
NodeIterator target;
|
||||||
bool operator<( const InputEdge& right ) const {
|
bool operator<( const InputEdge& right ) const {
|
||||||
if ( source != right.source )
|
if ( source != right.source ) {
|
||||||
return source < right.source;
|
return source < right.source;
|
||||||
|
}
|
||||||
return target < right.target;
|
return target < right.target;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct _StrNode {
|
||||||
|
//index of the first edge
|
||||||
|
EdgeIterator firstEdge;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _StrEdge {
|
||||||
|
NodeID target;
|
||||||
|
EdgeDataT data;
|
||||||
|
};
|
||||||
|
|
||||||
StaticGraph( const int nodes, std::vector< InputEdge > &graph ) {
|
StaticGraph( const int nodes, std::vector< InputEdge > &graph ) {
|
||||||
#ifdef _GLIBCXX_PARALLEL
|
|
||||||
__gnu_parallel::sort( graph.begin(), graph.end() );
|
|
||||||
#else
|
|
||||||
std::sort( graph.begin(), graph.end() );
|
std::sort( graph.begin(), graph.end() );
|
||||||
#endif
|
|
||||||
_numNodes = nodes;
|
_numNodes = nodes;
|
||||||
_numEdges = ( EdgeIterator ) graph.size();
|
_numEdges = ( EdgeIterator ) graph.size();
|
||||||
_nodes.resize( _numNodes + 1);
|
_nodes.resize( _numNodes + 1);
|
||||||
@@ -79,6 +91,45 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StaticGraph(
|
||||||
|
typename ShM<_StrNode, UseSharedMemory>::vector & nodes,
|
||||||
|
typename ShM<_StrEdge, UseSharedMemory>::vector & edges
|
||||||
|
) {
|
||||||
|
_numNodes = nodes.size()-1;
|
||||||
|
_numEdges = edges.size();
|
||||||
|
|
||||||
|
_nodes.swap(nodes);
|
||||||
|
_edges.swap(edges);
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
Percent p(GetNumberOfNodes());
|
||||||
|
for(unsigned u = 0; u < GetNumberOfNodes(); ++u) {
|
||||||
|
for(unsigned eid = BeginEdges(u); eid < EndEdges(u); ++eid) {
|
||||||
|
unsigned v = GetTarget(eid);
|
||||||
|
EdgeData & data = GetEdgeData(eid);
|
||||||
|
if(data.shortcut) {
|
||||||
|
unsigned eid2 = FindEdgeInEitherDirection(u, data.id);
|
||||||
|
if(eid2 == UINT_MAX) {
|
||||||
|
SimpleLogger().Write(logWARNING) <<
|
||||||
|
"cannot find first segment of edge (" <<
|
||||||
|
u << "," << data.id << "," << v << ")";
|
||||||
|
|
||||||
|
data.shortcut = false;
|
||||||
|
}
|
||||||
|
eid2 = FindEdgeInEitherDirection(data.id, v);
|
||||||
|
if(eid2 == UINT_MAX) {
|
||||||
|
SimpleLogger().Write(logWARNING) <<
|
||||||
|
"cannot find second segment of edge (" <<
|
||||||
|
u << "," << data.id << "," << v << ")";
|
||||||
|
data.shortcut = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.printIncrement();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
unsigned GetNumberOfNodes() const {
|
unsigned GetNumberOfNodes() const {
|
||||||
return _numNodes;
|
return _numNodes;
|
||||||
}
|
}
|
||||||
@@ -87,32 +138,32 @@ public:
|
|||||||
return _numEdges;
|
return _numEdges;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned GetOutDegree( const NodeIterator &n ) const {
|
unsigned GetOutDegree( const NodeIterator n ) const {
|
||||||
return BeginEdges(n)-EndEdges(n) - 1;
|
return BeginEdges(n)-EndEdges(n) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline NodeIterator GetTarget( const EdgeIterator &e ) const {
|
inline NodeIterator GetTarget( const EdgeIterator e ) const {
|
||||||
return NodeIterator( _edges[e].target );
|
return NodeIterator( _edges[e].target );
|
||||||
}
|
}
|
||||||
|
|
||||||
inline EdgeDataT &GetEdgeData( const EdgeIterator &e ) {
|
inline EdgeDataT &GetEdgeData( const EdgeIterator e ) {
|
||||||
return _edges[e].data;
|
return _edges[e].data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const EdgeDataT &GetEdgeData( const EdgeIterator &e ) const {
|
const EdgeDataT &GetEdgeData( const EdgeIterator e ) const {
|
||||||
return _edges[e].data;
|
return _edges[e].data;
|
||||||
}
|
}
|
||||||
|
|
||||||
EdgeIterator BeginEdges( const NodeIterator &n ) const {
|
EdgeIterator BeginEdges( const NodeIterator n ) const {
|
||||||
return EdgeIterator( _nodes[n].firstEdge );
|
return EdgeIterator( _nodes[n].firstEdge );
|
||||||
}
|
}
|
||||||
|
|
||||||
EdgeIterator EndEdges( const NodeIterator &n ) const {
|
EdgeIterator EndEdges( const NodeIterator n ) const {
|
||||||
return EdgeIterator( _nodes[n+1].firstEdge );
|
return EdgeIterator( _nodes[n+1].firstEdge );
|
||||||
}
|
}
|
||||||
|
|
||||||
//searches for a specific edge
|
//searches for a specific edge
|
||||||
EdgeIterator FindEdge( const NodeIterator &from, const NodeIterator &to ) const {
|
EdgeIterator FindEdge( const NodeIterator from, const NodeIterator to ) const {
|
||||||
EdgeIterator smallestEdge = SPECIAL_EDGEID;
|
EdgeIterator smallestEdge = SPECIAL_EDGEID;
|
||||||
EdgeWeight smallestWeight = UINT_MAX;
|
EdgeWeight smallestWeight = UINT_MAX;
|
||||||
for ( EdgeIterator edge = BeginEdges( from ); edge < EndEdges(from); edge++ ) {
|
for ( EdgeIterator edge = BeginEdges( from ); edge < EndEdges(from); edge++ ) {
|
||||||
@@ -125,38 +176,29 @@ public:
|
|||||||
return smallestEdge;
|
return smallestEdge;
|
||||||
}
|
}
|
||||||
|
|
||||||
EdgeIterator FindEdgeInEitherDirection( const NodeIterator &from, const NodeIterator &to ) const {
|
EdgeIterator FindEdgeInEitherDirection( const NodeIterator from, const NodeIterator to ) const {
|
||||||
EdgeIterator tmp = FindEdge( from, to );
|
EdgeIterator tmp = FindEdge( from, to );
|
||||||
return (UINT_MAX != tmp ? tmp : FindEdge( to, from ));
|
return (UINT_MAX != tmp ? tmp : FindEdge( to, from ));
|
||||||
}
|
}
|
||||||
|
|
||||||
EdgeIterator FindEdgeIndicateIfReverse( const NodeIterator &from, const NodeIterator &to, bool & result ) const {
|
EdgeIterator FindEdgeIndicateIfReverse( const NodeIterator from, const NodeIterator to, bool & result ) const {
|
||||||
EdgeIterator tmp = FindEdge( from, to );
|
EdgeIterator tmp = FindEdge( from, to );
|
||||||
if(UINT_MAX == tmp) {
|
if(UINT_MAX == tmp) {
|
||||||
tmp = FindEdge( to, from );
|
tmp = FindEdge( to, from );
|
||||||
if(UINT_MAX != tmp)
|
if(UINT_MAX != tmp) {
|
||||||
result = true;
|
result = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
struct _StrNode {
|
|
||||||
//index of the first edge
|
|
||||||
EdgeIterator firstEdge;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _StrEdge {
|
|
||||||
NodeID target;
|
|
||||||
EdgeDataT data;
|
|
||||||
};
|
|
||||||
|
|
||||||
NodeIterator _numNodes;
|
NodeIterator _numNodes;
|
||||||
EdgeIterator _numEdges;
|
EdgeIterator _numEdges;
|
||||||
|
|
||||||
std::vector< _StrNode > _nodes;
|
typename ShM< _StrNode, UseSharedMemory >::vector _nodes;
|
||||||
std::vector< _StrEdge > _edges;
|
typename ShM< _StrEdge, UseSharedMemory >::vector _edges;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // STATICGRAPH_H_INCLUDED
|
#endif // STATICGRAPH_H_INCLUDED
|
||||||
|
|||||||
@@ -1,34 +1,38 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, others 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
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
|
Redistributions of source code must retain the above copyright notice, this list
|
||||||
along with this program; if not, write to the Free Software
|
of conditions and the following disclaimer.
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
list of conditions and the following disclaimer in the documentation and/or
|
||||||
|
other materials provided with the distribution.
|
||||||
|
|
||||||
KD Tree coded by Christian Vetter, Monav Project
|
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.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// KD Tree coded by Christian Vetter, Monav Project
|
||||||
|
|
||||||
*/
|
|
||||||
#ifndef STATICKDTREE_H_INCLUDED
|
#ifndef STATICKDTREE_H_INCLUDED
|
||||||
#define STATICKDTREE_H_INCLUDED
|
#define STATICKDTREE_H_INCLUDED
|
||||||
|
|
||||||
|
#include <boost/assert.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#ifdef _GLIBCXX_PARALLEL
|
|
||||||
#include <parallel/algorithm>
|
|
||||||
#else
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#endif
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
@@ -96,8 +100,8 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
StaticKDTree( std::vector< InputPoint > * points ){
|
StaticKDTree( std::vector< InputPoint > * points ){
|
||||||
assert( k > 0 );
|
BOOST_ASSERT( k > 0 );
|
||||||
assert ( points->size() > 0 );
|
BOOST_ASSERT ( points->size() > 0 );
|
||||||
size = points->size();
|
size = points->size();
|
||||||
kdtree = new InputPoint[size];
|
kdtree = new InputPoint[size];
|
||||||
for ( Iterator i = 0; i != size; ++i ) {
|
for ( Iterator i = 0; i != size; ++i ) {
|
||||||
@@ -119,11 +123,7 @@ public:
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
Iterator middle = tree.left + ( tree.right - tree.left ) / 2;
|
Iterator middle = tree.left + ( tree.right - tree.left ) / 2;
|
||||||
#ifdef _GLIBCXX_PARALLEL
|
|
||||||
__gnu_parallel::nth_element( kdtree + tree.left, kdtree + middle, kdtree + tree.right, Less( tree.dimension ) );
|
|
||||||
#else
|
|
||||||
std::nth_element( kdtree + tree.left, kdtree + middle, kdtree + tree.right, Less( tree.dimension ) );
|
std::nth_element( kdtree + tree.left, kdtree + middle, kdtree + tree.right, Less( tree.dimension ) );
|
||||||
#endif
|
|
||||||
s.push( Tree( tree.left, middle, ( tree.dimension + 1 ) % k ) );
|
s.push( Tree( tree.left, middle, ( tree.dimension + 1 ) % k ) );
|
||||||
s.push( Tree( middle + 1, tree.right, ( tree.dimension + 1 ) % k ) );
|
s.push( Tree( middle + 1, tree.right, ( tree.dimension + 1 ) % k ) );
|
||||||
}
|
}
|
||||||
@@ -209,11 +209,11 @@ private:
|
|||||||
public:
|
public:
|
||||||
Less( unsigned d ) {
|
Less( unsigned d ) {
|
||||||
dimension = d;
|
dimension = d;
|
||||||
assert( dimension < k );
|
BOOST_ASSERT( dimension < k );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator() ( const InputPoint& left, const InputPoint& right ) {
|
bool operator() ( const InputPoint& left, const InputPoint& right ) {
|
||||||
assert( dimension < k );
|
BOOST_ASSERT( dimension < k );
|
||||||
return left.coordinates[dimension] < right.coordinates[dimension];
|
return left.coordinates[dimension] < right.coordinates[dimension];
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -0,0 +1,937 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 STATICRTREE_H_
|
||||||
|
#define STATICRTREE_H_
|
||||||
|
|
||||||
|
#include "DeallocatingVector.h"
|
||||||
|
#include "HilbertValue.h"
|
||||||
|
#include "PhantomNodes.h"
|
||||||
|
#include "SharedMemoryFactory.h"
|
||||||
|
#include "SharedMemoryVectorWrapper.h"
|
||||||
|
|
||||||
|
#include "../Util/MercatorUtil.h"
|
||||||
|
#include "../Util/OSRMException.h"
|
||||||
|
#include "../Util/SimpleLogger.h"
|
||||||
|
#include "../Util/TimingUtil.h"
|
||||||
|
#include "../typedefs.h"
|
||||||
|
|
||||||
|
#include <osrm/Coordinate.h>
|
||||||
|
|
||||||
|
#include <boost/assert.hpp>
|
||||||
|
#include <boost/bind.hpp>
|
||||||
|
#include <boost/foreach.hpp>
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <boost/filesystem/fstream.hpp>
|
||||||
|
#include <boost/algorithm/minmax.hpp>
|
||||||
|
#include <boost/algorithm/minmax_element.hpp>
|
||||||
|
#include <boost/range/algorithm_ext/erase.hpp>
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
|
#include <boost/thread.hpp>
|
||||||
|
#include <boost/type_traits.hpp>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <limits>
|
||||||
|
#include <queue>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
//tuning parameters
|
||||||
|
const static uint32_t RTREE_BRANCHING_FACTOR = 50;
|
||||||
|
const static uint32_t RTREE_LEAF_NODE_SIZE = 1170;
|
||||||
|
|
||||||
|
// Implements a static, i.e. packed, R-tree
|
||||||
|
|
||||||
|
static boost::thread_specific_ptr<boost::filesystem::ifstream> thread_local_rtree_stream;
|
||||||
|
|
||||||
|
template<class DataT, bool UseSharedMemory = false>
|
||||||
|
class StaticRTree : boost::noncopyable {
|
||||||
|
public:
|
||||||
|
struct RectangleInt2D {
|
||||||
|
RectangleInt2D() :
|
||||||
|
min_lon(INT_MAX),
|
||||||
|
max_lon(INT_MIN),
|
||||||
|
min_lat(INT_MAX),
|
||||||
|
max_lat(INT_MIN) {}
|
||||||
|
|
||||||
|
int32_t min_lon, max_lon;
|
||||||
|
int32_t min_lat, max_lat;
|
||||||
|
|
||||||
|
inline void InitializeMBRectangle(
|
||||||
|
const DataT * objects,
|
||||||
|
const uint32_t element_count
|
||||||
|
) {
|
||||||
|
for(uint32_t i = 0; i < element_count; ++i) {
|
||||||
|
min_lon = std::min(
|
||||||
|
min_lon, std::min(objects[i].lon1, objects[i].lon2)
|
||||||
|
);
|
||||||
|
max_lon = std::max(
|
||||||
|
max_lon, std::max(objects[i].lon1, objects[i].lon2)
|
||||||
|
);
|
||||||
|
|
||||||
|
min_lat = std::min(
|
||||||
|
min_lat, std::min(objects[i].lat1, objects[i].lat2)
|
||||||
|
);
|
||||||
|
max_lat = std::max(
|
||||||
|
max_lat, std::max(objects[i].lat1, objects[i].lat2)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void AugmentMBRectangle(const RectangleInt2D & other) {
|
||||||
|
min_lon = std::min(min_lon, other.min_lon);
|
||||||
|
max_lon = std::max(max_lon, other.max_lon);
|
||||||
|
min_lat = std::min(min_lat, other.min_lat);
|
||||||
|
max_lat = std::max(max_lat, other.max_lat);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline FixedPointCoordinate Centroid() const {
|
||||||
|
FixedPointCoordinate centroid;
|
||||||
|
//The coordinates of the midpoints are given by:
|
||||||
|
//x = (x1 + x2) /2 and y = (y1 + y2) /2.
|
||||||
|
centroid.lon = (min_lon + max_lon)/2;
|
||||||
|
centroid.lat = (min_lat + max_lat)/2;
|
||||||
|
return centroid;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool Intersects(const RectangleInt2D & other) const {
|
||||||
|
FixedPointCoordinate upper_left (other.max_lat, other.min_lon);
|
||||||
|
FixedPointCoordinate upper_right(other.max_lat, other.max_lon);
|
||||||
|
FixedPointCoordinate lower_right(other.min_lat, other.max_lon);
|
||||||
|
FixedPointCoordinate lower_left (other.min_lat, other.min_lon);
|
||||||
|
|
||||||
|
return (
|
||||||
|
Contains(upper_left ) ||
|
||||||
|
Contains(upper_right) ||
|
||||||
|
Contains(lower_right) ||
|
||||||
|
Contains(lower_left )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline double GetMinDist(const FixedPointCoordinate & location) const {
|
||||||
|
bool is_contained = Contains(location);
|
||||||
|
if (is_contained) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
double min_dist = std::numeric_limits<double>::max();
|
||||||
|
min_dist = std::min(
|
||||||
|
min_dist,
|
||||||
|
FixedPointCoordinate::ApproximateDistance(
|
||||||
|
location.lat,
|
||||||
|
location.lon,
|
||||||
|
max_lat,
|
||||||
|
min_lon
|
||||||
|
)
|
||||||
|
);
|
||||||
|
min_dist = std::min(
|
||||||
|
min_dist,
|
||||||
|
FixedPointCoordinate::ApproximateDistance(
|
||||||
|
location.lat,
|
||||||
|
location.lon,
|
||||||
|
max_lat,
|
||||||
|
max_lon
|
||||||
|
)
|
||||||
|
);
|
||||||
|
min_dist = std::min(
|
||||||
|
min_dist,
|
||||||
|
FixedPointCoordinate::ApproximateDistance(
|
||||||
|
location.lat,
|
||||||
|
location.lon,
|
||||||
|
min_lat,
|
||||||
|
max_lon
|
||||||
|
)
|
||||||
|
);
|
||||||
|
min_dist = std::min(
|
||||||
|
min_dist,
|
||||||
|
FixedPointCoordinate::ApproximateDistance(
|
||||||
|
location.lat,
|
||||||
|
location.lon,
|
||||||
|
min_lat,
|
||||||
|
min_lon
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return min_dist;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline double GetMinMaxDist(const FixedPointCoordinate & location) const {
|
||||||
|
double min_max_dist = std::numeric_limits<double>::max();
|
||||||
|
//Get minmax distance to each of the four sides
|
||||||
|
FixedPointCoordinate upper_left (max_lat, min_lon);
|
||||||
|
FixedPointCoordinate upper_right(max_lat, max_lon);
|
||||||
|
FixedPointCoordinate lower_right(min_lat, max_lon);
|
||||||
|
FixedPointCoordinate lower_left (min_lat, min_lon);
|
||||||
|
|
||||||
|
min_max_dist = std::min(
|
||||||
|
min_max_dist,
|
||||||
|
std::max(
|
||||||
|
FixedPointCoordinate::ApproximateDistance(location, upper_left ),
|
||||||
|
FixedPointCoordinate::ApproximateDistance(location, upper_right)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
min_max_dist = std::min(
|
||||||
|
min_max_dist,
|
||||||
|
std::max(
|
||||||
|
FixedPointCoordinate::ApproximateDistance(location, upper_right),
|
||||||
|
FixedPointCoordinate::ApproximateDistance(location, lower_right)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
min_max_dist = std::min(
|
||||||
|
min_max_dist,
|
||||||
|
std::max(
|
||||||
|
FixedPointCoordinate::ApproximateDistance(location, lower_right),
|
||||||
|
FixedPointCoordinate::ApproximateDistance(location, lower_left )
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
min_max_dist = std::min(
|
||||||
|
min_max_dist,
|
||||||
|
std::max(
|
||||||
|
FixedPointCoordinate::ApproximateDistance(location, lower_left ),
|
||||||
|
FixedPointCoordinate::ApproximateDistance(location, upper_left )
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return min_max_dist;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool Contains(const FixedPointCoordinate & location) const {
|
||||||
|
bool lats_contained =
|
||||||
|
(location.lat > min_lat) && (location.lat < max_lat);
|
||||||
|
bool lons_contained =
|
||||||
|
(location.lon > min_lon) && (location.lon < max_lon);
|
||||||
|
return lats_contained && lons_contained;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline friend std::ostream & operator<< (
|
||||||
|
std::ostream & out,
|
||||||
|
const RectangleInt2D & rect
|
||||||
|
) {
|
||||||
|
out << rect.min_lat/COORDINATE_PRECISION << ","
|
||||||
|
<< rect.min_lon/COORDINATE_PRECISION << " "
|
||||||
|
<< rect.max_lat/COORDINATE_PRECISION << ","
|
||||||
|
<< rect.max_lon/COORDINATE_PRECISION;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef RectangleInt2D RectangleT;
|
||||||
|
|
||||||
|
struct TreeNode {
|
||||||
|
TreeNode() : child_count(0), child_is_on_disk(false) {}
|
||||||
|
RectangleT minimum_bounding_rectangle;
|
||||||
|
uint32_t child_count:31;
|
||||||
|
bool child_is_on_disk:1;
|
||||||
|
uint32_t children[RTREE_BRANCHING_FACTOR];
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
struct WrappedInputElement {
|
||||||
|
explicit WrappedInputElement(
|
||||||
|
const uint32_t _array_index,
|
||||||
|
const uint64_t _hilbert_value
|
||||||
|
) : m_array_index(_array_index), m_hilbert_value(_hilbert_value) {}
|
||||||
|
|
||||||
|
WrappedInputElement() : m_array_index(UINT_MAX), m_hilbert_value(0) {}
|
||||||
|
|
||||||
|
uint32_t m_array_index;
|
||||||
|
uint64_t m_hilbert_value;
|
||||||
|
|
||||||
|
inline bool operator<(const WrappedInputElement & other) const {
|
||||||
|
return m_hilbert_value < other.m_hilbert_value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LeafNode {
|
||||||
|
LeafNode() : object_count(0) {}
|
||||||
|
uint32_t object_count;
|
||||||
|
DataT objects[RTREE_LEAF_NODE_SIZE];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct QueryCandidate {
|
||||||
|
explicit QueryCandidate(
|
||||||
|
const uint32_t n_id,
|
||||||
|
const double dist
|
||||||
|
) : node_id(n_id), min_dist(dist) {}
|
||||||
|
QueryCandidate() : node_id(UINT_MAX), min_dist(std::numeric_limits<double>::max()) {}
|
||||||
|
uint32_t node_id;
|
||||||
|
double min_dist;
|
||||||
|
inline bool operator<(const QueryCandidate & other) const {
|
||||||
|
return min_dist < other.min_dist;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typename ShM<TreeNode, UseSharedMemory>::vector m_search_tree;
|
||||||
|
uint64_t m_element_count;
|
||||||
|
|
||||||
|
const std::string m_leaf_node_filename;
|
||||||
|
public:
|
||||||
|
//Construct a packed Hilbert-R-Tree with Kamel-Faloutsos algorithm [1]
|
||||||
|
explicit StaticRTree(
|
||||||
|
std::vector<DataT> & input_data_vector,
|
||||||
|
const std::string tree_node_filename,
|
||||||
|
const std::string leaf_node_filename
|
||||||
|
)
|
||||||
|
: m_element_count(input_data_vector.size()),
|
||||||
|
m_leaf_node_filename(leaf_node_filename)
|
||||||
|
{
|
||||||
|
SimpleLogger().Write() <<
|
||||||
|
"constructing r-tree of " << m_element_count <<
|
||||||
|
" elements";
|
||||||
|
|
||||||
|
double time1 = get_timestamp();
|
||||||
|
std::vector<WrappedInputElement> input_wrapper_vector(m_element_count);
|
||||||
|
|
||||||
|
HilbertCode get_hilbert_number;
|
||||||
|
|
||||||
|
//generate auxiliary vector of hilbert-values
|
||||||
|
#pragma omp parallel for schedule(guided)
|
||||||
|
for(uint64_t element_counter = 0; element_counter < m_element_count; ++element_counter) {
|
||||||
|
input_wrapper_vector[element_counter].m_array_index = element_counter;
|
||||||
|
//Get Hilbert-Value for centroid in mercartor projection
|
||||||
|
DataT & current_element = input_data_vector[element_counter];
|
||||||
|
FixedPointCoordinate current_centroid = current_element.Centroid();
|
||||||
|
current_centroid.lat = COORDINATE_PRECISION*lat2y(current_centroid.lat/COORDINATE_PRECISION);
|
||||||
|
|
||||||
|
uint64_t current_hilbert_value = get_hilbert_number(current_centroid);
|
||||||
|
input_wrapper_vector[element_counter].m_hilbert_value = current_hilbert_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
//open leaf file
|
||||||
|
boost::filesystem::ofstream leaf_node_file(leaf_node_filename, std::ios::binary);
|
||||||
|
leaf_node_file.write((char*) &m_element_count, sizeof(uint64_t));
|
||||||
|
|
||||||
|
//sort the hilbert-value representatives
|
||||||
|
std::sort(input_wrapper_vector.begin(), input_wrapper_vector.end());
|
||||||
|
std::vector<TreeNode> tree_nodes_in_level;
|
||||||
|
|
||||||
|
//pack M elements into leaf node and write to leaf file
|
||||||
|
uint64_t processed_objects_count = 0;
|
||||||
|
while(processed_objects_count < m_element_count) {
|
||||||
|
|
||||||
|
LeafNode current_leaf;
|
||||||
|
TreeNode current_node;
|
||||||
|
//SimpleLogger().Write() << "reading " << tree_size << " tree nodes in " << (sizeof(TreeNode)*tree_size) << " bytes";
|
||||||
|
for(uint32_t current_element_index = 0; RTREE_LEAF_NODE_SIZE > current_element_index; ++current_element_index) {
|
||||||
|
if(m_element_count > (processed_objects_count + current_element_index)) {
|
||||||
|
uint32_t index_of_next_object = input_wrapper_vector[processed_objects_count + current_element_index].m_array_index;
|
||||||
|
current_leaf.objects[current_element_index] = input_data_vector[index_of_next_object];
|
||||||
|
++current_leaf.object_count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//generate tree node that resemble the objects in leaf and store it for next level
|
||||||
|
current_node.minimum_bounding_rectangle.InitializeMBRectangle(current_leaf.objects, current_leaf.object_count);
|
||||||
|
current_node.child_is_on_disk = true;
|
||||||
|
current_node.children[0] = tree_nodes_in_level.size();
|
||||||
|
tree_nodes_in_level.push_back(current_node);
|
||||||
|
|
||||||
|
//write leaf_node to leaf node file
|
||||||
|
leaf_node_file.write((char*)¤t_leaf, sizeof(current_leaf));
|
||||||
|
processed_objects_count += current_leaf.object_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
//close leaf file
|
||||||
|
leaf_node_file.close();
|
||||||
|
|
||||||
|
uint32_t processing_level = 0;
|
||||||
|
while(1 < tree_nodes_in_level.size()) {
|
||||||
|
std::vector<TreeNode> tree_nodes_in_next_level;
|
||||||
|
uint32_t processed_tree_nodes_in_level = 0;
|
||||||
|
while(processed_tree_nodes_in_level < tree_nodes_in_level.size()) {
|
||||||
|
TreeNode parent_node;
|
||||||
|
//pack RTREE_BRANCHING_FACTOR elements into tree_nodes each
|
||||||
|
for(
|
||||||
|
uint32_t current_child_node_index = 0;
|
||||||
|
RTREE_BRANCHING_FACTOR > current_child_node_index;
|
||||||
|
++current_child_node_index
|
||||||
|
) {
|
||||||
|
if(processed_tree_nodes_in_level < tree_nodes_in_level.size()) {
|
||||||
|
TreeNode & current_child_node = tree_nodes_in_level[processed_tree_nodes_in_level];
|
||||||
|
//add tree node to parent entry
|
||||||
|
parent_node.children[current_child_node_index] = m_search_tree.size();
|
||||||
|
m_search_tree.push_back(current_child_node);
|
||||||
|
//augment MBR of parent
|
||||||
|
parent_node.minimum_bounding_rectangle.AugmentMBRectangle(current_child_node.minimum_bounding_rectangle);
|
||||||
|
//increase counters
|
||||||
|
++parent_node.child_count;
|
||||||
|
++processed_tree_nodes_in_level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tree_nodes_in_next_level.push_back(parent_node);
|
||||||
|
}
|
||||||
|
tree_nodes_in_level.swap(tree_nodes_in_next_level);
|
||||||
|
++processing_level;
|
||||||
|
}
|
||||||
|
BOOST_ASSERT_MSG(1 == tree_nodes_in_level.size(), "tree broken, more than one root node");
|
||||||
|
//last remaining entry is the root node, store it
|
||||||
|
m_search_tree.push_back(tree_nodes_in_level[0]);
|
||||||
|
|
||||||
|
//reverse and renumber tree to have root at index 0
|
||||||
|
std::reverse(m_search_tree.begin(), m_search_tree.end());
|
||||||
|
|
||||||
|
#pragma omp parallel for schedule(guided)
|
||||||
|
for(uint32_t i = 0; i < m_search_tree.size(); ++i) {
|
||||||
|
TreeNode & current_tree_node = m_search_tree[i];
|
||||||
|
for(uint32_t j = 0; j < current_tree_node.child_count; ++j) {
|
||||||
|
const uint32_t old_id = current_tree_node.children[j];
|
||||||
|
const uint32_t new_id = m_search_tree.size() - old_id - 1;
|
||||||
|
current_tree_node.children[j] = new_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//open tree file
|
||||||
|
boost::filesystem::ofstream tree_node_file(
|
||||||
|
tree_node_filename,
|
||||||
|
std::ios::binary
|
||||||
|
);
|
||||||
|
|
||||||
|
uint32_t size_of_tree = m_search_tree.size();
|
||||||
|
BOOST_ASSERT_MSG(0 < size_of_tree, "tree empty");
|
||||||
|
tree_node_file.write((char *)&size_of_tree, sizeof(uint32_t));
|
||||||
|
tree_node_file.write((char *)&m_search_tree[0], sizeof(TreeNode)*size_of_tree);
|
||||||
|
//close tree node file.
|
||||||
|
tree_node_file.close();
|
||||||
|
double time2 = get_timestamp();
|
||||||
|
SimpleLogger().Write() <<
|
||||||
|
"finished r-tree construction in " << (time2-time1) << " seconds";
|
||||||
|
}
|
||||||
|
|
||||||
|
//Read-only operation for queries
|
||||||
|
explicit StaticRTree(
|
||||||
|
const boost::filesystem::path & node_file,
|
||||||
|
const boost::filesystem::path & leaf_file
|
||||||
|
) : m_leaf_node_filename(leaf_file.string()) {
|
||||||
|
//open tree node file and load into RAM.
|
||||||
|
|
||||||
|
if ( !boost::filesystem::exists( node_file ) ) {
|
||||||
|
throw OSRMException("ram index file does not exist");
|
||||||
|
}
|
||||||
|
if ( 0 == boost::filesystem::file_size( node_file ) ) {
|
||||||
|
throw OSRMException("ram index file is empty");
|
||||||
|
}
|
||||||
|
boost::filesystem::ifstream tree_node_file( node_file, std::ios::binary );
|
||||||
|
|
||||||
|
uint32_t tree_size = 0;
|
||||||
|
tree_node_file.read((char*)&tree_size, sizeof(uint32_t));
|
||||||
|
|
||||||
|
m_search_tree.resize(tree_size);
|
||||||
|
tree_node_file.read((char*)&m_search_tree[0], sizeof(TreeNode)*tree_size);
|
||||||
|
tree_node_file.close();
|
||||||
|
//open leaf node file and store thread specific pointer
|
||||||
|
if ( !boost::filesystem::exists( leaf_file ) ) {
|
||||||
|
throw OSRMException("mem index file does not exist");
|
||||||
|
}
|
||||||
|
if ( 0 == boost::filesystem::file_size( leaf_file ) ) {
|
||||||
|
throw OSRMException("mem index file is empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::filesystem::ifstream leaf_node_file( leaf_file, std::ios::binary );
|
||||||
|
leaf_node_file.read((char*)&m_element_count, sizeof(uint64_t));
|
||||||
|
leaf_node_file.close();
|
||||||
|
|
||||||
|
//SimpleLogger().Write() << tree_size << " nodes in search tree";
|
||||||
|
//SimpleLogger().Write() << m_element_count << " elements in leafs";
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit StaticRTree(
|
||||||
|
TreeNode * tree_node_ptr,
|
||||||
|
const uint32_t number_of_nodes,
|
||||||
|
const boost::filesystem::path & leaf_file
|
||||||
|
) : m_search_tree(tree_node_ptr, number_of_nodes),
|
||||||
|
m_leaf_node_filename(leaf_file.string())
|
||||||
|
{
|
||||||
|
//open leaf node file and store thread specific pointer
|
||||||
|
if ( !boost::filesystem::exists( leaf_file ) ) {
|
||||||
|
throw OSRMException("mem index file does not exist");
|
||||||
|
}
|
||||||
|
if ( 0 == boost::filesystem::file_size( leaf_file ) ) {
|
||||||
|
throw OSRMException("mem index file is empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::filesystem::ifstream leaf_node_file( leaf_file, std::ios::binary );
|
||||||
|
leaf_node_file.read((char*)&m_element_count, sizeof(uint64_t));
|
||||||
|
leaf_node_file.close();
|
||||||
|
|
||||||
|
if( thread_local_rtree_stream.get() ) {
|
||||||
|
thread_local_rtree_stream->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
//SimpleLogger().Write() << tree_size << " nodes in search tree";
|
||||||
|
//SimpleLogger().Write() << m_element_count << " elements in leafs";
|
||||||
|
}
|
||||||
|
//Read-only operation for queries
|
||||||
|
/*
|
||||||
|
inline void FindKNearestPhantomNodesForCoordinate(
|
||||||
|
const FixedPointCoordinate & location,
|
||||||
|
const unsigned zoom_level,
|
||||||
|
const unsigned candidate_count,
|
||||||
|
std::vector<std::pair<PhantomNode, double> > & result_vector
|
||||||
|
) const {
|
||||||
|
|
||||||
|
bool ignore_tiny_components = (zoom_level <= 14);
|
||||||
|
DataT nearest_edge;
|
||||||
|
|
||||||
|
uint32_t io_count = 0;
|
||||||
|
uint32_t explored_tree_nodes_count = 0;
|
||||||
|
SimpleLogger().Write() << "searching for coordinate " << input_coordinate;
|
||||||
|
double min_dist = std::numeric_limits<double>::max();
|
||||||
|
double min_max_dist = std::numeric_limits<double>::max();
|
||||||
|
bool found_a_nearest_edge = false;
|
||||||
|
|
||||||
|
FixedPointCoordinate nearest, current_start_coordinate, current_end_coordinate;
|
||||||
|
|
||||||
|
//initialize queue with root element
|
||||||
|
std::priority_queue<QueryCandidate> traversal_queue;
|
||||||
|
traversal_queue.push(QueryCandidate(0, m_search_tree[0].minimum_bounding_rectangle.GetMinDist(input_coordinate)));
|
||||||
|
BOOST_ASSERT_MSG(std::numberic_limits<double>::epsilon() > (0. - traversal_queue.top().min_dist), "Root element in NN Search has min dist != 0.");
|
||||||
|
|
||||||
|
while(!traversal_queue.empty()) {
|
||||||
|
const QueryCandidate current_query_node = traversal_queue.top(); traversal_queue.pop();
|
||||||
|
|
||||||
|
++explored_tree_nodes_count;
|
||||||
|
bool prune_downward = (current_query_node.min_dist >= min_max_dist);
|
||||||
|
bool prune_upward = (current_query_node.min_dist >= min_dist);
|
||||||
|
if( !prune_downward && !prune_upward ) { //downward pruning
|
||||||
|
TreeNode & current_tree_node = m_search_tree[current_query_node.node_id];
|
||||||
|
if (current_tree_node.child_is_on_disk) {
|
||||||
|
LeafNode current_leaf_node;
|
||||||
|
LoadLeafFromDisk(current_tree_node.children[0], current_leaf_node);
|
||||||
|
++io_count;
|
||||||
|
for(uint32_t i = 0; i < current_leaf_node.object_count; ++i) {
|
||||||
|
DataT & current_edge = current_leaf_node.objects[i];
|
||||||
|
if(ignore_tiny_components && current_edge.belongsToTinyComponent) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
double current_ratio = 0.;
|
||||||
|
double current_perpendicular_distance = current_edge.ComputePerpendicularDistance(
|
||||||
|
input_coordinate,
|
||||||
|
nearest,
|
||||||
|
current_ratio
|
||||||
|
);
|
||||||
|
|
||||||
|
if(
|
||||||
|
current_perpendicular_distance < min_dist
|
||||||
|
&& !DoubleEpsilonCompare(
|
||||||
|
current_perpendicular_distance,
|
||||||
|
min_dist
|
||||||
|
)
|
||||||
|
) { //found a new minimum
|
||||||
|
min_dist = current_perpendicular_distance;
|
||||||
|
result_phantom_node.edgeBasedNode = current_edge.id;
|
||||||
|
result_phantom_node.nodeBasedEdgeNameID = current_edge.nameID;
|
||||||
|
result_phantom_node.weight1 = current_edge.weight;
|
||||||
|
result_phantom_node.weight2 = INT_MAX;
|
||||||
|
result_phantom_node.location = nearest;
|
||||||
|
current_start_coordinate.lat = current_edge.lat1;
|
||||||
|
current_start_coordinate.lon = current_edge.lon1;
|
||||||
|
current_end_coordinate.lat = current_edge.lat2;
|
||||||
|
current_end_coordinate.lon = current_edge.lon2;
|
||||||
|
nearest_edge = current_edge;
|
||||||
|
found_a_nearest_edge = true;
|
||||||
|
} else if(
|
||||||
|
DoubleEpsilonCompare(current_perpendicular_distance, min_dist) &&
|
||||||
|
1 == abs(current_edge.id - result_phantom_node.edgeBasedNode )
|
||||||
|
&& EdgesAreEquivalent(
|
||||||
|
current_start_coordinate,
|
||||||
|
FixedPointCoordinate(
|
||||||
|
current_edge.lat1,
|
||||||
|
current_edge.lon1
|
||||||
|
),
|
||||||
|
FixedPointCoordinate(
|
||||||
|
current_edge.lat2,
|
||||||
|
current_edge.lon2
|
||||||
|
),
|
||||||
|
current_end_coordinate
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
result_phantom_node.edgeBasedNode = std::min(current_edge.id, result_phantom_node.edgeBasedNode);
|
||||||
|
result_phantom_node.weight2 = current_edge.weight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//traverse children, prune if global mindist is smaller than local one
|
||||||
|
for (uint32_t i = 0; i < current_tree_node.child_count; ++i) {
|
||||||
|
const int32_t child_id = current_tree_node.children[i];
|
||||||
|
TreeNode & child_tree_node = m_search_tree[child_id];
|
||||||
|
RectangleT & child_rectangle = child_tree_node.minimum_bounding_rectangle;
|
||||||
|
const double current_min_dist = child_rectangle.GetMinDist(input_coordinate);
|
||||||
|
const double current_min_max_dist = child_rectangle.GetMinMaxDist(input_coordinate);
|
||||||
|
if( current_min_max_dist < min_max_dist ) {
|
||||||
|
min_max_dist = current_min_max_dist;
|
||||||
|
}
|
||||||
|
if (current_min_dist > min_max_dist) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (current_min_dist > min_dist) { //upward pruning
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
traversal_queue.push(QueryCandidate(child_id, current_min_dist));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const double distance_to_edge =
|
||||||
|
ApproximateDistance (
|
||||||
|
FixedPointCoordinate(nearest_edge.lat1, nearest_edge.lon1),
|
||||||
|
result_phantom_node.location
|
||||||
|
);
|
||||||
|
|
||||||
|
const double length_of_edge =
|
||||||
|
ApproximateDistance(
|
||||||
|
FixedPointCoordinate(nearest_edge.lat1, nearest_edge.lon1),
|
||||||
|
FixedPointCoordinate(nearest_edge.lat2, nearest_edge.lon2)
|
||||||
|
);
|
||||||
|
|
||||||
|
const double ratio = (found_a_nearest_edge ?
|
||||||
|
std::min(1., distance_to_edge/ length_of_edge ) : 0 );
|
||||||
|
result_phantom_node.weight1 *= ratio;
|
||||||
|
if(INT_MAX != result_phantom_node.weight2) {
|
||||||
|
result_phantom_node.weight2 *= (1.-ratio);
|
||||||
|
}
|
||||||
|
result_phantom_node.ratio = ratio;
|
||||||
|
|
||||||
|
//Hack to fix rounding errors and wandering via nodes.
|
||||||
|
if(std::abs(input_coordinate.lon - result_phantom_node.location.lon) == 1) {
|
||||||
|
result_phantom_node.location.lon = input_coordinate.lon;
|
||||||
|
}
|
||||||
|
if(std::abs(input_coordinate.lat - result_phantom_node.location.lat) == 1) {
|
||||||
|
result_phantom_node.location.lat = input_coordinate.lat;
|
||||||
|
}
|
||||||
|
|
||||||
|
SimpleLogger().Write() << "mindist: " << min_distphantom_node.isBidirected() ? "yes" : "no");
|
||||||
|
return found_a_nearest_edge;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
bool LocateClosestEndPointForCoordinate(
|
||||||
|
const FixedPointCoordinate & input_coordinate,
|
||||||
|
FixedPointCoordinate & result_coordinate,
|
||||||
|
const unsigned zoom_level
|
||||||
|
) {
|
||||||
|
bool ignore_tiny_components = (zoom_level <= 14);
|
||||||
|
DataT nearest_edge;
|
||||||
|
double min_dist = std::numeric_limits<double>::max();
|
||||||
|
double min_max_dist = std::numeric_limits<double>::max();
|
||||||
|
bool found_a_nearest_edge = false;
|
||||||
|
|
||||||
|
//initialize queue with root element
|
||||||
|
std::priority_queue<QueryCandidate> traversal_queue;
|
||||||
|
double current_min_dist = m_search_tree[0].minimum_bounding_rectangle.GetMinDist(input_coordinate);
|
||||||
|
traversal_queue.push(
|
||||||
|
QueryCandidate(0, current_min_dist)
|
||||||
|
);
|
||||||
|
|
||||||
|
BOOST_ASSERT_MSG(
|
||||||
|
std::numeric_limits<double>::epsilon() > (0. - traversal_queue.top().min_dist),
|
||||||
|
"Root element in NN Search has min dist != 0."
|
||||||
|
);
|
||||||
|
|
||||||
|
while(!traversal_queue.empty()) {
|
||||||
|
const QueryCandidate current_query_node = traversal_queue.top();
|
||||||
|
traversal_queue.pop();
|
||||||
|
|
||||||
|
const bool prune_downward = (current_query_node.min_dist >= min_max_dist);
|
||||||
|
const bool prune_upward = (current_query_node.min_dist >= min_dist);
|
||||||
|
if( !prune_downward && !prune_upward ) { //downward pruning
|
||||||
|
TreeNode & current_tree_node = m_search_tree[current_query_node.node_id];
|
||||||
|
if (current_tree_node.child_is_on_disk) {
|
||||||
|
LeafNode current_leaf_node;
|
||||||
|
LoadLeafFromDisk(
|
||||||
|
current_tree_node.children[0],
|
||||||
|
current_leaf_node
|
||||||
|
);
|
||||||
|
for(uint32_t i = 0; i < current_leaf_node.object_count; ++i) {
|
||||||
|
const DataT & current_edge = current_leaf_node.objects[i];
|
||||||
|
if(
|
||||||
|
ignore_tiny_components &&
|
||||||
|
current_edge.belongsToTinyComponent
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
double current_minimum_distance = FixedPointCoordinate::ApproximateDistance(
|
||||||
|
input_coordinate.lat,
|
||||||
|
input_coordinate.lon,
|
||||||
|
current_edge.lat1,
|
||||||
|
current_edge.lon1
|
||||||
|
);
|
||||||
|
if( current_minimum_distance < min_dist ) {
|
||||||
|
//found a new minimum
|
||||||
|
min_dist = current_minimum_distance;
|
||||||
|
result_coordinate.lat = current_edge.lat1;
|
||||||
|
result_coordinate.lon = current_edge.lon1;
|
||||||
|
found_a_nearest_edge = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
current_minimum_distance = FixedPointCoordinate::ApproximateDistance(
|
||||||
|
input_coordinate.lat,
|
||||||
|
input_coordinate.lon,
|
||||||
|
current_edge.lat2,
|
||||||
|
current_edge.lon2
|
||||||
|
);
|
||||||
|
|
||||||
|
if( current_minimum_distance < min_dist ) {
|
||||||
|
//found a new minimum
|
||||||
|
min_dist = current_minimum_distance;
|
||||||
|
result_coordinate.lat = current_edge.lat2;
|
||||||
|
result_coordinate.lon = current_edge.lon2;
|
||||||
|
found_a_nearest_edge = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//traverse children, prune if global mindist is smaller than local one
|
||||||
|
for (uint32_t i = 0; i < current_tree_node.child_count; ++i) {
|
||||||
|
const int32_t child_id = current_tree_node.children[i];
|
||||||
|
const TreeNode & child_tree_node = m_search_tree[child_id];
|
||||||
|
const RectangleT & child_rectangle = child_tree_node.minimum_bounding_rectangle;
|
||||||
|
const double current_min_dist = child_rectangle.GetMinDist(input_coordinate);
|
||||||
|
const double current_min_max_dist = child_rectangle.GetMinMaxDist(input_coordinate);
|
||||||
|
if( current_min_max_dist < min_max_dist ) {
|
||||||
|
min_max_dist = current_min_max_dist;
|
||||||
|
}
|
||||||
|
if (current_min_dist > min_max_dist) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (current_min_dist > min_dist) { //upward pruning
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
traversal_queue.push(
|
||||||
|
QueryCandidate(child_id, current_min_dist)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return found_a_nearest_edge;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FindPhantomNodeForCoordinate(
|
||||||
|
const FixedPointCoordinate & input_coordinate,
|
||||||
|
PhantomNode & result_phantom_node,
|
||||||
|
const unsigned zoom_level
|
||||||
|
) {
|
||||||
|
|
||||||
|
bool ignore_tiny_components = (zoom_level <= 14);
|
||||||
|
DataT nearest_edge;
|
||||||
|
|
||||||
|
// uint32_t io_count = 0;
|
||||||
|
uint32_t explored_tree_nodes_count = 0;
|
||||||
|
//SimpleLogger().Write() << "searching for coordinate " << input_coordinate;
|
||||||
|
double min_dist = std::numeric_limits<double>::max();
|
||||||
|
double min_max_dist = std::numeric_limits<double>::max();
|
||||||
|
bool found_a_nearest_edge = false;
|
||||||
|
|
||||||
|
FixedPointCoordinate nearest, current_start_coordinate, current_end_coordinate;
|
||||||
|
|
||||||
|
//initialize queue with root element
|
||||||
|
std::priority_queue<QueryCandidate> traversal_queue;
|
||||||
|
double current_min_dist = m_search_tree[0].minimum_bounding_rectangle.GetMinDist(input_coordinate);
|
||||||
|
traversal_queue.push( QueryCandidate(0, current_min_dist) );
|
||||||
|
|
||||||
|
BOOST_ASSERT_MSG(
|
||||||
|
std::numeric_limits<double>::epsilon() > (0. - traversal_queue.top().min_dist),
|
||||||
|
"Root element in NN Search has min dist != 0."
|
||||||
|
);
|
||||||
|
|
||||||
|
LeafNode current_leaf_node;
|
||||||
|
while(!traversal_queue.empty()) {
|
||||||
|
const QueryCandidate current_query_node = traversal_queue.top(); traversal_queue.pop();
|
||||||
|
|
||||||
|
++explored_tree_nodes_count;
|
||||||
|
bool prune_downward = (current_query_node.min_dist >= min_max_dist);
|
||||||
|
bool prune_upward = (current_query_node.min_dist >= min_dist);
|
||||||
|
if( !prune_downward && !prune_upward ) { //downward pruning
|
||||||
|
TreeNode & current_tree_node = m_search_tree[current_query_node.node_id];
|
||||||
|
if (current_tree_node.child_is_on_disk) {
|
||||||
|
LoadLeafFromDisk(current_tree_node.children[0], current_leaf_node);
|
||||||
|
// ++io_count;
|
||||||
|
for(uint32_t i = 0; i < current_leaf_node.object_count; ++i) {
|
||||||
|
DataT & current_edge = current_leaf_node.objects[i];
|
||||||
|
if(ignore_tiny_components && current_edge.belongsToTinyComponent) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
double current_ratio = 0.;
|
||||||
|
double current_perpendicular_distance = current_edge.ComputePerpendicularDistance(
|
||||||
|
input_coordinate,
|
||||||
|
nearest,
|
||||||
|
current_ratio
|
||||||
|
);
|
||||||
|
|
||||||
|
BOOST_ASSERT( 0. <= current_perpendicular_distance );
|
||||||
|
|
||||||
|
if(
|
||||||
|
( current_perpendicular_distance < min_dist ) &&
|
||||||
|
!DoubleEpsilonCompare(
|
||||||
|
current_perpendicular_distance,
|
||||||
|
min_dist
|
||||||
|
)
|
||||||
|
) { //found a new minimum
|
||||||
|
min_dist = current_perpendicular_distance;
|
||||||
|
result_phantom_node.edgeBasedNode = current_edge.id;
|
||||||
|
result_phantom_node.nodeBasedEdgeNameID = current_edge.nameID;
|
||||||
|
result_phantom_node.weight1 = current_edge.weight;
|
||||||
|
result_phantom_node.weight2 = INT_MAX;
|
||||||
|
result_phantom_node.location = nearest;
|
||||||
|
current_start_coordinate.lat = current_edge.lat1;
|
||||||
|
current_start_coordinate.lon = current_edge.lon1;
|
||||||
|
current_end_coordinate.lat = current_edge.lat2;
|
||||||
|
current_end_coordinate.lon = current_edge.lon2;
|
||||||
|
nearest_edge = current_edge;
|
||||||
|
found_a_nearest_edge = true;
|
||||||
|
} else
|
||||||
|
if( DoubleEpsilonCompare(current_perpendicular_distance, min_dist) &&
|
||||||
|
( 1 == abs(current_edge.id - result_phantom_node.edgeBasedNode ) ) &&
|
||||||
|
EdgesAreEquivalent(
|
||||||
|
current_start_coordinate,
|
||||||
|
FixedPointCoordinate(
|
||||||
|
current_edge.lat1,
|
||||||
|
current_edge.lon1
|
||||||
|
),
|
||||||
|
FixedPointCoordinate(
|
||||||
|
current_edge.lat2,
|
||||||
|
current_edge.lon2
|
||||||
|
),
|
||||||
|
current_end_coordinate
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
|
||||||
|
BOOST_ASSERT_MSG(current_edge.id != result_phantom_node.edgeBasedNode, "IDs not different");
|
||||||
|
result_phantom_node.weight2 = current_edge.weight;
|
||||||
|
if(current_edge.id < result_phantom_node.edgeBasedNode) {
|
||||||
|
result_phantom_node.edgeBasedNode = current_edge.id;
|
||||||
|
std::swap(result_phantom_node.weight1, result_phantom_node.weight2);
|
||||||
|
std::swap(current_end_coordinate, current_start_coordinate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//traverse children, prune if global mindist is smaller than local one
|
||||||
|
for (uint32_t i = 0; i < current_tree_node.child_count; ++i) {
|
||||||
|
const int32_t child_id = current_tree_node.children[i];
|
||||||
|
TreeNode & child_tree_node = m_search_tree[child_id];
|
||||||
|
RectangleT & child_rectangle = child_tree_node.minimum_bounding_rectangle;
|
||||||
|
const double current_min_dist = child_rectangle.GetMinDist(input_coordinate);
|
||||||
|
const double current_min_max_dist = child_rectangle.GetMinMaxDist(input_coordinate);
|
||||||
|
if( current_min_max_dist < min_max_dist ) {
|
||||||
|
min_max_dist = current_min_max_dist;
|
||||||
|
}
|
||||||
|
if( current_min_dist > min_max_dist ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if( current_min_dist > min_dist ) { //upward pruning
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
traversal_queue.push(QueryCandidate(child_id, current_min_dist));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Hack to fix rounding errors and wandering via nodes.
|
||||||
|
if(std::abs(input_coordinate.lon - result_phantom_node.location.lon) == 1) {
|
||||||
|
result_phantom_node.location.lon = input_coordinate.lon;
|
||||||
|
}
|
||||||
|
if(std::abs(input_coordinate.lat - result_phantom_node.location.lat) == 1) {
|
||||||
|
result_phantom_node.location.lat = input_coordinate.lat;
|
||||||
|
}
|
||||||
|
|
||||||
|
double ratio = 0.;
|
||||||
|
|
||||||
|
if( found_a_nearest_edge) {
|
||||||
|
const double distance_1 = FixedPointCoordinate::ApproximateDistance(
|
||||||
|
current_start_coordinate,
|
||||||
|
result_phantom_node.location
|
||||||
|
);
|
||||||
|
|
||||||
|
const double distance_2 = FixedPointCoordinate::ApproximateDistance(
|
||||||
|
current_start_coordinate,
|
||||||
|
current_end_coordinate
|
||||||
|
);
|
||||||
|
|
||||||
|
ratio = distance_1/distance_2;
|
||||||
|
ratio = std::min(1., ratio);
|
||||||
|
}
|
||||||
|
|
||||||
|
result_phantom_node.weight1 *= ratio;
|
||||||
|
if(INT_MAX != result_phantom_node.weight2) {
|
||||||
|
result_phantom_node.weight2 *= (1.-ratio);
|
||||||
|
}
|
||||||
|
result_phantom_node.ratio = ratio;
|
||||||
|
|
||||||
|
return found_a_nearest_edge;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
inline void LoadLeafFromDisk(const uint32_t leaf_id, LeafNode& result_node) {
|
||||||
|
if(
|
||||||
|
!thread_local_rtree_stream.get() ||
|
||||||
|
!thread_local_rtree_stream->is_open()
|
||||||
|
) {
|
||||||
|
thread_local_rtree_stream.reset(
|
||||||
|
new boost::filesystem::ifstream(
|
||||||
|
m_leaf_node_filename,
|
||||||
|
std::ios::in | std::ios::binary
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if(!thread_local_rtree_stream->good()) {
|
||||||
|
thread_local_rtree_stream->clear(std::ios::goodbit);
|
||||||
|
SimpleLogger().Write(logDEBUG) << "Resetting stale filestream";
|
||||||
|
}
|
||||||
|
uint64_t seek_pos = sizeof(uint64_t) + leaf_id*sizeof(LeafNode);
|
||||||
|
thread_local_rtree_stream->seekg(seek_pos);
|
||||||
|
thread_local_rtree_stream->read((char *)&result_node, sizeof(LeafNode));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool EdgesAreEquivalent(
|
||||||
|
const FixedPointCoordinate & a,
|
||||||
|
const FixedPointCoordinate & b,
|
||||||
|
const FixedPointCoordinate & c,
|
||||||
|
const FixedPointCoordinate & d
|
||||||
|
) const {
|
||||||
|
return (a == b && c == d) || (a == c && b == d) || (a == d && b == c);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool DoubleEpsilonCompare(const double d1, const double d2) const {
|
||||||
|
return (std::abs(d1 - d2) < std::numeric_limits<double>::epsilon() );
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
//[1] "On Packing R-Trees"; I. Kamel, C. Faloutsos; 1993; DOI: 10.1145/170088.170403
|
||||||
|
//[2] "Nearest Neighbor Queries", N. Roussopulos et al; 1995; DOI: 10.1145/223784.223794
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* STATICRTREE_H_ */
|
||||||
@@ -1,80 +1,65 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, others 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
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
|
Redistributions of source code must retain the above copyright notice, this list
|
||||||
along with this program; if not, write to the Free Software
|
of conditions and the following disclaimer.
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
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 TURNINSTRUCTIONS_H_
|
#ifndef TURNINSTRUCTIONS_H_
|
||||||
#define TURNINSTRUCTIONS_H_
|
#define TURNINSTRUCTIONS_H_
|
||||||
|
|
||||||
#include <string>
|
#include <boost/noncopyable.hpp>
|
||||||
|
|
||||||
|
typedef unsigned char TurnInstruction;
|
||||||
|
|
||||||
//This is a hack until c++0x is available enough to use scoped enums
|
//This is a hack until c++0x is available enough to use scoped enums
|
||||||
struct TurnInstructionsClass {
|
struct TurnInstructionsClass : boost::noncopyable {
|
||||||
|
|
||||||
const static short NoTurn = 0; //Give no instruction at all
|
const static TurnInstruction NoTurn = 0; //Give no instruction at all
|
||||||
const static short GoStraight = 1; //Tell user to go straight!
|
const static TurnInstruction GoStraight = 1; //Tell user to go straight!
|
||||||
const static short TurnSlightRight = 2;
|
const static TurnInstruction TurnSlightRight = 2;
|
||||||
const static short TurnRight = 3;
|
const static TurnInstruction TurnRight = 3;
|
||||||
const static short TurnSharpRight = 4;
|
const static TurnInstruction TurnSharpRight = 4;
|
||||||
const static short UTurn = 5;
|
const static TurnInstruction UTurn = 5;
|
||||||
const static short TurnSharpLeft = 6;
|
const static TurnInstruction TurnSharpLeft = 6;
|
||||||
const static short TurnLeft = 7;
|
const static TurnInstruction TurnLeft = 7;
|
||||||
const static short TurnSlightLeft = 8;
|
const static TurnInstruction TurnSlightLeft = 8;
|
||||||
const static short ReachViaPoint = 9;
|
const static TurnInstruction ReachViaPoint = 9;
|
||||||
const static short HeadOn = 10;
|
const static TurnInstruction HeadOn = 10;
|
||||||
const static short EnterRoundAbout = 11;
|
const static TurnInstruction EnterRoundAbout = 11;
|
||||||
const static short LeaveRoundAbout = 12;
|
const static TurnInstruction LeaveRoundAbout = 12;
|
||||||
const static short StayOnRoundAbout = 13;
|
const static TurnInstruction StayOnRoundAbout = 13;
|
||||||
|
const static TurnInstruction StartAtEndOfStreet = 14;
|
||||||
|
const static TurnInstruction ReachedYourDestination = 15;
|
||||||
|
const static TurnInstruction EnterAgainstAllowedDirection = 16;
|
||||||
|
const static TurnInstruction LeaveAgainstAllowedDirection = 17;
|
||||||
|
|
||||||
std::string TurnStrings[14];
|
const static TurnInstruction AccessRestrictionFlag = 128;
|
||||||
std::string Ordinals[11];
|
const static TurnInstruction InverseAccessRestrictionFlag = 0x7f; // ~128 does not work without a warning.
|
||||||
|
|
||||||
//This is a hack until c++0x is available enough to use initializer lists.
|
const static int AccessRestrictionPenalty = 1 << 15; //unrelated to the bit set in the restriction flag
|
||||||
TurnInstructionsClass(){
|
|
||||||
TurnStrings [0] = "";
|
|
||||||
TurnStrings [1] = "Continue";
|
|
||||||
TurnStrings [2] = "Turn slight right";
|
|
||||||
TurnStrings [3] = "Turn right";
|
|
||||||
TurnStrings [4] = "Turn sharp right";
|
|
||||||
TurnStrings [5] = "U-Turn";
|
|
||||||
TurnStrings [6] = "Turn sharp left";
|
|
||||||
TurnStrings [7] = "Turn left";
|
|
||||||
TurnStrings [8] = "Turn slight left";
|
|
||||||
TurnStrings [9] = "Reach via point";
|
|
||||||
TurnStrings[10] = "Head";
|
|
||||||
TurnStrings[11] = "Enter round-about";
|
|
||||||
TurnStrings[12] = "Leave round-about";
|
|
||||||
TurnStrings[13] = "Stay on round-about";
|
|
||||||
|
|
||||||
Ordinals[0] = "zeroth";
|
static inline TurnInstruction GetTurnDirectionOfInstruction( const double angle ) {
|
||||||
Ordinals[1] = "first";
|
|
||||||
Ordinals[2] = "second";
|
|
||||||
Ordinals[3] = "third";
|
|
||||||
Ordinals[4] = "fourth";
|
|
||||||
Ordinals[5] = "fifth";
|
|
||||||
Ordinals[6] = "sixth";
|
|
||||||
Ordinals[7] = "seventh";
|
|
||||||
Ordinals[8] = "eighth";
|
|
||||||
Ordinals[9] = "nineth";
|
|
||||||
Ordinals[10] = "tenth";
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline double GetTurnDirectionOfInstruction( const double angle ) {
|
|
||||||
if(angle >= 23 && angle < 67) {
|
if(angle >= 23 && angle < 67) {
|
||||||
return TurnSharpRight;
|
return TurnSharpRight;
|
||||||
}
|
}
|
||||||
@@ -96,7 +81,7 @@ struct TurnInstructionsClass {
|
|||||||
if (angle >= 292 && angle < 336) {
|
if (angle >= 292 && angle < 336) {
|
||||||
return TurnSharpLeft;
|
return TurnSharpLeft;
|
||||||
}
|
}
|
||||||
return 5;
|
return UTurn;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool TurnIsNecessary ( const short turnInstruction ) {
|
static inline bool TurnIsNecessary ( const short turnInstruction ) {
|
||||||
@@ -105,48 +90,6 @@ struct TurnInstructionsClass {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// static inline void getDirectionOfInstruction(double angle, DirectionOfInstruction & dirInst) {
|
|
||||||
// if(angle >= 23 && angle < 67) {
|
|
||||||
// dirInst.direction = "southeast";
|
|
||||||
// dirInst.shortDirection = "SE";
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// if(angle >= 67 && angle < 113) {
|
|
||||||
// dirInst.direction = "south";
|
|
||||||
// dirInst.shortDirection = "S";
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// if(angle >= 113 && angle < 158) {
|
|
||||||
// dirInst.direction = "southwest";
|
|
||||||
// dirInst.shortDirection = "SW";
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// if(angle >= 158 && angle < 202) {
|
|
||||||
// dirInst.direction = "west";
|
|
||||||
// dirInst.shortDirection = "W";
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// if(angle >= 202 && angle < 248) {
|
|
||||||
// dirInst.direction = "northwest";
|
|
||||||
// dirInst.shortDirection = "NW";
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// if(angle >= 248 && angle < 292) {
|
|
||||||
// dirInst.direction = "north";
|
|
||||||
// dirInst.shortDirection = "N";
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// if(angle >= 292 && angle < 336) {
|
|
||||||
// dirInst.direction = "northeast";
|
|
||||||
// dirInst.shortDirection = "NE";
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// dirInst.direction = "East";
|
|
||||||
// dirInst.shortDirection = "E";
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static TurnInstructionsClass TurnInstructions;
|
static TurnInstructionsClass TurnInstructions;
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
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 TIMEUTIL_H_
|
|
||||||
#define TIMEUTIL_H_
|
|
||||||
|
|
||||||
#include <climits>
|
|
||||||
#include <cmath>
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
#ifndef M_PI
|
|
||||||
#define M_PI 3.14159265358979323846
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include <sys/timeb.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <winsock.h>
|
|
||||||
void gettimeofday(struct timeval* t,void* timezone)
|
|
||||||
{ struct _timeb timebuffer;
|
|
||||||
_ftime( &timebuffer );
|
|
||||||
t->tv_sec=timebuffer.time;
|
|
||||||
t->tv_usec=1000*timebuffer.millitm;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#include <sys/time.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include <boost/functional/hash.hpp>
|
|
||||||
#else
|
|
||||||
#include <tr1/functional_hash.h>
|
|
||||||
#endif
|
|
||||||
#include <boost/thread.hpp>
|
|
||||||
|
|
||||||
/** Returns a timestamp (now) in seconds (incl. a fractional part). */
|
|
||||||
static inline double get_timestamp() {
|
|
||||||
struct timeval tp;
|
|
||||||
gettimeofday(&tp, NULL);
|
|
||||||
return double(tp.tv_sec) + tp.tv_usec / 1000000.;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline double y2lat(double a) { return 180/M_PI * (2 * atan(exp(a*M_PI/180)) - M_PI/2); }
|
|
||||||
static inline double lat2y(double a) { return 180/M_PI * log(tan(M_PI/4+a*(M_PI/180)/2)); }
|
|
||||||
|
|
||||||
static inline unsigned boost_thread_id_hash(boost::thread::id const& id) {
|
|
||||||
std::stringstream ostr;
|
|
||||||
ostr << id;
|
|
||||||
std::tr1::hash<std::string> h;
|
|
||||||
return h(ostr.str());
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* TIMEUTIL_H_ */
|
|
||||||
@@ -1,217 +0,0 @@
|
|||||||
/*
|
|
||||||
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 XMLPARSER_H_
|
|
||||||
#define XMLPARSER_H_
|
|
||||||
|
|
||||||
#include <libxml/xmlreader.h>
|
|
||||||
|
|
||||||
#include "../typedefs.h"
|
|
||||||
#include "BaseParser.h"
|
|
||||||
#include "HashTable.h"
|
|
||||||
#include "ExtractorStructs.h"
|
|
||||||
#include "InputReaderFactory.h"
|
|
||||||
|
|
||||||
class XMLParser : public BaseParser<_Node, _RawRestrictionContainer, _Way> {
|
|
||||||
public:
|
|
||||||
XMLParser(const char * filename) {
|
|
||||||
WARN("Parsing plain .osm/.osm.bz2 is deprecated. Switch to .pbf");
|
|
||||||
inputReader = inputReaderFactory(filename);
|
|
||||||
}
|
|
||||||
virtual ~XMLParser() {}
|
|
||||||
|
|
||||||
bool RegisterCallbacks(bool (*nodeCallbackPointer)(_Node), bool (*restrictionCallbackPointer)(_RawRestrictionContainer), bool (*wayCallbackPointer)(_Way), bool (*addressCallbackPointer)(_Node, HashTable<std::string, std::string>) ) {
|
|
||||||
nodeCallback = *nodeCallbackPointer;
|
|
||||||
wayCallback = *wayCallbackPointer;
|
|
||||||
restrictionCallback = *restrictionCallbackPointer;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool Init() {
|
|
||||||
return (xmlTextReaderRead( inputReader ) == 1);
|
|
||||||
}
|
|
||||||
bool Parse() {
|
|
||||||
while ( xmlTextReaderRead( inputReader ) == 1 ) {
|
|
||||||
const int type = xmlTextReaderNodeType( inputReader );
|
|
||||||
|
|
||||||
//1 is Element
|
|
||||||
if ( type != 1 )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
xmlChar* currentName = xmlTextReaderName( inputReader );
|
|
||||||
if ( currentName == NULL )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if ( xmlStrEqual( currentName, ( const xmlChar* ) "node" ) == 1 ) {
|
|
||||||
_Node n = _ReadXMLNode( );
|
|
||||||
if(!(*nodeCallback)(n))
|
|
||||||
std::cerr << "[XMLParser] node not parsed" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( xmlStrEqual( currentName, ( const xmlChar* ) "way" ) == 1 ) {
|
|
||||||
string name;
|
|
||||||
_Way way = _ReadXMLWay( );
|
|
||||||
if(!(*wayCallback)(way)) {
|
|
||||||
std::cerr << "[XMLParser] way not parsed" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( xmlStrEqual( currentName, ( const xmlChar* ) "relation" ) == 1 ) {
|
|
||||||
_Relation r;
|
|
||||||
r.type = _Relation::unknown;
|
|
||||||
//todo: parse relation
|
|
||||||
}
|
|
||||||
xmlFree( currentName );
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
_Relation _ReadXMLRelation ( ) {
|
|
||||||
_Relation relation;
|
|
||||||
relation.type = _Relation::unknown;
|
|
||||||
|
|
||||||
return relation;
|
|
||||||
}
|
|
||||||
|
|
||||||
_Way _ReadXMLWay( ) {
|
|
||||||
_Way way;
|
|
||||||
way.direction = _Way::notSure;
|
|
||||||
way.speed = -1;
|
|
||||||
way.type = -1;
|
|
||||||
way.useful = false;
|
|
||||||
way.access = true;
|
|
||||||
// cout << "new way" << endl;
|
|
||||||
if ( xmlTextReaderIsEmptyElement( inputReader ) != 1 ) {
|
|
||||||
const int depth = xmlTextReaderDepth( inputReader );
|
|
||||||
while ( xmlTextReaderRead( inputReader ) == 1 ) {
|
|
||||||
const int childType = xmlTextReaderNodeType( inputReader );
|
|
||||||
if ( childType != 1 && childType != 15 )
|
|
||||||
continue;
|
|
||||||
const int childDepth = xmlTextReaderDepth( inputReader );
|
|
||||||
xmlChar* childName = xmlTextReaderName( inputReader );
|
|
||||||
if ( childName == NULL )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if ( depth == childDepth && childType == 15 && xmlStrEqual( childName, ( const xmlChar* ) "way" ) == 1 ) {
|
|
||||||
xmlFree( childName );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if ( childType != 1 ) {
|
|
||||||
xmlFree( childName );
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( xmlStrEqual( childName, ( const xmlChar* ) "tag" ) == 1 ) {
|
|
||||||
xmlChar* k = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "k" );
|
|
||||||
xmlChar* value = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "v" );
|
|
||||||
// cout << "->k=" << k << ", v=" << value << endl;
|
|
||||||
if ( k != NULL && value != NULL ) {
|
|
||||||
|
|
||||||
way.keyVals.Add(std::string( (char *) k ), std::string( (char *) value));
|
|
||||||
}
|
|
||||||
if ( k != NULL )
|
|
||||||
xmlFree( k );
|
|
||||||
if ( value != NULL )
|
|
||||||
xmlFree( value );
|
|
||||||
} else if ( xmlStrEqual( childName, ( const xmlChar* ) "nd" ) == 1 ) {
|
|
||||||
xmlChar* ref = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "ref" );
|
|
||||||
if ( ref != NULL ) {
|
|
||||||
way.path.push_back( atoi(( const char* ) ref ) );
|
|
||||||
xmlFree( ref );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
xmlFree( childName );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return way;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
_Node _ReadXMLNode( ) {
|
|
||||||
_Node node;
|
|
||||||
|
|
||||||
xmlChar* attribute = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "lat" );
|
|
||||||
if ( attribute != NULL ) {
|
|
||||||
node.lat = static_cast<NodeID>(100000.*atof(( const char* ) attribute ) );
|
|
||||||
xmlFree( attribute );
|
|
||||||
}
|
|
||||||
attribute = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "lon" );
|
|
||||||
if ( attribute != NULL ) {
|
|
||||||
node.lon = static_cast<NodeID>(100000.*atof(( const char* ) attribute ));
|
|
||||||
xmlFree( attribute );
|
|
||||||
}
|
|
||||||
attribute = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "id" );
|
|
||||||
if ( attribute != NULL ) {
|
|
||||||
node.id = atoi(( const char* ) attribute );
|
|
||||||
xmlFree( attribute );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( xmlTextReaderIsEmptyElement( inputReader ) != 1 ) {
|
|
||||||
const int depth = xmlTextReaderDepth( inputReader );
|
|
||||||
while ( xmlTextReaderRead( inputReader ) == 1 ) {
|
|
||||||
const int childType = xmlTextReaderNodeType( inputReader );
|
|
||||||
// 1 = Element, 15 = EndElement
|
|
||||||
if ( childType != 1 && childType != 15 )
|
|
||||||
continue;
|
|
||||||
const int childDepth = xmlTextReaderDepth( inputReader );
|
|
||||||
xmlChar* childName = xmlTextReaderName( inputReader );
|
|
||||||
if ( childName == NULL )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if ( depth == childDepth && childType == 15 && xmlStrEqual( childName, ( const xmlChar* ) "node" ) == 1 ) {
|
|
||||||
xmlFree( childName );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if ( childType != 1 ) {
|
|
||||||
xmlFree( childName );
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( xmlStrEqual( childName, ( const xmlChar* ) "tag" ) == 1 ) {
|
|
||||||
xmlChar* k = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "k" );
|
|
||||||
xmlChar* value = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "v" );
|
|
||||||
if ( k != NULL && value != NULL ) {
|
|
||||||
if ( xmlStrEqual( k, ( const xmlChar* ) "highway" ) == 1 ) {
|
|
||||||
if ( xmlStrEqual( value, ( const xmlChar* ) "traffic_signals" ) == 1 ){
|
|
||||||
//node.trafficSignal = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( k != NULL )
|
|
||||||
xmlFree( k );
|
|
||||||
if ( value != NULL )
|
|
||||||
xmlFree( value );
|
|
||||||
}
|
|
||||||
|
|
||||||
xmlFree( childName );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
/* Input Reader */
|
|
||||||
xmlTextReaderPtr inputReader;
|
|
||||||
|
|
||||||
/* Function pointer for nodes */
|
|
||||||
bool (*nodeCallback)(_Node);
|
|
||||||
bool (*wayCallback)(_Way);
|
|
||||||
bool (*restrictionCallback)(_RawRestrictionContainer);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* XMLPARSER_H_ */
|
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 FASTXORHASH_H_
|
||||||
|
#define FASTXORHASH_H_
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
/*
|
||||||
|
This is an implementation of Tabulation hashing, which has suprising properties like universality.
|
||||||
|
The space requirement is 2*2^16 = 256 kb of memory, which fits into L2 cache.
|
||||||
|
Evaluation boils down to 10 or less assembly instruction on any recent X86 CPU:
|
||||||
|
|
||||||
|
1: movq table2(%rip), %rdx
|
||||||
|
2: movl %edi, %eax
|
||||||
|
3: movzwl %di, %edi
|
||||||
|
4: shrl $16, %eax
|
||||||
|
5: movzwl %ax, %eax
|
||||||
|
6: movzbl (%rdx,%rax), %eax
|
||||||
|
7: movq table1(%rip), %rdx
|
||||||
|
8: xorb (%rdx,%rdi), %al
|
||||||
|
9: movzbl %al, %eax
|
||||||
|
10: ret
|
||||||
|
|
||||||
|
*/
|
||||||
|
class XORFastHash { //65k entries
|
||||||
|
std::vector<unsigned short> table1;
|
||||||
|
std::vector<unsigned short> table2;
|
||||||
|
public:
|
||||||
|
XORFastHash() {
|
||||||
|
table1.resize(2 << 16);
|
||||||
|
table2.resize(2 << 16);
|
||||||
|
for(unsigned i = 0; i < (2 << 16); ++i) {
|
||||||
|
table1[i] = i; table2[i] = i;
|
||||||
|
}
|
||||||
|
std::random_shuffle(table1.begin(), table1.end());
|
||||||
|
std::random_shuffle(table2.begin(), table2.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned short operator()(const unsigned originalValue) const {
|
||||||
|
unsigned short lsb = ((originalValue) & 0xffff);
|
||||||
|
unsigned short msb = (((originalValue) >> 16) & 0xffff);
|
||||||
|
return table1[lsb] ^ table2[msb];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class XORMiniHash { //256 entries
|
||||||
|
std::vector<unsigned char> table1;
|
||||||
|
std::vector<unsigned char> table2;
|
||||||
|
std::vector<unsigned char> table3;
|
||||||
|
std::vector<unsigned char> table4;
|
||||||
|
|
||||||
|
public:
|
||||||
|
XORMiniHash() {
|
||||||
|
table1.resize(1 << 8);
|
||||||
|
table2.resize(1 << 8);
|
||||||
|
table3.resize(1 << 8);
|
||||||
|
table4.resize(1 << 8);
|
||||||
|
for(unsigned i = 0; i < (1 << 8); ++i) {
|
||||||
|
table1[i] = i; table2[i] = i;
|
||||||
|
table3[i] = i; table4[i] = i;
|
||||||
|
}
|
||||||
|
std::random_shuffle(table1.begin(), table1.end());
|
||||||
|
std::random_shuffle(table2.begin(), table2.end());
|
||||||
|
std::random_shuffle(table3.begin(), table3.end());
|
||||||
|
std::random_shuffle(table4.begin(), table4.end());
|
||||||
|
}
|
||||||
|
unsigned char operator()(const unsigned originalValue) const {
|
||||||
|
unsigned char byte1 = ((originalValue) & 0xff);
|
||||||
|
unsigned char byte2 = ((originalValue >> 8) & 0xff);
|
||||||
|
unsigned char byte3 = ((originalValue >> 16) & 0xff);
|
||||||
|
unsigned char byte4 = ((originalValue >> 24) & 0xff);
|
||||||
|
return table1[byte1] ^ table2[byte2] ^ table3[byte3] ^ table4[byte4];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FASTXORHASH_H_ */
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 XORFASTHASHSTORAGE_H_
|
||||||
|
#define XORFASTHASHSTORAGE_H_
|
||||||
|
|
||||||
|
#include "XORFastHash.h"
|
||||||
|
|
||||||
|
#include <climits>
|
||||||
|
#include <vector>
|
||||||
|
#include <bitset>
|
||||||
|
|
||||||
|
template< typename NodeID, typename Key >
|
||||||
|
class XORFastHashStorage {
|
||||||
|
public:
|
||||||
|
struct HashCell{
|
||||||
|
Key key;
|
||||||
|
NodeID id;
|
||||||
|
unsigned time;
|
||||||
|
HashCell() : key(UINT_MAX), id(UINT_MAX), time(UINT_MAX) {}
|
||||||
|
|
||||||
|
HashCell(const HashCell & other) : key(other.key), id(other.id), time(other.time) { }
|
||||||
|
|
||||||
|
inline operator Key() const {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void operator=(const Key & keyToInsert) {
|
||||||
|
key = keyToInsert;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
XORFastHashStorage( size_t ) : positions(2<<16), currentTimestamp(0) { }
|
||||||
|
|
||||||
|
inline HashCell& operator[]( const NodeID node ) {
|
||||||
|
unsigned short position = fastHash(node);
|
||||||
|
while((positions[position].time == currentTimestamp) && (positions[position].id != node)){
|
||||||
|
++position %= (2<<16);
|
||||||
|
}
|
||||||
|
|
||||||
|
positions[position].id = node;
|
||||||
|
positions[position].time = currentTimestamp;
|
||||||
|
return positions[position];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Clear() {
|
||||||
|
++currentTimestamp;
|
||||||
|
if(UINT_MAX == currentTimestamp) {
|
||||||
|
positions.clear();
|
||||||
|
positions.resize((2<<16));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
XORFastHashStorage() : positions(2<<16), currentTimestamp(0) {}
|
||||||
|
std::vector<HashCell> positions;
|
||||||
|
XORFastHash fastHash;
|
||||||
|
unsigned currentTimestamp;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XORFASTHASHSTORAGE_H_ */
|
||||||
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
/** Copyright (c) 2010 Scott A. Crosby. <scott@sacrosby.com>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Lesser General Public License as
|
|
||||||
published by the Free Software Foundation, either version 3 of the
|
|
||||||
License, or (at your option) 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 General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
option java_package = "crosby.binary";
|
|
||||||
package OSMPBF;
|
|
||||||
|
|
||||||
//protoc --java_out=../.. fileformat.proto
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// STORAGE LAYER: Storing primitives.
|
|
||||||
//
|
|
||||||
|
|
||||||
message Blob {
|
|
||||||
optional bytes raw = 1; // No compression
|
|
||||||
optional int32 raw_size = 2; // When compressed, the uncompressed size
|
|
||||||
|
|
||||||
// Possible compressed versions of the data.
|
|
||||||
optional bytes zlib_data = 3;
|
|
||||||
|
|
||||||
// PROPOSED feature for LZMA compressed data. SUPPORT IS NOT REQUIRED.
|
|
||||||
optional bytes lzma_data = 4;
|
|
||||||
|
|
||||||
// Formerly used for bzip2 compressed data. Depreciated in 2010.
|
|
||||||
optional bytes OBSOLETE_bzip2_data = 5 [deprecated=true]; // Don't reuse this tag number.
|
|
||||||
}
|
|
||||||
|
|
||||||
/* A file contains an sequence of fileblock headers, each prefixed by
|
|
||||||
their length in network byte order, followed by a data block
|
|
||||||
containing the actual data. types staring with a "_" are reserved.
|
|
||||||
*/
|
|
||||||
|
|
||||||
message BlobHeader {
|
|
||||||
required string type = 1;
|
|
||||||
optional bytes indexdata = 2;
|
|
||||||
required int32 datasize = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,226 +0,0 @@
|
|||||||
/** Copyright (c) 2010 Scott A. Crosby. <scott@sacrosby.com>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Lesser General Public License as
|
|
||||||
published by the Free Software Foundation, either version 3 of the
|
|
||||||
License, or (at your option) 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 General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
option java_package = "crosby.binary";
|
|
||||||
package OSMPBF;
|
|
||||||
|
|
||||||
/* OSM Binary file format
|
|
||||||
|
|
||||||
This is the master schema file of the OSM binary file format. This
|
|
||||||
file is designed to support limited random-access and future
|
|
||||||
extendability.
|
|
||||||
|
|
||||||
A binary OSM file consists of a sequence of FileBlocks (please see
|
|
||||||
fileformat.proto). The first fileblock contains a serialized instance
|
|
||||||
of HeaderBlock, followed by a sequence of PrimitiveBlock blocks that
|
|
||||||
contain the primitives.
|
|
||||||
|
|
||||||
Each primitiveblock is designed to be independently parsable. It
|
|
||||||
contains a string table storing all strings in that block (keys and
|
|
||||||
values in tags, roles in relations, usernames, etc.) as well as
|
|
||||||
metadata containing the precision of coordinates or timestamps in that
|
|
||||||
block.
|
|
||||||
|
|
||||||
A primitiveblock contains a sequence of primitive groups, each
|
|
||||||
containing primitives of the same type (nodes, densenodes, ways,
|
|
||||||
relations). Coordinates are stored in signed 64-bit integers. Lat&lon
|
|
||||||
are measured in units <granularity> nanodegrees. The default of
|
|
||||||
granularity of 100 nanodegrees corresponds to about 1cm on the ground,
|
|
||||||
and a full lat or lon fits into 32 bits.
|
|
||||||
|
|
||||||
Converting an integer to a lattitude or longitude uses the formula:
|
|
||||||
$OUT = IN * granularity / 10**9$. Many encoding schemes use delta
|
|
||||||
coding when representing nodes and relations.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
/* Contains the file header. */
|
|
||||||
|
|
||||||
message HeaderBlock {
|
|
||||||
optional HeaderBBox bbox = 1;
|
|
||||||
/* Additional tags to aid in parsing this dataset */
|
|
||||||
repeated string required_features = 4;
|
|
||||||
repeated string optional_features = 5;
|
|
||||||
|
|
||||||
optional string writingprogram = 16;
|
|
||||||
optional string source = 17; // From the bbox field.
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** The bounding box field in the OSM header. BBOX, as used in the OSM
|
|
||||||
header. Units are always in nanodegrees -- they do not obey
|
|
||||||
granularity rules. */
|
|
||||||
|
|
||||||
message HeaderBBox {
|
|
||||||
required sint64 left = 1;
|
|
||||||
required sint64 right = 2;
|
|
||||||
required sint64 top = 3;
|
|
||||||
required sint64 bottom = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
message PrimitiveBlock {
|
|
||||||
required StringTable stringtable = 1;
|
|
||||||
repeated PrimitiveGroup primitivegroup = 2;
|
|
||||||
|
|
||||||
// Granularity, units of nanodegrees, used to store coordinates in this block
|
|
||||||
optional int32 granularity = 17 [default=100];
|
|
||||||
// Offset value between the output coordinates coordinates and the granularity grid in unites of nanodegrees.
|
|
||||||
optional int64 lat_offset = 19 [default=0];
|
|
||||||
optional int64 lon_offset = 20 [default=0];
|
|
||||||
|
|
||||||
// Granularity of dates, normally represented in units of milliseconds since the 1970 epoch.
|
|
||||||
optional int32 date_granularity = 18 [default=1000];
|
|
||||||
|
|
||||||
|
|
||||||
// Proposed extension:
|
|
||||||
//optional BBox bbox = XX;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Group of OSMPrimitives. All primitives in a group must be the same type.
|
|
||||||
message PrimitiveGroup {
|
|
||||||
repeated Node nodes = 1;
|
|
||||||
optional DenseNodes dense = 2;
|
|
||||||
repeated Way ways = 3;
|
|
||||||
repeated Relation relations = 4;
|
|
||||||
repeated ChangeSet changesets = 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** String table, contains the common strings in each block.
|
|
||||||
|
|
||||||
Note that we reserve index '0' as a delimiter, so the entry at that
|
|
||||||
index in the table is ALWAYS blank and unused.
|
|
||||||
|
|
||||||
*/
|
|
||||||
message StringTable {
|
|
||||||
repeated bytes s = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Optional metadata that may be included into each primitive. */
|
|
||||||
message Info {
|
|
||||||
optional int32 version = 1 [default = -1];
|
|
||||||
optional int64 timestamp = 2;
|
|
||||||
optional int64 changeset = 3;
|
|
||||||
optional int32 uid = 4;
|
|
||||||
optional uint32 user_sid = 5; // String IDs
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Optional metadata that may be included into each primitive. Special dense format used in DenseNodes. */
|
|
||||||
message DenseInfo {
|
|
||||||
repeated int32 version = 1 [packed = true];
|
|
||||||
repeated sint64 timestamp = 2 [packed = true]; // DELTA coded
|
|
||||||
repeated sint64 changeset = 3 [packed = true]; // DELTA coded
|
|
||||||
repeated sint32 uid = 4 [packed = true]; // DELTA coded
|
|
||||||
repeated sint32 user_sid = 5 [packed = true]; // String IDs for usernames. DELTA coded
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// THIS IS STUB DESIGN FOR CHANGESETS. NOT USED RIGHT NOW.
|
|
||||||
// TODO: REMOVE THIS?
|
|
||||||
message ChangeSet {
|
|
||||||
required int64 id = 1;
|
|
||||||
//
|
|
||||||
// // Parallel arrays.
|
|
||||||
// repeated uint32 keys = 2 [packed = true]; // String IDs.
|
|
||||||
// repeated uint32 vals = 3 [packed = true]; // String IDs.
|
|
||||||
//
|
|
||||||
// optional Info info = 4;
|
|
||||||
|
|
||||||
// optional int64 created_at = 8;
|
|
||||||
// optional int64 closetime_delta = 9;
|
|
||||||
// optional bool open = 10;
|
|
||||||
// optional HeaderBBox bbox = 11;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
message Node {
|
|
||||||
required sint64 id = 1;
|
|
||||||
// Parallel arrays.
|
|
||||||
repeated uint32 keys = 2 [packed = true]; // String IDs.
|
|
||||||
repeated uint32 vals = 3 [packed = true]; // String IDs.
|
|
||||||
|
|
||||||
optional Info info = 4; // May be omitted in omitmeta
|
|
||||||
|
|
||||||
required sint64 lat = 8;
|
|
||||||
required sint64 lon = 9;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Used to densly represent a sequence of nodes that do not have any tags.
|
|
||||||
|
|
||||||
We represent these nodes columnwise as five columns: ID's, lats, and
|
|
||||||
lons, all delta coded. When metadata is not omitted,
|
|
||||||
|
|
||||||
We encode keys & vals for all nodes as a single array of integers
|
|
||||||
containing key-stringid and val-stringid, using a stringid of 0 as a
|
|
||||||
delimiter between nodes.
|
|
||||||
|
|
||||||
( (<keyid> <valid>)* '0' )*
|
|
||||||
*/
|
|
||||||
|
|
||||||
message DenseNodes {
|
|
||||||
repeated sint64 id = 1 [packed = true]; // DELTA coded
|
|
||||||
|
|
||||||
//repeated Info info = 4;
|
|
||||||
optional DenseInfo denseinfo = 5;
|
|
||||||
|
|
||||||
repeated sint64 lat = 8 [packed = true]; // DELTA coded
|
|
||||||
repeated sint64 lon = 9 [packed = true]; // DELTA coded
|
|
||||||
|
|
||||||
// Special packing of keys and vals into one array. May be empty if all nodes in this block are tagless.
|
|
||||||
repeated int32 keys_vals = 10 [packed = true];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
message Way {
|
|
||||||
required int64 id = 1;
|
|
||||||
// Parallel arrays.
|
|
||||||
repeated uint32 keys = 2 [packed = true];
|
|
||||||
repeated uint32 vals = 3 [packed = true];
|
|
||||||
|
|
||||||
optional Info info = 4;
|
|
||||||
|
|
||||||
repeated sint64 refs = 8 [packed = true]; // DELTA coded
|
|
||||||
}
|
|
||||||
|
|
||||||
message Relation {
|
|
||||||
enum MemberType {
|
|
||||||
NODE = 0;
|
|
||||||
WAY = 1;
|
|
||||||
RELATION = 2;
|
|
||||||
}
|
|
||||||
required int64 id = 1;
|
|
||||||
|
|
||||||
// Parallel arrays.
|
|
||||||
repeated uint32 keys = 2 [packed = true];
|
|
||||||
repeated uint32 vals = 3 [packed = true];
|
|
||||||
|
|
||||||
optional Info info = 4;
|
|
||||||
|
|
||||||
// Parallel arrays
|
|
||||||
repeated int32 roles_sid = 8 [packed = true];
|
|
||||||
repeated sint64 memids = 9 [packed = true]; // DELTA encoded
|
|
||||||
repeated MemberType types = 10 [packed = true];
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,73 +1,68 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
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
|
Redistributions of source code must retain the above copyright notice, this list
|
||||||
along with this program; if not, write to the Free Software
|
of conditions and the following disclaimer.
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
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 BASE_DESCRIPTOR_H_
|
#ifndef BASE_DESCRIPTOR_H_
|
||||||
#define BASE_DESCRIPTOR_H_
|
#define BASE_DESCRIPTOR_H_
|
||||||
|
|
||||||
#include <cassert>
|
#include "../DataStructures/PhantomNodes.h"
|
||||||
#include <cmath>
|
#include "../DataStructures/RawRouteData.h"
|
||||||
#include <cstdio>
|
#include "../typedefs.h"
|
||||||
|
|
||||||
|
#include <osrm/Reply.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "../typedefs.h"
|
struct DescriptorConfig {
|
||||||
#include "../DataStructures/ExtractorStructs.h"
|
DescriptorConfig() :
|
||||||
#include "../DataStructures/HashTable.h"
|
instructions(true),
|
||||||
#include "../Util/StringUtil.h"
|
geometry(true),
|
||||||
|
encode_geometry(true),
|
||||||
#include "../Plugins/RawRouteData.h"
|
zoom_level(18)
|
||||||
|
{ }
|
||||||
struct _RouteSummary {
|
|
||||||
std::string lengthString;
|
|
||||||
std::string durationString;
|
|
||||||
std::string startName;
|
|
||||||
std::string destName;
|
|
||||||
_RouteSummary() : lengthString("0"), durationString("0"), startName("unknown street"), destName("unknown street") {}
|
|
||||||
void BuildDurationAndLengthStrings(unsigned distance, unsigned time) {
|
|
||||||
//compute distance/duration for route summary
|
|
||||||
std::ostringstream s;
|
|
||||||
s << 10*(round(distance/10.));
|
|
||||||
lengthString = s.str();
|
|
||||||
int travelTime = time/10 + 1;
|
|
||||||
s.str("");
|
|
||||||
s << travelTime;
|
|
||||||
durationString = s.str();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _DescriptorConfig {
|
|
||||||
_DescriptorConfig() : instructions(true), geometry(true), encodeGeometry(false), z(18) {}
|
|
||||||
bool instructions;
|
bool instructions;
|
||||||
bool geometry;
|
bool geometry;
|
||||||
bool encodeGeometry;
|
bool encode_geometry;
|
||||||
unsigned short z;
|
unsigned short zoom_level;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class SearchEngineT>
|
template<class DataFacadeT>
|
||||||
class BaseDescriptor {
|
class BaseDescriptor {
|
||||||
public:
|
public:
|
||||||
BaseDescriptor() { }
|
BaseDescriptor() { }
|
||||||
//Maybe someone can explain the pure virtual destructor thing to me (dennis)
|
//Maybe someone can explain the pure virtual destructor thing to me (dennis)
|
||||||
virtual ~BaseDescriptor() { }
|
virtual ~BaseDescriptor() { }
|
||||||
virtual void Run(http::Reply & reply, RawRouteData &rawRoute, PhantomNodes &phantomNodes, SearchEngineT &sEngine, unsigned distance) = 0;
|
virtual void Run(
|
||||||
virtual void SetConfig(const _DescriptorConfig & config) = 0;
|
const RawRouteData & rawRoute,
|
||||||
|
const PhantomNodes & phantomNodes,
|
||||||
|
DataFacadeT * facade,
|
||||||
|
http::Reply & reply
|
||||||
|
) = 0;
|
||||||
|
virtual void SetConfig(const DescriptorConfig & config) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* BASE_DESCRIPTOR_H_ */
|
#endif /* BASE_DESCRIPTOR_H_ */
|
||||||
|
|||||||
@@ -1,95 +1,143 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, others 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
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
|
Redistributions of source code must retain the above copyright notice, this list
|
||||||
along with this program; if not, write to the Free Software
|
of conditions and the following disclaimer.
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
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 "DescriptionFactory.h"
|
#include "DescriptionFactory.h"
|
||||||
|
|
||||||
DescriptionFactory::DescriptionFactory() { }
|
DescriptionFactory::DescriptionFactory() : entireLength(0) { }
|
||||||
|
|
||||||
DescriptionFactory::~DescriptionFactory() { }
|
DescriptionFactory::~DescriptionFactory() { }
|
||||||
|
|
||||||
double DescriptionFactory::GetAngleBetweenCoordinates() const {
|
inline double DescriptionFactory::DegreeToRadian(const double degree) const {
|
||||||
return 0.;//GetAngleBetweenTwoEdges(previousCoordinate, currentCoordinate, nextCoordinate);
|
return degree * (M_PI/180);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DescriptionFactory::SetStartSegment(const PhantomNode & _startPhantom) {
|
inline double DescriptionFactory::RadianToDegree(const double radian) const {
|
||||||
startPhantom = _startPhantom;
|
return radian * (180/M_PI);
|
||||||
AppendSegment(_startPhantom.location, _PathData(0, _startPhantom.nodeBasedEdgeNameID, 10, _startPhantom.weight1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DescriptionFactory::SetEndSegment(const PhantomNode & _targetPhantom) {
|
double DescriptionFactory::GetBearing(
|
||||||
targetPhantom = _targetPhantom;
|
const FixedPointCoordinate & A,
|
||||||
pathDescription.push_back(SegmentInformation(_targetPhantom.location, _targetPhantom.nodeBasedEdgeNameID, 0, _targetPhantom.weight1, 0, true) );
|
const FixedPointCoordinate & B
|
||||||
}
|
) const {
|
||||||
|
double delta_long = DegreeToRadian(B.lon/COORDINATE_PRECISION - A.lon/COORDINATE_PRECISION);
|
||||||
|
|
||||||
void DescriptionFactory::AppendSegment(const _Coordinate & coordinate, const _PathData & data ) {
|
const double lat1 = DegreeToRadian(A.lat/COORDINATE_PRECISION);
|
||||||
pathDescription.push_back(SegmentInformation(coordinate, data.nameID, 0, data.durationOfSegment, data.turnInstruction) );
|
const double lat2 = DegreeToRadian(B.lat/COORDINATE_PRECISION);
|
||||||
}
|
|
||||||
|
|
||||||
void DescriptionFactory::AppendEncodedPolylineString(std::string & output, bool isEncoded) {
|
const double y = sin(delta_long) * cos(lat2);
|
||||||
if(isEncoded)
|
const double x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(delta_long);
|
||||||
pc.printEncodedString(pathDescription, output);
|
double result = RadianToDegree(atan2(y, x));
|
||||||
else
|
while(result < 0.) {
|
||||||
pc.printUnencodedString(pathDescription, output);
|
result += 360.;
|
||||||
}
|
|
||||||
|
|
||||||
void DescriptionFactory::AppendEncodedPolylineString(std::string &output) {
|
|
||||||
pc.printEncodedString(pathDescription, output);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DescriptionFactory::AppendUnencodedPolylineString(std::string &output) {
|
|
||||||
pc.printUnencodedString(pathDescription, output);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned DescriptionFactory::Run(const unsigned zoomLevel) {
|
|
||||||
if(0 == pathDescription.size())
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
unsigned entireLength = 0;
|
|
||||||
/** starts at index 1 */
|
|
||||||
pathDescription[0].length = 0;
|
|
||||||
for(unsigned i = 1; i < pathDescription.size(); ++i) {
|
|
||||||
pathDescription[i].length = ApproximateDistance(pathDescription[i-1].location, pathDescription[i].location);
|
|
||||||
}
|
}
|
||||||
|
while(result >= 360.) {
|
||||||
unsigned lengthOfSegment = 0;
|
result -= 360.;
|
||||||
unsigned durationOfSegment = 0;
|
|
||||||
unsigned indexOfSegmentBegin = 0;
|
|
||||||
|
|
||||||
for(unsigned i = 1; i < pathDescription.size(); ++i) {
|
|
||||||
entireLength += pathDescription[i].length;
|
|
||||||
lengthOfSegment += pathDescription[i].length;
|
|
||||||
durationOfSegment += pathDescription[i].duration;
|
|
||||||
pathDescription[indexOfSegmentBegin].length = lengthOfSegment;
|
|
||||||
pathDescription[indexOfSegmentBegin].duration = durationOfSegment;
|
|
||||||
if(pathDescription[i].turnInstruction != 0) {
|
|
||||||
//INFO("Turn after " << lengthOfSegment << "m into way with name id " << segment.nameID);
|
|
||||||
assert(pathDescription[i].necessary);
|
|
||||||
lengthOfSegment = 0;
|
|
||||||
durationOfSegment = 0;
|
|
||||||
indexOfSegmentBegin = i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
//Generalize poly line
|
}
|
||||||
dp.Run(pathDescription, zoomLevel);
|
|
||||||
|
void DescriptionFactory::SetStartSegment(const PhantomNode & start) {
|
||||||
//fix what needs to be fixed else
|
start_phantom = start;
|
||||||
return entireLength;
|
AppendSegment(
|
||||||
|
start.location,
|
||||||
|
PathData(0, start.nodeBasedEdgeNameID, 10, start.weight1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DescriptionFactory::SetEndSegment(const PhantomNode & target) {
|
||||||
|
target_phantom = target;
|
||||||
|
pathDescription.push_back(
|
||||||
|
SegmentInformation(
|
||||||
|
target.location,
|
||||||
|
target.nodeBasedEdgeNameID,
|
||||||
|
0,
|
||||||
|
target.weight1,
|
||||||
|
0,
|
||||||
|
true
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DescriptionFactory::AppendSegment(
|
||||||
|
const FixedPointCoordinate & coordinate,
|
||||||
|
const PathData & data
|
||||||
|
) {
|
||||||
|
if(
|
||||||
|
( 1 == pathDescription.size()) &&
|
||||||
|
( pathDescription.back().location == coordinate)
|
||||||
|
) {
|
||||||
|
pathDescription.back().name_id = data.name_id;
|
||||||
|
} else {
|
||||||
|
pathDescription.push_back(
|
||||||
|
SegmentInformation(
|
||||||
|
coordinate,
|
||||||
|
data.name_id,
|
||||||
|
data.durationOfSegment,
|
||||||
|
0,
|
||||||
|
data.turnInstruction
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DescriptionFactory::AppendEncodedPolylineString(
|
||||||
|
const bool return_encoded,
|
||||||
|
std::vector<std::string> & output
|
||||||
|
) {
|
||||||
|
std::string temp;
|
||||||
|
if(return_encoded) {
|
||||||
|
polyline_compressor.printEncodedString(pathDescription, temp);
|
||||||
|
} else {
|
||||||
|
polyline_compressor.printUnencodedString(pathDescription, temp);
|
||||||
|
}
|
||||||
|
output.push_back(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DescriptionFactory::AppendEncodedPolylineString(
|
||||||
|
std::vector<std::string> &output
|
||||||
|
) const {
|
||||||
|
std::string temp;
|
||||||
|
polyline_compressor.printEncodedString(pathDescription, temp);
|
||||||
|
output.push_back(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DescriptionFactory::AppendUnencodedPolylineString(
|
||||||
|
std::vector<std::string>& output
|
||||||
|
) const {
|
||||||
|
std::string temp;
|
||||||
|
polyline_compressor.printUnencodedString(pathDescription, temp);
|
||||||
|
output.push_back(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DescriptionFactory::BuildRouteSummary(
|
||||||
|
const double distance,
|
||||||
|
const unsigned time
|
||||||
|
) {
|
||||||
|
summary.startName = start_phantom.nodeBasedEdgeNameID;
|
||||||
|
summary.destName = target_phantom.nodeBasedEdgeNameID;
|
||||||
|
summary.BuildDurationAndLengthStrings(distance, time);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,98 +1,213 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, others 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
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
|
Redistributions of source code must retain the above copyright notice, this list
|
||||||
along with this program; if not, write to the Free Software
|
of conditions and the following disclaimer.
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
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 DESCRIPTIONFACTORY_H_
|
#ifndef DESCRIPTIONFACTORY_H_
|
||||||
#define DESCRIPTIONFACTORY_H_
|
#define DESCRIPTIONFACTORY_H_
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "../typedefs.h"
|
|
||||||
#include "../Algorithms/DouglasPeucker.h"
|
#include "../Algorithms/DouglasPeucker.h"
|
||||||
#include "../Algorithms/PolylineCompressor.h"
|
#include "../Algorithms/PolylineCompressor.h"
|
||||||
#include "../DataStructures/ExtractorStructs.h"
|
#include "../DataStructures/PhantomNodes.h"
|
||||||
|
#include "../DataStructures/RawRouteData.h"
|
||||||
#include "../DataStructures/SegmentInformation.h"
|
#include "../DataStructures/SegmentInformation.h"
|
||||||
|
#include "../DataStructures/TurnInstructions.h"
|
||||||
|
#include "../Util/SimpleLogger.h"
|
||||||
|
#include "../typedefs.h"
|
||||||
|
|
||||||
|
#include <osrm/Coordinate.h>
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
/* This class is fed with all way segments in consecutive order
|
/* This class is fed with all way segments in consecutive order
|
||||||
* and produces the description plus the encoded polyline */
|
* and produces the description plus the encoded polyline */
|
||||||
|
|
||||||
class DescriptionFactory {
|
class DescriptionFactory {
|
||||||
DouglasPeucker<SegmentInformation> dp;
|
DouglasPeucker polyline_generalizer;
|
||||||
PolylineCompressor pc;
|
PolylineCompressor polyline_compressor;
|
||||||
PhantomNode startPhantom, targetPhantom;
|
PhantomNode start_phantom, target_phantom;
|
||||||
|
|
||||||
|
double DegreeToRadian(const double degree) const;
|
||||||
|
double RadianToDegree(const double degree) const;
|
||||||
public:
|
public:
|
||||||
|
struct RouteSummary {
|
||||||
|
std::string lengthString;
|
||||||
|
std::string durationString;
|
||||||
|
unsigned startName;
|
||||||
|
unsigned destName;
|
||||||
|
RouteSummary() :
|
||||||
|
lengthString("0"),
|
||||||
|
durationString("0"),
|
||||||
|
startName(0),
|
||||||
|
destName(0)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void BuildDurationAndLengthStrings(
|
||||||
|
const double distance,
|
||||||
|
const unsigned time
|
||||||
|
) {
|
||||||
|
//compute distance/duration for route summary
|
||||||
|
intToString(round(distance), lengthString);
|
||||||
|
int travel_time = time/10;
|
||||||
|
intToString(std::max(travel_time, 1), durationString);
|
||||||
|
}
|
||||||
|
} summary;
|
||||||
|
|
||||||
|
double entireLength;
|
||||||
|
|
||||||
//I know, declaring this public is considered bad. I'm lazy
|
//I know, declaring this public is considered bad. I'm lazy
|
||||||
std::vector <SegmentInformation> pathDescription;
|
std::vector <SegmentInformation> pathDescription;
|
||||||
DescriptionFactory();
|
DescriptionFactory();
|
||||||
virtual ~DescriptionFactory();
|
virtual ~DescriptionFactory();
|
||||||
double GetAngleBetweenCoordinates() const;
|
double GetBearing(const FixedPointCoordinate& C, const FixedPointCoordinate& B) const;
|
||||||
void AppendEncodedPolylineString(std::string &output);
|
void AppendEncodedPolylineString(std::vector<std::string> &output) const;
|
||||||
void AppendUnencodedPolylineString(std::string &output);
|
void AppendUnencodedPolylineString(std::vector<std::string> &output) const;
|
||||||
void AppendSegment(const _Coordinate & coordinate, const _PathData & data);
|
void AppendSegment(const FixedPointCoordinate & coordinate, const PathData & data);
|
||||||
void SetStartSegment(const PhantomNode & startPhantom);
|
void BuildRouteSummary(const double distance, const unsigned time);
|
||||||
void SetEndSegment(const PhantomNode & startPhantom);
|
void SetStartSegment(const PhantomNode & start_phantom);
|
||||||
void AppendEncodedPolylineString(std::string & output, bool isEncoded);
|
void SetEndSegment(const PhantomNode & start_phantom);
|
||||||
unsigned Run(const unsigned zoomLevel);
|
void AppendEncodedPolylineString(
|
||||||
|
const bool return_encoded,
|
||||||
|
std::vector<std::string> & output
|
||||||
|
);
|
||||||
|
|
||||||
|
template<class DataFacadeT>
|
||||||
|
void Run(
|
||||||
|
const DataFacadeT * facade,
|
||||||
|
const unsigned zoomLevel
|
||||||
|
) {
|
||||||
|
if( pathDescription.empty() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** starts at index 1 */
|
||||||
|
pathDescription[0].length = 0;
|
||||||
|
for(unsigned i = 1; i < pathDescription.size(); ++i) {
|
||||||
|
pathDescription[i].length = FixedPointCoordinate::ApproximateEuclideanDistance(pathDescription[i-1].location, pathDescription[i].location);
|
||||||
|
}
|
||||||
|
|
||||||
|
// std::string string0 = facade->GetEscapedNameForNameID(pathDescription[0].name_id);
|
||||||
|
// std::string string1;
|
||||||
|
|
||||||
|
|
||||||
|
/*Simplify turn instructions
|
||||||
|
Input :
|
||||||
|
10. Turn left on B 36 for 20 km
|
||||||
|
11. Continue on B 35; B 36 for 2 km
|
||||||
|
12. Continue on B 36 for 13 km
|
||||||
|
|
||||||
|
becomes:
|
||||||
|
10. Turn left on B 36 for 35 km
|
||||||
|
*/
|
||||||
|
//TODO: rework to check only end and start of string.
|
||||||
|
// stl string is way to expensive
|
||||||
|
|
||||||
|
// unsigned lastTurn = 0;
|
||||||
|
// for(unsigned i = 1; i < pathDescription.size(); ++i) {
|
||||||
|
// string1 = sEngine.GetEscapedNameForNameID(pathDescription[i].name_id);
|
||||||
|
// if(TurnInstructionsClass::GoStraight == pathDescription[i].turn_instruction) {
|
||||||
|
// if(std::string::npos != string0.find(string1+";")
|
||||||
|
// || std::string::npos != string0.find(";"+string1)
|
||||||
|
// || std::string::npos != string0.find(string1+" ;")
|
||||||
|
// || std::string::npos != string0.find("; "+string1)
|
||||||
|
// ){
|
||||||
|
// SimpleLogger().Write() << "->next correct: " << string0 << " contains " << string1;
|
||||||
|
// for(; lastTurn != i; ++lastTurn)
|
||||||
|
// pathDescription[lastTurn].name_id = pathDescription[i].name_id;
|
||||||
|
// pathDescription[i].turn_instruction = TurnInstructionsClass::NoTurn;
|
||||||
|
// } else if(std::string::npos != string1.find(string0+";")
|
||||||
|
// || std::string::npos != string1.find(";"+string0)
|
||||||
|
// || std::string::npos != string1.find(string0+" ;")
|
||||||
|
// || std::string::npos != string1.find("; "+string0)
|
||||||
|
// ){
|
||||||
|
// SimpleLogger().Write() << "->prev correct: " << string1 << " contains " << string0;
|
||||||
|
// pathDescription[i].name_id = pathDescription[i-1].name_id;
|
||||||
|
// pathDescription[i].turn_instruction = TurnInstructionsClass::NoTurn;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (TurnInstructionsClass::NoTurn != pathDescription[i].turn_instruction) {
|
||||||
|
// lastTurn = i;
|
||||||
|
// }
|
||||||
|
// string0 = string1;
|
||||||
|
// }
|
||||||
|
|
||||||
|
double lengthOfSegment = 0;
|
||||||
|
unsigned durationOfSegment = 0;
|
||||||
|
unsigned indexOfSegmentBegin = 0;
|
||||||
|
|
||||||
|
for(unsigned i = 1; i < pathDescription.size(); ++i) {
|
||||||
|
entireLength += pathDescription[i].length;
|
||||||
|
lengthOfSegment += pathDescription[i].length;
|
||||||
|
durationOfSegment += pathDescription[i].duration;
|
||||||
|
pathDescription[indexOfSegmentBegin].length = lengthOfSegment;
|
||||||
|
pathDescription[indexOfSegmentBegin].duration = durationOfSegment;
|
||||||
|
|
||||||
|
|
||||||
|
if(TurnInstructionsClass::NoTurn != pathDescription[i].turn_instruction) {
|
||||||
|
BOOST_ASSERT(pathDescription[i].necessary);
|
||||||
|
lengthOfSegment = 0;
|
||||||
|
durationOfSegment = 0;
|
||||||
|
indexOfSegmentBegin = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Post-processing to remove empty or nearly empty path segments
|
||||||
|
if(std::numeric_limits<double>::epsilon() > pathDescription.back().length) {
|
||||||
|
if(pathDescription.size() > 2){
|
||||||
|
pathDescription.pop_back();
|
||||||
|
pathDescription.back().necessary = true;
|
||||||
|
pathDescription.back().turn_instruction = TurnInstructions.NoTurn;
|
||||||
|
target_phantom.nodeBasedEdgeNameID = (pathDescription.end()-2)->name_id;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pathDescription[indexOfSegmentBegin].duration *= (1.-target_phantom.ratio);
|
||||||
|
}
|
||||||
|
if(std::numeric_limits<double>::epsilon() > pathDescription[0].length) {
|
||||||
|
if(pathDescription.size() > 2) {
|
||||||
|
pathDescription.erase(pathDescription.begin());
|
||||||
|
pathDescription[0].turn_instruction = TurnInstructions.HeadOn;
|
||||||
|
pathDescription[0].necessary = true;
|
||||||
|
start_phantom.nodeBasedEdgeNameID = pathDescription[0].name_id;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pathDescription[0].duration *= start_phantom.ratio;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Generalize poly line
|
||||||
|
polyline_generalizer.Run(pathDescription, zoomLevel);
|
||||||
|
|
||||||
|
//fix what needs to be fixed else
|
||||||
|
for(unsigned i = 0; i < pathDescription.size()-1 && pathDescription.size() >= 2; ++i){
|
||||||
|
if(pathDescription[i].necessary) {
|
||||||
|
double angle = GetBearing(pathDescription[i].location, pathDescription[i+1].location);
|
||||||
|
pathDescription[i].bearing = angle*10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DESCRIPTIONFACTORY_H_ */
|
#endif /* DESCRIPTIONFACTORY_H_ */
|
||||||
|
|
||||||
//private:
|
|
||||||
// void appendInstructionNameToString(const std::string & nameOfStreet, const std::string & instructionOrDirection, std::string &output, bool firstAdvice = false) {
|
|
||||||
// output += "[";
|
|
||||||
// if(config.instructions) {
|
|
||||||
// output += "\"";
|
|
||||||
// if(firstAdvice) {
|
|
||||||
// output += "Head ";
|
|
||||||
// }
|
|
||||||
// output += instructionOrDirection;
|
|
||||||
// output += "\",\"";
|
|
||||||
// output += nameOfStreet;
|
|
||||||
// output += "\",";
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// void appendInstructionLengthToString(unsigned length, std::string &output) {
|
|
||||||
// if(config.instructions){
|
|
||||||
// std::string tmpDistance;
|
|
||||||
// intToString(10*(round(length/10.)), tmpDistance);
|
|
||||||
// output += tmpDistance;
|
|
||||||
// output += ",";
|
|
||||||
// intToString(descriptionFactory.startIndexOfGeometry, tmp);
|
|
||||||
// output += tmp;
|
|
||||||
// output += ",";
|
|
||||||
// intToString(descriptionFactory.durationOfInstruction, tmp);
|
|
||||||
// output += tmp;
|
|
||||||
// output += ",";
|
|
||||||
// output += "\"";
|
|
||||||
// output += tmpDistance;
|
|
||||||
// output += "\",";
|
|
||||||
// double angle = descriptionFactory.GetAngleBetweenCoordinates();
|
|
||||||
// DirectionOfInstruction direction;
|
|
||||||
// getDirectionOfInstruction(angle, direction);
|
|
||||||
// output += "\"";
|
|
||||||
// output += direction.shortDirection;
|
|
||||||
// output += "\",";
|
|
||||||
// std::stringstream numberString;
|
|
||||||
// numberString << fixed << setprecision(2) << angle;
|
|
||||||
// output += numberString.str();
|
|
||||||
// }
|
|
||||||
// output += "]";
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,67 +1,106 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, others 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
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
|
Redistributions of source code must retain the above copyright notice, this list
|
||||||
along with this program; if not, write to the Free Software
|
of conditions and the following disclaimer.
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
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_
|
#ifndef GPX_DESCRIPTOR_H_
|
||||||
#define GPX_DESCRIPTOR_H_
|
#define GPX_DESCRIPTOR_H_
|
||||||
|
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
#include "BaseDescriptor.h"
|
#include "BaseDescriptor.h"
|
||||||
|
|
||||||
template<class SearchEngineT>
|
#include <boost/foreach.hpp>
|
||||||
class GPXDescriptor : public BaseDescriptor<SearchEngineT>{
|
|
||||||
|
template<class DataFacadeT>
|
||||||
|
class GPXDescriptor : public BaseDescriptor<DataFacadeT> {
|
||||||
private:
|
private:
|
||||||
_DescriptorConfig config;
|
DescriptorConfig config;
|
||||||
_Coordinate current;
|
FixedPointCoordinate current;
|
||||||
|
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
public:
|
public:
|
||||||
void SetConfig(const _DescriptorConfig& c) { config = c; }
|
void SetConfig(const DescriptorConfig & c) { config = c; }
|
||||||
void Run(http::Reply & reply, RawRouteData &rawRoute, PhantomNodes &phantomNodes, SearchEngineT &sEngine, unsigned distance) {
|
|
||||||
reply.content += ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
//TODO: reorder parameters
|
||||||
reply.content += "<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" "
|
void Run(
|
||||||
|
const RawRouteData &raw_route,
|
||||||
|
const PhantomNodes &phantom_node_list,
|
||||||
|
DataFacadeT * facade,
|
||||||
|
http::Reply & reply
|
||||||
|
) {
|
||||||
|
reply.content.push_back("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||||
|
reply.content.push_back(
|
||||||
|
"<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\" "
|
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
|
||||||
"xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 gpx.xsd"
|
"xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 gpx.xsd"
|
||||||
"\">";
|
"\">");
|
||||||
reply.content += "<rte>";
|
reply.content.push_back(
|
||||||
if(distance != UINT_MAX && rawRoute.routeSegments.size()) {
|
"<metadata><copyright author=\"Project OSRM\"><license>Data (c)"
|
||||||
convertInternalLatLonToString(phantomNodes.startPhantom.location.lat, tmp);
|
" OpenStreetMap contributors (ODbL)</license></copyright>"
|
||||||
reply.content += "<rtept lat=\"" + tmp + "\" ";
|
"</metadata>");
|
||||||
convertInternalLatLonToString(phantomNodes.startPhantom.location.lon, tmp);
|
reply.content.push_back("<rte>");
|
||||||
reply.content += "lon=\"" + tmp + "\"></rtept>";
|
bool found_route = (raw_route.lengthOfShortestPath != INT_MAX) &&
|
||||||
|
(raw_route.unpacked_path_segments[0].size());
|
||||||
|
if( found_route ) {
|
||||||
|
FixedPointCoordinate::convertInternalLatLonToString(
|
||||||
|
phantom_node_list.startPhantom.location.lat,
|
||||||
|
tmp
|
||||||
|
);
|
||||||
|
reply.content.push_back("<rtept lat=\"" + tmp + "\" ");
|
||||||
|
FixedPointCoordinate::convertInternalLatLonToString(
|
||||||
|
phantom_node_list.startPhantom.location.lon,
|
||||||
|
tmp
|
||||||
|
);
|
||||||
|
reply.content.push_back("lon=\"" + tmp + "\"></rtept>");
|
||||||
|
|
||||||
for(unsigned segmentIdx = 0; segmentIdx < rawRoute.routeSegments.size(); segmentIdx++) {
|
for(unsigned i=0; i < raw_route.unpacked_path_segments.size(); ++i){
|
||||||
BOOST_FOREACH(_PathData pathData, rawRoute.routeSegments[segmentIdx]) {
|
BOOST_FOREACH(
|
||||||
sEngine.GetCoordinatesForNodeID(pathData.node, current);
|
const PathData & pathData,
|
||||||
|
raw_route.unpacked_path_segments[i]
|
||||||
|
) {
|
||||||
|
current = facade->GetCoordinateOfNode(pathData.node);
|
||||||
|
|
||||||
convertInternalLatLonToString(current.lat, tmp);
|
FixedPointCoordinate::convertInternalLatLonToString(current.lat, tmp);
|
||||||
reply.content += "<rtept lat=\"" + tmp + "\" ";
|
reply.content.push_back("<rtept lat=\"" + tmp + "\" ");
|
||||||
convertInternalLatLonToString(current.lon, tmp);
|
FixedPointCoordinate::convertInternalLatLonToString(current.lon, tmp);
|
||||||
reply.content += "lon=\"" + tmp + "\"></rtept>";
|
reply.content.push_back("lon=\"" + tmp + "\"></rtept>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
convertInternalLatLonToString(phantomNodes.targetPhantom.location.lat, tmp);
|
// Add the via point or the end coordinate
|
||||||
reply.content += "<rtept lat=\"" + tmp + "\" ";
|
FixedPointCoordinate::convertInternalLatLonToString(
|
||||||
convertInternalLatLonToString(phantomNodes.targetPhantom.location.lon, tmp);
|
phantom_node_list.targetPhantom.location.lat,
|
||||||
reply.content += "lon=\"" + tmp + "\"></rtept>";
|
tmp
|
||||||
|
);
|
||||||
|
reply.content.push_back("<rtept lat=\"" + tmp + "\" ");
|
||||||
|
FixedPointCoordinate::convertInternalLatLonToString(
|
||||||
|
phantom_node_list.targetPhantom.location.lon,
|
||||||
|
tmp
|
||||||
|
);
|
||||||
|
reply.content.push_back("lon=\"" + tmp + "\"></rtept>");
|
||||||
}
|
}
|
||||||
reply.content += "</rte></gpx>";
|
reply.content.push_back("</rte></gpx>");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif /* GPX_DESCRIPTOR_H_ */
|
#endif // GPX_DESCRIPTOR_H_
|
||||||
|
|||||||
@@ -1,176 +1,510 @@
|
|||||||
/*
|
/*
|
||||||
open source routing machine
|
|
||||||
Copyright (C) Dennis Luxen, others 2010
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||||
it under the terms of the GNU AFFERO General Public License as published by
|
All rights reserved.
|
||||||
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
are permitted provided that the following conditions are met:
|
||||||
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
|
Redistributions of source code must retain the above copyright notice, this list
|
||||||
along with this program; if not, write to the Free Software
|
of conditions and the following disclaimer.
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
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 JSON_DESCRIPTOR_H_
|
#ifndef JSON_DESCRIPTOR_H_
|
||||||
#define JSON_DESCRIPTOR_H_
|
#define JSON_DESCRIPTOR_H_
|
||||||
|
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
|
|
||||||
#include "BaseDescriptor.h"
|
#include "BaseDescriptor.h"
|
||||||
#include "DescriptionFactory.h"
|
#include "DescriptionFactory.h"
|
||||||
|
#include "../Algorithms/ObjectToBase64.h"
|
||||||
#include "../DataStructures/SegmentInformation.h"
|
#include "../DataStructures/SegmentInformation.h"
|
||||||
#include "../DataStructures/TurnInstructions.h"
|
#include "../DataStructures/TurnInstructions.h"
|
||||||
|
#include "../Util/Azimuth.h"
|
||||||
#include "../Util/StringUtil.h"
|
#include "../Util/StringUtil.h"
|
||||||
|
|
||||||
template<class SearchEngineT>
|
#include <boost/bind.hpp>
|
||||||
class JSONDescriptor : public BaseDescriptor<SearchEngineT>{
|
#include <boost/lambda/lambda.hpp>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
template<class DataFacadeT>
|
||||||
|
class JSONDescriptor : public BaseDescriptor<DataFacadeT> {
|
||||||
private:
|
private:
|
||||||
_DescriptorConfig config;
|
DataFacadeT * facade;
|
||||||
_RouteSummary summary;
|
DescriptorConfig config;
|
||||||
DescriptionFactory descriptionFactory;
|
DescriptionFactory description_factory;
|
||||||
std::string tmp;
|
DescriptionFactory alternate_descriptionFactory;
|
||||||
_Coordinate current;
|
FixedPointCoordinate current;
|
||||||
struct {
|
unsigned entered_restricted_area_count;
|
||||||
int startIndex;
|
struct RoundAbout{
|
||||||
int nameID;
|
RoundAbout() :
|
||||||
int leaveAtExit;
|
start_index(INT_MAX),
|
||||||
|
name_id(INT_MAX),
|
||||||
|
leave_at_exit(INT_MAX)
|
||||||
|
{}
|
||||||
|
int start_index;
|
||||||
|
int name_id;
|
||||||
|
int leave_at_exit;
|
||||||
} roundAbout;
|
} roundAbout;
|
||||||
|
|
||||||
|
struct Segment {
|
||||||
|
Segment() : name_id(-1), length(-1), position(-1) {}
|
||||||
|
Segment(int n, int l, int p) : name_id(n), length(l), position(p) {}
|
||||||
|
int name_id;
|
||||||
|
int length;
|
||||||
|
int position;
|
||||||
|
};
|
||||||
|
std::vector<Segment> shortest_path_segments, alternative_path_segments;
|
||||||
|
std::vector<unsigned> shortest_leg_end_indices, alternative_leg_end_indices;
|
||||||
|
|
||||||
|
struct RouteNames {
|
||||||
|
std::string shortestPathName1;
|
||||||
|
std::string shortestPathName2;
|
||||||
|
std::string alternativePathName1;
|
||||||
|
std::string alternativePathName2;
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
JSONDescriptor() {}
|
JSONDescriptor() :
|
||||||
void SetConfig(const _DescriptorConfig & c) { config = c; }
|
facade(NULL),
|
||||||
|
entered_restricted_area_count(0)
|
||||||
void Run(http::Reply & reply, RawRouteData &rawRoute, PhantomNodes &phantomNodes, SearchEngineT &sEngine, unsigned durationOfTrip) {
|
{
|
||||||
WriteHeaderToOutput(reply.content);
|
shortest_leg_end_indices.push_back(0);
|
||||||
if(durationOfTrip != INT_MAX && rawRoute.routeSegments.size() > 0) {
|
alternative_leg_end_indices.push_back(0);
|
||||||
summary.startName = sEngine.GetEscapedNameForNameID(phantomNodes.startPhantom.nodeBasedEdgeNameID);
|
|
||||||
descriptionFactory.SetStartSegment(phantomNodes.startPhantom);
|
|
||||||
summary.destName = sEngine.GetEscapedNameForNameID(phantomNodes.targetPhantom.nodeBasedEdgeNameID);
|
|
||||||
reply.content += "0,"
|
|
||||||
"\"status_message\": \"Found route between points\",";
|
|
||||||
for(unsigned segmentIdx = 0; segmentIdx < rawRoute.routeSegments.size(); segmentIdx++) {
|
|
||||||
const std::vector< _PathData > & path = rawRoute.routeSegments[segmentIdx];
|
|
||||||
BOOST_FOREACH(_PathData pathData, path) {
|
|
||||||
sEngine.GetCoordinatesForNodeID(pathData.node, current);
|
|
||||||
descriptionFactory.AppendSegment(current, pathData );
|
|
||||||
}
|
|
||||||
//TODO: Add via points
|
|
||||||
}
|
|
||||||
descriptionFactory.SetEndSegment(phantomNodes.targetPhantom);
|
|
||||||
} else {
|
|
||||||
//We do not need to do much, if there is no route ;-)
|
|
||||||
reply.content += "207,"
|
|
||||||
"\"status_message\": \"Cannot find route between points\",";
|
|
||||||
}
|
|
||||||
|
|
||||||
summary.BuildDurationAndLengthStrings(descriptionFactory.Run(config.z), durationOfTrip);
|
|
||||||
|
|
||||||
reply.content += "\"route_summary\": {"
|
|
||||||
"\"total_distance\":";
|
|
||||||
reply.content += summary.lengthString;
|
|
||||||
reply.content += ","
|
|
||||||
"\"total_time\":";
|
|
||||||
reply.content += summary.durationString;
|
|
||||||
reply.content += ","
|
|
||||||
"\"start_point\":\"";
|
|
||||||
reply.content += summary.startName;
|
|
||||||
reply.content += "\","
|
|
||||||
"\"end_point\":\"";
|
|
||||||
reply.content += summary.destName;
|
|
||||||
reply.content += "\"";
|
|
||||||
reply.content += "},";
|
|
||||||
reply.content += "\"route_geometry\": ";
|
|
||||||
if(config.geometry) {
|
|
||||||
if(config.encodeGeometry)
|
|
||||||
descriptionFactory.AppendEncodedPolylineString(reply.content, config.encodeGeometry);
|
|
||||||
} else {
|
|
||||||
reply.content += "[]";
|
|
||||||
}
|
|
||||||
|
|
||||||
reply.content += ","
|
|
||||||
"\"route_instructions\": [";
|
|
||||||
if(config.instructions) {
|
|
||||||
//Segment information has following format:
|
|
||||||
//["instruction","streetname",length,position,time,"length","earth_direction",azimuth]
|
|
||||||
//Example: ["Turn left","High Street",200,4,10,"200m","NE",22.5]
|
|
||||||
//See also: http://developers.cloudmade.com/wiki/navengine/JSON_format
|
|
||||||
unsigned prefixSumOfNecessarySegments = 0;
|
|
||||||
roundAbout.leaveAtExit = 0;
|
|
||||||
roundAbout.nameID = 0;
|
|
||||||
std::string tmpDist, tmpLength, tmp;
|
|
||||||
//Fetch data from Factory and generate a string from it.
|
|
||||||
BOOST_FOREACH(SegmentInformation segment, descriptionFactory.pathDescription) {
|
|
||||||
if(TurnInstructions.TurnIsNecessary( segment.turnInstruction) ) {
|
|
||||||
if(TurnInstructions.EnterRoundAbout == segment.turnInstruction) {
|
|
||||||
roundAbout.nameID = segment.nameID;
|
|
||||||
roundAbout.startIndex = prefixSumOfNecessarySegments;
|
|
||||||
} else {
|
|
||||||
if(0 != prefixSumOfNecessarySegments)
|
|
||||||
reply.content += ",";
|
|
||||||
|
|
||||||
reply.content += "[\"";
|
|
||||||
if(TurnInstructions.LeaveRoundAbout == segment.turnInstruction) {
|
|
||||||
reply.content += TurnInstructions.TurnStrings[TurnInstructions.EnterRoundAbout];
|
|
||||||
reply.content += " and leave at ";
|
|
||||||
reply.content += TurnInstructions.Ordinals[roundAbout.leaveAtExit+1];
|
|
||||||
reply.content += " exit";
|
|
||||||
roundAbout.leaveAtExit = 0;
|
|
||||||
} else {
|
|
||||||
reply.content += TurnInstructions.TurnStrings[segment.turnInstruction];
|
|
||||||
}
|
|
||||||
reply.content += "\",\"";
|
|
||||||
reply.content += sEngine.GetEscapedNameForNameID(segment.nameID);
|
|
||||||
reply.content += "\",";
|
|
||||||
intToString(segment.length, tmpDist);
|
|
||||||
reply.content += tmpDist;
|
|
||||||
reply.content += ",";
|
|
||||||
intToString(prefixSumOfNecessarySegments, tmpLength);
|
|
||||||
reply.content += tmpLength;
|
|
||||||
reply.content += ",";
|
|
||||||
intToString(segment.duration, tmp);
|
|
||||||
reply.content += ",\"";
|
|
||||||
reply.content += tmpLength;
|
|
||||||
//TODO: fix heading
|
|
||||||
reply.content += "\",\"NE\",22.5";
|
|
||||||
reply.content += "]";
|
|
||||||
}
|
|
||||||
} else if(TurnInstructions.StayOnRoundAbout == segment.turnInstruction) {
|
|
||||||
++roundAbout.leaveAtExit;
|
|
||||||
}
|
|
||||||
if(segment.necessary)
|
|
||||||
++prefixSumOfNecessarySegments;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
reply.content += "],";
|
|
||||||
//list all viapoints so that the client may display it
|
|
||||||
reply.content += "\"via_points\":[";
|
|
||||||
for(unsigned segmentIdx = 1; (true == config.geometry) && (segmentIdx < rawRoute.segmentEndCoordinates.size()); segmentIdx++) {
|
|
||||||
if(segmentIdx > 1)
|
|
||||||
reply.content += ",";
|
|
||||||
reply.content += "[";
|
|
||||||
if(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location.isSet())
|
|
||||||
convertInternalReversedCoordinateToString(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location, tmp);
|
|
||||||
else
|
|
||||||
convertInternalReversedCoordinateToString(rawRoute.rawViaNodeCoordinates[segmentIdx], tmp);
|
|
||||||
reply.content += tmp;
|
|
||||||
reply.content += "]";
|
|
||||||
}
|
|
||||||
reply.content += "],"
|
|
||||||
"\"transactionId\": \"OSRM Routing Engine JSON Descriptor (v0.2)\"";
|
|
||||||
reply.content += "}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteHeaderToOutput(std::string & output) {
|
void SetConfig(const DescriptorConfig & c) { config = c; }
|
||||||
output += "{"
|
|
||||||
"\"version\": 0.3,"
|
int DescribeLeg(
|
||||||
"\"status\":";
|
const std::vector<PathData> & route_leg,
|
||||||
|
const PhantomNodes & leg_phantoms
|
||||||
|
) {
|
||||||
|
int added_element_count = 0;
|
||||||
|
//Get all the coordinates for the computed route
|
||||||
|
FixedPointCoordinate current_coordinate;
|
||||||
|
BOOST_FOREACH(const PathData & path_data, route_leg) {
|
||||||
|
current_coordinate = facade->GetCoordinateOfNode(path_data.node);
|
||||||
|
description_factory.AppendSegment(current_coordinate, path_data );
|
||||||
|
++added_element_count;
|
||||||
|
}
|
||||||
|
// description_factory.SetEndSegment( leg_phantoms.targetPhantom );
|
||||||
|
++added_element_count;
|
||||||
|
BOOST_ASSERT( (int)(route_leg.size() + 1) == added_element_count );
|
||||||
|
return added_element_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Run(
|
||||||
|
const RawRouteData & raw_route,
|
||||||
|
const PhantomNodes & phantom_nodes,
|
||||||
|
// TODO: move facade initalization to c'tor
|
||||||
|
DataFacadeT * f,
|
||||||
|
http::Reply & reply
|
||||||
|
) {
|
||||||
|
facade = f;
|
||||||
|
reply.content.push_back(
|
||||||
|
"{\"status\":"
|
||||||
|
);
|
||||||
|
|
||||||
|
if(INT_MAX == raw_route.lengthOfShortestPath) {
|
||||||
|
//We do not need to do much, if there is no route ;-)
|
||||||
|
reply.content.push_back(
|
||||||
|
"207,\"status_message\": \"Cannot find route between points\"}"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
description_factory.SetStartSegment(phantom_nodes.startPhantom);
|
||||||
|
reply.content.push_back("0,"
|
||||||
|
"\"status_message\": \"Found route between points\",");
|
||||||
|
|
||||||
|
BOOST_ASSERT( raw_route.unpacked_path_segments.size() == raw_route.segmentEndCoordinates.size() );
|
||||||
|
for( unsigned i = 0; i < raw_route.unpacked_path_segments.size(); ++i ) {
|
||||||
|
const int added_segments = DescribeLeg(
|
||||||
|
raw_route.unpacked_path_segments[i],
|
||||||
|
raw_route.segmentEndCoordinates[i]
|
||||||
|
);
|
||||||
|
BOOST_ASSERT( 0 < added_segments );
|
||||||
|
shortest_leg_end_indices.push_back(
|
||||||
|
added_segments + shortest_leg_end_indices.back()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
description_factory.SetEndSegment(phantom_nodes.targetPhantom);
|
||||||
|
description_factory.Run(facade, config.zoom_level);
|
||||||
|
|
||||||
|
reply.content.push_back("\"route_geometry\": ");
|
||||||
|
if(config.geometry) {
|
||||||
|
description_factory.AppendEncodedPolylineString(
|
||||||
|
config.encode_geometry,
|
||||||
|
reply.content
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
reply.content.push_back("[]");
|
||||||
|
}
|
||||||
|
|
||||||
|
reply.content.push_back(",\"route_instructions\": [");
|
||||||
|
if(config.instructions) {
|
||||||
|
BuildTextualDescription(
|
||||||
|
description_factory,
|
||||||
|
reply,
|
||||||
|
raw_route.lengthOfShortestPath,
|
||||||
|
facade,
|
||||||
|
shortest_path_segments
|
||||||
|
);
|
||||||
|
}
|
||||||
|
reply.content.push_back("],");
|
||||||
|
description_factory.BuildRouteSummary(
|
||||||
|
description_factory.entireLength,
|
||||||
|
raw_route.lengthOfShortestPath
|
||||||
|
);
|
||||||
|
|
||||||
|
reply.content.push_back("\"route_summary\":");
|
||||||
|
reply.content.push_back("{");
|
||||||
|
reply.content.push_back("\"total_distance\":");
|
||||||
|
reply.content.push_back(description_factory.summary.lengthString);
|
||||||
|
reply.content.push_back(","
|
||||||
|
"\"total_time\":");
|
||||||
|
reply.content.push_back(description_factory.summary.durationString);
|
||||||
|
reply.content.push_back(","
|
||||||
|
"\"start_point\":\"");
|
||||||
|
reply.content.push_back(
|
||||||
|
facade->GetEscapedNameForNameID(description_factory.summary.startName)
|
||||||
|
);
|
||||||
|
reply.content.push_back("\","
|
||||||
|
"\"end_point\":\"");
|
||||||
|
reply.content.push_back(
|
||||||
|
facade->GetEscapedNameForNameID(description_factory.summary.destName)
|
||||||
|
);
|
||||||
|
reply.content.push_back("\"");
|
||||||
|
reply.content.push_back("}");
|
||||||
|
reply.content.push_back(",");
|
||||||
|
|
||||||
|
//only one alternative route is computed at this time, so this is hardcoded
|
||||||
|
|
||||||
|
if(raw_route.lengthOfAlternativePath != INT_MAX) {
|
||||||
|
alternate_descriptionFactory.SetStartSegment(phantom_nodes.startPhantom);
|
||||||
|
//Get all the coordinates for the computed route
|
||||||
|
BOOST_FOREACH(const PathData & path_data, raw_route.unpacked_alternative) {
|
||||||
|
current = facade->GetCoordinateOfNode(path_data.node);
|
||||||
|
alternate_descriptionFactory.AppendSegment(current, path_data );
|
||||||
|
}
|
||||||
|
alternate_descriptionFactory.SetEndSegment(phantom_nodes.targetPhantom);
|
||||||
|
}
|
||||||
|
alternate_descriptionFactory.Run(facade, config.zoom_level);
|
||||||
|
|
||||||
|
// //give an array of alternative routes
|
||||||
|
reply.content.push_back("\"alternative_geometries\": [");
|
||||||
|
if(config.geometry && INT_MAX != raw_route.lengthOfAlternativePath) {
|
||||||
|
//Generate the linestrings for each alternative
|
||||||
|
alternate_descriptionFactory.AppendEncodedPolylineString(
|
||||||
|
config.encode_geometry,
|
||||||
|
reply.content
|
||||||
|
);
|
||||||
|
}
|
||||||
|
reply.content.push_back("],");
|
||||||
|
reply.content.push_back("\"alternative_instructions\":[");
|
||||||
|
if(INT_MAX != raw_route.lengthOfAlternativePath) {
|
||||||
|
reply.content.push_back("[");
|
||||||
|
//Generate instructions for each alternative
|
||||||
|
if(config.instructions) {
|
||||||
|
BuildTextualDescription(
|
||||||
|
alternate_descriptionFactory,
|
||||||
|
reply,
|
||||||
|
raw_route.lengthOfAlternativePath,
|
||||||
|
facade,
|
||||||
|
alternative_path_segments
|
||||||
|
);
|
||||||
|
}
|
||||||
|
reply.content.push_back("]");
|
||||||
|
}
|
||||||
|
reply.content.push_back("],");
|
||||||
|
reply.content.push_back("\"alternative_summaries\":[");
|
||||||
|
if(INT_MAX != raw_route.lengthOfAlternativePath) {
|
||||||
|
//Generate route summary (length, duration) for each alternative
|
||||||
|
alternate_descriptionFactory.BuildRouteSummary(
|
||||||
|
alternate_descriptionFactory.entireLength,
|
||||||
|
raw_route.lengthOfAlternativePath
|
||||||
|
);
|
||||||
|
reply.content.push_back("{");
|
||||||
|
reply.content.push_back("\"total_distance\":");
|
||||||
|
reply.content.push_back(
|
||||||
|
alternate_descriptionFactory.summary.lengthString
|
||||||
|
);
|
||||||
|
reply.content.push_back(","
|
||||||
|
"\"total_time\":");
|
||||||
|
reply.content.push_back(
|
||||||
|
alternate_descriptionFactory.summary.durationString
|
||||||
|
);
|
||||||
|
reply.content.push_back(","
|
||||||
|
"\"start_point\":\"");
|
||||||
|
reply.content.push_back(
|
||||||
|
facade->GetEscapedNameForNameID(
|
||||||
|
description_factory.summary.startName
|
||||||
|
)
|
||||||
|
);
|
||||||
|
reply.content.push_back("\","
|
||||||
|
"\"end_point\":\"");
|
||||||
|
reply.content.push_back(facade->GetEscapedNameForNameID(description_factory.summary.destName));
|
||||||
|
reply.content.push_back("\"");
|
||||||
|
reply.content.push_back("}");
|
||||||
|
}
|
||||||
|
reply.content.push_back("],");
|
||||||
|
|
||||||
|
// //Get Names for both routes
|
||||||
|
RouteNames routeNames;
|
||||||
|
GetRouteNames(shortest_path_segments, alternative_path_segments, facade, routeNames);
|
||||||
|
|
||||||
|
reply.content.push_back("\"route_name\":[\"");
|
||||||
|
reply.content.push_back(routeNames.shortestPathName1);
|
||||||
|
reply.content.push_back("\",\"");
|
||||||
|
reply.content.push_back(routeNames.shortestPathName2);
|
||||||
|
reply.content.push_back("\"],"
|
||||||
|
"\"alternative_names\":[");
|
||||||
|
reply.content.push_back("[\"");
|
||||||
|
reply.content.push_back(routeNames.alternativePathName1);
|
||||||
|
reply.content.push_back("\",\"");
|
||||||
|
reply.content.push_back(routeNames.alternativePathName2);
|
||||||
|
reply.content.push_back("\"]");
|
||||||
|
reply.content.push_back("],");
|
||||||
|
//list all viapoints so that the client may display it
|
||||||
|
reply.content.push_back("\"via_points\":[");
|
||||||
|
|
||||||
|
BOOST_ASSERT( !raw_route.segmentEndCoordinates.empty() );
|
||||||
|
|
||||||
|
std::string tmp;
|
||||||
|
FixedPointCoordinate::convertInternalReversedCoordinateToString(
|
||||||
|
raw_route.segmentEndCoordinates.front().startPhantom.location,
|
||||||
|
tmp
|
||||||
|
);
|
||||||
|
reply.content.push_back("[");
|
||||||
|
reply.content.push_back(tmp);
|
||||||
|
reply.content.push_back("]");
|
||||||
|
|
||||||
|
BOOST_FOREACH(const PhantomNodes & nodes, raw_route.segmentEndCoordinates) {
|
||||||
|
tmp.clear();
|
||||||
|
FixedPointCoordinate::convertInternalReversedCoordinateToString(
|
||||||
|
nodes.targetPhantom.location,
|
||||||
|
tmp
|
||||||
|
);
|
||||||
|
reply.content.push_back(",[");
|
||||||
|
reply.content.push_back(tmp);
|
||||||
|
reply.content.push_back("]");
|
||||||
|
}
|
||||||
|
|
||||||
|
reply.content.push_back("],");
|
||||||
|
reply.content.push_back("\"via_indices\":[");
|
||||||
|
BOOST_FOREACH(const unsigned index, shortest_leg_end_indices) {
|
||||||
|
tmp.clear();
|
||||||
|
intToString(index, tmp);
|
||||||
|
reply.content.push_back(tmp);
|
||||||
|
if( index != shortest_leg_end_indices.back() ) {
|
||||||
|
reply.content.push_back(",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reply.content.push_back("],\"alternative_indices\":[");
|
||||||
|
if(INT_MAX != raw_route.lengthOfAlternativePath) {
|
||||||
|
reply.content.push_back("0,");
|
||||||
|
tmp.clear();
|
||||||
|
intToString(alternate_descriptionFactory.pathDescription.size(), tmp);
|
||||||
|
reply.content.push_back(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
reply.content.push_back("],");
|
||||||
|
reply.content.push_back("\"hint_data\": {");
|
||||||
|
reply.content.push_back("\"checksum\":");
|
||||||
|
intToString(raw_route.checkSum, tmp);
|
||||||
|
reply.content.push_back(tmp);
|
||||||
|
reply.content.push_back(", \"locations\": [");
|
||||||
|
|
||||||
|
std::string hint;
|
||||||
|
for(unsigned i = 0; i < raw_route.segmentEndCoordinates.size(); ++i) {
|
||||||
|
reply.content.push_back("\"");
|
||||||
|
EncodeObjectToBase64(raw_route.segmentEndCoordinates[i].startPhantom, hint);
|
||||||
|
reply.content.push_back(hint);
|
||||||
|
reply.content.push_back("\", ");
|
||||||
|
}
|
||||||
|
EncodeObjectToBase64(raw_route.segmentEndCoordinates.back().targetPhantom, hint);
|
||||||
|
reply.content.push_back("\"");
|
||||||
|
reply.content.push_back(hint);
|
||||||
|
reply.content.push_back("\"]");
|
||||||
|
reply.content.push_back("}}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// construct routes names
|
||||||
|
void GetRouteNames(
|
||||||
|
std::vector<Segment> & shortest_path_segments,
|
||||||
|
std::vector<Segment> & alternative_path_segments,
|
||||||
|
const DataFacadeT * facade,
|
||||||
|
RouteNames & routeNames
|
||||||
|
) {
|
||||||
|
|
||||||
|
Segment shortestSegment1, shortestSegment2;
|
||||||
|
Segment alternativeSegment1, alternativeSegment2;
|
||||||
|
|
||||||
|
if(0 < shortest_path_segments.size()) {
|
||||||
|
sort(shortest_path_segments.begin(), shortest_path_segments.end(), boost::bind(&Segment::length, _1) > boost::bind(&Segment::length, _2) );
|
||||||
|
shortestSegment1 = shortest_path_segments[0];
|
||||||
|
if(0 < alternative_path_segments.size()) {
|
||||||
|
sort(alternative_path_segments.begin(), alternative_path_segments.end(), boost::bind(&Segment::length, _1) > boost::bind(&Segment::length, _2) );
|
||||||
|
alternativeSegment1 = alternative_path_segments[0];
|
||||||
|
}
|
||||||
|
std::vector<Segment> shortestDifference(shortest_path_segments.size());
|
||||||
|
std::vector<Segment> alternativeDifference(alternative_path_segments.size());
|
||||||
|
std::set_difference(shortest_path_segments.begin(), shortest_path_segments.end(), alternative_path_segments.begin(), alternative_path_segments.end(), shortestDifference.begin(), boost::bind(&Segment::name_id, _1) < boost::bind(&Segment::name_id, _2) );
|
||||||
|
int size_of_difference = shortestDifference.size();
|
||||||
|
if(0 < size_of_difference ) {
|
||||||
|
int i = 0;
|
||||||
|
while( i < size_of_difference && shortestDifference[i].name_id == shortest_path_segments[0].name_id) {
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
if(i < size_of_difference ) {
|
||||||
|
shortestSegment2 = shortestDifference[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::set_difference(alternative_path_segments.begin(), alternative_path_segments.end(), shortest_path_segments.begin(), shortest_path_segments.end(), alternativeDifference.begin(), boost::bind(&Segment::name_id, _1) < boost::bind(&Segment::name_id, _2) );
|
||||||
|
size_of_difference = alternativeDifference.size();
|
||||||
|
if(0 < size_of_difference ) {
|
||||||
|
int i = 0;
|
||||||
|
while( i < size_of_difference && alternativeDifference[i].name_id == alternative_path_segments[0].name_id) {
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
if(i < size_of_difference ) {
|
||||||
|
alternativeSegment2 = alternativeDifference[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(shortestSegment1.position > shortestSegment2.position)
|
||||||
|
std::swap(shortestSegment1, shortestSegment2);
|
||||||
|
|
||||||
|
if(alternativeSegment1.position > alternativeSegment2.position)
|
||||||
|
std::swap(alternativeSegment1, alternativeSegment2);
|
||||||
|
|
||||||
|
routeNames.shortestPathName1 = facade->GetEscapedNameForNameID(
|
||||||
|
shortestSegment1.name_id
|
||||||
|
);
|
||||||
|
routeNames.shortestPathName2 = facade->GetEscapedNameForNameID(
|
||||||
|
shortestSegment2.name_id
|
||||||
|
);
|
||||||
|
|
||||||
|
routeNames.alternativePathName1 = facade->GetEscapedNameForNameID(
|
||||||
|
alternativeSegment1.name_id
|
||||||
|
);
|
||||||
|
routeNames.alternativePathName2 = facade->GetEscapedNameForNameID(
|
||||||
|
alternativeSegment2.name_id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: reorder parameters
|
||||||
|
inline void BuildTextualDescription(
|
||||||
|
DescriptionFactory & description_factory,
|
||||||
|
http::Reply & reply,
|
||||||
|
const int route_length,
|
||||||
|
const DataFacadeT * facade,
|
||||||
|
std::vector<Segment> & route_segments_list
|
||||||
|
) {
|
||||||
|
//Segment information has following format:
|
||||||
|
//["instruction","streetname",length,position,time,"length","earth_direction",azimuth]
|
||||||
|
//Example: ["Turn left","High Street",200,4,10,"200m","NE",22.5]
|
||||||
|
//See also: http://developers.cloudmade.com/wiki/navengine/JSON_format
|
||||||
|
unsigned prefixSumOfNecessarySegments = 0;
|
||||||
|
roundAbout.leave_at_exit = 0;
|
||||||
|
roundAbout.name_id = 0;
|
||||||
|
std::string tmpDist, tmpLength, tmpDuration, tmpBearing, tmpInstruction;
|
||||||
|
//Fetch data from Factory and generate a string from it.
|
||||||
|
BOOST_FOREACH(const SegmentInformation & segment, description_factory.pathDescription) {
|
||||||
|
TurnInstruction current_instruction = segment.turn_instruction & TurnInstructions.InverseAccessRestrictionFlag;
|
||||||
|
entered_restricted_area_count += (current_instruction != segment.turn_instruction);
|
||||||
|
if(TurnInstructions.TurnIsNecessary( current_instruction) ) {
|
||||||
|
if(TurnInstructions.EnterRoundAbout == current_instruction) {
|
||||||
|
roundAbout.name_id = segment.name_id;
|
||||||
|
roundAbout.start_index = prefixSumOfNecessarySegments;
|
||||||
|
} else {
|
||||||
|
if(0 != prefixSumOfNecessarySegments){
|
||||||
|
reply.content.push_back(",");
|
||||||
|
}
|
||||||
|
reply.content.push_back("[\"");
|
||||||
|
if(TurnInstructions.LeaveRoundAbout == current_instruction) {
|
||||||
|
intToString(TurnInstructions.EnterRoundAbout, tmpInstruction);
|
||||||
|
reply.content.push_back(tmpInstruction);
|
||||||
|
reply.content.push_back("-");
|
||||||
|
intToString(roundAbout.leave_at_exit+1, tmpInstruction);
|
||||||
|
reply.content.push_back(tmpInstruction);
|
||||||
|
roundAbout.leave_at_exit = 0;
|
||||||
|
} else {
|
||||||
|
intToString(current_instruction, tmpInstruction);
|
||||||
|
reply.content.push_back(tmpInstruction);
|
||||||
|
}
|
||||||
|
|
||||||
|
reply.content.push_back("\",\"");
|
||||||
|
reply.content.push_back(facade->GetEscapedNameForNameID(segment.name_id));
|
||||||
|
reply.content.push_back("\",");
|
||||||
|
intToString(segment.length, tmpDist);
|
||||||
|
reply.content.push_back(tmpDist);
|
||||||
|
reply.content.push_back(",");
|
||||||
|
intToString(prefixSumOfNecessarySegments, tmpLength);
|
||||||
|
reply.content.push_back(tmpLength);
|
||||||
|
reply.content.push_back(",");
|
||||||
|
intToString(segment.duration/10, tmpDuration);
|
||||||
|
reply.content.push_back(tmpDuration);
|
||||||
|
reply.content.push_back(",\"");
|
||||||
|
intToString(segment.length, tmpLength);
|
||||||
|
reply.content.push_back(tmpLength);
|
||||||
|
reply.content.push_back("m\",\"");
|
||||||
|
double bearing_value = round(segment.bearing/10.);
|
||||||
|
reply.content.push_back(Azimuth::Get(bearing_value));
|
||||||
|
reply.content.push_back("\",");
|
||||||
|
intToString(bearing_value, tmpBearing);
|
||||||
|
reply.content.push_back(tmpBearing);
|
||||||
|
reply.content.push_back("]");
|
||||||
|
|
||||||
|
route_segments_list.push_back(
|
||||||
|
Segment(
|
||||||
|
segment.name_id,
|
||||||
|
segment.length,
|
||||||
|
route_segments_list.size()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if(TurnInstructions.StayOnRoundAbout == current_instruction) {
|
||||||
|
++roundAbout.leave_at_exit;
|
||||||
|
}
|
||||||
|
if(segment.necessary)
|
||||||
|
++prefixSumOfNecessarySegments;
|
||||||
|
}
|
||||||
|
if(INT_MAX != route_length) {
|
||||||
|
reply.content.push_back(",[\"");
|
||||||
|
intToString(TurnInstructions.ReachedYourDestination, tmpInstruction);
|
||||||
|
reply.content.push_back(tmpInstruction);
|
||||||
|
reply.content.push_back("\",\"");
|
||||||
|
reply.content.push_back("\",");
|
||||||
|
reply.content.push_back("0");
|
||||||
|
reply.content.push_back(",");
|
||||||
|
intToString(prefixSumOfNecessarySegments-1, tmpLength);
|
||||||
|
reply.content.push_back(tmpLength);
|
||||||
|
reply.content.push_back(",");
|
||||||
|
reply.content.push_back("0");
|
||||||
|
reply.content.push_back(",\"");
|
||||||
|
reply.content.push_back("\",\"");
|
||||||
|
reply.content.push_back(Azimuth::Get(0.0));
|
||||||
|
reply.content.push_back("\",");
|
||||||
|
reply.content.push_back("0.0");
|
||||||
|
reply.content.push_back("]");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* JSON_DESCRIPTOR_H_ */
|
#endif /* JSON_DESCRIPTOR_H_ */
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
Third Party Libraries:
|
|
||||||
|
|
||||||
Scons 1.3+
|
|
||||||
Boost 1.37+
|
|
||||||
sparsehash 1.4+
|
|
||||||
stxxl 1.3.1+
|
|
||||||
libz2-dev 1.0.5+
|
|
||||||
protobuffer 2.3.0+
|
|
||||||
zlib 1.2.3.4+
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
FAQ
|
|
||||||
---
|
|
||||||
|
|
||||||
Q: What platforms does OSMR run on?
|
|
||||||
A: Virtually any Unix-like platform with g++ installed. It has been developed
|
|
||||||
under Linux and tested on MacOS X 10.6. It should run under Windows as well
|
|
||||||
though the code will need some adjustments.
|
|
||||||
|
|
||||||
Q: What is the workflow to get the engine up and running
|
|
||||||
A: Road network extraction->Preprocessing->Startup
|
|
||||||
|
|
||||||
Q: What does OSRM stand for?
|
|
||||||
A: It is an abbreviation for Open Source Routing Machine.
|
|
||||||
|
|
||||||
Q: What does HSGR stand for?
|
|
||||||
A: It is an abbreviation for Hierarchy Search GRaph.
|
|
||||||
|
|
||||||
Q: What is the .nodes file?
|
|
||||||
A: It is a map that translates between internal and external Node IDs. Remember
|
|
||||||
that external NodeIDs can be arbitrary and non-contigous. Internally the
|
|
||||||
nodes are numbered from 0 to n-1.
|
|
||||||
|
|
||||||
Q: The routing engine crashes with a seg-fault
|
|
||||||
A: Check the startup parameters.
|
|
||||||
|
|
||||||
Q: Something about the route is odd. I know that there is a better path
|
|
||||||
A: Most probably it is missing data in the OSM file.
|
|
||||||
|
|
||||||
Q: I work for this company that would like to use the code, but we are hesistant
|
|
||||||
because of the license.
|
|
||||||
A: Contact me. Probably, we can work something out.
|
|
||||||
|
|
||||||
Q: How fast is this thing?
|
|
||||||
A: Good question. Here is a number. The engine was able to handle more than
|
|
||||||
2800 requests per Minute on the German road network with the travel time
|
|
||||||
metric on a Core 2 Duo. This also includes transfer of data across a
|
|
||||||
switched 100MBit/s LAN. So, I guess it's fair to say it's fast.
|
|
||||||
|
|
||||||
Q: What is the difference between extractNetwork and extractLargeNetwork?
|
|
||||||
A: extractNetwork does all of its magic in RAM, while extractLargeNetwork uses the
|
|
||||||
stxxl library to store the data in external memory. Use the first one for small
|
|
||||||
networks, but beware of running out of RAM. Swapping is the kiss of death. For
|
|
||||||
larger networks use extractLargeNetwork. It will be somewhat slower on the
|
|
||||||
smaller files, but way faster with large ones like the planet file.
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
- extractorLargeNetwork finishes with:
|
|
||||||
terminate called after throwing an instance of 'stxxl::resource_error'
|
|
||||||
what(): Error in function void stxxl::mutex::lock() pthread_mutex_lock(&_mutex) Invalid argument
|
|
||||||
|
|
||||||
This ist a known, albeit odd behavior that is caused by a bug in stxxl. It can be ignored. Upgrade
|
|
||||||
to version 1.3.1 of stxxl.
|
|
||||||
@@ -1,159 +0,0 @@
|
|||||||
/*
|
|
||||||
* Open Source Routing Machine (OSRM) - Web (GUI) Interface
|
|
||||||
* Copyright (C) Pascal Neis, 2011
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Title: Geocode.js
|
|
||||||
* Description: JS file for geocoding
|
|
||||||
*
|
|
||||||
* @author Pascal Neis, pascal@neis-one.org
|
|
||||||
* @version 0.1 2011-05-15
|
|
||||||
*/
|
|
||||||
|
|
||||||
//======================
|
|
||||||
// OBJECTS
|
|
||||||
var HOST_GEOCODE_URL = 'http://open.mapquestapi.com';
|
|
||||||
var GEOCODE_POST = HOST_GEOCODE_URL + '/nominatim/v1/search?format=json&json_callback=showResultsGeocode';
|
|
||||||
var searchType = 'search';
|
|
||||||
|
|
||||||
var isStartPointSet = false;
|
|
||||||
var isEndPointSet = false;
|
|
||||||
|
|
||||||
//======================
|
|
||||||
// FUNCTIONS
|
|
||||||
/*
|
|
||||||
* geocodeAddress()-Function to read out textfield and send request to a OSM nominatim geocoder
|
|
||||||
*/
|
|
||||||
function geocodeAddress(tf){
|
|
||||||
var freeform;
|
|
||||||
|
|
||||||
if(tf == 'start'){
|
|
||||||
freeform = document.getElementById('tfStartSearch').value;
|
|
||||||
}
|
|
||||||
if(tf == 'end'){
|
|
||||||
freeform = document.getElementById('tfEndSearch').value;
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById('information').style.visibility = 'visible';
|
|
||||||
document.getElementById('information').innerHTML = '<p class="infoHL">One moment please ...</p>';
|
|
||||||
|
|
||||||
|
|
||||||
var newURL = GEOCODE_POST + "&q="+freeform;
|
|
||||||
var script = document.createElement('script');
|
|
||||||
script.type = 'text/javascript';
|
|
||||||
script.src = newURL;
|
|
||||||
document.body.appendChild(script);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* showResultsGeocode()-Function to show the geocode result in a div
|
|
||||||
*/
|
|
||||||
function showResultsGeocode(response) {
|
|
||||||
var html = '';
|
|
||||||
var lonlat = '';
|
|
||||||
|
|
||||||
if(response){
|
|
||||||
html += '<p class="infoHL">Search Results:</p>';
|
|
||||||
html += '<table>'
|
|
||||||
var markername;
|
|
||||||
if(getStatus()=='start'){
|
|
||||||
markername = 'start'; isStartPointSet = true;
|
|
||||||
}
|
|
||||||
else if(getStatus()=='end'){
|
|
||||||
markername = 'end'; isEndPointSet = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(var i=0; i < response.length; i++){
|
|
||||||
var result = response[i]; var resultNum = i+1;
|
|
||||||
//odd or even ?
|
|
||||||
var rowstyle='geocodeResultOdd';
|
|
||||||
if(i%2==0){ rowstyle='geocodeResultEven'; }
|
|
||||||
|
|
||||||
html += '<tr class="'+rowstyle+'">';
|
|
||||||
html += '<td align="right" valign="top"><span class="routeSummarybold">'+resultNum+'</span></td>';
|
|
||||||
html += '<td class="'+rowstyle+'">';
|
|
||||||
if(result.display_name){
|
|
||||||
var new_display_name = result.display_name;//.replace(/,/g, ",<br />")
|
|
||||||
html += '<a href="#" onclick="javascript:setMarkerAndZoom(\''+markername+'\', new OpenLayers.LonLat('+result.lon+','+result.lat+'));">'+new_display_name.trim()+'</a>';
|
|
||||||
}
|
|
||||||
html += "</td></tr>";
|
|
||||||
|
|
||||||
//alert(result.lat + ", " + result.lon);
|
|
||||||
if(lonlat == ''){
|
|
||||||
lonlat = new OpenLayers.LonLat(result.lon,result.lat);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
html += '</table>';
|
|
||||||
|
|
||||||
setMarkerAndZoom(markername, lonlat);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
switch (searchType) {
|
|
||||||
case "search":
|
|
||||||
document.getElementById('information').style.display = "";
|
|
||||||
document.getElementById('information').innerHTML = html;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* setMarkerAndZoom()-Function to set a marker on the map and zoom
|
|
||||||
*/
|
|
||||||
function setMarkerAndZoom(markername,lonlat){
|
|
||||||
setMarker(markername,lonlat);
|
|
||||||
|
|
||||||
//Hack - FIXME !
|
|
||||||
lonlat.lon -= 500;
|
|
||||||
//Set Center
|
|
||||||
map.setCenter(lonlat, 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* setMarker()-Function to set a marker on the map
|
|
||||||
*/
|
|
||||||
function setMarker(markername,lonlat){
|
|
||||||
lonlat.transform(EPSG_4326, EPSG_900913);
|
|
||||||
for(var i= 0; i<dragLayer.features.length; i++){
|
|
||||||
if(dragLayer.features[i].name == markername){ dragLayer.removeFeatures([dragLayer.features[i]]); }
|
|
||||||
}
|
|
||||||
var point = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat));
|
|
||||||
point.attributes = { icon: "img/start.png" };
|
|
||||||
|
|
||||||
if(markername == 'start'){
|
|
||||||
point.attributes = { icon: "img/start.png" };
|
|
||||||
}
|
|
||||||
else if(markername == 'end'){
|
|
||||||
point.attributes = { icon: "img/end.png" };
|
|
||||||
}
|
|
||||||
|
|
||||||
point.name = markername;
|
|
||||||
dragLayer.addFeatures([point]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* getMarkerByName()-Function to return the marker-object by a name
|
|
||||||
*/
|
|
||||||
function getMarkerByName(markerName){
|
|
||||||
for(var i= 0; i<dragLayer.features.length; i++){
|
|
||||||
if(dragLayer.features[i].name == markerName){
|
|
||||||
return dragLayer.features[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,354 +0,0 @@
|
|||||||
/*
|
|
||||||
* Open Source Routing Machine (OSRM) - Web (GUI) Interface
|
|
||||||
* Copyright (C) Pascal Neis, 2011
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Title: Map.js
|
|
||||||
* Description: JS file to show a map, for markers, left slide div, ...
|
|
||||||
*
|
|
||||||
* @author Pascal Neis, pascal@neis-one.org
|
|
||||||
* @version 0.1.1 2011-06-09
|
|
||||||
*/
|
|
||||||
|
|
||||||
//======================
|
|
||||||
// OBJECTS
|
|
||||||
//Map
|
|
||||||
var map;
|
|
||||||
|
|
||||||
//Status object for what position actually a coordinate is searched
|
|
||||||
var status = ''; //possible values [start,end]
|
|
||||||
function getStatus(){ return status; }
|
|
||||||
function setStatus(stat){ status = stat; }
|
|
||||||
|
|
||||||
//Indicator
|
|
||||||
var ISDRAGGING = false;
|
|
||||||
|
|
||||||
//Layer
|
|
||||||
var dragLayer;
|
|
||||||
var vectorLayerRoute;
|
|
||||||
var vectorLayerViaRoute;
|
|
||||||
var markersLayer;
|
|
||||||
|
|
||||||
var selectFeature;
|
|
||||||
//======================
|
|
||||||
// FUNCTIONS
|
|
||||||
/*
|
|
||||||
* init()-Function to create the map div
|
|
||||||
*/
|
|
||||||
function init(){
|
|
||||||
//Create Map
|
|
||||||
map = new OpenLayers.Map ("map", {
|
|
||||||
controls:[
|
|
||||||
new OpenLayers.Control.Navigation(),
|
|
||||||
new OpenLayers.Control.Permalink(),
|
|
||||||
new OpenLayers.Control.LayerSwitcher()],
|
|
||||||
maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
|
|
||||||
maxResolution: 156543.0399,
|
|
||||||
numZoomLevels: 19,
|
|
||||||
units: 'm',
|
|
||||||
projection: new OpenLayers.Projection("EPSG:900913"),
|
|
||||||
displayProjection: new OpenLayers.Projection("EPSG:4326")
|
|
||||||
} );
|
|
||||||
//Add the base layers.
|
|
||||||
|
|
||||||
var coverageLayer = new OpenLayers.Layer.Vector("Coverage", {
|
|
||||||
style: {
|
|
||||||
strokeColor: "#000000",
|
|
||||||
strokeTransparency: 0.5,
|
|
||||||
strokeWidth: 4
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if("map.project-osrm.org" == location.host) {
|
|
||||||
var coveragePointList = [
|
|
||||||
new OpenLayers.Geometry.Point(-11.99, 58.80),
|
|
||||||
new OpenLayers.Geometry.Point(-11.99, 35.30),
|
|
||||||
new OpenLayers.Geometry.Point(-7.57, 35.30),
|
|
||||||
new OpenLayers.Geometry.Point(9.22, 38.24),
|
|
||||||
new OpenLayers.Geometry.Point(15.38, 35.39),
|
|
||||||
new OpenLayers.Geometry.Point(18.92, 40.02),
|
|
||||||
new OpenLayers.Geometry.Point(15.70, 42.25),
|
|
||||||
new OpenLayers.Geometry.Point(15.70, 55.40),
|
|
||||||
new OpenLayers.Geometry.Point(30.31, 60.29),
|
|
||||||
new OpenLayers.Geometry.Point(30.31, 71.27),
|
|
||||||
new OpenLayers.Geometry.Point(21.01, 71.27),
|
|
||||||
new OpenLayers.Geometry.Point(-11.99, 58.80)
|
|
||||||
];
|
|
||||||
|
|
||||||
var line_string = new OpenLayers.Geometry.LineString(coveragePointList).transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
|
|
||||||
coverageLayer.addFeatures([new OpenLayers.Feature.Vector(line_string)]);
|
|
||||||
|
|
||||||
map.addLayer(coverageLayer);
|
|
||||||
}
|
|
||||||
|
|
||||||
map.addLayer(new OpenLayers.Layer.OSM.Mapnik("Mapnik"));
|
|
||||||
map.addLayer(new OpenLayers.Layer.OSM.MapQuest("MapQuest"));
|
|
||||||
map.addLayer(new OpenLayers.Layer.OSM.Osmarender("Osmarender"));
|
|
||||||
|
|
||||||
//Add layer for the route
|
|
||||||
vectorLayerRoute = new OpenLayers.Layer.Vector("Route",{maxResolution: 156543.0339});
|
|
||||||
map.addLayer(vectorLayerRoute);
|
|
||||||
|
|
||||||
//Add layer for temporary via route
|
|
||||||
vectorLayerViaRoute = new OpenLayers.Layer.Vector("ViaRoute",{maxResolution: 156543.0339});
|
|
||||||
map.addLayer(vectorLayerViaRoute);
|
|
||||||
|
|
||||||
//Add Layerswitcher
|
|
||||||
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
|
||||||
|
|
||||||
//Add Panzoombar
|
|
||||||
var panZoomBar = new OpenLayers.Control.PanZoomBar({id:'panzoombar',displayClass:'olControlPanZoomBar'})
|
|
||||||
map.addControl(panZoomBar);
|
|
||||||
//Customize the position of the panzoombar
|
|
||||||
document.getElementById('panzoombar').style.left="400px";
|
|
||||||
document.getElementById('panzoombar').style.top="25px";
|
|
||||||
|
|
||||||
//Create drag vector layer
|
|
||||||
dragLayer = new OpenLayers.Layer.Vector(
|
|
||||||
"Start/End Marker",{
|
|
||||||
styleMap: new OpenLayers.StyleMap({
|
|
||||||
// Set the external graphic and background graphic images.
|
|
||||||
externalGraphic: '${icon}',
|
|
||||||
// Makes sure the background graphic is placed correctly relative
|
|
||||||
// to the external graphic.
|
|
||||||
backgroundXOffset: -11,
|
|
||||||
backgroundYOffset: -40,
|
|
||||||
graphicXOffset: -11,
|
|
||||||
graphicYOffset: -40,
|
|
||||||
|
|
||||||
// Set the z-indexes of both graphics to make sure the background
|
|
||||||
// graphics stay in the background (shadows on top of markers looks
|
|
||||||
// odd; let's not do that).
|
|
||||||
graphicZIndex: 10,
|
|
||||||
backgroundGraphicZIndex: 11,
|
|
||||||
|
|
||||||
pointRadius: 10,
|
|
||||||
graphicWidth: 22,
|
|
||||||
graphicHeight: 40
|
|
||||||
}),
|
|
||||||
rendererOptions: {zIndexing: true}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
// Add a drag feature control to move features around.
|
|
||||||
var dragFeatures = new OpenLayers.Control.DragFeature(dragLayer,
|
|
||||||
{ onDrag: function(feature, pixel){
|
|
||||||
ISDRAGGING = true;
|
|
||||||
if(feature.name == "start" || feature.name == "end") {
|
|
||||||
feature.move(map.getLonLatFromPixel(pixel));
|
|
||||||
if(!ISCALCULATING){ routing(true); }
|
|
||||||
}
|
|
||||||
if(feature.name == "via") {
|
|
||||||
computeViaRoute(pixel, true);
|
|
||||||
}
|
|
||||||
if(feature.name == "viapoint" && feature.popup) {
|
|
||||||
map.removePopup(feature.popup);
|
|
||||||
computeViaRoute(pixel, true, feature.viaIndex);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onComplete: function(feature, pixel){
|
|
||||||
ISDRAGGING = false;
|
|
||||||
if(feature.name == "start" || feature.name == "end") {
|
|
||||||
feature.move(map.getLonLatFromPixel(pixel));
|
|
||||||
routing(false);
|
|
||||||
} else if(feature.name == "via") {
|
|
||||||
console.log('finished via');
|
|
||||||
//Erase temporary point from draglayer
|
|
||||||
dragLayer.renderer.eraseFeatures([feature]);
|
|
||||||
//delete temporary route from via route Layer
|
|
||||||
vectorLayerViaRoute.removeFeatures(vectorLayerViaRoute.features);
|
|
||||||
//compute via route
|
|
||||||
computeViaRoute(pixel, false);
|
|
||||||
feature.destroy();
|
|
||||||
} else if(feature.name == "viapoint") {
|
|
||||||
//Erase temporary point from draglayer
|
|
||||||
dragLayer.renderer.eraseFeatures([feature]);
|
|
||||||
//delete via point from vector
|
|
||||||
viaPointsVector.splice(feature.viaIndex,1);
|
|
||||||
//delete temporary route from via route Layer
|
|
||||||
vectorLayerViaRoute.removeFeatures(vectorLayerViaRoute.features);
|
|
||||||
//compute via route
|
|
||||||
computeViaRoute(pixel, false);
|
|
||||||
feature.destroy();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onLeave: function(f){
|
|
||||||
if(!ISCALCULATING){ routing(false); }}
|
|
||||||
});
|
|
||||||
map.addControl(dragFeatures);
|
|
||||||
dragFeatures.activate();
|
|
||||||
map.addLayers([dragLayer]);
|
|
||||||
|
|
||||||
//Add a marker layer
|
|
||||||
markersLayer = new OpenLayers.Layer.Markers("Markers");
|
|
||||||
map.addLayer(markersLayer);
|
|
||||||
|
|
||||||
//Add zoom event for rerouting
|
|
||||||
map.events.on({zoomend: function(e) {reroute();distanceToRoute(null);}});
|
|
||||||
|
|
||||||
// Register Callback to evaluate distance to from mouse location to route on Mousemove
|
|
||||||
map.events.on({mousemove: function(e) {distanceToRoute(e.xy);}});
|
|
||||||
|
|
||||||
// Set center of the map
|
|
||||||
if (!map.getCenter()){
|
|
||||||
map.setCenter(new OpenLayers.LonLat(600000, 6600000),6);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Check if the URL contains some GET parameter, e.g. for the route
|
|
||||||
checkURL();
|
|
||||||
|
|
||||||
for(var i = 0; i < map.layers.length; i++) {
|
|
||||||
map.layers[i].transitionEffect = 'resize';
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById('map').oncontextmenu = function(e){
|
|
||||||
e = e?e:window.event;
|
|
||||||
if (e.preventDefault) e.preventDefault(); // For non-IE browsers.
|
|
||||||
else return false; // For IE browsers.
|
|
||||||
};
|
|
||||||
|
|
||||||
// A control class for capturing click events...
|
|
||||||
OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
|
|
||||||
|
|
||||||
defaultHandlerOptions: {
|
|
||||||
'single': true,
|
|
||||||
'double': true,
|
|
||||||
'pixelTolerance': 0,
|
|
||||||
'stopSingle': false,
|
|
||||||
'stopDouble': false
|
|
||||||
},
|
|
||||||
handleRightClicks:true,
|
|
||||||
initialize: function(options) {
|
|
||||||
this.handlerOptions = OpenLayers.Util.extend(
|
|
||||||
{}, this.defaultHandlerOptions
|
|
||||||
);
|
|
||||||
OpenLayers.Control.prototype.initialize.apply(
|
|
||||||
this, arguments
|
|
||||||
);
|
|
||||||
this.handler = new OpenLayers.Handler.Click(
|
|
||||||
this, this.eventMethods, this.handlerOptions
|
|
||||||
);
|
|
||||||
},
|
|
||||||
CLASS_NAME: "OpenLayers.Control.Click"
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add an instance of the Click control that listens to various click events:
|
|
||||||
var oClick = new OpenLayers.Control.Click({eventMethods:{
|
|
||||||
'rightclick': function(e) {
|
|
||||||
rightClick(e);
|
|
||||||
},
|
|
||||||
'click': function(e) {
|
|
||||||
leftClick(e);
|
|
||||||
},
|
|
||||||
'dblclick': function(e) {
|
|
||||||
dblClick(e);
|
|
||||||
},
|
|
||||||
'dblrightclick': function(e) {
|
|
||||||
dblRightClick(e);
|
|
||||||
}
|
|
||||||
}});
|
|
||||||
map.addControl(oClick);
|
|
||||||
oClick.activate();
|
|
||||||
|
|
||||||
|
|
||||||
selectFeature = new OpenLayers.Control.SelectFeature(
|
|
||||||
[dragLayer],
|
|
||||||
{
|
|
||||||
clickout: true, toggle: false,
|
|
||||||
multiple: false, hover: true,
|
|
||||||
toggleKey: "ctrlKey", // ctrl key removes from selection
|
|
||||||
multipleKey: "shiftKey", // shift key adds to selection
|
|
||||||
onSelect: createPopup,
|
|
||||||
onUnselect: destroyPopup
|
|
||||||
|
|
||||||
}
|
|
||||||
);
|
|
||||||
map.addControl(selectFeature);
|
|
||||||
dragLayer.events.on({
|
|
||||||
"featureselected": function(e) {
|
|
||||||
featureSelected(e);
|
|
||||||
},
|
|
||||||
"featureunselected": function(e) {
|
|
||||||
featureUnselected(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
selectFeature.activate();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Helper Functions
|
|
||||||
function checkReturn(textfieldname,e){
|
|
||||||
var evt = e || window.event;
|
|
||||||
if(!evt){ return; }
|
|
||||||
|
|
||||||
var key = 0;
|
|
||||||
if (evt.keyCode) { key = evt.keyCode; }
|
|
||||||
else if (typeof(evt.which)!= 'undefined') { key = evt.which; }
|
|
||||||
if( key == 13 && textfieldname=='start'){ setStatus('start'); geocodeAddress('start'); return; }
|
|
||||||
if( key == 13 && textfieldname=='end'){ setStatus('end'); geocodeAddress('end'); return; }
|
|
||||||
}
|
|
||||||
|
|
||||||
function closeOpenDiv(name){
|
|
||||||
if(document.getElementById(name).style.display == 'none'){ document.getElementById(name).style.display = ''; }
|
|
||||||
else{ document.getElementById(name).style.display = 'none'; }
|
|
||||||
}
|
|
||||||
|
|
||||||
//URL Functions
|
|
||||||
function checkURL(){
|
|
||||||
var getObjs = new Array();
|
|
||||||
var getString = document.location.search.substr(1,document.location.search.length);
|
|
||||||
if(getString != ''){
|
|
||||||
var getArray=getString.split('&');
|
|
||||||
console.log(getArray);
|
|
||||||
for(i=0 ; i<getArray.length ; ++i){
|
|
||||||
var v='';
|
|
||||||
var vArr = getArray[i].split('=');
|
|
||||||
if(vArr.length>1){ v = vArr[1]; }
|
|
||||||
if("via" == vArr[0]) {
|
|
||||||
var via_loc = unescape(v).split(',');
|
|
||||||
for(var j=0; j<via_loc.length; j++) { via_loc[j] = parseFloat(via_loc[j]); }
|
|
||||||
viaPointsVector.push(via_loc);
|
|
||||||
} else {
|
|
||||||
getObjs[unescape(vArr[0])]=unescape(v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var fr = getObjectOfArray(getObjs, "fr");
|
|
||||||
var to = getObjectOfArray(getObjs, "to");
|
|
||||||
|
|
||||||
if(fr != 'undefined' && to != 'undefined'){
|
|
||||||
//From
|
|
||||||
var fr_pos = fr.split(',');
|
|
||||||
var fr_lonlat = new OpenLayers.LonLat(fr_pos[1],fr_pos[0]);
|
|
||||||
setMarkerAndZoom('start', fr_lonlat);
|
|
||||||
isStartPointSet = true;
|
|
||||||
//To
|
|
||||||
var to_pos = to.split(',');
|
|
||||||
var to_lonlat = new OpenLayers.LonLat(to_pos[1],to_pos[0]);
|
|
||||||
setMarker('end', to_lonlat);
|
|
||||||
isEndPointSet = true;
|
|
||||||
//Calculate the route
|
|
||||||
routing(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getObjectOfArray(objects, elementName){
|
|
||||||
if(!objects[elementName]){ return 'undefined'; }
|
|
||||||
return objects[elementName];
|
|
||||||
}
|
|
||||||
@@ -1,115 +0,0 @@
|
|||||||
var selectedFeature = null;
|
|
||||||
var popupCloseTimer = null;
|
|
||||||
var popupToRemove = null;
|
|
||||||
|
|
||||||
function rightClick(e) {
|
|
||||||
console.log("right click1");
|
|
||||||
if(null == selectedFeature)
|
|
||||||
return;
|
|
||||||
//alert('rightclick at '+e.xy.x+','+e.xy.y);
|
|
||||||
console.log("right click2");
|
|
||||||
}
|
|
||||||
|
|
||||||
function dblClick(e) {
|
|
||||||
//alert('dblclick at '+e.xy.x+','+e.xy.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
function dblRightClick(e) {
|
|
||||||
//alert('dblrightclick at '+e.xy.x+','+e.xy.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
function leftClick(e) {
|
|
||||||
//set start and target via clicks
|
|
||||||
var lonlat = map.getLonLatFromViewPortPx(e.xy);
|
|
||||||
var markername = "";
|
|
||||||
|
|
||||||
/* //routing shall not be done by left clicks
|
|
||||||
* if (e.ctrlKey || e.altKey) {
|
|
||||||
markername = "end";
|
|
||||||
isEndPointSet = true;
|
|
||||||
} else if(e.shiftKey) {
|
|
||||||
markername = "start";
|
|
||||||
isStartPointSet = true;
|
|
||||||
}
|
|
||||||
for(var i= 0; i<dragLayer.features.length; i++){
|
|
||||||
if(dragLayer.features[i].name == markername){ dragLayer.removeFeatures([dragLayer.features[i]]); }
|
|
||||||
}
|
|
||||||
|
|
||||||
var point = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat));
|
|
||||||
point.attributes = { icon: "img/start.png" };
|
|
||||||
|
|
||||||
if(markername == 'start'){
|
|
||||||
point.attributes = { icon: "img/start.png" };
|
|
||||||
}
|
|
||||||
else if(markername == 'end'){
|
|
||||||
point.attributes = { icon: "img/end.png" };
|
|
||||||
}
|
|
||||||
|
|
||||||
point.name = markername;
|
|
||||||
dragLayer.addFeatures([point]);
|
|
||||||
reroute();
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
function featureSelected(f) {
|
|
||||||
if("viapoint" == f.feature.name) {
|
|
||||||
// console.log('selected ' + f.feature.name);
|
|
||||||
selectedFeature = f.feature;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function featureUnselected(f) {
|
|
||||||
if("viapoint" == f.feature.name) {
|
|
||||||
// console.log('unselected ' + f.feature.name);
|
|
||||||
selectedFeature = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function createPopup(feature) {
|
|
||||||
if("viapoint" != feature.name || ISDRAGGING)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(popupCloseTimer != null) {
|
|
||||||
clearInterval(popupCloseTimer);
|
|
||||||
popupCloseTimer = null;
|
|
||||||
map.removePopup(popupToRemove);
|
|
||||||
popupToRemove = null;
|
|
||||||
}
|
|
||||||
var location = feature.geometry.getBounds().getCenterLonLat().clone();
|
|
||||||
location.lon; location.lat;
|
|
||||||
feature.popup = new OpenLayers.Popup.Anchored("ViaPointInfo",
|
|
||||||
location,
|
|
||||||
new OpenLayers.Size(16,16),
|
|
||||||
'<div><a href="javascript:removeViaPoint('+ feature.viaIndex +')"><img src="img/cancel_small.png"/></a></div>',
|
|
||||||
null,
|
|
||||||
false,
|
|
||||||
destroyPopup );
|
|
||||||
feature.popup.backgroundColor = 'transparent';
|
|
||||||
feature.popup.fixedRelativePosition = true;
|
|
||||||
feature.popup.relativePosition = "tr";
|
|
||||||
map.addPopup(feature.popup, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function destroyPopup(feature) {
|
|
||||||
if(feature.popup) {
|
|
||||||
popupToRemove = feature.popup;
|
|
||||||
popupCloseTimer = setTimeout("removePopup()",2000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function removePopup() {
|
|
||||||
if(null == popupToRemove)
|
|
||||||
return;
|
|
||||||
|
|
||||||
map.removePopup(popupToRemove);
|
|
||||||
popupToRemove = null;
|
|
||||||
popupCloseTimer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeViaPoint(index) {
|
|
||||||
for(var i = 0; i < map.popups.length; i++) {
|
|
||||||
map.removePopup(map.popups[i]);
|
|
||||||
}
|
|
||||||
viaPointsVector.splice(index, 1);
|
|
||||||
reroute();
|
|
||||||
}
|
|
||||||
@@ -1,366 +0,0 @@
|
|||||||
/*
|
|
||||||
* Open Source Routing Machine (OSRM) - Web (GUI) Interface
|
|
||||||
* Copyright (C) Pascal Neis, 2011
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Title: Route.js
|
|
||||||
* Description: JS file for routing
|
|
||||||
*
|
|
||||||
* @author Pascal Neis, pascal@neis-one.org
|
|
||||||
* @version 0.2 2011-06-23
|
|
||||||
*/
|
|
||||||
|
|
||||||
//======================
|
|
||||||
// OBJECTS
|
|
||||||
//Map
|
|
||||||
//var HOST_ROUTING_URL = 'http://localhost:5000/viaroute';
|
|
||||||
var HOST_ROUTING_URL = 'http://routingdemo.geofabrik.de/route-via/';
|
|
||||||
var HOST_WEBSITE = 'http://map.project-osrm.org/';//location.host
|
|
||||||
|
|
||||||
var ISCALCULATING = false;
|
|
||||||
var EPSG_4326 = new OpenLayers.Projection("EPSG:4326");
|
|
||||||
var EPSG_900913 = new OpenLayers.Projection("EPSG:900913");
|
|
||||||
var allRoutePoints = [];
|
|
||||||
//======================
|
|
||||||
// FUNCTIONS
|
|
||||||
/*
|
|
||||||
* routing()-Function to create and send route request
|
|
||||||
*/
|
|
||||||
function routing(isDragRoute){
|
|
||||||
//Check if startpoint is set
|
|
||||||
if(!isStartPointSet){
|
|
||||||
//alert("Please set your Start location first!");
|
|
||||||
document.getElementById('information').innerHTML = '<p class="infoHLRed">Please set your Start location first!</p>';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//Check if endpoint is set
|
|
||||||
if(!isEndPointSet){
|
|
||||||
//alert("Please set your Destination first!");
|
|
||||||
document.getElementById('information').innerHTML = '<p class="infoHLRed">Please set your Destination first!</p>';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Check if already a route is planning
|
|
||||||
if(!isDragRoute){ ISCALCULATING = false; }
|
|
||||||
if(ISCALCULATING){ return; }
|
|
||||||
else{ ISCALCULATING = true; }
|
|
||||||
|
|
||||||
//Get Coordinates of the Start and Endpoint
|
|
||||||
var startFeat = getMarkerByName('start');
|
|
||||||
var endFeat = getMarkerByName('end');
|
|
||||||
var from = new OpenLayers.LonLat(startFeat.geometry.x,startFeat.geometry.y).transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
|
|
||||||
var to = new OpenLayers.LonLat(endFeat.geometry.x,endFeat.geometry.y).transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
|
|
||||||
|
|
||||||
//Send Request
|
|
||||||
var script = document.createElement('script');
|
|
||||||
script.type = 'text/javascript';
|
|
||||||
|
|
||||||
var callBackFunction = 'showResultsRoute';
|
|
||||||
var instructions = '&geomformat=cmp&instructions=true';
|
|
||||||
if(isDragRoute){
|
|
||||||
callBackFunction = 'showResultsDragRoute';
|
|
||||||
instructions = '&geomformat=cmp&instructions=false';
|
|
||||||
document.getElementById('information').innerHTML = '<p class="infoHL">Release mouse button to get Route Information!</p>(If no Route Summary is diplayed, press the Route!-button)';
|
|
||||||
}
|
|
||||||
|
|
||||||
script.src = HOST_ROUTING_URL + "&start="+from.lat + ',' + from.lon + '&dest=' + to.lat + ',' + to.lon;
|
|
||||||
for(var i = 0; i < viaPointsVector.length; i++) {
|
|
||||||
script.src += ('&via=' + viaPointsVector[i][0] + ',' + viaPointsVector[i][1]);
|
|
||||||
}
|
|
||||||
script.src +='&z='+this.map.getZoom()+'&output=json&jsonp='+callBackFunction+instructions;
|
|
||||||
document.body.appendChild(script);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* reroute()-Function
|
|
||||||
*/
|
|
||||||
function reroute() {
|
|
||||||
if(!isStartPointSet || !isEndPointSet){ return; }
|
|
||||||
routing(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* showResultsDragRoute()-Function to show route result for drag-route
|
|
||||||
*/
|
|
||||||
function showResultsDragRoute(response) {
|
|
||||||
if (response) {
|
|
||||||
//Display Route
|
|
||||||
showRouteGeometry(response);
|
|
||||||
}
|
|
||||||
markersLayer.clearMarkers();
|
|
||||||
ISCALCULATING = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* showResultsRoute()-Function to show route result
|
|
||||||
*/
|
|
||||||
function showResultsRoute(response) {
|
|
||||||
if (response) {
|
|
||||||
//Display Route
|
|
||||||
if(document.getElementById("cbNoNames").checked == true){
|
|
||||||
showNoNameStreets(response);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
showRouteGeometry(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Save Via Points that come with route
|
|
||||||
var lengthOfArray = response.via_points.length;
|
|
||||||
var i = 0;
|
|
||||||
viaPointsVector.length = 0;
|
|
||||||
viaPointsVector = response.via_points.slice(0);
|
|
||||||
paintViaPoints();
|
|
||||||
|
|
||||||
//Create Link of the route
|
|
||||||
var startFeat = getMarkerByName('start');
|
|
||||||
var endFeat = getMarkerByName('end');
|
|
||||||
var from = new OpenLayers.LonLat(startFeat.geometry.x,startFeat.geometry.y).transform(EPSG_900913,EPSG_4326);
|
|
||||||
var to = new OpenLayers.LonLat(endFeat.geometry.x,endFeat.geometry.y).transform(EPSG_900913,EPSG_4326);
|
|
||||||
var routelink = '<div id="routelink"><input name="routelink" type="submit" title="Get Link" onClick="createShortLink(\''+HOST_WEBSITE+'?fr='+from.lat.toFixed(6)+','+from.lon.toFixed(6)+'&to='+to.lat.toFixed(6)+','+to.lon.toFixed(6);
|
|
||||||
for(i = 0; i < viaPointsVector.length; i++) {
|
|
||||||
routelink += "&via=" + viaPointsVector[i][0] + "," + viaPointsVector[i][1];
|
|
||||||
}
|
|
||||||
routelink += '\');" value="Get Link"></div>';
|
|
||||||
|
|
||||||
//Link for the GPX Download
|
|
||||||
var gpxLink = '(<a href="'+HOST_ROUTING_URL+'&start='+from.lat.toFixed(6)+','+from.lon.toFixed(6)+'&dest='+to.lat.toFixed(6)+','+to.lon.toFixed(6)+'&z='+this.map.getZoom();
|
|
||||||
for(i = 0; i < viaPointsVector.length; i++) {
|
|
||||||
gpxLink += "&via=" + viaPointsVector[i][0] + "," + viaPointsVector[i][1];
|
|
||||||
}
|
|
||||||
gpxLink += '&output=gpx">Get GPX File</a>)';;
|
|
||||||
|
|
||||||
//Show Route Summary
|
|
||||||
var output = '<p class="routeSummaryHL">Some information about your Way <br> from \'<span class="routeSummaryHLlight">'+response.route_summary.start_point+'</span>\' to \'<span class="routeSummaryHLlight">'+response.route_summary.end_point+'</span>\'</p>';
|
|
||||||
output += '<p class="routeSummary">Distance: <span class="routeSummarybold">'+response.route_summary.total_distance/1000+' km</span> - Duration: <span class="routeSummarybold">'+secondsToTime(response.route_summary.total_time)+'</span></p><p>'+routelink+'</p><p><span class="routeInstructionsHL">The Route-Instructions:</span> '+gpxLink+'</p>';
|
|
||||||
//Show Route Instructions
|
|
||||||
output += '<table>';
|
|
||||||
lengthOfArray = response.route_instructions.length;
|
|
||||||
for (i = 0; i < lengthOfArray; i++) {
|
|
||||||
//console.log(response.route_instructions[i]);
|
|
||||||
//odd or even ?
|
|
||||||
var rowstyle='routeInstructionsOdd';
|
|
||||||
if(i%2==0){ rowstyle='routeInstructionsEven'; }
|
|
||||||
|
|
||||||
var indexPos = response.route_instructions[i][3];
|
|
||||||
//console.log('setting : ' + response.route_instructions[i] + ' at ' + allRoutePoints[indexPos]);
|
|
||||||
var point = allRoutePoints[indexPos];
|
|
||||||
|
|
||||||
output += '<tr class="'+rowstyle+'"><td align="right" valign="top"><span class="routeSummarybold">'+(i+1)+'.</span></td><td class="'+rowstyle+'"><a href="#" class="nolinkStyle" onclick="setMapCenter(new OpenLayers.LonLat('+point.x+','+point.y+'));">'+response.route_instructions[i][0]+' on '+response.route_instructions[i][1]+' for '+getDistanceWithUnit(response.route_instructions[i][2])+'</a></td></tr>';
|
|
||||||
}
|
|
||||||
var rowstyle='routeInstructionsOdd';
|
|
||||||
if(i%2==0){ rowstyle='routeInstructionsEven'; }
|
|
||||||
if( lengthOfArray > 0) {
|
|
||||||
var point = allRoutePoints[allRoutePoints.length-1];
|
|
||||||
output += '<tr class="'+rowstyle+'"><td align="right" valign="top"><span class="routeSummarybold">'+(i+1)+'.</span></td><td class="'+rowstyle+'"><a href="#" class="nolinkStyle" onclick="setMapCenter(new OpenLayers.LonLat('+point.x+','+point.y+'));">You have reached your destination</a></td></tr>';
|
|
||||||
}
|
|
||||||
output += '</table>';
|
|
||||||
//alert(vectorLayerRoute.features[0].geometry.getVertices());
|
|
||||||
|
|
||||||
document.getElementById('information').innerHTML = output;
|
|
||||||
ISCALCULATING = false;
|
|
||||||
ISCALCULATINGVIA = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* showRouteGeometry()-Function to show route result
|
|
||||||
*/
|
|
||||||
function showRouteGeometry(response) {
|
|
||||||
if (response) {
|
|
||||||
allRoutePoints.length = 0;
|
|
||||||
// now with compression of the route geometry
|
|
||||||
var geometry = decodeRouteGeometry(response.route_geometry, 5);
|
|
||||||
var lengthOfArray = geometry.length;
|
|
||||||
var points = [];
|
|
||||||
points.length = lengthOfArray;
|
|
||||||
var points = [];
|
|
||||||
//delete any previously displayed via route
|
|
||||||
vectorLayerViaRoute.removeFeatures(vectorLayerViaRoute.features);
|
|
||||||
vectorLayerRoute.removeAllFeatures();
|
|
||||||
|
|
||||||
//Create Route Layer for Display
|
|
||||||
for (var i = 0; i < lengthOfArray; i++) {
|
|
||||||
var point = new OpenLayers.Geometry.Point(geometry[i][1], geometry[i][0]).transform(EPSG_4326, EPSG_900913);
|
|
||||||
allRoutePoints.push(point);
|
|
||||||
points.push(point);
|
|
||||||
|
|
||||||
if(i % 1024 == 0 && i>0 || i==lengthOfArray-1){
|
|
||||||
/* var feature2 = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.LineString(points), null, {
|
|
||||||
strokeColor: "#000066",
|
|
||||||
strokeOpacity: 1,
|
|
||||||
strokeWidth: 9
|
|
||||||
});
|
|
||||||
|
|
||||||
var feature1 = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.LineString(points), null, {
|
|
||||||
strokeColor: "#ffffff",
|
|
||||||
strokeOpacity: 0.75,
|
|
||||||
strokeWidth: 7
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
var feature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.LineString(points), null, {
|
|
||||||
strokeColor: "#0033ff",
|
|
||||||
strokeOpacity: 0.7,
|
|
||||||
strokeWidth: 5
|
|
||||||
});
|
|
||||||
// vectorLayerRoute.addFeatures([feature2]);
|
|
||||||
// vectorLayerRoute.addFeatures([feature1]);
|
|
||||||
vectorLayerRoute.addFeatures([feature]);
|
|
||||||
points = [];
|
|
||||||
points.push(point);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* showNoNameStreets()-Function to show route result
|
|
||||||
*/
|
|
||||||
function showNoNameStreets(response) {
|
|
||||||
if (response) {
|
|
||||||
allRoutePoints.length = 0;
|
|
||||||
vectorLayerRoute.removeFeatures(vectorLayerRoute.features);
|
|
||||||
// now with compression of the route geometry
|
|
||||||
var geometry = decodeRouteGeometry(response.route_geometry, 5);
|
|
||||||
var lengthOfArray = geometry.length;
|
|
||||||
var points = [];
|
|
||||||
points.length = lengthOfArray;
|
|
||||||
|
|
||||||
//Check if a instruction has no name !
|
|
||||||
var colors = [];
|
|
||||||
if(true){
|
|
||||||
var instrucLength = response.route_instructions.length;
|
|
||||||
for (var i = 0; i < instrucLength; i++) {
|
|
||||||
var indexPos = response.route_instructions[i][3];
|
|
||||||
var streetName = response.route_instructions[i][1];
|
|
||||||
if(streetName == ''){ colors[indexPos] = "#FF00FF"; }
|
|
||||||
else{ colors[indexPos] = "#0033ff"; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//delete any previously displayed via route
|
|
||||||
vectorLayerViaRoute.removeFeatures(vectorLayerViaRoute.features);
|
|
||||||
vectorLayerRoute.removeAllFeatures();
|
|
||||||
|
|
||||||
//Create Route Layer for Display
|
|
||||||
var color = "#0033ff";
|
|
||||||
var changeColor = false;
|
|
||||||
for (var i = 0; i < lengthOfArray; i++) {
|
|
||||||
var point = new OpenLayers.Geometry.Point(geometry[i][1], geometry[i][0]).transform(EPSG_4326, EPSG_900913);
|
|
||||||
points.push(point);
|
|
||||||
allRoutePoints.push(point);
|
|
||||||
|
|
||||||
if(colors[i] != undefined){ changeColor=true;}
|
|
||||||
|
|
||||||
if(i % 1024 == 0 && i>0 || i==lengthOfArray-1 || changeColor){
|
|
||||||
var feature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.LineString(points), null, {
|
|
||||||
strokeColor: color,
|
|
||||||
strokeOpacity: 0.7,
|
|
||||||
strokeWidth: 5
|
|
||||||
});
|
|
||||||
vectorLayerRoute.addFeatures([feature]);
|
|
||||||
points = [];
|
|
||||||
points.push(point);
|
|
||||||
|
|
||||||
if(colors[i] != undefined){ color = colors[i]; }
|
|
||||||
changeColor=false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* secondsToTime()-Function to transform seconds to a time string
|
|
||||||
*/
|
|
||||||
function secondsToTime(seconds){
|
|
||||||
seconds = parseInt(seconds);
|
|
||||||
minutes = parseInt(seconds/60);
|
|
||||||
seconds = seconds%60;
|
|
||||||
hours = parseInt(minutes/60);
|
|
||||||
minutes = minutes%60;
|
|
||||||
//return stunden+':'+minuten+':'+seconds;
|
|
||||||
if(hours==0){
|
|
||||||
return minutes+' min(s)';
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return hours+' h '+minutes+' min(s)';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* getDistanceWithUnit()-Function to return a distance with units
|
|
||||||
*/
|
|
||||||
function getDistanceWithUnit(distance){
|
|
||||||
distance = parseInt(distance);
|
|
||||||
if(distance >= 1000){ return (parseInt(distance/1000))+' km'; }
|
|
||||||
else{ return distance+' m'; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* setMapCenter()-Function to add a marker and center the map
|
|
||||||
*/
|
|
||||||
function setMapCenter(lonlat){
|
|
||||||
//lonlat.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
|
|
||||||
//console.log('zooming to :' + lonlat);
|
|
||||||
|
|
||||||
//Add Marker
|
|
||||||
markersLayer.clearMarkers();
|
|
||||||
var size = new OpenLayers.Size(21,25);
|
|
||||||
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
|
|
||||||
var icon = new OpenLayers.Icon('img/marker.png',size,offset);
|
|
||||||
markersLayer.addMarker(new OpenLayers.Marker(lonlat,icon));
|
|
||||||
|
|
||||||
//Hack - FIXME !
|
|
||||||
map.setCenter(new OpenLayers.LonLat(lonlat.lon-200, lonlat.lat), 17);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* decodeRouteGeometry()-Function to decode encoded Route Geometry
|
|
||||||
*/
|
|
||||||
function decodeRouteGeometry(encoded, precision) {
|
|
||||||
precision = Math.pow(10, -precision);
|
|
||||||
var len = encoded.length, index=0, lat=0, lng = 0, array = [];
|
|
||||||
while (index < len) {
|
|
||||||
var b, shift = 0, result = 0;
|
|
||||||
do {
|
|
||||||
b = encoded.charCodeAt(index++) - 63;
|
|
||||||
result |= (b & 0x1f) << shift;
|
|
||||||
shift += 5;
|
|
||||||
} while (b >= 0x20);
|
|
||||||
var dlat = ((result & 1) ? ~(result >> 1) : (result >> 1));
|
|
||||||
lat += dlat;
|
|
||||||
shift = 0;
|
|
||||||
result = 0;
|
|
||||||
do {
|
|
||||||
b = encoded.charCodeAt(index++) - 63;
|
|
||||||
result |= (b & 0x1f) << shift;
|
|
||||||
shift += 5;
|
|
||||||
} while (b >= 0x20);
|
|
||||||
var dlng = ((result & 1) ? ~(result >> 1) : (result >> 1));
|
|
||||||
lng += dlng;
|
|
||||||
array.push([lat * precision, lng * precision]);
|
|
||||||
}
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* createShortLink()-Function to "create" shortlink of a route
|
|
||||||
*/
|
|
||||||
function createShortLink(str){
|
|
||||||
var script = document.createElement('script');
|
|
||||||
@@ -1,114 +0,0 @@
|
|||||||
/*
|
|
||||||
* Open Source Routing Machine (OSRM) - Web (GUI) Interface
|
|
||||||
* Copyright (C) Pascal Neis, 2011
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Title: Slide.js
|
|
||||||
* Description: Fixme
|
|
||||||
*
|
|
||||||
* @author Pascal Neis, pascal@neis-one.org
|
|
||||||
* @version 0.1 2011-05-15
|
|
||||||
*/
|
|
||||||
|
|
||||||
var timerlen = 5;
|
|
||||||
var slideAniLen = 250;
|
|
||||||
|
|
||||||
var timerID = new Array();
|
|
||||||
var startTime = new Array();
|
|
||||||
var obj = new Array();
|
|
||||||
var endWidth = new Array();
|
|
||||||
var moving = new Array();
|
|
||||||
var dir = new Array();
|
|
||||||
|
|
||||||
function toggleSlide(objname){
|
|
||||||
document.getElementById('panzoombar').style.top="25px";
|
|
||||||
document.getElementById('panzoombar').style.display = "none";
|
|
||||||
document.getElementById('slide').style.display = "none";
|
|
||||||
if(document.getElementById(objname).style.display == "none"){
|
|
||||||
// div is hidden, so let's slide right
|
|
||||||
slide_right(objname);
|
|
||||||
}else{
|
|
||||||
// div is not hidden, so slide left
|
|
||||||
slide_left(objname);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function slide_right(objname){
|
|
||||||
if(moving[objname]){ return; }
|
|
||||||
if(document.getElementById(objname).style.display != "none"){
|
|
||||||
return; // cannot slide right something that is already visible
|
|
||||||
}
|
|
||||||
moving[objname] = true; dir[objname] = "right"; startslide(objname);
|
|
||||||
}
|
|
||||||
|
|
||||||
function slide_left(objname){
|
|
||||||
if(moving[objname]){ return; }
|
|
||||||
if(document.getElementById(objname).style.display == "none"){
|
|
||||||
return; // cannot slide left something that is already hidden
|
|
||||||
}
|
|
||||||
moving[objname] = true; dir[objname] = "left"; startslide(objname);
|
|
||||||
}
|
|
||||||
|
|
||||||
function startslide(objname){
|
|
||||||
obj[objname] = document.getElementById(objname);
|
|
||||||
endWidth[objname] = parseInt(obj[objname].style.width);
|
|
||||||
startTime[objname] = (new Date()).getTime();
|
|
||||||
if(dir[objname] == "right"){ obj[objname].style.width = "1px"; }
|
|
||||||
obj[objname].style.display = "block";
|
|
||||||
timerID[objname] = setInterval('slidetick(\'' + objname + '\');',timerlen);
|
|
||||||
}
|
|
||||||
|
|
||||||
function slidetick(objname){
|
|
||||||
var elapsed = (new Date()).getTime() - startTime[objname];
|
|
||||||
if (elapsed > slideAniLen){ endSlide(objname); }
|
|
||||||
else {
|
|
||||||
var d = Math.round(elapsed / slideAniLen * endWidth[objname]);
|
|
||||||
if(dir[objname] == "left"){ d = endWidth[objname] - d; }
|
|
||||||
obj[objname].style.width = d + "px";
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
function endSlide(objname){
|
|
||||||
clearInterval(timerID[objname]);
|
|
||||||
|
|
||||||
if(dir[objname] == "left"){
|
|
||||||
obj[objname].style.display = "none";
|
|
||||||
document.getElementById('panzoombar').style.left="25px";
|
|
||||||
document.getElementById('panzoombar').style.display = "";
|
|
||||||
document.getElementById('slide').style.left="5px";
|
|
||||||
document.getElementById('slide').innerHTML = "<a class=\"btn-slide\" href=\"javascript:;\" onmousedown=\"toggleSlide('data');\">>></a>";
|
|
||||||
document.getElementById('slide').style.display = "";
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
document.getElementById('panzoombar').style.left="400px";
|
|
||||||
document.getElementById('panzoombar').style.display = "";document.getElementById('slide').style.left="365px";
|
|
||||||
document.getElementById('slide').innerHTML = "<a class=\"btn-slide\" href=\"javascript:;\" onmousedown=\"toggleSlide('data');\"><<</a>";
|
|
||||||
document.getElementById('slide').style.display = "";
|
|
||||||
}
|
|
||||||
obj[objname].style.width = endWidth[objname] + "px";
|
|
||||||
|
|
||||||
delete(moving[objname]);
|
|
||||||
delete(timerID[objname]);
|
|
||||||
delete(startTime[objname]);
|
|
||||||
delete(endWidth[objname]);
|
|
||||||
delete(obj[objname]);
|
|
||||||
delete(dir[objname]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
@@ -1,340 +0,0 @@
|
|||||||
/*
|
|
||||||
* Open Source Routing Machine (OSRM) - Web (GUI) Interface
|
|
||||||
* Copyright (C) Dennis Luxen, 2011
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Title: ViaRoute.js
|
|
||||||
* Description: JS file for routing with via points
|
|
||||||
*
|
|
||||||
* @author Dennis Luxen, luxen@kit.edu
|
|
||||||
* @version 0.1 June 2011
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
//======================
|
|
||||||
// OBJECTS
|
|
||||||
|
|
||||||
//global timestamp to control frequency of mouse->route distance computations
|
|
||||||
var timestamp = (new Date()).getTime();
|
|
||||||
var ISCOMPUTINGDISTANCE = false;
|
|
||||||
var ISCALCULATINGVIA = false;
|
|
||||||
//var HASDELETEDTEMPORARYVIAROUTE = false;
|
|
||||||
var nearestPoint = new OpenLayers.Geometry.Point(1,1);
|
|
||||||
var nearestSegmentIndex = null;
|
|
||||||
var viaPointsVector = [];
|
|
||||||
var p0;
|
|
||||||
|
|
||||||
var temporaryViaStyle = {
|
|
||||||
fillColor: "#ffffff",
|
|
||||||
strokeColor: "#33ff33",
|
|
||||||
strokeOpacity: 0.6,
|
|
||||||
strokeWidth: 2,
|
|
||||||
pointRadius: 4,
|
|
||||||
pointerEvents: "visiblePainted"
|
|
||||||
};
|
|
||||||
|
|
||||||
var permanentViaStyle = {
|
|
||||||
fillColor: "#ffffff",
|
|
||||||
strokeColor: "#0033ff",
|
|
||||||
strokeOpacity: 0.6,
|
|
||||||
strokeWidth: 2,
|
|
||||||
pointRadius: 4,
|
|
||||||
pointerEvents: "visiblePainted"
|
|
||||||
};
|
|
||||||
|
|
||||||
//======================
|
|
||||||
//FUNCTIONS
|
|
||||||
function distanceBetweenPoint(x1, y1, x2, y2) {
|
|
||||||
var a = x1 - x2;
|
|
||||||
var b = y1 - y2;
|
|
||||||
return Math.sqrt(a*a + b*b);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Distance from a point to a line or segment.
|
|
||||||
x point's x coord
|
|
||||||
y point's y coord
|
|
||||||
x0 x coord of the line's A point
|
|
||||||
y0 y coord of the line's A point
|
|
||||||
x1 x coord of the line's B point
|
|
||||||
y1 y coord of the line's B point
|
|
||||||
o specifies if the distance should respect the limits of the segment
|
|
||||||
(overLine = true) or if it should consider the segment as an infinite
|
|
||||||
line (overLine = false), if false returns the distance from the point
|
|
||||||
to the line, otherwise the distance from the point to the segment
|
|
||||||
*/
|
|
||||||
function dotLineLength(x, y, x0, y0, x1, y1, o){
|
|
||||||
function lineLength(x, y, x0, y0){
|
|
||||||
return Math.sqrt((x -= x0) * x + (y -= y0) * y);
|
|
||||||
}
|
|
||||||
if(o && !(o = function(x, y, x0, y0, x1, y1){
|
|
||||||
if(!(x1 - x0)) return {x: x0, y: y};
|
|
||||||
else if(!(y1 - y0)) return {x: x, y: y0};
|
|
||||||
var left, tg = -1 / ((y1 - y0) / (x1 - x0));
|
|
||||||
return {x: left = (x1 * (x * tg - y + y0) + x0 * (x * - tg + y - y1)) / (tg * (x1 - x0) + y0 - y1), y: tg * left - tg * x + y};
|
|
||||||
}(x, y, x0, y0, x1, y1), o.x >= Math.min(x0, x1) && o.x <= Math.max(x0, x1) && o.y >= Math.min(y0, y1) && o.y <= Math.max(y0, y1))){
|
|
||||||
var l1 = lineLength(x, y, x0, y0), l2 = lineLength(x, y, x1, y1);
|
|
||||||
return l1 > l2 ? l2 : l1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var a = y0 - y1, b = x1 - x0, c = x0 * y1 - y0 * x1;
|
|
||||||
return Math.abs(a * x + b * y + c) / Math.sqrt(a * a + b * b);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
function distanceToRoute(pixel) {
|
|
||||||
if(!isStartPointSet || !isEndPointSet){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(ISDRAGGING) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ISCOMPUTINGDISTANCE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var tempTime = (new Date()).getTime()
|
|
||||||
if( tempTime - timestamp < 25) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
timestamp = tempTime;
|
|
||||||
if(ISCALCULATING) {
|
|
||||||
var viaPointFeature = dragLayer.getFeatureBy("name", 'via');
|
|
||||||
if(viaPointFeature != null) {
|
|
||||||
dragLayer.removeFeatures(viaPointFeature);
|
|
||||||
viaPointFeature.destroy;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(pixel == null) {
|
|
||||||
pixel.x = window.event.clientX;
|
|
||||||
pixel.y = window.event.clientY;
|
|
||||||
}
|
|
||||||
|
|
||||||
var newLonLat = map.getLonLatFromPixel(pixel);
|
|
||||||
var minimumDist = 20*Math.pow(2,(19- this.map.getZoom()));
|
|
||||||
var minimumDistToVia = 20*Math.pow(2,(19- this.map.getZoom()));
|
|
||||||
var indexToInsertViaPoint = 0;
|
|
||||||
|
|
||||||
var startFeat = getMarkerByName('start');
|
|
||||||
var endFeat = getMarkerByName('end');
|
|
||||||
var from = new OpenLayers.LonLat(startFeat.geometry.x,startFeat.geometry.y).transform(EPSG_900913, EPSG_4326);
|
|
||||||
var to = new OpenLayers.LonLat(endFeat.geometry.x,endFeat.geometry.y).transform(EPSG_900913, EPSG_4326);
|
|
||||||
|
|
||||||
var mapExtent = map.getExtent();
|
|
||||||
for(var i = 0; i < allRoutePoints.length-1; i++) {
|
|
||||||
var p1 = allRoutePoints[i];
|
|
||||||
var p2 = allRoutePoints[i+1];
|
|
||||||
if(p1.x < mapExtent.left || p1.x > mapExtent.right || p1.y < mapExtent.bottom || p1.y > mapExtent.top) {
|
|
||||||
if(p2.x < mapExtent.left || p2.x > mapExtent.right || p2.y < mapExtent.bottom || p2.y > mapExtent.top) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//check if previous segment is closest to via point
|
|
||||||
//if yes, then we have passed a via point.
|
|
||||||
if(viaPointsVector.length > indexToInsertViaPoint && p0) {
|
|
||||||
var viaPoint = new OpenLayers.LonLat(viaPointsVector[indexToInsertViaPoint][1],viaPointsVector[indexToInsertViaPoint][0]).transform(EPSG_4326, EPSG_900913);
|
|
||||||
var dist2 = dotLineLength(viaPoint.lon, viaPoint.lat, p1.x, p1.y, p0.x, p0.y, true)
|
|
||||||
if( 0 == dist2 ) {
|
|
||||||
indexToInsertViaPoint++;
|
|
||||||
}
|
|
||||||
var tmpDist = distanceBetweenPoint(viaPoint.lat, viaPoint.lon, newLonLat.lat, newLonLat.lon);
|
|
||||||
if(tmpDist < minimumDistToVia) {
|
|
||||||
minimumDistToVia = tmpDist;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//continue if point out of view
|
|
||||||
dist = dotLineLength(newLonLat.lon, newLonLat.lat, p1.x, p1.y, p2.x, p2.y, true);
|
|
||||||
if(dist <= minimumDist) {
|
|
||||||
nearestSegmentIndex = indexToInsertViaPoint;
|
|
||||||
minimumDist = dist;
|
|
||||||
var lonDiff = (p2.x - p1.x)
|
|
||||||
var m = (p2.y - p1.y) / lonDiff;
|
|
||||||
|
|
||||||
var b = p1.y - (m * p1.x);
|
|
||||||
var m2 = m*m;
|
|
||||||
var x = (m * newLonLat.lat + newLonLat.lon - m * b) / (m2 + 1);
|
|
||||||
var y = (m2 * newLonLat.lat + m * newLonLat.lon + b) / (m2 + 1);
|
|
||||||
var r = (x - p1.x) / lonDiff;
|
|
||||||
if ( r <= 1 && r >= 0 ) {
|
|
||||||
nearestPoint.x = x;
|
|
||||||
nearestPoint.y = y;
|
|
||||||
} else {
|
|
||||||
if( r < 0 ) {
|
|
||||||
nearestPoint.x = p1.x;
|
|
||||||
nearestPoint.y = p1.y;
|
|
||||||
} if ( r > 1 ) {
|
|
||||||
nearestPoint.x = p2.x;
|
|
||||||
nearestPoint.y = p2.y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(p2.x == p1.x) {
|
|
||||||
nearestPoint.x = p1.x;
|
|
||||||
nearestPoint.y = newLonLat.lat;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var zoomFactor = Math.pow(2,(19- this.map.getZoom()));
|
|
||||||
var viaPointFeature = dragLayer.getFeatureBy("name", 'via');
|
|
||||||
if(viaPointFeature != null) {
|
|
||||||
dragLayer.removeFeatures(viaPointFeature);
|
|
||||||
viaPointFeature.destroy;
|
|
||||||
}
|
|
||||||
|
|
||||||
//too close to start or destination?
|
|
||||||
if(Math.min(distanceBetweenPoint(startFeat.geometry.x, startFeat.geometry.y, newLonLat.lon, newLonLat.lat),
|
|
||||||
distanceBetweenPoint(endFeat.geometry.x, endFeat.geometry.y, newLonLat.lon, newLonLat.lat)) < 10*zoomFactor) {
|
|
||||||
ISCOMPUTINGDISTANCE = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Are we close to the route but sufficiently far away from any existing via point?
|
|
||||||
if(minimumDist < 10*zoomFactor && minimumDistToVia > 5*zoomFactor) {
|
|
||||||
viaPointFeature = new OpenLayers.Feature.Vector( OpenLayers.Geometry.Polygon.createRegularPolygon( nearestPoint, (1.5*zoomFactor), 15, 0 ), null, temporaryViaStyle );
|
|
||||||
viaPointFeature.name = "via";
|
|
||||||
dragLayer.addFeatures( viaPointFeature );
|
|
||||||
//console.log('nearestSegmentIndex: ' + nearestSegmentIndex);
|
|
||||||
}
|
|
||||||
ISCOMPUTINGDISTANCE = false;
|
|
||||||
p0 = p1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function computeViaRoute(pixel, isTemporary, skipViaPointsIndex) {
|
|
||||||
if(ISCALCULATINGVIA && isTemporary)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if( nearestSegmentIndex == null ) {
|
|
||||||
//console.log('nearestSegmentIndex: ' + nearestSegmentIndex);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isTemporary == null) {
|
|
||||||
isTemporary = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//So, we jumped all fences
|
|
||||||
ISCALCULATINGVIA = true;
|
|
||||||
|
|
||||||
var startFeat = getMarkerByName('start');
|
|
||||||
var endFeat = getMarkerByName('end');
|
|
||||||
var from = new OpenLayers.LonLat(startFeat.geometry.x,startFeat.geometry.y).transform(EPSG_900913, EPSG_4326);
|
|
||||||
var to = new OpenLayers.LonLat(endFeat.geometry.x,endFeat.geometry.y).transform(EPSG_900913, EPSG_4326);
|
|
||||||
|
|
||||||
var coordinate = map.getLonLatFromPixel(pixel);
|
|
||||||
var via = coordinate.transform(EPSG_900913, EPSG_4326);
|
|
||||||
var viaNodeInserted = false;
|
|
||||||
var newURL = HOST_ROUTING_URL + "&start="+from.lat + ',' + from.lon + '&dest=' + to.lat + ',' + to.lon;
|
|
||||||
newURL += '&geomformat=cmp';
|
|
||||||
for(var i = 0; i < viaPointsVector.length; i++) {
|
|
||||||
if(i == nearestSegmentIndex) { //insert new via node here
|
|
||||||
newURL += '&via=' + via.lat + ',' + via.lon;
|
|
||||||
viaNodeInserted = true;
|
|
||||||
}
|
|
||||||
if(skipViaPointsIndex == i)
|
|
||||||
continue;
|
|
||||||
newURL += '&via=' + viaPointsVector[i][0] + ',' + viaPointsVector[i][1];
|
|
||||||
}
|
|
||||||
if(false == viaNodeInserted) {
|
|
||||||
newURL += '&via=' + via.lat + ',' + via.lon;
|
|
||||||
}
|
|
||||||
newURL += '&output=json' + '&z=' + this.map.getZoom();
|
|
||||||
if(!isTemporary) {
|
|
||||||
newURL += '&instructions=true&jsonp=showResultsRoute';
|
|
||||||
} else {
|
|
||||||
newURL += '&instructions=false&jsonp=showResultsViaRoute';
|
|
||||||
}
|
|
||||||
//console.log(newURL);
|
|
||||||
var script = document.createElement('script');
|
|
||||||
script.id = 'JSONP';
|
|
||||||
script.type = 'application/javascript';
|
|
||||||
script.src = newURL;
|
|
||||||
|
|
||||||
document.body.appendChild(script);
|
|
||||||
}
|
|
||||||
|
|
||||||
function showResultsViaRoute(response) {
|
|
||||||
if (response) {
|
|
||||||
var viaRouteVector = [];
|
|
||||||
// now with compression of the route geometry
|
|
||||||
var geometry = decodeRouteGeometry(response.route_geometry, 5);
|
|
||||||
var lengthOfArray = geometry.length;
|
|
||||||
var points = [];
|
|
||||||
points.length = lengthOfArray;
|
|
||||||
|
|
||||||
//Create Route Layer for Display
|
|
||||||
for (var i = 0; i < lengthOfArray; i++) {
|
|
||||||
var point = new OpenLayers.Geometry.Point(geometry[i][1], geometry[i][0]).transform(EPSG_4326, EPSG_900913);
|
|
||||||
allRoutePoints.push(point);
|
|
||||||
points.push(point);
|
|
||||||
|
|
||||||
if(i % 1024 == 0 && i>0 || i==lengthOfArray-1){
|
|
||||||
/* var feature1 = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.LineString(points), null, {
|
|
||||||
strokeColor: "#006600",
|
|
||||||
strokeOpacity: 1,
|
|
||||||
strokeWidth: 9
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
var feature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.LineString(points), null, {
|
|
||||||
strokeColor: "#aaffaa",
|
|
||||||
strokeOpacity: 0.8,
|
|
||||||
strokeWidth: 7
|
|
||||||
});
|
|
||||||
// viaRouteVector.push(feature1);
|
|
||||||
viaRouteVector.push(feature);
|
|
||||||
points = [];
|
|
||||||
points.push(point);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
vectorLayerViaRoute.removeFeatures(vectorLayerViaRoute.features);
|
|
||||||
|
|
||||||
for(var i = 0; i< viaRouteVector.length; i++) {
|
|
||||||
vectorLayerViaRoute.addFeatures(viaRouteVector[i]);
|
|
||||||
}
|
|
||||||
viaRouteVector.length = 0;
|
|
||||||
ISCALCULATINGVIA = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function paintViaPoints() {
|
|
||||||
//remove all previous via points
|
|
||||||
var featuresToRemove = [];
|
|
||||||
for(var i = 0; i < dragLayer.features.length; i++) {
|
|
||||||
if(dragLayer.features[i].name == "viapoint" || "via" == dragLayer.features[i].name ) {
|
|
||||||
featuresToRemove.push(dragLayer.features[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dragLayer.removeFeatures(featuresToRemove);
|
|
||||||
featuresToRemove.length = 0;
|
|
||||||
|
|
||||||
//paint all via points
|
|
||||||
var zoomFactor = Math.pow(2,(19- this.map.getZoom()));
|
|
||||||
//console.log('painting ' + viaPointsVector.length + ' via points');
|
|
||||||
for(var i = 0; i < viaPointsVector.length; i++) {
|
|
||||||
//console.log(viaPointsVector[i]);
|
|
||||||
var viapoint = new OpenLayers.Geometry.Point(
|
|
||||||
viaPointsVector[i][1],
|
|
||||||
viaPointsVector[i][0]);
|
|
||||||
viapoint.transform(EPSG_4326, EPSG_900913);
|
|
||||||
var viaPointFeature = new OpenLayers.Feature.Vector( OpenLayers.Geometry.Polygon.createRegularPolygon( viapoint, (1.5*zoomFactor), 20, 0 ), null, permanentViaStyle );
|
|
||||||
viaPointFeature.name = "viapoint";
|
|
||||||
viaPointFeature.viaIndex = i;
|
|
||||||
dragLayer.addFeatures( viaPointFeature )
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Before Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 934 B |
|
Before Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 831 B |
|
Before Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 3.0 KiB |
@@ -1,70 +0,0 @@
|
|||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
||||||
<title>OSRM Web(GUI)Interface</title>
|
|
||||||
<meta name="description" content="OSRM Web(GUI)Interface"/>
|
|
||||||
<meta name="language" content="en" />
|
|
||||||
<meta name="robots" content="index,follow" />
|
|
||||||
<meta name="author" content="Pascal Neis" />
|
|
||||||
<meta name="revisit-After" content="7 days" />
|
|
||||||
<meta name="distribution" content="global" />
|
|
||||||
|
|
||||||
<script src="ol/OpenLayers.js"></script>
|
|
||||||
<script src="ol/OpenStreetMap.js"></script>
|
|
||||||
<script src="Slides.js"></script>
|
|
||||||
<script src="Map.js"></script>
|
|
||||||
<script src="Route.js"></script>
|
|
||||||
<script src="ViaRoute.js"></script>
|
|
||||||
<script src="Geocode.js"></script>
|
|
||||||
<script src="MouseClick.js"></script>
|
|
||||||
<!-- <script src="osrm.js"></script> -->
|
|
||||||
|
|
||||||
<link rel="stylesheet" href="style.css" type="text/css" media="all" />
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body onload="init();">
|
|
||||||
|
|
||||||
<div id="slide" class="slide"><a class="btn-slide" href="javascript:;" onmousedown="toggleSlide('data');"><<</a></div>
|
|
||||||
<div id="data" style="width:350px;overflow:hidden;" class="data">
|
|
||||||
<div id="inner" style="width:350px;overflow:hidden;">
|
|
||||||
<div id="routing">
|
|
||||||
<!-- http://map.project-osrm.org/osrm3_small.png - http://project-osrm.org/osrm3.png -->
|
|
||||||
<img src="http://map.project-osrm.org/osrm3_small.png" style="margin-left:auto; margin-right:auto; width:200px; display:block; padding: 5px;" alt="">
|
|
||||||
|
|
||||||
<table width="100%">
|
|
||||||
<tr id="StartPoint">
|
|
||||||
<td><div class="textLabel"><img src="img/arrow-start.png" class="radioIcons" width="12" height="16" alt=""><span class="text"></span></div></td>
|
|
||||||
<td><input name="tfStartSearch" style="width:220px" type="text" id="tfStartSearch" class="tfPoints" value="Berlin" title="Search your start point!" onKeyPress="checkReturn('start',event);" >
|
|
||||||
<button name="enterStart" onclick="setStatus('start'); geocodeAddress('start');">Search</button></td>
|
|
||||||
<td rowspan="2" valign="middle">
|
|
||||||
<!-- <button name="switchStartEnd" disabled="true" id="switchStartEnd" type="button"
|
|
||||||
value="Change Start and Endpoint"onClick="changeStartEnd();"><img src="img/changePos.gif" width="9" height="22" alt="Tausche Start- und Endpunkt"><br> --></button></td>
|
|
||||||
</tr>
|
|
||||||
<tr id="EndPoint">
|
|
||||||
<td nowrap>
|
|
||||||
<div class="textLabel"><img src="img/arrow-finish.png" class="radioIcons" width="12" height="16" alt=""><span class="text"></span></div>
|
|
||||||
</td>
|
|
||||||
<td id="tdEnd">
|
|
||||||
<input name="tfEndSearch" style="width:220px" type="text" id="tfEndSearch" class="tfPoints" value="München, Altstadt" title="Search your end point!" onKeyPress="checkReturn('end',event);">
|
|
||||||
<button name="enterEnd" onclick="setStatus('end'); geocodeAddress('end');">Search</button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="calc_route" class="calc_route"><span class="options"><a href="#" onclick="closeOpenDiv('options');">Options</a></span>
|
|
||||||
<select name="selectRoutePref" id="selectRoutePref" title="Select the route preference ..."><option value="Fastest" selected>Car (travel time)</option></select>
|
|
||||||
<input name="Submit5" type="submit" class="calculate_button" id="Calculate" title="Route!" onClick="markersLayer.clearMarkers(); routing(false);" value="Route!"></div>
|
|
||||||
|
|
||||||
<div id="options" class="options_div" style="display:none"><input class="checkbox" type="checkbox" name="cbNoNames" id="cbNoNames" value="checkbox">Highlight No Name Streets in my Route</div>
|
|
||||||
<div id="information" class="information"> <p class="infoHL">Demo Website for the <br><a target="_blank" href="http://project-osrm.org/">Open Source Routing Machine Project</a></p> </div>
|
|
||||||
<div id="thx" class="thx">GUI v0.3 110722 - OSRM hosting by <a target="_blank" href="http://www.geofabrik.de/">Geofabrik</a> - Geocoder by <a target="_blank" href="http://developer.mapquest.com/web/products/open/nominatim/">MapQuest</a></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="map" class="map"></div>
|
|
||||||
|
|
||||||
<div class="copyright">© 2011 <a target="_blank" href="http://project-osrm.org/">Project OSRM</a> - Map data <a target="_blank" href="http://creativecommons.org/licenses/by-sa/2.0/">CC-By-SA</a> <a target="_blank" href="http://www.openstreetmap.org">by OpenStreetMap</a></div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
/**
|
|
||||||
* Namespace: Util.OSM
|
|
||||||
*/
|
|
||||||
OpenLayers.Util.OSM = {};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constant: MISSING_TILE_URL
|
|
||||||
* {String} URL of image to display for missing tiles
|
|
||||||
*/
|
|
||||||
OpenLayers.Util.OSM.MISSING_TILE_URL = "http://www.openstreetmap.org/openlayers/img/404.png";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Property: originalOnImageLoadError
|
|
||||||
* {Function} Original onImageLoadError function.
|
|
||||||
*/
|
|
||||||
OpenLayers.Util.OSM.originalOnImageLoadError = OpenLayers.Util.onImageLoadError;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function: onImageLoadError
|
|
||||||
*/
|
|
||||||
OpenLayers.Util.onImageLoadError = function() {
|
|
||||||
if (this.src.match(/^http:\/\/[abc]\.[a-z]+\.openstreetmap\.org\//)) {
|
|
||||||
this.src = OpenLayers.Util.OSM.MISSING_TILE_URL;
|
|
||||||
} else if (this.src.match(/^http:\/\/[def]\.tah\.openstreetmap\.org\//)) {
|
|
||||||
// do nothing - this layer is transparent
|
|
||||||
} else {
|
|
||||||
OpenLayers.Util.OSM.originalOnImageLoadError;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class: OpenLayers.Layer.OSM.Mapnik
|
|
||||||
*
|
|
||||||
* Inherits from:
|
|
||||||
* - <OpenLayers.Layer.OSM>
|
|
||||||
*/
|
|
||||||
OpenLayers.Layer.OSM.Mapnik = OpenLayers.Class(OpenLayers.Layer.OSM, {
|
|
||||||
/**
|
|
||||||
* Constructor: OpenLayers.Layer.OSM.Mapnik
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* name - {String}
|
|
||||||
* options - {Object} Hashtable of extra options to tag onto the layer
|
|
||||||
*/
|
|
||||||
initialize: function(name, options) {
|
|
||||||
var url = [
|
|
||||||
"http://a.tile.openstreetmap.org/${z}/${x}/${y}.png",
|
|
||||||
"http://b.tile.openstreetmap.org/${z}/${x}/${y}.png",
|
|
||||||
"http://c.tile.openstreetmap.org/${z}/${x}/${y}.png"
|
|
||||||
];
|
|
||||||
options = OpenLayers.Util.extend({ numZoomLevels: 19, buffer: 0 }, options);
|
|
||||||
var newArguments = [name, url, options];
|
|
||||||
OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
|
|
||||||
},
|
|
||||||
|
|
||||||
CLASS_NAME: "OpenLayers.Layer.OSM.Mapnik"
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class: OpenLayers.Layer.OSM.Osmarender
|
|
||||||
*
|
|
||||||
* Inherits from:
|
|
||||||
* - <OpenLayers.Layer.OSM>
|
|
||||||
*/
|
|
||||||
OpenLayers.Layer.OSM.Osmarender = OpenLayers.Class(OpenLayers.Layer.OSM, {
|
|
||||||
/**
|
|
||||||
* Constructor: OpenLayers.Layer.OSM.Osmarender
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* name - {String}
|
|
||||||
* options - {Object} Hashtable of extra options to tag onto the layer
|
|
||||||
*/
|
|
||||||
initialize: function(name, options) {
|
|
||||||
var url = [
|
|
||||||
"http://a.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png",
|
|
||||||
"http://b.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png",
|
|
||||||
"http://c.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png"
|
|
||||||
];
|
|
||||||
options = OpenLayers.Util.extend({ numZoomLevels: 18, buffer: 0 }, options);
|
|
||||||
var newArguments = [name, url, options];
|
|
||||||
OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
|
|
||||||
},
|
|
||||||
|
|
||||||
CLASS_NAME: "OpenLayers.Layer.OSM.Osmarender"
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class: OpenLayers.Layer.OSM.CycleMap
|
|
||||||
*
|
|
||||||
* Inherits from:
|
|
||||||
* - <OpenLayers.Layer.OSM>
|
|
||||||
*/
|
|
||||||
OpenLayers.Layer.OSM.CycleMap = OpenLayers.Class(OpenLayers.Layer.OSM, {
|
|
||||||
/**
|
|
||||||
* Constructor: OpenLayers.Layer.OSM.CycleMap
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* name - {String}
|
|
||||||
* options - {Object} Hashtable of extra options to tag onto the layer
|
|
||||||
*/
|
|
||||||
initialize: function(name, options) {
|
|
||||||
var url = [
|
|
||||||
"http://a.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png",
|
|
||||||
"http://b.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png",
|
|
||||||
"http://c.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png"
|
|
||||||
];
|
|
||||||
options = OpenLayers.Util.extend({ numZoomLevels: 19, buffer: 0 }, options);
|
|
||||||
var newArguments = [name, url, options];
|
|
||||||
OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
|
|
||||||
},
|
|
||||||
|
|
||||||
CLASS_NAME: "OpenLayers.Layer.OSM.CycleMap"
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class: OpenLayers.Layer.OSM.MapQuest
|
|
||||||
*
|
|
||||||
* Inherits from:
|
|
||||||
* - <OpenLayers.Layer.OSM>
|
|
||||||
*/
|
|
||||||
OpenLayers.Layer.OSM.MapQuest = OpenLayers.Class(OpenLayers.Layer.OSM, {
|
|
||||||
/**
|
|
||||||
* Constructor: OpenLayers.Layer.OSM.MapQuest
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* name - {String}
|
|
||||||
* options - {Object} Hashtable of extra options to tag onto the layer
|
|
||||||
*/
|
|
||||||
initialize: function(name, options) {
|
|
||||||
var url = [
|
|
||||||
"http://otile1.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png",
|
|
||||||
"http://otile2.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png",
|
|
||||||
"http://otile3.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png"
|
|
||||||
];
|
|
||||||
options = OpenLayers.Util.extend({ numZoomLevels: 19, buffer: 0 }, options);
|
|
||||||
var newArguments = [name, url, options];
|
|
||||||
OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
|
|
||||||
},
|
|
||||||
|
|
||||||
CLASS_NAME: "OpenLayers.Layer.OSM.MapQuest"
|
|
||||||
});
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
This is the OpenLayers Version 2.10
|
|
||||||
|
Before Width: | Height: | Size: 42 B |
|
Before Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 451 B |
|
Before Width: | Height: | Size: 451 B |
|
Before Width: | Height: | Size: 249 B |
|
Before Width: | Height: | Size: 992 B |