glpk 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +15 -1
- data/lib/glpk/problem.rb +12 -6
- data/lib/glpk/version.rb +1 -1
- data/lib/glpk.rb +7 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b33673df7b1d1ddefb1d561f60a0742cc57988154b027814690a23751eb325ad
|
4
|
+
data.tar.gz: 1145b0ad7dfbc30a7fd4cd11c83ad834deb98679760f613d018620869e9956c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4be3835974e198a429e28c9aef30b898c8b1fa2e8634e80b822570a533c6f6b2ac92a4416c7d04af0f2ec53b8edef558fd263b9bedcd09d85276a4f8c6a92123
|
7
|
+
data.tar.gz: 967a2d957f359fccfc40d3ce03eb8526d445a1142119417c27a0c7c76017552bbd13b3413964cc6a99209e5baeef2e415a474d7f37c79d056ef4a53b3ac1aceb
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
[GLPK](https://www.gnu.org/software/glpk/) - the GNU linear programming kit - for Ruby
|
4
4
|
|
5
|
+
Check out [Opt](https://github.com/ankane/opt) for a high-level interface
|
6
|
+
|
5
7
|
[](https://github.com/ankane/glpk-ruby/actions)
|
6
8
|
|
7
9
|
## Installation
|
@@ -12,12 +14,18 @@ First, install GLPK. For Homebrew, use:
|
|
12
14
|
brew install glpk
|
13
15
|
```
|
14
16
|
|
15
|
-
|
17
|
+
For Ubuntu, use:
|
16
18
|
|
17
19
|
```sh
|
18
20
|
sudo apt-get install libglpk40
|
19
21
|
```
|
20
22
|
|
23
|
+
And for Fedora, use:
|
24
|
+
|
25
|
+
```sh
|
26
|
+
sudo dnf install glpk
|
27
|
+
```
|
28
|
+
|
21
29
|
Then add this line to your application’s Gemfile:
|
22
30
|
|
23
31
|
```ruby
|
@@ -68,6 +76,12 @@ problem = Glpk.read_lp("hello.lp")
|
|
68
76
|
problem = Glpk.read_mps("hello.mps")
|
69
77
|
```
|
70
78
|
|
79
|
+
Free the problem (only required in multi-threaded environments) [unreleased]
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
problem.free
|
83
|
+
```
|
84
|
+
|
71
85
|
## Reference
|
72
86
|
|
73
87
|
Set the message level
|
data/lib/glpk/problem.rb
CHANGED
@@ -2,7 +2,13 @@ module Glpk
|
|
2
2
|
class Problem
|
3
3
|
def initialize
|
4
4
|
@model = FFI.glp_create_prob
|
5
|
-
|
5
|
+
@model.free = FFI["glp_delete_prob"]
|
6
|
+
end
|
7
|
+
|
8
|
+
def free
|
9
|
+
model.free = nil
|
10
|
+
FFI.glp_delete_prob(model)
|
11
|
+
@model = nil
|
6
12
|
end
|
7
13
|
|
8
14
|
def load_problem(obj_dir:, obj_coef:, mat_ia:, mat_ja:, mat_ar:, col_kind:, col_lower:, col_upper:, row_lower:, row_upper:)
|
@@ -73,14 +79,10 @@ module Glpk
|
|
73
79
|
end
|
74
80
|
end
|
75
81
|
|
76
|
-
def self.finalize(model)
|
77
|
-
# must use proc instead of stabby lambda
|
78
|
-
proc { FFI.glp_delete_prob(model) }
|
79
|
-
end
|
80
|
-
|
81
82
|
private
|
82
83
|
|
83
84
|
def model
|
85
|
+
raise Error, "can't use freed problem" unless @model
|
84
86
|
@model
|
85
87
|
end
|
86
88
|
|
@@ -135,6 +137,10 @@ module Glpk
|
|
135
137
|
|
136
138
|
status = FFI::RET_CODE[ret_code] || FFI::SOLUTION_STATUS[FFI.glp_mip_status(model)]
|
137
139
|
|
140
|
+
if status == :root_lp_optimum
|
141
|
+
status = FFI::SOLUTION_STATUS[FFI.glp_get_status(model)]
|
142
|
+
end
|
143
|
+
|
138
144
|
{
|
139
145
|
status: status,
|
140
146
|
obj_val: FFI.glp_mip_obj_val(model),
|
data/lib/glpk/version.rb
CHANGED
data/lib/glpk.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
require "fiddle/import"
|
3
3
|
|
4
4
|
# modules
|
5
|
-
|
6
|
-
|
5
|
+
require_relative "glpk/problem"
|
6
|
+
require_relative "glpk/version"
|
7
7
|
|
8
8
|
module Glpk
|
9
9
|
class Error < StandardError; end
|
@@ -16,7 +16,11 @@ module Glpk
|
|
16
16
|
# TODO test
|
17
17
|
["glpk.dll"]
|
18
18
|
elsif RbConfig::CONFIG["host_os"] =~ /darwin/i
|
19
|
-
["
|
19
|
+
if RbConfig::CONFIG["host_cpu"] =~ /arm|aarch64/i
|
20
|
+
["libglpk.dylib", "/opt/homebrew/lib/libglpk.dylib"]
|
21
|
+
else
|
22
|
+
["libglpk.dylib"]
|
23
|
+
end
|
20
24
|
else
|
21
25
|
["libglpk.so", "libglpk.so.40"]
|
22
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glpk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: andrew@ankane.org
|
@@ -42,7 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: '0'
|
44
44
|
requirements: []
|
45
|
-
rubygems_version: 3.
|
45
|
+
rubygems_version: 3.4.10
|
46
46
|
signing_key:
|
47
47
|
specification_version: 4
|
48
48
|
summary: Linear programming kit for Ruby
|