Search code examples
pyomo

Pyomo: Unable to print set list


Edit: I realized that my initial model was set up as an AbstractModel and so because the model data and model framework are separated, it would of course show that the set was empty. However, if you change your model to a ConcreteModel and repeat, you'll find that the function will work. Of course, make sure things are case sensitive too!

I am just trying to learn and experiment with Pyomo. I have the following piece of code from the book that I am trying to run:

model.A = Set(initialize=[1,2,3])
print(len(model.a))

I should get 3. However, I get this:

    'WARNING: Implicitly replacing the Component attribute A (type=<class pyomo.core.base.sets.SimpleSet'>) on block unknown with a new Component
    (type=<class 'pyomo.core.base.sets.SimpleSet'>). This is usually
    indicative of a modelling error. To avoid this warning, use
    block.del_component() and block.add_component().
0

Solution

  • I realized that my initial model was set up as an AbstractModel and so because the model data and model framework are separated, it would of course show that the set was empty. However, if you change your model to a ConcreteModel and repeat, you'll find that the function will work. Of course, make sure things are case sensitive too!