Skip to content

Cannot solve quadratic problem with Highs solver #3381

Open
@mhechthz

Description

@mhechthz

I'm on Windows 11. I have HiGHS version 1.7.2 Githash 5ce7a2753. Copyright (c) 2024 HiGHS under MIT licence terms in a given directory (EDIT: same problem with AMPL/HiGHS Optimizer [1.7.1] (Windows AMD64), driver(20240724), MP(20240724)).

This program (standard solver factory doesn't accept 'highs' argument which is another bug):

import os
from pyomo.environ import ConcreteModel, Var, Objective, NonNegativeReals, Constraint
from pyomo.contrib.appsi.solvers import Highs

# Set the environment variable PATH to include the directory of HiGHS executable
os.environ['PATH'] += os.pathsep + r"C:\bin\Highs\bin"

# Define the model
model = ConcreteModel("MyModel")

# Variables (Renamed to x1 and x2)
model.x1 = Var(name='x1', domain=NonNegativeReals)
model.x2 = Var(name='x2', domain=NonNegativeReals)

# Quadratic Objective function
model.obj = Objective(expr=model.x1 + model.x2 , sense=1)  # Minimize

# Constraints
model.con1 = Constraint(expr=model.x1 + 2 * model.x2 >= 1)
model.con2 = Constraint(expr=3 * model.x1 + 4 * model.x2 <= 2)

# Instantiate the HiGHS solver directly via APPSI
solver = Highs()

# Solve the model
results = solver.solve(model)

# Display the results
print("Termination Condition:", results.termination_condition)

# Print the values of the variables
print(f"x1 = {model.x1.value}")
print(f"x2 = {model.x2.value}")

# Display full model details
print()
model.display()

works well but changing objective to

model.obj = Objective(expr=model.x1*model.x1 + model.x2*model.x2, sense=1)

results in

Traceback (most recent call last):
  File "C:\Micha\Programming\Python\Optimierung\highs_pyomo.py", line 26, in <module>
    results = solver.solve(model)
              ^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\pyomo\contrib\appsi\solvers\highs.py", line 263, in solve
    self.set_instance(model)
  File "C:\Python312\Lib\site-packages\pyomo\contrib\appsi\solvers\highs.py", line 383, in set_instance
    self.add_block(model)
  File "C:\Python312\Lib\site-packages\pyomo\contrib\appsi\base.py", line 1128, in add_block
    self.set_objective(obj)
  File "C:\Python312\Lib\site-packages\pyomo\contrib\appsi\base.py", line 1083, in set_objective
    self._set_objective(obj)
  File "C:\Python312\Lib\site-packages\pyomo\contrib\appsi\solvers\highs.py", line 595, in _set_objective
    raise DegreeError(
pyomo.contrib.appsi.solvers.highs.DegreeError: Highs interface does not support expressions of degree None

Solving the corresponding lp file model.write('model_output.lp', format='lp') on commandline using highs.exe works (after some syntactic corrections).

EDIT: Changing the line 591ff in highs.py

            repn = generate_standard_repn(
                obj.expr, quadratic=False, compute_values=False
            )

from quadratic=False to quadratic=True removes the error and solution is produced.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions