def stuffed_objective(self, problem, extractor): # Extract to c.T * x + r; c is represented by a ma c = extractor.affine(problem.objective.expr) boolean, integer = extract_mip_idx(problem.variables()) x = Variable(extractor.x_length, boolean=boolean, integer=integer) return c, x
def stuffed_objective(self, problem, extractor): # extract to x.T * P * x + q.T * x + r expr = problem.objective.expr.copy() P, q, r = extractor.quad_form(expr) # concatenate all variables in one vector boolean, integer = extract_mip_idx(problem.variables()) x = Variable(extractor.x_length, boolean=boolean, integer=integer) new_obj = QuadForm(x, P) + q.T @ x return new_obj, x, r
def stuffed_objective(self, problem, extractor): # Extract to c.T * x + r C, R = extractor.affine(problem.objective.expr) c = C.toarray().flatten() boolean, integer = extract_mip_idx(problem.variables()) x = Variable(extractor.N, boolean=boolean, integer=integer) new_obj = c.T * x + 0 return new_obj, x, R[0]
def stuffed_objective(self, problem, extractor): # extract to x.T * P * x + q.T * x + r # TODO need to copy objective? P, q, r = extractor.quad_form(problem.objective.expr) # concatenate all variables in one vector boolean, integer = extract_mip_idx(problem.variables()) x = Variable(extractor.N, boolean=boolean, integer=integer) new_obj = QuadForm(x, P) + q.T*x return new_obj, x, r
def stuffed_objective(self, problem, extractor): # extract to 0.5 * x.T * P * x + q.T * x + r expr = problem.objective.expr.copy() params_to_P, params_to_q = extractor.quad_form(expr) # Handle 0.5 factor. params_to_P = 2 * params_to_P # concatenate all variables in one vector boolean, integer = extract_mip_idx(problem.variables()) x = Variable(extractor.x_length, boolean=boolean, integer=integer) return params_to_P, params_to_q, x
def stuffed_objective(self, problem, inverse_data): extractor = CoeffExtractor(inverse_data) # Extract to c.T * x, store r C, R = extractor.get_coeffs(problem.objective.expr) c = np.asarray(C.todense()).flatten() boolean, integer = extract_mip_idx(problem.variables()) x = Variable(inverse_data.x_length, boolean=boolean, integer=integer) new_obj = c.T * x + 0 inverse_data.r = R[0] return new_obj, x
def stuffed_objective(self, problem, inverse_data): # We need to copy the problem because we are changing atoms in the # expression tree problem_copy = problems.problem.Problem( Minimize(problem.objective.expr.tree_copy()), [con.tree_copy() for con in problem.constraints]) inverse_data_of_copy = InverseData(problem_copy) extractor = CoeffExtractor(inverse_data_of_copy) # extract to x.T * P * x + q.T * x, store r P, q, r = extractor.quad_form(problem_copy.objective.expr) # concatenate all variables in one vector boolean, integer = extract_mip_idx(problem.variables()) x = Variable(inverse_data.x_length, boolean=boolean, integer=integer) new_obj = QuadForm(x, P) + q.T * x inverse_data.r = r return new_obj, x
def stuffed_objective(self, problem, extractor): # Extract to c.T * x + r C, R = extractor.affine(problem.objective.expr) c = C.toarray().flatten() boolean, integer = extract_mip_idx(problem.variables()) x = Variable(extractor.N, boolean=boolean, integer=integer) # CHANGE -------------------------- # set the value of the variable. We use NaNs to # show which values are unknown. This would not # satisfy the requirements imposed on x.value # Hence, we have to set the variable x._value # directly to circumvent the check. # x.value will be set when the problem is solved, the # inconsistent value will be overwritten soon anyway. x._value = stack_vals(problem.variables()) # ---------------------------------- new_obj = c.T * x + 0 return new_obj, x, R[0]