optimwarmstart - Create warm start object - MATLAB (original) (raw)
Create warm start object
Since R2021a
Syntax
Description
[ws](#mw%5F46992975-b1fb-494a-8401-164fdc2b12a2) = optimwarmstart([x0](#mw%5Fd39d9136-0cdd-4e85-8dc9-162620d0951e),[options](#mw%5Fd285f08c-2d9f-41ed-bf8a-0489d419e5a6))
creates a warm start object ws
for use with the solver indicated inoptions
. For an example using a warm start object, see Return Warm Start Object.
[ws](#mw%5F46992975-b1fb-494a-8401-164fdc2b12a2) = optimwarmstart([x0](#mw%5Fd39d9136-0cdd-4e85-8dc9-162620d0951e),[options](#mw%5Fd285f08c-2d9f-41ed-bf8a-0489d419e5a6),[Name,Value](#namevaluepairarguments))
incorporates memory bounds in ws
using name-value arguments. Use memory bounds only when generating code.
Examples
Create a default warm start object forquadprog
.
x0 = [1 3 5]; options = optimoptions('quadprog','Algorithm','active-set'); ws = optimwarmstart(x0,options)
ws =
QuadprogWarmStart with properties:
X: [3×1 double]
Options: [1×1 optim.options.Quadprog]
Code generation limitations
Create an lsqlin
warm start object for code generation with memory limits.
x0 = [1 3 5]; options = optimoptions('lsqlin','Algorithm','active-set'); ws = optimwarmstart(x0,options,... 'MaxLinearEqualities',30,... 'MaxLinearInequalities',5)
Click the Code generation limitations
link to see the memory settings.
MaxLinearEqualities: 30 MaxLinearInequalities: 5
To speed subsequent quadprog
calls, create a warm start object.
options = optimoptions('quadprog','Algorithm','active-set'); x0 = [1 2 3]; ws = optimwarmstart(x0,options);
Solve a quadratic program using ws
.
H = [1,-1,1 -1,2,-2 1,-2,4]; f = [-7;-12;-15]; A = [1,1,1]; b = 3; lb = zeros(3,1); tic [ws,fval,exitflag,output,lambda] = quadprog(H,f,A,b,[],[],lb,[],ws);
Minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
Elapsed time is 0.060411 seconds.
Change the objective function and solve the problem again.
f = [-10;-15;-20];
tic [ws,fval,exitflag,output,lambda] = quadprog(H,f,A,b,[],[],lb,[],ws);
Minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
Elapsed time is 0.010756 seconds.
Input Arguments
Initial point, specified as a real array. This point is stored inws.X
.
Example: 10*rand(5,1)
Data Types: single
| double
Optimization options, specified as the output of optimoptions. You must specify at least a supported solver, eitherlsqlin
or quadprog
, and'active-set'
for the and Algorithm
option. For example, enter the following code to specify the quadprog
solver.
options = optimoptions('quadprog','Algorithm','active-set');
These options are stored in ws.Options
.
Name-Value Arguments
Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN
, where Name
is the argument name and Value
is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose Name
in quotes.
Example: ws = optimwarmstart(x0,options,'MaxLinearEqualities',30,'MaxLinearInequalities',5)
specifies up to 30 linear equalities and 5 linear inequalities.
Maximum number of linear equality constraints, specified as a positive integer. To allocate enough memory for equality constraints, specify the maximum number of equality constraints during the entire run of the code.
Use this argument only for code generation without dynamic memory allocation. You must use both this argument and 'MaxLinearInequalities'
.
The value of this argument is stored inws.MaxLinearEqualities
.
Example: 25
Data Types: single
| double
Maximum number of linear inequality constraints, specified as a positive integer. To allocate enough memory for inequality constraints, specify the maximum number of inequality constraints during the entire run of the code.
Use this argument only for code generation without dynamic memory allocation. You must use both this argument and 'MaxLinearEqualities'
.
The value of this argument is stored inws.MaxLinearInequalities
.
Example: 25
Data Types: single
| double
Output Arguments
Warm start object, returned as an LsqlinWarmStart
object or aQuadprogWarmStart
object. For an example using a warm start object, see Warm Start quadprog.
ws
has the following read-only properties:
X
— Initial pointOptions
— Optimization optionsMaxLinearEqualities
— Maximum number of linear equalities for code generationMaxLinearInequalities
— Maximum number of linear inequalities for code generation
To change any properties of ws
, recreate the object by callingoptimwarmstart
.
Algorithms
A warm start object maintains a list of active constraints from the previous solved problem. The solver carries over as much active constraint information as possible to solve the current problem. If the previous problem is too different from the current one, no active set information is reused. In this case, the solver effectively executes a cold start in order to rebuild the list of active constraints.
Extended Capabilities
Usage notes and limitations:
- Warm start options must specify the
'active-set'
algorithm.
options = optimoptions('lsqlin','Algorithm','active-set');
% Or
options = optimoptions('quadprog','Algorithm','active-set'); - If your target hardware uses static memory allocation (the
DynamicMemoryAllocation
option is'off'
), you must specify both the 'MaxLinearEqualities' and the 'MaxLinearInequalities' arguments.- For non-MEX targets, if the solver tries to exceed either of these levels, the solver returns an exit flag –
8
. - For MEX targets, if the solver tries to exceed either of these levels, the solver throws an error and indicates to increase the relevant level.
- For non-MEX targets, if the solver tries to exceed either of these levels, the solver returns an exit flag –
- For more warm start code generation information, see
lsqlin
Code Generation orquadprog
Code Generation.
Version History
Introduced in R2021a