BlockList

44 views
Skip to first unread message

Christian Øyn Naversen

unread,
Mar 29, 2019, 10:13:09 AM3/29/19
to Pyomo Forum
Hello!

I've been implementing some different decomposition schemes in Pyomo, and liked using ConstraintList for adding cuts in Benders decomp.
As far as I know, there is no corresponding BlockList object, which would be useful when implementing things like the column-and-constraint generation technique of robust optimization. 
I think a BlockList would be a good addition to Pyomo.

Gabriel Hackebeil

unread,
Mar 29, 2019, 11:28:28 AM3/29/19
to Pyomo Forum
You might consider trying the pyomo.kernel modeling interface. It includes a list-like and dict-like container for basically every modeling component, including blocks (which are equivalent to ConcreteModel). A side-by-side comparison of syntax can be found here.

Gabe

--
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.

Siirola, John D

unread,
Mar 29, 2019, 1:55:39 PM3/29/19
to pyomo...@googlegroups.com

The VarList / ConstraintList components are actually very thin wrappers around normal Var / Constraint containers.  The easiest way to mock up a simple equivalent for Block with:

 

model.blockList = Block(Any)

 

The “Any” set will admit any index, so you can add a new block (in a manner similar to ConstraintList) with something like:

 

                b = model.blockList[len(model.blockList)]

 

…that is, you will get blocks indexed by a list of integers starting with 0.

 

Alternatively, you can do a nearly identical replication of ConstraintList with an explicit Set:

 

                model.blockList_index = Set()

                model.blockList = Block(model.blockList_index)

 

To add a new block, you first need to add the new index to the underlying set:

 

                def add(model):

                    i = len(model.blockList) + 1  # 1-indexed like ConstraintList

    model.blockList_index.add(i)

                    return model.blockList[i]

 

john

Christian Øyn Naversen

unread,
Apr 1, 2019, 4:47:07 AM4/1/19
to pyomo...@googlegroups.com
Thank you all for the input!

I actually attended the PyomoFest workshop in Kassel, Germany last week where I raised the same questions regarding BlockList. The attending developers encouraged me to also post it here.
I got the same suggestion to use the Any set to index my Blocks by Carl L., but it didn't actually work when he tested it. I believe the issue was related to a Block needing its parent when created (or something like that).
I'm not sure if this will also affect the other methods proposed here, but I still think an explicit BlockList component is a decent idea.

CØN

Siirola, John D

unread,
Apr 1, 2019, 6:21:55 AM4/1/19
to pyomo...@googlegroups.com
Carl emailed me off-list as well. His approach was slightly different from what I posted here. In particular, he tried to “explicitly” add blocks to the Any-indexed block with:

    model.blockList[i] = Block()

This syntax does not currently work due to what looks like a bug in Block’s implementation of set_value(). While that syntax could be made to work (its been added to my backlog of things to look into), it is conceptually different from the way we handle other components (and causes Python/Pyomo to do extra unnecessary work).

John
Reply all
Reply to author
Forward
0 new messages