Bonjour à tous,
I’m trying to test a new extension provide with jruby which allows
to write a binding for a C library directly in ruby without
writing a C line of code.
This (ffi) extension is now part of the standard Jruby version.
That allows to use mixing of java library (like choco constraint
solver), C extensions (like glpk) directly in (j)ruby code.
As Pierre asked (on the Glpk list) for a java or other binding
for Glpk, I write this “pseudo-annonce” although ffi-glpk is just
a demonstrator for now.
But it allows to write the glpk documentation minimal example
in full (j)ruby code!
The demonstrator is available at :
The code provided is the mimimum for writing the glpk doc mini
example in ruby.
Hope this help,
– Maurice Diamantini
Here is the README :
what is it
This directory contains a test exemple to validate Glpk interface to
thanks to the new ffi Ruby package.
- Glpk is the Gnu Library tookit for Linear Programming written
by Andrew Makhorin,
- Ruby is a wonderfull true objet oriented programming scripting
written in C
- JRuby is a Ruby (100% compatible) version written in Java and
supported by Sun. It is also fully integrated with the java
world and is
as fast as the new native Ruby-1.9 version
- FFI is a new package which allow to write 100% Ruby interface
library!! FFI is currently fully integrated with JRuby language.
and can be installed for Ruby native language.
The provided exemple allow to solve the following problem :
max z = 10x1 + 6x2 + 4x3 s.c. x1 + x2 + x3 <= 100 10x1 + 4x2 + 5x3 <= 600 2x1 + 2x2 + 6x3 <= 300 x1 >= 0 x2 >= 0 x3 >= 0
This directory contains :
a file “miniglpk.c” which is exactly the glpk exemple provide with
You should be able to test this programme to make sure glpk is
your system, but a compilator is not required for using glpk from
a file “ffi-glpk.rb” wich contains the minimum for writing the low
API used in the tutorial example,
the file “mini_glpk.rb” which is the the ruby version of the tutorial.
Execution of the test the C version
For compiling and running the C exemple, you should set two environment
GLPK_LIB should be set the path were the library file libglpk.so or
libglpk.dylib is located,
GLPK_INCLUDE should be set the path were the library file glpk.h
Then compile by:
gcc -I$GLPK_INCLUDE -L$GLPK_LIB -l glpk -o mini_glpk mini_glpk.c
and run by:
The following result should appear:
* 0: obj = 0.000000000e+00 infeas = 0.000e+00 (0) * 2: obj = 7.333333333e+02 infeas = 0.000e+00 (0) OPTIMAL SOLUTION FOUND z = 733.333; x1 = 33.3333; x2 = 66.6667; x3 = 0
Execution the jruby test
You should have the last jruby version (jruby-1.6) which contains
FFI out of the box, or ruby and install ffi with
gem install ffi (not tested)
Also, the glpk lib should be discover aumoticaly on osx leopard or
linux distrib, but for now, you can specify the path path (i.e. bu
using the previous GLPK_LIB variable.
See the start “ffi-glpk.rb” if you have problems
then run ./mini_glpk.rb
It’s all !
Remark about the “ffi-glpk.rb” interface file
This kind of file could become the low level interface to the glpk
It seems that the FFI community converge to the idea that there should
be one standard low level interface to a C library. It is essentialy
a sort of mapping of the include file and should be easy to maintain
(ideally automically generated from the include file).
Then it could exist several higher level API to make this interface more
Object Oriented ou more Ruby frendly.
To unsubscribe from this list, please visit: