メインコンテンツへスキップ

Using "AddGenConstrExp()" with pyomo.

回答済み

コメント

1件のコメント

  • Eli Towle
    • Gurobi Staff

    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:

    1. 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.
    2. 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

サインインしてコメントを残してください。