Example program
The following interactive session example enforces the same scalar
constraint as the nonlinear constraint example, but this time it uses
the augmented Lagrangian method to enforce the constraint and the
SBPLX algorithm, which does not support nonlinear constraints
itself, to perform the minimization. As before, the parameters must
always sum to 1, and the minimizer finds the same constrained minimum
of 22.5 at
(0.5, 0.5).
>>> import Numeric.LinearAlgebra ( dot, fromList, toList )
>>> let objf x = x `dot` x + 22
>>> let stop = ObjectiveRelativeTolerance 1e-9 :| []
>>> let algorithm = SBPLX objf [] Nothing
>>> let subproblem = LocalProblem 2 stop algorithm
>>> let x0 = fromList [5, 10]
>>> minimizeLocal subproblem x0
Right (Solution {solutionCost = 22.0, solutionParams = [0.0,0.0], solutionResult = FTOL_REACHED})
>>> -- define constraint function:
>>> let constraintf x = sum (toList x) - 1.0
>>> -- define constraint object to pass to the algorithm:
>>> let constraint = EqualityConstraint (Scalar constraintf) 1e-6
>>> let problem = AugLagProblem [constraint] [] (AUGLAG_EQ_LOCAL subproblem)
>>> minimizeAugLag problem x0
Right (Solution {solutionCost = 22.500000015505844, solutionParams = [0.5000880506776678,0.4999119493223323], solutionResult = FTOL_REACHED})