[AMPL 24505] AMPL beginner

HI! I am starting to use AMPL and I am having syntax problems when setting up the sets.

I need to use a set called “PI”, with “P” being reload points and “I” being the resources I have to get to “P”.

I have tried to write it as:

set PP { I } within P;

If someone could help me write the correct notation I would appreciate it.

Thanks.

1 Like

Are you trying to define sets like these?

  • P is the set of reload points
  • I_all is the set of all resources
  • I[p] is the subset of resources that you have to get to reload point p

Then the AMPL definitions should be as follows:

set P;
set I_all;
set I {P} within I_all;

Here I is an “indexed collection of sets”. To learn more, see our introduction in section 6.5 Indexed collections of sets in the AMPL book.

If you are looking for something different, can you give a small example? Using just a few resources and reload points, list the sets that you would want to create, and the members that each set should have.

1 Like

Are you trying to define sets like these?

  • P is the set of reload points
  • I_all is the set of all resources
  • I[p] is the subset of resources that you have to get to reload point p
    Then the AMPL definitions should be as follows:

set P;
set I_all;
set I {P} within I_all;

Here I is an “indexed collection of sets”. To learn more, see our introduction in section 6.5 Indexed collections of sets in the AMPL book.

If you are looking for something different, can you give a small example? Using just a few resources and reload points, list the sets that you would want to create, and the members that each set should have.

Thank you very much for your help.

Now I am having problems with the definition of the constraints, as I am getting syntax errors.

This is the line which is failing:

subject to CONSTRAINT2 {g in G, p in P, k in K}:
sum {i in I, g in GG[i], p in PP[i]} a[i, p, k]<= NUI[g, p, k];

This is the message I recieve when I run it:

syntax error
context: sum {i in I, g >>> in <<< GG[i], p in PP[i]} a[i, p, k]<= NUI[g, p, k];
ampl:

And the sets I have for the exercise is the following:

set I;
set G;
set P;
set K;
set PP{I} within P;
set GG{I} within G;

If someone could help me I would apreciate a lot.

Thanks!

In the indexing expression for CONSTRAINT2, you define the index “g”:

subject to CONSTRAINT2 {g in G, ...

But then, in the indexing expression for the summation in the constraint, you also define “g”:

sum {i in I, g in GG, ...

You are seeing the “syntax error” message because it is not permitted to redefine an index like “g” in a place where it is already defined. (Admittedly, the error message could be more informative.)

Probably the summation needs to be fixed, but I cannot say anything more definite, as I do not know how your model defines a and NUI.