I have wrapped quadprog on __qp__ instead of qp.m in [1].
Main differences between quadprog in [1] and qp.m.
- Input argument placement
quadprog(H, f, A, b, Aeq, beq, lb, ub, x0, options) = qp (x0, H, f, Aeq, beq, lb, ub, [], A, b, options)
- Check for empty inputs A and b
qp ([],H,f,Aeq,beq,lb,ub,[],A,[])
This works. qp simply ignores inequality constraints due to if checks
in lines 258, 266 and 275 of qp.m. Matlab gives an error if A is empty and b is not and vice versa.
Example:
quadprog (H, f, A, [], Aeq, beq, lb, ub)
Error: The number of rows in A must be the same as the length of b. I have added this check in line 181 in [1].
- Lambda output as a structure instead of a vector as in qp.m.
Ordering of lambda:
Main differences between quadprog in [1] and qp.m.
- Input argument placement
quadprog(H, f, A, b, Aeq,
- Check for empty inputs A and b
qp ([],H,f,Aeq,beq,lb,ub,[],A,[])
This works. qp simply ignores inequality constraints due to if checks
in lines 258, 266 and 275 of qp.m. Matlab gives an error if A is empty and b is not and vice versa.
Example:
quadprog (H, f, A, [], Aeq, beq, lb, ub)
Error: The number of rows in A must be the same as the length of b. I have added this check in line 181 in [1].
- Lambda output as a structure instead of a vector as in qp.m.
- The order of lambda vector output (qp_lambda) from __qp__(in my code) is [equality constraints; inequality constraints; lower bounds; upper bounds].
- The multipliers are present if the constraints are given as inputs so the size of qp_lambda depends on the size of constraints.
- Variables idx_ineq, idx_lb and idx_ub make sure I pick the right values.
Example:
H = diag([1; 0]);
f = [3; 4];
A = [-1 -3; 2 5; 3 4];
b = [-15; 100; 80];
l = zeros(2,1);
[x, obj, info, qp_lambda] = qp ([], H, f, [], [],l,[],[], A, b)
[x,fval,exitflag,output,lambda] = quadprog (H, f, A, b,[],[],l,[])
qp_lambda =
1.66667
0.00000
1.33333
0.00000
0.00000
lambda =
scalar structure containing the fields:
lower =
1.66667
0.00000
upper = [](0x0)
eqlin = [](0x0)
ineqlin =
1.33333
0.00000
0.00000
Things to do:
- Check the sign issue for lambda.eqlin (qp gives values -1* Matlab's)
- Check if __qp__ changes the order of constraints. The values of lambda from qp.m in the last example in [2] are there but not coinciding with the respective constraints.
- Move on to optimoptions.
[1] https://github.com/AsmaAfzal/octave_workspace/blob/master/quadprog.m
[2] https://github.com/AsmaAfzal/octave_workspace/blob/master/runquadprog.m
No comments:
Post a Comment