# \[AMPL 25008\] doubt writing the code

**URL:** <https://discuss.ampl.com/t/ampl-25008-doubt-writing-the-code/1013>\
**Category:** Google Group Mirror\
**Created:** [March 24, 2024, 10:04am UTC](https://discuss.ampl.com/t/ampl-25008-doubt-writing-the-code/1013 "2024-03-24T10:04:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maria\_Vargas\_Magan](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@Maria\_Vargas\_Magan](https://discuss.ampl.com/u/Maria_Vargas_Magan)\
**Post date:** [March 24, 2024, 10:04am UTC](https://discuss.ampl.com/t/ampl-25008-doubt-writing-the-code/1013/1 "2024-03-24T10:04:33Z")

</div>

Hello. I would like to define the subset S contained in N:={1…n} and that S is not equal to N at the same time and I don´t know how to do it. I’ve thought define the restriction

```auto
subject to not_equal_to_N:
   card(S) =! card(N);

```

so that S is not equal to N.

Can you help me? 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:** [March 25, 2024, 7:15pm UTC](https://discuss.ampl.com/t/ampl-25008-doubt-writing-the-code/1013/2 "2024-03-25T19:15:02Z")

</div>

Are the members of S already known, before the optimization problem is sent to the solver? (In other words, is S part of the problem data?) Then you can use an AMPL `check` statement to confirm that S is not equal to N:

```auto
param n > 0;
set N = 1..n;
set S within N;
   check: card(S) < n;

```

If after the data is read, S turns out to be the same as N, then the `solve` command will report an error.

If instead you want the members of S to be determined by the solver, then that is a harder situation. AMPL does not have set-valued variables, so you would have to reformulate the problem — most likely, using n binary (zero-one) AMPL variables. To get more help in this case, you would have to give more details of the problem you are trying to solve.

---

<div class="post-metadata">

**Author:** ![AMPL\_Google\_Group1](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@AMPL\_Google\_Group1](https://discuss.ampl.com/u/AMPL_Google_Group1)\
**Post date:** [March 25, 2024, 7:19pm UTC](https://discuss.ampl.com/t/ampl-25008-doubt-writing-the-code/1013/3 "2024-03-25T19:19:07Z")

</div>

Your question has been moved to our new user forum at [discuss.ampl.com](http://discuss.ampl.com), and a response has been posted. To see the response, use this link:

[https://discuss.ampl.com/t/ampl-25008-doubt-writing-the-code/1013/2](https://discuss.ampl.com/t/ampl-25008-doubt-writing-the-code/1013/2)

To reply, click the red “Reply” button that follows the response. (Do not send an email reply to this message.)
