|
Pipal
1.2.0
Penalty Interior-Point ALgorithm
|
Solver class for the Pipal library. More...
#include <Solver.hxx>
Public Types | |
| using | ProblemPtr = typename Problem<Real>::UniquePtr |
| using | ObjectiveFunc = typename ProblemWrapper<Real>::ObjectiveFunc |
| using | ObjectiveGradientFunc = typename ProblemWrapper<Real>::ObjectiveGradientFunc |
| using | ConstraintsFunc = typename ProblemWrapper<Real>::ConstraintsFunc |
| using | ConstraintsJacobianFunc = typename ProblemWrapper<Real>::ConstraintsJacobianFunc |
| using | LagrangianHessianFunc = typename ProblemWrapper<Real>::LagrangianHessianFunc |
| using | BoundsFunc = typename ProblemWrapper<Real>::BoundsFunc |
Public Member Functions | |
| Solver ()=default | |
| Default constructor for the Pipal class. | |
| Solver (std::string const &name, ObjectiveFunc const &objective, ObjectiveGradientFunc const &objective_gradient, ConstraintsFunc const &constraints, ConstraintsJacobianFunc const &constraints_jacobian, LagrangianHessianFunc const &lagrangian_hessian, BoundsFunc const &primal_lower_bounds, BoundsFunc const &primal_upper_bounds, BoundsFunc const &constraints_lower_bounds, BoundsFunc const &constraints_upper_bounds) | |
| Constructor for the Pipal class. | |
| Solver (ProblemPtr &&problem) | |
| Constructor for the Pipal class (with a unique pointer to a Problem object). | |
| Solver (Solver const &)=delete | |
| Deleted copy constructor. | |
| Solver & | operator= (Solver const &)=delete |
| Deleted assignment operator. | |
| Solver (Solver &&)=delete | |
| Deleted move constructor. | |
| Solver & | operator= (Solver &&)=delete |
| Deleted move assignment operator. | |
| ~Solver ()=default | |
| Destructor for the Pipal class. | |
| void | problem (ProblemPtr &&problem) |
| Set the problem to be solved using a unique pointer. | |
| Problem< Real > const & | problem () const |
| Get the problem being solved. | |
| bool | verbose_mode () const |
| Get the verbose mode. | |
| void | verbose_mode (bool const t_verbose) |
| Set the verbose mode. | |
| bool | bfgs () const |
| Get the BFGS mode. | |
| void | bfgs (bool const t_bfgs) |
| Set the BFGS mode. | |
| Algorithm | algorithm () const |
| Get the algorithm mode. | |
| void | algorithm (Algorithm const t_algorithm) |
| Set the algorithm mode. | |
| void | tolerance (Real const t_tolerance) |
| Set the convergence tolerance for the solver. | |
| Real | tolerance () const |
| Get the tolerance for convergence. | |
| void | max_iterations (Integer const t_max_iterations) |
| Set the maximum number of iterations for the solver. | |
| Integer | max_iterations () const |
| Get the maximum number of iterations. | |
| bool | optimize (Vector< Real > const &x_guess, Vector< Real > &x_sol) |
| Solves the optimization problem using the interior-point method. | |
| void | getSolution (Vector< Real > &x, Vector< Real > &l) |
| Extract a primal-dual solution in original ordering. | |
Private Member Functions | |
| void | buildIterate () |
| Initialize an Iterate object for a given problem/input. | |
| void | evalStep () |
| Compute the search direction for the current iterate. | |
| void | updateParameters () |
| Update penalty and interior-point parameters based on KKT errors. | |
| void | lineSearch () |
| Line-search driver. | |
| void | bfgsUpdate (Vector< Real > const &s, Vector< Real > const &y) |
| Browder-Broyden-Fletcher-Goldfarb-Shanno (BFGS) update for the Hessian approximation. | |
| void | updateIterate () |
| Update the iterate after a trial step is accepted. | |
| void | updatePoint () |
| Apply a step to the primal and dual variables of the iterate. | |
| void | backtracking () |
| Backtracking line search. | |
| void | evalFunctions () |
| Evaluate objective and constraint functions at the current iterate. | |
| void | evalGradients () |
| Evaluate objective gradient and constraint Jacobian. | |
| void | evalHessian () |
| Evaluate the Hessian of the Lagrangian and assemble internal H. | |
| void | evalNewtonMatrix () |
| Assemble and (attempt to) factorize the Newton system matrix. | |
| void | evalScalings () |
| Evaluate scaling multipliers for objective and constraints. | |
| void | evalModels () |
| Evaluate model reductions and quality metric for a direction. | |
| void | fractionToBoundary () |
| Fraction-to-boundary rule for primal and dual variables. | |
| void | evalNewtonRhs () |
| Build the right-hand side vector for the Newton system. | |
| void | evalSlacks () |
| Compute internal slack variables from current iterate. | |
| void | evalMerit () |
| Compute the merit function value for the current iterate. | |
| void | initNewtonMatrix () |
| Reserve and initialize the internal sparse Newton matrix structure. | |
| void | resetDirection (Direction< Real > &d) const |
| Reset a search direction to zero and initialize norms. | |
| void | evalLambdaOriginal (Vector< Real > &l) const |
| Reconstruct multipliers in the original variable/constraint space. | |
| Real | evalViolation (Array< Real > const &cE, Array< Real > const &cI) const |
| Compute the 1-norm feasibility violation from equality/inequality values. | |
| void | evalNewtonStep () |
| Recover direction components from the Newton system solution. | |
| void | evalTrialStep (Direction< Real > &v) const |
| Store a trial step into another direction object. | |
| Integer | checkTermination () const |
| Check termination criteria for the solver. | |
| Integer | fullStepCheck () |
| Full-step check for trial penalty parameters. | |
| Integer | secondOrderCorrection () |
| Second-order correction (SOC). | |
| void | evalXOriginal (Vector< Real > &x) |
| Reconstruct the full primal vector in the original variable ordering. | |
| void | setDirection (Vector< Real > const &dx, Vector< Real > const &dr1, Vector< Real > const &dr2, Vector< Real > const &ds1, Vector< Real > const &ds2, Vector< Real > const &dlE, Vector< Real > const &dlI, Real const dx_norm, Real const dl_norm) |
| Populate a Direction object from its component vectors. | |
| void | evalTrialSteps (Direction< Real > &d1, Direction< Real > &d2, Direction< Real > &d3) |
| Compute and store directions for a few parameter combinations. | |
| void | evalTrialStepCut () |
| Scale a trial step by the fraction-to-boundary values. | |
| void | evalLinearCombination (Direction< Real > const &d1, Direction< Real > const &d2, Direction< Real > const &d3, Real const a1, Real const a2, Real const a3) |
| Evaluate a linear combination of up to three directions. | |
| Real | evalKKTError (Real const rho, Real const mu) |
| Compute the infinity-norm of the KKT optimality vector. | |
| void | evalKKTErrors () |
| Compute the three KKT error measures used by the solver. | |
| void | setPrimals (Vector< Real > const &x, Array< Real > const &r1, Array< Real > const &r2, Array< Real > const &s1, Array< Real > const &s2, Array< Real > const &lE, Array< Real > const &lI, Real const f, Array< Real > const &cE, Array< Real > const &cI, Real const phi) |
| Set primal/dual blocks and associated quantities on an iterate. | |
| void | buildInput (std::string const &name, Vector< Real > const &x0, Vector< Real > const &bl, Vector< Real > const &bu, Vector< Real > const &cl, Vector< Real > const &cu) |
| Build the input data for the solver. | |
| void | evalInfeasibility (Iterate< Real > &z) const |
| Compute scaled and unscaled feasibility violations. | |
| void | resetMuMaxExp () |
| Reset maximum exponent used for mu increases to its default. | |
| void | buildParameter (Algorithm t_algorithm) |
| Initialize algorithm parameters. | |
| void | setMuMaxExpZero () |
| Force mu exponent increases to use zero as maximum exponent. | |
| void | setRho (Real const rho) |
| Set penalty parameter rho. | |
| void | setRhoLast (Real const rho) |
| Set last (previous) penalty parameter value. | |
| void | setMu (Real const mu) |
Set interior-point parameter mu. | |
| void | evalDependent () |
| Evaluate quantities that depend on penalty/interior parameters. | |
| void | resetCounter () |
| Reset all internal counters to zero. | |
| void | incrementFactorizationCount () |
| Increment the matrix factorization counter. | |
| void | incrementFunctionCount () |
| Increment the function evaluation counter. | |
| void | incrementGradientCount () |
| Increment the gradient evaluation counter. | |
| void | incrementHessianCount () |
| Increment the Hessian evaluation counter. | |
| void | incrementIterationCount () |
| Increment the iteration counter. | |
Private Attributes | |
| Counter | m_counter |
| Acceptance< Real > | m_acceptance |
| Input< Real > | m_input |
| Direction< Real > | m_direction |
| Iterate< Real > | m_iterate |
| Output< Real > | m_output |
| Parameter< Real > | m_parameter |
| ProblemPtr | m_problem |
| bool | m_verbose {false} |
| bool | m_bfgs {false} |
The Solver class provides an interface for solving the optimization problems using Frank E. Curtis Pipal algorithm. It utilizes the Problem class to define the optimization problem and implements various methods for solving it.
| Real | The floating-point type used for computations (e.g., float, double). |
| using Pipal::Solver< Real >::BoundsFunc = typename ProblemWrapper<Real>::BoundsFunc |
| using Pipal::Solver< Real >::ConstraintsFunc = typename ProblemWrapper<Real>::ConstraintsFunc |
| using Pipal::Solver< Real >::ConstraintsJacobianFunc = typename ProblemWrapper<Real>::ConstraintsJacobianFunc |
| using Pipal::Solver< Real >::LagrangianHessianFunc = typename ProblemWrapper<Real>::LagrangianHessianFunc |
| using Pipal::Solver< Real >::ObjectiveFunc = typename ProblemWrapper<Real>::ObjectiveFunc |
| using Pipal::Solver< Real >::ObjectiveGradientFunc = typename ProblemWrapper<Real>::ObjectiveGradientFunc |
| using Pipal::Solver< Real >::ProblemPtr = typename Problem<Real>::UniquePtr |
|
default |
Initializes the solver with default values for the objective, gradient, constraints, and Jacobian functions.
|
inline |
Initializes the solver with the provided objective, gradient, constraints, and Jacobian functions.
| [in] | name | Name of the optimization problem. |
| [in] | objective | Objective function handle. |
| [in] | objective_gradient | Gradient of the objective function handle. |
| [in] | constraints | Constraints function handle. |
| [in] | constraints_jacobian | Jacobian of the constraints function handle. |
| [in] | lagrangian_hessian | Hessian of the Lagrangian function handle. |
| [in] | primal_lower_bounds | Lower bounds on the primal variables handle. |
| [in] | primal_upper_bounds | Upper bounds on the primal variables handle. |
| [in] | constraints_lower_bounds | Lower bounds on the constraints handle. |
| [in] | constraints_upper_bounds | Upper bounds on the constraints handle. |
|
inline |
|
delete |
|
delete |
|
default |
Cleans up resources used by the solver.
|
inline |
|
inline |
This method allows the user to specify the algorithm mode, which can be either CONSERVATIVE or ADAPTIVE.
| [in] | t_algorithm | The algorithm mode. |
|
private |
Performs a backtracking Armijo line search on the merit function. The routine updates the trial primal/dual variables using the candidate direction and the current acceptance object. On success the iterate is restored to the accepted trial point; otherwise the steplength is reduced until the Armijo condition or the fraction-to-boundary constraint prevents further reductions.
|
inline |
|
inline |
| [in] | t_bfgs | The BFGS mode. |
|
private |
This method updates the Hessian approximation using the Browder-Broyden-Fletcher-Goldfarb-Shanno (BFGS) formula*
\[ \mathbf{B}_{k+1} = \mathbf{B}_{k} - \displaystyle\frac{(\mathbf{B}_{k}\mathbf{s}_{k})( \mathbf{B}_{k}\mathbf{s}_{k}^\top)}{\mathbf{s}_{k}^\top \mathbf{B}_{k}\mathbf{s}_{k}} + \displaystyle\frac{\mathbf{y}\mathbf{y}^\top)}{\mathbf{y}^\top\mathbf{s}_{k}} \]
where \(B\) is the current Hessian approximation, \(s\) is the step taken, and \(y\) is the gradient difference.
| Real | Floating-point type used by the algorithm. |
| [in] | s | Step taken in primal variables. |
| [in] | y | Difference in gradients. |
|
private |
| [in] | name | Problem name. |
| [in] | x0 | Initial guess for the solution. |
| [in] | bl | Lower bounds for the variables. |
| [in] | bu | Upper bounds for the variables. |
| [in] | cl | Lower bounds for the constraints. |
| [in] | cu | Upper bounds for the constraints. |
|
private |
| Real | Floating-point type used by the algorithm. |
|
inlineprivate |
| [in] | t_algorithm | Algorithm selection enumerator. |
|
private |
Evaluates optimality/feasibility/iteration-count/bounds error conditions and returns the termination code used by the solver.
| Real | Floating-point type used by the algorithm. |
|
inlineprivate |
Runs slack, merit and KKT-error evaluations that are functions of the current penalty and interior-point parameters.
|
private |
| Real | Floating-point type used by the algorithm. |
|
private |
Calls the problem-provided gradient/jacobian functions in the original space, maps the results into the internal compressed representations and applies scaling. Increments gradient counters and handles exceptions.
| Real | Floating-point type used by the algorithm. |
|
private |
Calls the problem's Hessian-of-Lagrangian routine (with multipliers and primal variables in the original space), maps blocks into the internal sparse Hessian and rescales according to penalization and scaling factors.
| Real | Floating-point type used by the algorithm. |
|
inlineprivate |
| Real | Floating-point type used by the algorithm. |
| [in] | z | Current iterate. |
|
private |
| Real | Floating-point type used by the algorithm. |
| [in] | rho | Current penalty parameter. |
| [in] | mu | Current interior-point parameter. |
|
private |
| Real | Floating-point type used by the algorithm. |
|
private |
| Real | Floating-point type used by the algorithm. |
| [out] | l | Vector to store multipliers in original space. |
|
private |
| Real | Floating-point type used by the algorithm. |
| [in] | d1 | First direction. |
| [in] | d2 | Second direction. |
| [in] | d3 | Third direction. |
| [in] | a1 | Scalar multiplier for the first direction. |
| [in] | a2 | Scalar multiplier for the second direction. |
| [in] | a3 | Scalar multiplier for the third direction. |
|
private |
| Real | Floating-point type used by the algorithm. |
|
private |
| Real | Floating-point type used by the algorithm. |
|
private |
| Real | Floating-point type used by the algorithm. |
|
private |
| Real | Floating-point type used by the algorithm. |
|
private |
| Real | Floating-point type used by the algorithm. |
|
private |
| Real | Floating-point type used by the algorithm. |
|
private |
| Real | Floating-point type used by the algorithm. |
|
private |
| Real | Floating-point type used by the algorithm. |
|
private |
| Real | Floating-point type used by the algorithm. |
| [out] | v | Destination direction that will contain the trial step. |
|
private |
| Real | Floating-point type used by the algorithm. |
|
private |
|
private |
| Real | Floating-point type used by the algorithm. |
| [in] | cE | Equality constraint values. |
| [in] | cI | Inequality constraint values. |
|
private |
| Real | Floating-point type used by the algorithm. |
| [out] | x | Vector to store primal variables in original space. |
|
private |
Computes the maximum allowable primal and dual step fractions that keep interior-point slacks and multipliers within their prescribed bounds. The computed values are stored in the a.p0 (initial primal fraction), a.p (primal steplength) and a.d (dual steplength).
| Real | Floating-point type used by the algorithm. |
|
private |
Attempts full steps for a sequence of trial penalty parameters, verifying the Armijo condition on the merit. If a full step satisfies the acceptance condition the routine returns 1 and the iterate is left at the accepted trial point; otherwise the penalty parameter is decreased and the process repeats.
| Real | Floating-point type used by the algorithm. |
|
inline |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
private |
| Real | Floating-point type used by the algorithm. |
|
private |
Runs the fraction-to-boundary rule, full-step check, second-order correction and backtracking as needed to find an acceptable trial step. The acceptance object is updated with the final chosen step.
| Real | Floating-point type used by the algorithm. |
|
inline |
|
inline |
This method allows the user to specify the maximum number of iterations the solver will perform before stopping.
| [in] | t_max_iterations | The maximum number of iterations. |
|
delete |
|
delete |
|
inline |
This method implements the interior-point algorithm to solve the optimization problem defined by the objective function, constraints, and their respective gradients and Jacobians.
| [in] | x_guess | Initial guess for the optimization variables. |
| [out] | x_sol | Solution vector. |
|
inline |
|
inline |
This method allows the user to specify the problem to be solved using a unique pointer.
| [in] | problem | The unique pointer to the problem to set. |
|
inlineprivate |
|
private |
| Real | Floating-point type used by the algorithm. |
| [in] | d | Direction object to reset. |
|
inlineprivate |
| Real | Floating-point type used by the algorithm. |
|
private |
Attempts a second-order correction to improve feasibility when the trial step fails the Armijo condition (or other checks). The routine evaluates a corrected Newton step and tests acceptance similarly to the main line-search path.
| Real | Floating-point type used by the algorithm. |
|
private |
| Real | Floating-point type used by the algorithm. |
| [in] | dx | Primal component of the direction. |
| [in] | dr1 | Equality slack direction (first part). |
| [in] | dr2 | Equality slack direction (second part). |
| [in] | ds1 | Inequality slack direction (first part). |
| [in] | ds2 | Inequality slack direction (second part). |
| [in] | dlE | Equality multipliers direction. |
| [in] | dlI | Inequality multipliers direction. |
| [in] | dx_norm | Norm of the primal direction (precomputed). |
| [in] | dl_norm | Norm of the dual direction (precomputed). |
|
inlineprivate |
| Real | Floating-point type used by the algorithm. |
| [in] | mu | New interior-point parameter value. |
|
inlineprivate |
|
private |
| Real | Floating-point type used by the algorithm. |
| [in] | x | Primal variable vector. |
| [in] | r1 | Equality constraint slack variables (lower). |
| [in] | r2 | Equality constraint slack variables (upper). |
| [in] | s1 | Inequality constraint slack variables (lower). |
| [in] | s2 | Inequality constraint slack variables (upper). |
| [in] | lE | Equality constraint multipliers. |
| [in] | lI | Inequality constraint multipliers. |
| [in] | f | Objective function value. |
| [in] | cE | Equality constraint values. |
| [in] | cI | Inequality constraint values. |
| [in] | phi | Merit function value. |
|
inlineprivate |
| Real | Floating-point type used by the algorithm. |
| [in] | rho | New penalty parameter value. |
|
inlineprivate |
| Real | Floating-point type used by the algorithm. |
| [in] | rho | New last penalty parameter value. |
|
inline |
|
inline |
This method allows the user to specify the tolerance for convergence. The solver will stop when the residuals are below this tolerance.
| [in] | t_tolerance | The convergence tolerance. |
|
private |
Applies the accepted step to the iterate, recomputes infeasibility and gradients and updates parameter memory used for adaptive strategies.
| Real | Floating-point type used by the algorithm. |
|
private |
Adjusts rho and mu using the solver's adaptive rules to drive optimality and feasibility towards the desired tolerances.
| Real | Floating-point type used by the algorithm. |
|
private |
| Real | Floating-point type used by the algorithm. |
|
inline |
|
inline |
| [in] | t_verbose | The verbose mode. |
|
private |
Acceptance criteria for trial points.
|
private |
BFGS update flag.
|
private |
Internal counters for solver statistics.
|
private |
Current search direction of the solver.
|
private |
Input structure for the solver.
|
private |
Current iterate of the solver.
|
private |
Output class for managing solver output.
|
private |
Internal parameters for the solver algorithm.
|
private |
Problem object pointer.
|
private |
Verbosity flag.