Project-OSRM / osrm-backend

Open Source Routing Machine - C++ backend
http://map.project-osrm.org
BSD 2-Clause "Simplified" License
6.34k stars 3.35k forks source link

Distance Table #5366

Closed Eichenherz closed 1 month ago

Eichenherz commented 5 years ago

I need a matrix/table of distances between coords to pass to a VRP Solver. This is the format: std::vector<std::vector> . I know OSRM does provide such a table, but it returns a JSON object, I don't need this, since I want to feed the table right into the Solver ( same .exe ). How can I do this ? Without converting back & forth to JSON

danpat commented 5 years ago

@Eichenherz Without modifying OSRM's code, you can't.

Internally, OSRM stores a flat std::vector before serializing to JSON - the data is there in an efficient format, it's just not exposed in the primary OSRM API (either via Node, HTTP or C++).

I've been considering how we could expose more compact representations, but there has been no work done so far. Unless you're willing to modify OSRM C++ code, there is no way to get the data in non-JSON format currently.

Eichenherz commented 5 years ago

If there's no other way, then I'll modify the code. Where should I look exactly ?

danpat commented 5 years ago

Here: https://github.com/Project-OSRM/osrm-backend/blob/master/src/engine/plugins/table.cpp#L157

On this line, the result_tables_pair vector is fully populated with results. The .MakeResponse function converts that and packs it into the result object in JSON form.

The easiest thing to do would be to dive into .MakeResponse and have it serialize out a Buffer or some other flat structure. Check the tile.cpp plugin for an example of how to return binary data.

rgugliel commented 5 years ago

Is this feature (exposing raw data) planned for the future?

I use osrm-backend with a homemade Scala/JNI wrapper and avoid the passage through JSON would be very nice.

github-actions[bot] commented 2 months ago

This issue seems to be stale. It will be closed in 30 days if no further activity occurs.