rglpk 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog.md CHANGED
@@ -1,3 +1,8 @@
1
+ # rglpk 0.2.5 2011-06-23
2
+
3
+ * Add Row#get_stat, Row#get_prim Row#get_dual.
4
+ * Update tests to work with Ruby 1.9.2.
5
+
1
6
  # rglpk 0.2.4 2010-11-04
2
7
 
3
8
  * Add Rglpk#mip_status.
@@ -12,7 +17,7 @@
12
17
 
13
18
  # rglpk 0.2.1 2010-10-13
14
19
 
15
- * Point readers to gethub in README.
20
+ * Point readers to github in README.
16
21
 
17
22
  # rglpk 0.2.0 2010-10-07
18
23
 
data/README.md CHANGED
@@ -29,7 +29,7 @@ Rglpk provides two primary files: ext/glpk_wrapper.c which is a Swig generated w
29
29
 
30
30
  An example:
31
31
 
32
- # The same Brief Example as found in section 1.3 of
32
+ # The same Brief Example as found in section 1.3 of
33
33
  # glpk-4.44/doc/glpk.pdf.
34
34
  #
35
35
  # maximize
@@ -80,6 +80,16 @@ An example:
80
80
  printf("z = %g; x1 = %g; x2 = %g; x3 = %g\n", z, x1, x2, x3)
81
81
  #=> z = 733.333; x1 = 33.3333; x2 = 66.6667; x3 = 0
82
82
 
83
+ # Testing
84
+
85
+ Test everything with:
86
+
87
+ > rake test
88
+
89
+ Test a specific test with:
90
+
91
+ > ruby test/test_brief_example.rb # or what have you.
92
+
83
93
  # License
84
94
 
85
95
  Copyright (C) 2007 Alex Gutteridge
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.4
1
+ 0.2.5
data/lib/rglpk.rb CHANGED
@@ -81,13 +81,27 @@ module Rglpk
81
81
  def nz
82
82
  Glpk_wrapper.glp_get_num_nz(@lp)
83
83
  end
84
-
84
+
85
+ def add_row
86
+ Glpk_wrapper.glp_add_rows(@lp, 1)
87
+ new_row = Row.new(self, @rows.size + 1)
88
+ @rows.send(:push, new_row)
89
+ new_row
90
+ end
91
+
85
92
  def add_rows(n)
86
93
  Glpk_wrapper.glp_add_rows(@lp, n)
87
94
  s = @rows.size
88
95
  n.times{|i| @rows.send(:push, Row.new(self, s + i + 1))}
89
96
  @rows
90
97
  end
98
+
99
+ def add_col
100
+ Glpk_wrapper.glp_add_cols(@lp, 1)
101
+ new_column = Column.new(self, @cols.size + 1)
102
+ @cols.send(:push, new_column)
103
+ new_column
104
+ end
91
105
 
92
106
  def add_cols(n)
93
107
  Glpk_wrapper.glp_add_cols(@lp, n)
@@ -115,7 +129,7 @@ module Rglpk
115
129
  end
116
130
 
117
131
  def del_cols(a)
118
- # Ensure the array of rows tro delete is sorted and unique.
132
+ # Ensure the array of rows to delete is sorted and unique.
119
133
  a = a.sort.uniq
120
134
 
121
135
  r = Glpk_wrapper.new_intArray(a.size + 1)
@@ -194,6 +208,13 @@ module Rglpk
194
208
  def mip_status
195
209
  Glpk_wrapper.glp_mip_status(@lp)
196
210
  end
211
+
212
+
213
+ def write_lp(filename)
214
+ Glpk_wrapper.glp_write_lp(@lp, nil, filename)
215
+ end
216
+
217
+
197
218
  end
198
219
 
199
220
  class Row
@@ -211,7 +232,7 @@ module Rglpk
211
232
  def name
212
233
  Glpk_wrapper.glp_get_row_name(@p.lp, @i)
213
234
  end
214
-
235
+
215
236
  def set_bounds(type, lb, ub)
216
237
  raise ArgumentError unless TypeConstants.include?(type)
217
238
  lb = 0.0 if lb.nil?
@@ -254,6 +275,18 @@ module Rglpk
254
275
  end
255
276
  row
256
277
  end
278
+
279
+ def get_stat
280
+ Glpk_wrapper.glp_get_row_stat(@p.lp, @i)
281
+ end
282
+
283
+ def get_prim
284
+ Glpk_wrapper.glp_get_row_prim(@p.lp, @i)
285
+ end
286
+
287
+ def get_dual
288
+ Glpk_wrapper.glp_get_row_dual(@p.lp, @i)
289
+ end
257
290
  end
258
291
 
259
292
  class Column
data/rglpk.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rglpk}
8
- s.version = "0.2.4"
8
+ s.version = "0.2.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alex Gutteridge", "William Taysom"]
12
- s.date = %q{2010-11-04}
12
+ s.date = %q{2011-06-23}
13
13
  s.description = %q{Rglpk is a package providing a Ruby wrapper to the [GNU GLPK](http://www.gnu.org/software/glpk/) library. The GLPK (GNU Linear Programming Kit) package is intended for solving large-scale linear programming (LP), mixed integer programming (MIP), and other related problems.
14
14
 
15
15
  Rglpk (pronounced as "wriggle-pick") is currently in alpha status and the API should be considered subject to change. Rglpk uses [Swig](http://www.swig.org/) to initially wrap the C GLPK library (using a Swig wrapper originally developed by Nigel Galloway) and then a pure Ruby library to wrap the Swig code in a more friendly OO-style.
@@ -19,44 +19,35 @@ See [github](http://github.com/wtaysom/rglpk) for installation instructions. Al
19
19
  s.extensions = ["ext/extconf.rb", "ext/extconf.rb"]
20
20
  s.extra_rdoc_files = [
21
21
  "ChangeLog.md",
22
- "README.md"
22
+ "README.md"
23
23
  ]
24
24
  s.files = [
25
- ".gitignore",
26
- "ChangeLog.md",
27
- "License.txt",
28
- "README.md",
29
- "Rakefile",
30
- "VERSION",
31
- "ext/extconf.rb",
32
- "ext/glpk_wrapper.c",
33
- "lib/rglpk.rb",
34
- "rglpk.gemspec",
35
- "swig/Makefile.in",
36
- "swig/configure.in",
37
- "swig/glpk.i",
38
- "test/helper.rb",
39
- "test/test_all.rb",
40
- "test/test_basic.rb",
41
- "test/test_brief_example.rb",
42
- "test/test_problem_kind.rb"
25
+ "ChangeLog.md",
26
+ "License.txt",
27
+ "README.md",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "ext/extconf.rb",
31
+ "ext/glpk_wrapper.c",
32
+ "lib/rglpk.rb",
33
+ "rglpk.gemspec",
34
+ "swig/Makefile.in",
35
+ "swig/configure.in",
36
+ "swig/glpk.i",
37
+ "test/helper.rb",
38
+ "test/test_all.rb",
39
+ "test/test_basic.rb",
40
+ "test/test_brief_example.rb",
41
+ "test/test_problem_kind.rb"
43
42
  ]
44
43
  s.homepage = %q{http://rglpk.rubyforge.org/}
45
- s.rdoc_options = ["--charset=UTF-8", "--exclude", "."]
44
+ s.rdoc_options = ["--exclude", "."]
46
45
  s.require_paths = ["lib", "ext", "ext"]
47
46
  s.rubyforge_project = %q{rglpk}
48
- s.rubygems_version = %q{1.3.7}
47
+ s.rubygems_version = %q{1.6.2}
49
48
  s.summary = %q{Rglpk is a package providing a Ruby wrapper to the [GNU GLPK](http://www.gnu.org/software/glpk/) library. The GLPK (GNU Linear Programming Kit) package is intended for solving large-scale linear programming (LP), mixed integer programming (MIP), and other related problems.}
50
- s.test_files = [
51
- "test/helper.rb",
52
- "test/test_all.rb",
53
- "test/test_basic.rb",
54
- "test/test_brief_example.rb",
55
- "test/test_problem_kind.rb"
56
- ]
57
49
 
58
50
  if s.respond_to? :specification_version then
59
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
60
51
  s.specification_version = 3
61
52
 
62
53
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
data/test/helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ here = File.expand_path(File.dirname(__FILE__))
2
+
1
3
  require 'test/unit'
2
4
  $LOAD_PATH << './ext'
3
- require 'lib/rglpk'
5
+ require here+'/../lib/rglpk'
data/test/test_basic.rb CHANGED
@@ -27,6 +27,17 @@ class TestRglpk < Test::Unit::TestCase
27
27
  assert_raise(ArgumentError){p.obj.dir = 3}
28
28
  end
29
29
 
30
+ def test_add_row
31
+ p = Rglpk::Problem.new
32
+ r = p.add_row
33
+ assert_kind_of Rglpk::Row, r
34
+ assert_equal 1, r.i
35
+ assert_equal 1, p.rows.size
36
+ r = p.add_row
37
+ assert_equal 2, r.i
38
+ assert_equal 2, p.rows.size
39
+ end
40
+
30
41
  def test_add_rows
31
42
  p = Rglpk::Problem.new
32
43
  p.add_rows(2)
@@ -35,6 +46,17 @@ class TestRglpk < Test::Unit::TestCase
35
46
  assert_equal 4, p.rows.size
36
47
  end
37
48
 
49
+ def test_add_column
50
+ p = Rglpk::Problem.new
51
+ c = p.add_col
52
+ assert_kind_of Rglpk::Column, c
53
+ assert_equal 1, c.j
54
+ assert_equal 1, p.cols.size
55
+ c = p.add_col
56
+ assert_equal 2, c.j
57
+ assert_equal 2, p.cols.size
58
+ end
59
+
38
60
  def test_add_cols
39
61
  p = Rglpk::Problem.new
40
62
  p.add_cols(2)
@@ -52,5 +52,11 @@ class TestExample < Test::Unit::TestCase
52
52
 
53
53
  result = "z = %g; x1 = %g; x2 = %g; x3 = %g" % [z, x1, x2, x3]
54
54
  assert_equal "z = 733.333; x1 = 33.3333; x2 = 66.6667; x3 = 0", result
55
+ assert_equal Rglpk::GLP_NU, rows[0].get_stat
56
+ assert_equal 100, rows[0].get_prim
57
+ assert_equal 3.333333333333333, rows[0].get_dual
58
+ File.delete("test.lp") rescue Errno::ENOENT
59
+ p.write_lp("test.lp")
60
+ assert File.exists?("test.lp")
55
61
  end
56
62
  end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rglpk
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 2
9
- - 4
10
- version: 0.2.4
4
+ prerelease:
5
+ version: 0.2.5
11
6
  platform: ruby
12
7
  authors:
13
8
  - Alex Gutteridge
@@ -16,7 +11,7 @@ autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
13
 
19
- date: 2010-11-04 00:00:00 +08:00
14
+ date: 2011-06-23 00:00:00 +08:00
20
15
  default_executable:
21
16
  dependencies: []
22
17
 
@@ -38,7 +33,6 @@ extra_rdoc_files:
38
33
  - ChangeLog.md
39
34
  - README.md
40
35
  files:
41
- - .gitignore
42
36
  - ChangeLog.md
43
37
  - License.txt
44
38
  - README.md
@@ -62,7 +56,6 @@ licenses: []
62
56
 
63
57
  post_install_message:
64
58
  rdoc_options:
65
- - --charset=UTF-8
66
59
  - --exclude
67
60
  - .
68
61
  require_paths:
@@ -74,29 +67,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
67
  requirements:
75
68
  - - ">="
76
69
  - !ruby/object:Gem::Version
77
- hash: 3
78
- segments:
79
- - 0
80
70
  version: "0"
81
71
  required_rubygems_version: !ruby/object:Gem::Requirement
82
72
  none: false
83
73
  requirements:
84
74
  - - ">="
85
75
  - !ruby/object:Gem::Version
86
- hash: 3
87
- segments:
88
- - 0
89
76
  version: "0"
90
77
  requirements: []
91
78
 
92
79
  rubyforge_project: rglpk
93
- rubygems_version: 1.3.7
80
+ rubygems_version: 1.6.2
94
81
  signing_key:
95
82
  specification_version: 3
96
83
  summary: Rglpk is a package providing a Ruby wrapper to the [GNU GLPK](http://www.gnu.org/software/glpk/) library. The GLPK (GNU Linear Programming Kit) package is intended for solving large-scale linear programming (LP), mixed integer programming (MIP), and other related problems.
97
- test_files:
98
- - test/helper.rb
99
- - test/test_all.rb
100
- - test/test_basic.rb
101
- - test/test_brief_example.rb
102
- - test/test_problem_kind.rb
84
+ test_files: []
85
+
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- pkg
2
- *.swp
3
-
4
- # SWIG Files
5
- swig/Makefile
6
- swig/autom4te.cache/
7
- swig/config.log
8
- swig/config.status
9
- swig/configure
10
- swig/rglpk.c
11
-
12
- # ext Files
13
- ext/Makefile
14
- ext/conftest.dSYM/
15
- ext/mkmf.log
16
- ext/glpk_wrapper.bundle
17
- ext/glpk_wrapper.o