def canonical_form(self, compute_values=True): """Build a canonical representation of the body of this constraints""" from pyomo.repn.standard_repn import \ StandardRepn variables = [] coefficients = [] constant = 0 for v, c in self.terms: if v.is_expression_type(): v = v.expr if not v.fixed: variables.append(v) if compute_values: coefficients.append(value(c)) else: coefficients.append(c) else: if compute_values: constant += value(c) * v() else: constant += c * v repn = StandardRepn() repn.linear_vars = tuple(variables) repn.linear_coefs = tuple(coefficients) repn.constant = constant return repn
def canonical_form(self, compute_values=True): """Build a canonical representation of the body of this constraints""" comp = self.parent_component() index = self._index data = comp._A_data indices = comp._A_indices indptr = comp._A_indptr x = comp._x variables = [] coefficients = [] constant = 0 for p in xrange(indptr[index], indptr[index + 1]): v = x[indices[p]] c = data[p] if not v.fixed: variables.append(v) if compute_values: coefficients.append(value(c)) else: coefficients.append(c) else: if compute_values: constant += value(c) * v.value else: constant += c * v repn = StandardRepn() repn.linear_vars = tuple(variables) repn.linear_coefs = tuple(coefficients) repn.constant = constant return repn
def canonical_form(self, compute_values=True): """Build a canonical representation of the body of this constraints""" from pyomo.repn.standard_repn import StandardRepn variables = [] coefficients = [] constant = 0 for v, c in self.terms: # we call float to get rid of the numpy type c = float(c) if not v.fixed: variables.append(v) coefficients.append(c) else: if compute_values: constant += c * v() else: constant += c * v repn = StandardRepn() repn.linear_vars = tuple(variables) repn.linear_coefs = tuple(coefficients) repn.constant = constant return repn