Error reading table NodosDesde with table handler amplxl: AddRows: duplicate subscript ['n1']

Hello everyone,

Im trying to read data from Excel in Ampl and I’m facing this error: “Error reading table NodosDesde with table handler amplxl:
AddRows: duplicate subscript [‘n1’]”

This is what im trying to read:

#------------------------------------------------------------------------------

table NodosDesde IN “amplxl” “sistema1.xlsx” “lin”:
FROM ← [FROM];

table NodosHasta IN “amplxl” “sistema1.xlsx” “lin”:
TO ← [TO];

read table NodosDesde;
read table NodosHasta;
let B := FROM union TO;

this is my spreadsheet “lin”

Hope someone can help me :slight_smile:

You are seeing the duplicate subscript ['n1'] error becuase n1 appears more than once in the FROM column. There will be the same problem with the TO column.

It appears however that the pair of FROM and TO nodes in each row of the spreadsheet is unique. So, you can read the set of pairs from the spreadsheet, and use that to define the FROM and TO sets. For example:

set ARCS dimen 2;

table Arcs IN "amplxl" "..\sistema1.xlsx" "pairs":
   ARCS <- [FROM,TO];
read table Arcs;

set FROM = setof {(i,j) in ARCS} i;
set TO = setof {(i,j) in ARCS} j;

set B = FROM union TO;

Here the range pairs should include both the FROM and TO columns of the spreadsheet.