Gurobi in yalmip

165 views
Skip to first unread message

Isadora Bejarano Salinas

unread,
Aug 21, 2021, 4:18:01 PM8/21/21
to YALMIP
Hello, I have a problem, I expect someone help me. 
I want to found a solution of my problem faster, so, that´s why I introduced Gurobi in Matlab and now Yalmip can call to Gurobi as a upper and lp solver when I am using 'bmibnb'.
The problem is that it isn´t faster when I try with gurobi as a solver or not. But, I tried to call Gurobi as a solver like  sdpsettings('solver','gurobi') but Yalmip say that Gurobi not support polynomial constraints, so, that´s mean that I need to change all my program and I don´t want to do that because I have done it since 6 months ago and change it implies to take much more time. 
How can I solve this or make it faster?

Johan Löfberg

unread,
Aug 22, 2021, 2:08:24 AM8/22/21
to YALMIP
Polynomial hence gurobi simply cannot be used. It is for mixed-integer SOCP-representable problems

Not much can be said without the actual model. If you want a global solution, your options are bmibnb, baron, scip

Isadora Bejarano Salinas

unread,
Aug 23, 2021, 2:53:50 PM8/23/21
to YALMIP
My problem is a MINLP problem with polynomial constraints. 
BMIBNN is a great solver but actually, it is not the faster. 
Of the solvers that you mention, which one do you think is the fastest to solve the type of problem that I mention?
And, how can I install it into Yalmip?
Thanks a lot

Isadora Bejarano Salinas

unread,
Aug 23, 2021, 3:02:19 PM8/23/21
to YALMIP

this is my model if you have a chance to see it, please!!
OPF_ver_YALMIP_BINVAR_39nodos.zip

Johan Löfberg

unread,
Aug 23, 2021, 3:04:43 PM8/23/21
to YALMIP
MINLP is much much (much) harder than the problem classes you can solve using gurobi.

Supported global MINLP solvers are baron and scip in YALMIP (in addition to bmibnb)

You can also convert it to quadratics if you want to use the global nonconvex quadratic solver of gurobi, i.e. replace x^6 with u^2 and u == x*y,  y == x^2 etc. Any polynomial model can be reduced to a set of quadratics that way. Unless it is a very simple model, it will grow very large quickly though

Johan Löfberg

unread,
Aug 23, 2021, 3:11:29 PM8/23/21
to YALMIP
I would not hold my breath trying to solve that using off-the-shelf solvers

and there is a bug
constraints_1 = [ Pfv(1,1)  -Pl(1,1) - ((((VP(nb+1,1))^2)*Gkk(1,1)+VP(nb+1,1)*VP(nb+2,1)*(Gkm(1,1)*cos(VP(1,1)-VP(2,1))+Bkm(1,1)*sin(VP(1,1)-VP(2,1))))+...
                                    (((VP(nb+1,1))^2)*Gkk(2,1)+VP(nb+1,1)*VP(nb+39,1)*(Gkm(2,1)*cos(VP(1,1)-VP(39,1))+Bkm(2,1)*sin(VP(1,1)-VP(39,1)))) + (( Pbat(1,1)/MVAb))*h(1,1) ) == 0];


you mean
constraints_1 = [ Pfv(1,1)  - Pl(1,1) - ((((VP(nb+1,1))^2)*Gkk(1,1)+VP(nb+1,1)*VP(nb+2,1)*(Gkm(1,1)*cos(VP(1,1)-VP(2,1))+Bkm(1,1)*sin(VP(1,1)-VP(2,1))))+...
                                    (((VP(nb+1,1))^2)*Gkk(2,1)+VP(nb+1,1)*VP(nb+39,1)*(Gkm(2,1)*cos(VP(1,1)-VP(39,1))+Bkm(2,1)*sin(VP(1,1)-VP(39,1)))) + (( Pbat(1,1)/MVAb))*h(1,1) ) == 0];


note spaces

[1 -1 - 2]

vs

[1 - 1 - 2

Johan Löfberg

unread,
Aug 23, 2021, 3:25:17 PM8/23/21
to YALMIP
your model is not polynomial (it involves trigonometric). hence a reduction of quadratics is not possible and thus gurobi completely out of the picture

in fact, neither baron nor scip support trigonometrics, so those are out too

So to summarize, the only solver possible bmibnb, and the model is simply way beyond what is solvable today (with bmibnb and most likely any other solver had they supported trigs)

måndag 23 augusti 2021 kl. 21:02:19 UTC+2 skrev 1153...@umich.mx:

Isadora Bejarano Salinas

unread,
Aug 23, 2021, 3:31:14 PM8/23/21
to YALMIP
pfff...... :(

Isadora Bejarano Salinas

unread,
Aug 23, 2021, 3:32:39 PM8/23/21
to YALMIP
bmibnb has been trying to solve for 5 days and 5 nights :(

Isadora Bejarano Salinas

unread,
Aug 23, 2021, 3:38:58 PM8/23/21
to YALMIP
Do you think that the mistake of the spaces on my constraints is also the reason of the large time??

PS. I did a study case of 9 buses system with the same methodology. Now the system is bigger, and the time too. :(
Do you advice me  waiting for the time that bmibnb requires for the simulation?

Johan Löfberg

unread,
Aug 23, 2021, 3:42:54 PM8/23/21
to YALMIP
I would not expect it to terminate any day (month or year) soon

But then again, you have to look at the log, if it finds something reasonable (what ever reasonable is, but say with 10% gap) you should consider your self lucky and settle with that

You are branching in a 274-dimensional space. Here is a story about branching in a simple binary space (yours is much harder)

Isadora Bejarano Salinas

unread,
Aug 23, 2021, 6:09:50 PM8/23/21
to YALMIP
I have some extra doubts.
1. Why, even though I write better initial conditions on my model, I still have the same time and gap results?
2. You mean no solver that Yalmip can call? or no solver in general?

Johan Löfberg

unread,
Aug 24, 2021, 12:24:12 AM8/24/21
to YALMIP
even if you assign the globally optimal solution, it can take just as long, as a global solver can struggle to close the optimality gap. indeed, rather often,  finding a good or even the optimal solution is simple but the struggle is to tighten the lowerbound. if you see the examples here https://yalmip.github.io/tutorial/globaloptimization/ you see many have the globally optimal solution in the root

I don't know of any solver besides bmibnb (but there are probably some). baron is the benchmark minlp solver, but does not support trigs

Johan Löfberg

unread,
Aug 24, 2021, 12:39:41 AM8/24/21
to YALMIP
and you should probably remove the unnecessary continuous*binary P*h that you have in the model. as it just adds extra nonconvexity

i.e. replace P*h with a new variable z and the linear big-M constraints [-M*(1-h) <= z-P <= M*(1-h), -M*h<=-P<= M*h]

Isadora Bejarano Salinas

unread,
Sep 3, 2021, 1:06:42 PM9/3/21
to YALMIP
Hi again!!
I've been trying different simplifications: 1. I made a variable change in my constraints, I replaced my quadratic variables with a vector of auxiliary variables Vaux, however, this did not improve my times at all. You can see the attached zip file.

OPF_ver_YALMIP_consimplificaciion5_cambio_de_variable.zip

Isadora Bejarano Salinas

unread,
Sep 3, 2021, 1:09:27 PM9/3/21
to YALMIP
2. Also, in one more of my attempts, I did a simplification, removing my trigonometric functions (simplification that is possible based on previous studies), but now my model has become infeasible. What else can I do? Thank you very much teacher.
OPF_ver_YALMIP_consimplificaciion6_cambio_de_variable_sin_trig.zip

Johan Löfberg

unread,
Sep 3, 2021, 1:13:21 PM9/3/21
to YALMIP

Johan Löfberg

unread,
Sep 3, 2021, 1:22:57 PM9/3/21
to YALMIP
solving a polynomial nonconvex program branching in R^234-dimensional space can take longer than the age of the universe to finish. you have a local solution rather quickly though, so unless you can create a good model you should be happy with this

Isadora Bejarano Salinas

unread,
Sep 3, 2021, 5:11:24 PM9/3/21
to YALMIP
what do you mean with that  local solution and how do you know?

Johan Löfberg

unread,
Sep 4, 2021, 2:23:22 AM9/4/21
to YALMIP
fmincon (and most other nonlinear solvers) is a local solver

Isadora Bejarano Salinas

unread,
Sep 21, 2021, 9:22:33 PM9/21/21
to YALMIP
Dear Johan Löfberg   
I have been applying your advice in order to relax my square variables, besides I have done an additional simplification at the moment to approximate trigonometric functions. However, there is a unique row in one of my constraints, which causes my system becomes an infeasible problem.
I would like to know if there is a way to show the value of the iterations during the process and not only the value of the objective function. Thank you in advance.
Best regards,
Isadora Bejarano

Isadora Bejarano Salinas

unread,
Sep 21, 2021, 9:23:32 PM9/21/21
to YALMIP
PD. I have considerable improvements in gap and time

Johan Löfberg

unread,
Sep 22, 2021, 1:25:03 AM9/22/21
to YALMIP
no
Reply all
Reply to author
Forward
0 new messages