[AMPL 25008] doubt writing the code

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

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

so that S is not equal to N.

Can you help me? Thanks !! :slight_smile:

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:

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.

Your question has been moved to our new user forum at 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

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