Yalmip+matlab解决UC机组问题

摘自: https://yalmip.github.io/example/unitcommitment/
详细的UC请看上面的链接,这里主要介绍隐含的Yalmip的解法

需要注意的是,在Yalmip中,不能直接使用if else if等判断语句,应该设置隐含command implies

在本文中,不可以直接将发电机是否开启乘以发电机的出力这样表示的约束,最好如:

for k = 1:Horizon
  Constraints = [Constraints, onoff(:,k). *Pmin <= P(:,k) <= onoff(:,k). *Pmax];

隐含的情况是:

Model = [sum(d) == 1,
implies(d(1), [      e <= -5, f == 7]);
implies(d(2), [-5 <= e <= -2, f == 2-e]);
implies(d(3), [-2 <= e <= 2,  f == e^2]);
implies(d(4), [ 2 <= e <= 5,  f == 2+e]);
implies(d(5), [ 5 <= e,       f == 7])];

再利用大M法,因为二次等式约束是非凸的。然而,由于我们知道f是最小的,我们可以将等式松弛为凸不等式。
原话:At this point, we have a simple cleanly enumerated model, but in this particular case we have a remaining problem as the quadratic equality constraint is nonconvex. However, since we know f will be minimized, we can relax the equality to a convex inequality. The big-M model that will be derived for implies(d,e^2<=f) would be e2≤f+M(1−d), which is convex for relaxed integer variables, and hence mixed-integer second-order cone锥 representable

Model = [sum(d) == 1,
implies(d(1), [      e <= -5, f == 7]);
implies(d(2), [-5 <= e <= -2, f == 2-e]);
implies(d(3), [-2 <= e <= 2,  f >= e^2]);
implies(d(4), [ 2 <= e <= 5,  f == 2+e]);
implies(d(5), [ 5 <= e,       f == 7])];

最后,整个隐含的例子代码如下:

f = sdpvar(length(y),1);
e = sdpvar(length(y),1);
xBound = 100;
eBound = norm(y,inf) + norm(A,inf)*xBound;
fBound = max([2 + eBound, 7, eBound^2]);
Model = [          e == y-A*xhat, 
             -xBound <= xhat <= xBound,
             -eBound <= e <= eBound,
             -fBound <= f <= fBound];
Objective = sum(f);
for i = 1:length(f)
 d = binvar(5,1);
 Model = [Model, sum(d) == 1,
          implies(d(1), [      e(i) <= -5, f(i) == 7]);
          implies(d(2), [-5 <= e(i) <= -2, f(i) == 2-e(i)]);
          implies(d(3), [-2 <= e(i) <= 2,  f(i) >= e(i)^2]);
          implies(d(4), [ 2 <= e(i) <= 5,  f(i) == 2+e(i)]);
          implies(d(5), [ 5 <= e(i),       f(i) == 7])];
optimize(Model,Objective)
xhat1 = value(xhat);