TypeError: unsupported operand type(s) for +: 'NoneType' and 'float'
AnsweredHi,
I have a problem with my Optimization in pulp with the solver Gurobi.
The goal of my code is to determine the minimum cost of green hydrogen supply. Input are the hourly values of electricity supply from PV and wind. The optimization is written in Python with the package pulp and the solver Gurobi. The optimization works without any problems for the hourly values from January to July inclusive (5112 values). When I apply the optimization to the hourly values of a year (8760 h), the following error occurs:
--> 168 c_tot=value(prob.objective)+TLCC['Bat'] * c_Bat+ TLCC['Comp']*c_MC
169 c_tot_fullyear=c_tot/(hours*fuel_production)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'float'
This is the optimization of my code:
prob=LpProblem("System",LpMinimize)
#Energy supply System (Renewable Energy)
c_PV = LpVariable ("PVCapacity",0) #PV Capacity in kW_el
c_WT = LpVariable ("WTCapacity",0) #WT Capacity in kW_el
#Hydrogen supply System
c_EL = LpVariable ("c_EL",0) #PEM Capacity in kW
el_EL_in = LpVariable.dicts ("el_EL_in",(idx),0,None) #Inlet to PEM in kWh
h2_EL_out = LpVariable.dicts ("h2_EL_out",(idx),0,None) #Outlet to PEM in kg #Hydrogen Storage: Pressurized Tank
#Hydrogen Storage: Pressurized Tank
c_PT = LpVariable ("c_PT",0) #Pressurized Tank Capacity in kg
h2_PT_in = LpVariable.dicts ("h2_PT_in",(idx),0,None) #Inlet to Pressurized Tank in kg
h2_PT_out = LpVariable.dicts ("h2_PT_out",(idx),0,None) #Outlet to Pressurized Tank in kg
soc_PT = LpVariable.dicts ("soc_PT",(idx),0,None) #State of Charge, Pressurized Tank in kg
soc_PT[0] = 1*min_H2Storage*fuel_production
prob+= TLCC['PV']*c_PV + TLCC['WT']*c_WT + TLCC['PL']*distOff*c_WT + TLCC['EL']*c_EL + TLCC['PT']*c_PT, "TotalCostSystem"
#idx = range(len(PVdata))
for i in idx:
#Electricity system
el_source = [val_PV*c_PV*profile_pv['FLH'][i] + val_Wind*c_WT*profile_wt['FLH'][i] for i in idx] #From PV, Wind
el_demand = [el_EL_in[i] for i in idx] #Energy Used for PEM System and compression
# Electricity balance
prob += el_demand[i] <= el_source[i]
# Hydrogen system
h2_source = [h2_EL_out[i] for i in idx]
h2_supply = [h2_source[i] + h2_PT_out[i]*ETA_PT - h2_PT_in[i] for i in idx]
h2_demand = [fuel_production for i in idx] # system requirement (1 kg/h product)
# Hydrogen balance
prob += h2_demand[i] <= h2_supply[i]
# Electrolyser
h2_EL_out = [el_EL_in[i]*ETA_EL/h_u for i in idx]
prob += el_EL_in[i] <= c_EL #Size Constraint for PEM
#Hydrogen Storage
prob += (h2_PT_in[i]) <= h2_EL_out[i]
prob += soc_PT[i] * 1/(1-MIN_PT) <= c_PT #Size constraint
prob += h2_PT_in[i] <= (c_PT-soc_PT[i]) #Inlet constraint
prob += h2_PT_out[i] <= soc_PT[i] #Outlet constraint
soc_PT[i+1] = soc_PT[i] + h2_PT_in[i] - h2_PT_out[i] #State of charge constraint
prob += soc_PT[len(idx)] >= min_H2Storage*fuel_production #Final State of Charge for Pressurized Tank
prob.solve(GUROBI_CMD())
#Total cost
c_Bat=4.55 #kW_el
c_MC=1 #kW_el
c_tot=value(prob.objective)+TLCC['Bat']*c_Bat+TLCC['Comp']*c_MC
I don't understand why the optimization works for, for example, the months January to July, but when it is applied to the whole year, the error is thrown out.
Any idea what might be going wrong?
Thanks in advance!
Julia
-
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?. -
Hi Julia,
It might be that the problem becomes infeasible when you optimize over the whole year and then \(\texttt{prob.objective}\) returns a None value. You might want to check the optimization status code before accessing the objective value.
Best regards,
Jaromił0 -
Hi Jaromil,
Thank you for the feedback. I will try that out!
Julia
0
Post is closed for comments.
Comments
3 comments