Did I attach the matdata files? That is surprising since I find that interface confusing and try not to use it. I suggest that you avoid it also. It’s there only for backwards compatibility.
Best practice is to write your GDX files, call a gams model that uses generic GDX commands, and read any GDX files back into Matlab. Examples and more explanation on the GDXMRW Wiki.
Dear
I have run the files you attached, and I am confused by how the files “matdata” and “matdata.gdx” are generated. Could you please explain more about it? Thanks a lot!
Yalin
On Monday, 15 April 2013 20:04:42 UTC+2, Steven Dirkse wrote:
Salman,
There is a certain amount of overhead that is introduced when you run a loop in Matlab and call gams each time in the loop. It's not necessarily a large overhead, but it can seem large compared to the amount of work required to solve a QP with 2 vars and 3 constraints. I am attaching a .zip file with an example that demonstrates what I mean. A few things to note about the example:
1. It uses the save/restart and solvelink=5 features of GAMS (documented in the User's Guide) to minimize the startup time and solver-call times required by the gams calls in the loop.
2. No data is passed on the gams() call: it runs a generic GAMS model that can be run independently of Matlab and can be used with save/restart.
3. The average time for the trivial GAMS call (no new data, solve the QP starting from solution, do not read results back to Matlab): .055 seconds/iteration.
4. The average time for the real GAMS call (new data, solve from base solution, results back to Matlab): .064 seconds/iteration.
I did these runs on a Dell XPS13 laptop with a solid-state disk which I believe helps keep the startup time for GAMS low. I used Matlab R2013a and GAMS 24.0.2 as we ship it.
My conclusion: in my computing environment, the overhead required to call gams is only large compared to the solve time for a very tiny model. .055 seconds/run is something that is typically noise when solving larger, more challenging models.
HTH,
Steve
On Sun, Apr 14, 2013 at 4:45 AM, Salman wrote:
Hi Steve,
I changed both the constraint and objective function in each iteration. I have copied my matlab code and my gams code below. this is a quadratic programming with inequality constraint:
obj: 0.5 *transpose(x)Hx + transpose(f)x
constraint: Ax It takes about 0.5 sec for gams to compute this optimization problem and return the results to the matlab. by deleting the "solve" statement in my gams code, this time reduced to 0.2 sec. it means that gams solve this optimization problem in 0.3sec (0.5-0.2=0.3).
In a matlab loop, I solved this problem 5 times with gams() function and 5 times with matlab quadprog() function. and in each iteration I changed the constraint (A,b) and objective function (H,f). the time duration to solve this problem for gams() was: 0.55, 0.53, 0.54, 0.59, 0.53 sec and for quadprog() was : 0.41, 0.06, 0.04, 0.04, 0.002 sec.
Best,
Salman.
%-------------------may gams code-------------------------------
$set matout " 'matsol.gdx', z, x, cons, mdlstat, solstat ";
set i /1*2/,
id(i) /1*2/;
set j /1*3/;
parameters f(i);
parameters bineq(j);
parameter h(i,i);
parameter Aineq(j,i);
$if exist matdata.gms $include matdata.gms
scalar mdlstat,solstat;
positive variables x(i);
variable z;
equations obj,cons(j);
obj.. z=E= sum(i,0.5*x(i)*sum(id,h(i,id)*x(id)))+sum(i,f(i)*x(i));
cons(j).. sum(i,Aineq(j,i)*x(i) )=l=bineq(j);
model salmanqp /All/
solve salmanqp USING QCP MINIMIZING z ;
mdlstat=salmanqp.modelstat;
solstat=salmanqp.solvestat;
execute_unload %matout%;
% -------------------------- my matlab code-------------------------------------
clc;clear all;close all;
ii={'1','2'};
jj={'1','2','3'};
H0=[1,-1;-1,2];
f0=[-2;-6];
Aineq0=[1,1;-1,2;2,1];
bineq0=[4;2;3];
for t=1:5
H0=randi(50,2,2);
f0=-randi(100,2,1);
Aineq0=randi(80,3,2);
bineq0=randi(10,3,1);
H.name='h';
H.val=H0;
H.uels={ii,ii};
H.form='full';
f.name='f';
f.form='full';
f.val=f0;
f.uels={ii};
Aineq.name='Aineq';
Aineq.form='full';
Aineq.val=Aineq0;
Aineq.uels={jj,ii};
bineq.name='bineq';
bineq.form='full';
bineq.val=bineq0;
bineq.uels={jj};
tic;
gamso.output='Std';
gamso.show='invisible';
[z1 ,x1,cons,modelstat,solverstat] = gams('salman QCP=conopt',H,f,Aineq,bineq);
x1
z1
toc
tic;
% clear all;
H1=H.val;
f1=f.val;
bineq1=bineq.val;
Aineq1=Aineq.val;
lb=zeros(2,1);
options=optimset('LargeScale','off');
[x,fval,~,~]=quadprog(H1,f1,Aineq1,bineq1,[],[],lb,[],[],options)
toc
end
On 04/12/2013 01:44 ق.ظ, Steven Dirkse wrote:
Salman,
It sounds like Matlab is able to take advantage of the similarity between the QPs you are solving. This is also possible when using GAMS, but to say more some additional detail would be helpful. Specifically, what is changing in the sequence of QPs, and what stays constant?
-Steve
On Thu, Apr 11, 2013 at 4:44 PM, salman wrote:
Hi,
I understood that the difference between computation speed of these two matlab code (1- use gams() function to compute quadratic programming in matlab in a loop
2- use matlab quadprog() function in a loop) is not because of GAMS problem or GDXMRW utility problem but it is because of matlab priority in this case.
I measured the computation time of gams() function and quadprog() function in every iteration , in the first iteration quadprog() takes 0.4 sec and gams() takes 0.3 sec.(it means that gams was a bit faster than matlab optimization toolbox function) .
but I surprisingly saw that in subsequent iterations gams() computation did not changed significantly but quadprog() computation time was 0.02 sec.(20 times faster) (I should mention that I changed the constraints in every iteration).
I tested this several times, in different problems, and the result was: when recalling matlab quadprog() for secend time in a code, the computation speed, become very faster. in another experiment I used "clear all" command in matlab in every iteration, and I saw that the computaion speed was the same (0.4 sec) in all the iterations.
I guess matlab use past experiences and this is the reason that it is faster when executing the optimization function for more that one time. I don't know what are these (experience or configurations or .... )? and what can I do to speed up my gams optimization problem, when using it in matlab code, the computation speed is very important for me. so I would really appreciate if you could tell me how I can speed up my optimization problem.
Best,
Salman
On Thursday, April 11, 2013 7:23:03 AM UTC+4:30, salman wrote:
Hi,
after hours of working to make a link between gams and matlab, finally i made it. I learned how to use gams in a matlab loop to solve a quadratic programming problem via GDXMRW utility (gams() ). the problem is : when i use gams in a matlab loop to solve the quadratic programming problem, it is 10 times slower than using matlab quadprog function in the loop. I found that gams solve the problem faster than matlab when using gams out of the loop (execute for 1 time) but in the loop I don't know what happens that cause delay.
additionally i used gams() without any input and output arguments but it was still slow.
my operating system is windows7 64bit and i use gams 24.0.2 64bit and matlab 2010a64bit.
my final goal is to use gams in matlab to solve a mixed integer nonlinear programming problem that matlab can not solve itself, and I should solve this problem 2000 times in a loop. because of this, computation speed is very important for me.
I would really appreciate if you could help my solve this problem.
Best Regards,
Salman.
--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.
To post to this group, send email to gams...@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
Steven Dirkse, Ph.D.
GAMS Development Corp., Washington DC
Voice: (202)342-0180 Fax: (202)342-0181
sdi...@gams.com
http://www.gams.com
--
You received this message because you are subscribed to a topic in the Google Groups "gamsworld" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gamsworld/36ZKIQHBdx8/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to gamsworld+...@googlegroups.com.
To post to this group, send email to gams...@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.
To post to this group, send email to gams...@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
Steven Dirkse, Ph.D.
GAMS Development Corp., Washington DC
Voice: (202)342-0180 Fax: (202)342-0181
sdi...@gams.com
http://www.gams.com
–
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/groups/opt_out.