Error bei optimizaion fomulation
AnsweredHello,
I'm trying to solve a MILP in a energy system. I tried two ways to fomulate the problems as follows:

The only difference is the + and - symbols of two different vars. However, the left one with"+" can't be solved by gurobi, but the right one with "-" do.
Could anyone tell me why this happens?
Thanks
Yusheng
First one:
\ Model energy system
\ LP format - for model browsing. Use MPS format to capture full model detail.
Minimize
total_opex
Subject To
balance_powerHP_0: 0.3333333333333333 heat_HP_0 - power_HP_0 = 0
balance_powerHP_1: 0.3333333333333333 heat_HP_1 - power_HP_1 = 0
balance_powerHP_2: 0.3333333333333333 heat_HP_2 - power_HP_2 = 0
investment_HP: - 1500 rated_heat_HP + investment_HP = 0
capex_HP: - 0.0871845569768514 investment_HP + capex_HP = 0
fix_opex_HP: - 0.01 investment_HP + fix_opex_HP = 0
var_opex_HP: - 0.3 power_HP_0 - 0.3 power_HP_1 - 0.3 power_HP_2
+ var_opex_HP = 0
tac_HP: - capex_HP - fix_opex_HP - var_opex_HP + tac_HP = 0
balance_gasCHP_0: 2.857142857142857 power_CHP_0 - gas_CHP_0 = 0
balance_heatCHP_0: 2.857142857142857 power_CHP_0 - 2 heat_CHP_0 = 0
balance_gasCHP_1: 2.857142857142857 power_CHP_1 - gas_CHP_1 = 0
balance_heatCHP_1: 2.857142857142857 power_CHP_1 - 2 heat_CHP_1 = 0
balance_gasCHP_2: 2.857142857142857 power_CHP_2 - gas_CHP_2 = 0
balance_heatCHP_2: 2.857142857142857 power_CHP_2 - 2 heat_CHP_2 = 0
investment_CHP: - 1000 rated_power_CHP + investment_CHP = 0
capex_CHP: - 0.0871845569768514 investment_CHP + capex_CHP = 0
fix_opex_CHP: - 0.02 investment_CHP + fix_opex_CHP = 0
var_opex_CHP: - 0.05 gas_CHP_0 - 0.05 gas_CHP_1 - 0.05 gas_CHP_2
+ var_opex_CHP = 0
tac_CHP: - capex_CHP - fix_opex_CHP - var_opex_CHP + tac_CHP = 0
R19: heat_HP_0 + heat_CHP_0 = 1815.309722637984
R20: heat_HP_1 + heat_CHP_1 = 1780.50765403553
R21: heat_HP_2 + heat_CHP_2 = 1835.657173529321
R22: - tac_HP - tac_CHP + total_opex = 0
lb_HP_0: heat_HP_0 + [ ] >= 0
ub_HP_0: heat_HP_0 + [ - rated_heat_HP * operation_HP_0 ] <= 0
lb_HP_1: heat_HP_1 + [ ] >= 0
ub_HP_1: heat_HP_1 + [ - rated_heat_HP * operation_HP_1 ] <= 0
lb_HP_2: heat_HP_2 + [ ] >= 0
ub_HP_2: heat_HP_2 + [ - rated_heat_HP * operation_HP_2 ] <= 0
lb_CHP_0: power_CHP_0 + [ - 0.2 rated_power_CHP * operation_CHP_0 ] >= 0
ub_CHP_0: power_CHP_0 + [ - rated_power_CHP * operation_CHP_0 ] <= 0
lb_CHP_1: power_CHP_1 + [ - 0.2 rated_power_CHP * operation_CHP_1 ] >= 0
ub_CHP_1: power_CHP_1 + [ - rated_power_CHP * operation_CHP_1 ] <= 0
lb_CHP_2: power_CHP_2 + [ - 0.2 rated_power_CHP * operation_CHP_2 ] >= 0
ub_CHP_2: power_CHP_2 + [ - rated_power_CHP * operation_CHP_2 ] <= 0
Bounds
rated_heat_HP <= 1e+07
rated_power_CHP <= 1e+07
total_opex free
Binaries
operation_HP_0 operation_HP_1 operation_HP_2 operation_CHP_0
operation_CHP_1 operation_CHP_2
End
Second one:
\ Model energy system
\ LP format - for model browsing. Use MPS format to capture full model detail.
Minimize
total_opex
Subject To
balance_powerHP_0: 0.3333333333333333 heat_HP_0 + power_HP_0 = 0
balance_powerHP_1: 0.3333333333333333 heat_HP_1 + power_HP_1 = 0
balance_powerHP_2: 0.3333333333333333 heat_HP_2 + power_HP_2 = 0
investment_HP: - 1500 rated_heat_HP + investment_HP = 0
capex_HP: - 0.0871845569768514 investment_HP + capex_HP = 0
fix_opex_HP: - 0.01 investment_HP + fix_opex_HP = 0
var_opex_HP: 0.3 power_HP_0 + 0.3 power_HP_1 + 0.3 power_HP_2
+ var_opex_HP = 0
tac_HP: - capex_HP - fix_opex_HP - var_opex_HP + tac_HP = 0
balance_gasCHP_0: 2.857142857142857 power_CHP_0 + gas_CHP_0 = 0
balance_heatCHP_0: 2.857142857142857 power_CHP_0 - 2 heat_CHP_0 = 0
balance_gasCHP_1: 2.857142857142857 power_CHP_1 + gas_CHP_1 = 0
balance_heatCHP_1: 2.857142857142857 power_CHP_1 - 2 heat_CHP_1 = 0
balance_gasCHP_2: 2.857142857142857 power_CHP_2 + gas_CHP_2 = 0
balance_heatCHP_2: 2.857142857142857 power_CHP_2 - 2 heat_CHP_2 = 0
investment_CHP: - 1000 rated_power_CHP + investment_CHP = 0
capex_CHP: - 0.0871845569768514 investment_CHP + capex_CHP = 0
fix_opex_CHP: - 0.02 investment_CHP + fix_opex_CHP = 0
var_opex_CHP: 0.05 gas_CHP_0 + 0.05 gas_CHP_1 + 0.05 gas_CHP_2
+ var_opex_CHP = 0
tac_CHP: - capex_CHP - fix_opex_CHP - var_opex_CHP + tac_CHP = 0
R19: heat_HP_0 + heat_CHP_0 = 1815.309722637984
R20: heat_HP_1 + heat_CHP_1 = 1780.50765403553
R21: heat_HP_2 + heat_CHP_2 = 1835.657173529321
R22: - tac_HP - tac_CHP + total_opex = 0
lb_HP_0: heat_HP_0 + [ ] >= 0
ub_HP_0: heat_HP_0 + [ - rated_heat_HP * operation_HP_0 ] <= 0
lb_HP_1: heat_HP_1 + [ ] >= 0
ub_HP_1: heat_HP_1 + [ - rated_heat_HP * operation_HP_1 ] <= 0
lb_HP_2: heat_HP_2 + [ ] >= 0
ub_HP_2: heat_HP_2 + [ - rated_heat_HP * operation_HP_2 ] <= 0
lb_CHP_0: power_CHP_0 + [ - 0.2 rated_power_CHP * operation_CHP_0 ] >= 0
ub_CHP_0: power_CHP_0 + [ - rated_power_CHP * operation_CHP_0 ] <= 0
lb_CHP_1: power_CHP_1 + [ - 0.2 rated_power_CHP * operation_CHP_1 ] >= 0
ub_CHP_1: power_CHP_1 + [ - rated_power_CHP * operation_CHP_1 ] <= 0
lb_CHP_2: power_CHP_2 + [ - 0.2 rated_power_CHP * operation_CHP_2 ] >= 0
ub_CHP_2: power_CHP_2 + [ - rated_power_CHP * operation_CHP_2 ] <= 0
Bounds
rated_heat_HP <= 1e+07
rated_power_CHP <= 1e+07
total_opex free
Binaries
operation_HP_0 operation_HP_1 operation_HP_2 operation_CHP_0
operation_CHP_1 operation_CHP_2
End
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
I think your idea is the following: the models are equivalent in the sense that given a solution to either model, you can construct a solution to the other model with equal objective value. In particular, you should be able to flip the signs on the values of the \( \texttt{power_HP} \) and \( \texttt{gas_CHP} \) variables in any solution to the first model to obtain a solution to the second model with the same objective value (and vice versa).
If this is the case, the problem is that variables in an LP file have a lower bound of \( 0 \) unless otherwise specified. What functions do you use to add the variables to your model? In the Python API, variables added to a model using Model.addVar() or Model.addVars() have a lower bound of \( 0 \) by default. To add variables without a lower bound, add the argument \( \texttt{lb=-GRB.INFINITY} \).
0 -
Hi Eli,
thank you! The problem is solved by add the argument
0
Post is closed for comments.
Comments
3 comments