glpk 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86566e1e5bf15191e73ee45386a860854d42be93ca39d149eea0821128a5116a
4
- data.tar.gz: c14d0f10736dc2180b3d90c284f3816fb30bf424de6a112a4c281c4952a76c07
3
+ metadata.gz: b33673df7b1d1ddefb1d561f60a0742cc57988154b027814690a23751eb325ad
4
+ data.tar.gz: 1145b0ad7dfbc30a7fd4cd11c83ad834deb98679760f613d018620869e9956c4
5
5
  SHA512:
6
- metadata.gz: 32d6f945c5abc14eaa7e8e7f08696f0d6db629bcfbf4edb42bb1fe8dc68de10b01a4aff472ddd6ae154ba857fe293a017beba34d0337e9f352dbbb02542040ca
7
- data.tar.gz: c1be49795ce8d6eb3a22d81dd02a7d2045401aaef038d1c1f933b8f03ec1d338a00adee08bb624855a6959d9dfffeb58155b027038a785f87e7a4211240e02b8
6
+ metadata.gz: 4be3835974e198a429e28c9aef30b898c8b1fa2e8634e80b822570a533c6f6b2ac92a4416c7d04af0f2ec53b8edef558fd263b9bedcd09d85276a4f8c6a92123
7
+ data.tar.gz: 967a2d957f359fccfc40d3ce03eb8526d445a1142119417c27a0c7c76017552bbd13b3413964cc6a99209e5baeef2e415a474d7f37c79d056ef4a53b3ac1aceb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 0.2.1 (2023-06-07)
2
+
3
+ - Added `free` method
4
+ - Improved support for Mac ARM
5
+ - Fixed error with `dup` and `clone`
6
+
7
+ ## 0.2.0 (2023-01-25)
8
+
9
+ - Improved MIP status when LP fails
10
+
1
11
  ## 0.1.0 (2022-04-13)
2
12
 
3
13
  - First release
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
  [![Build Status](https://github.com/ankane/glpk-ruby/workflows/build/badge.svg?branch=master)](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
- And for Ubuntu, use:
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
- ObjectSpace.define_finalizer(self, self.class.finalize(@model))
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
@@ -1,3 +1,3 @@
1
1
  module Glpk
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/glpk.rb CHANGED
@@ -2,8 +2,8 @@
2
2
  require "fiddle/import"
3
3
 
4
4
  # modules
5
- require "glpk/problem"
6
- require "glpk/version"
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
- ["libglpk.dylib"]
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.0
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: 2022-04-14 00:00:00.000000000 Z
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.3.7
45
+ rubygems_version: 3.4.10
46
46
  signing_key:
47
47
  specification_version: 4
48
48
  summary: Linear programming kit for Ruby