首页 > 解决方案 > 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

我怀疑这与从另一个模型访问变量的值有关,但我不确定。任何建议/帮助表示赞赏 - 谢谢!

标签: pyomo

解决方案


推荐阅读