How to use Cost Matrix Array from the API response in Jsprit input file pattern

I’m having the distance cost matrix from the Here Maps API where I’m getting it in the below pattern.

    "matrix": {
    "numOrigins": 7,
    "numDestinations": 7,
    "distances": [
        0,
        1371660,
        1095330,
        2398157,
        1863064,
        1057507,
        1509647,
        1417624,
        0,
        2470654,
        3756006,
        862045,
        2434034,
        2469934,
        1104670,
        2479180,
        0,
        1723441,
        2909077,
        463021,
        1844673,
        2399422,
        3709873,
        1713409,
        0,
        4194674,
        1272042,
        1970555,
        1846938,
        853422,
        2899968,
        4239843,
        0,
        2862145,
        3086316,
        1053392,
        2432312,
        452061,
        1273493,
        2857799,
        0,
        1427966,
        1509159,
        2467407,
        1835375,
        1971354,
        3059758,
        1432000,
        0
    ]

How can I use this matrix data and automate it to This format or pickups_and_deliveries_solomon_r101_open.xml or any input format to solve VRP probelm.

In simple terms- How can I use the distance/time cost square matrix input array into jsprit. Is there any code available to automate this task?

Thanks!

You can read file CostMatrixDistance.java in example. It resolve this problem
(sorry, iam lazy)

Vào Th 6, 29 thg 5, 2020 vào lúc 18:59 Rishabh Shrivas via GraphHopper Forum discuss-management@graphhopper.com đã viết:

1 Like

I have also solved a similar problem. I took the distance matrix from GraphHopper down to js. Then use Js to send that matrix to Jsprit. I put Jsprit in a java server. This server receives the matrix and processes it. This is my controller file

Vào Th 7, 30 thg 5, 2020 vào lúc 20:45 Đức Vũ Văn vuvanduc1998realkio@gmail.com đã viết:

HelloController.java (5.76 KB)

@D_c_Vu_Van Thanks for replying. I checked this example but the problem is it is getting done by hard code one by one like this

    costMatrixBuilder.addTransportDistance("1", "3", 1.0);
    costMatrixBuilder.addTransportDistance("2", "3", 2.0);

    costMatrixBuilder.addTransportTime("0", "1", 10.0);
    costMatrixBuilder.addTransportTime("0", "2", 20.0);

In my case its in NxN matrix format which has to be automated for building cost matrix using costMatrixBuilder. I would like to know your opinion on this.

Thanks!

You can save the results received after creating the matrix. Then add each spacing as sample code. I did the same above

You can read it