1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
|
// Copyright (C) 2005, 2009 International Business Machines and others.
// All Rights Reserved.
// This code is published under the Eclipse Public License.
//
// Authors: Andreas Waechter IBM 2004-11-05
#include "IpIpoptApplication.hpp"
#include "IpUtils.hpp"
#include "RegisteredTNLP.hpp"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
//**********************************************************************
// Stuff for benchmarking
// Enable this define to allow passing timelimit as 3rd program parameter
// #define TIME_LIMIT
//**********************************************************************
using namespace Ipopt;
using namespace std;
// This could probably be done more elegant and automatically, but I
// can't get it to work right now. For now, list explicitly the
// problems we want to include:
#include "LuksanVlcek1.hpp"
REGISTER_TNLP(LuksanVlcek1(0, 0), LukVlE1)
REGISTER_TNLP(LuksanVlcek1(-1., 0.), LukVlI1)
#include "LuksanVlcek2.hpp"
REGISTER_TNLP(LuksanVlcek2(0, 0), LukVlE2)
REGISTER_TNLP(LuksanVlcek2(-1., 0.), LukVlI2)
#include "LuksanVlcek3.hpp"
REGISTER_TNLP(LuksanVlcek3(0, 0), LukVlE3)
REGISTER_TNLP(LuksanVlcek3(-1., 0.), LukVlI3)
#include "LuksanVlcek4.hpp"
REGISTER_TNLP(LuksanVlcek4(0, 0), LukVlE4)
REGISTER_TNLP(LuksanVlcek4(-1., 0.), LukVlI4)
#include "LuksanVlcek5.hpp"
REGISTER_TNLP(LuksanVlcek5(0, 0), LukVlE5)
REGISTER_TNLP(LuksanVlcek5(-1., 0.), LukVlI5)
#include "LuksanVlcek6.hpp"
REGISTER_TNLP(LuksanVlcek6(0, 0), LukVlE6)
REGISTER_TNLP(LuksanVlcek6(-1., 0.), LukVlI6)
#include "LuksanVlcek7.hpp"
REGISTER_TNLP(LuksanVlcek7(0, 0), LukVlE7)
REGISTER_TNLP(LuksanVlcek7(-1., 0.), LukVlI7)
#include "MittelmannBndryCntrlDiri.hpp"
REGISTER_TNLP(MittelmannBndryCntrlDiri1, MBndryCntrl1)
REGISTER_TNLP(MittelmannBndryCntrlDiri2, MBndryCntrl2)
REGISTER_TNLP(MittelmannBndryCntrlDiri3, MBndryCntrl3)
REGISTER_TNLP(MittelmannBndryCntrlDiri4, MBndryCntrl4)
#include "MittelmannBndryCntrlDiri3D.hpp"
REGISTER_TNLP(MittelmannBndryCntrlDiri3D, MBndryCntrl_3D)
#include "MittelmannBndryCntrlDiri3D_27.hpp"
REGISTER_TNLP(MittelmannBndryCntrlDiri3D_27, MBndryCntrl_3D_27)
REGISTER_TNLP(MittelmannBndryCntrlDiri3D_27BT, MBndryCntrl_3D_27BT)
#include "MittelmannBndryCntrlDiri3Dsin.hpp"
REGISTER_TNLP(MittelmannBndryCntrlDiri3Dsin, MBndryCntrl_3Dsin)
#include "MittelmannBndryCntrlNeum.hpp"
REGISTER_TNLP(MittelmannBndryCntrlNeum1, MBndryCntrl5)
REGISTER_TNLP(MittelmannBndryCntrlNeum2, MBndryCntrl6)
REGISTER_TNLP(MittelmannBndryCntrlNeum3, MBndryCntrl7)
REGISTER_TNLP(MittelmannBndryCntrlNeum4, MBndryCntrl8)
#include "MittelmannDistCntrlDiri.hpp"
REGISTER_TNLP(MittelmannDistCntrlDiri1, MDistCntrl1)
REGISTER_TNLP(MittelmannDistCntrlDiri2, MDistCntrl2)
REGISTER_TNLP(MittelmannDistCntrlDiri3, MDistCntrl3)
REGISTER_TNLP(MittelmannDistCntrlDiri3a, MDistCntrl3a)
#include "MittelmannDistCntrlNeumA.hpp"
REGISTER_TNLP(MittelmannDistCntrlNeumA1, MDistCntrl4)
REGISTER_TNLP(MittelmannDistCntrlNeumA2, MDistCntrl5)
REGISTER_TNLP(MittelmannDistCntrlNeumA3, MDistCntrl6a)
#include "MittelmannDistCntrlNeumB.hpp"
REGISTER_TNLP(MittelmannDistCntrlNeumB1, MDistCntrl4a)
REGISTER_TNLP(MittelmannDistCntrlNeumB2, MDistCntrl5a)
REGISTER_TNLP(MittelmannDistCntrlNeumB3, MDistCntrl6)
#include "MittelmannParaCntrl.hpp"
REGISTER_TNLP(MittelmannParaCntrlBase<MittelmannParaCntrl5_1>, MPara5_1)
REGISTER_TNLP(MittelmannParaCntrlBase<MittelmannParaCntrl5_2_1>, MPara5_2_1)
REGISTER_TNLP(MittelmannParaCntrlBase<MittelmannParaCntrl5_2_2>, MPara5_2_2)
REGISTER_TNLP(MittelmannParaCntrlBase<MittelmannParaCntrl5_2_3>, MPara5_2_3)
static void print_problems()
{
printf("\nList of all registered problems:\n\n");
RegisteredTNLPs::PrintRegisteredProblems();
}
int main(
int argc,
char* argv[]
)
{
if( argc == 2 && !strcmp(argv[1], "list") )
{
print_problems();
return 0;
}
#ifdef TIME_LIMIT
int runtime;
if( argc == 4 )
{
runtime = atoi(argv[3]);
}
else
#endif
if( argc != 3 && argc != 1 )
{
printf("Usage: %s (this will ask for problem name)\n", argv[0]);
printf(" %s ProblemName N\n", argv[0]);
printf(" where N is a positive parameter determining problem size\n");
printf(" %s list\n", argv[0]);
printf(" to list all registered problems.\n");
return -1;
}
SmartPtr<RegisteredTNLP> tnlp;
Index N;
if( argc != 1 )
{
// Create an instance of your nlp...
tnlp = RegisteredTNLPs::GetTNLP(argv[1]);
if( !IsValid(tnlp) )
{
printf("Problem with name \"%s\" not known.\n", argv[1]);
print_problems();
return -2;
}
N = atoi(argv[2]);
}
else
{
bool done = false;
while( !done )
{
string inputword;
cout << "Enter problem name (or \"list\" for all available names):\n";
cin >> inputword;
if( inputword == "list" )
{
print_problems();
}
else
{
tnlp = RegisteredTNLPs::GetTNLP(inputword);
if( !IsValid(tnlp) )
{
printf("Problem with name \"%s\" not known.\n", inputword.c_str());
}
else
{
done = true;
}
}
}
cout << "Enter problem size:\n";
cin >> N;
}
if( N <= 0 )
{
printf("Given problem size is invalid.\n");
return -3;
}
bool retval = tnlp->InitializeProblem(N);
if( !retval )
{
printf("Cannot initialize problem. Abort.\n");
return -4;
}
// Create an instance of the IpoptApplication
// We are using the factory, since this allows us to compile this
// example with an Ipopt Windows DLL
SmartPtr<IpoptApplication> app = IpoptApplicationFactory();
ApplicationReturnStatus status;
status = app->Initialize();
if( status != Solve_Succeeded )
{
printf("\n\n*** Error during initialization!\n");
return (int) status;
}
// Set option to use internal scaling
// DOES NOT WORK FOR VLUKL* PROBLEMS:
// app->Options()->SetStringValueIfUnset("nlp_scaling_method", "user-scaling");
#ifdef TIME_LIMIT
app->Options()->SetNumericValue("max_wall_time", runtime);
#endif
Ipopt::RegisterInterruptHandler(NULL, &tnlp->interrupted_, 5);
status = app->OptimizeTNLP(GetRawPtr(tnlp));
Ipopt::UnregisterInterruptHandler();
return (int) status;
}
|