<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>Driver for Running the Ipopt ODE Example</title>
<meta name="description" id="description" content="Driver for Running the Ipopt ODE Example"/>
<meta name="keywords" id="keywords" content=" "/>
<style type='text/css'>
body { color : black }
body { background-color : white }
A:link { color : blue }
A:visited { color : purple }
A:active { color : purple }
</style>
<script type='text/javascript' language='JavaScript' src='_ipopt_ode_run.hpp_xml.js'>
</script>
</head>
<body>
<table><tr>
<td>
<a href="http://www.coin-or.org/CppAD/" target="_top"><img border="0" src="_image.gif"/></a>
</td>
<td><a href="ipopt_ode_fast.hpp.xml" target="_top">Prev</a>
</td><td><a href="ipopt_ode_check.cpp.xml" target="_top">Next</a>
</td><td>
<select onchange='choose_across0(this)'>
<option>Index-&gt;</option>
<option>contents</option>
<option>reference</option>
<option>index</option>
<option>search</option>
<option>external</option>
</select>
</td>
<td>
<select onchange='choose_up0(this)'>
<option>Up-&gt;</option>
<option>CppAD</option>
<option>cppad_ipopt_nlp</option>
<option>cppad_ipopt_ode</option>
<option>ipopt_ode_run.hpp</option>
</select>
</td>
<td>
<select onchange='choose_down3(this)'>
<option>CppAD-&gt;</option>
<option>Install</option>
<option>Introduction</option>
<option>AD</option>
<option>ADFun</option>
<option>multi_thread</option>
<option>library</option>
<option>cppad_ipopt_nlp</option>
<option>Example</option>
<option>preprocessor</option>
<option>Appendix</option>
</select>
</td>
<td>
<select onchange='choose_down2(this)'>
<option>cppad_ipopt_nlp-&gt;</option>
<option>cppad_ipopt_windows</option>
<option>ipopt_get_started.cpp</option>
<option>cppad_ipopt_ode</option>
<option>ipopt_ode_speed.cpp</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>cppad_ipopt_ode-&gt;</option>
<option>ipopt_ode_problem</option>
<option>ipopt_ode_simple</option>
<option>ipopt_ode_fast</option>
<option>ipopt_ode_run.hpp</option>
<option>ipopt_ode_check.cpp</option>
</select>
</td>
<td>ipopt_ode_run.hpp</td>
<td>Headings</td>
</tr></table><br/>



<center><b><big><big>Driver for Running the Ipopt ODE Example</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 
# include &quot;ode_problem.hpp&quot;

namespace { // BEGIN empty namespace -----------------------------------------
using namespace cppad_ipopt;

template &lt;class FG_info&gt;
void ipopt_ode_case(
	bool  retape        ,
	const SizeVector&amp; N ,
	NumberVector&amp;     x )
{	bool ok = true;
	size_t i, j;

	// compute the partial sums of the number of grid points
	assert( N.size() == Nz + 1);
	assert( N[0] == 0 );
	SizeVector S(Nz+1);
	S[0] = 0;
	for(i = 1; i &lt;= Nz; i++)
		S[i] = S[i-1] + N[i];
	
	// number of components of x corresponding to values for y
	size_t ny_inx = (S[Nz] + 1) * Ny;
	// number of constraints (range dimension of g)
	size_t m      = ny_inx;
	// number of components in x (domain dimension for f and g)
	size_t n      = ny_inx + Na;
	// the argument vector for the optimization is 
	// y(t) at t[0] , ... , t[S[Nz]] , followed by a
	NumberVector x_i(n), x_l(n), x_u(n);
	for(j = 0; j &lt; ny_inx; j++)
	{	x_i[j] = 0.;       // initial y(t) for optimization
		x_l[j] = -1.0e19;  // no lower limit
		x_u[j] = +1.0e19;  // no upper limit
	}
	for(j = 0; j &lt; Na; j++)
	{	x_i[ny_inx + j ] = .5;       // initiali a for optimization
		x_l[ny_inx + j ] =  -1.e19;  // no lower limit
		x_u[ny_inx + j ] =  +1.e19;  // no upper
	}
	// all of the difference equations are constrained to the value zero
	NumberVector g_l(m), g_u(m);
	for(i = 0; i &lt; m; i++)
	{	g_l[i] = 0.;
		g_u[i] = 0.;
	}

	// object defining the objective f(x) and constraints g(x)
	FG_info fg_info(retape, N);

	// create the CppAD Ipopt interface
	cppad_ipopt_solution solution;
	Ipopt::SmartPtr&lt;Ipopt::TNLP&gt; cppad_nlp = new cppad_ipopt_nlp(
		n, m, x_i, x_l, x_u, g_l, g_u, &amp;fg_info, &amp;solution
	);

	// Create an Ipopt application
	using Ipopt::IpoptApplication;
	Ipopt::SmartPtr&lt;IpoptApplication&gt; app = new IpoptApplication();

	// turn off any printing
	app-&gt;Options()-&gt;SetIntegerValue(&quot;print_level&quot;, 0);

	// maximum number of iterations
	app-&gt;Options()-&gt;SetIntegerValue(&quot;max_iter&quot;, 30);

	// approximate accuracy in first order necessary conditions;
	// see Mathematical Programming, Volume 106, Number 1, 
	// Pages 25-57, Equation (6)
	app-&gt;Options()-&gt;SetNumericValue(&quot;tol&quot;, 1e-9);

	// Derivative testing is very slow for large problems
	// so comment this out if you use a large value for N[].
	app-&gt;Options()-&gt; SetStringValue( &quot;derivative_test&quot;, &quot;second-order&quot;);
	app-&gt;Options()-&gt; SetNumericValue( &quot;point_perturbation_radius&quot;, 0.);

	// Initialize the application and process the options
	Ipopt::ApplicationReturnStatus status = app-&gt;Initialize();
	ok    &amp;= status == Ipopt::Solve_Succeeded;

	// Run the application
	status = app-&gt;OptimizeTNLP(cppad_nlp);
	ok    &amp;= status == Ipopt::Solve_Succeeded;

	// return the solution
	x.resize( solution.x.size() );
	for(j = 0; j &lt; x.size(); j++)
		x[j] = solution.x[j];

	return;
}
} // END empty namespace ----------------------------------------------------
</pre>

</font></code>


<hr/>Input File: cppad_ipopt/example/ode_run.hpp

</body>
</html>

