or-fusion / pyomo_simplemodel

An extension of Pyomo that defines a simple modeling class that is similar to PuLP
Other
6 stars 6 forks source link

Omitted or dummy objectives aren't allowed in 1.0.2 #7

Closed amarvin closed 4 years ago

amarvin commented 5 years ago

Both of these seem to produce an error in v1.0.2

Not defining the objective function:

from pyomo.contrib.simplemodel import SimpleModel

m = SimpleModel()
x = m.var('x')
m += x == 1
m.solve('glpk')

results in this error traceback:

  File "/usr/local/lib/python3.6/dist-packages/pyomocontrib_simplemodel/core.py", line 177, in solve
    return solver.solve(self.model, *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/pyomo/opt/base/solvers.py", line 569, in solve
    self._presolve(*args, **kwds)
  File "/usr/local/lib/python3.6/dist-packages/pyomo/opt/solver/shellcmd.py", line 200, in _presolve
    OptSolver._presolve(self, *args, **kwds)
  File "/usr/local/lib/python3.6/dist-packages/pyomo/opt/base/solvers.py", line 669, in _presolve
    **kwds)
  File "/usr/local/lib/python3.6/dist-packages/pyomo/opt/base/solvers.py", line 740, in _convert_problem
    **kwds)
  File "/usr/local/lib/python3.6/dist-packages/pyomo/opt/base/convert.py", line 105, in convert_problem
    problem_files, symbol_map = converter.apply(*tmp, **tmpkw)
  File "/usr/local/lib/python3.6/dist-packages/pyomo/solvers/plugins/converter/model.py", line 88, in apply
    io_options=io_options)
  File "/usr/local/lib/python3.6/dist-packages/pyomo/core/base/block.py", line 1716, in write
    io_options)
  File "/usr/local/lib/python3.6/dist-packages/pyomo/repn/plugins/cpxlp.py", line 175, in __call__
    include_all_variable_bounds=include_all_variable_bounds)
  File "/usr/local/lib/python3.6/dist-packages/pyomo/repn/plugins/cpxlp.py", line 553, in _print_model_LP
    "ERROR: No objectives defined for input model. "
ValueError: ERROR: No objectives defined for input model. Cannot write legal LP file.

Dummy objective functions

from pyomo.contrib.simplemodel import SimpleModel

m = SimpleModel()
m += 1.0
x = m.var('x')
m += x == 1
m.solve('glpk')

results in this error traceback:

    prob += 1.0  # dummy objective
  File "/usr/local/lib/python3.6/dist-packages/pyomocontrib_simplemodel/core.py", line 147, in __iadd__
    elif expr.is_relational():
AttributeError: 'float' object has no attribute 'is_relational'
amarvin commented 5 years ago

Dummy objectives are now supported, but not omitted objectives. Maybe the solve() function can add a dummy objective, if there are zero objective functions defined.

whart222 commented 4 years ago

Resolved with PR #14