[AMPL 16130] Alternative ways of defining sets/vectors of indices

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[AMPL 16130] Alternative ways of defining sets/vectors of indices

Lorenzo Magnolfi
A simple question on how to define sets/vectors of indices (numbers) that I have not been able to answer using the manual:

For two numbers N1 >N2, I currently define vectors:

param SetKeep {i in 1..N2};
param X { i in 1..N1};

And then use these in the definition of a new variable of dimension N2:

var XI { h in 1..N2} = X[SetKeep[h]];

How can I define SetKeep differently to be able to define my variable directly as:

var XI { h in SetKeep} = X[SetKeep];?

Can I do it without touching my .dat file (where SetKeep is defined as param)? If not, what's the syntax I need to use to define the set?


Thanks for your help.

-L

--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [AMPL 16130] Alternative ways of defining sets/vectors of indices

AMPL mailing list
If the members of SetKeep are unique, then you could use set to define SetKeep as follows:

set setKeep :={1,2,3};
param X { setKeep};
var XI{h in setKeep}:=X[h];

data;
param X := 1 4 2 5 3 2;

Thanks,
Paras



--
Paras Tiwari
[hidden email]
{#HS:558440862-4886#}
On Tue, Apr 10, 2018 at 4:20 PM UTC, Zeyad Kassem' Via Ampl Modeling Language <[hidden email]> wrote:
A simple question on how to define sets/vectors of indices (numbers) that I have not been able to answer using the manual:

For two numbers N1 >N2, I currently define vectors:

param SetKeep {i in 1..N2};
param X { i in 1..N1};

And then use these in the definition of a new variable of dimension N2:

var XI { h in 1..N2} = X[SetKeep[h]];

How can I define SetKeep differently to be able to define my variable directly as:

var XI { h in SetKeep} = X[SetKeep];?

Can I do it without touching my .dat file (where SetKeep is defined as param)? If not, what's the syntax I need to use to define the set?


Thanks for your help.

-L

--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.



--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.