Solution to JSON

Is there any class/utility on jsprit to get the solution in Json? right now i’m getting it on XML and then transforming it on json with org.json but it’ll be better to get it firstly as Json

new VrpXMLWriter(vrp, solutions).write(“output/problem-with-solutions.xml”);
String xml = FileUtils.readFileToString(new File(“output/problem-with-solutions.xml”));


I’ve written one, but not complete yet. I was planning to offer for the project, but has to be cleaned a little bit before.

1 Like

The problem is that i’m gonna use it on a external server so i’m having time problems cose:
-DistanceMatrix calls take a while if there are some locations
-Jsprit problemSolution takes a while too if there are some locations
-if the server has lot of background work just create the XML file +read it to then create the Json file takes a while too
I was thikin’ about doing it directly to Json from BestSolution but i’m not that into java to make it by my own i think.
¿Any thoughts?

I’ve sent you my code to export into JSON privatly as a start. Did you get it? It needs gson library.
It exports the solution into JSON.
To tell you the truth, it is not clear what you wished to write. I don’t see how distance matrix calls interfere with solution export?

Using Jsprit, being a genetic algorithm is time consuming by itself. (You can’t help it.) I don’t really see how any export/import tasks would cause any real time impact compared to the time consumption by running jspit.

If your distance matrix calls are time-expensive, but static (doesn’t depend on the current solution), you could choose one of these.
(1) Pre-render the whole distance matrix before running Jsplit. It
(2) Cache the calculated values while running Jsplit. This is best, when there are many dependencies and you suspect that just a small percentage of the whole matrix will ever be queried. This usually needs less memory (than whole matrix), requires only a Map<> object.

Although the possibility to do any of this depends on the number of different locations in the problem you are about to solve. The feasibility of using any of the above strongly depends on other factors, like how expensive to calculate it, how many iterations Jsprit will do, what are the mutation parameters of the algorithm.

But as a main rule: if distance calculation is static (doesn’t depends on any solution parameters) and not extremely fast, it is always the caching is the best solution.