rulp 0.0.13 → 0.0.14
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 +4 -22
- data/lib/solvers/cbc.rb +14 -4
- data/lib/solvers/glpk.rb +1 -1
- data/lib/solvers/gurobi.rb +7 -4
- data/lib/solvers/scip.rb +30 -2
- data/lib/solvers/solvers.rb +0 -2
- metadata +1 -3
- data/lib/solvers/pcbc.rb +0 -25
- data/lib/solvers/pscip.rb +0 -30
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzYxYzBjMTNmYmFhN2MxY2MwOGVmZTgzZmEzNTBlZTczMzAzODg4YQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGYxNzNjODE3YmJmMWVjYzU5MjFhOWM2NTg2OWQ2ZTY2MTI3ZTEyYg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTZhMmIyYjdkMGZhNzFjM2VkNDBjNjZkOTBjYWU1YjNjMmQzOGRiMDUxNWZm
|
10
|
+
MmQwNmJkZWIzZjczMjU3YTAzNTc4NjFlYTgzNWIyMjIxYTI3ODM4ZDkwNTcy
|
11
|
+
Y2Y1N2RjM2I4N2U4YzFmNjVhYzI0N2FkMzAwZGIyMzBmNzY0Nzk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzllNGI2NTQxZDcyNGU0OWQxYjg0MjM4NjY5YTRlNDFkMWYzZTU0NDMzODFj
|
14
|
+
NjRiYzc3Njc5NjAwZWEwZDBjYzg3NGU3ZjNkNGM1MDdlM2EwY2NjOWQzOGI1
|
15
|
+
ZmU5YWFlNjM5MDI5N2ZlZDFkZWE5ZDIyNjk0MGNmZTdhOTQyODM=
|
data/lib/rulp/rulp.rb
CHANGED
@@ -13,8 +13,6 @@ require 'set'
|
|
13
13
|
GLPK = "glpsol"
|
14
14
|
SCIP = "scip"
|
15
15
|
CBC = "cbc"
|
16
|
-
PSCIP = "pscip"
|
17
|
-
PCBC = "pcbc"
|
18
16
|
GUROBI = "gurobi_cl"
|
19
17
|
|
20
18
|
module Rulp
|
@@ -26,20 +24,16 @@ module Rulp
|
|
26
24
|
GUROBI = ::GUROBI
|
27
25
|
SCIP = ::SCIP
|
28
26
|
CBC = ::CBC
|
29
|
-
PSCIP = ::PSCIP
|
30
|
-
PCBC = ::PCBC
|
31
27
|
|
32
28
|
SOLVERS = {
|
33
29
|
GLPK => Glpk,
|
34
30
|
SCIP => Scip,
|
35
|
-
PSCIP => PScip,
|
36
|
-
PCBC => PCbc,
|
37
31
|
CBC => Cbc,
|
38
32
|
GUROBI => Gurobi,
|
39
33
|
}
|
40
34
|
|
41
35
|
def self.Glpk(lp, opts={})
|
42
|
-
lp.solve_with(GLPK, opts)
|
36
|
+
lp.solve_with(GLPK, opts)
|
43
37
|
end
|
44
38
|
|
45
39
|
def self.Cbc(lp, opts={})
|
@@ -47,23 +41,11 @@ module Rulp
|
|
47
41
|
end
|
48
42
|
|
49
43
|
def self.Scip(lp, opts={})
|
50
|
-
lp.solve_with(SCIP, opts)
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.Pcbc(lp, opts={})
|
54
|
-
lp.solve_with(PCBC, opts) rescue nil
|
55
|
-
end
|
56
|
-
|
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
|
44
|
+
lp.solve_with(SCIP, opts)
|
63
45
|
end
|
64
46
|
|
65
47
|
def self.Gurobi(lp, opts={})
|
66
|
-
lp.solve_with(GUROBI, opts)
|
48
|
+
lp.solve_with(GUROBI, opts)
|
67
49
|
end
|
68
50
|
|
69
51
|
def self.Max(objective_expression)
|
@@ -160,7 +142,7 @@ module Rulp
|
|
160
142
|
`open #{filename}` if options[:open_definition]
|
161
143
|
|
162
144
|
"Solving problem".log(:info)
|
163
|
-
_, time = _profile{ solver.solve
|
145
|
+
_, time = _profile{ solver.solve }
|
164
146
|
|
165
147
|
`open #{solver.outfile}` if options[:open_solution]
|
166
148
|
|
data/lib/solvers/cbc.rb
CHANGED
@@ -1,9 +1,19 @@
|
|
1
1
|
class Cbc < Solver
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
|
3
|
+
#maxN
|
4
|
+
|
5
|
+
def solve
|
6
|
+
if options[:parallel]
|
7
|
+
command = "#{executable} #{@filename} %s %s threads 8 branch solution #{@outfile}"
|
8
|
+
else
|
9
|
+
command = "#{executable} #{@filename} %s %s branch solution #{@outfile}"
|
10
|
+
end
|
11
|
+
command %= [
|
12
|
+
options[:gap] ? "ratio #{options[:gap]}":"",
|
13
|
+
options[:node_limit] ? "maxN #{options[:node_limit]}":""
|
14
|
+
]
|
15
|
+
|
5
16
|
system(command)
|
6
|
-
`open #{@outfile}` if options[:open_solution]
|
7
17
|
end
|
8
18
|
|
9
19
|
def self.executable
|
data/lib/solvers/glpk.rb
CHANGED
data/lib/solvers/gurobi.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
class Gurobi < Solver
|
2
|
-
def solve
|
3
|
-
command = "
|
4
|
-
command %=
|
2
|
+
def solve
|
3
|
+
command = "#{executable} ResultFile=#{@outfile} %s %s #{@filename}"
|
4
|
+
command %= [
|
5
|
+
options[:gap] ? "MipGap=#{options[:gap]}":"",
|
6
|
+
options[:node_limit] ? "NodeLimit=#{options[:node_limit]}":""
|
7
|
+
]
|
5
8
|
system(command)
|
6
9
|
end
|
7
10
|
|
8
11
|
def self.executable
|
9
|
-
:
|
12
|
+
:gurobi_cl
|
10
13
|
end
|
11
14
|
|
12
15
|
def store_results(variables)
|
data/lib/solvers/scip.rb
CHANGED
@@ -3,8 +3,36 @@ class Scip < Solver
|
|
3
3
|
:scip
|
4
4
|
end
|
5
5
|
|
6
|
-
def solve
|
7
|
-
|
6
|
+
def solve
|
7
|
+
settings = settings_file
|
8
|
+
if options[:parallel]
|
9
|
+
command = "touch /tmp/fscip_params; rm #{@outfile}; fscip /tmp/fscip_params #{@filename} -fsol #{@outfile} -s #{settings}"
|
10
|
+
else
|
11
|
+
command = "rm #{@outfile}; #{executable} -f #{@filename} -l #{@outfile} -s #{settings}"
|
12
|
+
end
|
13
|
+
system(command)
|
14
|
+
end
|
15
|
+
|
16
|
+
def settings_file
|
17
|
+
existing_settings = if File.exists?("./scip.set")
|
18
|
+
IO.read("./scip.set")
|
19
|
+
else
|
20
|
+
""
|
21
|
+
end
|
22
|
+
if options[:node_limit]
|
23
|
+
existing_settings += "\nlimits/nodes = #{options[:node_limit]}"
|
24
|
+
end
|
25
|
+
if options[:gap]
|
26
|
+
existing_settings += "\nlimits/gap = #{options[:gap]}"
|
27
|
+
end
|
28
|
+
|
29
|
+
settings_file = get_settings_filename
|
30
|
+
IO.write(settings_file, existing_settings)
|
31
|
+
return settings_file
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_settings_filename
|
35
|
+
"/tmp/rulp-#{Random.rand(0..1000)}.set"
|
8
36
|
end
|
9
37
|
|
10
38
|
def store_results(variables)
|
data/lib/solvers/solvers.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wouter Coppieters
|
@@ -35,8 +35,6 @@ files:
|
|
35
35
|
- lib/solvers/cbc.rb
|
36
36
|
- lib/solvers/glpk.rb
|
37
37
|
- lib/solvers/gurobi.rb
|
38
|
-
- lib/solvers/pcbc.rb
|
39
|
-
- lib/solvers/pscip.rb
|
40
38
|
- lib/solvers/scip.rb
|
41
39
|
- lib/solvers/solvers.rb
|
42
40
|
- test/test_basic_suite.rb
|
data/lib/solvers/pcbc.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
class PCbc < Solver
|
2
|
-
def solve(options)
|
3
|
-
command = "#{executable} #{@filename} %s threads 8 branch solution #{@outfile}"
|
4
|
-
command %= options[:gap] ? "ratio #{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[1].to_s] = cols[2].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/pscip.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
class PScip < Solver
|
2
|
-
|
3
|
-
def self.executable
|
4
|
-
:fscip
|
5
|
-
end
|
6
|
-
|
7
|
-
def solve(options)
|
8
|
-
command = "touch /tmp/fscip_params; rm #{@outfile}; #{executable} /tmp/fscip_params #{@filename} -fsol #{@outfile}"
|
9
|
-
command += " -s ./scip.set" if File.exists?("./scip.set")
|
10
|
-
system(command)
|
11
|
-
end
|
12
|
-
|
13
|
-
def store_results(variables)
|
14
|
-
results = IO.read(@outfile)
|
15
|
-
rows = results.split("\n")
|
16
|
-
|
17
|
-
objective = rows[1].split(/\s+/)[-1].to_f
|
18
|
-
|
19
|
-
vars_by_name = {}
|
20
|
-
rows[1..-1].each do |row|
|
21
|
-
cols = row.strip.split(/\s+/)
|
22
|
-
vars_by_name[cols[0].to_s] = cols[1].to_f
|
23
|
-
end
|
24
|
-
variables.each do |var|
|
25
|
-
var.value = vars_by_name[var.to_s].to_f
|
26
|
-
end
|
27
|
-
|
28
|
-
return objective
|
29
|
-
end
|
30
|
-
end
|