def _solve(self, solver=None, warm_start=True, verbose=False, parallel=False, gp=False, **kwargs): """Solves a DCP compliant optimization problem. Saves the values of primal and dual variables in the variable and constraint objects, respectively. Parameters ---------- solver : str, optional The solver to use. Defaults to ECOS. warm_start : bool, optional Should the previous solver result be used to warm start? verbose : bool, optional Overrides the default of hiding solver output. parallel : bool, optional If problem is separable, solve in parallel. gp : bool, optional If True, then parses the problem as a disciplined geometric program instead of a disciplined convex program. kwargs : dict, optional A dict of options that will be passed to the specific solver. In general, these options will override any default settings imposed by cvxpy. Returns ------- float The optimal value for the problem, or a string indicating why the problem could not be solved. """ if parallel: from cvxpy.transforms.separable_problems import get_separable_problems self._separable_problems = (get_separable_problems(self)) if len(self._separable_problems) > 1: return self._parallel_solve(solver, warm_start, verbose, **kwargs) self._construct_chains(solver=solver, gp=gp) data, solving_inverse_data = \ self._solving_chain.apply(self._intermediate_problem) solution = self._solving_chain.solve_via_data(self, data, warm_start, verbose, kwargs) full_chain = \ self._solving_chain.prepend(self._intermediate_chain) inverse_data = self._intermediate_inverse_data + solving_inverse_data self.unpack_results(solution, full_chain, inverse_data) return self.value
def _solve(self, solver=None, ignore_dcp=False, warm_start=True, verbose=False, parallel=False, gp=False, **kwargs): """Solves a DCP compliant optimization problem. Saves the values of primal and dual variables in the variable and constraint objects, respectively. Parameters ---------- solver : str, optional The solver to use. Defaults to ECOS. ignore_dcp : bool, optional TODO(akshayka): This option will probably be eliminated. Overrides the default of raising an exception if the problem is not DCP. warm_start : bool, optional Should the previous solver result be used to warm start? verbose : bool, optional Overrides the default of hiding solver output. parallel : bool, optional If problem is separable, solve in parallel. gp : bool, optional If True, then parses the problem as a disciplined geometric program instead of a disciplined convex program. kwargs : dict, optional A dict of options that will be passed to the specific solver. In general, these options will override any default settings imposed by cvxpy. Returns ------- float The optimal value for the problem, or a string indicating why the problem could not be solved. """ if parallel: from cvxpy.transforms.separable_problems import get_separable_problems self._separable_problems = (get_separable_problems(self)) if len(self._separable_problems) > 1: return self._parallel_solve(solver, ignore_dcp, warm_start, verbose, **kwargs) chain_key = (solver, gp) if chain_key != self._cached_chain_key: try: self._solving_chain = construct_solving_chain(self, solver=solver, gp=gp) except Exception as e: raise e self._cached_chain_key = chain_key data, inverse_data = self._solving_chain.apply(self) solver_output = self._solving_chain.solve_via_data( self, data, warm_start, verbose, kwargs) self.unpack_results(solver_output, self._solving_chain, inverse_data) return self.value
def _solve(self, solver=None, ignore_dcp=False, warm_start=True, verbose=False, parallel=False, **kwargs): """Solves a DCP compliant optimization problem. Saves the values of primal and dual variables in the variable and constraint objects, respectively. Parameters ---------- solver : str, optional The solver to use. Defaults to ECOS. ignore_dcp : bool, optional TODO(akshayka): This option will probably be eliminated. Overrides the default of raising an exception if the problem is not DCP. warm_start : bool, optional Should the previous solver result be used to warm start? verbose : bool, optional Overrides the default of hiding solver output. parallel : bool, optional If problem is separable, solve in parallel. kwargs : dict, optional A dict of options that will be passed to the specific solver. In general, these options will override any default settings imposed by cvxpy. Returns ------- float The optimal value for the problem, or a string indicating why the problem could not be solved. """ if parallel: from cvxpy.transforms.separable_problems import get_separable_problems self._separable_problems = (get_separable_problems(self)) if len(self._separable_problems) > 1: return self._parallel_solve(solver, ignore_dcp, warm_start, verbose, **kwargs) # If a previous chain does not exist, or if the solver is # specified and it does not match the solver used for the previous # solve, then construct a new solving chain. if (self._solving_chain is None or (solver is not None and self._solving_chain.solver.name != solver)): try: self._solving_chain = construct_solving_chain(self, solver=solver) except Exception as e: raise e data, inverse_data = self._solving_chain.apply(self) solution = self._solving_chain.solve_via_data(self, data, warm_start, verbose, kwargs) self.unpack_results(solution, self._solving_chain, inverse_data) return self.value
def _solve(self, solver=None, warm_start=True, verbose=False, parallel=False, gp=False, qcp=False, **kwargs): """Solves a DCP compliant optimization problem. Saves the values of primal and dual variables in the variable and constraint objects, respectively. Parameters ---------- solver : str, optional The solver to use. Defaults to ECOS. warm_start : bool, optional Should the previous solver result be used to warm start? verbose : bool, optional Overrides the default of hiding solver output. parallel : bool, optional If problem is separable, solve in parallel. gp : bool, optional If True, parses the problem as a disciplined geometric program. qcp : bool, optional If True, parses the problem as a disciplined quasiconvex program. kwargs : dict, optional A dict of options that will be passed to the specific solver. In general, these options will override any default settings imposed by cvxpy. Returns ------- float The optimal value for the problem, or a string indicating why the problem could not be solved. """ if gp and qcp: raise ValueError("At most one of `gp` and `qcp` can be True.") if qcp and not self.is_dcp(): if not self.is_dqcp(): raise error.DQCPError("The problem is not DQCP.") reductions = [dqcp2dcp.Dqcp2Dcp()] if type(self.objective) == Maximize: reductions = [FlipObjective()] + reductions chain = Chain(problem=self, reductions=reductions) soln = bisection.bisect(chain.reduce(), solver=solver, verbose=verbose, **kwargs) self.unpack(chain.retrieve(soln)) return self.value if parallel: from cvxpy.transforms.separable_problems import get_separable_problems self._separable_problems = (get_separable_problems(self)) if len(self._separable_problems) > 1: return self._parallel_solve(solver, warm_start, verbose, **kwargs) self._construct_chains(solver=solver, gp=gp) data, solving_inverse_data = self._solving_chain.apply( self._intermediate_problem) solution = self._solving_chain.solve_via_data(self, data, warm_start, verbose, kwargs) full_chain = self._solving_chain.prepend(self._intermediate_chain) inverse_data = self._intermediate_inverse_data + solving_inverse_data self.unpack_results(solution, full_chain, inverse_data) return self.value