[AMPL 2834] "Dynamic" constraints

View: New views
2 Messages — Rating Filter:   Alert me  

[AMPL 2834] "Dynamic" constraints

by ruf@donax.ch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hello,

I have created a large generic model with many variables and
constraints. Depending on the input data, some additional constraints
may exist. They are of this type:

# Constraints
subject to Eqs_solve_l{e in Equations}:
        sum {t in EqTermsOfEquations[e]} EqTs_Coeff[t]*EqTs_Var[t]  <= Eqs_Rht
[e];

where EqTs_Coeff is a scalar coefficient, Eqs_Rht is the right hand
term of the equation and EqTs_Var is a reference to a variable in the
model. Since the name of the variable to constrain depends on the
input data, I cannot know in advance its name and hardcode it in the
constraint. So, it would be nice to store it in EqTs_Var parameter,
like this:

set Equations := eq1;
set EqTerms := eqt1 eqt2;
set EqTermsOfEquations[eq1] := eqt1 eqt2;

param Eqs_Rht:=
        eq1  0;

param EqTs_Coeff :=
        eqt1 2
        eqt2 5;

param EqTs_Var :=
        eqt1 "Units_Mult[cooling]"
        eqt2 "Stream_Flow[cooling2]"

So, when specifying my data, i can directly create my additional
constraints.

But, when trying the above code, I obtain the following (expected)
message :

can't convert EqTs_Var['eqt1'] = 'Units_Mult[EI_equations_cooling]' to
a number.

Is there a way to create such "dynamic" constraints or shall I create
the constraints model explicitly for each data set?

Thank you

Raffaele

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to ampl@...
To unsubscribe from this group, send email to ampl+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---


[AMPL 2837] Re: "Dynamic" constraints

by Paul A. Rubin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Sep 18, 4:25 am, "r...@..." <r...@...> wrote:

> Hello,
>
> I have created a large generic model with many variables and
> constraints. Depending on the input data, some additional constraints
> may exist. They are of this type:
>
> # Constraints
> subject to Eqs_solve_l{e in Equations}:
>         sum {t in EqTermsOfEquations[e]} EqTs_Coeff[t]*EqTs_Var[t]  <= Eqs_Rht
> [e];
>
> where EqTs_Coeff is a scalar coefficient, Eqs_Rht is the right hand
> term of the equation and EqTs_Var is a reference to a variable in the
> model. Since the name of the variable to constrain depends on the
> input data, I cannot know in advance its name and hardcode it in the
> constraint. So, it would be nice to store it in EqTs_Var parameter,
> like this:
>
> set Equations :=        eq1;
> set EqTerms :=  eqt1 eqt2;
> set EqTermsOfEquations[eq1] :=  eqt1 eqt2;
>
> param Eqs_Rht:=
>         eq1  0;
>
> param EqTs_Coeff :=
>         eqt1 2
>         eqt2 5;
>
> param EqTs_Var :=
>         eqt1    "Units_Mult[cooling]"
>         eqt2    "Stream_Flow[cooling2]"
>
> So, when specifying my data, i can directly create my additional
> constraints.
>
> But, when trying the above code, I obtain the following (expected)
> message :
>
> can't convert EqTs_Var['eqt1'] = 'Units_Mult[EI_equations_cooling]' to
> a number.
>
> Is there a way to create such "dynamic" constraints or shall I create
> the constraints model explicitly for each data set?
>

If you put all your variables in one array (var Var {1..nvars}) and
create an _ordered_ set VARS containing all your variable names, then
you can use ord('Units_Mult[cooling]', VARS) to get the index of the
Units_Mult[cooling] variable, and use that index to pick the correct
member of Var[].  If "cooling" is itself an index (meaning there's a
Units_Mult[cooling2], Units_Mult[warming], etc. lurking around),
you'll either have to store the name of every possible version in the
VARS set or make Var two-dimensional and use a similar trick to get
the second index.  There are probably other approaches as well.

/Paul
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to ampl@...
To unsubscribe from this group, send email to ampl+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---