Permalink
Browse files

Rename rglpk.c as glpk_wrapper.c.

  • Loading branch information...
1 parent 357f00e commit 0ae1654bcd8f29dc155d3d86be0bca8bcce7952b @wtaysom wtaysom committed Oct 6, 2010
Showing with 652 additions and 651 deletions.
  1. +2 −2 .gitignore
  2. +7 −6 Rakefile
  3. +1 −1 ext/extconf.rb
  4. +568 −568 ext/{rglpk.c → glpk_wrapper.c}
  5. +71 −71 lib/glpk.rb
  6. +2 −2 swig/Makefile.in
  7. +1 −1 swig/glpk.i
View
@@ -13,5 +13,5 @@ swig/rglpk.c
ext/Makefile
ext/conftest.dSYM/
ext/mkmf.log
-ext/rglpk.bundle
-ext/rglpk.o
+ext/glpk_wrapper.bundle
+ext/glpk_wrapper.o
View
@@ -34,22 +34,23 @@ end
SHARED_LIBRARY_EXTENSION = RUBY_PLATFORM.include?("darwin") ? 'bundle' : 'so'
-EXTENSION = 'ext/rglpk.'+SHARED_LIBRARY_EXTENSION
+EXTENSION = 'ext/glpk_wrapper.'+SHARED_LIBRARY_EXTENSION
desc "Use extconf.rb and make to build the extension."
task :build_extension => EXTENSION
-file EXTENSION => 'ext/rglpk.c' do
+file EXTENSION => 'ext/glpk_wrapper.c' do
+ puts "why am I here?"
in_dir('ext') do
system("ruby extconf.rb")
system("make")
end
end
CLEAN.include('ext/Makefile', 'ext/conftest.dSYM', 'ext/mkmf.log',
- 'ext/rglpk.bundle', 'ext/rglpk.o')
+ 'ext/glpk_wrapper.bundle', 'ext/glpk_wrapper.o')
-file 'ext/rglpk.c' => 'swig/glpk.i' do
+file 'ext/glpk_wrapper.c' => 'swig/glpk.i' do
in_dir('swig') do
system("autoconf")
system("configure")
@@ -58,9 +59,9 @@ file 'ext/rglpk.c' => 'swig/glpk.i' do
end
CLEAN.include('swig/Makefile', 'swig/autom4te.cache', 'swig/config.log',
- 'swig/config.status', 'swig/configure', 'swig/rglpk.c')
+ 'swig/config.status', 'swig/configure', 'swig/glpk_wrapper.c')
-CLOBBER.include('ext/rglpk.c')
+CLOBBER.include('ext/glpk_wrapper.c')
desc "Run Test::Unit tests."
task :test => :build_extension do
View
@@ -9,4 +9,4 @@
exit 1
end
-create_makefile("rglpk")
+create_makefile('glpk_wrapper')

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,9 +1,9 @@
-require 'rglpk.so'
+require 'glpk_wrapper'
module GLPK
- Rglpk.constants.each do |c|
- v = Rglpk.const_get(c)
+ Glpk_wrapper.constants.each do |c|
+ v = Glpk_wrapper.const_get(c)
self.const_set(c,v) if v.kind_of? Numeric
end
TypeConstants =[GLP_FR, GLP_LO, GLP_UP, GLP_DB, GLP_FX]
@@ -31,7 +31,7 @@ def [](i)
super(i)
elsif i.kind_of?(String)
raise RuntimeError if self[1].nil?
- idx = Rglpk.glp_find_row(self[1].p.lp,i)
+ idx = Glpk_wrapper.glp_find_row(self[1].p.lp,i)
raise ArgumentError if idx == 0
super(idx)
else
@@ -49,7 +49,7 @@ def [](i)
super(i)
elsif i.kind_of?(String)
raise RuntimeError if self[1].nil?
- idx = Rglpk.glp_find_col(self[1].p.lp,i)
+ idx = Glpk_wrapper.glp_find_col(self[1].p.lp,i)
raise ArgumentError if idx == 0
super(idx)
else
@@ -67,33 +67,33 @@ class Problem
attr_accessor :rows, :cols, :obj, :lp
def initialize
- @lp = Rglpk.glp_create_prob
+ @lp = Glpk_wrapper.glp_create_prob
@obj = GLPK::ObjectiveFunction.new(self)
@rows = GLPK::RowArray.new
@cols = GLPK::ColArray.new
- Rglpk.glp_create_index(@lp)
+ Glpk_wrapper.glp_create_index(@lp)
@status = nil
end
def name=(n)
- Rglpk.glp_set_prob_name(@lp,n)
+ Glpk_wrapper.glp_set_prob_name(@lp,n)
end
def name
- Rglpk.glp_get_prob_name(@lp)
+ Glpk_wrapper.glp_get_prob_name(@lp)
end
def nz
- Rglpk.glp_get_num_nz(@lp)
+ Glpk_wrapper.glp_get_num_nz(@lp)
end
def add_rows(n)
- Rglpk.glp_add_rows(@lp,n)
+ Glpk_wrapper.glp_add_rows(@lp,n)
s = @rows.size
n.times{|i| @rows << GLPK::Row.new(self,s+i+1)}
@rows
end
def add_cols(n)
- Rglpk.glp_add_cols(@lp,n)
+ Glpk_wrapper.glp_add_cols(@lp,n)
s = @cols.size
n.times{|i| @cols << GLPK::Column.new(self,s+i+1)}
@cols
@@ -103,9 +103,9 @@ def del_rows(a)
#ensure the array of rows tro delete is sorted and unique
a = a.sort.uniq
- r = Rglpk.new_intArray(a.size+1)
- a.each_with_index{|n,i| Rglpk.intArray_setitem(r,i+1,n)}
- Rglpk.glp_del_rows(@lp,a.size,r)
+ r = Glpk_wrapper.new_intArray(a.size+1)
+ a.each_with_index{|n,i| Glpk_wrapper.intArray_setitem(r,i+1,n)}
+ Glpk_wrapper.glp_del_rows(@lp,a.size,r)
a.each do |n|
@rows.delete_at(n)
@@ -121,9 +121,9 @@ def del_cols(a)
#ensure the array of rows tro delete is sorted and unique
a = a.sort.uniq
- r = Rglpk.new_intArray(a.size+1)
- a.each_with_index{|n,i| Rglpk.intArray_setitem(r,i+1,n)}
- Rglpk.glp_del_cols(@lp,a.size,r)
+ r = Glpk_wrapper.new_intArray(a.size+1)
+ a.each_with_index{|n,i| Glpk_wrapper.intArray_setitem(r,i+1,n)}
+ Glpk_wrapper.glp_del_cols(@lp,a.size,r)
a.each do |n|
@cols.delete_at(n)
@@ -137,30 +137,30 @@ def del_cols(a)
def set_matrix(v)
- nr = Rglpk.glp_get_num_rows(@lp)
- nc = Rglpk.glp_get_num_cols(@lp)
+ nr = Glpk_wrapper.glp_get_num_rows(@lp)
+ nc = Glpk_wrapper.glp_get_num_cols(@lp)
- ia = Rglpk.new_intArray(v.size+1)
- ja = Rglpk.new_intArray(v.size+1)
- ar = Rglpk.new_doubleArray(v.size+1)
+ ia = Glpk_wrapper.new_intArray(v.size+1)
+ ja = Glpk_wrapper.new_intArray(v.size+1)
+ ar = Glpk_wrapper.new_doubleArray(v.size+1)
v.each_with_index do |x,y|
rn = (y+nr) / nc
cn = (y % nc) + 1
- Rglpk.intArray_setitem(ia,y+1,rn) # 1,1,2,2
- Rglpk.intArray_setitem(ja,y+1,cn) # 1,2,1,2
- Rglpk.doubleArray_setitem(ar,y+1,x)
+ Glpk_wrapper.intArray_setitem(ia,y+1,rn) # 1,1,2,2
+ Glpk_wrapper.intArray_setitem(ja,y+1,cn) # 1,2,1,2
+ Glpk_wrapper.doubleArray_setitem(ar,y+1,x)
end
- Rglpk.glp_load_matrix(@lp,v.size,ia,ja,ar)
+ Glpk_wrapper.glp_load_matrix(@lp,v.size,ia,ja,ar)
end
def simplex(options)
- parm = Rglpk::Glp_smcp.new
- Rglpk.glp_init_smcp(parm)
+ parm = Glpk_wrapper::Glp_smcp.new
+ Glpk_wrapper.glp_init_smcp(parm)
#Default to errors only temrinal output
parm.msg_lev = GLPK::GLP_MSG_ERR
@@ -174,11 +174,11 @@ def simplex(options)
end
end
- Rglpk.glp_simplex(@lp,parm)
+ Glpk_wrapper.glp_simplex(@lp,parm)
end
def status
- Rglpk.glp_get_status(@lp)
+ Glpk_wrapper.glp_get_status(@lp)
end
end
@@ -190,21 +190,21 @@ def initialize(problem,i)
@i = i
end
def name=(n)
- Rglpk.glp_set_row_name(@p.lp,@i,n)
+ Glpk_wrapper.glp_set_row_name(@p.lp,@i,n)
end
def name
- Rglpk.glp_get_row_name(@p.lp,@i)
+ Glpk_wrapper.glp_get_row_name(@p.lp,@i)
end
def set_bounds(type,lb,ub)
raise ArgumentError unless GLPK::TypeConstants.include?(type)
lb = 0.0 if lb.nil?
ub = 0.0 if ub.nil?
- Rglpk.glp_set_row_bnds(@p.lp,@i,type,lb.to_f,ub.to_f)
+ Glpk_wrapper.glp_set_row_bnds(@p.lp,@i,type,lb.to_f,ub.to_f)
end
def bounds
- t = Rglpk.glp_get_row_type(@p.lp,@i)
- lb = Rglpk.glp_get_row_lb(@p.lp,@i)
- ub = Rglpk.glp_get_row_ub(@p.lp,@i)
+ t = Glpk_wrapper.glp_get_row_type(@p.lp,@i)
+ lb = Glpk_wrapper.glp_get_row_lb(@p.lp,@i)
+ ub = Glpk_wrapper.glp_get_row_ub(@p.lp,@i)
lb = (t == GLPK::GLP_FR or t == GLPK::GLP_UP) ? nil : lb
ub = (t == GLPK::GLP_FR or t == GLPK::GLP_LO) ? nil : ub
@@ -213,22 +213,22 @@ def bounds
end
def set(v)
raise RuntimeError unless v.size == @p.cols.size
- ind = Rglpk.new_intArray(v.size+1)
- val = Rglpk.new_doubleArray(v.size+1)
+ ind = Glpk_wrapper.new_intArray(v.size+1)
+ val = Glpk_wrapper.new_doubleArray(v.size+1)
- 1.upto(v.size){|x| Rglpk.intArray_setitem(ind,x,x)}
- v.each_with_index{|x,y| Rglpk.doubleArray_setitem(val,y+1,x)}
+ 1.upto(v.size){|x| Glpk_wrapper.intArray_setitem(ind,x,x)}
+ v.each_with_index{|x,y| Glpk_wrapper.doubleArray_setitem(val,y+1,x)}
- Rglpk.glp_set_mat_row(@p.lp,@i,v.size,ind,val)
+ Glpk_wrapper.glp_set_mat_row(@p.lp,@i,v.size,ind,val)
end
def get
- ind = Rglpk.new_intArray(@p.cols.size+1)
- val = Rglpk.new_doubleArray(@p.cols.size+1)
- len = Rglpk.glp_get_mat_row(@p.lp,@i,ind,val)
+ ind = Glpk_wrapper.new_intArray(@p.cols.size+1)
+ val = Glpk_wrapper.new_doubleArray(@p.cols.size+1)
+ len = Glpk_wrapper.glp_get_mat_row(@p.lp,@i,ind,val)
row = Array.new(@p.cols.size,0)
len.times do |i|
- v = Rglpk.doubleArray_getitem(val,i+1)
- j = Rglpk.intArray_getitem(ind,i+1)
+ v = Glpk_wrapper.doubleArray_getitem(val,i+1)
+ j = Glpk_wrapper.intArray_getitem(ind,i+1)
row[j-1] = v
end
return row
@@ -241,21 +241,21 @@ def initialize(problem,i)
@j = i
end
def name=(n)
- Rglpk.glp_set_col_name(@p.lp,@j,n)
+ Glpk_wrapper.glp_set_col_name(@p.lp,@j,n)
end
def name
- Rglpk.glp_get_col_name(@p.lp,@j)
+ Glpk_wrapper.glp_get_col_name(@p.lp,@j)
end
def set_bounds(type,lb,ub)
raise ArgumentError unless GLPK::TypeConstants.include?(type)
lb = 0.0 if lb.nil?
ub = 0.0 if ub.nil?
- Rglpk.glp_set_col_bnds(@p.lp,@j,type,lb,ub)
+ Glpk_wrapper.glp_set_col_bnds(@p.lp,@j,type,lb,ub)
end
def bounds
- t = Rglpk.glp_get_col_type(@p.lp,@j)
- lb = Rglpk.glp_get_col_lb(@p.lp,@j)
- ub = Rglpk.glp_get_col_ub(@p.lp,@j)
+ t = Glpk_wrapper.glp_get_col_type(@p.lp,@j)
+ lb = Glpk_wrapper.glp_get_col_lb(@p.lp,@j)
+ ub = Glpk_wrapper.glp_get_col_ub(@p.lp,@j)
lb = (t == GLPK::GLP_FR or t == GLPK::GLP_UP) ? nil : lb
ub = (t == GLPK::GLP_FR or t == GLPK::GLP_LO) ? nil : ub
@@ -264,22 +264,22 @@ def bounds
end
def set(v)
raise RuntimeError unless v.size == @p.rows.size
- ind = Rglpk.new_intArray(v.size+1)
- val = Rglpk.new_doubleArray(v.size+1)
+ ind = Glpk_wrapper.new_intArray(v.size+1)
+ val = Glpk_wrapper.new_doubleArray(v.size+1)
- 1.upto(v.size){|x| Rglpk.intArray_setitem(ind,x,x)}
- v.each_with_index{|x,y| Rglpk.doubleArray_setitem(val,y+1,x)}
+ 1.upto(v.size){|x| Glpk_wrapper.intArray_setitem(ind,x,x)}
+ v.each_with_index{|x,y| Glpk_wrapper.doubleArray_setitem(val,y+1,x)}
- Rglpk.glp_set_mat_col(@p.lp,@j,v.size,ind,val)
+ Glpk_wrapper.glp_set_mat_col(@p.lp,@j,v.size,ind,val)
end
def get
- ind = Rglpk.new_intArray(@p.rows.size+1)
- val = Rglpk.new_doubleArray(@p.rows.size+1)
- len = Rglpk.glp_get_mat_col(@p.lp,@j,ind,val)
+ ind = Glpk_wrapper.new_intArray(@p.rows.size+1)
+ val = Glpk_wrapper.new_doubleArray(@p.rows.size+1)
+ len = Glpk_wrapper.glp_get_mat_col(@p.lp,@j,ind,val)
col = Array.new(@p.rows.size,0)
len.times do |i|
- v = Rglpk.doubleArray_getitem(val,i+1)
- j = Rglpk.intArray_getitem(ind,i+1)
+ v = Glpk_wrapper.doubleArray_getitem(val,i+1)
+ j = Glpk_wrapper.intArray_getitem(ind,i+1)
col[j-1] = v
end
return col
@@ -291,30 +291,30 @@ def initialize(problem)
@p = problem
end
def name=(n)
- Rglpk.glp_set_obj_name(@p.lp,n)
+ Glpk_wrapper.glp_set_obj_name(@p.lp,n)
end
def name
- Rglpk.glp_get_obj_name(@p.lp)
+ Glpk_wrapper.glp_get_obj_name(@p.lp)
end
def dir=(d)
raise ArgumentError if d != GLPK::GLP_MIN and d != GLPK::GLP_MAX
- Rglpk.glp_set_obj_dir(@p.lp,d)
+ Glpk_wrapper.glp_set_obj_dir(@p.lp,d)
end
def dir
- Rglpk.glp_get_obj_dir(@p.lp)
+ Glpk_wrapper.glp_get_obj_dir(@p.lp)
end
def set_coef(j,coef)
- Rglpk.glp_set_obj_coef(@p.lp,j,coef)
+ Glpk_wrapper.glp_set_obj_coef(@p.lp,j,coef)
end
def coefs=(a)
- @p.cols.each{|c| Rglpk.glp_set_obj_coef(@p.lp,c.j,a[c.j-1])}
+ @p.cols.each{|c| Glpk_wrapper.glp_set_obj_coef(@p.lp,c.j,a[c.j-1])}
a
end
def coefs
- @p.cols.map{|c| Rglpk.glp_get_obj_coef(@p.lp,c.j)}
+ @p.cols.map{|c| Glpk_wrapper.glp_get_obj_coef(@p.lp,c.j)}
end
def get
- Rglpk.glp_get_obj_val(@p.lp)
+ Glpk_wrapper.glp_get_obj_val(@p.lp)
end
end
end
View
@@ -1,4 +1,4 @@
-rglpk.c: glpk.i
+glpk_wrapper.c: glpk.i
@SWIG@ -I/usr/local/include -ruby -w801 -o $@ $?
-wrap: rglpk.c
+wrap: glpk_wrapper.c
cp $? ../ext/$?
View
@@ -23,7 +23,7 @@
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-%module rglpk
+%module glpk_wrapper
%{
#include "glpk.h"

0 comments on commit 0ae1654

Please sign in to comment.