[Ipopt] Runtime modification of the model

Horand Gassmann Horand.Gassmann at DAL.CA
Sun Feb 27 12:49:43 EST 2011


Paul Smith <phhs80 at gmail.com> wrote:

> Thanks, Horand. The issue is how to populate the TNLP object.
> According to the Ipopt examples, we need to write the following
> methods:
>
>     * Method get_nlp_info
>     * Method get_bounds_info
>     * Method get_starting_point
>     * Method eval_f
>     * Method eval_grad_f
>     * Method eval_g
>     * Method eval_jac_g
>     * Method eval_h
>     * Method finalize_solution
>
> It seems to me that one needs to know in advance the structure of the
> model to write theses methods. For instance, suppose that one wants to
> write the method eval_f for the following objective function:
>
> x^2 + b y^3,
>
> with b being extracted from an uniform distribution. How could one
> write the eval_f method?
>
> But perhaps there a different way of populating the TNLP object that I
> am now aware of.

Hereès how we do it in OS (Optimization Services, another COIN project)

// returns the value of the objective function
bool IpoptProblem::eval_f(Index n, const Number* x, bool new_x,  
Number& obj_value){
	try{
		if(osinstance->getObjectiveNumber() > 0){
			if(new_x == false) obj_value  =  
osinstance->calculateAllObjectiveFunctionValues(  
const_cast<double*>(x), false)[ 0];
				else obj_value = osinstance->calculateAllObjectiveFunctionValues(  
const_cast<double*>(x), NULL, NULL, true, 0 )[ 0];
		}

	}
	catch(const ErrorClass& eclass){

		*ipoptErrorMsg = eclass.errormsg;
		throw;
	}

   	return true;
}


Note the call to our own method, which allows us to hide anything we  
need, and don't want Ipopt to worry about.






More information about the Ipopt mailing list