def op_runner(objective, constraints, **kwargs): """ Minimize the objective specified by the constraints. This safely let's you pass options to the solver and restores their values once the optimization process has completed. The objective must be linear in the variables. This uses cvxopt.modeling. """ from cvxopt.solvers import options from cvxopt.modeling import op old_options = options.copy() opt = op(objective, constraints) try: options.clear() options.update(kwargs) # Ignore 0 log 0 warnings. with np.errstate(divide='ignore', invalid='ignore'): opt.solve() except: raise finally: options.clear() options.update(old_options) return opt
def op_runner(objective, constraints, **kwargs): """ Minimize the objective specified by the constraints. This safely let's you pass options to the solver and restores their values once the optimization process has completed. The objective must be linear in the variables. This uses cvxopt.modeling. """ from cvxopt.solvers import options from cvxopt.modeling import variable, op old_options = options.copy() opt = op(objective, constraints) try: options.clear() options.update(kwargs) # Ignore 0 log 0 warnings. with np.errstate(divide='ignore', invalid='ignore'): opt.solve() except: raise finally: options.clear() options.update(old_options) return opt
def optimize(self, **kwargs): """ Options: show_progress=False, maxiters=100, abstol=1e-7, reltol=1e-6, feastol=1e-7, refinement=0 if m=0 else 1 """ from cvxopt.solvers import cp, options old_options = options.copy() out = None try: options.clear() options.update(kwargs) with np.errstate(divide='ignore', invalid='ignore'): result = cp(F=self.F, G=self.G, h=self.h, dims={ 'l': self.G.size[0], 'q': [], 's': [] }, A=self.A, b=self.b) except: raise else: self.result = result out = np.asarray(result['x']) finally: options.clear() options.update(old_options) return out
def optimize(self, **kwargs): """ Options: show_progress=False, maxiters=100, abstol=1e-7, reltol=1e-6, feastol=1e-7, refinement=0 if m=0 else 1 """ from cvxopt.solvers import cp, options old_options = options.copy() out = None try: options.clear() options.update(kwargs) with np.errstate(divide='ignore', invalid='ignore'): result = cp(F=self.F, G=self.G, h=self.h, dims={'l':self.G.size[0], 'q':[], 's':[]}, A=self.A, b=self.b) except: raise else: self.result = result out = np.asarray(result['x']) finally: options.clear() options.update(old_options) return out