[AMPL 24863] Unsolved syntax error

Good afternoon.
I´ve spent some time trying to fix this error but cannot find the way nor the reason.

Here´s the code from the .dat

table listaAristas IN “amplxl” “Pruebadat.xlsx” “Aristas”: L ← [Ol, Dl], Pl, xl;
read table listaAristas;

table listaOrigenaristas {L} IN “amplxl” “Pruebadat.xlsx” “Aristas”: Ol ← [Ol];
read table listaOrigenaristas;

The system easily reads table listaAristas, but when it gets to read listaOrigenaristas, it says:

syntax error
context: table listaOrigenaristas {L} IN “amplxl” “Pruebadat.xlsx” “Aristas”: Ol >>> ← <<< [Ol];

Thank you in advance,
Gonzalo R

There are some issues with the table listaOrigenaristas, and I do not think that a table statement like it can give the result that you want. However, it is not entirely clear what you are trying to achieve with this table.

Can you give a small example? Your example should include the following:

  • Some data values as they would appear in the spreadsheet.
  • A description of what the corresponding members of the sets Ol, Dl, and L should be, after the “read table” statements are executed.
    Also, attach all of the files that you used in the run that led the the “syntax error” message.

Please find attached the .mod, .dat, and the excel with the data.

On the .dat you´ll find that the table “listaGeneradoresaN” and table “listaDestionaristas” are written as comments yet, because they were giving the same problem as “listaOrigenaristas”.

The intention of all of these three tables is to: define a set of generators connected to a specific node (listaGeneradoresaN); define a set of nodes which are the origin of a line L (listaOrigenaristas); and define a set of nodes which are the destination of a line L (listaDestinoaristas). “listaGeneradoresaN” may be more complicated because it´s a 2D table, but the other two are simple columns which are in fact easily accepted in the table “listaAristas”.

Thank you again,
Gonzalo R

RenesesMP.dat (688 Bytes)

(Attachment Pruebadat.xlsx is missing)

RenesesMP.mod (5.33 KB)

You defined “set Jn {N} within J;” so you need to write

table listaGeneradoresaN {n in N} IN "amplxl" "Pruebadat.xlsx" "Generadores": Jn[n] <- [Jn];

However, this will give you all the same members in every set Jn[1], Jn[2], etc.:

ampl: display Jn;
set Jn[1] :=
1 3 5 7 9  11 13 15 17 19 21 23 25 27 29 31
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32;
set Jn[2] :=
1 3 5 7 9  11 13 15 17 19 21 23 25 27 29 31
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32;
set Jn[3] :=
1 3 5 7 9  11 13 15 17 19 21 23 25 27 29 31
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32;

Is that what you want?

You can try a similar modification to listaOrigenaristas,

table listaOrigenaristas {(o,d) in L} IN "amplxl" "Pruebadat.xlsx" "Aristas": Ol[o,d] <- [Ol];

but you will get this error message:

Error reading table listaOrigenaristas[1,2] with table handler amplxl:
AddRows: duplicate subscript [1]

That is because the number 1 is repeated several times in column Ol of the spreadsheet, but a number can appear only once in a set. Instead of trying to read the Ol sets from the spreadsheet, you can define them in the model; replace “set Ol {L} within N;” by

set Ol {L} = setof {(o,d) in L} o;

(and remove the references to table listaOrigenaristas in your data file). However, this will assign all the same members to Ol[1,2], Ol[1,3], Ol[1,5], Ol[2,4], etc. – and I am not sure that is what you want.

Hello and thank you for your attention, I really appreciate it.

Regarding the table “listaGeneradoresaN” as you said I´m not getting what I want. The idea for it is to show the generators connected to each node by reading the binary table “Jn” on the excel. Each node is the head of each column, and each generator is the head of each line. Is there anyway to get this loaded?

For the table “listaOrigenaristas” I think I´d do better by just creating the whole set on the .dat, since as you said both of those options aren´t really giving what I´m looking for (which again is simply define a column with the origins of the lines).

Gonzalo R

I guess Jn[n] is the set of generators at node n. But I am not sure how to get the data for Jn[n] from your binary table. There seem to be 24 nodes, but the binary table has 38 rows.

Can you give some examples? For the spreadsheet that you attached to your previous message, what should be the members of Jn[1], Jn[2], Jn[3], . . . ? You answer should look like

Jn[1] = {1}
Jn[2] = { }
Jn[3] = {3,4}
. . . . . . .
Jn[24] = {1,2,3}

except that the correct values are probably different from what I am showing here.

You´re pretty close to it. So I have 24 nodes and 32 generators.

Jn(1)= 1,2,3
Jn(2)= 5,6,7,8

Now I see the binary table (beginning in column Q). You can read in that table, and then compute the Jn sets from it. You’ll need to define a new range in the spreadsheet that contains just columns R through AP and rows 2 through 34 – let’s call that range GeneradoresNodos. Then replace “set Jn {N} within J;” by

param GenNod {J,N} binary;
set Jn {n in N} = {j in J: GenNod[j,n] = 1};

Then all you have to do is read the binary table into GenNod, and the sets Jn[n] will be computed automatically. The following table statement will read the binary table into GenNod:

table listaGeneradoresaN IN "amplxl" "..\Pruebadat.xlsx" 
   "GeneradoresNodos" "2D": [Jn,N], GenNod;
read table listaGeneradoresaN;

The “2D” in the table statement identifies this as a two-dimensional spreadsheet table, as explained in the section “Learning more” at https://plugins.ampl.com/amplxl.html.

It worked perfectly, thank you so much again!!!

Good morning again.

After solving many of the problems I initially asked you with some of your tips, I have encountered another one.
What I´m trying to do right now is to load a series of attack vectors. The method I´m following is pretty similar to the one you showed me to declare the set of Generators connected to nodes (Jn), by using a binary 2D table.

Loading the table isn´t apparently a problem, the thing is that afterwards I need to declare a set of lines that are attacked (Lalpha) and a set that are not attacked (Lbeta), and AMPL shows a syntax error even after trying different methods.

K is a set of attack options. Vl is a set of attack vectors, each one containing a series of lines which are attacked (=1) or not attacked (=0). For example let´s say that Vl (3) is =1 for lines (1,2), (1,3) and (21,23) and =0 for the rest of lines. Therefore, Lalpha (3) would be the rest of lines, and Lbeta(3) would be (1,2), (1,3) and (21,23).

Would you have any clues about it?
Thank you beforehand once again.

You are getting an error on “Vl[i] = 0” – because Vl[i] is defined as a set in your model. It is not possible to test whether a set equals a number. Maybe you do not need Vl; instead you could define Lalpha and Lbeta directly in terms of VectAtaq like this:

param VectAtaq {L,K} binary;
set Lalpha {i in K} := {(o,d) in L: VectAtaq[o,d,i] = 0};
set Lbeta {i in K} := {(o,d) in L: VectAtaq[o,d,i] = 1};

Once again, worked perfectly.

Thank you for your support,