Changeset 2199
 Timestamp:
 Jan 29, 2010 9:57:20 AM (10 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

coopr.pysp/trunk/coopr/pysp/ph.py
r2169 r2199 37 37 # routine to compute linearization breakpoints uniformly between the bounds and the mean. 38 38 # 39 40 # IMPT: In general, the breakpoint computation codes can return a 2list 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. 39 43 40 44 def compute_uniform_breakpoints(self, lb, node_min, xavg, node_max, ub, num_breakpoints_per_side): … … 108 112 breakpoints.append(ub) 109 113 110 # add the mean  it's always a breakpoint. unless! 114 # add the mean  it's always a breakpoint. unless!  111 115 # it happens to be equal to (within tolerance) the lower or upper bounds. 112 116 # sort to insert it in the correct place. … … 375 379 # on this piece, variable is the actual instance variable, and average is the instance 376 380 # 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. 378 384 def _create_piecewise_constraint_expression(self, lb, ub, instance_variable, variable_average, quad_variable): 379 385 380 386 penalty_at_lb = (lb  variable_average()) * (lb  variable_average()) 381 387 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(ublb) > self._integer_tolerance: 390 slope = (penalty_at_ub  penalty_at_lb) / (ub  lb) 391 else: 392 slope = 0.0 383 393 intercept = penalty_at_lb  slope * lb 384 394 expression = (0.0, quad_variable  slope * instance_variable  intercept, None)
Note: See TracChangeset
for help on using the changeset viewer.