Inferring algebraic form of constraints/obj. fn. from Gurobipy model

Is there a way to print the algebraic form of the constraint or the objective function in Gurobi’s Python API?

Gurobi’s Python API provides the ability to print the algebraic form of the constraint or the objective function. This can be done with the display method.

For example, given the code snippet below:

import gurobipy as gp
from gurobipy import GRB

products, price = gp.multidict({"table": 80, "chair": 45})
resources, availability = gp.multidict({"mahogany": 400, "labour": 450})

bom = {
    ("mahogany", "chair"): 5,
    ("mahogany", "table"): 20,
    ("labour", "chair"): 10,
    ("labour", "table"): 15,
}

model = gp.Model("furniture")

make = model.addVars(products, name="make", obj=list(price.values()), vtype=GRB.INTEGER)

res = model.addConstrs(
    gp.quicksum(bom[r, p] * make[p] for p in products) <= availability[r]
    for r in resources
)

model.ModelSense = GRB.MAXIMIZE
model.optimize()

To print the algebraic form of the constraints or the objective function, use the display method:

model.display()

This will print the algebraic form of the constraints and the objective function.

Yes, there is a way to print the algebraic form of the constraint or the objective function in Gurobi’s Python API. You can use the display method to achieve this. Here is an example of how to do it:

model.display()

This will print the algebraic form of the constraints and the objective function.