I tried to figure it out every time I have to solve problem with data matrix, but I haven’t been able to figure it out.
I have two sets in the assignment problem, one for depot (garaz on the picture) and customer (Michle, Prosek, Radlice, Troja), and distances between them in sheet named distance like this:
Until now I had separate sheet for each set and the one for data matrix, but I wonder if there is a way to read all the information at once, a way to say to AMPL: set depot is in the first column, set customer is in the first column and numbers are param distance.
The “read table” statement cannot read a 2-dimensional data table and also two 1-dimensional sets at the same time. However, it is possible to read a 2-dimensional data table and also its 2-dimensional index set at the same time; and the AMPL model can create the needed 1-dimensional sets:
set DepCust dimen 2;
set Depots = setof {(i,j) in DepCust} i;
set Customers = setof {(i,j) in DepCust} j;
param distances {Depots,Customers} >= 0;
table disttab IN "amplxl" "garaz.xlsx" "2D":
DepCust <- [garaz,cust], distances;
read table disttab;
You can try this out with the attached files. The output that you will see is as follows: