Is it possible to write a bi-level program in CVX using mathematical programming equilibrium constraints.

That is not a convex problem so no.

YALMIP has some support for Bi-level programming https://yalmip.github.io/tutorial/bilevelprogramming/ .

As discussed in the link, it may be possible to include the KKT conditions for the inner problem into the outer problem. In order to do this in CVX, it would be necessary to handle the KKT conditions, which are non-convex, by use of Big M to handle the (non-convex) complementarity condition. So you would end up with a Mixed Integer formulation, which would require either Gurobi or Mosek as solver, if performed in CVX.

As discussed in the link, the Big M formulation cab be pretty tricky, because you don’t know in advance how big M needs to be. If you pick `M`

too small, you may cut off the solution. If you pick `M`

too large, you may have disastrous numerics, which among other things could result in trickle flow due to solver integrality tolerance allowing the intended logic constraint to be violated. So CVX is probably not the best tool to use.

thanks for your quick response,

I have modeled my bilevel program in CVX. Further, KKT condition has been utilized through Big-M approach to formulate lower level bilevel problem into a single level problem. The code is working fine for small dimensionality. However the issue I am facing my problem is that in lower level decision variable are large matrix, which are aggregated in upper level using a expression assignment. This aggregated expression assignment is used in the objective function. However, the objective function is giving result without including expression assignment value,

After CVX has solved or inaccurate/solved, the CVX variables have their optimal values. But CVX expressions do not necessarily.correspond to the optimal values of CVX variables. CVX makes sure the expressions are properly evaluated for purposes of conducting the optimization and populating cvx_optval, but the numerical values of CVX expressions after CVX completes do not necessarily correspond to the optimal values of the variables. Therefore, you should recompute CVX expression values using the optimal values of CVX variables if you wish to know the optimal values of CVX expressions.

Also, do not forget what I wrote in the last paragraph in my preceding post. Perhaps you get away with a shaky Big M formulation for low dimension problems, and are not faring as well for larger dimension problems.

If that doesn’t resolve your issue, please show your code and exactly what you mean by “the objective function is giving result without including expression assignment value,”.

## Summary

This is code, here CUST is aggregated in CN_LOAD_DRA then subsequently summed up in CN_LOAD, which is being utilized in the objective function. Here my question is that CN_LOAD is giving numerical value in the output, but is not being used in the objective function calculation, why is that so

When DSO_Obj is calculated in

`DSO_Obj=FLAT.UNC_LOAD+FLAT.(CN_LOAD_BASE-CN_LOAD)-MCP.*(CN_LOAD_BASE-CN_LOAD+UNC_LOAD)-CN_LOAD.*INC_RATE;`

the expression `CN_LOAD`

has only been declared, but not otherwise been set. It therefore has the value `0`

at that time, as all CvX expressions do prior to being set. Therefore, relative to the objective function in your problem, the statement `CN_LOAD=sum(CN_LOAD_DRA,1);`

is “for entertainment purposes only”, i.e., has no effect on the optimization problem being solved by CVX. So you need to move the code for calculation of `CN_LOAD`

ahead of where it is used in `DSO_OBJ`

.

But when i putting CN_LOAD above DSO_Obj, it is giving zeros value. In my problem CUST_LOAD is a decision variable, which is being optimized, this CUST_LOAD optimized variable is summed in CN_LOAD_DRA and finally in CN_LOAD. I want to calculate DSO_Obj including CN_LOAD, where CN_LOAD will be treated as constant variable. it is to be noted that I have formulated my problem as tri-level optimization, where in first stage INC_RATE is decision variable, in second stage DRA_INC_RATE and CUST_LOAD third stage variable.

You need to make sure `CN_LOAD_DRA`

is set to what you want prior to using it in `CN_LOAD=sum(CN_LOAD_DRA,1);`

And of course, any other such dependencies.

The order of calculating expressions, or calculating with them, matters. If instead, something is declared as a `variable`

, its order doesn’t matter, and you use constraints instead of expression assignment. Such constraints can appear anywhere in the CVX program, provided that expressions and variables appearing in them have already been declared, and subject to expressions having whatever value they have at that point, to include zero, if the expression has not already been set (assigned).

but in my problem CN_LOAD and CN_LOAD_DRA can not be declared as variable, as I have mentioned in my last post that the decision variables in each stage are INC_RATE, DRA_INC_RATE and CUST_LOAD., where each decision variable being optimized in their stage as tri-level optimization. it is framed as sequential programs

I don’t have the energy or desire to understand your complete optimization problem. Please take my preceding posts into account when arriving at your CVX formulation. With expressions, the order of calculation matters; with variables, it does not.

You probably need to carefully rethink the structure of your problem. Perhaps some of the things you have declared as expressions should instead be declared as variables, with the needed constraints added.

thank you very much for precious time.