The issue of obtaining multiple optimal solutions and their corresponding decision variable values.

88 views
Skip to first unread message

llL o0O

unread,
Nov 4, 2023, 6:12:24 AM11/4/23
to YALMIP
Long time no see! dear prof. I still got no clue about my damn paper. Anyway, I got a new problem.
In optimization problems, there seem to be multiple optimal solutions. However, I'm not quite sure how to obtain all optimal solutions and examine the values of decision variables for each of them when using YALMIP + Gurobi.



llL o0O

unread,
Nov 4, 2023, 6:22:33 AM11/4/23
to YALMIP
I just check the " Computing multiple solutions in one shot ". Well , I'm still confused. So I just post my code here:

clc;
clear;
mu_nt = sdpvar(1);
P_ctb_D = sdpvar(1,5);
P_ts_WPH = sdpvar(1,5);
lambda_ts_WPH = sdpvar(1,5);
xi_ts_WPH_min = sdpvar(1,5);
xi_ts_WPH_max = sdpvar(1,5);
xi_ts_WPHsum_min = sdpvar(1);
xi_ts_WPHsum_max = sdpvar(1);
xi_ts_WPH0 = sdpvar(1,5);
B_ts_WPH_min = binvar(1,5);
B_ts_WPH_max = binvar(1,5);
B_ts_WPHsum_min = binvar(1);
B_ts_WPHsum_max = binvar(1);
xi_ctb_D_min = sdpvar(1,5);
xi_ctb_D_max = sdpvar(1,5);
xi_ctb_Dsum_min = sdpvar(1);
xi_ctb_Dsum_max = sdpvar(1);
B_ctb_D_min = binvar(1,5);
B_ctb_D_max = binvar(1,5);
B_ctb_Dsum_min = binvar(1);
B_ctb_Dsum_max = binvar(1);
xi_ctb_D0 = sdpvar(1,5);
M = 100;
P_ts_WPH_sum_min = 0;
P_ts_WPH_sum_max = 5;
P_ts_WPH_min = 0;
P_ts_WPH_max = 1;
lambda_ctb_D = [900 800 700 600 500]/100;
P_ctb_D_sum_max = 5;
P_ctb_D_sum_min = 0;
P_ctb_D_max = 1;
P_ctb_D_min = 0;
c = [];
c = [c,-lambda_ts_WPH + repmat(mu_nt,[1,5]) + xi_ts_WPH_min - xi_ts_WPH_max + repmat(xi_ts_WPHsum_min,[1,5]) - repmat(xi_ts_WPHsum_max,[1,5]) == 0];
c = [c, 0 <= P_ts_WPH - P_ts_WPH_min <= M.*B_ts_WPH_min, 0<= xi_ts_WPH_min <= M.*(1-B_ts_WPH_min)];
c = [c, 0 <= P_ts_WPH_max - P_ts_WPH <= M.*B_ts_WPH_max, 0<= xi_ts_WPH_max <= M.*(1-B_ts_WPH_max)];
c = [c, 0 <= sum(P_ts_WPH,2) - P_ts_WPH_sum_min <= M.*B_ts_WPHsum_min, 0 <= xi_ts_WPHsum_min <= M.*(1-B_ts_WPHsum_min)];
c = [c, 0 <= P_ts_WPH_sum_max - sum(P_ts_WPH,2)<= M.*B_ts_WPHsum_max, 0 <= xi_ts_WPHsum_max <= M.*(1-B_ts_WPHsum_max)];
c = [c,lambda_ctb_D - repmat(mu_nt,[1,5]) + xi_ctb_D_min - xi_ctb_D_max + repmat(xi_ctb_Dsum_min,[1,5]) - repmat(xi_ctb_Dsum_max,[1,5]) == 0];
c = [c, 0 <= P_ctb_D - P_ctb_D_min <= M.*B_ctb_D_min, 0<= xi_ctb_D_min <= M.*(1-B_ctb_D_min)];
c = [c, 0 <= P_ctb_D_max - P_ctb_D <= M.*B_ctb_D_max, 0<= xi_ctb_D_max <= M.*(1-B_ctb_D_max)];
c = [c, 0 <= sum(P_ctb_D,2) - P_ctb_D_sum_min <= M.*B_ctb_Dsum_min, 0 <= xi_ctb_Dsum_min <= M.*(1-B_ctb_Dsum_min)];
c = [c, 0 <= P_ctb_D_sum_max - sum(P_ctb_D,2)<= M.*B_ctb_Dsum_max, 0 <= xi_ctb_Dsum_max <= M.*(1-B_ctb_Dsum_max)];
c = [c,implies(lambda_ts_WPH(1,5) <= (lambda_ctb_D(1,5) -0.000001) , [P_ts_WPH == 0,P_ctb_D == 0])];
c_mu_nt = sum(P_ts_WPH,'all') == sum(P_ctb_D,'all');
c = [c,c_mu_nt];
for i = 1:4
c = [c, (lambda_ts_WPH(1,i) - lambda_ts_WPH(1,i+1)) <= 0];
c = [c, 1 <= lambda_ts_WPH <= 5];
end
obj = mu_nt.*sum(P_ts_WPH,2);
ops = sdpsettings('solver', 'Gurobi+', 'verbose', 2, 'debug', 1, 'gurobi.NonConvex', 2);
ops.gurobi.ResultFile = 'MyFile.lp';
ops.gurobi.Method = 2;
ops.gurobi.PoolSearchMode = 2;
ops.gurobi.PoolGap = 0;
result = optimize(c,-obj,ops);
xi_ts_WPH_min_value = value(xi_ts_WPH_min);
xi_ts_WPH_max_value = value(xi_ts_WPH_max);
xi_ts_WPHsum_min_value = value(xi_ts_WPHsum_min);
xi_ts_WPHsum_max_value = value(xi_ts_WPHsum_max);
LMP = value(mu_nt);
lambda_ts_WPH_value = value(lambda_ts_WPH);
P_ts_WPH_value = value(P_ts_WPH);
P_ctb_D_value = value(P_ctb_D);

FYI, someone told me I can set the params of gurobi like ' PoolSearchMode ' and ' PoolGap ' so I can get all  optimal solutions. I tried, and yes. It did return the following information:
Solution count 10: -25 -25 -25 ... -25
No other solutions better than -25

Optimal solution found (tolerance 1.00e-04)
Best objective -2.500000000000e+01, best bound -2.500000000000e+01, gap 0.0000% 
So...help me pls.
Message has been deleted

llL o0O

unread,
Nov 4, 2023, 6:52:12 AM11/4/23
to YALMIP
And I need getting different values of ''lambda_ts_WPH"

Kai Xing

unread,
Nov 5, 2023, 12:04:17 PM11/5/23
to YALMIP
I think you can use the parameter "savesolveroutput", and then check the pool of gurobi. I have tried this, and ideally get my solutions.
But it only works when you can easily figure out the relationships between the your original sdpvar and the gurobi's x.

llL o0O

unread,
Nov 8, 2023, 9:42:42 PM11/8/23
to YALMIP
oh that's a nice move!Thx and I'll try
Reply all
Reply to author
Forward
0 new messages