bool GenericType::operator!=(const GenericType& op2) const{ if(isString() && op2.isString()){ return toString().compare(op2.toString()) != 0; } if(isInt() && op2.isInt()){ return toInt() != op2.toInt(); } if(isDouble() && op2.isDouble()){ return toDouble() != op2.toDouble(); } if(isDoubleVector() && op2.isDoubleVector()){ const vector<double> &v1 = toDoubleVector(); const vector<double> &v2 = op2.toDoubleVector(); if(v1.size() != v2.size()) return true; for(int i=0; i<v1.size(); ++i) if(v1[i] != v2[i]) return true; return false; } if(isIntVector() && op2.isIntVector()){ const vector<int> &v1 = toIntVector(); const vector<int> &v2 = op2.toIntVector(); if(v1.size() != v2.size()) return true; for(int i=0; i<v1.size(); ++i) if(v1[i] != v2[i]) return true; return false; } // Different types return true; }
void IpoptInternal::init(){ // Free existing IPOPT instance freeIpopt(); // Call the init method of the base class NLPSolverInternal::init(); // Read user options exact_hessian_ = !hasSetOption("hessian_approximation") || getOption("hessian_approximation")=="exact"; #ifdef WITH_SIPOPT if(hasSetOption("run_sens")){ run_sens_ = getOption("run_sens")=="yes"; } else { run_sens_ = false; } if(hasSetOption("compute_red_hessian")){ compute_red_hessian_ = getOption("compute_red_hessian")=="yes"; } else { compute_red_hessian_ = false; } #endif // WITH_SIPOPT // Get/generate required functions gradF(); jacG(); if(exact_hessian_){ hessLag(); } // Start an IPOPT application Ipopt::SmartPtr<Ipopt::IpoptApplication> *app = new Ipopt::SmartPtr<Ipopt::IpoptApplication>(); app_ = static_cast<void*>(app); *app = new Ipopt::IpoptApplication(); #ifdef WITH_SIPOPT if(run_sens_ || compute_red_hessian_){ // Start an sIPOPT application Ipopt::SmartPtr<Ipopt::SensApplication> *app_sens = new Ipopt::SmartPtr<Ipopt::SensApplication>(); app_sens_ = static_cast<void*>(app_sens); *app_sens = new Ipopt::SensApplication((*app)->Jnlst(),(*app)->Options(),(*app)->RegOptions()); // Register sIPOPT options Ipopt::RegisterOptions_sIPOPT((*app)->RegOptions()); (*app)->Options()->SetRegisteredOptions((*app)->RegOptions()); } #endif // WITH_SIPOPT // Create an Ipopt user class -- need to use Ipopts spart pointer class Ipopt::SmartPtr<Ipopt::TNLP> *userclass = new Ipopt::SmartPtr<Ipopt::TNLP>(); userclass_ = static_cast<void*>(userclass); *userclass = new IpoptUserClass(this); if(verbose_){ cout << "There are " << nx_ << " variables and " << ng_ << " constraints." << endl; if(exact_hessian_) cout << "Using exact Hessian" << endl; else cout << "Using limited memory Hessian approximation" << endl; } bool ret = true; // Pass all the options to ipopt for(map<string,opt_type>::const_iterator it=ops_.begin(); it!=ops_.end(); ++it) if(hasSetOption(it->first)){ GenericType op = getOption(it->first); switch(it->second){ case OT_REAL: ret &= (*app)->Options()->SetNumericValue(it->first,op.toDouble(),false); break; case OT_INTEGER: ret &= (*app)->Options()->SetIntegerValue(it->first,op.toInt(),false); break; case OT_STRING: ret &= (*app)->Options()->SetStringValue(it->first,op.toString(),false); break; default: throw CasadiException("Illegal type"); } } if (!ret) casadi_error("IpoptInternal::Init: Invalid options were detected by Ipopt."); // Extra initialization required by sIPOPT // #ifdef WITH_SIPOPT // if(run_sens_ || compute_red_hessian_){ // Ipopt::ApplicationReturnStatus status = (*app)->Initialize(""); // casadi_assert_message(status == Solve_Succeeded, "Error during IPOPT initialization"); // } // #endif // WITH_SIPOPT // Intialize the IpoptApplication and process the options Ipopt::ApplicationReturnStatus status = (*app)->Initialize(); casadi_assert_message(status == Solve_Succeeded, "Error during IPOPT initialization"); #ifdef WITH_SIPOPT if(run_sens_ || compute_red_hessian_){ Ipopt::SmartPtr<Ipopt::SensApplication> *app_sens = static_cast<Ipopt::SmartPtr<Ipopt::SensApplication> *>(app_sens_); (*app_sens)->Initialize(); } #endif // WITH_SIPOPT }