Inquiry for multidimensional data

Hi supoort team! I tried to define a 3-dimensional parameter and I referred to the documentation (https://ampl.com/wp-content/uploads/Chapter-9-Specifying-Data-AMPL-Book.pdf) and decided to specify the values in two-dimensional slices following page 157 param cost.

I defined the param in .mod file as param tilde_invest{k in K,i in I, t in T}; ( I believe I have clarified K, I, T in the file and data file)

However, I received this error tilde_invest[22.2,1,3] already defined. I think 22.2 should be an element ( it’s the second element of one row) instead of an index and I am not sure what caused this problem. I attached the screenshot of my param.


I used the excel and CSV files to help store my data and paste it directly to the .dat file. I don’t know if this causes this problem. Looking forward to hearing your advice.

The usual cause of this kind of error is a missing number. Line 23 under [*,*,3] should consist of 23 followed by 20 data values. But if that line has only 19 data values, then AMPL will go to the next line and read 24 as the 20th value, and everything will be off by one after that.

If you can’t see a missing number in line 23, then to get more help, upload the whole data file (by clicking on Discourse’s upload icon).

(If you will be reading a lot of spreadsheet files, you may also want to check out the amplxl plugin for .xlsx spreadsheet files, or the amplcsv plugin for .csv files.)

1 Like

Thank you for your reply! I checked the original CSV file and believe there is no missing number. I uploaded the .dat file and I see that the format is a bit messy after [,,3], which might cause the problem. While I haven’t found the exact problem and am not sure whether it’s handy to use amplcsv plugin based on the current data format. ( I have the data store exactly what I have here in the .dat file for each parameter.)

test_1.dat (168.7 KB)

The file does look right when I view it in a plain-text editor. But when I take a closer look in a hex editor (I use HxD for Windows) I see something wrong: in the line that begins [*,*,3], the : character is represented by 3 unicode bytes EF BC 9a (which represent something called a “fullwidth colon”):

image

These 3 bytes need to be replaced by the single byte 3A that represents : in ASCII code. The same problem occurs in several other lines. One way to fix it is to use a plain-text editor to delete and replace 20 := in every line where it appears.

1 Like

Thank you so much for checking the file and providing clear instructions! It’s now solved!