0

I have two sets in Pyomo, the first one is G=/GD1,GD2,GD3/, And the second one is N=/N1,N2,N3,...,N32,N33/. Naturally they have symbolic representation here for the sake of simplicity. I would like to map G into N, in order to define the relation between G and N as follows: /GD1.N2,GD2.N4,GD3.N20/

For example, in GAMS we use the command map(G,N) and define manually the new set. Is it possible to do the same in Pyomo? If the answer is yes, then how?

Thank you in advance...

2 Answers 2

0

As I understand it from the GAMS user guide, "mappings" are GAMS terminology for multi-dimensional sets. In Pyomo, you just need to declare and initialize the set:

import pyomo.environ as pyo
m = pyo.ConcreteModel()
m.G = pyo.Set(initialize=['GD1', 'GD2', 'GD3'])
m.N = pyo.Set(initialize=['N1', 'N2', 'N3', 'N4', 'N20'])
m.GN = pyo.Set(within=m.G*m.N, initialize=[('GD1', 'N2'), ('GD2', 'N4'), ('GD3', 'N20')])

Note that the "within" is optional: it performs error checking on the set members. Omitting it will still work, but will not enforce that m.GN elements are all in m.G * m.N

Sign up to request clarification or add additional context in comments.

Comments

0

There may be a pyomo-specific way, but since you write pyomo models in python you can use python's language features, including native python dictionaries:

mapGtoN = {GD1:N2, GD2:N4, GD3:N20}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.