Open
Description
Summary
When running with gurobi_direct
, I get a failure when I specify the WORK_LIMIT
and the WORK_LIMIT
gets exceeded
Steps to reproduce the issue
# example.py
import pyomo.environ as pyo
from pyomo.opt import SolverFactory
import numpy as np
# Number of cities
num_cities = 100
# Distance matrix (symmetric)
np.random.seed(42) # For reproducibility
distances = np.random.randint(1, 100, size=(num_cities, num_cities))
distances = (distances + distances.T) // 2 # Make the matrix symmetric
np.fill_diagonal(distances, 0) # Set diagonal to 0
# Create a Concrete Model
model = pyo.ConcreteModel()
# Sets
model.CITIES = pyo.RangeSet(num_cities - 1)
model.EDGES = pyo.Set(initialize=[(i, j) for i in range(num_cities) for j in range(num_cities) if i != j])
# Variables
model.x = pyo.Var(model.EDGES, within=pyo.Binary)
# Objective function
def objective_rule(model):
return sum(model.x[i, j] * distances[i, j] for i, j in model.EDGES)
model.obj = pyo.Objective(rule=objective_rule, sense=pyo.minimize)
# Constraints
def degree_rule(model, i):
return sum(model.x[i, j] for j in range(num_cities) if i != j) == 1
model.degree = pyo.Constraint(model.CITIES, rule=degree_rule)
def degree_rule_2(model, j):
return sum(model.x[i, j] for i in range(num_cities) if i != j) == 1
model.degree_2 = pyo.Constraint(model.CITIES, rule=degree_rule_2)
# Subtour elimination constraints
model.u = pyo.Var(model.CITIES, within=pyo.NonNegativeIntegers, bounds=(0, num_cities-1))
def subtour_elimination_rule(model, i, j):
if i != j and (i != 0 and j != 0):
return model.u[i] - model.u[j] + model.x[i, j] * num_cities <= num_cities - 1
return pyo.Constraint.Skip
model.subtour_elimination = pyo.Constraint(model.EDGES, rule=subtour_elimination_rule)
# Solve the model
solver = SolverFactory('gurobi_direct')
solver.options["WorkLimit"] = 1.0
results = solver.solve(model, tee=True)
Error Message
Explored 1 nodes (1344 simplex iterations) in 1.01 seconds (1.00 work units)
Thread count was 16 (of 16 available processors)
Solution count 10: 974 1008 1032 ... 1833
Work limit reached
Best objective 9.740000000000e+02, best bound 9.550000000000e+02, gap 1.9507%
---> 50 results = solver.solve(model, tee=True)
File .venv/lib/python3.10/site-packages/pyomo/solvers/plugins/solvers/direct_solver.py:198, in DirectSolver.solve(self, *args, **kwds)
196 else:
197 if self._load_solutions:
--> 198 _model.solutions.load_from(
199 result,
200 select=self._select_index,
201 default_variable_value=self._default_variable_value,
202 )
203 result._smap_id = None
204 result.solution.clear()
File .venv/lib/python3.10/site-packages/pyomo/core/base/PyomoModel.py:231, in ModelSolutions.load_from(self, results, allow_consistent_values_for_fixed_vars, comparison_tolerance_for_fixed_vars, ignore_invalid_labels, id, delete_symbol_map, clear, default_variable_value, select, ignore_fixed_vars)
226 logger.warning(
227 "Loading a SolverResults object with "
228 "an 'aborted' status, but containing a solution"
229 )
230 else:
--> 231 raise ValueError(
232 "Cannot load a SolverResults object "
233 "with bad status: %s" % str(results.solver.status)
234 )
235 if clear:
236 #
237 # Clear the solutions, but not the symbol map
238 #
239 self.clear(clear_symbol_maps=False)
ValueError: Cannot load a SolverResults object with bad status: error
Information on your system
Pyomo version: 6.8.2
Python version: 3.10.16
Operating system: 15.1.1
How Pyomo was installed (PyPI, conda, source): PyPI
Solver (if applicable): Gurobi Compute Server
Additional information
It is unclear to me why this is failing based on this code:
pyomo/pyomo/solvers/plugins/solvers/GUROBI_RUN.py
Lines 176 to 180 in 038f38b