def get_M_value_src(self, constraint): """Return a tuple indicating how the M value used to transform constraint was specified. (In particular, this can be used to verify which BigM Suffixes were actually necessary to the transformation.) Return is of the form: ((lower_M_val, lower_M_source, lower_M_key), (upper_M_val, upper_M_source, upper_M_key)) If the constraint does not have a lower bound (or an upper bound), the first (second) element will be (None, None, None). Note that if a constraint is of the form a <= expr <= b or is an equality constraint, it is not necessarily true that the source of lower_M and upper_M are the same. If the M value came from an arg, source is the dictionary itself and key is the key in that dictionary which gave us the M value. If the M value came from a Suffix, source is the BigM suffix used and key is the key in that Suffix. If the transformation calculated the value, both source and key are None. Parameters ---------- constraint: Constraint, which must be in the subtree of a transformed Disjunct """ transBlock = _get_constraint_transBlock(constraint) # This is a KeyError if it fails, but it is also my fault if it # fails... (That is, it's a bug in the mapping.) return transBlock.bigm_src[constraint]
def get_m_value_src(self, constraint): """Return a tuple indicating how the M value used to transform constraint was specified. (In particular, this can be used to verify which BigM Suffixes were actually necessary to the transformation.) If the M value came from an arg, returns (bigm_arg_dict, key), where bigm_arg_dict is the dictionary itself and key is the key in that dictionary which gave us the M value. If the M value came from a Suffix, returns (suffix, key) where suffix is the BigM suffix used and key is the key in that Suffix. If the transformation calculated the value, returns (M_lower, M_upper), where M_lower is the float we calculated for the lower bound constraint and M_upper is the value calculated for the upper bound constraint. Parameters ---------- constraint: Constraint, which must be in the subtree of a transformed Disjunct """ transBlock = _get_constraint_transBlock(constraint) # This is a KeyError if it fails, but it is also my fault if it # fails... (That is, it's a bug in the mapping.) return transBlock.bigm_src[constraint]
def get_M_value(self, constraint): """Returns the M values used to transform constraint. Return is a tuple: (lower_M_value, upper_M_value). Either can be None if constraint does not have a lower or upper bound, respectively. Parameters ---------- constraint: Constraint, which must be in the subtree of a transformed Disjunct """ transBlock = _get_constraint_transBlock(constraint) # This is a KeyError if it fails, but it is also my fault if it # fails... (That is, it's a bug in the mapping.) lower, upper = transBlock.bigm_src[constraint] return (lower[0], upper[0])
def get_m_value_src(self, constraint): transBlock = _get_constraint_transBlock(constraint) ((lower_val, lower_source, lower_key), (upper_val, upper_source, upper_key)) = transBlock.bigm_src[constraint] if constraint.lower is not None and constraint.upper is not None and \ (not lower_source is upper_source or not lower_key is upper_key): raise GDP_Error("This is why this method is deprecated: The lower " "and upper M values for constraint %s came from " "different sources, please use the get_M_value_src " "method." % constraint.name) # if source and key are equal for the two, this is representable in the # old format. if constraint.lower is not None and lower_source is not None: return (lower_source, lower_key) if constraint.upper is not None and upper_source is not None: return (upper_source, upper_key) # else it was calculated: return (lower_val, upper_val)