soltanian2000@gmail.com

1,170 views
Skip to first unread message
Message has been deleted

Mehdi Jalali

unread,
Apr 11, 2013, 6:04:04 AM4/11/13
to gams...@googlegroups.com
Hi, Salman
I am Mehdi Jalali from Tabriz,Iran . I see your link in gams group. I have an error in linking gams and matlab. My function is about Power System Expansion Planning.
Can you help me to use gams and matlab simoultanously? I am working to solve my project that is a MINLP in large scale, too.
I will thank you.
Mehdi Jalali
Electrical and Computer Engineering Faculty of Tabriz University,Tabriz Iran.
 

 


   

Steven Dirkse

unread,
Apr 11, 2013, 5:14:15 PM4/11/13
to gams...@googlegroups.com
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 <soltan...@gmail.com> 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.


--
You received this message because you are subscribed to the Google Groups "gamsworld" group.
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

Salman

unread,
Apr 14, 2013, 4:45:09 AM4/14/13
to gams...@googlegroups.com
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<b,  
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

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.

Steven Dirkse

unread,
Apr 15, 2013, 2:04:42 PM4/15/13
to gams...@googlegroups.com
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 
solveCompare.zip

Salman

unread,
Apr 17, 2013, 2:17:49 PM4/17/13
to gams...@googlegroups.com
Dear Steve,

Thanks  a lot, your modifications was very effective and instructive. I learned to use save/restart and  wgdx, rgdx for transferring data and many other things. The average time reduced from 0.5sec to
1) 0.204 seconds/iteration (for trivial GAMS call)
 2) 0.206 seconds/iteration (for real GAMS call)
in my laptop (ASUS N43S with a rotating hard drive).

Kind Regards,

Salman

Ajit Gopalakrishnan

unread,
Oct 10, 2013, 12:30:12 PM10/10/13
to gams...@googlegroups.com
Hi Steven,

I ran your same files, but also compared it with the following time:
%base time
tic
for t=1:N
    wgdx('QPdata', H, f, Aineq, bineq);
    gams('base.gms');
end
toc/N
This would be the time for a naive gams call, where I read the data in each time. 
I observe the following wall clock time:
Base time: 0.04 secs/iteration
Trivial gams call: 0.039 secs/iteration
real gams call: 0.04 secs/iteration

When I turn solvelink = 0, all the 3 runs take 0.09 secs per iteration.  So by leaving gams open in the shell, the start up time is reduced. 

However, there appears to be no savings from the save and restart commands. 

I am running some large problems where the model generation time takes about 6 secs, but solve time is < 1 sec. I would like to eliminate my NLP model generation time. By using the save and restart commands, I was hoping that this time would be eliminated and any execution time parameters would be loaded into the saved model file that gams understands, without having to generate the model all over again. Is gams capable of doing that, or every time a parameter changes, the entire model needs to be generated from scratch? Is there a way around that?

Thanks,
Ajit

Steven Dirkse

unread,
Oct 11, 2013, 9:50:38 AM10/11/13
to gams...@googlegroups.com
Ajit,

I found this question a bit confusing.  You mention Matlab runs in a loop, but your question seems to have nothing to do with Matlab.  You mention save and restart, but there are no save/restart commands in the script you send.  You have very small run times in the Matlab loop, but you mention a generation time of 6 seconds for some other model.  So I'm not sure where to start.

It is true that by default GAMS regenerates the model and incurs some additional overhead as well each time it encounters a solve.  If this becomes an issue there are ways to address it.  Perhaps the place to start is by setting 

option solvelink = %solvelink.LoadLibrary%;

prior to the solve.  But if your model takes 6 seconds to generate and <1 to solve perhaps there is something about the model itself that can be altered to reduce generation time.  The profile option is often useful to pinpoint equations that require significant memory and/or time during the model generation phase.

-Steve


--
You received this message because you are subscribed to the Google Groups "gamsworld" group.
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.

For more options, visit https://groups.google.com/groups/opt_out.

reza bajool

unread,
Feb 26, 2014, 2:45:28 AM2/26/14
to gams...@googlegroups.com
hi dear
i have big problem with link matlab with the gams can you help me
i waana  link matlab with gams for wind forecast consider a astochastic functtion in matlab or use matlab function
can you send me simple example gams file
thanks
best regards
 

Yalin Huang

unread,
Feb 28, 2014, 12:05:34 PM2/28/14
to gams...@googlegroups.com
Dear Steve,

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

Fahimeh Farjadnia

unread,
Mar 1, 2014, 1:50:12 AM3/1/14
to gams...@googlegroups.com
Hi everybody!
I'm trying to call a GAMS model from MATLAB, but every time it executes the the GAMS command , I get the " gdxxrw.exe has stopped working" error.The model reads the data from excel files(xls not xlsx) and I run the model within the gams IDE just fine! Moreover, when I remove the lines related to gdxxrw from the GMAS model the mentioned link(between GMAS and MATLAB) works correctly.
Any suggestion what the problem might be?
Thanks in advance
Fahimeh

Steven Dirkse

unread,
Mar 1, 2014, 7:33:06 AM3/1/14
to gams...@googlegroups.com
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. 


Steve

Sent from my iPhone

Sent from my iPhone
On Feb 28, 2014, at 12:12, Yalin Huang <huang.y...@gmail.com> wrote:

Dear 

mojtaba torkinejad

unread,
Mar 17, 2014, 10:10:27 AM3/17/14
to gams...@googlegroups.com
hi
i want to run gams from matlab could  you please help me too.?

Fateme Dorry

unread,
May 18, 2014, 10:48:57 AM5/18/14
to gams...@googlegroups.com
 Hello Steven Dirkse
I have used Gams in a Matlab loop and I want to reduce the running time of my problem. I downloaded your file "solveCompare.zip" but when I run code "solve.gms" there appears an error "Error 140 Unknown symbol". I also expanded your codes to my problem and I see the error too. I don't know what's the problem. I'll be grateful if you help me.

Best Regards
Fateme Dorry 

Steven Dirkse

unread,
May 22, 2014, 10:44:50 AM5/22/14
to gams...@googlegroups.com
Fateme,

You mention that you downloaded the file solveCompare.zip.  I don't recall that file: including a URL would be helpful.

Also, if you attach the .lst file from the run that would provide some context.  Error 140 is not much to go on in isolation.

-Steve


--
You received this message because you are subscribed to the Google Groups "gamsworld" group.
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.
For more options, visit https://groups.google.com/d/optout.

shohag shorkar shohag

unread,
Jun 13, 2014, 6:19:37 AM6/13/14
to gams...@googlegroups.com
hi

Carlos

unread,
Jun 26, 2014, 8:21:37 PM6/26/14
to gams...@googlegroups.com
Dear all,

I am trying to link MATLAB and GAMS but I receive the error 128 which the "testinstlog.txt" is as follows. I have read all the documentation related to linking GAMS and MATLAB.  Your help is really appreciated.

Regards,

Carlos


Date = 27-Jun-2014
Matlab version = 7.14.0.739 (R2012a) built for win64
GAMS Mex-file version = GDXMRW::gams : rev32781 2012-04-26 18:00:27Z sdirkse
GAMS/Base version = unknown: Error using <a href="matlab:helpUtils.errorDocCallback('gams')" style="font-weight:bold">gams</a>
Cannot find/open gversion.gms file.
Error in testinst: terminating prematurely
   last error message: Error using <a href="matlab:helpUtils.errorDocCallback('gams')" style="font-weight:bold">gams</a>
Cannot find/open testinst.gms file.
last error identifier: GDXMRW:gams:misc

somaye torkaman

unread,
Jul 5, 2014, 4:42:10 PM7/5/14
to gams...@googlegroups.com
hi dear
i have a question. I need to solve some lp in loop in my ga algorithem. i have used the link between gams and matlab to this but it 's too slow. is there any way to this work faster?
best regards

mehdim...@gmail.com

unread,
Oct 26, 2014, 11:34:19 PM10/26/14
to gams...@googlegroups.com
Hi Salman;
I use matlab 2013a and gams 24.1;
I've tried a lot but I couldn't link matlab and gams. I wonder if you would can help me in this regard.

Thank you so much.
mehdi massahi;
Phd student of Industrial Engineering
Amirkabir University of Technology;
Reply all
Reply to author
Forward
0 new messages