1

I am trying to use scip solver in pyomo on ubuntu 20.04 but get a strange error message when invoking the solver:

FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpxsrkdky5.pyomo.sol'

pyomo was installed via pip and scip was installed via the installer script on their download page. I was unable to install the .deb file because of dependency issues -- being on Ubuntu 20.04 instead of 18.04. The installer script installed scip in a folder in my home directory, but I do provide the path to the solver in my python script.

Minimal Working Example:

import pyomo.environ as pyo

# basic setup
Agents = list(range(10))
Values = [1, 3, 5, 3, 2, 4, 5, 6, 4, 1]
Weight = [1, 2, 3, 4, 5, 6, 4, 2, 3, 1]

# create pyo model and set variable
Dummy = pyo.ConcreteModel()
Dummy.x = pyo.Var(Agents, bounds=(0, 1))

# set objective
Dummy.obj = pyo.Objective(expr=(sum(Dummy.x[i]*Values[i] for i in Agents)))

# add a constraint
Dummy.constraint = pyo.ConstraintList()
Dummy.constraint.add(sum(Dummy.x[i]*Weight[i] for i in Agents) <= 10)

# select solver and solve problem
opt = pyo.SolverFactory('scip', executable='/path/to/solver/SCIPOptSuite-7.0.1-Linux/bin/scip')
opt.solve(Dummy)

Edit: I was not able to solve the pyomo model with scip. However, I was able to directly model and solve the problem using PySCIPOpt. The Examples in their documentation helped quite a bit.

from pyscipopt import Model, quicksum

# basic setup
Agents = list(range(10))
Values = [1, 3, 5, 3, 2, 4, 5, 6, 4, 1]
Weight = [1, 2, 3, 4, 5, 6, 4, 2, 3, 1]

#==================solve it straight with scip================================
Dummy = Model("dummy")
# vtype='C' means the variable is continuous
x = [Dummy.addVar(lb = 0, ub=1, name=("x" + str(i)), vtype='C') for i in Agents]

# set objective
Dummy.setObjective(quicksum(x[i]*Values[i] for i in Agents), sense="maximize")

# add a constraint
Dummy.addCons(quicksum(x[i]*Weight[i] for i in Agents) <= 10)

# solve problem
Dummy.optimize()
sol = Dummy.getBestSol()
print(sol)

EditEdit: Yesterday it still worked, but trying to run it again today, it returns a trivial solution and not the optimal solution.

oldmansaur
  • 163
  • 1
  • 9

1 Answers1

0

I had the same problem. The issue arises because you are pointing pyomo directly to the scip executable, rather than the AMPL interface that pyomo needs. Unfortunately, the AMPL interface does not seem to be included anymore in the pre-compiled installer (I tried the *.deb approach, and it was not there).

Luckily, though, building scipampl from the source code is very straightforward. I followed these instructions exactly with version 7.0.3: https://stackoverflow.com/a/66736905/7382307

And then in was just a matter of

from pyomo import environ as po
opt = po.SolverFactory('scipampl')

Alternatively, for those willing to use an older version (6.0), this seems to also fix the problem, at least on Windows: https://stackoverflow.com/a/56886542/7382307

billjoie
  • 808
  • 8
  • 17
  • SCIP 8 seems to have the AMPL interface built in. So you just need to install it, then use `po.SolverFactory('scip', solver_io='nl')`. `solver_io='nl'` forces Pyomo to use the AMPL interface instead of SCIP's own interface (which didn't work for me). – Matthias Fripp Jan 26 '23 at 18:13