optimwarmstart
Description
creates a warm start object ws
= optimwarmstart(x0
,options
)ws
for use with the solver indicated in
options
. For an example using a warm start object, see Return Warm Start Object.
incorporates memory bounds in ws
= optimwarmstart(x0
,options
,Name,Value
)ws
using name-value arguments. Use memory
bounds only when generating code.
Examples
Create Warm Start Object
Create a default warm start object for
quadprog
.
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 Warm Start Object with Memory Limits
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
Return Warm Start Object
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. <stopping criteria details>
toc
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. <stopping criteria details>
toc
Elapsed time is 0.010756 seconds.
Input Arguments
x0
— Initial point
real array
Initial point, specified as a real array. This point is stored in
ws.X
.
Example: 10*rand(5,1)
Data Types: single
| double
options
— Optimization options
output of optimoptions
Optimization options, specified as the output of optimoptions
. You must specify at least a supported solver, either
lsqlin
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 as
Name1=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.
MaxLinearEqualities
— Maximum number of linear equality constraints
Inf
(default) | positive integer
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 in
ws.MaxLinearEqualities
.
Example: 25
Data Types: single
| double
MaxLinearInequalities
— Maximum number of linear inequality constraints
Inf
(default) | positive integer
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 in
ws.MaxLinearInequalities
.
Example: 25
Data Types: single
| double
Output Arguments
ws
— Warm start object
LsqlinWarmStart
object | QuadprogWarmStart
object
Warm start object, returned as an LsqlinWarmStart
object or a
QuadprogWarmStart
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 calling
optimwarmstart
.
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
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
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 more warm start code generation information, see
lsqlin
Code Generation orquadprog
Code Generation.
Version History
Introduced in R2021aR2024b: Generate single-precision code
You can generate code using optimwarmstart
for single-precision
floating point hardware. For instructions, see Single-Precision Code Generation.
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)