Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added Problem#add_row and Problem#add_col. Unlike add_rows(n) and add…

…_cols(n) these return the newly added column or row rather than all columns or rows.
  • Loading branch information...
commit 083986927f53388df22ab8f5db7a19fc59d98c42 1 parent 76160dc
@tamc tamc authored
Showing with 37 additions and 1 deletion.
  1. +15 −1 lib/rglpk.rb
  2. +22 −0 test/test_basic.rb
View
16 lib/rglpk.rb
@@ -81,13 +81,27 @@ def name
def nz
Glpk_wrapper.glp_get_num_nz(@lp)
end
-
+
+ def add_row
+ Glpk_wrapper.glp_add_rows(@lp, 1)
+ new_row = Row.new(self, @rows.size + 1)
+ @rows.send(:push,new_row)
+ new_row
+ end
+
def add_rows(n)
Glpk_wrapper.glp_add_rows(@lp, n)
s = @rows.size
n.times{|i| @rows.send(:push, Row.new(self, s + i + 1))}
@rows
end
+
+ def add_col
+ Glpk_wrapper.glp_add_cols(@lp, 1)
+ new_column = Column.new(self, @cols.size + 1)
+ @cols.send(:push,new_column)
+ new_column
+ end
def add_cols(n)
Glpk_wrapper.glp_add_cols(@lp, n)
View
22 test/test_basic.rb
@@ -27,6 +27,17 @@ def test_obj_fun_dir
assert_raise(ArgumentError){p.obj.dir = 3}
end
+ def test_add_row
+ p = Rglpk::Problem.new
+ r = p.add_row
+ assert_kind_of Rglpk::Row, r
+ assert_equal 1, r.i
+ assert_equal 1, p.rows.size
+ r = p.add_row
+ assert_equal 2, r.i
+ assert_equal 2, p.rows.size
+ end
+
def test_add_rows
p = Rglpk::Problem.new
p.add_rows(2)
@@ -35,6 +46,17 @@ def test_add_rows
assert_equal 4, p.rows.size
end
+ def test_add_column
+ p = Rglpk::Problem.new
+ c = p.add_col
+ assert_kind_of Rglpk::Column, c
+ assert_equal 1, c.j
+ assert_equal 1, p.cols.size
+ c = p.add_col
+ assert_equal 2, c.j
+ assert_equal 2, p.cols.size
+ end
+
def test_add_cols
p = Rglpk::Problem.new
p.add_cols(2)
Please sign in to comment.
Something went wrong with that request. Please try again.