pyomo - Pyomo KeyError:140624460880288
问题描述
我刚开始使用 pyomo 并试图解决一个子问题,该子问题使用从主问题传递的变量的一些实现,这些变量写在另一个文件中。在尝试解决我的模型后,我得到了以下我不知道如何解释的 KeyError:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-5-7d003f1b8947> in <module>()
1 sub_opt = pyo.SolverFactory('glpk')
----> 2 sub_opt.solve(SP2.sub)
/Applications/anaconda3/lib/python3.6/site-packages/pyomo/opt/base/solvers.py in solve(self, *args, **kwds)
571 initial_time = time.time()
572
--> 573 self._presolve(*args, **kwds)
574
575 presolve_completion_time = time.time()
/Applications/anaconda3/lib/python3.6/site-packages/pyomo/opt/solver/shellcmd.py in _presolve(self, *args, **kwds)
196 self._define_signal_handlers = kwds.pop('use_signal_handling',None)
197
--> 198 OptSolver._presolve(self, *args, **kwds)
199
200 #
/Applications/anaconda3/lib/python3.6/site-packages/pyomo/opt/base/solvers.py in _presolve(self, *args, **kwds)
671 self._problem_format,
672 self._valid_problem_formats,
--> 673 **kwds)
674 total_time = time.time() - write_start_time
675 if self._report_timing:
/Applications/anaconda3/lib/python3.6/site-packages/pyomo/opt/base/solvers.py in _convert_problem(self, args, problem_format, valid_problem_formats, **kwds)
742 valid_problem_formats,
743 self.has_capability,
--> 744 **kwds)
745
746 def _default_results_format(self, prob_format):
/Applications/anaconda3/lib/python3.6/site-packages/pyomo/opt/base/convert.py in convert_problem(args, target_problem_type, valid_problem_types, has_capability, **kwds)
103 tmpkw = kwds
104 tmpkw['capabilities'] = has_capability
--> 105 problem_files, symbol_map = converter.apply(*tmp, **tmpkw)
106 return problem_files, ptype, symbol_map
107
/Applications/anaconda3/lib/python3.6/site-packages/pyomo/solvers/plugins/converter/model.py in apply(self, *args, **kwds)
86 format=ProblemFormat.cpxlp,
87 solver_capability=capabilities,
---> 88 io_options=io_options)
89 return (problem_filename,), symbol_map_id
90 else:
/Applications/anaconda3/lib/python3.6/site-packages/pyomo/core/base/block.py in write(self, filename, format, solver_capability, io_options)
1772 filename,
1773 solver_capability,
-> 1774 io_options)
1775 smap_id = id(smap)
1776 if not hasattr(self, 'solutions'):
pyomo/repn/plugins/cpxlp.pyx in pyomo.repn.plugins.cpxlp.ProblemWriter_cpxlp.__call__()
pyomo/repn/plugins/cpxlp.pyx in pyomo.repn.plugins.cpxlp.ProblemWriter_cpxlp.__call__()
pyomo/repn/plugins/cpxlp.pyx in pyomo.repn.plugins.cpxlp.ProblemWriter_cpxlp.__call__()
pyomo/repn/plugins/cpxlp.pyx in pyomo.repn.plugins.cpxlp.ProblemWriter_cpxlp._print_model_LP()
pyomo/repn/plugins/cpxlp.pyx in pyomo.repn.plugins.cpxlp.ProblemWriter_cpxlp._print_expr_canonical()
KeyError: 140624460880288
我怀疑这与从另一个模型访问变量的值有关,但我不确定。任何建议/帮助表示赞赏 - 谢谢!
解决方案
推荐阅读
- pandas - 如何将有序 dict 转换为 Pandas 数据框,每列的每个键值(“标签”)
- javascript - ' 在 Javascript 函数上使用
- javascript - 带有条件的 GAS 地图数组
- r - 如何用 NA 标记丢失的左手搭配
- python - 如何处理具有扩展用户(onetoone字段)关系django rest框架的模型的PUT请求
- c# - 如何使用 Windows 照片查看器查看二进制照片
- python-3.x - 如何使用不同形状的 DataFrame 解决“IndexError:单个位置索引器超出范围”
- python - TypeError:sort_index() 在 pandas Python 中出现意外的关键字参数“by”错误
- wordpress - 在 post_results() 过滤器之后,Wordpress 分页不考虑过滤后的帖子
- excel - 使用 mid 函数获取用户窗体的查找值?