Hi,
I wonder if there is any way to do the easy calculation after I got the optimal solution.
For example,
I would like to use the optimal solution values (e.g., X(1), X(2), … X(1000)) to calculate some other quantity (e.g., variance of X(1), X(2), … X(1000)).
This is just a calculation that uses the optimal solution, and its calculation does not have to be included in the objective function or constraint.
I can do it by adding the formula to the formulation as a constraint, but this will make the problem non-linear and the constraints more complicated.
I am wondering if there is any way to solve it in a simple way.
Outside of a solve statement, a variable is similar to a parameter. You can assign to it, display it and use it in calculations. For example:
setting a level value is good practice for nonlinear models
x.L(i) = X0(i);
now solve a model - this changes the value of x
solve m using nlp min z;
now do some computation
scalar mu ‘mean’;
mu = sum{i, x.L(i)} / card(i);
The GAMS User’s Guide is full of info and is a big read if you go cover to cover, but you should at least digest the Rosenthal tutorial fully. That is not long at all and gives a big-picture idea of how it all works, so that you know about levels and such and that you can do computations with GAMS symbols outside of a model.