# \[AMPL 24505\] AMPL beginner

**URL:** <https://discuss.ampl.com/t/ampl-24505-ampl-beginner/356>\
**Category:** Google Group Mirror\
**Created:** [February 2, 2023, 5:21pm UTC](https://discuss.ampl.com/t/ampl-24505-ampl-beginner/356 "2023-02-02T17:21:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jesus\_Pascual](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@Jesus\_Pascual](https://discuss.ampl.com/u/Jesus_Pascual)\
**Post date:** [February 2, 2023, 5:21pm UTC](https://discuss.ampl.com/t/ampl-24505-ampl-beginner/356/1 "2023-02-02T17:21:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![4er](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/4er/32/530_2.png) [@4er](https://discuss.ampl.com/u/4er)\
**Post date:** [February 2, 2023, 10:42pm UTC](https://discuss.ampl.com/t/ampl-24505-ampl-beginner/356/2 "2023-02-02T22:42:49Z")

</div>

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:

```auto
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](https://ampl.com/wp-content/uploads/Chapter-6-Compound-Sets-and-Indexing-AMPL-Book.pdf#page=10) in the [AMPL book](https://ampl.com/learn/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.

---

<div class="post-metadata">

**Author:** ![AMPL\_Google\_Group](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@AMPL\_Google\_Group](https://discuss.ampl.com/u/AMPL_Google_Group)\
**Post date:** [February 3, 2023, 4:37pm UTC](https://discuss.ampl.com/t/ampl-24505-ampl-beginner/356/3 "2023-02-03T16:37:46Z")

</div>

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](https://ampl.com/wp-content/uploads/Chapter-6-Compound-Sets-and-Indexing-AMPL-Book.pdf#page=10) in the [AMPL book](https://ampl.com/learn/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.

---

<div class="post-metadata">

**Author:** ![Jesus\_Pascual](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@Jesus\_Pascual](https://discuss.ampl.com/u/Jesus_Pascual)\
**Post date:** [February 8, 2023, 5:41pm UTC](https://discuss.ampl.com/t/ampl-24505-ampl-beginner/356/4 "2023-02-08T17:41:12Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![AMPL\_Google\_Group](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@AMPL\_Google\_Group](https://discuss.ampl.com/u/AMPL_Google_Group)\
**Post date:** [February 9, 2023, 2:02pm UTC](https://discuss.ampl.com/t/ampl-24505-ampl-beginner/356/5 "2023-02-09T14:02:13Z")

</div>

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.
