Drake
 All Classes Files Functions Variables
NonlinearProgram Class Reference

minimize_x objective(x) subject to cin_lb<=nonlinear_inequality_constraints(x) <= cin_ub nonlinear_equality_constraints(x) = 0 Ain*x <= bin Aeq*x = beq x_lb <= x <= x_ub More...

Inheritance diagram for NonlinearProgram:
Collaboration diagram for NonlinearProgram:

Public Member Functions

function NonlinearProgram (num_vars, x_name)
 
function addCompositeConstraints (obj, cnstr, xind, data_ind)
 add a CompositeConstraint to the object, change the constraint evalation of the program. More...
 
function addConstraint (obj, cnstr, varargin)
 obj = addConstraint(obj,cnstr,varargin) Queries the constraint type and calls the appropriate addConstraint method (e.g. More...
 
function addNonlinearConstraint (obj, cnstr, xind, data_ind)
 add a NonlinearConstraint to the object, change the constraint evalation of the program. More...
 
function addLinearConstraint (obj, cnstr, xind)
 add a LinearConstraint to the program More...
 
function addBoundingBoxConstraint (obj, cnstr, xind)
 add a BoundingBoxConstraint to the program More...
 
function addCost (obj, cnstr, xind, data_ind)
 Add a cost to the objective function. More...
 
function addQuadraticCost (obj, Q, x_desired, xind)
 helper function for the very common case of adding the objective g(x) = (x-xd)'Q(x-xd), Q = Q' >= 0 More...
 
function getArgumentArray (obj, x, xind)
 Retrieves the elements from the vector x related to xind and returns them as a cell array where: args{i} = x(xind{i}) More...
 
function nonlinearConstraints (obj, x)
 evaluate the nonlinear constraints More...
 
function objective (obj, x)
 return the value of the objective More...
 
function objectiveAndNonlinearConstraints (obj, x)
 evaluate the objective and the nonlinear constraints altogher More...
 
function addDecisionVariable (obj, num_new_vars, var_name)
 appending new decision variables to the end of the current decision variables More...
 
function replaceCost (obj, cost, cost_idx, xind)
 replace the cost_idx'th cost in the original problem with a new cost More...
 
function addSharedDataFunction (obj, user_fun, xind)
 Adds the specified shared data function to be evaluated within each iteration of the program. More...
 
function getNumSharedDataFunctions (obj)
 
function evaluateSharedDataFunctions (obj, x)
 Evaluate all shared data functions and return the data object. More...
 
function addDisplayFunction (obj, display_fun, indices)
 add a dispay function that gets called on every iteration of the algorithm More...
 
function setCheckGrad (obj, check_grad)
 
function setConstraintErrTol (obj, tol)
 
function setSolver (obj, solver)
 
function setSolverOptions (obj, solver, optionname, optionval)
 
function getNonlinearGradientSparsity (obj)
 This function sets the nonlinear sparsity vector iGfun and jGvar based on the nonlinear sparsity of the objective, nonlinear inequality constraints and nonlinear equality constraints. More...
 
function bounds (obj)
 return the bounds for all the objective function, nonlinear constraints and linear constraints More...
 
function solve (obj, x0)
 
function compareSolvers (obj, x0, solvers)
 
function isNonlinearConstraintID (obj, cnstr_id)
 Given an ID, determine if any of the nonlinear constraint obj.nlcon has that ID. More...
 
function isLinearConstraintID (obj, cnstr_id)
 Given an ID, determine if any of the linear constraint obj.lcon has that ID. More...
 
function isBoundingBoxConstraintID (obj, cnstr_id)
 Given an ID, determine if any of the bounding box constraint obj.bbcon has that ID. More...
 
function deleteConstraint (obj, delete_cnstr_id)
 delete a constraint from the program More...
 
function updateConstraint (obj, varargin)
 update a Constraint of the program. More...
 
function deleteNonlinearConstraint (obj, delete_cnstr_id)
 delete a nonlinear constraint from the program More...
 
function updateNonlinearConstraint (obj, varargin)
 updateNonlinearConstraint(obj,cnstr_id,cnstr,xind,data_ind) update the nonlinear constraint whose id=cnstr_id with a new Constraint object cnstr, the newly added Constraint cnstr has the ID new_cnstr_id More...
 
function deleteLinearConstraint (obj, delete_cnstr_id)
 delete the LinearConstraint obj.lcon{cnstr_idx} from the program More...
 
function updateLinearConstraint (obj, varargin)
 updateLinearConstraint(obj,cnstr_id,cnstr,xind) update the linear constraint whose id=cnstr_id with a new Constraint object cnstr, the newly added Constraint cnstr has the ID new_cnstr_id More...
 
function deleteBoundingBoxConstraint (obj, cnstr_id)
 delete the BoundingBoxConstraint in obj.bbcon with ID=cnstr_id from the program More...
 
function updateBoundingBoxConstraint (obj, varargin)
 updateBoundingBoxConstraint(obj,cnstr_id,cnstr,xind) update the BoundingBoxConstraint whose id=cnstr_id with a new BoundingBoxConstraint cnstr More...
 

Protected Member Functions

function snopt (obj, x0)
 
function fmincon (obj, x0)
 if (obj.num_cin + obj.num_ceq) nonlinearConstraints = .nonlinearConstraint; else nonlinearConstraints = []; end More...
 
function ipopt (obj, x0)
 
function setVarBounds (obj, lb, ub)
 
function mapSolverInfo (obj, exitflag, x)
 Based on the solver information and solution, re-map the info. More...
 

Protected Attributes

Property num_vars
 
Property num_cin
 
Property num_ceq
 
Property Ain
 
Property bin
 
Property Ain_name
 
Property Aeq
 
Property beq
 
Property Aeq_name
 
Property cin_lb
 
Property cin_ub
 
Property cin_name
 
Property ceq_name
 
Property x_lb
 
Property x_ub
 
Property x_name
 
Property solver
 
Property solver_options
 
Property display_funs
 
Property display_fun_indices
 
Property check_grad
 
Property constraint_err_tol
 numerical gradient at the begining and end of the nonlinear optimization More...
 
Property nlcon
 
Property lcon
 
Property bbcon
 
Property cost
 
Property nlcon_xind
 
Property bbcon_xind
 nlcon{i}.eval(x(nlcon_xind{i}{1},x(nlcon_xind{i}{2},) cost_xind_cell % A cell array, cost_xind{i} is a cell array of int vectors recording the indices of x that is used in evaluating obj.cost{i} More...
 
Property shared_data_xind_cell
 a cell array like nlcon_xind, where shared_data_xind_cell{i} is a cell array of int vectors recording indices used in evaluating the shared_data_function More...
 
Property nlcon_dataind
 a cell array of function handles, each of which returns a data object so that shared_data{i} = shared_data_functions(x(shared_data_xind_cell{i}{1}),x(shared_data_xind_cell{i}{2}),) shared_data_functions More...
 
Property cost_dataind
 
Property iFfun
 2 if user has their own snopt in MATLAB path More...
 
Property iCinfun
 
Property iCeqfun
 

Detailed Description

minimize_x objective(x) subject to cin_lb<=nonlinear_inequality_constraints(x) <= cin_ub nonlinear_equality_constraints(x) = 0 Ain*x <= bin Aeq*x = beq x_lb <= x <= x_ub

Constructor & Destructor Documentation

function NonlinearProgram ( num_vars  ,
x_name   
)
Parameters
num_vars– Number of decision variables
x_name– An optional argument. A cell of strings containing the name of each decision variable
Return values
obj

Member Function Documentation

function addBoundingBoxConstraint ( obj  ,
cnstr  ,
xind   
)

add a BoundingBoxConstraint to the program

Parameters
cnstr– A BoundingBoxConstraint
xind– Optional argument. x(xind) is the decision variables to be set bounds
Return values
cnstr_id– The ID stored in obj.bbcon_id. This is the unique ID of the newly added constraint in the program.
function addCompositeConstraints ( obj  ,
cnstr  ,
xind  ,
data_ind   
)

add a CompositeConstraint to the object, change the constraint evalation of the program.

Parameters
mgr– A CompositeConstraint object
xind– Optional argument. The x(xind) is the decision variables used in evaluating the cnstr. Default value is (1:obj.num_vars)
data_ind– Optional argument. shared_data{data_ind} are the data objects used
Return values
cnstr_id– A vector, cnstr_id(i) is the unique ID of the newly added constraint cnstr{i} in the program
function addConstraint ( obj  ,
cnstr  ,
varargin   
)

obj = addConstraint(obj,cnstr,varargin) Queries the constraint type and calls the appropriate addConstraint method (e.g.

addLinearConstraint, etc)

Parameters
cnstra Constraint object. if cnstr is a cell array, then each of the constraints are added individually.
vararginthe remaining arguments are passed directly through to the specialized methods. Note that if cnstr is a cell array, then the same varargin is passed to all of the specialized methods.
Return values
cnstr_idThe unique ID of the newly added constraint in the program.
function addCost ( obj  ,
cnstr  ,
xind  ,
data_ind   
)

Add a cost to the objective function.

Parameters
cnstr– A NonlinearConstraint or a LinearConstraint
xind– Optional argument. x(xind) is the decision variables used in evaluating the cost. Default value is (1:obj.num_vars)
data_ind– Optional argument. shared_data{data_ind} are the data objects used
Return values
obj
function addDecisionVariable ( obj  ,
num_new_vars  ,
var_name   
)

appending new decision variables to the end of the current decision variables

Parameters
num_new_vars– An integer. The newly added decision variable is an num_new_vars x 1 double vector.
var_name– An optional argument. A cell of strings containing the name of the new decision variables
Return values
new_variable_idx– A num_new_vars x 1 vector. x(new_variable_idx) is the newly added variables
function addDisplayFunction ( obj  ,
display_fun  ,
indices   
)

add a dispay function that gets called on every iteration of the algorithm

Parameters
display_funa function handle of the form displayFun(x(indices))
indicesoptionally specify a subset of the decision variables to be passed to the displayFun
Default: 1:obj.num_vars
Return values
obj
function addLinearConstraint ( obj  ,
cnstr  ,
xind   
)

add a LinearConstraint to the program

Parameters
cnstr– A LinearConstraint object
xind– Optional argument. x(xind) is the decision variables used in evaluating the constraint. Default value is (1:obj.num_vars)
cnstr_name– An optional argument. A cell of strings. cnstr_name{i} is the name of the i'th constraint. If not given, the cnstr.name will be used instead
Return values
cnstr_id– The ID stored in obj.lcon_id. This is the unique ID of the newly added constraint in the program. if cnstr.num_cnstr > 0
function addNonlinearConstraint ( obj  ,
cnstr  ,
xind  ,
data_ind   
)

add a NonlinearConstraint to the object, change the constraint evalation of the program.

Parameters
cnstr– A NonlinearConstraint object
xind– Optional argument. The x(xind) is the decision variables used in evaluating the cnstr. Default value is (1:obj.num_vars)
data_ind– Optional argument. shared_data{data_ind} are the data objects used
Return values
cnstr_id– The ID of stored in obj.nlcon_id, this is the unique ID of the newly added constraint in the program.
function addQuadraticCost ( obj  ,
,
x_desired  ,
xind   
)

helper function for the very common case of adding the objective g(x) = (x-xd)'Q(x-xd), Q = Q' >= 0

Parameters
Qa symmetric PSD cost matrix
x_desiredcolumn vector of desired values
xindoptional subset of x to apply cost to
Return values
obj
function addSharedDataFunction ( obj  ,
user_fun  ,
xind   
)

Adds the specified shared data function to be evaluated within each iteration of the program.

Parameters
user_fun– The function to be evaluated, where shared_data{ind} = user_fun(x(xind));
xind– Optional argument. The x(xind) is the decision variables used in evaluating the cnstr. Default value is (1:obj.num_vars)
Returns
ind – the shared data index
Return values
obj
ind
function bounds ( obj  )

return the bounds for all the objective function, nonlinear constraints and linear constraints

Return values
lb
ub
function compareSolvers ( obj  ,
x0  ,
solvers   
)
Return values
x
objval
exitflag
execution_time
solvers
function deleteBoundingBoxConstraint ( obj  ,
cnstr_id   
)

delete the BoundingBoxConstraint in obj.bbcon with ID=cnstr_id from the program

Parameters
cnstr_idThe unique ID of the BoundingBoxConstraint in obj.bbcon that is going to be deleted
Return values
obj
function deleteConstraint ( obj  ,
delete_cnstr_id   
)

delete a constraint from the program

Parameters
delete_cnstr_idThe Constraint object whose ID=delete_cnstr_id is going to be deleted from the program
Return values
obj
function deleteLinearConstraint ( obj  ,
delete_cnstr_id   
)

delete the LinearConstraint obj.lcon{cnstr_idx} from the program

Parameters
cnstr_idThe ID of the linear constraint to be deleted in the program
Return values
obj
function deleteNonlinearConstraint ( obj  ,
delete_cnstr_id   
)

delete a nonlinear constraint from the program

Parameters
delete_cnstr_idThe id of the constraint being deleted. The id is generated when calling addNonlinearConstraint or updateNonlinearConstraint
Return values
obj
function evaluateSharedDataFunctions ( obj  ,
 
)

Evaluate all shared data functions and return the data object.

Return values
data
function fmincon ( obj  ,
x0   
)
protected

if (obj.num_cin + obj.num_ceq) nonlinearConstraints = .nonlinearConstraint; else nonlinearConstraints = []; end

Return values
x
objval
exitflag
infeasible_constraint_name
function getArgumentArray ( obj  ,
,
xind   
)

Retrieves the elements from the vector x related to xind and returns them as a cell array where: args{i} = x(xind{i})

Return values
args
function getNonlinearGradientSparsity ( obj  )

This function sets the nonlinear sparsity vector iGfun and jGvar based on the nonlinear sparsity of the objective, nonlinear inequality constraints and nonlinear equality constraints.

Parameters
iGfun,jGvar.G(iGfun,jGvar) are the non-zero entries in the matrix G, which is the gradient of return value f in the objectiveAndNonlinearConstraints function
Return values
iGfun
jGvar
function getNumSharedDataFunctions ( obj  )
Return values
n
function ipopt ( obj  ,
x0   
)
protected
Return values
x
objval
exitflag
infeasible_constraint_name
function isBoundingBoxConstraintID ( obj  ,
cnstr_id   
)

Given an ID, determine if any of the bounding box constraint obj.bbcon has that ID.

Return values
flagTrue if the cnstr_id is a valid ID of the bounding box constraint in the program
cnstr_idxIf flag = true, obj.bbcon{cnstr_idx} is the bounding box constraint with ID=cnstr_id. Otherwise, cnstr_idx = [];
function isLinearConstraintID ( obj  ,
cnstr_id   
)

Given an ID, determine if any of the linear constraint obj.lcon has that ID.

Return values
flagTrue if the cnstr_id is a valid ID of the linear constraint
cnstr_idxIf flag = true, obj.lcon{cnstr_idx} is the linear constraint with ID=cnstr_id. Otherwise, cnstr_idx = [];
function isNonlinearConstraintID ( obj  ,
cnstr_id   
)

Given an ID, determine if any of the nonlinear constraint obj.nlcon has that ID.

Return values
flagTrue if the cnstr_id is a valid ID of the nonlinear constraint
cnstr_idxIf flag = true, obj.nlcon{cnstr_idx} is the nonlinear constraint with ID=cnstr_id. Otherwise, cnstr_idx = [];
function mapSolverInfo ( obj  ,
exitflag  ,
 
)
protected

Based on the solver information and solution, re-map the info.

Parameters
exitflagThe info returned from the solver
xThe solution
Return values
exitflag
infeasible_constraint_name
function nonlinearConstraints ( obj  ,
 
)

evaluate the nonlinear constraints

Parameters
xA num_vars x 1 double vector. The decision variables
Return values
gThe value of the nonlinear inequality constraints
hThe value of the nonlinear equality constraints
dgThe gradient of g w.r.t x
dhThe gradient of h w.r.t x
function objective ( obj  ,
 
)

return the value of the objective

Parameters
xA obj.num_vars x 1 double vector. The decision variables
Return values
fA double scalar. The value of the objective function
dfThe gradient of f w.r.t x
function objectiveAndNonlinearConstraints ( obj  ,
 
)

evaluate the objective and the nonlinear constraints altogher

Parameters
xA obj.num_vars x 1 double vector. The decision variables
Return values
fA 1+obj.num_cin+obj.num_ceq x 1 double vector. f = [objective;nonlinear_inequality_constraints;nonlinear_equality_constraints]
dfThe gradient of f w.r.t x
function replaceCost ( obj  ,
cost  ,
cost_idx  ,
xind   
)

replace the cost_idx'th cost in the original problem with a new cost

Parameters
cost– A Constraint object, currently accepts NonlinearConstraint and LinearConstraint
cost_idx– The index of the original cost to be replaced
xind– Optional argument. x(xind) is the decision variables used in evaluating the cost. Default value is (1:obj.num_vars)
Return values
obj
function setCheckGrad ( obj  ,
check_grad   
)
Return values
obj
function setConstraintErrTol ( obj  ,
tol   
)
Return values
obj
function setSolver ( obj  ,
solver   
)
Parameters
solverCan be 'snopt', 'ipopt', 'fmincon' and 'default'.
Return values
obj
function setSolverOptions ( obj  ,
solver  ,
optionname  ,
optionval   
)
Parameters
solver- string name of the solver
optionname– string name of the option field
optionval– option value
Return values
obj
function setVarBounds ( obj  ,
lb  ,
ub   
)
protected
Return values
obj
function snopt ( obj  ,
x0   
)
protected
Return values
x
objval
exitflag
infeasible_constraint_name
function solve ( obj  ,
x0   
)
Parameters
x0A obj.num_vars x 1 double vector. The initial seed
Return values
xA obj.num_vars x 1 double vector. The solution obtained after running the solver
objvalA double scalar. The value of the objective function after running the solver
exitflagAn integer scalar. 1 – Solved successful
If the solver is SNOPT, then exitflag is the same as the INFO returned by the solver. Please refer to http://www.cam.ucsd.edu/~peg/papers/sndoc7.pdf for more information 2 – Solved with SNOPT, but the accuracy of the linear constraints cannot be achieved. 3 – Solved with SNOPT, but the accuracy of the nonlinear constraints cannot be achieved. 4 – SNOPT thinks it fails to solve the problem, but the solution satisfies the constraints within obj.constraint_err_tol 5 – SNOPT thinks it runs out of iterations limits, but the solution satisfies the constraints within obj.constraint_err_tol, try increase the iterations limits 6 – SNOPT thinks it runs out of major iterations limits, but the solution satisfies the constraints within obj.constraint_err_tol. try increase the major iterations limits 11 – SNOPT fails as the linear constraints are infeasible. This is most likely because the decision variables in some constraints (nonlinear or linear constraints) are fixed (due to the equality bounding box constraint on the decision variable). Consider either to remove the constraints, or relax the bounding box constraint on the decision variable. 12 – SNOPT fails as the linear equality constraints are infeasible 13 – SNOPT fails as the nonlinear constraints are infeasible 31 – SNOPT fails by running out of iterations limit 32 – SNOPT fails by running out of major iterations limit 33 – SNOPT fails due to small super basics limit 41 – SNOPT fails due to numerical problems
If the solver is fmincon, then the exitflag is 200 + fmincon_exitflag 200 – In fmincon, number of iterations exceeds options.MaxIter 199 – In fmincon, stopped by an output function or plot function 198 – In fmincon, no feasible point was found. 202 – In fmincon, change in x was less than options.TolX and maximum constraint violation was less than options.TolCon. 203 – In fmincon, change in the objective function value was less than options.TolFun and maximum constraint violation was less than options.TolCon. 204 – In fmincon, magnitude of the search direction was less than 2*options.TolX and maximum constraint violation was less than options.TolCon. 205 – In fmincon, magnitude of directional derivative in search direction was less than 2*options.TolFun and maximum constraint violation was less than options.TolCon. 197 – In fmincon, objective function at current iteration went below options.ObjectiveLimit and maximum constraint violation was less than options.TolCon.
If the solver is IPOPT, then the exitflag = -100 + ipopt_exitflag -99 – In ipopt, solved to acceptable level -98 – In ipopt, infeasible problem detected -97 – In ipopt, search direction becomes too small -96 – In ipopt, diverging iterates -95 – In ipopt, user requested stop -101 – In ipopt, maximum number of iterations exceeded -102 – In ipopt, restoration phase failed -103 – In ipopt, error in step computation -110 – In ipopt, not enough degrees of freedom -111 – In ipopt, invalid problem definition -112 – In ipopt, invalid option -113 – In ipopt, invalid number detected -200 – In ipopt, unrecoverable exception -201 – In ipopt, non-IPOPT exception thrown -202 – In ipopt, insufficient memory -299 – In ipopt, internal error

When using fmincon, if the algorithm is not specified through setSolverOptions('fmincon','Algorithm',ALGORITHM), then it will iterate all possible algorithms in fmincon to search for a solution.

function updateBoundingBoxConstraint ( obj  ,
varargin   
)

updateBoundingBoxConstraint(obj,cnstr_id,cnstr,xind) update the BoundingBoxConstraint whose id=cnstr_id with a new BoundingBoxConstraint cnstr

Parameters
cnstr_idThe ID of the constraint to be replaced. This ID is returned from obj.addBoundingBoxConstraint function
cnstrA Constraint object. The constraint to be added
xindSame as xind in obj.addBoundingBoxConstraint
Return values
new_cnstr_idThe ID of the newly updated constraint in the program
function updateConstraint ( obj  ,
varargin   
)

update a Constraint of the program.

Refer to obj.updateNonlinearConstraint, obj.updateLinearConstraint and obj.updateBoundingBoxConstraint for its use

Return values
obj
new_cnstr_id
function updateLinearConstraint ( obj  ,
varargin   
)

updateLinearConstraint(obj,cnstr_id,cnstr,xind) update the linear constraint whose id=cnstr_id with a new Constraint object cnstr, the newly added Constraint cnstr has the ID new_cnstr_id

Parameters
cnstr_idThe ID of the constraint to be replaced. This ID is returned from obj.addLinearConstraint function
cnstrA Constraint object. The constraint to be added
xindSame as xind in addLinearConstraint
Return values
new_cnstr_idThe ID of the newly updated constraint in the program
function updateNonlinearConstraint ( obj  ,
varargin   
)

updateNonlinearConstraint(obj,cnstr_id,cnstr,xind,data_ind) update the nonlinear constraint whose id=cnstr_id with a new Constraint object cnstr, the newly added Constraint cnstr has the ID new_cnstr_id

Parameters
cnstr_idThe ID of the constraint to be replaced. This ID is returned from obj.addNonlinearConstraint
cnstrA Constraint object. The constraint to be added
xindSame as the xind in obj.addNonlinearConstraint
data_indSame as the data_ind in obj.addNonlinearConstraint
Return values
new_cnstr_idThe ID of the newly updated constraint in the program

Member Data Documentation

Property Aeq
protected
Property Aeq_name
protected
Property Ain
protected
Property Ain_name
protected
Property bbcon
protected
Property bbcon_xind
protected

nlcon{i}.eval(x(nlcon_xind{i}{1},x(nlcon_xind{i}{2},) cost_xind_cell % A cell array, cost_xind{i} is a cell array of int vectors recording the indices of x that is used in evaluating obj.cost{i}

Property beq
protected
Property bin
protected
Property ceq_name
protected
Property check_grad
protected
Property cin_lb
protected
Property cin_name
protected
Property cin_ub
protected
Property constraint_err_tol
protected

numerical gradient at the begining and end of the nonlinear optimization

Property cost
protected
Property cost_dataind
protected
Property display_fun_indices
protected
Property display_funs
protected
Property iCeqfun
protected
Property iCinfun
protected
Property iFfun
protected

2 if user has their own snopt in MATLAB path

iGfun,jGvar % sparsity pattern in objective and nonlinear constraints

Property lcon
protected
Property nlcon
protected
Property nlcon_dataind
protected

a cell array of function handles, each of which returns a data object so that shared_data{i} = shared_data_functions(x(shared_data_xind_cell{i}{1}),x(shared_data_xind_cell{i}{2}),) shared_data_functions

cell arrays of vectors where nlcon_dataind{i} are indices into the shared_data used by nonlinear constraints and cost functions

Property nlcon_xind
protected
Property num_ceq
protected
Property num_cin
protected
Property num_vars
protected
Property shared_data_xind_cell
protected

a cell array like nlcon_xind, where shared_data_xind_cell{i} is a cell array of int vectors recording indices used in evaluating the shared_data_function

Property solver
protected
Property solver_options
protected
Property x_lb
protected
Property x_name
protected
Property x_ub
protected

The documentation for this class was generated from the following file: