Changeset 2199


Ignore:
Timestamp:
Jan 29, 2010 9:57:20 AM (10 years ago)
Author:
jwatson
Message:

Fixed linearization issue in PH when a variable lower and upper bounds are equal

File:
1 edited

Legend:

Unmodified
Added
Removed
  • coopr.pysp/trunk/coopr/pysp/ph.py

    r2169 r2199  
    3737   # routine to compute linearization breakpoints uniformly between the bounds and the mean.
    3838   #
     39
     40   # IMPT: In general, the breakpoint computation codes can return a 2-list even if the lb equals
     41   #       the ub. This case happens quite often in real models (although typically lb=xvag=ub).
     42   #       See the code for constructing the pieces on how this case is handled in the linearization.
    3943   
    4044   def compute_uniform_breakpoints(self, lb, node_min, xavg, node_max, ub, num_breakpoints_per_side):
     
    108112      breakpoints.append(ub)
    109113
    110       # add the mean - it's always a breakpoint. unless!
     114      # add the mean - it's always a breakpoint. unless! -
    111115      # it happens to be equal to (within tolerance) the lower or upper bounds.
    112116      # sort to insert it in the correct place.
     
    375379   # on this piece, variable is the actual instance variable, and average is the instance
    376380   # parameter specifying the average of this variable across instances sharing passing
    377    # through a common tree node. lb and ub are floats.
     381   # through a common tree node. lb and ub are floats.
     382   # IMPT: There are cases where lb=ub, in which case the slope is 0 and the intercept
     383   #       is simply the penalty at the lower(or upper) bound.
    378384   def _create_piecewise_constraint_expression(self, lb, ub, instance_variable, variable_average, quad_variable):
    379385
    380386      penalty_at_lb = (lb - variable_average()) * (lb - variable_average())
    381387      penalty_at_ub = (ub - variable_average()) * (ub - variable_average())
    382       slope = (penalty_at_ub - penalty_at_lb) / (ub - lb)
     388      slope = None
     389      if fabs(ub-lb) > self._integer_tolerance:
     390         slope = (penalty_at_ub - penalty_at_lb) / (ub - lb)
     391      else:
     392         slope = 0.0
    383393      intercept = penalty_at_lb - slope * lb
    384394      expression = (0.0, quad_variable - slope * instance_variable - intercept, None)
Note: See TracChangeset for help on using the changeset viewer.