<div dir="ltr"><div><div><div><div><div><div><div>First of all, don't use C-style casts, a la `(int)myObject;` as this will (in the worst case) degrade to a `reinterpret_cast` and you really don't want this behavior.<br><br></div>Now take a look here:<br>> <a href="https://github.com/Project-OSRM/osrm-backend/blob/e1ac1c4fdc062a0e5c017d268d0a7fcb25bbbab1/include/osrm/json_container.hpp#L84-L87">https://github.com/Project-OSRM/osrm-backend/blob/e1ac1c4fdc062a0e5c017d268d0a7fcb25bbbab1/include/osrm/json_container.hpp#L84-L87</a><br><br></div>This is the definition of `osrm::json::Object`. Above it you find the definition of `osrm::json::Value`, which is a heterogeneous sum type, making use of the following implementation:<br>> <a href="https://github.com/mapbox/variant">https://github.com/mapbox/variant</a><br><br></div>And here is the basic hello world example for the variant implementation:<br>> <a href="https://github.com/mapbox/variant/blob/bf485dfb59aef26f3ef2183d7c8c1111ad97062b/test/variant_hello_world.cpp">https://github.com/mapbox/variant/blob/bf485dfb59aef26f3ef2183d7c8c1111ad97062b/test/variant_hello_world.cpp</a><br><br></div>Because it mimics Boost.Variant, please have a look at the detailed tutorial here:<br>> <a href="http://www.boost.org/doc/libs/1_59_0/doc/html/variant/tutorial.html">http://www.boost.org/doc/libs/1_59_0/doc/html/variant/tutorial.html</a><br><br></div>It shows you among other things how to use the double dispatch visitor pattern for extracting values from a variant.<br><br></div>Hope that helps,<br></div>Daniel</div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Sep 20, 2015 at 8:20 PM, Richard Marsden <span dir="ltr"><<a href="mailto:winwaed@gmail.com" target="_blank">winwaed@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Steve how did you extract information from the osrm::json::Object<br>
returned object?<br>
I could covert the Object to string, and then parse it with a 3rd<br>
party JSON library, but that seems long-winded.<br>
I've already asked this question on the OSM Q&A site but no anwers yet:<br>
<br>
<a href="https://help.openstreetmap.org/questions/45342/extracting-data-values-from-osrms-osrmjsonobject-using-c" rel="noreferrer" target="_blank">https://help.openstreetmap.org/questions/45342/extracting-data-values-from-osrms-osrmjsonobject-using-c</a><br>
<br>
Text of question:<br>
<br>
I can receive the JSON result successfully and printing it to the<br>
console (as per the online samples), but I am have problems extracting<br>
actual field data. How can I extract individual fields as numbers,<br>
string, etc?<br>
<br>
I've tried various forms of casting, but this is what I have at the<br>
moment (trying to extract the status value):<br>
<br>
const int gr_result_code = routing_machine.RunQuery(route_parameters,<br>
json_result);<br>
std::string sStat("status");<br>
auto it = json_result.values.find(sStat);<br>
osrm::json::Number vv =  (osrm::json::Number) ((*it).second); // doesn't compile<br>
int v = (int) (vv.value); // probably some dodgy rounding here<br>
<br>
The Number casting is producing compiler errors. I guess I could<br>
convert the object to a string, and then using a third party JSON<br>
parser to extract individual fields, but this seems very wasteful.<br>
<br>
<br>
--------------------<br>
Richard<br>
<span class="im HOEnZb"><br>
On Thu, Sep 17, 2015 at 8:20 PM, Stephen Woodbridge<br>
<<a href="mailto:woodbri@swoodbridge.com">woodbri@swoodbridge.com</a>> wrote:<br>
</span><div class="HOEnZb"><div class="h5">> Richard,<br>
><br>
> I have already imbedded OSRM into a C++ application and in fact wrapped that<br>
> application into a postgresql database extension. I my case I only need data<br>
> for a city but I was making literally billions of calls to osrm.<br>
><br>
> As Patrick said, OSRM makes random access calls to memory and there are a<br>
> lot of variables that come into play like how well the data is clustered in<br>
> memory pages, how many page faults you hit, etc. For your specific use case<br>
> no one will have a good answer for you and you really need to do some<br>
> performance testing using the product the way you intend it to be used and<br>
> see what the performance issues are. Maybe you use case is fine. The OSRM<br>
> public service uses lots of memory because it has to support multiple random<br>
> requests anywhere in the world and it can not afford to get stuck page in<br>
> swap. Using swap and an SSD might be fine in your application, and may be it<br>
> won't, but we do not have enough information to consider the problem more<br>
> than to give the standard answer - more memory is faster more swapping is<br>
> slower.<br>
><br>
> -Steve<br>
><br>
><br>
><br>
><br>
> On 9/17/2015 8:45 PM, Richard Marsden wrote:<br>
>><br>
>> Thanks for the quick reply Patrick.<br>
>><br>
>>> Presumably I could do the same for world preparation & routing? Have,<br>
>>> perhaps a 100GB+ swap file, ideally on an SSD.<br>
>><br>
>><br>
>>> This will fall apart when you have some actual load pressure on the<br>
>>> system. We need random access to memory, which will create a lot of<br>
>>> page faults (== slow). Even an SSD is not even close to memory speed.<br>
>><br>
>><br>
>>> You have two options:<br>
>>> split the datasets<br>
>>> get a bigger server<br>
>><br>
>><br>
>><br>
>> I would imagine that is the case for the standard http server. I was<br>
>> thinking of using it as a linked library from a C++ program. Splitting<br>
>> the datasets by continent is a possibility though.<br>
>><br>
>> (writing a C# interface was another thought, but that would be a<br>
>> different use case and definitely with smaller datasets)<br>
>><br>
>> Cheers,<br>
>><br>
>> Richard<br>
>><br>
>><br>
>><br>
>><br>
>> On Thu, Sep 17, 2015 at 4:37 PM, Patrick Niklaus<br>
>> <<a href="mailto:patrick.niklaus@student.kit.edu">patrick.niklaus@student.kit.edu</a>> wrote:<br>
>>><br>
>>> W.r.t. the pre-preprocessing you are correct.<br>
>>><br>
>>>> What is that extra power used for?<br>
>>><br>
>>><br>
>>> Including all sorts of external data sources. Also the logic in the<br>
>>> lua profiles is not just replaceable by simple key-value pairs, OSM<br>
>>> requires you to handle a lot of special cases.<br>
>>><br>
>>>> Presumably I could do the same for world preparation & routing? Have,<br>
>>>> perhaps a 100GB+ swap file, ideally on an SSD.<br>
>>><br>
>>><br>
>>> This will fall apart when you have some actual load pressure on the<br>
>>> system. We need random access to memory, which will create a lot of<br>
>>> page faults (== slow). Even an SSD is not even close to memory speed.<br>
>>><br>
>>> You have two options:<br>
>>> - split the datasets<br>
>>> - get a bigger server<br>
>>><br>
>>> Cheers,<br>
>>> Patrick<br>
>>><br>
>>><br>
>>> On Thu, Sep 17, 2015 at 10:06 PM, Richard Marsden <<a href="mailto:winwaed@gmail.com">winwaed@gmail.com</a>><br>
>>> wrote:<br>
>>>><br>
>>>> I've been evaluating OSRM, using it primarily as a library from C++.<br>
>>>><br>
>>>> I believe I've determined the answer to most of the questions, but I'm<br>
>>>> also looking for confirmation.<br>
>>>> (I understand the reason for these constraints - the trade-off of<br>
>>>> speed vs flexibility)<br>
>>>><br>
>>>> First, road speeds are set with 'profile.lua' at the osrm-extract<br>
>>>> stage. This filters out unnecessary roads (eg. foot paths for car<br>
>>>> routing), but also applies the road speeds.<br>
>>>> If I wish to change the speed profile, I need to regenerate the road<br>
>>>> network with osrm-extract and osrm-routed.<br>
>>>> Correct?<br>
>>>><br>
>>>> If I wanted different speeds for the final distance/time calculations,<br>
>>>> I could use the returned route, and apply my own speed table according<br>
>>>> to the road type of each road segment. This would not, of course,<br>
>>>> change the route geometry is calculated.<br>
>>>><br>
>>>> If I want a shortest route (distance optimized) instead of a quickest<br>
>>>> route (time optimized), I need to set all the road speeds to the same<br>
>>>> speed and regenerate the network. I.e. osrm does not directly support<br>
>>>> the concept of a "shortest route".<br>
>>>><br>
>>>> The profile is provided with a LUA file. I had to look this one up :-)<br>
>>>> Looks a useful scripting language, but why is this profile a script<br>
>>>> file, and not a simple configuration file of constants (eg. key-value<br>
>>>> pairs)?<br>
>>>> Seems like an unnecessary complexity - I'd like to understand the<br>
>>>> perceived advantages. What is that extra power used for?<br>
>>>><br>
>>>> Finally, the memory usage... I saw a reference to the server requiring<br>
>>>> 40GB of memory for pan-European routing. Presumably that could be<br>
>>>> offset with a large swap file(?)<br>
>>>> A large swap file has worked well when I was testing the US-South<br>
>>>> region on an 8GB machine.<br>
>>>> Presumably I could do the same for world preparation & routing? Have,<br>
>>>> perhaps a 100GB+ swap file, ideally on an SSD.<br>
>>>><br>
>>>><br>
>>>> Cheers,<br>
>>>><br>
>>>> Richard Marsden<br>
>>>><br>
>>>> _______________________________________________<br>
>>>> OSRM-talk mailing list<br>
>>>> <a href="mailto:OSRM-talk@openstreetmap.org">OSRM-talk@openstreetmap.org</a><br>
>>>> <a href="https://lists.openstreetmap.org/listinfo/osrm-talk" rel="noreferrer" target="_blank">https://lists.openstreetmap.org/listinfo/osrm-talk</a><br>
>>><br>
>>><br>
>>> _______________________________________________<br>
>>> OSRM-talk mailing list<br>
>>> <a href="mailto:OSRM-talk@openstreetmap.org">OSRM-talk@openstreetmap.org</a><br>
>>> <a href="https://lists.openstreetmap.org/listinfo/osrm-talk" rel="noreferrer" target="_blank">https://lists.openstreetmap.org/listinfo/osrm-talk</a><br>
>><br>
>><br>
>> _______________________________________________<br>
>> OSRM-talk mailing list<br>
>> <a href="mailto:OSRM-talk@openstreetmap.org">OSRM-talk@openstreetmap.org</a><br>
>> <a href="https://lists.openstreetmap.org/listinfo/osrm-talk" rel="noreferrer" target="_blank">https://lists.openstreetmap.org/listinfo/osrm-talk</a><br>
>><br>
><br>
><br>
> _______________________________________________<br>
> OSRM-talk mailing list<br>
> <a href="mailto:OSRM-talk@openstreetmap.org">OSRM-talk@openstreetmap.org</a><br>
> <a href="https://lists.openstreetmap.org/listinfo/osrm-talk" rel="noreferrer" target="_blank">https://lists.openstreetmap.org/listinfo/osrm-talk</a><br>
<br>
_______________________________________________<br>
OSRM-talk mailing list<br>
<a href="mailto:OSRM-talk@openstreetmap.org">OSRM-talk@openstreetmap.org</a><br>
<a href="https://lists.openstreetmap.org/listinfo/osrm-talk" rel="noreferrer" target="_blank">https://lists.openstreetmap.org/listinfo/osrm-talk</a><br>
</div></div></blockquote></div><br></div>