Skip to content
Advertisement

Switching to Pyomo – Syntax issue with sets

I have used the algebraic modelling language AMPL but I’m now making the switch to python and Pyomo.

I’m struggling a bit with its syntax though. In AMPL I would have something like this:

JavaScript

How can I implement the last line in Pyomo?

Any help is much appreciated, thank you!

Best regards, Johannes

Advertisement

Answer

Welcome to the site.

Below is an example that I think does what you want. There are many ways to build a sparse set in pyomo. You can do it “on the side” in pure python (like example below) using set comprehensions or whatever or you can create a rule that returns same. There is a decent example in the documentation.

JavaScript

Yields:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement