void IpoptOptions::setNumberOption (const char* label, const mxArray* ptr) { // Check whether the option value is a number. if (!mxIsDouble(ptr)) { char buf[256]; Snprintf(buf, 255, "IPOPT option value for option \"%s\" should be a number", label); throw MatlabException(buf); } // Set either the numeric option. double value = mxGetScalar(ptr); bool success = app.Options()->SetNumericValue(label,value); if (!success) { char buf[256]; Snprintf(buf, 255, "Invalid value for numeric IPOPT option \"%s\"", label); throw MatlabException(buf); } }
void IpoptOptions::setStringOption (const char* label, const mxArray* ptr) { // Check whether the option value is a string. if (!mxIsChar(ptr)) { char buf[256]; Snprintf(buf, 255, "IPOPT option value for option \"%s\" should be a string", label); throw MatlabException(buf); } // Get the option value. char* value = mxArrayToString(ptr); // Set the option. bool success = app.Options()->SetStringValue(label,value); if (!success) { char buf[256]; Snprintf(buf, 255, "Invalid value for IPOPT option \"%s\"", label); throw MatlabException(buf); } // Free the dynamically allocated memory. mxFree(value); }
void IpoptOptions::setOption (const char* label, const mxArray* ptr) { // Check to make sure we have a valid option. SmartPtr<const RegisteredOption> option = app.RegOptions()->GetOption(label); if (!IsValid(option)) { char buf[256]; Snprintf(buf, 255, "You have specified a nonexistent IPOPT option (\"%s\")", label); throw MatlabException(buf); } Ipopt::RegisteredOptionType type = option->Type(); if (type == Ipopt::OT_String) setStringOption(label,ptr); else if (type == Ipopt::OT_Integer) setIntegerOption(label,ptr); else setNumberOption(label,ptr); }