from pyomo.common.collections import ComponentSet cs = ComponentSet() # add components to the ComponentSet cs.add("component1") cs.add("component2") cs.add("component3") # print the ComponentSet print(cs)
from pyomo.common.collections import ComponentSet cs1 = ComponentSet(["component1", "component2"]) cs2 = ComponentSet(["component2", "component3"]) # union of cs1 and cs2 union = cs1 | cs2 # intersection of cs1 and cs2 intersection = cs1 & cs2 # difference of cs1 and cs2 difference = cs1 - cs2 # symmetric difference of cs1 and cs2 symmetric_difference = cs1 ^ cs2 # print the results print("Union:", union) print("Intersection:", intersection) print("Difference:", difference) print("Symmetric Difference:", symmetric_difference)
Union: ComponentSet({'component1', 'component2', 'component3'}) Intersection: ComponentSet({'component2'}) Difference: ComponentSet({'component1'}) Symmetric Difference: ComponentSet({'component1', 'component3'})Package Library: pyomo.