introducing a comparison related to variables in linear programming
4 views (last 30 days)
Show older comments
Hello,
I want to run linear programming to make a trade off between multiple sources of energy. I want to include a battery in the system and size it using linear programming. Therefore, I have the following varaibles:
Pdemand: demands of energy which I have it already as a vector colmun.
X1= A_pv [m^2 ]-maximum total area occupied by the solar photovoltaic system
X2=A_w [m^2 ]-maximum total wind rotor area
.
.
X8=E_bess (t) [kWh]-energy in the BESS at time t
X9=P_(bess.in) (t) [kW]-power in battery at time t
X10=P_(bess.out) (t) [kW]-power out from battery at time t
I started to encounter problems when setting my first inequality since X9 and X10 are related to X1 and X2 as following
if X1 + X2 > Pdemand
X9 = (X1 +X2) - Pdemand;
X10 = 0;
else
X10 = Pdemand - (X1 + X2);
X9= 0;
Now I want to make the first constrain for linear programming by reporting the coefficient to use it later in linear programming
X1 + X2 +X9 +X10 = demands
I included X9 and X10 here in the equation since one of them needs to be zero at the time the other is presented.
A1 = [CX1 CX2 0 0 0 0 0 0 0 CX9 CX10]
As you can see, I am trying to solve for X9 and X10 but before I need them to go throght the if statment which is not possible till I get the results of linear programming first.
Can someone help me please, I have zero ideas how to solve this. Thanks.
4 Comments
Accepted Answer
Matt J
on 20 Jan 2023
Edited: Matt J
on 20 Jan 2023
The constraints you describe are non-convex, so there is no way to formulate them in a linear way. However, you can modify your problem so that the solution to a linear program is encouraged to satisfy those constraints. Introduce additional variables U,V and the constraints,
U=(X1 +X2) - Pdemand
-V<=U<=V %implies V>=abs(U)
X9>=0
V>=X9>=U %(1a)
X10>=0
V>=X10>=-U %(1b)
X9+X10=V %(2)
Also, modify your linear objective to have a penalty term,
min. f(X) + largeNumber*V
So, if largeNumber is large enough, the penalty will force V to its lower bound V=abs(U) at the solution. In that case when U>0 then U=V and constraint (1a) implies X9=U=(X1 +X2) - Pdemand. Additionally constraint (2) then implies X10=0.
A similar argument shows that if U<0 and so -U=V, then constraint (1b) implies X10=V=abs(U)= Pdemand-(X1+X2) and X9=0.
0 Comments
More Answers (1)
Torsten
on 20 Jan 2023
Edited: Torsten
on 20 Jan 2023
Your constraint says that
X9 = max(0,X1+X2-Pdemand)
X10 = max(0,Pdemand-(X1+X2))
Usually, it suffices to set the constraints
X9 >= 0
X9 >= X1+X2-Pdemand
X10 >= 0
X10 >= Pdemand-(X1+X2)
since you usually won't "oversupply" in an optimization.
If the constraints don't suffice for your application, look up on how to linearize the max-operator independent of the objective following Larry Snyder's answer under
But in case you have to use this formulation, your problem becomes a problem for intlinprog - it can no longer be solved with linprog.
0 Comments
See Also
Categories
Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!