How to pass Cost Matrix Using CSV/JSON file in bulk for production

Sorry if this question is already been answered as I’m new to jsprit. I found in jsprit, for passing the cost matrix it is hardcoded into it like:

    VehicleRoutingTransportCostsMatrix.Builder costMatrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true);
        costMatrixBuilder.addTransportDistance("0", "1", 10.0);
        costMatrixBuilder.addTransportDistance("0", "2", 20.0);
        costMatrixBuilder.addTransportDistance("0", "3", 5.0);
        costMatrixBuilder.addTransportDistance("1", "2", 4.0);
        costMatrixBuilder.addTransportDistance("1", "3", 1.0);
        costMatrixBuilder.addTransportDistance("2", "3", 2.0);

        costMatrixBuilder.addTransportTime("0", "1", 10.0);
        costMatrixBuilder.addTransportTime("0", "2", 20.0);
        costMatrixBuilder.addTransportTime("0", "3", 5.0);
        costMatrixBuilder.addTransportTime("1", "2", 4.0);
        costMatrixBuilder.addTransportTime("1", "3", 1.0);
        costMatrixBuilder.addTransportTime("2", "3", 2.0);

How it can be generalized into production? like by passing the matrix with CSV/JSON or anything in bulk. What is the best approach to pass this information dynamically? Also what can be the best method to calculate and get this cost matrix using any api or open-source?

Any code sample or example would be a great help.

Not sure I understand, but the basic idea is to just call those methods (addTransportDistance(), addTransportTime()) based on the values read from your CSV/JSON file.

Powered by Discourse