cbc 0.1.0 → 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 +9 -0
- data/README.md +7 -5
- data/lib/cbc/ffi.rb +9 -0
- data/lib/cbc/model.rb +12 -9
- data/lib/cbc/version.rb +1 -1
- data/lib/cbc.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: 872906265947008e72d46ca695d37f3787b58207e985e22e0446c1ecea0e7696
|
4
|
+
data.tar.gz: 0bc422b8cc9b5d7aff800f6210799f4003509c62d5d3833a0c5eee3fbc5b4c62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9df3966a5841c3cb280a40153f8c3e97d6b60e52702850b9f5a1f2193759fd17f7f6040830b4f30828686a4b9354f164b79db247102d1c433d80e9a5e2f16e36
|
7
|
+
data.tar.gz: 7937bccb59ba45630c137ec8a415e7e8f15255db4a4ff860bd89629a91682c66f0d338788a1f943684ed16e8617bfc2b9ca8942cd853800feebf45b7353ba431
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
[Cbc](https://github.com/coin-or/Cbc) - the mixed-integer programming solver - 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/cbc-ruby/workflows/build/badge.svg?branch=master)](https://github.com/ankane/cbc-ruby/actions)
|
6
8
|
|
7
9
|
## Installation
|
@@ -52,15 +54,15 @@ Solve
|
|
52
54
|
model.solve
|
53
55
|
```
|
54
56
|
|
55
|
-
Write the problem to an LP or MPS file (LP requires Cbc 2.10
|
57
|
+
Write the problem to an LP or MPS file (LP requires Cbc 2.10+)
|
56
58
|
|
57
59
|
```ruby
|
58
60
|
model.write_lp("hello.lp")
|
59
61
|
# or
|
60
|
-
model.write_mps("hello") # adds mps.gz
|
62
|
+
model.write_mps("hello") # adds .mps.gz
|
61
63
|
```
|
62
64
|
|
63
|
-
Read a problem from an LP or MPS file (LP requires Cbc 2.10
|
65
|
+
Read a problem from an LP or MPS file (LP requires Cbc 2.10+)
|
64
66
|
|
65
67
|
```ruby
|
66
68
|
model = Cbc.read_lp("hello.lp")
|
@@ -70,13 +72,13 @@ model = Cbc.read_mps("hello.mps.gz")
|
|
70
72
|
|
71
73
|
## Reference
|
72
74
|
|
73
|
-
Set the log level (requires Cbc 2.10
|
75
|
+
Set the log level (requires Cbc 2.10+)
|
74
76
|
|
75
77
|
```ruby
|
76
78
|
model.solve(log_level: 1) # 0 = off, 3 = max
|
77
79
|
```
|
78
80
|
|
79
|
-
Set the time limit in seconds (requires Cbc 2.10
|
81
|
+
Set the time limit in seconds (requires Cbc 2.10+)
|
80
82
|
|
81
83
|
```ruby
|
82
84
|
model.solve(time_limit: 30)
|
data/lib/cbc/ffi.rb
CHANGED
@@ -66,7 +66,16 @@ module Cbc
|
|
66
66
|
extern "int Cbc_isProvenOptimal(Cbc_Model *model)"
|
67
67
|
extern "int Cbc_isProvenInfeasible(Cbc_Model *model)"
|
68
68
|
extern "int Cbc_isContinuousUnbounded(Cbc_Model *model)"
|
69
|
+
extern "int Cbc_isNodeLimitReached(Cbc_Model * model)"
|
70
|
+
extern "int Cbc_isSecondsLimitReached(Cbc_Model * model)"
|
71
|
+
extern "int Cbc_isSolutionLimitReached(Cbc_Model * model)"
|
72
|
+
extern "int Cbc_isInitialSolveAbandoned(Cbc_Model * model)"
|
73
|
+
extern "int Cbc_isInitialSolveProvenOptimal(Cbc_Model * model)"
|
74
|
+
extern "int Cbc_isInitialSolveProvenPrimalInfeasible(Cbc_Model * model)"
|
69
75
|
extern "double Cbc_getObjValue(Cbc_Model *model)"
|
76
|
+
extern "double Cbc_getBestPossibleObjValue(Cbc_Model * model)"
|
77
|
+
extern "int Cbc_getNodeCount(Cbc_Model * model)"
|
78
|
+
extern "void Cbc_printSolution(Cbc_Model * model)"
|
70
79
|
extern "int Cbc_status(Cbc_Model *model)"
|
71
80
|
extern "int Cbc_secondaryStatus(Cbc_Model *model)"
|
72
81
|
|
data/lib/cbc/model.rb
CHANGED
@@ -2,7 +2,7 @@ module Cbc
|
|
2
2
|
class Model
|
3
3
|
def initialize
|
4
4
|
@model = FFI.Cbc_newModel
|
5
|
-
|
5
|
+
@model.free = FFI["Cbc_deleteModel"]
|
6
6
|
|
7
7
|
@below210 = Gem::Version.new(Cbc.lib_version) < Gem::Version.new("2.10.0")
|
8
8
|
FFI.Cbc_setLogLevel(model, 0) unless @below210
|
@@ -69,10 +69,18 @@ module Cbc
|
|
69
69
|
|
70
70
|
ret_status =
|
71
71
|
case status
|
72
|
-
when :not_started
|
73
|
-
if FFI.
|
72
|
+
when :not_started
|
73
|
+
if FFI.Cbc_isInitialSolveProvenOptimal(model) != 0
|
74
74
|
:optimal
|
75
|
-
elsif FFI.
|
75
|
+
elsif FFI.Cbc_isInitialSolveProvenPrimalInfeasible(model) != 0
|
76
|
+
:primal_infeasible
|
77
|
+
else
|
78
|
+
secondary_status
|
79
|
+
end
|
80
|
+
when :finished
|
81
|
+
if FFI.Cbc_isProvenOptimal(model) != 0
|
82
|
+
:optimal
|
83
|
+
elsif FFI.Cbc_isProvenInfeasible(model) != 0
|
76
84
|
:infeasible
|
77
85
|
else
|
78
86
|
secondary_status
|
@@ -88,11 +96,6 @@ module Cbc
|
|
88
96
|
}
|
89
97
|
end
|
90
98
|
|
91
|
-
def self.finalize(model)
|
92
|
-
# must use proc instead of stabby lambda
|
93
|
-
proc { FFI.Cbc_deleteModel(model) }
|
94
|
-
end
|
95
|
-
|
96
99
|
private
|
97
100
|
|
98
101
|
def model
|
data/lib/cbc/version.rb
CHANGED
data/lib/cbc.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
require "fiddle/import"
|
3
3
|
|
4
4
|
# modules
|
5
|
-
|
6
|
-
|
5
|
+
require_relative "cbc/model"
|
6
|
+
require_relative "cbc/version"
|
7
7
|
|
8
8
|
module Cbc
|
9
9
|
class Error < StandardError; end
|
@@ -16,7 +16,11 @@ module Cbc
|
|
16
16
|
# TODO test
|
17
17
|
["CbcSolver.dll"]
|
18
18
|
elsif RbConfig::CONFIG["host_os"] =~ /darwin/i
|
19
|
-
["
|
19
|
+
if RbConfig::CONFIG["host_cpu"] =~ /arm|aarch64/i
|
20
|
+
["libCbcSolver.dylib", "/opt/homebrew/lib/libCbcSolver.dylib"]
|
21
|
+
else
|
22
|
+
["libCbcSolver.dylib"]
|
23
|
+
end
|
20
24
|
else
|
21
25
|
# coinor-libcbc-dev has libCbcSolver.so
|
22
26
|
# coinor-libcbc3 has libCbcSolver.so.3
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cbc
|
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:
|
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: Mixed-integer programming for Ruby
|