clp 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +14 -0
- data/lib/clp/ffi.rb +4 -0
- data/lib/clp/model.rb +23 -3
- data/lib/clp/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 185f03fde8ab409746c146c6193e34b8beb1317991c52b869d0a9a1714227259
|
4
|
+
data.tar.gz: b785a19d316b0ff5dea8647ef63d762b42a8891c9a4c5615ee7cfd252018be7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 798dfc96c75bece7fcfb5581b036d78a0f82a4f7b6a904f0253b5c3d765398c5b69bb7b58d70ce9bd7d9a38d692eb24ae41c44eb71f9fabc2597703f38b7b23d
|
7
|
+
data.tar.gz: 8e95103aecb6162e352cfc12be4048cca63e94cc44e463f04afdd699e8ddccaf55aecb96a2156376965369e4cdb782abdef4ff61123d41c9123c4a5140850402
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -63,6 +63,20 @@ Read a problem from an MPS file
|
|
63
63
|
model = Clp.read_mps("hello.mps")
|
64
64
|
```
|
65
65
|
|
66
|
+
## Reference
|
67
|
+
|
68
|
+
Set the log level
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
model.solve(log_level: 4)
|
72
|
+
```
|
73
|
+
|
74
|
+
Set the time limit in seconds
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
model.solve(time_limit: 30)
|
78
|
+
```
|
79
|
+
|
66
80
|
## History
|
67
81
|
|
68
82
|
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
@@ -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)
|
@@ -63,7 +66,7 @@ module Clp
|
|
63
66
|
|
64
67
|
def check_status(status)
|
65
68
|
if status != 0
|
66
|
-
raise Error, "Bad status"
|
69
|
+
raise Error, "Bad status: #{status}"
|
67
70
|
end
|
68
71
|
end
|
69
72
|
|
@@ -87,5 +90,22 @@ module Clp
|
|
87
90
|
def read_double_array(ptr, size)
|
88
91
|
ptr[0, size * Fiddle::SIZEOF_DOUBLE].unpack("d#{size}")
|
89
92
|
end
|
93
|
+
|
94
|
+
def with_options(log_level:, time_limit:)
|
95
|
+
if log_level
|
96
|
+
previous_log_level = FFI.Clp_logLevel(model)
|
97
|
+
FFI.Clp_setLogLevel(model, log_level)
|
98
|
+
end
|
99
|
+
|
100
|
+
if time_limit
|
101
|
+
previous_time_limit = FFI.Clp_maximumSeconds(model)
|
102
|
+
FFI.Clp_setMaximumSeconds(model, time_limit)
|
103
|
+
end
|
104
|
+
|
105
|
+
yield
|
106
|
+
ensure
|
107
|
+
FFI.Clp_setLogLevel(model, previous_log_level) if previous_log_level
|
108
|
+
FFI.Clp_setMaximumSeconds(model, previous_time_limit) if previous_time_limit
|
109
|
+
end
|
90
110
|
end
|
91
111
|
end
|
data/lib/clp/version.rb
CHANGED
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.2
|
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-
|
11
|
+
date: 2022-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: andrew@ankane.org
|