Next: Coding the Executable (main)
Up: Coding the Problem Representation
Previous: Method eval_h
Contents
with prototype
virtual void 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)
This is the only method that is not mentioned in Figure
2. This method is called by IPOPT after the
algorithm has finished (successfully or even with most errors).
- status: (in), gives the status of the algorithm as
specified in IpAlgTypes.hpp,
- SUCCESS: Algorithm terminated successfully at a locally
optimal point, satisfying the convergence tolerances (can be
specified by options).
- MAXITER_EXCEEDED: Maximum number of iterations exceeded
(can be specified by an option).
- STOP_AT_TINY_STEP: Algorithm proceeds with very
little progress.
- STOP_AT_ACCEPTABLE_POINT: Algorithm stopped at a
point that was converged, not to ``desired'' tolerances, but to
``acceptable'' tolerances (see the acceptable-... options).
- LOCAL_INFEASIBILITY: Algorithm converged to a point of
local infeasibility. Problem may be infeasible.
- USER_REQUESTED_STOP: The user call-back function intermediate_callback (see Section 3.3.4)
returned false, i.e., the user code requested a premature
termination of the optimization.
- DIVERGING_ITERATES: It seems that the iterates diverge.
- RESTORATION_FAILURE: Restoration phase failed,
algorithm doesn't know how to proceed.
- ERROR_IN_STEP_COMPUTATION: An unrecoverable error
occurred while IPOPT tried to compute the search direction.
- INVALID_NUMBER_DETECTED: Algorithm received an
invalid number (such as NaN or Inf) from the NLP; see
also option check_derivatives_for_naninf.
- INTERNAL_ERROR: An unknown internal error occurred. Please
contact the IPOPT authors through the mailing list.
- n: (in), the number of variables in the problem (dimension
of
).
- x: (in), the final values for the primal variables,
.
- z_L: (in), the final values for the lower bound
multipliers,
.
- z_U: (in), the final values for the upper bound
multipliers,
.
- m: (in), the number of constraints in the problem
(dimension of
).
- g: (in), the final value of the constraint function
values,
.
- lambda: (in), the final values of the constraint
multipliers,
.
- obj_value: (in), the final value of the objective,
.
- ip_data and ip_cq are provided for expert users.
This method gives you the return status of the algorithm
(SolverReturn), and the values of the variables,
the objective and constraint function values when the algorithm exited.
In our example, we will print the values of some of the variables to
the screen.
void HS071_NLP::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)
{
// here is where we would store the solution to variables, or write to a file, etc
// so we could use the solution.
// For this example, we write the solution to the console
printf("\n\nSolution of the primal variables, x\n");
for (Index i=0; i<n; i++) {
printf("x[%d] = %e\n", i, x[i]);
}
printf("\n\nSolution of the bound multipliers, z_L and z_U\n");
for (Index i=0; i<n; i++) {
printf("z_L[%d] = %e\n", i, z_L[i]);
}
for (Index i=0; i<n; i++) {
printf("z_U[%d] = %e\n", i, z_U[i]);
}
printf("\n\nObjective value\n");
printf("f(x*) = %e\n", obj_value);
}
This is all that is required for our HS071_NLP class and
the coding of the problem representation.
Next: Coding the Executable (main)
Up: Coding the Problem Representation
Previous: Method eval_h
Contents
Andreas Waechter
2008-08-26