help-glpk
[Top][All Lists]
Advanced

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

Re: [Help-glpk] Patch for GLPK 4.35 to support SWIG


From: Nigel Galloway
Subject: Re: [Help-glpk] Patch for GLPK 4.35 to support SWIG
Date: Mon, 2 Feb 2009 15:26:02 +0100

Details of projects using swig can be found at:
    http://www.swig.org/projects.html

It is not necessary to use the same file in the #include statement 
as in the %include statement. Therefore it is not necessary to 
modify glpk.h. I asked for these to be removed 18 months ago when 
there were only 3. If Andrew takes them out for you, when he didn't 
for me, I shall have to consider him sexist. It is better to use 
your own file as there is a lot of other rubbish that can be 
removed.

Attached are some files demonstrating using SWIG with glpk_4.35.

test.rb is the example of using Glpk's new graph feature (page 159 
glpk.pdf) written in ruby.

GLPK.swig is similar to the Swig input files previously described. Two lines:
   %include "cmalloc.i"
   %sizeof(double)
are added. This causes a constant NigelzGLPK::Sizeof_double to be 
available to test.rb (if required). I didn't use it (it's 8), I'm 
hoping the interfaces to the graph routines improve soon.

glpkSWIG.h is similar to glpk.h as distributed. Terrible coding 
practice in Glpk uses #DEFINE of the same name more than once, 
fortunately to the same value. Previously there were 3, now there 
are 5. These are commented out, SWIG thinks they're bad, I think 
they're bad, they're out.

diff.out documents the difference between glpk.h and glpkSWIG.h.

sample.min is the data file described in glpk.pdf (page 156).

mincost.lp is the file created by running 'ruby test.rb'.

GLPK_wrap.cxx is the output file created by:
   swig -c++ -ruby GLPK.swig
if you want to try without installing swig use this file:
   g++ -c GLPK_wrap.cxx -I/usr/lib/ruby/1.8/i486-linux/ -I 
/opt/glpk-4.35/include/
then:
   g++ -shared GLPK_wrap.o -L /opt/glpk-4.35/lib/ -lglpk -o nigelzGLPK.so

This is the minimum required to make Glpk available, using SWIG, in 
a number of languages including Ruby, Java, C#, Lua, and Python.

Ruby already has a project using SWIG to interface Glpk and Ruby called rGLPK.

Individuals may wish to comment out a lot more of glpkSWIG.h, 
however it would be better if a lot of the rubbish was removed from 
glpk.h to another header, say GLPKdirtywashing.h.



> ----- Original Message -----
> From: "Kelly Westbrooks" <address@hidden>
> To: "Andrew Makhorin" <address@hidden>
> Cc: address@hidden
> Subject: Re: [Help-glpk] Patch for GLPK 4.35 to support SWIG
> Date: Fri, 30 Jan 2009 08:43:45 -0800 (PST)
>
>
> > Could you point out a GNU package (library) similar to glpk which
> > provides swig support? The GNU maintainer documentation says nothing
> > about such feature.
>
> Actually, I can't provide you an example. Math::GSL is a 
> SWIG-generated Perl interface to the GSL library, but it looks 
> like its maintained in a separate repository.
>
> > Is it sufficient to have glpk.h and libglpk to build a wrapper with
> > swig?
>
> I haven't tried, but i'm fairly sure it's possible. It would 
> burden the user with having to deploy 2 libraries (libglpk and 
> the wrapper library) instead of one, which might be undesirable 
> for some people. But then, there are good arguments for keeping 
> them separate as well.
>
> > Which lines in glpk.h cause problems? I did not find that
> > in your patch file.
>
> Lines 152-156:
>
> #define GLP_MSG_OFF        0  /* no output */
> #define GLP_MSG_ERR        1  /* warning and error messages only */
> #define GLP_MSG_ON         2  /* normal output */
> #define GLP_MSG_ALL        3  /* full output */
> #define GLP_MSG_DBG        4  /* debug output */
>
> These lines are redundant (they are identical to lines 115-119) 
> and i'm pretty sure they can be safely removed without breaking 
> anything. When you try to run SWIG against glpk.h, SWIG complains 
> about these lines.
>
> I can appreciate you hesitation about including the SWIG 
> interface file in the GLPK source tree - it would be one more 
> thing to maintain and it is peripheral to the fundamental purpose 
> of the library. I know that i'm not the first person that has had 
> a desire use GLPK from a language other than C - in fact, I stole 
> the interface file from here:
> http://www.nabble.com/Re:-GLPK-and-Java-using-SWIG-tc10910553.html
> and made a few changes to it to suit my own tastes.
>
> I guess that i'm suggesting that by including the glpk.i 
> interface file in the GLPK source tree, it might encourage others 
> to use the SWIG-generated wrappers as a foundation for writing 
> clean interfaces to GLPK in other languages. As it currently 
> stands, someone that wants to do this has to jump through a few 
> hoops (write the SWIG interface file glpk.i, make changes to 
> glpk.h, etc).
>
> --Kelly
>
>
>
>
>
> _______________________________________________
> Help-glpk mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/help-glpk

>


-- 
_______________________________________________
Surf the Web in a faster, safer and easier way:
Download Opera 9 at http://www.opera.com

Powered by Outblaze

Attachment: GLPKruby.tar.bz2
Description: Binary data


reply via email to

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