Define a parameter depending on some variables.

304 views
Skip to first unread message

valerio giuseppe sasso

unread,
Oct 2, 2022, 2:01:40 PM10/2/22
to AMPL Modeling Language
I am trying to define a parameter that depends on other parameters and some variables. I know I should use a constraint rather than an assignment. When i declare the parameter in the model, then i add the constraints that should define it, i get the error ' no value for parametername'. Where am i wrong? thank you!

AMPL Google Group

unread,
Oct 3, 2022, 10:32:04 AM10/3/22
to AMPL Modeling Language
In an AMPL model, a parameter cannot be defined to depend on the values of variables. You can define a parameter in your model, and then later assign it a value that depends on the current values of some variables. For example, if your model file has these statements,

var Buy {FOOD} >= 0;
param TotalBuyUnits;

then you can later make an assignment like this:

let TotalBuyUnits := sum {j in FOOD} Buy[j];

As assignment of this kind can be useful after solving, when the current values of the variables are optimal. For instance, you may want to store the optimal value of some expression in a parameter, for convenience in using the value later; or you may want to use optimal values from the current model to set a parameter that appears another model.


--
Robert Fourer
am...@googlegroups.com
{#HS:2026231290-112171#}
Reply all
Reply to author
Forward
0 new messages