Jasper Boekel
Jasper Boekel

Reputation: 1

How can I print part of a constraint in Pyomo

I have an AbstractModel in Pyomo and I don't want to print the full constraint since it takes quite a while since the instance is quite big (up to 5 minutes sometimes). It's an indexed constraint where the index has a length of 3000. I can print the full list of constraints by instance.balance_rule2.pprint(). Does anybody know how to retrieve just the first element?

Upvotes: 0

Views: 4422

Answers (1)

Bethany Nicholson
Bethany Nicholson

Reputation: 2828

First, you should not be printing an abstract model until after construction, i.e. only print constructed instances of the model. Every component on the model has a pprint() method so if you want to print out a constraint you can do the following:

model.con.pprint()

Alternatively, if you just want to see the constraint expression for a single index of an indexed constraint you can do the following:

print(model.con[1].expr)

Assuming that '1' is a valid index for Constraint 'con'.

Upvotes: 2

Related Questions