提问人:mary 提问时间:7/20/2023 更新时间:9/14/2023 访问量:40
在 Visual Studio 2022 版本配置中不可设置的 IPOPT 选项
IPOPT Options Not Settable in Visual Studio 2022 Release Configuration
问:
我目前正在使用 Visual Studio 2022 在 C++ 中使用 IPOPT 解决优化问题。我正在使用 IPOPT 提供的HS071_NLP示例,我想使用以下代码限制迭代次数:
#include "IpIpoptApplication.hpp"
#include "hs071_nlp.hpp"
#include "ipoptOptimizer.h"
#include <iostream>
using namespace Ipopt;
int main()
{
SmartPtr<TNLP> mynlp = new HS071_NLP();
SmartPtr<IpoptApplication> app = IpoptApplicationFactory();
Ipopt::SmartPtr<Ipopt::OptionsList> options_list = app->Options();
try {
app->Options()->SetIntegerValue("max_iter", 500);
}
catch (std::exception e) {
std::cerr << "Exception while setting max_iter: " << e.what() << std::endl;
return 1;
}
ApplicationReturnStatus status;
status = app->Initialize();
if( status != Solve_Succeeded )
{
std::cout << std::endl << std::endl << "*** Error during initialization!" << std::endl;
return (int) status;
}
status = app->OptimizeTNLP(mynlp);
if( status == Solve_Succeeded )
{
std::cout << std::endl << std::endl << "*** The problem solved!" << std::endl;
}
else
{
std::cout << std::endl << std::endl << "*** The problem FAILED!" << std::endl;
}
return (int) status;
}
当我注释掉这一行时,代码工作正常:
// app->Options()->SetIntegerValue("max_iter", 50);
但是当我取消注释它时,我会收到以下输出:
已尝试设置选项:└t♂ä█uHç§zJ。这不是一个有效的选项。请查看可用选项列表。
此外,没有其他任何变化,优化在 50 次迭代后继续进行。
以下是一些其他详细信息:
- 我从这个下载了 IPOPT 库 IPOPT-3.14.12-win64-msvs2019-mdd.zip [链接:https://github.com/coin-or/Ipopt/releases/tag/releases%2F3.14.12]
- 我正在使用我的解决方案的发布配置。
我将不胜感激有关如何解决此问题的任何见解或建议,并在我的 IPOPT 优化中成功设置最大迭代次数。
谢谢!
答:
1赞
alex grn
9/14/2023
#1
IPOPT 有两个可再发行版本,zip 压缩文件,一个用于发布配置,带有 -md 后缀,另一个用于调试,带有 -mdd 后缀。适当使用它们。
评论