@@ -213,21 +213,15 @@ def _apply_to_impl(self, instance, **kwds):
213213 bigM = self ._config .bigM
214214 for t in preprocessed_targets :
215215 if t .ctype is Disjunction :
216- self ._transform_disjunctionData (
217- t ,
218- t .index (),
219- bigM ,
220- parent_disjunct = gdp_tree .parent (t ),
221- root_disjunct = gdp_tree .root_disjunct (t ),
222- )
216+ self ._transform_disjunctionData (t , t .index (), bigM , gdp_tree )
223217
224218 # issue warnings about anything that was in the bigM args dict that we
225219 # didn't use
226220 _warn_for_unused_bigM_args (bigM , self .used_args , logger )
227221
228- def _transform_disjunctionData (
229- self , obj , index , bigM , parent_disjunct = None , root_disjunct = None
230- ):
222+ def _transform_disjunctionData (self , obj , index , bigM , gdp_tree ):
223+ parent_disjunct = gdp_tree . parent ( obj )
224+ root_disjunct = gdp_tree . root_disjunct ( obj )
231225 (transBlock , xorConstraint ) = self ._setup_transform_disjunctionData (
232226 obj , root_disjunct
233227 )
@@ -236,7 +230,7 @@ def _transform_disjunctionData(
236230 or_expr = 0
237231 for disjunct in obj .disjuncts :
238232 or_expr += disjunct .binary_indicator_var
239- self ._transform_disjunct (disjunct , bigM , transBlock )
233+ self ._transform_disjunct (disjunct , bigM , transBlock , gdp_tree )
240234
241235 if obj .xor :
242236 xorConstraint [index ] = or_expr == 1
@@ -249,7 +243,7 @@ def _transform_disjunctionData(
249243 # and deactivate for the writers
250244 obj .deactivate ()
251245
252- def _transform_disjunct (self , obj , bigM , transBlock ):
246+ def _transform_disjunct (self , obj , bigM , transBlock , gdp_tree ):
253247 # We're not using the preprocessed list here, so this could be
254248 # inactive. We've already done the error checking in preprocessing, so
255249 # we just skip it here.
@@ -261,6 +255,12 @@ def _transform_disjunct(self, obj, bigM, transBlock):
261255
262256 relaxationBlock = self ._get_disjunct_transformation_block (obj , transBlock )
263257
258+ indicator_expression = 0
259+ node = obj
260+ while node is not None :
261+ indicator_expression += 1 - node .binary_indicator_var
262+ node = gdp_tree .parent_disjunct (node )
263+
264264 # This is crazy, but if the disjunction has been previously
265265 # relaxed, the disjunct *could* be deactivated. This is a big
266266 # deal for Hull, as it uses the component_objects /
@@ -270,13 +270,21 @@ def _transform_disjunct(self, obj, bigM, transBlock):
270270 # comparing the two relaxations.
271271 #
272272 # Transform each component within this disjunct
273- self ._transform_block_components (obj , obj , bigM , arg_list , suffix_list )
273+ self ._transform_block_components (
274+ obj , obj , bigM , arg_list , suffix_list , indicator_expression
275+ )
274276
275277 # deactivate disjunct to keep the writers happy
276278 obj ._deactivate_without_fixing_indicator ()
277279
278280 def _transform_constraint (
279- self , obj , disjunct , bigMargs , arg_list , disjunct_suffix_list
281+ self ,
282+ obj ,
283+ disjunct ,
284+ bigMargs ,
285+ arg_list ,
286+ disjunct_suffix_list ,
287+ indicator_expression ,
280288 ):
281289 # add constraint to the transformation block, we'll transform it there.
282290 transBlock = disjunct ._transformation_block ()
@@ -348,7 +356,13 @@ def _transform_constraint(
348356 bigm_src [c ] = (lower , upper )
349357
350358 self ._add_constraint_expressions (
351- c , i , M , disjunct .binary_indicator_var , newConstraint , constraint_map
359+ c ,
360+ i ,
361+ M ,
362+ disjunct .binary_indicator_var ,
363+ newConstraint ,
364+ constraint_map ,
365+ indicator_expression = indicator_expression ,
352366 )
353367
354368 # deactivate because we relaxed
0 commit comments