Defining initial values
Defining initial values
However, with the Python API it seems to be harder to access the level values of variables. My intention with the attached code was to manually define initial values for ALL variables in the model and then solve it multiple times. My rationale was that if the initial point was always the same, the solution would also be the same. However, there are some small changes in the objective function. For the present example, the results of 4 runs are:
Obj: 110.47759190140623,
Obj: 110.47759190141258
Obj: 110.47759190457893
Obj: 110.47759190358889
For this particular minimal example the change is almost negligible, but for my actual complete model it could be as much as 3 orders of magnitude.
Any help in how to change my code to be able to achieve exactly the same result while manually defining the initial conditions will be much appreciated. I am using Gams 31 and its Python Interface, with Python 3.8, but the same problem happens with different versions too.
PS: I apologize for this not-so-minimal MWE. I tried to reproduce this issue with smaller models but when a GamsModifier was used to define the Primal of all variables, the optimization results turned out to be consistently the same.
Re: Defining initial values
You also get different results if you start Conopt from the same point just in plain GAMS:
gives you
and
Don't look at the values but since it does different number of iterations indicates that is takes a different path and hence you might end up with slightly different solutions. You also need to set the dual solution or instruct Conopt to ignore the dual information from of a starting point. This can be done, e.g. by setting bratio (in the GAMS model) to 1: option bratio=1; If I do that I get identical solutions:
-Michael
Code: Select all
y.l('ny1',t) = 54.2249;
y.l['ny2',t] = 397.0828;
y.l['ny3',t] = 0.659;
u.l['nu1',t] = 0.1;
u.l['nu2',t] = 325;
uCont.l['nu1',tCont] = 0.1;
uCont.l['nu2',tCont] = 325;
obj.l = 0;
solve reactor using NLP minimizing obj;
y.l('ny1',t) = 54.2249;
y.l['ny2',t] = 397.0828;
y.l['ny3',t] = 0.659;
u.l['nu1',t] = 0.1;
u.l['nu2',t] = 325;
uCont.l['nu1',tCont] = 0.1;
uCont.l['nu2',tCont] = 325;
obj.l = 0;
solve reactor using NLP minimizing obj;
Code: Select all
31 4 1.1087270812E+02 8.0E+00 7 1.6E+00 6 F T
36 4 1.1047759101E+02 1.2E-05 7 1.0E+00 2 F T
40 4 1.1047759190E+02 4.3E-10 7
** Optimal solution. Reduced gradient less than tolerance.
Code: Select all
46 4 1.1047759190E+02 2.4E-03 7 1.0E+00 2 F T
48 4 1.1047759190E+02 5.6E-10 7
** Optimal solution. Reduced gradient less than tolerance.
Code: Select all
python py_NMPC_Caller.py | grep Obj
Obj: 110.47759190140746
Obj: 110.47759190140746
Obj: 110.47759190140746
Obj: 110.47759190140746
Obj: 110.47759190140616
Obj: 110.47759190140616
Obj: 110.47759190140616
Obj: 110.47759190140616