std::vector<unsigned int> bTree::findGreater(Index ind, bool equal){ unsigned int i; std::vector<unsigned int> res; bTreeNode cur = findFirstNode(ind); for (i = 0; i < cur.valNum; ++i) { if(cur.indexList[i]>=ind) break; } if(i>=cur.valNum) { freeNode(cur); if(cur.ptrList.back()==0) return res; cur = assignNode(cur.ptrList.back()); i = 0; } while(true) { if(equal || cur.indexList[i]!=ind) res.push_back(cur.ptrList[i]); i++; if(i>=cur.valNum) { if(cur.ptrList[i]==0) break; freeNode(cur); cur = assignNode(cur.ptrList[i]); i = 0; } } freeNode(cur); return res; }
LinearSolver::LinearSolver(const std::string& solver, const Sparsity& sp, int nrhs) { if (solver=="none") { assignNode(new LinearSolverInternal(sp, nrhs)); } else { assignNode(LinearSolverInternal::getPlugin(solver).creator(sp, nrhs)); } }
bTreeNode bTree::findBro(bTreeNode& node){ bTreeNode par = assignNode(node.parentPtr); if(findPath.back() > 0 && findPath.back() < par.valNum) { bTreeNode l = assignNode(par.ptrList[findPath.back()-1]); bTreeNode r = assignNode(par.ptrList[findPath.back()+1]); freeNode(par); if(l.valNum<r.valNum) { freeNode(r); return l; } else { freeNode(l); return r; } } freeNode(par); if(findPath.back() > 0) return assignNode(par.ptrList[findPath.back()-1]); if(findPath.back() < par.valNum) return assignNode(par.ptrList[findPath.back()+1]); return bTreeNode(); }
std::vector<unsigned int> bTree::findAll(Index ind){ unsigned int i; std::vector<unsigned int> res; bTreeNode cur = findFirstNode(ind); for (i = 0; i < cur.valNum; ++i) { if(cur.indexList[i]==ind) break; } if(i>=cur.valNum) { freeNode(cur); if(cur.ptrList.back()==0) return res; cur = assignNode(cur.ptrList.back()); if(cur.indexList.front()!=ind) return res; i = 0; } while(cur.indexList[i]==ind) { res.push_back(cur.ptrList[i++]); if(i==cur.valNum) { if(cur.ptrList[i]==0) break; freeNode(cur); cur = assignNode(cur.ptrList[i]); i = 0; } } freeNode(cur); return res; }
bTreeNode bTree::findFirstNode(Index ind){ bTreeNode cur = assignNode(root); bTreeNode par = cur; findPath.clear(); int ser; while(cur.type!=LEAF) { for (ser = 0; ser < cur.valNum; ++ser) { if(ind<cur.indexList[ser]) break; } findPath.push_back(ser); if(cur.type!=ROOT) { freeNode(par); par = cur; } cur = assignNode(cur.ptrList[ser]); } freeNode(par); return cur; }
void SharedObject::makeUnique(std::map<SharedObjectNode*, SharedObject>& already_copied, bool clone_members) { if (node && node->count>1) { // First find out if the expression has already been copied std::map<SharedObjectNode*, SharedObject>::iterator it = already_copied.find(node); if (it==already_copied.end()) { // If the expression has not yet been copied SharedObjectNode *newnode = node->clone(); // Copy the data members if (clone_members) newnode->deepCopyMembers(already_copied); // Initialize object if parent was initialized if (isInit() && !newnode->is_init_) { newnode->init(); } // Assign cloned node to object assignNode(newnode); } else { // Use an existing copy assignNode(it->second.get()); } } }
LinearSolver::LinearSolver(const std::string& name, const std::string& solver, const Sparsity& sp, int nrhs, const Dict& opts) { if (solver=="none") { assignNode(new LinearSolverInternal(sp, nrhs)); } else { assignNode(LinearSolverInternal::getPlugin(solver).creator(sp, nrhs)); } setOption("name", name); setOption(opts); init(); }
ImplicitFunction::ImplicitFunction(const std::string& name, const std::string& solver, const Function& f, const Dict& opts) { assignNode(ImplicitFunctionInternal::instantiatePlugin(solver, f)); setOption("name", name); setOption(opts); init(); }
ExportVariable& ExportVariable::setup( const String& _name, const Matrix& _data, ExportType _type, ExportStruct _dataStruct, BooleanType _callItByValue, const String& _prefix ) { assignNode(new ExportVariableInternal(_name, _data, _type, _dataStruct, _callItByValue, _prefix)); // setName( _name ); // // (*this)->data = _data; // // setDataStruct( _dataStruct ); // // (*this)->callItByValue = _callItByValue; // // (*this)->doAccessTransposed = BT_FALSE; // // setPrefix( _prefix ); // // (*this)->setSubmatrixOffsets(0, 0, _data.getNumRows(), _data.getNumCols(), 0, 0); return *this; }
ExportVariable& ExportVariable::setup( const String& _name, uint _nRows, uint _nCols, ExportType _type, ExportStruct _dataStruct, BooleanType _callItByValue, const String& _prefix ) { Matrix m(_nRows, _nCols); m.setAll( undefinedEntry ); assignNode(new ExportVariableInternal(_name, m, _type, _dataStruct, _callItByValue, _prefix)); // if ( isNull() ) // assignNode(new ExportVariableInternal); // // setName( _name ); // // // (*this)->data = m; // // setDataStruct( _dataStruct ); // // (*this)->callItByValue = _callItByValue; // // setPrefix( _prefix ); // // (*this)->setSubmatrixOffsets(0, 0, _nRows, _nCols, 0, 0); return *this; }
void bTree::bfs(bTreeNode& b,std::vector<bTreeNode>& t){ t.push_back(b); int c=0; while(c < t.size()) { //std::cout<<t[c].blockNo<<":"; //std::cout<<t[c].type<<" "; //t[c].testOutput(); //std::cout<<std::endl; if(t[c].type!=LEAF) { int i; for (i = 0; i <= t[c].valNum; ++i) { //if(t[c].ptrList[i] == 0) //{ //std::cout<<"error: "; //t[c].testOutput(); //} t.push_back(assignNode(t[c].ptrList[i])); } } c++; } return; }
NlpSolver::NlpSolver(const std::string& name, const std::string& solver, const MXDict& nlp, const Dict& opts) { // Create an NLP function MX x, p, f, g; for (MXDict::const_iterator i=nlp.begin(); i!=nlp.end(); ++i) { if (i->first=="x") { x = i->second; } else if (i->first=="p") { p = i->second; } else if (i->first=="f") { f = i->second; } else if (i->first=="g") { g = i->second; } else { casadi_error("No such field: \"" + i->first + "\""); } } MXFunction nlpf("nlp", nlpIn("x", x, "p", p), nlpOut("f", f, "g", g)); // Create the solver instance assignNode(NlpSolverInternal::instantiatePlugin(solver, nlpf)); setOption("name", name); setOption(opts); init(); }
CleSolver::CleSolver(const std::string& name, const std::string& solver, const std::map<std::string, Sparsity>& st, const Dict& opts) { assignNode(CleInternal::instantiatePlugin(solver, st)); setOption("name", name); setOption(opts); init(); }
ImplicitFunction::ImplicitFunction(const std::string& solver, const Function& f, const Function& jac, const LinearSolver& linsol) { assignNode(ImplicitFunctionInternal::instantiatePlugin(solver, f)); setOption("jacobian_function", jac); setOption("linear_solver_function", linsol); }
NlpSolver::NlpSolver(const std::string& name, const std::string& solver, const Function& nlp, const Dict& opts) { assignNode(NlpSolverInternal::instantiatePlugin(solver, nlp)); setOption("name", name); setOption(opts); init(); }
std::vector<unsigned int> bTree::findLess(Index ind, bool equal){ unsigned int i; std::vector<unsigned int> res; bTreeNode cur = assignNode(root); while(cur.type != LEAF) { freeNode(cur); cur = assignNode(cur.ptrList.front()); } i=0; if(i>=cur.valNum) { freeNode(cur); return res; } while(cur.indexList[i]!=ind) { if(equal || cur.indexList[i]!=ind) res.push_back(cur.ptrList[i]); i++; if(i>=cur.valNum) { if(cur.ptrList[i]==0) break; freeNode(cur); cur = assignNode(cur.ptrList[i]); i = 0; } } if(equal) while(cur.indexList[i]==ind) { res.push_back(cur.ptrList[i++]); if(i>=cur.valNum) { if(cur.ptrList[i]==0) break; freeNode(cur); cur = assignNode(cur.ptrList[i]); i = 0; } } freeNode(cur); return res; }
Variable::Variable(const string& name, bool create_expression){ assignNode(new VariableInternal(name)); if(create_expression){ setExpression(SX(name)); setDerivative(SX("der_" + name)); setBinding(var(),false); setBinding(der(),true); } }
ExportVariable::ExportVariable( const String& _name, const matrixPtr& _data, ExportType _type, ExportStruct _dataStruct, BooleanType _callItByValue, const String& _prefix ) { assignNode(new ExportVariableInternal(_name, _data, _type, _dataStruct, _callItByValue, _prefix)); }
ExportVariable& ExportVariable::setup( const String& _name, const Matrix& _data, ExportType _type, ExportStruct _dataStruct, BooleanType _callItByValue, const String& _prefix ) { assignNode(new ExportVariableInternal(_name, matrixPtr(new Matrix( _data )), _type, _dataStruct, _callItByValue, _prefix)); return *this; }
Index bTree::findMinIndex(bTreeNode& node){ Index res; if(node.type==LEAF) res=node.indexList.front(); else { bTreeNode temp = assignNode(node.ptrList.front()); res = findMinIndex(temp); freeNode(temp); } return res; }
ExportArgument::ExportArgument( const String& _name, const Matrix& _data, ExportType _type, ExportStruct _dataStruct, BooleanType _callItByValue, const ExportIndex& _addressIdx, const String& _prefix ) { assignNode(new ExportArgumentInternal( _name, _data, _type, _dataStruct, _callItByValue, _addressIdx, _prefix)); }
CRSSparsity::CRSSparsity(int nrow, int ncol, bool dense){ vector<int> col, rowind(nrow+1,0); if(dense){ col.resize(nrow*ncol); rowind.resize(nrow+1); for(int i=0; i<nrow+1; ++i) rowind[i] = i*ncol; for(int i=0; i<nrow; ++i) for(int j=0; j<ncol; ++j) col[j+i*ncol] = j; } assignNode(new CRSSparsityInternal(nrow, ncol, col, rowind)); }
ExportVariable::ExportVariable( const String& _name, uint _nRows, uint _nCols, ExportType _type, ExportStruct _dataStruct, BooleanType _callItByValue, const String& _prefix ) { Matrix m(_nRows, _nCols); m.setAll( undefinedEntry ); assignNode(new ExportVariableInternal(_name, matrixPtr(new Matrix( m )), _type, _dataStruct, _callItByValue, _prefix)); }
void bTree::printTree(){ bTreeNode r = assignNode(root); //std::cout<<r.type<<std::endl; std::vector<bTreeNode> temp; bfs(r,temp); std::vector<bTreeNode>::iterator iter; for (iter = temp.begin(); iter < temp.end(); ++iter) { std::cout<<iter->blockNo<<":"; iter->testOutput(); std::cout<<std::endl; } return; }
ExportArgument::ExportArgument( const String& _name, uint _nRows, uint _nCols, ExportType _type, ExportStruct _dataStruct, BooleanType _callItByValue, const ExportIndex& _addressIdx, const String& _prefix ) { Matrix m(_nRows, _nCols); m.setAll( undefinedEntry ); assignNode(new ExportArgumentInternal( _name, m, _type, _dataStruct, _callItByValue, _addressIdx, _prefix)); }
GenericType::GenericType(void* ptr) : type_(OT_VOIDPTR){ assignNode(new GenericTypeInternal<void*>(ptr)); }
GenericType::GenericType(const Dictionary& dict) : type_(OT_DICTIONARY) { assignNode(new GenericTypeInternal<Dictionary>(dict)); }
GenericType::GenericType(SparsityGenerator ptr) : type_(OT_SPARSITYGENERATOR) { assignNode(new GenericTypeInternal<SparsityGenerator>(ptr)); }
GenericType::GenericType(JacobianGenerator ptr) : type_(OT_JACOBIANGENERATOR) { assignNode(new GenericTypeInternal<JacobianGenerator>(ptr)); }
GenericType::GenericType(implicitFunctionCreator ptr) : type_(OT_IMPLICITFUNCTION) { assignNode(new GenericTypeInternal<implicitFunctionCreator>(ptr)); }