Function 'quadprogIP' runs fast seperately but extremely slow in a for loop simulation

1 view (last 30 days)
I am currently using the function 'quadprogIP' from https://github.com/xiawei918/quadprogIP
This is a function that solves a nonconvex quadratic optimization, via IBM Cplex function for mixed-integer linear programming. My problem is: if I run the function 'quadprogIP' once, it executes very fast (around 10 minute).
clear
n = 50;
f = zeros([n,1]);
A = zeros(n); b = zeros([n,1]);
Aeq = ones([1,n]); beq = 1;
LB = zeros([n,1]); UB = ones([n,1]);
epsilon = 1e-6;
sigma = 2*rand(1,n);
rho = rand(n);
Cov = sigma.'*sigma.*rho;
rhoc = ones(n);
Covc = sigma.'*sigma.*rhoc;
low = 0; high = 1; iter = 1;
q = (low+high)/2; H = Cov-q*Covc;
[w,Fq,time,stats] = quadprogIP(H,f,A,b,Aeq,beq,LB,UB,[]);
TT(iter) = stats.total_time % This is normally 10 seconds
But if I wanna run a while loop, and the function 'quadprogIP' is called upon in the loop, the average time for each execution is much longer (at least 5 times higher).
while abs(Fq) > epsilon
if Fq>0
low = q;
else
high = q;
end
iter = iter+1;
q = (low+high)/2;
H = Cov-q*Covc;
[w,Fq,time,stats] = quadprogIP(H,f,A,b,Aeq,beq,LB,UB,[]); % from Github
TT(iter) = stats.total_time
end
mean(TT) % But this one is a lot higher.
I don't know what could be the possible reason for this situation, and if there is any way to solve this problem. Thanks!

Answers (1)

Torsten
Torsten on 14 Sep 2023
Moved: Torsten on 14 Sep 2023
Maybe the problems to be solved get larger or more complicated within the for loop so that the average time spent for each problem increases ? But we can only speculate without your code.
Since "quadprogIP" is not an official MATLAB tool, I'd suggest to contact the authors.
  1 Comment
Churui Li
Churui Li on 14 Sep 2023
Thank you for answering! I added the relevant code in the post.
Indeed it is not an official Matlab function, I may turn to the authors if the problem remains after a while.

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!