gurobi to pyomo conversion

Asked 2 years ago, Updated 2 years ago, 99 views

I want to change python from gurobi to pyomo, but I don't know how to do it.

from gurobipy import*
import pandas aspd
import numpy as np
import csv
from pyomo.environ import SolverFactory
opt=SolverFactory("optimizer", solver_io="python")
opt.solve (model, tee=True)
opt.options['NonConvex'] = 2

After that, I inserted data using pandas from excel.

model=Model("optimizer")
model.params.NonConvex=2

and ran the gurobi program.
The error message is

untimeError: Attempting to use an unavailable solver.

The SolverFactory was unable to create the solver "optimizer"
and returned an UnknownSolver object.This error is raised at the point
where the UnknownSolver object was used as if it were valid (by calling)
method "solve")

The original solver was created with the following parameters:
    executable:optimizer
    solver_io —python
    type —Optimizer
    _args:()
    options:{}

https://pyomo.readthedocs.io/en/stable/working_models.html?highlight=options#sending-options-to-the-solver
I was going to use this site to make various changes, but there are many things I don't understand.
For example,

 results=optimizer.solve (instance, options="threads=4", tee=True)

Do I need to change both the formula constants and variables to "optimizer.solve"?
Are you only changing the dictionary notation?
Is it not necessary to change the int type or list?
Also, should I change all ( ) to instance?

s={(1:2, 2:3, 3:5, 4:5)}
d = {(1,1):1(1,2):2(1:3):3(1:4):4
  (1,1):3(1,2):4(1:3):5(1:4):6}

How can I change the s,d above?
"options="=dict name=dict count"
Is there anything else I should add?
For example, please let me know if there are any constraint expressions or objective functions.
I'm a beginner, so I'd appreciate it if you could tell me as much detail as possible.

python python3 pandas algorithm data-structure

2022-09-30 20:17

1 Answers

"The source code contains a list of gurobi options available in pyomo, but ""NonConvex"" is not listed there, so I don't think I can set it up."

https://github.com/Pyomo/pyomo/blob/2e57707a4bd0aab98df7cb9b0c78e984013fac62/pyomo/solvers/plugins/solvers/gurobi_direct.py

#Options accepted by gurobi (case insensitive):
    # ['Cutoff', 'IterationLimit', 'NodeLimit', 'SolutionLimit', 'TimeLimit',
    #  'FeasibilityTol', 'IntFeasTol', 'MarkowitzTol', 'MIPGap', 'MIPGapAbs',
    #  'OptimalityTol', 'PSDTol', 'Method', 'PerturbValue', 'ObjScale', 'ScaleFlag',
    #  'SimplexPricing', 'Quad', 'NormAdjust', 'BarIterLimit', 'BarConvTol',
    #  'BarCorrectors', 'BarOrder', 'Crossover', 'CrossoverBasis', 'BranchDir',
    #  'Heuristics', 'MinRelNodes', 'MIPFocus', 'NodefileStart', 'NodefileDir',
    #  'NodeMethod', 'PumpPasses', 'RINS', 'SolutionNumber', 'SubMIPNodes', 'Symmetry',
    #  'VarBranch', 'Cuts', 'CutPasses', 'CliqueCuts', 'CoverCuts', 'CutAggPasses',
    #  'FlowCoverCuts', 'FlowPathCuts', 'GomoryPasses', 'GUBCoverCuts', 'ImplifiedCuts',
    #  'MIPSepCuts', 'MIRCuts', 'NetworkCuts', 'SubMIPCuts', 'ZeroHalfCuts', 'ModKCuts',
    #  'Aggregate', 'AggFill', 'PreDual', 'DisplayInterval', 'IISMethod', 'InfUnbdInfo',
    #  'LogFile', 'PreCrush', 'PreDepRow', 'PreMIQPMethod', 'PrePasses', 'Presolve',
    #  'ResultFile', 'ImproveStartTime', 'ImproveStartGap', 'Threads', 'Dummy', 'OutputFlag']


2022-09-30 20:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.