source: stable/2.4/ADOL-C/examples/additional_examples/ipopt/LuksanVlcek1/cpp_example.cpp

Last change on this file was 71, checked in by awalther, 9 years ago

add two example for the coupling of Ipopt and ADOL-C

File size: 1.9 KB
Line 
1/*----------------------------------------------------------------------------
2 ADOL-C -- Automatic Differentiation by Overloading in C++
3 File:     cpp_example.cpp
4 Revision: $$
5 Contents: example for class myADOLC_NPL for interfacing with Ipopt
6 
7 Copyright (c) Andrea Walther
8   
9 This file is part of ADOL-C. This software is provided as open source.
10 Any use, reproduction, or distribution of the software constitutes
11 recipient's acceptance of the terms of the accompanying license file.
12 
13 This code is based on the file corresponding file cpp_example.cpp contained
14 in the Ipopt package with the authors:  Carl Laird, Andreas Waechter   
15----------------------------------------------------------------------------*/
16
17//*************************************************************************
18//
19//
20//         Nothing has to be changed in this file !!
21//
22//
23//*************************************************************************
24
25#include "IpIpoptApplication.hpp"
26#include "IpSolveStatistics.hpp"
27#include "ADOL-C_NLP.hpp"
28
29using namespace Ipopt;
30
31int main(int argv, char* argc[])
32{
33  // Create an instance of your nlp...
34  SmartPtr<TNLP> myadolc_nlp = new MyADOLC_NLP();
35
36  // Create an instance of the IpoptApplication
37  SmartPtr<IpoptApplication> app = new IpoptApplication();
38
39  // Initialize the IpoptApplication and process the options
40  ApplicationReturnStatus status;
41  status = app->Initialize();
42  if (status != Solve_Succeeded) {
43    printf("\n\n*** Error during initialization!\n");
44    return (int) status;
45  }
46
47  status = app->OptimizeTNLP(myadolc_nlp);
48
49  if (status == Solve_Succeeded) {
50    // Retrieve some statistics about the solve
51    Index iter_count = app->Statistics()->IterationCount();
52    printf("\n\n*** The problem solved in %d iterations!\n", iter_count);
53
54    Number final_obj = app->Statistics()->FinalObjective();
55    printf("\n\n*** The final value of the objective function is %e.\n", final_obj);
56  }
57
58  return (int) status;
59}
Note: See TracBrowser for help on using the repository browser.