def setupSolver(self,solverOpts=[],constraintFunOpts=[],callback=None): if not self.collocationIsSetup: raise ValueError("you forgot to call setupCollocation") g = self._constraints.getG() lbg = self._constraints.getLb() ubg = self._constraints.getUb() # Nonlinear constraint function gfcn = CS.MXFunction([self._dvMap.vectorize()],[g]) setFXOptions(gfcn,constraintFunOpts) # Objective function of the NLP if not hasattr(self,'_objective'): raise ValueError('need to set objective function') ofcn = CS.MXFunction([self._dvMap.vectorize()],[self._objective]) # solver callback (optional) if callback is not None: nd = self._dvMap.vectorize().size() nc = self._constraints.getG().size() c = CS.PyFunction( callback, CS.nlpsolverOut(x_opt = CS.sp_dense(nd,1), cost = CS.sp_dense(1,1), lambda_x = CS.sp_dense(nd,1), lambda_g = CS.sp_dense(nc,1), lambda_p = CS.sp_dense(0,1), g = CS.sp_dense(nc,1) ), [CS.sp_dense(1,1)] ) c.init() solverOpts.append( ("iteration_callback", c) ) # Allocate an NLP solver self.solver = CS.IpoptSolver(ofcn,gfcn) # self.solver = CS.WorhpSolver(ofcn,gfcn) # self.solver = CS.SQPMethod(ofcn,gfcn) # Set options setFXOptions(self.solver, solverOpts) # initialize the solver self.solver.init() # Bounds on g self.solver.setInput(lbg,CS.NLP_LBG) self.solver.setInput(ubg,CS.NLP_UBG) self._gfcn = gfcn
def setupSolver(self, solverOpts=[], constraintFunOpts=[], callback=None): if not self.collocationIsSetup: raise ValueError("you forgot to call setupCollocation") g = self._constraints.getG() lbg = self._constraints.getLb() ubg = self._constraints.getUb() # Objective function/constraints of the NLP if not hasattr(self, '_objective'): raise ValueError('need to set objective function') nlp = CS.MXFunction(CS.nlpIn(x=self._dvMap.vectorize()), CS.nlpOut(f=self._objective, g=g)) setFXOptions(nlp, constraintFunOpts) nlp.init() # solver callback (optional) if callback is not None: nd = self._dvMap.vectorize().size() nc = self._constraints.getG().size() c = CS.PyFunction( callback, CS.nlpSolverOut(x=CS.sp_dense(nd, 1), f=CS.sp_dense(1, 1), lam_x=CS.sp_dense(nd, 1), lam_g=CS.sp_dense(nc, 1), lam_p=CS.sp_dense(0, 1), g=CS.sp_dense(nc, 1)), [CS.sp_dense(1, 1)]) c.init() solverOpts.append(("iteration_callback", c)) # Allocate an NLP solver self.solver = CS.IpoptSolver(nlp) # self.solver = CS.WorhpSolver(nlp) # self.solver = CS.SQPMethod(nlp) # Set options setFXOptions(self.solver, solverOpts) # initialize the solver self.solver.init() # Bounds on g self.solver.setInput(lbg, 'lbg') self.solver.setInput(ubg, 'ubg') ## Nonlinear constraint function, for debugging gfcn = CS.MXFunction([self._dvMap.vectorize()], [g]) gfcn.init() setFXOptions(gfcn, constraintFunOpts) self._gfcn = gfcn
def setupSolver(self,solverOpts=[],constraintFunOpts=[],callback=None): if not self.collocationIsSetup: raise ValueError("you forgot to call setupCollocation") g = self._constraints.getG() lbg = self._constraints.getLb() ubg = self._constraints.getUb() # Objective function/constraints of the NLP if not hasattr(self,'_objective'): raise ValueError('need to set objective function') nlp = CS.MXFunction(CS.nlpIn(x=self._dvMap.vectorize()),CS.nlpOut(f=self._objective, g=g)) setFXOptions(nlp,constraintFunOpts) nlp.init() # solver callback (optional) if callback is not None: nd = self._dvMap.vectorize().size() nc = self._constraints.getG().size() c = CS.PyFunction( callback, CS.nlpSolverOut(x = CS.sp_dense(nd,1), f = CS.sp_dense(1,1), lam_x = CS.sp_dense(nd,1), lam_g = CS.sp_dense(nc,1), lam_p = CS.sp_dense(0,1), g = CS.sp_dense(nc,1) ), [CS.sp_dense(1,1)] ) c.init() solverOpts.append( ("iteration_callback", c) ) # Allocate an NLP solver self.solver = CS.IpoptSolver(nlp) # self.solver = CS.WorhpSolver(nlp) # self.solver = CS.SQPMethod(nlp) # Set options setFXOptions(self.solver, solverOpts) # initialize the solver self.solver.init() # Bounds on g self.solver.setInput(lbg,'lbg') self.solver.setInput(ubg,'ubg') ## Nonlinear constraint function, for debugging gfcn = CS.MXFunction([self._dvMap.vectorize()],[g]) gfcn.init() setFXOptions(gfcn,constraintFunOpts) self._gfcn = gfcn
def setupSolver(self,solverOpts=[],constraintFunOpts=[],callback=None,solver='ipopt'): if not self.collocationIsSetup: raise ValueError("you forgot to call setupCollocation") g = self._constraints.getG() lbg = self._constraints.getLb() ubg = self._constraints.getUb() # Objective function/constraints of the NLP if not hasattr(self,'_objective'): raise ValueError('need to set objective function') nlp = CS.MXFunction(CS.nlpIn(x=self._dvMap.vectorize()),CS.nlpOut(f=self._objective, g=g)) setFXOptions(nlp,constraintFunOpts) nlp.init() # solver callback (optional) if callback is not None: @pycallback def c(f): return callback(f) solverOpts.append( ("iteration_callback", c) ) # Allocate an NLP solver self.solver = CS.NlpSolver(solver,nlp) # Set options setFXOptions(self.solver, solverOpts) # initialize the solver self.solver.init() # Bounds on g self.solver.setInput(lbg,'lbg') self.solver.setInput(ubg,'ubg') ## Nonlinear constraint function, for debugging gfcn = CS.MXFunction([self._dvMap.vectorize()],[g]) gfcn.init() setFXOptions(gfcn,constraintFunOpts) self._gfcn = gfcn