classdef (Sealed) QuadprogWarmStart < optim.warmstart.base.QPActiveSetWarmStart
%QUADPROGWARMSTART Warm start object to accelerate the QUADPROG solver.
%   A QUADPROGWARMSTART object can reduce the total time to solve
%   sequence of quadratic programming problems of the form:
% 
%        min  0.5*x'*H*x + f'*x   subject to:
%         x                          A*x <= b 
%                                    Aeq*x = beq
%                                    lb <= x <= ub
% 
%   when the objective or constraints change slightly between
%   consecutive solves.
% 
%   WS = OPTIMWARMSTART(X0,OPTIONS) creates a warm start object for the
%   QUADPROG algorithm specified in OPTIONS.  X0 is an initial point to
%   begin the warm start process.  OPTIONS is a quadratic options object
%   created with OPTIMOPTIONS.
% 
%   WS = OPTIMWARMSTART(X0,OPTIONS,PROP,VAL,...) specifies a set of
%   property-value pairs that are applied to the warm start object before
%   creation.  For code generation, set the 'MaxLinearEqualities' and
%   'MaxLinearInequalities' properties.
%   
%   QuadprogWarmStart properties:
%     Read-only:
%      X                      - Initial point for the quadratic
%                               programming problem.
%      Options                - Algorithm-specific options for the QUADPROG
%                               solver. 
%      MaxLinearEqualities    - Upper bound on the number of linear
%                               equality constraints over all quadratic
%                               programming problems solved using warm
%                               start. Applies to code generation.
%      MaxLinearInequalities  - Upper bound on the number of linear
%                               inequality constraints over all quadratic
%                               programming problems solved using warm
%                               start. Applies to code generation.
%
%   Example:
% 
%   Create a quadratic programming problem:
%      H = eye(3);
%      f = [-7;-12;-15];
%      A = [1,1,1];
%      b = 3;
%      lb = zeros(3,1);
% 
%   Create a warm start object using OPTIMWARMSTART:
%      options = optimoptions('quadprog','Algorithm','active-set');
%      x0 = [1;2;3];
%      ws = optimwarmstart(x0,options);
%   
%   Solve the problem using the warm start syntax with QUADPROG:
%      [ws,fval,exitflag,output,lambda] = quadprog(H,f,A,b,[],[],lb,[],ws);
%   
%   Change the problem and solve again:
%      f = [-10;-15;-20];
%      [ws,fval,exitflag,output,lambda] = quadprog(H,f,A,b,[],[],lb,[],ws);
%
%   See also OPTIMWARMSTART, QUADPROG, OPTIMOPTIONS
        
%   Copyright 2020 The MathWorks, Inc.
    
    properties (Constant, Access = protected)
        SolverName = "quadprog";
    end
        
    methods
        function obj = QuadprogWarmStart(x0, options, CoderOpts)
            
            % Arguments block is faster for validating arguments than an 
            % input parser.  We cannot do argument validation with varargin
            % on base classes.
            arguments
                x0 double {mustBeReal, mustBeNonempty}
                options {optim.warmstart.validate.optionsValidate(options, 'quadprog', 'active-set')}
                CoderOpts.MaxLinearEqualities {optim.warmstart.validate.maxLinearValidate(CoderOpts.MaxLinearEqualities, 'MaxLinearEqualities')} = Inf
                CoderOpts.MaxLinearInequalities {optim.warmstart.validate.maxLinearValidate(CoderOpts.MaxLinearInequalities, 'MaxLinearInequalities')} = Inf
            end
            
            % Call the base class constructor.
            obj = obj@optim.warmstart.base.QPActiveSetWarmStart(x0, options, ...
                CoderOpts.MaxLinearEqualities, CoderOpts.MaxLinearInequalities);
            
            obj.Version = 1;
        end
    end
    
end

