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.