V2H Optimization: No feasible solution found

I have some troubles to code an optimization Problem in Matlab. Since this is my first optimization i am a bit lost. This code is not running because "Linprog stopped because no point satisfies the constraints.". But I fail to see which constraint is prohibiting the code from running.
T = length(PV); % Anzahl der Zeitschritte
Unrecognized function or variable 'PV'.
% Problem
prob = optimproblem;
% battery storage system parameter
BSS_Pmax = 11; % max power
BSS_Emax = 100; % max energy
% battery variables
BSS_ch = optimvar('BSS_ch', T, 'LowerBound', 0, 'UpperBound', BSS_Pmax);
BSS_disch = optimvar('BSS_disch', T, 'LowerBound', 0, 'UpperBound', BSS_Pmax);
BSS_SOC = optimvar('BSS_SOC', T, 'LowerBound', 0, 'UpperBound', BSS_Emax);
% other variables
Grid_Import = optimvar('Grid_Import', T, 'LowerBound', 0);
% battery constraints
prob.Constraints.energyStorage = optimconstr(T);
prob.Constraints.energyStorage = BSS_SOC(1) == 0;
prob.Constraints.energyStorage = BSS_SOC(2:T) == BSS_SOC(1:T-1) - BSS_disch(2:T) + BSS_ch(2:T);
% energy flow
prob.Constraints.EnergyBalance = Grid_Import == Bedarf - PV - BSS_disch + BSS_ch;
% cost funtion
cost = Grid_Import .* Price;
prob.ObjectiveSense = 'minimize';
prob.Objective = sum(cost);
% solve
[x, fval] = solve(prob);
% optional display
%disp(x.BSS_ch);
%disp(x.BSS_disch);

 채택된 답변

Torsten
Torsten 2024년 5월 21일
편집: Torsten 2024년 5월 21일

1 개 추천

Use
energyStorage = optimconstr(T);
energyStorage(1) = BSS_SOC(1) == 0;
energyStorage(2:T) = BSS_SOC(2:T) == BSS_SOC(1:T-1) - BSS_disch(2:T) + BSS_ch(2:T);
prob.Constraints.energyStorage = energyStorage;
instead of
% battery constraints
prob.Constraints.energyStorage = optimconstr(T);
prob.Constraints.energyStorage = BSS_SOC(1) == 0;
prob.Constraints.energyStorage = BSS_SOC(2:T) == BSS_SOC(1:T-1) - BSS_disch(2:T) + BSS_ch(2:T);
I can't check your constraints since I cannot execute your code. So I don't know if the above modification solves your problem.

댓글 수: 6

Hi Torsten, thanks for your suggestion. Unfortunately, it did not solve the problem.
What do you need to be able to execute the code? Instead of the data, randomly selected arrays could act as placeholders. e.g. PV = values between 0-500; Household = values between 500-1000; Price = values between 0.2 and 0.4
Torsten
Torsten 2024년 5월 21일
편집: Torsten 2024년 5월 21일
Then I suggest you post a code with random data here that can be executed and reproduces the error you get from "linprog".
Tim Sanders
Tim Sanders 2024년 5월 22일
편집: Tim Sanders 2024년 5월 22일
Please see the updated code below:
% Set the size of the array
n = 8760;
% Generate random values between 0 and 500
PV = randi([0, 500], n, 1); % Beispielwerte
Household = randi([200, 1000], n, 1); % Beispielwerte
Price = 0.006 .* randi([1, 100], n, 1); % Beispielwerte
T = length(PV); % Anzahl der Zeitschritte
% Problem
prob = optimproblem;
% battery storage system parameter
BSS_Pmax = 11; % max power
BSS_Emax = 100; % max energy
% battery variables
BSS_ch = optimvar('BSS_ch', T, 'LowerBound', 0, 'UpperBound', BSS_Pmax);
BSS_disch = optimvar('BSS_disch', T, 'LowerBound', 0, 'UpperBound', BSS_Pmax);
BSS_SOC = optimvar('BSS_SOC', T, 'LowerBound', 0, 'UpperBound', BSS_Emax);
% other variables
Grid_Import = optimvar('Grid_Import', T, 'LowerBound', 0);
% battery constraints
energyStorage = optimconstr(T);
energyStorage(1) = BSS_SOC(1) == 0;
energyStorage(2:T) = BSS_SOC(2:T) == BSS_SOC(1:T-1) - BSS_disch(2:T) + BSS_ch(2:T);
prob.Constraints.energyStorage = energyStorage;
% energy flow
prob.Constraints.EnergyBalance = Grid_Import == Household - PV - BSS_disch + BSS_ch;
% cost funtion
cost = Grid_Import .* Price;
prob.ObjectiveSense = 'minimize';
prob.Objective = sum(cost);
% solve
[x, fval] = solve(prob);
Torsten
Torsten 2024년 5월 22일
편집: Torsten 2024년 5월 22일
It works if you relax the condition
% energy flow
prob.Constraints.EnergyBalance = Grid_Import == Household - PV - BSS_disch + BSS_ch
to
% energy flow
prob.Constraints.EnergyBalance = Grid_Import >= Household - PV - BSS_disch + BSS_ch
Hi thanks, this does work.
But it created a new problem. I was unware of the fact that in the real dataset the price can get to a negative value. If you replace the random data generation of the price parameter with "Price = 0.006 .* randi([-100, 100], n, 1); % Beispielwerte". The Problem will become unbounded. Because it will generate an inf. Gridimport in those hours to reduce the cost.
Torsten
Torsten 2024년 5월 24일
Most probably, you need to set an upper bound for Gridimport.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Linear Programming and Mixed-Integer Linear Programming에 대해 자세히 알아보기

제품

릴리스

R2024a

질문:

2024년 5월 21일

댓글:

2024년 5월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by