## who Maurice Diamantini at ensta point fr modif: see details at the end of this file License: FreeBSD License - see details at the end of this file ## what is it This directory contains a test exemple to validate Glpk interface to (J)Ruby thanks to the new ffi Ruby package. - Glpk is the Gnu Library tookit for Linear Programming written in C by Andrew Makhorin, http://www.gnu.org/software/glpk/ - Ruby is a wonderfull true objet oriented programming scripting language written in C - JRuby is a Ruby (100% compatible) version written in Java and fully supported. It is also fully integrated with the java world and is as fast as the new native Ruby-1.9 version http://jruby.org/ - FFI is a new package which allow to write 100% Ruby interface to C library!! FFI is currently fully integrated with JRuby language. and can be installed for Ruby native language. http://kenai.com/projects/ruby-ffi/pages/Home ## The provided example 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 example provided with the glpk documentation. You should be able to test this program to make sure glpk is installed on your system, but a compilator is not required for using glpk from (J)ruby - a file "ffi-glpk.rb" which contains the minimum for writing the low level 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 variables : - GLPK_LIB should be set the path were the library file libglpk.so or libglpk.dylib is located, For example: export GLPK_LIB=/usr/local/lib - GLPK_INCLUDE should be set the path were the library file glpk.h is located For example: export GLPK_INCLUDE=/usr/local/include Then compile by: gcc -I$GLPK_INCLUDE -L$GLPK_LIB -l glpk -o mini_glpk mini_glpk.c and run by: ./mini_glpk.rb 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 result is: z = 733.333; x1 = 33.3333; x2 = 66.6667; x3 = 0 expected: z = 733.333; x1 = 33.3333; x2 = 66.6667; x3 = 0 FINI ! ## Execution the jruby test You should have a recent jruby version (at least 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 automaticaly on osx or recent linux distrib, but for now, you can specify the path path (i.e. by 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 library. 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 may exists several higher levels of API to make this interface more Object Oriented ou more Ruby friendly. ## other ruby binding Thanks to Kelly Westbrooks and Nigel Galloway suggestion, glpk.h can now be read directly from swig for create binding for various language (ruby, java, ...) See google : Kelly Westbrooks Nigel Galloway glpk swig ruby java See also rglpk (old?) a wrapper on top on the swig generated ruby interface. ## License (FreeBSD License) Copyright <2010..2011>, . All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of . ## Historique - 17/02/2015 - add glp_get_obj_coef glpk function - 16/02/2015 - add some mip glpk function (thanks to Thibaut Lefevre) note: the glpk api are manually added as needed, and are still incompletes - correct bug with reoptimization (thanks to Thibaut Lefevre) - test with jrury-9.0.0.0.pre1 (os 10.9.5) => ok - test with jruby-1.7.18 (os 10.9.5) => ok - test with ruby2.1.5p273 (os 10.9.5) => ok - 09/03/2014 - test with jruby-1.7.10 (osx 10.9.2) => ok without modifications - test with 2.1.1p76 => ok - 23/11/2011 : (as asked for the glpk wiki) - specify the license - test with jruby-1.6.5 => ok - test with ruby 1.9.2p290 (2011-07-09 revision 32553) => ok - 16/04/2010 : - A bug with jruby-1.4 was corrected in jruby-1.5-RC1. - I add some minor change like adding "FFI::" prefix for MemoryPointer - 04/03/2009 : - There is a bug with the standard MRI ruby interpreter (1.9.1) - But it works out of the box with jruby (tested on 1.1.6 and 1.2rc1) ## ./