source: trunk/example/ipopt_solve/solve.cpp @ 2859

Last change on this file since 2859 was 2859, checked in by bradbell, 7 years ago

merge in changes from branches/atomic; see bin/svn_merge.sh

  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1/* $Id: solve.cpp 2859 2013-05-28 06:03:21Z bradbell $ */
2/* --------------------------------------------------------------------------
3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-13 Bradley M. Bell
4
5CppAD is distributed under multiple licenses. This distribution is under
6the terms of the
7                    Eclipse Public License Version 1.0.
8
9A copy of this license is included in the COPYING file of this distribution.
10Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
11-------------------------------------------------------------------------- */
12
13// system include files used for I/O
14# include <iostream>
15
16// C style asserts
17# include <cassert>
18
19// ipopt solve include file
20# include <cppad/ipopt/solve.hpp>
21
22// external complied tests
23extern bool get_started(void);
24extern bool ode_inverse(void);
25extern bool retape(void);
26
27namespace {
28        // function that runs one test
29        static size_t Run_ok_count    = 0;
30        static size_t Run_error_count = 0;
31        bool Run(bool TestOk(void), const char *name)
32        {       bool ok = true;
33                double s0 = CppAD::elapsed_seconds();
34                ok &= TestOk();
35                double s1 = CppAD::elapsed_seconds();
36                double sec = std::floor(100*(s1 - s0) + 0.5) / 100.;
37                if( ok )
38                {       std::cout << "OK:    " << "ipopt_solve: " << name;
39                        std::cout << ", seconds = " << sec  << std::endl;
40                        Run_ok_count++;
41                }
42                else
43                {       std::cout << "Error: " << "ipopt_solve: " << name << std::endl;
44                        Run_error_count++;
45                }
46                return ok;
47        }
48}
49
50// main program that runs all the tests
51int main(void)
52{       bool ok = true;
53
54        // external compiled tests
55        ok &= Run( get_started,         "get_started"  );
56        ok &= Run( ode_inverse,         "ode_inverse"  );
57        ok &= Run( retape,              "retape"       );
58       
59        // check for errors
60        using std::cout;
61        using std::endl;
62        assert( ok || (Run_error_count > 0) );
63        if( CppAD::thread_alloc::free_all() )
64        {       Run_ok_count++;
65                cout << "OK:    " << "No memory leak detected" << endl;
66        }
67        else
68        {       ok = false;
69                Run_error_count++;
70                cout << "Error: " << "memory leak detected" << endl;
71        }
72        // convert int(size_t) to avoid warning on _MSC_VER systems
73        if( ok )
74                cout << "All " << int(Run_ok_count) << " tests passed." << endl;
75        else    cout << int(Run_error_count) << " tests failed." << endl;
76
77        return static_cast<int>( ! ok );
78}
Note: See TracBrowser for help on using the repository browser.