# Help with building a model

Hello, I am a beginner using Gurobi and would like your assistance with the following problem.

I want to implement the following optimization problem in **Matlab**. I have given a power demand profile **for 24 hours** and have to minimize the cost of two power plants to meet the demand at each hour. Moreover, I have minimum and maximum capacity constraints for each power plant.

The solution must be the generated power for each power plant for each hour. (So, the values for my decision variables P_generated_coal_1 and P_generated_coal_2 for each hour.)

% minimize

% C_coal_1*P_generated_coal_1 + C_coal_2*P_generated_coal_2

% subject to

% Power balance

% Power_demand(t) = P_generated_coal_1(t) + P_generated_coal_2(t); % Power balance constraint

%

% Coal power plant 1

% P_min_coal_1 <= P_generated_coal_1 <= P_max_coal_1;

%

% Coal power plant 2

% P_min_coal_2 <= P_generated_coal_2 <= P_max_coal_2;

hours = 24;

% Define the parameters

C_coal_1 = 5; % Production cost $ per MWh for coal plant 1

C_coal_2 = 1; % Production cost $ per MWh for coal plant 2

% Coal power plant 1 parameters

P_max_coal_1 = 4000; % Maximal power capacity constraint for plant 1

P_min_coal_1 = 0; %Minimal power capacity constraint plant 1

P_generated_coal_1= zeros(1,hours); %Generated power from plant 1 at each time instance t

% Coal power plant 2 parameters

P_max_coal_2 = 6000; % Maximal power capacity constraint for plant 2

P_min_coal_2 = 0; %Minimal power capacity constraint plant 2

P_generated_coal_2=zeros(1,hours); %Generatied power from plant 2 at each time instance t

%%

csvFile = 'Demand_PV_CW_34_2022_1.csv';

data = readmatrix(csvFile);

Power_demand = data(:,1); %Format 24x1 double

names = {'P_generated_coal_1';'P_generated_coal_2'};

A=[];

b=[];

c = []; % objective function

sense = [];

% define the opt problem for each hour

for k = 1:hours

A = [A; ones(1,2)];

b = [b; Power_demand(k)] ;

c = [c, C_coal_1, C_coal_2];

sense = [sense,'='] ;

end

%define model for Gurobi

model.A = sparse(A);

model.obj = c;

model.rhs = b;

model.ub = [P_max_coal_1; P_max_coal_2];

model.lb = [P_min_coal_1; P_min_coal_2];

model.sense = sense;

model.modelsense = 'Min';

model.varnames = names;

%Solve the optimization problem

result = gurobi(model);

** My problem **is that I cannot correctly implement the objective function; therefore, the dimensions are somehow never correct.

The idea is to formulate your example problem from https://github.com/Gurobi/modeling-examples/blob/master/power_generation/optimize_power_schedule.ipynb to Matlab.

Thanks in advance for the help!

BR

Georgi

Please sign in to leave a comment.

## Comments

0 comments