def apply(self, problem): """Returns a new problem and data for inverting the new solution. Returns ------- tuple (dict of arguments needed for the solver, inverse data) """ data = {} inv_data = {self.VAR_ID: problem.variables()[0].id} data[s.C], data[s.OFFSET] = ConicSolver.get_coeff_offset( problem.objective.args[0]) data[s.C] = data[s.C].ravel() inv_data[s.OFFSET] = data[s.OFFSET][0] constr_map = group_constraints(problem.constraints) data[ConicSolver.DIMS] = ConeDims(constr_map) inv_data[self.EQ_CONSTR] = constr_map[Zero] data[s.A], data[s.B] = self.group_coeff_offset( problem, constr_map[Zero], ECOS.EXP_CONE_ORDER) # Order and group nonlinear constraints. neq_constr = constr_map[NonPos] + constr_map[SOC] + constr_map[ExpCone] inv_data[self.NEQ_CONSTR] = neq_constr data[s.G], data[s.H] = self.group_coeff_offset( problem, neq_constr, ECOS.EXP_CONE_ORDER) return data, inv_data
def apply(self, problem): """Returns a new problem and data for inverting the new solution. Returns ------- tuple (dict of arguments needed for the solver, inverse data) """ data = {} objective, _ = problem.objective.canonical_form constraints = [con for c in problem.constraints for con in c.canonical_form[1]] data["objective"] = objective data["constraints"] = constraints data[ConicSolver.DIMS] = ConeDims( group_constraints(problem.constraints)) variables = problem.variables()[0] data[s.BOOL_IDX] = [t[0] for t in variables.boolean_idx] data[s.INT_IDX] = [t[0] for t in variables.integer_idx] inv_data = {self.VAR_ID: problem.variables()[0].id} # Order and group constraints. eq_constr = [c for c in problem.constraints if type(c) == Zero] inv_data[CVXOPT.EQ_CONSTR] = eq_constr leq_constr = [c for c in problem.constraints if type(c) == NonPos] soc_constr = [c for c in problem.constraints if type(c) == SOC] sdp_constr = [c for c in problem.constraints if type(c) == PSD] exp_constr = [c for c in problem.constraints if type(c) == ExpCone] inv_data[CVXOPT.NEQ_CONSTR] = leq_constr + soc_constr + sdp_constr + exp_constr return data, inv_data
def apply(self, problem): """Returns a new problem and data for inverting the new solution. Returns ------- tuple (dict of arguments needed for the solver, inverse data) """ data = {} inv_data = {self.VAR_ID: problem.variables()[0].id} # Parse the coefficient vector from the objective. data[s.C], data[s.OFFSET] = self.get_coeff_offset( problem.objective.args[0]) data[s.C] = data[s.C].ravel() inv_data[s.OFFSET] = data[s.OFFSET][0] # Order and group nonlinear constraints. constr_map = group_constraints(problem.constraints) data[ConicSolver.DIMS] = ConeDims(constr_map) inv_data[ConicSolver.DIMS] = data[ConicSolver.DIMS] # SCS requires constraints to be specified in the following order: # 1. zero cone # 2. non-negative orthant # 3. soc # 4. psd # 5. exponential zero_constr = constr_map[Zero] neq_constr = (constr_map[NonPos] + constr_map[SOC] + constr_map[PSD] + constr_map[ExpCone]) inv_data[SCS.EQ_CONSTR] = zero_constr inv_data[SCS.NEQ_CONSTR] = neq_constr # Obtain A, b such that Ax + s = b, s \in cones. # # Note that scs mandates that the cones MUST be ordered with # zero cones first, then non-nonnegative orthant, then SOC, # then PSD, then exponential. data[s.A], data[s.B] = self.group_coeff_offset( problem, zero_constr + neq_constr, self.EXP_CONE_ORDER) return data, inv_data