r[0,0] = 2 * 4 * x[0]**3 r[1,1] = 2 * x[1] r[1,2] = 2 * x[2] + 15 #incorrect derivative return r p.dc = dc p.h = lambda x: (1e1*(x[-1]-1)**4, (x[-2]-1.5)**4) def dh(x): r = zeros((2, p.n)) r[0,-1] = 1e1*4*(x[-1]-1)**3 r[1,-2] = 4*(x[-2]-1.5)**3 + 15 #incorrect derivative return r p.dh = dh p.checkdf() p.checkdc() p.checkdh() """ you can use p.checkdF(x) for other point than x0 (F is f, c or h) p.checkdc(myX) or p.checkdc(x=myX) values with difference greater than maxViolation (default 1e-5) will be shown p.checkdh(maxViolation=1e-4) p.checkdh(myX, maxViolation=1e-4) p.checkdh(x=myX, maxViolation=1e-4) #################################################################################
def minimize(self, **kwargs): """ solve the nonlinear problem using OpenOpt Returns: obj_value, solution obj_value -- value of the objective function at the discovered solution solution -- the solution flux vector (indexed like matrix columns) """ if self.iterator is None: nlp = NLP(self.obj, self.x0, df=self.d_obj, c=self.nlc, dc=self.d_nlc, A=self.Aineq, Aeq=self.Aeq, b=self.bineq, beq=self.beq, lb=self.lb, ub=self.ub, **kwargs) nlp.debug = 1 nlp.plot = False nlp.checkdf() if self.nlc is not None: nlp.checkdc() r = nlp.solve(self.solver) else: self.rlist = [] for x0 in self.iterator: nlp = NLP(self.obj, x0, df=self.d_obj, c=self.nlc, dc=self.d_nlc, A=self.Aineq, Aeq=self.Aeq, b=self.bineq, beq=self.beq, lb=self.lb, ub=self.ub, **kwargs) r = nlp.solve(self.solver) if r.istop > 0 and r.ff == r.ff: self.rlist.append(r) if self.rlist != []: r = min(self.rlist, key=lambda x: x.ff) if r.istop <= 0 or r.ff != r.ff: # check halting condition self.obj_value = 0. self.solution = [] self.istop = r.istop else: self.obj_value = r.ff self.solution = r.xf self.istop = r.istop return self.obj_value, self.solution