[HELP!!] How to make objective function with MINLP

4 vues (au cours des 30 derniers jours)
JunGi Kim
JunGi Kim le 30 Jan 2020
Hi, I want make Optimal Charging / Discharging EV scheduling.
So, I made code like this.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Matlab Optimization toolbox %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:24 % 08 a.m ~ 18:00 p.m
for j=1:num_EV
%objective Function
% minimize
fun = @(x) x(1)*x(2)*cost_1(i) - x(3)*x(4)*cost_2(i);
% x(1) = charging mode (1,0) , x(2) = charging power,
% x(3) = discharging mode(1,0), x(4) = discharging power,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% constraints %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Non-linear Constraints (cl <= nlcon(x) <= cu)
nlcon = @(x) [
(x(1)*x(2) - x(3)*x(4))/ev_bat;
];
cl = [min_soc - cur_soc(j);];
cu = [max_soc - cur_soc(j);];
%Inequality Constraints (Ax <= b)
A = [-charging_rate 1 0 0;
0 0 -charging_rate 1;];
b = [0;
0;];
%Equality Constraints (Aeqx = beq)
Aeq = [1 0 1 0];
beq = [1];
% Initial Guess
x0 = [0 0 1 10];
% Bounds (lb<=x<=ub)
lb = zeros(4,1);
ub = [1, charging_rate, 1,charging_rate];
%range of n to solve for
% Set
xtype = 'BCBC';
Opt = opti('fun', fun,'ineq', A,b, 'eq', Aeq, beq, 'nl',nlcon,cl,cu,'bounds', lb, ub, 'x0', x0, 'xtype', xtype);
% Solve
[x,fval,exitflag,info] = solve(Opt)
deltaSoC = (x(1)*x(2) - x(3)*x(4))/ev_bat
cur_soc(j) = cur_soc(j) + deltaSoC
cur_soc(j,1);
end
end
But, When I run this, every time step only discharging maximum until limit SoC. and they not charging for minimize cost.
So, I think this code consider just current time step. they didn't think about other time's cost.
Therefore, I change code like this
%FROM
for i= 1:24
fun = @(x) x(1)*x(2)*cost_1(i) - x(3)*x(4)*cost_2(i);
end
%Changed code
fun = @(x) sum(x(1)*x(2).*k_1 - x(3)*x(4).*cost_p,2);
But when i run this,
I can see this error.
" The returned vector length (24) did not match the specified length (1)"
오류 발생: opti.buildOpti>@(x)mklJac(prob.fun,x,1) (line 127)
prob.f = @(x) mklJac(prob.fun,x,1);
How can I fix this?? Help Please.

Réponses (0)

Catégories

En savoir plus sur Linear Programming and Mixed-Integer Linear Programming dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by