• Gurobi Staff

Hi Victor,

You can query the Pi attribute on each linear constraint. The script below returns the Pi attribute for a specific constraint named $$\texttt{c0}$$.

# Access the constraint via its namec = model.getConstrByName("c0")# Query the Pi attribute on the linear constraint cpi = c.Pi

Best regards,

Maliheh

Dear Maliheh,

Thank you so much for your message. However, I have problems getting these values for a matrix LP formulation. The optimization problem is modeled using model.addMVar() function.

Best Regards,

Victor

• Gurobi Staff

The Model.getConstrByName() method can be used regardless of how the variables are defined. Since you are using the Gurobi Matrix API, you can retrieve the constraint attributes more efficiently. Please see the example script below.

import numpy as npA, b = np.ones((5, 10)), np.ones((5, 5))model = gp.Model()x = model.addMVar(shape=(10, 5), name="x")# Add constraints Ax <= b. This will add 25 constraints to the model. The constraints # are named as c0[0,0], c0[0,1], ..., c0[4,4]. In other words, the scalar name given # is subscripted by the index of the constraints in the matrixc = model.addConstr(A @ x <= b, name="c0")model.optimize()# Since c is an <MConstr (5, 5)> object, calling c.Pi returns # a numpy array with shape (5, 5) where pi[i,j] equals the Pi attribute for # constraint named as c0[i,j]pi = c.Pi# Alternatively, you can do the following to query the Pi attribute for a specific # constraint named "c0[0,4]", for example:c0_04 = model.getConstrByName("c0[0,4]")pi_04 = c0_04.Pi

Best regards,

Maliheh

Dear Maliheh,

Thank you so much for your message and support. I got the Lagrange multipliers.

Best Regards,

Victor