Adding name to constraints

976 views
Skip to first unread message

Suhas Pai

unread,
Jun 14, 2019, 8:21:46 AM6/14/19
to Pyomo Forum
Hey guys, 
I'm using a constraint list for a concrete model, cause the number of constraints I have is around 50k, and so it's much easier using a constraint list and adding expressions. Is there any way I can add names to this constraints as well. As of now the Pyomo Documentation has the doc argument only for constraints of the form : Model.c=Constraint(expr=whatever,doc='Name of constraint')
However, I want to add names to constraints like this:
Model.l=ConstraintList()
Model.l.add(Model.x+ Model.y >=2,name='Name of constraint')
Is there any way this can be done?

Thanks in advance
Suhas

Bynum, Michael Lee

unread,
Jun 14, 2019, 8:25:49 AM6/14/19
to pyomo...@googlegroups.com
import pyomo.environ as pyo

create model and variables

m.c = pyo.Constraint(pyo.Any)
m.c[name1] = m.x + m.y == 1
m.c[name2] = …

I hope this helps. 

Michael

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyomo-forum/a24eac0e-5fdb-4f88-9f56-dd265b6b6d05%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Suhas Pai

unread,
Jun 16, 2019, 11:48:40 PM6/16/19
to Pyomo Forum
Hey,
When I generate the .gams file for this, the names of the constraints still dont show up in it.

Suhas


On Friday, June 14, 2019 at 5:55:49 PM UTC+5:30, Michael Bynum wrote:
import pyomo.environ as pyo

create model and variables

m.c = pyo.Constraint(pyo.Any)
m.c[name1] = m.x + m.y == 1
m.c[name2] = …

I hope this helps. 

Michael

On Jun 14, 2019, at 2:29 AM, Suhas Pai <suhasp...@gmail.com> wrote:

Hey guys, 
I'm using a constraint list for a concrete model, cause the number of constraints I have is around 50k, and so it's much easier using a constraint list and adding expressions. Is there any way I can add names to this constraints as well. As of now the Pyomo Documentation has the doc argument only for constraints of the form : Model.c=Constraint(expr=whatever,doc='Name of constraint')
However, I want to add names to constraints like this:
Model.l=ConstraintList()
Model.l.add(Model.x+ Model.y >=2,name='Name of constraint')
Is there any way this can be done?

Thanks in advance
Suhas

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo...@googlegroups.com.

Nicholson, Bethany L.

unread,
Jun 17, 2019, 10:32:19 AM6/17/19
to pyomo...@googlegroups.com

If you want constraint names to show up in the Gams file you need to add “symbolic_solver_labels=True” to your call to the solver:

 

solver.solve(model, symbolic_solver_labels=True)

To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyomo-forum/7063e1d5-10f6-4d09-84da-0bacbcadf618%40googlegroups.com.

Suhas Pai

unread,
Jun 18, 2019, 12:21:29 AM6/18/19
to Pyomo Forum
Yep this worked, I set it in the io_options for the model.write function.
Thanks!
Reply all
Reply to author
Forward
0 new messages