help-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-glpk] Import data from Matlab variables to GLPK/GMPL


From: Jeffrey Kantor
Subject: [Help-glpk] Import data from Matlab variables to GLPK/GMPL
Date: Sun, 29 Dec 2013 06:25:18 -1000


I may not be understanding your intended use. If the problem has already been reduced to canonical form with A, b, c, lb, and ub as Matlab matrices, then there is little value to introducing a modeling layer. You could just call a glpk through glpkmex (see http://en.wikibooks.org/wiki/GLPK/Matlab) and avoid the overhead of converting your data to a text format, building the model, and reading the results.  

If you do wish to use a modeling language, such as Mathprog, then you might consider using AWK to manipulate and generate instances of data inputs to your model.  But from your note, it sounds like you've already got that worked out in Matlab.

Also, if you have access to it, you may want to look into the prerelease of Matlab 2014a.

Jeff

On Saturday, December 28, 2013, Nazmul Islam wrote:
Hello Reg (& others),

Thanks a lot for your email. 

As a fast step, I want to solve a mixed integer linear program like follows 

min c'x
s.t. Ax <= b, 
lb <= x <= ub
Some variables of x are binary ones.

I have generated A, b, c, lb, ub in Matlab and stored them in .mat format. I have to convert them to GMPL readable format so that I can solve this code using GLPK. I have attached a sample of those files with my email. I will really appreciate if you could tell me how I can convert them using AWK. Please let me know if you want me to send a .mat file with smaller size.

Your help will be very appreciated.

Thanks,

Nazmul


On Fri, Dec 27, 2013 at 3:30 PM, Reginald Beardsley <address@hidden> wrote:
Nazmul,

I suggest you consider using  awk to generate data files in GMPL format from ASCII text (.txt) files if you have very many instances to solve.  You put the problem formulation in one file and the data for each instance in  another file and execute "gplsol -m model.dat -d data.dat".  I've found this works very well solving large numbers of problem instances.  In particular, it makes changing the model very simple.  I can't find out anything about the Guesk editor so I can't comment on setting up GMPL notation data files using that.

I tried using the CSV import facility in GMPL, but found it not very convenient because of restrictions on the CSV format glpk accepts. 

There is a MATLAB binding for GLPK, but I don't know how usable it is.  The MATLAB clone, Octave, also has a built-in binding to GLPK.

http://en.wikibooks.org/wiki/GLPK/Matlab

http://en.wikibooks.org/wiki/GLPK/Octave

http://en.wikibooks.org/wiki/GLPK/Scripting_plus_MathProg

There is a Gnu implementation of awk, gawk, which is standard on Linux systems.  It's also available on Windows.

http://gnuwin32.sourceforge.net/packages/gawk.htm

If you need help with writing an awk script to convert the MATLAB .txt files to GMPL notation send me a small example of the MATLAB .txt file and I'll add an example to the GLPK wiki.

You'll need to figure out how to write a basic GMPL problem first.  A good place to look is in the examples directory at cf12a.mod which implements an L1 line fit.  I solve physics inverse  problems by basis pursuit using GMPL notation so I can probably offer some help.  I do problems with 30,000 columns by 50-300 rows.  The resulting files are huge, so you want to get everything working using a small example before doing something that large.  I did some little 10x10 problems to figure out how to set it up.

Reg




--------------------------------------------
On Thu, 12/26/13, Nazmul Islam <address@hidden> wrote:

 Subject: [Help-glpk] Import data from Matlab variables to GLPK/GMPL
 To: address@hidden
 Date: Thursday, December 26, 2013, 8:49 PM

 Hello,
 I want to write my GLPK code through the Guesk
 editor and I am very new to the GNU Math Programming
 Language. 
 I want to import some data from Matlab to my GLPK
 code. I want to run the code with these imported data. The
 data is currently in some variables of Matlab and I can
 store them in some .mat files. Do I need to save all these
 Matlab variables in a single .dat file (or .txt file?) and
 then import to GNU Math Prog language?

 Is there any example that I can
 follow?
 Thanks,
 Nazmul


 -----Inline Attachment Follows-----

 _______________________________________________
 Help-glpk mailing list
 address@hidden
 https://lists.gnu.org/mailman/listinfo/help-glpk





reply via email to

[Prev in Thread] Current Thread [Next in Thread]