Problems caused by multiplication of uncertain variables with sdpvar

175 views
Skip to first unread message

Jinfan Chen

unread,
Aug 31, 2022, 7:37:41 AM8/31/22
to YALMIP
I am very sorry to disturb you, I have been thinking about it for a long time, but I really can't find the cause of the problem, and I need your help very much.
This program has two uncertain variables, p_e_need and price_e, which are defined in lines 81 and 82 of the program. There is also an sdpvar named p_grid, whose range is not constrained. The only difference between the two uncertain variables p_e_need and price_e is that in the objective function (lines 125 and 126), the uncertain variable price_e is multiplied by the variable p_grid.
When price_e is a constant, everything works fine, but when it is an indeterminate variable, the following errors occur.
(1) The variable p_grid will always be close to 0, no matter how the rest of the constants change, which is illogical.
(2) There is no constraint on the range of the variable p_grid, so the equation constraint in line 102 could have been satisfied forever. However, when price_e is an uncertain variable, if p_e_need in this constraint is changed to a very large number, 'Model is infeasible or unbounded' displayed. It seems that this constraint is no longer relevant to p_grid.

I have simplified the program and I beg you to help me when you have time.
pred.mat
DO_debug1.m

Johan Löfberg

unread,
Aug 31, 2022, 8:14:39 AM8/31/22
to YALMIP
Not sure what the actual question is. The code runs and terminates successfully (although it warns you massively that you are using unbounded variables in the implies operators, which you shouldn't as it leads to poor or even incorrect models)

Additionally, you talk about uncertain variables, but there is no call to uncertain in this code. Having something which you call uncertainty being just a decision variables makes no sense, as that would mean you are allowed to select the best possible uncertainty.

Jinfan Chen

unread,
Aug 31, 2022, 10:03:59 AM8/31/22
to YALMIP
Dear Prof.  Lofberg,
Thank you for your patience, I defined the uncertain variables p_e_need and price_e in this way according to your documentation.
-------------------------------------------
p_e_need = sdpvar(1, schedule_period);
price_e = sdpvar(1, schedule_period);

W = [  ];
for i_sche = 1:schedule_period
    W = [W,...
    p_e_demand(1, i_sche)*(1-sig_e(1, i_sche)) <= p_e_need(1, i_sche) <= p_e_demand(1, i_sche)*(1+sig_e(1, i_sche)),...
    price_e_pred(1, i_sche)*(1-sig_prce(1, i_sche)) <= price_e(1, i_sche) <= price_e_pred(1, i_sche)*(1+sig_prce(1, i_sche))];
end
W = [W, uncertain([p_e_need price_e])];
---------------------------------------------

where sig is the uncertainty and p_e_demand and price_e_pred are the constants. Can you please point out my mistake? Maybe my understanding is wrong.

Johan Löfberg

unread,
Aug 31, 2022, 4:28:42 PM8/31/22
to YALMIP
Sorry, I misread.

A quick start to see if it is your modelling, or a bug inte the robustification is to solve an approximation where you simply draw a lot of samples from the uncertainty set and add constraints and see if it converges to something similiar

It could be related to some issue happening due to your uncertainty set which has no interior. Maybe try with a slightly opened up set
>> [~,ll,uu]=boundingbox(W(1:48));
>> [ll uu]

ans =

    2.3377    2.3377
    2.3357    2.3357
    2.3981    2.3981
    2.3300    2.3300
    2.4331    2.4331
    5.6916    5.6916
    5.2883    5.2883
    8.4698    8.4698
    8.1434    8.1434
    8.6016    8.6016
    8.6320    8.6320
    8.3116    8.3116
    9.2027    9.2027
    8.7544    8.7544
    9.4663    9.4663
    9.0863    9.0863
    5.3718    5.3718
    4.4616    4.4616
    2.6586    2.6586
    2.5508    2.5508
    2.5273    2.5273
    2.3382    2.3382
    1.7533    1.7533
    2.3856    2.3856
    0.0653    0.0798
    0.0563    0.0688
    0.0563    0.0688
    0.0520    0.0636
    0.0546    0.0667
    0.0596    0.0729
    0.0741    0.0906
    0.0720    0.0880
    0.0711    0.0869
    0.0747    0.0913
    0.0824    0.1008
    0.0860    0.1051
    0.0856    0.1047
    0.0922    0.1127
    0.0897    0.1096
    0.0922    0.1127
    0.1032    0.1261
    0.0947    0.1158
    0.0930    0.1137
    0.0914    0.1117
    0.0899    0.1098
    0.0791    0.0967
    0.0771    0.0942
    0.0699    0.0855

Johan Löfberg

unread,
Aug 31, 2022, 4:34:53 PM8/31/22
to YALMIP
You have uncertainties in equalities (in some implications). This is not possible, as it makes no sense to have an uncertainty in an equality
onsdag 31 augusti 2022 kl. 13:37:41 UTC+2 skrev chenjin...@gmail.com:

Jinfan Chen

unread,
Sep 1, 2022, 2:33:31 AM9/1/22
to YALMIP
Dear Prof. Lofberg,
Thank you very much for your detailed explanation, however, I have a new problem 
I am correcting the error according to your hints, however when I try to reduce an equality constraint by converting p_grid and sdpvar to assignment, I get the following error, however I don't have any secondary variables in existence.
-------------------------Error-----------------------------------------------
 filter_eliminatation
Cannot get rid of nonlinear uncertainty in uncertain constraint

 optimize (line 31 )
[varargout{1:nargout}] = solvesdp(varargin{:});

 DO_debug1 (line 163 )
sol = optimize(W + Constraints, Objective, options);

----------------------------The original code----------------------------
Constraints = [Constraints,...
pv_out + p_grid + p_ge - p_e_need >= 0,... 
Q_h_ge * eta_hru - p_h_need - Q_c_all_double >= 0,... 
Q_c_all_double * double_brli_cop - p_c_need >= 0,... 
0 <= Q_h_ge,...
0 <= Q_c_all_double,...
0 <= p_gas_ge,...
0 <= p_ge <= mt_bound];
----------------------------------Error code 1--------------------------------
p_grid = p_e_need - p_ge - pv_out;  % Changed >= equal to assignment
Constraints = [Constraints,...
Q_h_ge * eta_hru - p_h_need - Q_c_all_double >= 0,... 
Q_c_all_double * double_brli_cop - p_c_need >= 0,... 
0 <= Q_h_ge,...
0 <= Q_c_all_double,...
0 <= p_gas_ge,...
0 <= p_ge <= mt_bound];
--------------------------------- Error code2 -------------------------------
Constraints = [Constraints,...
pv_out + p_grid + p_ge - p_e_need == 0,...   % Changed >= to ==
Q_h_ge * eta_hru - p_h_need - Q_c_all_double >= 0,... 
Q_c_all_double * double_brli_cop - p_c_need >= 0,... 
0 <= Q_h_ge,...
0 <= Q_c_all_double,...
0 <= p_gas_ge,...
0 <= p_ge <= mt_bound];
--------------------------------------------------------------------------------------

DO_debug1.m

Johan Löfberg

unread,
Sep 1, 2022, 2:42:31 AM9/1/22
to YALMIP
First, when debugging, always simplify and clean away as much as possible. Here, there is no reason to include the code related to the objective

You still have uncertainty in equalities, and to make matters worse it involves products between uncertain terms with no way to remove it

This "impossible" requirement

x == uncertain1*uncertain2*y+z

can be dealt with by forcing the decision variable to take the value 0, and simplify to x==z

This
x == uncertain1*uncertain2+z

makes no sense as there is no way to select the decision variables x and z such that it is equal to the the product of those uncertainties, for all possible uncertainty realizations
Message has been deleted

Jinfan Chen

unread,
Sep 1, 2022, 3:26:32 AM9/1/22
to YALMIP
Thank you very much for your lecture. Your simple words can always make me understand the long confused problems.
I was going to ask
-----------------------------------------------------------------------
For the robust optimization problem that the output must satisfy the equality constraint, but the output and the sales price cannot be determined, and that wants to maximize the profit (the product of the output and the sales price), what good solution is there for the product of the random variable that cannot be bypassed?

For example, in the power system, the electric power needs to be balanced in real time, but the future electricity price and electric power cannot be fully determined.
---------------------------------------------------------------------
But I later realized that this seemed to be an NP-hard problem. In the first stage of robust optimization, it seems that there should be no equality constraint, and it is better to be greater than or equal to.

But do you have any good suggestions on the product of random variables?

Jinfan Chen

unread,
Sep 1, 2022, 3:41:34 AM9/1/22
to YALMIP
That is, the constraint is that the output is guaranteed to meet the demand, but not exactly the demand, so that the constraint of equal is replaced by greater than or equal to. But the demand is uncertain, the selling price is uncertain, and the objective function is the output multiplied by the selling price, how to do this robust optimization?

Johan Löfberg

unread,
Sep 1, 2022, 3:44:27 AM9/1/22
to YALMIP
Very likely, you are just modelling in a bad way.

for instance, if I want to minimize the objective production*price where price is uncertain, it would be very bad to model it as [f ==  production*price] and then minimize f. The way to model it would be [ production*price <= f] and then minimize f, since the optimal solution will be an f which satisfies the inequality for all uncertainties, which is what one means

If you have nonlinear uncertainties which enter the model, it is often a very hard problem. A constraint of the type unc1*unc2 <= f requires implicitly an analytical representation of the maximum of an indefinite quadratic to be able to represent the robust counterpart. You might be able to derive this manually, but YALMIP will not be able to handle such a model natively

Jinfan Chen

unread,
Sep 3, 2022, 1:44:57 AM9/3/22
to YALMIP
Dear  Prof. Lofberg,
Thank you very much for your help, I am not familiar with the process of manually deriving robust counterpart, I will go and learn it.
I would like to ask you in advance, after deriving the robust counterpart manually, can I still use yalmip to solve it?

Johan Löfberg

unread,
Sep 3, 2022, 9:59:23 AM9/3/22
to YALMIP
A roubust counterpart can be completely intractable/impossible to represent, or trivial

x + x*y <= 2 for all -1<=y<=1

i.e 

x + max_{-1<=y<=1} x*y <= 2

is simply x + |x| <=1

The robust counterpart of a quadratic expression is much harder, as it requires you to somehow represent the maximum, which might be pretty much impossible if you are unlucky
Reply all
Reply to author
Forward
0 new messages