Can I initialize a Set() in pyomo with a list of sets? In other words, I'd like to do something like this:
from pyomo.environ import *
model = AbstractModel()
a = set([1,2,3])
b = set([4,5,6])
model.c = Set(initialize = [a,b])
instance = model.create_instance()
Unfortunately, this gives me an error:
ERROR: Constructing component 'a' from data=None failed:
TypeError: Problem inserting set([1, 2, 3]) into set c
Is there another way to achieve the same effect that I am missing?
TL;DR: I am working on a network interdiction model. My model Set represents a set of paths in the network. I want to use (python) sets to store the paths, because the model constraints are limited to feasible paths. Thus, I need to check if any edge in the path is interdicted, and the hash function will allow me to efficiently check if an interdicted edge is incident on a path. In other words, I have a function later on:
def is_feasible(model, path):
return any([edge in path and model.Interdicts[edge].value] for edge in model.edges)
where path is an element of my Set, and model.Interdicts is a Var(model.edges, within = binary)
My fallback has been to initialize my Set with indices that references paths in an external list, but then I'm having to mix my pyomo model with non-model elements to evaluate the model constraints, which is a real headache (but then so is most network interdiction modeling ...)