Two convex problems one inside the other

I have a problem that can be decoupled into two problems: one is a master problem and one is a subproblem. These two problems are convex. How can I handle this situation?

I used the following code:

cvx_begin
variable x,y

 cvx_begin
         variable u
         mininze(f1(u,x,y))% here x,y are assumed constant but the issues cvx assumes them real affine
 cvx_end

 mininze(f1(u,x,y)+f2(u,x,y))

cvx_end

Does this do what you want?
“New functions via partially specified problems”

1 Like

No it dose not: I will end up with this issue
{real affine} .* {convex}

Even if use function, the function keeps all variables as convex variables and does not assume any of them constant.

Can I convert the real affine to constant to by used to calculate the objective function?

At this point, the description of your problem is too vague. Can you show us the complete detailed mathematics of your proleml, making clear what are input data and what are optimization (a.k.a. decision) variables? And show us your complete code, including for the partially specified optimization.

But first:

Have you tried to implement the examples in the link, and then tried to modify them to ensure your understanding of how partially specified optimization works?

Or: Do you really have a bilevel optimization problem? If so, look at Bi-level programming in CVX .

Your help is appreciated!

The main code is as follows:

Load=given
PV=given

cvx_begin
variables Cap N_PV;

    u=find_u(Cap, N_PV); the function is given below
    battery= 1000*Cap*u
    grid_=Load'+battery-N_PV*PV';


    minimize (sum(grid_)+10*max(grid_)+1000*Cap +200*N_PV
    subject to
    Cap>=0
    N_PV>=0
    Cap<=100
    N_PV<=100
    
 cvx_end

the function to find u is as follows:

function cvx_optval =find_u(Cap, N_PV)

global Load
global PV
E0=Cap/2;
L = 0.5*tril(ones(50));

cvx_begin
variables u(50)
*battery= 1000*Cap*u;*
 Es = Cap*L*u;
 grid_=Load'+battery-N_PV*PV';

  minimize sum(grid_)+10*max(grid_)

    subject to
    u <= 0.4;
    u >= -1; 
    Es <= Cap;
    Es >= 0;
    Es(end)>=0.99*Cap;
    
 cvx_end

I was able to decouple the problem and find u using CVX and find Cap and N_PV using another optimization algorithm (for example surrogate optimization or gentic algorithm) but I am interested to see if it can be solved using convex.

If I use the code given above the following error I will get: {real affine} .* {convex}
the equation inside the function (find_u)
battery= 1000*Cap*u
causes the issue which is: u is CVX variable and Cap is the input of the function (find_u) but the function does not deal with Cap as constant since it is obtained by the main code

The first rule of convex optimization is that it is applied to convex optimization problems. Is your problem convex?

At its heart, it appears that battery involves the product of two optimization expressions. Having one of these expressions be the output of a function (find_u) does not change that fundamental fact. Creating a function as you have is not a valid way of skirting CVX’s DCP rules, which your program violates.

I don’t completely understand your problem, so am not 100% ruling out that it can be formulated for CVX. But until you show otherwise, i am assessing it to be non-convex.

1 Like

Thank you for your help.

I assume now the battery = Q instead of battery = Cap*u (Q is CVX variable) and assume the size of the battery Cap is not given and need to be optimized. The Size of the battery will be equal to maximum energy stored in the battery (maximum integral of Q over time). The objective function will take care of that.

Now the problem is convex and I was able to solve the problem and no need to decuple the problem.

Thank you so much