Optimal schedule using fmincon, nonlcon

1 次查看(过去 30 天)
I have an assignment where I am supposed to calculate the optimal schedule for a wood boiler and an oil boiler connected to an accumulator tank.
Wood boiler has an effect of 30 MW and fuel cost of 150 units/MWh
Oil boiler has an effect of 50 MW and fuel cost of 600 units/MWh
Accumulator tank has a capacity of 300 MWh, and loses daily 2% of its capacity.
Now I will calculate the optimal schedule given this daily needs:
Monday: 600MWh
Thuesday: 900 MW
Wednesday: 900 MWh
Thurday: 700 MWh
Friday: 800 MWh
Saturday: 500 MWh
Sunday: 500 MWh
This is my code so far:
demand = [600;900;900;700;800;500;500];
[x, fval] = optimal_schedule(demand)
x = 2×7
1.0e-05 * 0.2178 0.2171 0.2188 0.2185 0.2195 0.2194 0.2214 0.1639 0.1631 0.1624 0.1618 0.1611 0.1604 0.1597
fval = 0.0091
function [x, fval] = optimal_schedule(demand)
% demand: a 7x1 vector representing daily demand in MWh
% x: a 2x7 matrix representing the daily use of each boiler in MW
% fval: the total cost of the schedule
% Define the objective function
obj_fun = @(x) sum(150 * x(1,:) + 600 * x(2,:));
% Define the constraints
A = [];
b = [];
Aeq = [];
beq = [];
lb = [zeros(1,7); zeros(1,7)];
ub = [30 * ones(1,7); 50 * ones(1,7)];
nonlcon = @(x) accumulator_constraint(x, demand);
% Solve the optimization problem
options = optimoptions(@fmincon, 'Display', 'off');
x0 = [15 * ones(1,7); 25 * ones(1,7)];
[x, fval] = fmincon(obj_fun, x0, A, b, Aeq, beq, lb, ub, nonlcon, options);
end
function [c, ceq] = accumulator_constraint(x, demand)
% x: a 2x7 matrix representing the daily use of each boiler in MW
% demand: a 7x1 vector representing daily demand in MWh
% c: the inequality constraints
% ceq: the equality constraints
% Define the accumulator's initial state and capacity
init = 300;
capacity = 300;
% Compute the daily state of the accumulator
state = init;
for i = 1:7
state = state - (demand(i) - sum(x(:,i))) * 0.02;
c(i) = state - capacity;
end
% No equality constraints
ceq = [];
end
I know x should be a 7x3 or 3x7 matrix to keep track of both the productions and the contents within the tank.
And that I´ll need 7 equality constraints within the nonlcon function to account for the energy stored within the acktank.
But I seem to be stuck by getting error:
Error in fmincon (line 655)
[ctmp,ceqtmp] = feval(confcn{3},X,varargin{:});
Error in optimal_schedule (line 21)
[x, fval] = fmincon(obj_fun, x0, A, b, Aeq, beq, lb, ub, nonlcon, options);
Caused by:
Failure in initial nonlinear constraint function evaluation. FMINCON cannot continue.
Woul gladly receive som help!
Thank you!
  3 个评论
Matt J
Matt J 2023-2-8
And that I´ll need 7 equality constraints
Did you mean here the 7 constraints that you've implemented already? These are inequality constraints, not equalities.
Also, they are linear, not nonlinear constraints, so you are handicapping the performance of the algorithm by putting them in nonlcon.
Sam Chak
Sam Chak 2024-5-30
Is there any update on this unresolved issue? If you wish to pursue it further, providing feedback would enable interested users to offer the beautiful solution you're seeking.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by