[Ipopt] Segmentation fault for very simple problem

Paul van Hoven paul.van.hoven at googlemail.com
Wed Jun 8 10:25:58 EDT 2011


I' m currently setting up ipopt in a c++ environent. Therefore  I
compiled and run the example code for hs_071 and it worked fine. Now,
I programmed a very very simple toy example to solve.

Here is the code of the NLP:

[BEGIN CODE]
#include "DemoProblem.hpp"

#include <cmath>

using namespace Ipopt;

DemoProblem::DemoProblem() {}

bool DemoProblem::get_nlp_info( Index& n, Index& m, Index& nnz_jac_g,
                             Index& nnz_h_lag, IndexStyleEnum& index_style )
{
	n = 2;
	m = 0;
	index_style = TNLP::C_STYLE;
	return true;
}



bool DemoProblem::get_bounds_info(Index n, Number* x_l, Number* x_u,
                                  Index m, Number* g_l, Number* g_u)
{
	assert( n == 2 );
	assert( m == 0 );
	
	
	x_l[0] = -10.0;
	x_l[1] = -10.0;
	
	x_u[0] = 10.1;
	x_u[1] = 10.1;
	
	return true;
}



bool DemoProblem::get_starting_point(Index n, bool init_x, Number* x,
                                   bool init_z, Number* z_L, Number* z_U,
                                   Index m, bool init_lambda,
                                   Number* lambda)
{
	assert( init_x == true );
	assert( init_z == false );
	assert( init_lambda == false );
	
	x[0] = 1.0;
	x[1] = 1.5;
	return true;
}



bool DemoProblem::eval_f(Index n, const Number* x, bool new_x, Number&
obj_value)
{
	obj_value = -pow( x[0]-.5, 2 ) + pow( x[1], 2 );
	return true;
}



bool DemoProblem::eval_grad_f(Index n, const Number* x, bool new_x,
Number* grad_f)
{
	grad_f[0] = -2*(x[0]-.5);
	grad_f[1] = -2*x[1];
	return true;
}



bool DemoProblem::eval_g(Index n, const Number* x, bool new_x, Index
m, Number* g)
	{ return true; }
	
bool DemoProblem::eval_jac_g(Index n, const Number* x, bool new_x,
							Index m, Index nele_jac, Index* iRow, Index *jCol,
							Number* values)
	{ return true; }
	
bool DemoProblem::eval_h(Index n, const Number* x, bool new_x,
							Number obj_factor, Index m, const Number* lambda,
							bool new_lambda, Index nele_hess, Index* iRow,
							Index* jCol, Number* values)
	{ return true; }



void DemoProblem::finalize_solution( SolverReturn status,
				Index n, const Number* x, const Number* z_L, const Number* z_U,
				Index m, const Number* g, const Number* lambda,
				Number obj_value, const IpoptData* ip_data,
IpoptCalculatedQuantities* ip_cq )
{
	cout << "Die Lösung lautet: " << obj_value << endl;
	cout << "Optimaler Punkt: " << endl;
	cout << "[" << x[0] << "," << x[1] << "]" << endl;
}
[END CODE]

It compiles fine but when I run it I get the following output

[BEGIN QUOTE]
./IPOptDemo

******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
 Ipopt is released as open source code under the Eclipse Public License (EPL).
         For more information visit http://projects.coin-or.org/Ipopt
******************************************************************************

This is Ipopt version 3.9.2, running with linear solver ma27.

Segmentation fault
[END QUOTE]

If I modify the bool get_bounds_info(...) method the following way
(commenting the bounds out)
[BEGIN CODE]
bool DemoProblem::get_bounds_info(Index n, Number* x_l, Number* x_u,
                                  Index m, Number* g_l, Number* g_u)
{
	assert( n == 2 );
	assert( m == 0 );
	
/*
	x_l[0] = -10.0;
	x_l[1] = -10.0;
	
	x_u[0] = 10.1;
	x_u[1] = 10.1;
*/	
	return true;
}
[END CODE]

it works fine and I get no segmentation fault. I don't see where I'm
making a mistake here. Maybee somebody can help me?




More information about the Ipopt mailing list