Search code examples
javaxmljsprit

Jsprit outputing and Saving variables


Is there a way to obtain the output/store results in variables other than outputting solutions to an xml file using vrpxmlwriter?

I tried to get the results with dom parser, xpath and family and can proudly say that I made a complete mess!! Common Jsprit team you've made this beautiful piece of art, why couldn't you provide us with functions like bestSolution.getAllVehicles() ??

If i'm wrong please correct me.


Solution

  • Judging only from the source code, shouldn't you be able to easily extract all the vehicles from the bestSolution instance?

    Assuming bestSolution is of type VehicleRoutingProblemSolution, I'd expect something like this to work:

    Collection<VehicleRoute> routes = bestSolution.getRoutes();
    Set<Vehicle> allVehicles = routes
        .stream()
        .map(VehicleRoute::getVehicle)
        .collect(Collectors::toSet());
    

    It seems like VehicleRoutingProblemSolution contains a lot of information and you are inetersted in a specific projection/subset of this information. Since there are clearly a lot of such subsets, I think it quite reasonable that the API does not provide all of them.