Changing a Set

36 views
Skip to first unread message

Bryan Arguello

unread,
Feb 27, 2016, 9:53:09 AM2/27/16
to Pyomo Forum
Part of my algorithm requires adding an element to one of my sets during each iteration.

I am wondering two things:

1. How can I add one element to a Set in my instance after the instance has been constructed?

2. How can I change the set completely?

Watson, Jean-Paul

unread,
Feb 27, 2016, 1:59:45 PM2/27/16
to pyomo...@googlegroups.com
You can add elements to sets on-the-fly, e.g., with the add() method. You can also clear() them, and start over from scratch. The bigger problem is making sure that components that depend on the newly modified set. In particular, you may have to re-construct (via a reconstruct()) any constraints / variables / parameters that are indexed by the set. 

If you are simply doing something iteratively (like benders) and are using a ConcreteModel, you can add the new element of the set and then add the a single new expression, indexed by the new set element. 

If you can post a bit more on the use case, we can provide more guidance.

jpw

--
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.
For more options, visit https://groups.google.com/d/optout.

Bryan Arguello

unread,
Feb 28, 2016, 12:59:40 AM2/28/16
to Pyomo Forum
That worked perfectly. Thanks, jp!
Reply all
Reply to author
Forward
0 new messages