Optimal schedule using fmincon, nonlcon

1 回表示 (過去 30 日間)
Erik Eriksson
Erik Eriksson 2023 年 2 月 8 日
コメント済み: Sam Chak 2024 年 5 月 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 Center および File ExchangeGet 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