#include "AmplTNLP.hpp"
#include "IpIpoptApplication.hpp"
#include "IpoptConfig.h"
#include <cstring>
#include <cstdio>
int main(
int argc,
char** args)
{
using namespace Ipopt;
SmartPtr<IpoptApplication> app = IpoptApplicationFactory();
app->RethrowNonIpoptException(false);
if( argc == 2 )
{
bool print_options = false;
std::string print_options_mode("text");
if( !strcmp(args[1], "--print-options=latex") )
{
print_options = true;
print_options_mode = "latex";
}
else if( !strcmp(args[1], "--print-options=doxygen") )
{
print_options = true;
print_options_mode = "doxygen";
}
else if( !strcmp(args[1], "--print-options") )
{
print_options = true;
}
else if( !strcmp(args[1], "--print-latex-options") )
{
fprintf(stderr, "ampl_ipopt.cpp: Options --print-latex-options has been replaced by --print-options=latex. Please adjust your call.\n");
exit(-200);
}
if( print_options )
{
SmartPtr<OptionsList> options = app->Options();
options->SetStringValue("print_options_documentation", "yes");
options->SetStringValue("print_advanced_options", "yes");
options->SetStringValue("print_options_mode", print_options_mode);
app->Initialize("");
return 0;
}
}
ApplicationReturnStatus retval;
retval = app->Initialize("");
if( retval != Solve_Succeeded )
{
printf("ampl_ipopt.cpp: Error in first Initialize!!!!\n");
exit(-100);
}
SmartPtr<AmplSuffixHandler> suffix_handler = new AmplSuffixHandler();
suffix_handler->AddAvailableSuffix("scaling_factor", AmplSuffixHandler::Variable_Source,
AmplSuffixHandler::Number_Type);
suffix_handler->AddAvailableSuffix("scaling_factor", AmplSuffixHandler::Constraint_Source,
AmplSuffixHandler::Number_Type);
suffix_handler->AddAvailableSuffix("scaling_factor", AmplSuffixHandler::Objective_Source,
AmplSuffixHandler::Number_Type);
suffix_handler->AddAvailableSuffix("ipopt_zL_out", AmplSuffixHandler::Variable_Source,
AmplSuffixHandler::Number_Type);
suffix_handler->AddAvailableSuffix("ipopt_zU_out", AmplSuffixHandler::Variable_Source,
AmplSuffixHandler::Number_Type);
suffix_handler->AddAvailableSuffix("ipopt_zL_in", AmplSuffixHandler::Variable_Source,
AmplSuffixHandler::Number_Type);
suffix_handler->AddAvailableSuffix("ipopt_zU_in", AmplSuffixHandler::Variable_Source,
AmplSuffixHandler::Number_Type);
SmartPtr<TNLP> ampl_tnlp = new AmplTNLP(ConstPtr(app->Jnlst()), app->RegOptions(), app->Options(), args, suffix_handler);
retval = app->Initialize();
if( retval != Solve_Succeeded )
{
printf("ampl_ipopt.cpp: Error in second Initialize!!!!\n");
exit(-101);
}
const int n_loops = 1; for( Index i = 0; i < n_loops; i++ )
{
app->OptimizeTNLP(ampl_tnlp);
}
return 0;
}