See "Automatic substitution of variables" on pages 399-400 of the AMPL book.
This feature is more general than writing "var y {i in OUTCOMES} = ... ;". To
use it, try setting "option substout 1;" before solving.
As an example, consider your simple problem with some objective function added:
set OUTCOMES;
set SOME_SET;
data;
set OUTCOMES := foo bar;
set SOME_SET := wilma fred;
model;
var x {SOME_SET};
var y {OUTCOMES};
minimize obj: sum {i in OUTCOMES} (y[i]-1) ^ 2;
subj to Some_Constraint_1:
y["foo"] = 21*x["wilma"] - 11*x["fred"];
subj to Some_Constraint_2:
y["bar"] = -9*x["wilma"] - 28 *x["fred"];
Solving with option substout 0, four variables are send to the solver:
ampl: option substout 0;
ampl: solve;
4 variables:
2 nonlinear variables
2 linear variables
2 constraints, all linear; 6 nonzeros
1 nonlinear objective; 2 nonzeros.
MINOS 5.5: optimal solution found.
4 iterations, objective 0
Nonlin evals: obj = 8, grad = 7.
ampl: display x; display y;
x [*] :=
fred -0.0436681
wilma 0.0247453
;
y [*] :=
bar 1
foo 1
;
Solving with option substout 1, only two variables (the x-variables) are sent
to the solver:
ampl: option substout 1;
ampl: solve;
Substitution eliminates 2 variables.
Adjusted problem:
2 variables, all nonlinear
0 constraints
1 nonlinear objective; 2 nonzeros.
MINOS 5.5: optimal solution found.
4 iterations, objective 1.972152263e-31
Nonlin evals: obj = 9, grad = 8.
ampl: display x; display y;
x [*] :=
fred -0.0436681
wilma 0.0247453
;
y [*] :=
bar 1
foo 1
;
Similar results are achieved when some of the expressions for the y-variables
are nonlinear.
Bob Fourer
4er@...
> -----Original Message-----
> From:
ampl@... [mailto:
ampl@...] On Behalf Of Jacob
> JKW
> Sent: Thursday, June 19, 2008 6:36 AM
> To: AMPL Modeling Language
> Subject: [AMPL 1841] Defining declarations on subscripted variables
>
>
> So this this is a simplified version of what I have:
>
> ###########START###########
> model;
> reset;
>
> set OUTCOMES;
> set SOME_SET;
>
> data;
> set OUTCOMES := foo bar;
> set SOME_SET := wilma fred;
>
> model;
>
> var x (SOME_SET}
> var y {OUTCOMES};
>
> subj to Some_Constraint_1:
> y["foo"] = 21*x["wilma"] - 11*x["fred"];
>
> subj to Some_Constraint_2:
> y["bar"] = -9*x["wilma"] - 28 *x["fred"];
>
> /* more stuff follows */
>
> ###########END###########
>
> Now what I'd like to do is get rid of the two constraints and just add
> them to the declaration of y, but I just can't figure out the proper
> format for doing so.
>
> Obviously if y weren't subscripted I could just write something like
>
> var y = 21*x["wilma"] - 11*x["fred"]
>
> but because of the subscripts I just don't know how to handle it.
>
> As always, my apologies if I've missed this in either the FAQ or the
> AMPL book.
>
>
> Thanks in advance,
> J.
>
--~--~---------~--~----~------------~-------~--~----~
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-~----------~----~----~----~------~----~------~--~---