当前位置: 首页>>代码示例>>C++>>正文


C++ casadi_error函数代码示例

本文整理汇总了C++中casadi_error函数的典型用法代码示例。如果您正苦于以下问题:C++ casadi_error函数的具体用法?C++ casadi_error怎么用?C++ casadi_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了casadi_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: evaluateTask

void ParallelizerInternal::evaluate(int nfdir, int nadir){
  // Let the first call (which may contain memory allocations) be serial when using OpenMP
  if(mode_== SERIAL || (first_call_ && mode_ == OPENMP)){
    for(int task=0; task<funcs_.size(); ++task){
      evaluateTask(task,nfdir,nadir);
    }
  } else if(mode_== OPENMP) {
    #ifdef WITH_OPENMP
    // Allocate some lists to collect statistics
    std::vector<int> task_allocation(funcs_.size());
    std::vector<int> task_order(funcs_.size());
    std::vector<double> task_cputime(funcs_.size());
    std::vector<double> task_starttime(funcs_.size());
    std::vector<double> task_endtime(funcs_.size());
    // A private counter
    int cnt=0;
    #pragma omp parallel for firstprivate(cnt)
    for(int task=0; task<funcs_.size(); ++task) {
      if (gather_stats_ && task==0) {
        stats_["max_threads"] = omp_get_max_threads();
        stats_["num_threads"] = omp_get_num_threads();
      }
      task_allocation[task] = omp_get_thread_num();
      task_starttime[task] = omp_get_wtime();
      
      // Do the actual work
      evaluateTask(task,nfdir,nadir);
      
      task_endtime[task] = omp_get_wtime();
      task_cputime[task] =  task_endtime[task] - task_starttime[task];
      task_order[task] = cnt++;
    }
    if (gather_stats_) {
      stats_["task_allocation"] = task_allocation;
      stats_["task_order"] = task_order;
      stats_["task_cputime"] = task_cputime;
    }
    // Measure all times relative to the earliest start_time.
    double start = *std::min_element(task_starttime.begin(),task_starttime.end());
    for (int task=0; task<funcs_.size(); ++task) {
      task_starttime[task] =  task_starttime[task] - start;
      task_endtime[task] = task_endtime[task] - start;
    }
    if (gather_stats_) {
      stats_["task_starttime"] = task_starttime;
      stats_["task_endtime"] = task_endtime;
    }
    
    #endif //WITH_OPENMP
    #ifndef WITH_OPENMP
      casadi_error("ParallelizerInternal::evaluate: OPENMP support was not available during CasADi compilation");
    #endif //WITH_OPENMP
  } else if(mode_ == MPI){
    casadi_error("ParallelizerInternal::evaluate: MPI not implemented");
  }
  first_call_ = false;
}
开发者ID:slavakung,项目名称:casadi,代码行数:57,代码来源:parallelizer_internal.cpp

示例2: getOption

  void ShellCompiler::init() {
    // Initialize the base classes
    CompilerInternal::init();

    // Read options
    string compiler = getOption("compiler").toString();
    string compiler_setup = getOption("compiler_setup").toString();
    vector<string> flags;
    if (hasSetOption("flags")) flags = getOption("flags");

    // Construct the compiler command
    stringstream cmd;
    cmd << compiler << " " << compiler_setup;
    for (vector<string>::const_iterator i=flags.begin(); i!=flags.end(); ++i) {
      cmd << " " << *i;
    }

    // C/C++ source file
    cmd << " " << name_;

    // Name of temporary file
#ifdef HAVE_MKSTEMPS
    // Preferred solution
    char bin_name[] = "tmp_casadi_compiler_shell_XXXXXX.so";
    if (mkstemps(bin_name, 3) == -1) {
      casadi_error("Failed to create a temporary file name");
    }
    bin_name_ = bin_name;
#else
    // Fallback, may result in deprecation warnings
    char* bin_name = tempnam(0, "tmp_casadi_compiler_shell_");
    bin_name_ = bin_name;
    free(bin_name);
#endif

    // Have relative paths start with ./
    if (bin_name_.at(0)!='/') {
      bin_name_ = "./" + bin_name_;
    }

    // Temporary file
    cmd << " -o " << bin_name_;

    // Compile into a shared library
    if (system(cmd.str().c_str())) {
      casadi_error("Compilation failed. Tried \"" + cmd.str() + "\"");
    }

    // Load shared library
    handle_ = dlopen(bin_name_.c_str(), RTLD_LAZY);
    casadi_assert_message(handle_!=0, "CommonExternal: Cannot open function: "
                          << bin_name_ << ". error code: "<< dlerror());
    // reset error
    dlerror();
  }
开发者ID:jgillis,项目名称:casadi,代码行数:55,代码来源:shell_compiler.cpp

示例3: casadi_error

  DMatrix IpoptInternal::getReducedHessian(){
#ifndef WITH_SIPOPT
    casadi_error("This feature requires sIPOPT support. Please consult the CasADi documentation.");
#else // WITH_SIPOPT
#ifndef WITH_CASADI_PATCH
    casadi_error("Retrieving the Hessian requires the CasADi sIPOPT patch. Please consult the CasADi documentation.");
#else // WITH_CASADI_PATCH
    return red_hess_;
#endif // WITH_SIPOPT
#endif // WITH_CASADI_PATCH

  }
开发者ID:zhenglei-gao,项目名称:casadi,代码行数:12,代码来源:ipopt_internal.cpp

示例4: nrhs_

  DpleInternal::DpleInternal(const std::map<std::string, std::vector<Sparsity> > &st,
                             int nrhs, bool transp) :
    nrhs_(nrhs), transp_(transp) {

    // set default options
    setOption("name", "unnamed_dple_solver"); // name of the function

    addOption("const_dim", OT_BOOLEAN, true, "Assume constant dimension of P");
    addOption("pos_def", OT_BOOLEAN, false, "Assume P positive definite");

    addOption("error_unstable", OT_BOOLEAN, false,
              "Throw an exception when it is detected that Product(A_i, i=N..1) "
              "has eigenvalues greater than 1-eps_unstable");
    addOption("eps_unstable", OT_REAL, 1e-4, "A margin for unstability detection");

    st_.resize(Dple_STRUCT_NUM);
    for (std::map<std::string, std::vector<Sparsity> >::const_iterator i=st.begin();
         i!=st.end(); ++i) {
      if (i->first=="a") {
        st_[Dple_STRUCT_A]=i->second;
      } else if (i->first=="v") {
        st_[Dple_STRUCT_V]=i->second;
      } else {
        casadi_error("Unrecognized field in Dple structure: " << i->first);
      }
    }

    if (nrhs_==1) {
      ischeme_ = IOScheme(SCHEME_DPLEInput);
      oscheme_ = IOScheme(SCHEME_DPLEOutput);
    }
  }
开发者ID:BrechtBa,项目名称:casadi,代码行数:32,代码来源:dple_internal.cpp

示例5: sp_rowcol

CRSSparsity sp_rowcol(std::vector<int> row, std::vector<int> col, int nrow, int ncol) {
  std::vector<int> rowind(nrow+1);
  std::vector<int> col_new(row.size()*col.size());
  
  // resulting col: the entries of col are repeated row.size() times
  for (int i=0;i<row.size();i++)
    std::copy(col.begin(),col.end(),col_new.begin()+col.size()*i);

  // resulting rowind: first entry is always zero
  int cnt=0;
  int z=0;
  rowind[0]=0;
  int k=0;
  try {
    for (k=0; k < row.size(); k++) {
      // resulting rowind: fill up rowind entries with copies
      while (z<row[k])
        rowind.at(++z)=cnt;
        
      // resulting rowind: add col.size() at each row[k]
      rowind.at(row[k]+1)=(cnt+=col.size());
    }
    while (z<nrow)
      rowind.at(++z)=cnt;                 
  }
  catch (out_of_range& oor) {
    casadi_error(
      "sp_rowcol: out-of-range error." << endl <<
      "The " << k << "th entry of row (" << row[k] << ") was bigger or equal to the specified total number of rows (" << nrow << ")"
    );
  }
  return CRSSparsity(nrow, ncol, col_new, rowind);
}
开发者ID:tobias-verbeke,项目名称:casadi,代码行数:33,代码来源:sparsity_tools.cpp

示例6: switch

 bool QpoasesInterface::BooleanType_to_bool(qpOASES::BooleanType b) {
   switch (b) {
   case qpOASES::BT_TRUE:              return true;
   case qpOASES::BT_FALSE:             return false;
   default:                            casadi_error("not_implemented");
   }
 }
开发者ID:ghorn,项目名称:debian-casadi,代码行数:7,代码来源:qpoases_interface.cpp

示例7: acadoIn

std::vector<M> acadoIn(const std::string arg_s0="",M arg_m0=M(),const std::string arg_s1="",M arg_m1=M(),const std::string arg_s2="",M arg_m2=M(),const std::string arg_s3="",M arg_m3=M(),const std::string arg_s4="",M arg_m4=M(),const std::string arg_s5="",M arg_m5=M(),const std::string arg_s6="",M arg_m6=M(),const std::string arg_s7="",M arg_m7=M(),const std::string arg_s8="",M arg_m8=M(),const std::string arg_s9="",M arg_m9=M(),const std::string arg_s10="",M arg_m10=M(),const std::string arg_s11="",M arg_m11=M(),const std::string arg_s12="",M arg_m12=M(),const std::string arg_s13="",M arg_m13=M(),const std::string arg_s14="",M arg_m14=M(),const std::string arg_s15="",M arg_m15=M(),const std::string arg_s16="",M arg_m16=M()){
  std::vector<M> ret(17);
  std::map<std::string,M> arg;
  if (arg_s0!="") arg.insert(make_pair(arg_s0,arg_m0));
  if (arg_s1!="") arg.insert(make_pair(arg_s1,arg_m1));
  if (arg_s2!="") arg.insert(make_pair(arg_s2,arg_m2));
  if (arg_s3!="") arg.insert(make_pair(arg_s3,arg_m3));
  if (arg_s4!="") arg.insert(make_pair(arg_s4,arg_m4));
  if (arg_s5!="") arg.insert(make_pair(arg_s5,arg_m5));
  if (arg_s6!="") arg.insert(make_pair(arg_s6,arg_m6));
  if (arg_s7!="") arg.insert(make_pair(arg_s7,arg_m7));
  if (arg_s8!="") arg.insert(make_pair(arg_s8,arg_m8));
  if (arg_s9!="") arg.insert(make_pair(arg_s9,arg_m9));
  if (arg_s10!="") arg.insert(make_pair(arg_s10,arg_m10));
  if (arg_s11!="") arg.insert(make_pair(arg_s11,arg_m11));
  if (arg_s12!="") arg.insert(make_pair(arg_s12,arg_m12));
  if (arg_s13!="") arg.insert(make_pair(arg_s13,arg_m13));
  if (arg_s14!="") arg.insert(make_pair(arg_s14,arg_m14));
  if (arg_s15!="") arg.insert(make_pair(arg_s15,arg_m15));
  if (arg_s16!="") arg.insert(make_pair(arg_s16,arg_m16));
  typedef typename std::map<std::string,M>::const_iterator it_type;
  for(it_type it = arg.begin(); it != arg.end(); it++) {
    int n = getSchemeEntryEnum(SCHEME_ACADO_Input,it->first);
    if (n==-1)
      casadi_error("Keyword error in ACADO_Input: '" << it->first << "' is not recognized. Available keywords are: x_guess, u_guess, p_guess, lbx, ubx, lbx0, ubx0, lbxf, ubxf, lbu, ubu, lbp, ubp, lbc, ubc, lbr, ubr");
    ret[n] = it->second;
  }
  return ret;
}
开发者ID:tobias-verbeke,项目名称:casadi,代码行数:29,代码来源:autogenerated.hpp

示例8: printOption

GenericType OptionsFunctionalityNode::getOption(const string &name) const{

  // Locate the option
  Dictionary::const_iterator it = dictionary_.find(name);

  // Check if found
  if(it == dictionary_.end()){
    stringstream ss;
    if (allowed_options.find(name)!=allowed_options.end()) {
      ss << "Option: '" << name << "' has not been set." << endl;
      printOption(name,ss);
    } else {
      ss << "Option: '" << name << "' does not exist." << endl << endl;
      std::vector<std::string> suggestions;
      getBestMatches(name,suggestions,5);
      ss << "Did you mean one of the following?" << endl;
      for (int i=0;i<suggestions.size();++i)
        printOption(suggestions[i],ss);
      ss << "Use printOptions() to get a full list of options." << endl;
    }
    casadi_error(ss.str());
  }
  
  // Return the option
  return GenericType(it->second);
}
开发者ID:tobias-verbeke,项目名称:casadi,代码行数:26,代码来源:options_functionality.cpp

示例9: log

  bool IpoptInternal::eval_grad_f(int n, const double* x, bool new_x, double* grad_f)
  {
    try {
      log("eval_grad_f started");
      double time1 = clock();
      casadi_assert(n == nx_);
    
      // Pass the argument to the function
      gradF_.setInput(x,NL_X);
      gradF_.setInput(input(NLP_SOLVER_P),NL_P);
      
      // Evaluate, adjoint mode
      gradF_.evaluate();
      
      // Get the result
      gradF_.output().getArray(grad_f,n,DENSE);
      
      // Printing
      if(monitored("eval_grad_f")){
        cout << "x = " << gradF_.input(NL_X) << endl;
        cout << "grad_f = " << gradF_.output() << endl;
      }

      if (regularity_check_ && !isRegular(gradF_.output().data())) casadi_error("IpoptInternal::grad_f: NaN or Inf detected.");
    
      double time2 = clock();
      t_eval_grad_f_ += double(time2-time1)/CLOCKS_PER_SEC;
      n_eval_grad_f_ += 1;
      log("eval_grad_f ok");
      return true;
    } catch (exception& ex){
      cerr << "eval_grad_f failed: " << ex.what() << endl;
      return false;
    }
  }
开发者ID:zhenglei-gao,项目名称:casadi,代码行数:35,代码来源:ipopt_internal.cpp

示例10: find

  void Options::check(const Dict& opts) const {
    // Make sure all options exist and have the correct type
    for (auto&& op : opts) {
      const Options::Entry* entry = find(op.first);

      // Informative error message if option does not exist
      if (entry==nullptr) {
        stringstream ss;
        ss << "Unknown option: " << op.first << endl;
        ss << endl;
        ss << "Did you mean one of the following?" << endl;
        for (auto&& s : suggestions(op.first)) {
          print_one(s, ss);
        }
        ss << "Use print_options() to get a full list of options." << endl;
        casadi_error(ss.str());
      }

      // Check type
      casadi_assert(op.second.can_cast_to(entry->type),
                            "Illegal type for " + op.first + ": " +
                            op.second.get_description() +
                            " cannot be cast to " +
                            GenericType::get_type_description(entry->type) + ".");

    }
  }
开发者ID:casadi,项目名称:casadi,代码行数:27,代码来源:options.cpp

示例11: name

  SXElement Variable::atTime(double t, bool allocate) {
    // Find an existing element
    map<double, SXElement>::const_iterator it = timed_.find(t);

    // If not found
    if (it==timed_.end()) {
      if (allocate) {
        // Create a timed variable
        stringstream ss;
        ss << name() << ".atTime(" << t << ")";
        SXElement tvar = SXElement::sym(ss.str());

        // Save to map
        timed_[t] = tvar;

        // Return the expression
        return tvar;
      } else {
        casadi_error(" has no timed variable with t = " << t << ".");
      }

    } else {
      // Return the expression
      return it->second;
    }
  }
开发者ID:tmmsartor,项目名称:casadi,代码行数:26,代码来源:variable.cpp

示例12: if

  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();
  }
开发者ID:BrechtBa,项目名称:casadi,代码行数:27,代码来源:nlp_solver.cpp

示例13: getRealTime

  void LapackLuDense::prepare() {
    double time_start=0;
    if (CasadiOptions::profiling && CasadiOptions::profilingBinary) {
      time_start = getRealTime(); // Start timer
      profileWriteEntry(CasadiOptions::profilingLog, this);
    }
    prepared_ = false;

    // Get the elements of the matrix, dense format
    input(0).get(mat_);

    if (equilibriate_) {
      // Calculate the col and row scaling factors
      double colcnd, rowcnd; // ratio of the smallest to the largest col/row scaling factor
      double amax; // absolute value of the largest matrix element
      int info = -100;
      dgeequ_(&ncol_, &nrow_, getPtr(mat_), &ncol_, getPtr(r_),
              getPtr(c_), &colcnd, &rowcnd, &amax, &info);
      if (info < 0)
          throw CasadiException("LapackQrDense::prepare: "
                                "dgeequ_ failed to calculate the scaling factors");
      if (info>0) {
        stringstream ss;
        ss << "LapackLuDense::prepare: ";
        if (info<=ncol_)  ss << (info-1) << "-th row (zero-based) is exactly zero";
        else             ss << (info-1-ncol_) << "-th col (zero-based) is exactly zero";

        userOut() << "Warning: " << ss.str() << endl;



        if (allow_equilibration_failure_)  userOut() << "Warning: " << ss.str() << endl;
        else                              casadi_error(ss.str());
      }

      // Equilibrate the matrix if scaling was successful
      if (info!=0)
        dlaqge_(&ncol_, &nrow_, getPtr(mat_), &ncol_, getPtr(r_), getPtr(c_),
                &colcnd, &rowcnd, &amax, &equed_);
      else
        equed_ = 'N';
    }

    // Factorize the matrix
    int info = -100;
    dgetrf_(&ncol_, &ncol_, getPtr(mat_), &ncol_, getPtr(ipiv_), &info);
    if (info != 0) throw CasadiException("LapackLuDense::prepare: "
                                         "dgetrf_ failed to factorize the Jacobian");

    // Success if reached this point
    prepared_ = true;

    if (CasadiOptions::profiling && CasadiOptions::profilingBinary) {
      double time_stop = getRealTime(); // Stop timer
      profileWriteTime(CasadiOptions::profilingLog, this, 0, time_stop-time_start,
                       time_stop-time_start);
      profileWriteExit(CasadiOptions::profilingLog, this, time_stop-time_start);
    }
  }
开发者ID:BrechtBa,项目名称:casadi,代码行数:59,代码来源:lapack_lu_dense.cpp

示例14: casadi_error

  void SXFunctionInternal::generateDeclarations(CodeGenerator& g) const {

    // Make sure that there are no free variables
    if (!free_vars_.empty()) {
      casadi_error("Code generation is not possible since variables "
                   << free_vars_ << " are free.");
    }
  }
开发者ID:jgillis,项目名称:casadi,代码行数:8,代码来源:sx_function_internal.cpp

示例15: casadi_error

  void Assertion::eval(const double** arg, double** res, int* iw, double* w, int mem) const {
    if (arg[1][0]!=1) {
      casadi_error("Assertion error: " << fail_message_);
    }

    if (arg[0]!=res[0]) {
      copy(arg[0], arg[0]+nnz(), res[0]);
    }
  }
开发者ID:RobotXiaoFeng,项目名称:casadi,代码行数:9,代码来源:assertion.cpp


注:本文中的casadi_error函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。