0
$\begingroup$

I want to know how I can check constraints like https://www.gurobi.com/documentation/current/refman/py_model_agc_indicator.html in my model using something like model.disply() function. E.g. for the following dummy example:

import gurobipy as gp

model = gp.Model()

x = model.addVar(vtype=gp.GRB.BINARY, name="x")
y = model.addVar(vtype=gp.GRB.BINARY, name="y")
a = model.addVar(vtype=gp.GRB.BINARY, name="a")


z = model.addVar(vtype=gp.GRB.CONTINUOUS, name="z", ub=30)
model.addGenConstrAnd(a, [x, y], "andconstr")

model.update()

# constr1 = model.addConstr(z <= 20)
constr2 = model.addConstr((a == 0) >> (z <= 5))

model.setObjective(z+x+y+a, gp.GRB.MAXIMIZE)

model.update()
# Solve the model
model.optimize()
model.display()

calling model.display() will only show me the following:

Maximize
  x + y + a + z
Subject To
Bounds
  0 <= z <= 30
Binaries
  ['x', 'y', 'a']

and it dos not show anything regarding:

model.addGenConstrAnd(a, [x, y], "andconstr")

or:

constr2 = model.addConstr((a == 0) >> (z <= 5))

Is there a way to see such information in Gurobi model.display() or some similar function?

$\endgroup$
1
  • 1
    $\begingroup$ tried model.write('model.lp') or model.write('model.mps')? $\endgroup$ Commented Mar 5, 2023 at 20:49

1 Answer 1

0
$\begingroup$

Use model.write('filename.lp') or model.write('filename.mps'). AND constraint will appear in the section General constraints(lp) or GENCONS(mps).

Subject To
 GC1: a = 0 -> z <= 5
Bounds
 z <= 30
Binaries
 x y a
General Constraints
 andconstr: a = AND ( x , y )
$\endgroup$
2
  • $\begingroup$ Is there a way to get the same results without writing results into a file? $\endgroup$ Commented Mar 5, 2023 at 21:20
  • 1
    $\begingroup$ This I'd put to Gurobi community portal. They'd be best placed to respond or they can use your input as feature improvement in next version. $\endgroup$ Commented Mar 5, 2023 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.