clp 0.1.1 → 0.1.3
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 +9 -0
- data/README.md +16 -0
- data/lib/clp/ffi.rb +4 -0
- data/lib/clp/model.rb +24 -9
- data/lib/clp/version.rb +1 -1
- data/lib/clp.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: ce8d28ee2e7e1772cfc1cdc8ea027e6946a791a3682ac4865f10f78cce765426
|
4
|
+
data.tar.gz: 656c14297cc86e4baf08b33b64940530b3a83e2133a8e944c1c47d75487fae0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '086c1b6352fb07f1a425b955ccf95eebe4fbf7c4c7a2ba8736ca04811732dd0c9dde9f7233611d12ed71c9880b2646f6ffcc892b334231a33aee9e63f2b1ace7'
|
7
|
+
data.tar.gz: 103720186f2a2a547fd9561a381ab9b4bb7b7c8c197a2f573ac6183e52506ecafb6d1513a61cd68862209d915a3dabc3e856d7cbceb3d9e4ca3a9c492ecc2e0c
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## 0.1.3 (2023-06-07)
|
2
|
+
|
3
|
+
- Improved support for Mac ARM
|
4
|
+
- Fixed error with `dup` and `clone`
|
5
|
+
|
6
|
+
## 0.1.2 (2022-04-14)
|
7
|
+
|
8
|
+
- Added `log_level` and `time_limit` options to `solve` method
|
9
|
+
|
1
10
|
## 0.1.1 (2022-04-06)
|
2
11
|
|
3
12
|
- Fixed shared library detection on Linux
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
[Clp](https://github.com/coin-or/Clp) - linear programming solver - 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/clp-ruby/actions)
|
6
8
|
|
7
9
|
## Installation
|
@@ -63,6 +65,20 @@ Read a problem from an MPS file
|
|
63
65
|
model = Clp.read_mps("hello.mps")
|
64
66
|
```
|
65
67
|
|
68
|
+
## Reference
|
69
|
+
|
70
|
+
Set the log level
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
model.solve(log_level: 4)
|
74
|
+
```
|
75
|
+
|
76
|
+
Set the time limit in seconds
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
model.solve(time_limit: 30)
|
80
|
+
```
|
81
|
+
|
66
82
|
## History
|
67
83
|
|
68
84
|
View the [changelog](https://github.com/ankane/clp-ruby/blob/master/CHANGELOG.md)
|
data/lib/clp/ffi.rb
CHANGED
@@ -14,6 +14,7 @@ module Clp
|
|
14
14
|
|
15
15
|
OBJ_SENSE = {
|
16
16
|
minimize: 1,
|
17
|
+
ignore: 0,
|
17
18
|
maximize: -1
|
18
19
|
}
|
19
20
|
|
@@ -42,6 +43,8 @@ module Clp
|
|
42
43
|
extern "int Clp_numberColumns(Clp_Simplex *model)"
|
43
44
|
extern "double Clp_objectiveOffset(Clp_Simplex *model)"
|
44
45
|
extern "void Clp_setObjectiveOffset(Clp_Simplex *model, double value)"
|
46
|
+
extern "double Clp_maximumSeconds(Clp_Simplex *model)"
|
47
|
+
extern "void Clp_setMaximumSeconds(Clp_Simplex *model, double value)"
|
45
48
|
extern "int Clp_status(Clp_Simplex *model)"
|
46
49
|
extern "double Clp_getObjSense(Clp_Simplex *model)"
|
47
50
|
extern "void Clp_setObjSense(Clp_Simplex *model, double objsen)"
|
@@ -57,6 +60,7 @@ module Clp
|
|
57
60
|
extern "double * Clp_getElements(Clp_Simplex *model)"
|
58
61
|
extern "double Clp_objectiveValue(Clp_Simplex *model)"
|
59
62
|
extern "void Clp_setLogLevel(Clp_Simplex *model, int value)"
|
63
|
+
extern "int Clp_logLevel(Clp_Simplex *model)"
|
60
64
|
|
61
65
|
# solve
|
62
66
|
extern "int Clp_initialSolve(Clp_Simplex *model)"
|
data/lib/clp/model.rb
CHANGED
@@ -2,7 +2,7 @@ module Clp
|
|
2
2
|
class Model
|
3
3
|
def initialize
|
4
4
|
@model = FFI.Clp_newModel
|
5
|
-
|
5
|
+
@model.free = FFI["Clp_deleteModel"]
|
6
6
|
|
7
7
|
FFI.Clp_setLogLevel(model, 0)
|
8
8
|
end
|
@@ -34,8 +34,11 @@ module Clp
|
|
34
34
|
check_status FFI.Clp_writeMps(model, filename, 0, 1, 0)
|
35
35
|
end
|
36
36
|
|
37
|
-
def solve
|
38
|
-
|
37
|
+
def solve(log_level: nil, time_limit: nil)
|
38
|
+
with_options(log_level: log_level, time_limit: time_limit) do
|
39
|
+
# do not check status
|
40
|
+
FFI.Clp_initialSolve(model)
|
41
|
+
end
|
39
42
|
|
40
43
|
num_rows = FFI.Clp_numberRows(model)
|
41
44
|
num_cols = FFI.Clp_numberColumns(model)
|
@@ -50,11 +53,6 @@ module Clp
|
|
50
53
|
}
|
51
54
|
end
|
52
55
|
|
53
|
-
def self.finalize(model)
|
54
|
-
# must use proc instead of stabby lambda
|
55
|
-
proc { FFI.Clp_deleteModel(model) }
|
56
|
-
end
|
57
|
-
|
58
56
|
private
|
59
57
|
|
60
58
|
def model
|
@@ -63,7 +61,7 @@ module Clp
|
|
63
61
|
|
64
62
|
def check_status(status)
|
65
63
|
if status != 0
|
66
|
-
raise Error, "Bad status"
|
64
|
+
raise Error, "Bad status: #{status}"
|
67
65
|
end
|
68
66
|
end
|
69
67
|
|
@@ -87,5 +85,22 @@ module Clp
|
|
87
85
|
def read_double_array(ptr, size)
|
88
86
|
ptr[0, size * Fiddle::SIZEOF_DOUBLE].unpack("d#{size}")
|
89
87
|
end
|
88
|
+
|
89
|
+
def with_options(log_level:, time_limit:)
|
90
|
+
if log_level
|
91
|
+
previous_log_level = FFI.Clp_logLevel(model)
|
92
|
+
FFI.Clp_setLogLevel(model, log_level)
|
93
|
+
end
|
94
|
+
|
95
|
+
if time_limit
|
96
|
+
previous_time_limit = FFI.Clp_maximumSeconds(model)
|
97
|
+
FFI.Clp_setMaximumSeconds(model, time_limit)
|
98
|
+
end
|
99
|
+
|
100
|
+
yield
|
101
|
+
ensure
|
102
|
+
FFI.Clp_setLogLevel(model, previous_log_level) if previous_log_level
|
103
|
+
FFI.Clp_setMaximumSeconds(model, previous_time_limit) if previous_time_limit
|
104
|
+
end
|
90
105
|
end
|
91
106
|
end
|
data/lib/clp/version.rb
CHANGED
data/lib/clp.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
require "fiddle/import"
|
3
3
|
|
4
4
|
# modules
|
5
|
-
|
6
|
-
|
5
|
+
require_relative "clp/model"
|
6
|
+
require_relative "clp/version"
|
7
7
|
|
8
8
|
module Clp
|
9
9
|
class Error < StandardError; end
|
@@ -16,7 +16,11 @@ module Clp
|
|
16
16
|
# TODO test
|
17
17
|
["Clp.dll"]
|
18
18
|
elsif RbConfig::CONFIG["host_os"] =~ /darwin/i
|
19
|
-
["
|
19
|
+
if RbConfig::CONFIG["host_cpu"] =~ /arm|aarch64/i
|
20
|
+
["libClp.dylib", "/opt/homebrew/lib/libClp.dylib"]
|
21
|
+
else
|
22
|
+
["libClp.dylib"]
|
23
|
+
end
|
20
24
|
else
|
21
25
|
# coinor-libclp-dev has libClp.so
|
22
26
|
# coinor-libclp1 has libClp.so.1
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
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 solver for Ruby
|