Optimal schedule using fmincon, nonlcon
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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)
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 Commenti
Matt J
il 8 Feb 2023
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
il 30 Mag 2024
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.
Risposte (0)
Vedere anche
Categorie
Scopri di più su Get Started with Optimization Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!