Hi,
I need to solve mixed integer optimization problem having objective function which consists several parts like quadratic function, linear function and most critical two integral functions. I am using MOSEK as external solver. The mathematical model is given in the attached PDF file.
I am in dire need to know whether it is possible to define integral function in objective function in direct or indirect way …if so , Can you please tell me how ????
I am currently using code for unit commitment example given in YALMIP wiki examples.
http://users.isy.liu.se/johanl/yalmip/pmwiki.php?n=Examples.UnitCommitment
Thanks in advance,
Regards,
Nur
Q = @(P,y) (y-P).*sin(P).^3;values = (0:0.01:2*pi);for i = 1:length(values) f1(i) = integral(@(P)Q(P,values(i)),0,values(i)); f2(i) = integral(@(P)Q(P,values(i)),values(i),values(end)); endplot(values,[f1' f2'])
[X,Y] = meshgrid(-1:0.01:1,-1:0.01:1);
% Global minimum 0 at [0.5;-0.25]
mesh(X,Y,sin((X-.5).^2+(Y+.25).^2).^2)
% Create a triangulation
x = sdpvar(2,1);
f = @(x) sin((x(1)-.5)^2+(x(2)+.25)^2)^2;
% 2n simplicies will be generated
n = 5;
[f_pwa,model] = pwatriangulate2D([-1 <= x <= 1],f,x,n);
% And try to find the solution
solvesdp(model,f_pwa)
% Actual value in found point vs approximation value
[f(double(x)) double(f_pwa)]
function [f_pwa,model] = pwatriangulate2D(D,f,x,n);
[~,L,U] = boundingbox(D,[],x);
X = linspace(L(1),U(1),n);
Y = linspace(L(2),U(2),n);
% Number of squares (two simplicies in each)
in_region = binvar((length(X)-1)*(length(Y)-1),1);
k = 1;
f_pwa = 0;
% We are in one box (save bounds also)
model = [D, sum(in_region) == 1];
for i = 1:length(X)-1
for j = 1:length(Y)-1
% Two simplicies in each box
which_simplex = binvar(2,1);
v1 = [X(i);Y(j)];
v2 = [X(i+1);Y(j)];
v3 = [X(i);Y(j+1)];
v4 = [X(i+1);Y(j+1)];
z1 = f(v1);
z2 = f(v2);
z3 = f(v3);
z4 = f(v4);
% Interpolation variables in two simplicies
corners1 = sdpvar(3,1);
corners2 = sdpvar(3,1);
x1 = sdpvar(2,1);
x2 = sdpvar(2,1);
model = [model, implies(in_region(k), x == x1+x2), corners1 >=0, corners2 >= 0];
% Interpolate function and variable in first simplex
f_pwa = f_pwa + z1*corners1(1)+z2*corners1(2)+z3*corners1(3);
model = [model, x1 == v1*corners1(1)+v2*corners1(2)+v3*corners1(3)];
model = [model, sum(corners1) == which_simplex(1)];
% Second simplex
f_pwa = f_pwa + z2*corners2(1)+z3*corners2(2)+z4*corners2(3);
model = [model, x2 == v2*corners2(1)+v3*corners2(2)+v4*corners2(3)];
model = [model, sum(corners2) == which_simplex(2)];
% We are in at most one simplex, if we are in this region
model = [model, sum(which_simplex) == in_region(k)];
k = k+1;
end
end
[X,Y] = meshgrid(-1:0.01:1,-1:0.01:1);
ftemp = cos(X+sin(X)).^2;
% f(x) + f(x)*y = f(x) + .5(f(x)+y)^2-.5*f(x)^2-.5*y^2
mesh(X,Y,ftemp + ftemp*Y);
sdpvar x y f f2 y2
n = 25;
xyi = linspace(-1,1,n)';
fi = cos(xyi+sin(xyi)).^2;
fi_squared = fi.^2;
lambda1 = sdpvar(length(xyi),1); % for f and f^2
lambda2 = sdpvar(length(xyi),1); % for y^2
F = [sos2(lambda1), sos2(lambda2)];
F = [F, x == lambda1'*xyi, f == lambda1'*fi, lambda1>=0,sum(lambda1)==1]
F = [F, f2 == lambda1'*fi_squared];
F = [F, y == lambda2'*xyi, y2 == lambda2'*xyi.^2, lambda2>=0,sum(lambda2)==1]
Objective = f + 0.5*(f+y)^2-0.5*f2-0.5*y2;
solvesdp([-1 <= [x;y] <= 1,F],Objective)
plot([f2(3,:,1)' f2(3,:,2)' f2(3,:,3)'])
plot([f2(3,:,1)'./f2(2,:,1)' f2(1,:,2)'./f2(2,:,2)'])