diff --git a/pyomo/contrib/fme/fourier_motzkin_elimination.py b/pyomo/contrib/fme/fourier_motzkin_elimination.py index 021650e8f9a..ad3a6b5aeb2 100644 --- a/pyomo/contrib/fme/fourier_motzkin_elimination.py +++ b/pyomo/contrib/fme/fourier_motzkin_elimination.py @@ -730,12 +730,9 @@ def post_process_fme_constraints( continue # deactivate the constraint projected_constraints[i].deactivate() - m.del_component(obj) - # make objective to maximize its infeasibility - obj = Objective( - expr=projected_constraints[i].body - projected_constraints[i].lower - ) - m.add_component(obj_name, obj) + # Our constraint looks like: 0 <= a^Tx - b, so make objective to + # maximize its infeasibility + obj.expr = projected_constraints[i].body - projected_constraints[i].lower results = solver_factory.solve(m) if results.solver.termination_condition == TerminationCondition.unbounded: obj_val = -float('inf') @@ -753,13 +750,13 @@ def post_process_fme_constraints( obj_val = value(obj) # if we couldn't make it infeasible, it's useless if obj_val >= tolerance: - m.del_component(projected_constraints[i]) del projected_constraints[i] else: projected_constraints[i].activate() # clean up m.del_component(obj) + del obj for obj in active_objs: obj.activate() # undo relax integrality diff --git a/pyomo/core/base/block.py b/pyomo/core/base/block.py index 656bf6008c4..de94dbe8ae8 100644 --- a/pyomo/core/base/block.py +++ b/pyomo/core/base/block.py @@ -34,6 +34,7 @@ from pyomo.common.timing import ConstructionTimer from pyomo.core.base.component import ( Component, + ComponentData, ActiveComponentData, ModelComponentFactory, ) @@ -1139,6 +1140,14 @@ def del_component(self, name_or_object): # return name = obj.local_name + if isinstance(obj, ComponentData) and not isinstance(obj, Component): + raise ValueError( + "Argument '%s' to del_component is a ComponentData object. Please " + "use the Python 'del' function to delete members of indexed " + "Pyomo objects. The del_component function can only be used to " + "delete IndexedComponents and ScalarComponents." % name + ) + if name in self._Block_reserved_words: raise ValueError( "Attempting to delete a reserved block component:\n\t%s" % (obj.name,) diff --git a/pyomo/core/base/component.py b/pyomo/core/base/component.py index a5763264b14..5aa260cd9b2 100644 --- a/pyomo/core/base/component.py +++ b/pyomo/core/base/component.py @@ -732,11 +732,7 @@ class ComponentData(ComponentBase): This is the base class for the component data used in Pyomo modeling components. Subclasses of ComponentData are used in indexed components, and this class assumes that indexed - components are subclasses of IndexedComponent. Note that - ComponentData instances do not store their index. This makes - some operations significantly more expensive, but these are (a) - associated with I/O generation and (b) this cost can be managed - with caches. + components are subclasses of IndexedComponent. Constructor arguments: owner The component that owns this data object