Using "AddGenConstrExp()" with pyomo.
AnsweredHi,
I would like to use the AddGenConstrExp() function in pyomo. Is it possible? If it is not, where can I find documentation of AddGenConstrExp() to build by my own?
Thank you.
-
Pyomo does not include any integration to Gurobi's general constraint methods like Model.addGenConstrExp(). If you use Pyomo's persistent Gurobi interface, you can access the underlying gurobipy Model object via the \(\texttt{_solver_model}\) attribute of the GurobiPersistent object. For example, the code below calls the gurobipy method Model.printStats() from Pyomo:
opt = pyo.SolverFactory("gurobi_persistent")
opt.set_instance(model, symbolic_solver_labels=True)
opt._solver_model.printStats()It's more complicated to use Model.addGenConstrExp() in this way, because you need to pass gurobipy Var objects as arguments. You can access these variable objects in one of two ways:
- From the gurobipy side: Model.getVarByName(). By setting \( \texttt{symbolic_solver_labels} \) to \( \texttt{True} \), the names of the underlying gurobipy variables (and constraints) will match the names of the corresponding Pyomo components.
- From the Pyomo side: \(\texttt{opt._pyomo_var_to_solver_var_map}\). This is a ComponentMap object (similar to a dictionary) that maps Pyomo Var objects to gurobipy Var objects.
Alternatively, you could just use Gurobi's native Python API.
0
Please sign in to leave a comment.
Comments
1 comment