rulp 0.0.12 → 0.0.13
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 +8 -8
- data/lib/rulp/rulp.rb +38 -25
- data/lib/rulp/rulp_bounds.rb +1 -1
- data/lib/solvers/cbc.rb +5 -3
- data/lib/solvers/glpk.rb +4 -3
- data/lib/solvers/gurobi.rb +25 -0
- data/lib/solvers/pcbc.rb +4 -3
- data/lib/solvers/pscip.rb +1 -2
- data/lib/solvers/scip.rb +1 -3
- data/lib/solvers/solvers.rb +5 -1
- data/test/test_save_to_file.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzVkMDQ0N2U5ZTg3NGNiMGQ3N2ZlODAyNDljY2U4MDNlMDVkOGRhMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MGI2M2ZiYWVlZWYzMmUzZDM2NjU4NzZlNGQ2Y2M4YzU4YTU0NGE5Ng==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NGQxOWZlNDZkNTU2ZjA1ZTM1M2RkMTIxYmY0ZTExOWE5YjMyODRhNjVlZDhj
|
10
|
+
MGI5YWZiM2MwMTU5ZTcyNDQ2MmI1NWU2NzVmZjNhYzViNmE4MGY5MjcxZjZh
|
11
|
+
YjJjZTM3YTUzZmZiYWE5MGJiNTNlZjBjNWFiYzNjOTg5NTgzZDc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NmYwM2Q1NmFmODk1OGI3OGNjNDRmNDU5OTRhMDRiZGE5ZDJmYzAzZTI3YTQw
|
14
|
+
MzNiMTRhZjdlOTQzZWE2NDE4ZGMwOWI0YzM5MTFjZjAyM2M0MjM4M2YyZjZl
|
15
|
+
Yzc0OWI5NGYxYjdiZTRhMzUxMmM1ODYxZGI3ZWU1NDM3ODBjOWE=
|
data/lib/rulp/rulp.rb
CHANGED
@@ -15,6 +15,7 @@ SCIP = "scip"
|
|
15
15
|
CBC = "cbc"
|
16
16
|
PSCIP = "pscip"
|
17
17
|
PCBC = "pcbc"
|
18
|
+
GUROBI = "gurobi_cl"
|
18
19
|
|
19
20
|
module Rulp
|
20
21
|
attr_accessor :expressions
|
@@ -22,37 +23,47 @@ module Rulp
|
|
22
23
|
MAX = "Maximize"
|
23
24
|
|
24
25
|
GLPK = ::GLPK
|
26
|
+
GUROBI = ::GUROBI
|
25
27
|
SCIP = ::SCIP
|
26
28
|
CBC = ::CBC
|
27
29
|
PSCIP = ::PSCIP
|
28
30
|
PCBC = ::PCBC
|
29
31
|
|
30
32
|
SOLVERS = {
|
31
|
-
GLPK
|
32
|
-
SCIP
|
33
|
-
PSCIP
|
34
|
-
PCBC
|
35
|
-
CBC
|
33
|
+
GLPK => Glpk,
|
34
|
+
SCIP => Scip,
|
35
|
+
PSCIP => PScip,
|
36
|
+
PCBC => PCbc,
|
37
|
+
CBC => Cbc,
|
38
|
+
GUROBI => Gurobi,
|
36
39
|
}
|
37
40
|
|
38
|
-
def self.Glpk(lp)
|
39
|
-
lp.solve_with(GLPK) rescue nil
|
41
|
+
def self.Glpk(lp, opts={})
|
42
|
+
lp.solve_with(GLPK, opts) rescue nil
|
40
43
|
end
|
41
44
|
|
42
|
-
def self.Cbc(lp)
|
43
|
-
lp.solve_with(CBC)
|
45
|
+
def self.Cbc(lp, opts={})
|
46
|
+
lp.solve_with(CBC, opts)
|
44
47
|
end
|
45
48
|
|
46
|
-
def self.Scip(lp)
|
47
|
-
lp.solve_with(SCIP) rescue nil
|
49
|
+
def self.Scip(lp, opts={})
|
50
|
+
lp.solve_with(SCIP, opts) rescue nil
|
48
51
|
end
|
49
52
|
|
50
|
-
def self.Pcbc(lp)
|
51
|
-
lp.solve_with(PCBC) rescue nil
|
53
|
+
def self.Pcbc(lp, opts={})
|
54
|
+
lp.solve_with(PCBC, opts) rescue nil
|
52
55
|
end
|
53
56
|
|
54
|
-
def self.Pscip(lp)
|
55
|
-
lp.solve_with(PSCIP) rescue nil
|
57
|
+
def self.Pscip(lp, opts={})
|
58
|
+
lp.solve_with(PSCIP, opts) rescue nil
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.Pscip(lp, opts={})
|
62
|
+
lp.solve_with(PSCIP, opts) rescue nil
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.Gurobi(lp, opts={})
|
66
|
+
lp.solve_with(GUROBI, opts) rescue nil
|
56
67
|
end
|
57
68
|
|
58
69
|
def self.Max(objective_expression)
|
@@ -86,12 +97,12 @@ module Rulp
|
|
86
97
|
self
|
87
98
|
end
|
88
99
|
|
89
|
-
def solve
|
90
|
-
Rulp.send(self.solver, self)
|
100
|
+
def solve(opts={})
|
101
|
+
Rulp.send(self.solver, self, opts)
|
91
102
|
end
|
92
103
|
|
93
|
-
def method_missing(method_name)
|
94
|
-
self.call(method_name)
|
104
|
+
def method_missing(method_name, *args)
|
105
|
+
self.call(method_name, *args)
|
95
106
|
end
|
96
107
|
|
97
108
|
def solver(solver=nil)
|
@@ -99,8 +110,8 @@ module Rulp
|
|
99
110
|
solver = solver[0].upcase + solver[1..-1].downcase
|
100
111
|
end
|
101
112
|
|
102
|
-
def call(using=nil)
|
103
|
-
Rulp.send(self.solver(using), self)
|
113
|
+
def call(using=nil, options={})
|
114
|
+
Rulp.send(self.solver(using), self, options)
|
104
115
|
end
|
105
116
|
|
106
117
|
def constraints
|
@@ -139,17 +150,19 @@ module Rulp
|
|
139
150
|
IO.write(filename, self)
|
140
151
|
end
|
141
152
|
|
142
|
-
def solve_with(type,
|
153
|
+
def solve_with(type, options={})
|
143
154
|
filename = get_output_filename
|
144
|
-
solver = SOLVERS[type].new(filename)
|
155
|
+
solver = SOLVERS[type].new(filename, options)
|
145
156
|
|
146
157
|
"Writing problem".log(:info)
|
147
158
|
IO.write(filename, self)
|
148
159
|
|
149
|
-
`open #{filename}` if open_definition
|
160
|
+
`open #{filename}` if options[:open_definition]
|
150
161
|
|
151
162
|
"Solving problem".log(:info)
|
152
|
-
_, time = _profile{ solver.solve(
|
163
|
+
_, time = _profile{ solver.solve(options) }
|
164
|
+
|
165
|
+
`open #{solver.outfile}` if options[:open_solution]
|
153
166
|
|
154
167
|
"Solver took #{time}".log(:debug)
|
155
168
|
|
data/lib/rulp/rulp_bounds.rb
CHANGED
data/lib/solvers/cbc.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
class Cbc < Solver
|
2
|
-
def solve(
|
3
|
-
|
4
|
-
|
2
|
+
def solve(options)
|
3
|
+
command = "#{executable} #{@filename} %s branch solution #{@outfile}"
|
4
|
+
command %= options[:gap] ? "ratio #{options[:gap]}":""
|
5
|
+
system(command)
|
6
|
+
`open #{@outfile}` if options[:open_solution]
|
5
7
|
end
|
6
8
|
|
7
9
|
def self.executable
|
data/lib/solvers/glpk.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
class Glpk < Solver
|
2
|
-
def solve(
|
3
|
-
|
4
|
-
|
2
|
+
def solve(options)
|
3
|
+
command = "#{executable} --lp #{@filename} %s --cuts --write #{@outfile}"
|
4
|
+
command %= options[:gap] ? "--mipgap #{options[:gap]}" : ""
|
5
|
+
system(command)
|
5
6
|
end
|
6
7
|
|
7
8
|
def self.executable
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Gurobi < Solver
|
2
|
+
def solve(options)
|
3
|
+
command = "gurobi_cl ResultFile=#{@outfile} #{@filename}"
|
4
|
+
command %= options[:gap] ? "MipGap=#{options[:gap]}":""
|
5
|
+
system(command)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.executable
|
9
|
+
:cbc
|
10
|
+
end
|
11
|
+
|
12
|
+
def store_results(variables)
|
13
|
+
rows = IO.read(@outfile).split("\n")
|
14
|
+
objective = rows[0].split(/\s+/)[-1].to_f
|
15
|
+
vars_by_name = {}
|
16
|
+
rows[1..-1].each do |row|
|
17
|
+
cols = row.strip.split(/\s+/)
|
18
|
+
vars_by_name[cols[0].to_s] = cols[1].to_f
|
19
|
+
end
|
20
|
+
variables.each do |var|
|
21
|
+
var.value = vars_by_name[var.to_s].to_f
|
22
|
+
end
|
23
|
+
return objective
|
24
|
+
end
|
25
|
+
end
|
data/lib/solvers/pcbc.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
class PCbc < Solver
|
2
|
-
def solve(
|
3
|
-
|
4
|
-
|
2
|
+
def solve(options)
|
3
|
+
command = "#{executable} #{@filename} %s threads 8 branch solution #{@outfile}"
|
4
|
+
command %= options[:gap] ? "ratio #{options[:gap]}":""
|
5
|
+
system(command)
|
5
6
|
end
|
6
7
|
|
7
8
|
def self.executable
|
data/lib/solvers/pscip.rb
CHANGED
@@ -4,11 +4,10 @@ class PScip < Solver
|
|
4
4
|
:fscip
|
5
5
|
end
|
6
6
|
|
7
|
-
def solve(
|
7
|
+
def solve(options)
|
8
8
|
command = "touch /tmp/fscip_params; rm #{@outfile}; #{executable} /tmp/fscip_params #{@filename} -fsol #{@outfile}"
|
9
9
|
command += " -s ./scip.set" if File.exists?("./scip.set")
|
10
10
|
system(command)
|
11
|
-
`open #{@outfile}` if open_solution
|
12
11
|
end
|
13
12
|
|
14
13
|
def store_results(variables)
|
data/lib/solvers/scip.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
class Scip < Solver
|
2
|
-
|
3
2
|
def self.executable
|
4
3
|
:scip
|
5
4
|
end
|
6
5
|
|
7
|
-
def solve(
|
6
|
+
def solve(options)
|
8
7
|
system("rm #{@outfile}; #{executable} -f #{@filename} -l #{@outfile} -s ./scip.set")
|
9
|
-
`open #{@outfile}` if open_solution
|
10
8
|
end
|
11
9
|
|
12
10
|
def store_results(variables)
|
data/lib/solvers/solvers.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
class Solver
|
2
|
-
|
2
|
+
attr_reader :options, :outfile
|
3
|
+
|
4
|
+
def initialize(filename, options)
|
5
|
+
@options = options
|
3
6
|
@filename = filename
|
4
7
|
@outfile = get_output_filename
|
5
8
|
raise StandardError.new("Couldn't find solver #{executable}!") if `which #{executable}`.length == 0
|
@@ -32,3 +35,4 @@ require_relative 'scip'
|
|
32
35
|
require_relative 'glpk'
|
33
36
|
require_relative 'pscip'
|
34
37
|
require_relative 'pcbc'
|
38
|
+
require_relative 'gurobi'
|
data/test/test_save_to_file.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rulp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wouter Coppieters
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A simple Ruby LP description DSL
|
14
14
|
email: wc@pico.net.nz
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- lib/rulp/rulp_initializers.rb
|
35
35
|
- lib/solvers/cbc.rb
|
36
36
|
- lib/solvers/glpk.rb
|
37
|
+
- lib/solvers/gurobi.rb
|
37
38
|
- lib/solvers/pcbc.rb
|
38
39
|
- lib/solvers/pscip.rb
|
39
40
|
- lib/solvers/scip.rb
|