为什么我在 docplex 中没有属性?
Why do i get no attribute in docplex?
我是 运行 docplex 中的优化代码,但由于某种原因我收到错误消息:
AttributeError: 'NoneType' object has no attribute 'get_value_dict'
此错误指的是行:
prod_hpp_grid_ts = pd.DataFrame.from_dict(sol.get_value_dict(prod_hpp_grid_t), orient='index')
在下面的代码中。知道为什么会这样吗?
def sizing_Wind_Solar_Hydrogen(self, prod_wtg_t, prod_pv_t, price_spot):
globals().update(self.__dict__)
mdl = Model(name='Sizing')
time = price_spot.index
prod_hpp_t = mdl.continuous_var_dict(time, lb=0, name='Power produced by HPP')
.
.
.
'''
Other variables
'''
mdl.maximize(
-(cost_invest_wtg * cap_wtg)
.
.
.
'''
Rest of optimization model
'''
for t in time:
tt = t + pd.Timedelta('1hour')
ttt = t - pd.Timedelta('1hour')
dt = 1
mdl.add_constraint(prod_hpp_t[t] == prod_wtg_t[t] * cap_wtg + prod_pv_t[t] * cap_pv )
.
.
.
'''
Other constraints
'''
sol = mdl.solve(log_output=False)
prod_hpp_grid_ts = pd.DataFrame.from_dict(sol.get_value_dict(prod_hpp_grid_t), orient='index')
prod_hpp_grid_ts = prod_hpp_grid_ts.reset_index()
P_curt = pd.DataFrame.from_dict(sol.get_value_dict(P_curt), orient='index')
P_curt = P_curt.reset_index()
.
.
.
'''
Other solutions
'''
return sol.get_value(cap_wtg), sol.get_value(cap_pv), prod_hpp_grid_ts[0], \
P_curt[0], cost_invest_hpp, cost_onm_hpp, LCOE, NPV, IRR
溶胶是 None。当 solve 方法找不到可行的解决方案时,就会发生这种情况。请参阅文档:http://ibmdecisionoptimization.github.io/docplex-doc/mp/docplex.mp.model.html#docplex.mp.model.Model.solve
我是 运行 docplex 中的优化代码,但由于某种原因我收到错误消息:
AttributeError: 'NoneType' object has no attribute 'get_value_dict'
此错误指的是行:
prod_hpp_grid_ts = pd.DataFrame.from_dict(sol.get_value_dict(prod_hpp_grid_t), orient='index')
在下面的代码中。知道为什么会这样吗?
def sizing_Wind_Solar_Hydrogen(self, prod_wtg_t, prod_pv_t, price_spot):
globals().update(self.__dict__)
mdl = Model(name='Sizing')
time = price_spot.index
prod_hpp_t = mdl.continuous_var_dict(time, lb=0, name='Power produced by HPP')
.
.
.
'''
Other variables
'''
mdl.maximize(
-(cost_invest_wtg * cap_wtg)
.
.
.
'''
Rest of optimization model
'''
for t in time:
tt = t + pd.Timedelta('1hour')
ttt = t - pd.Timedelta('1hour')
dt = 1
mdl.add_constraint(prod_hpp_t[t] == prod_wtg_t[t] * cap_wtg + prod_pv_t[t] * cap_pv )
.
.
.
'''
Other constraints
'''
sol = mdl.solve(log_output=False)
prod_hpp_grid_ts = pd.DataFrame.from_dict(sol.get_value_dict(prod_hpp_grid_t), orient='index')
prod_hpp_grid_ts = prod_hpp_grid_ts.reset_index()
P_curt = pd.DataFrame.from_dict(sol.get_value_dict(P_curt), orient='index')
P_curt = P_curt.reset_index()
.
.
.
'''
Other solutions
'''
return sol.get_value(cap_wtg), sol.get_value(cap_pv), prod_hpp_grid_ts[0], \
P_curt[0], cost_invest_hpp, cost_onm_hpp, LCOE, NPV, IRR
溶胶是 None。当 solve 方法找不到可行的解决方案时,就会发生这种情况。请参阅文档:http://ibmdecisionoptimization.github.io/docplex-doc/mp/docplex.mp.model.html#docplex.mp.model.Model.solve