Error on multiple looped optimconstr

I am trying to run a simple power dispatch optimization model which includes three looped optimconstr problems. I have 7 different generator groups all of which need to produce a certain output in MWh each hour to meet demand in that hour. They are selected based on their cost of production. The problem is optimizing for a least cost solution. When I solve for the problem however the solver returns all zero values and I suspect this is because the constraints are not loading properly into the problem. The three constraints are 1) hourly generation must always be equal to hourly demand 2) wind output must equal hourly wind profile (loaded in from external data file) and 3)solar output must equal hourly solar profile (loaded in from external data file) I would really appreciate help on figuring out where the code is going wrong. Key parts of my code is the following:
% Create the problem
prob=optimproblem('Description',desc,'ObjectiveSense','min');
% Define the variables of the problem, their type and their bounds
var_OC = optimvar('var_OC',N,'Type','continuous','LowerBound',0,'UpperBound',OC_max);
var_CC = optimvar('var_CC',N,'Type','continuous','LowerBound',0,'UpperBound',CC_max);
var_Hydro = optimvar('var_Hydro',N,'Type','continuous','LowerBound',0,'UpperBound',Hydro_max);
var_Nuclear = optimvar('var_Nuclear',N,'Type','continuous','LowerBound',0,'UpperBound',Nuclear_max);
var_Coal = optimvar('var_Coal',N,'Type','continuous','LowerBound',0,'UpperBound',Coal_max);
var_Wind = optimvar('var_Wind',N,'Type','continuous','LowerBound',0,'UpperBound',Wind_max);
var_Solar = optimvar('var_Solar',N,'Type','continuous','LowerBound',0,'UpperBound',Solar_max);
% Define the objective function
prob.Objective = sum(var_CC.*CC_MC + var_OC.*OC_MC + var_Hydro.*Hydro_MC + var_Nuclear.*Nuclear_MC + var_Coal.*Coal_MC + var_Wind.*Wind_MC + var_Solar.*Solar_MC);
% Define constraint functions
constr_load = optimconstr(N);
for i = 1:N;
constr_load(i) = var_OC(i)+var_CC(i)+var_Hydro(i)+var_Nuclear(i)+var_Coal(i)+var_Wind(i)+var_Solar(i)== HL(i); % Hourly generation is equal to hourly system demand
end
constr_wind = optimconstr(N);
for m = 1:N;
constr_wind(m) = var_Wind(m) == wind_prod(m);
end
constr_solar = optimconstr(N);
for k = 1:N;
constr_solar(k)= var_Solar(k) == solar_prod(k);
end
% Load constraints into the problem
prob.Constraints.constr_load = constr_load;
prob.Constraints.constr_wind = constr_wind;
prob.Constraints.constr_solar = constr_solar;

Answers (1)

I am not sure that I understand what variables you are trying to solve for, and which variables are really not variables at all, but are data. Your constraints
constr_wind(m) = var_Wind(m) == wind_prod(m);
constr_solar(k)= var_Solar(k) == solar_prod(k);
seem to me to say that var_Wind and var_Solar are not variables that you can change, but are instead given by the data vectors wind_prod and solar_prod respectively. If I am correct, then you should remove var_Wind and var_Solar from your problem statement, and replace them by their values, wind_prod and solar_prod.
I do not understand why you define your variables in a loop each time. For example, I believe that instead of
constr_load = optimconstr(N);
for i = 1:N;
constr_load(i) = var_OC(i)+var_CC(i)+var_Hydro(i)+var_Nuclear(i)+var_Coal(i)+var_Wind(i)+var_Solar(i)== HL(i); % Hourly generation is equal to hourly system demand
end
you could write
constr_load = var_OC + var_CC + var_Hydro + var_Nuclear + var_Coal + var_Wind + var_Solar == HL;
With those changes, see whether your problem simplifies to something that has a solution satisfying your constraints.
Alan Weiss
MATLAB mathematical toolbox documentation

Asked:

on 20 May 2018

Answered:

on 22 May 2018

Community Treasure Hunt

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

Start Hunting!