def convert_problem(problem): # NOTE(mwytock): Maximize inherits from Minimize so this clause first! if isinstance(problem.objective, objective.Maximize): obj_expr = -problem.objective.args[0] elif isinstance(problem.objective, objective.Minimize): obj_expr = problem.objective.args[0] else: raise RuntimeError("Unknown objective: %s" % type(problem.objective)) return expression.Problem( objective=convert_expression(obj_expr), constraint=[convert_constraint(c) for c in problem.constraints])
def transform_problem(problem, params): prox_rules = PROX_RULES + BASE_RULES # Epigraph/cone rules if params.use_epigraph: prox_rules.append(epigraph) prox_rules.append(prox_non_negative) prox_rules.append(transform_cone) f_exprs = list(transform_expr(prox_rules, problem.objective)) for constr in problem.constraint: f_exprs += list(transform_expr(prox_rules, constr)) return expression.Problem(objective=expression.add(*f_exprs))
def problem(self): return expression.Problem( objective=expression.add(*(f.expr for f in self.nodes(FUNCTION))), constraint=[f.expr for f in self.nodes(CONSTRAINT)])