部分代码
% 确定性优化结果
clc
close all
clear
% A Benchmark Case of Optimal Recourse Under Wind Power Uncertainty
D = 320; %MW % demand
what = 60; % mean wind output
V = 3000; % $/MW % penalty cost for load loss
a = 3; % $/MW
b = 30; % $
x = binvar(1); % 机组启停机
p = sdpvar(1); % 机组出力
l = sdpvar(1);
% 不确定性变量
ResultP = [];
ResultQ = [];
i= 1;
for v = -50 :10 :100
Q = b * x + a * p +V * l;
constrains = [ p >= 20 * x ;
p <= 300 *x;
p + l == D - what - v;
l >= 0 ;];
opt = sdpsettings('verbose',1,'solver','cplex');
result = optimize(constrains,Q,opt); % 主问题求解
ResultP(i) = value(p);
ResultQ(i) = value(Q);
i = i+1;
end