rulp 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/rulp/rulp.rb +17 -3
- data/lib/solvers/pcbc.rb +24 -0
- data/lib/solvers/pscip.rb +31 -0
- data/lib/solvers/solvers.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTI0NWU3NTcxYTg3MzczYWE4MzI0NDRkNTNlMWQ3NTllNGU4ZjdkYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWYzNDhlYzI1MTM2ZjM1M2E0NTcyMGY4YmE2Y2E4MzM1YTRkZmZmZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjMzMGVjNWI5YWJmNWQxY2Q2MjZkYTMzZmQ2NWJjZmJlMmMyODA0N2ZiYTQz
|
10
|
+
MjRlYzY1MmY4NTQxNWU0OWRkNGNkZTU1ODQ0YjU3NGRhMWJkMTIzM2U5Y2Zj
|
11
|
+
NDU4YWY5YTViNDQ1NTNiNGVmZTYyNjlkZDhiYzA0ZDM2YTA2ZmM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjY2NjJiNDgzNWUzYzk1MmJlMGYyZTUxMGYxOTVlMDdhNjVkYzM3OWYzMjcz
|
14
|
+
OWU0ZDQ0MmU3Y2QyMjdmMTYyNzQ2MmVkMzAxZjEzNWJlOGMwZWIxMDRlYTNk
|
15
|
+
OGI5MGJlN2NiZjkzMjQ5NjA1OGIwMGQyMDdjZDA5ODY3YmFhMGI=
|
data/lib/rulp/rulp.rb
CHANGED
@@ -13,6 +13,8 @@ require 'set'
|
|
13
13
|
GLPK = "glpsol"
|
14
14
|
SCIP = "scip"
|
15
15
|
CBC = "cbc"
|
16
|
+
PSCIP = "pscip"
|
17
|
+
PCBC = "pcbc"
|
16
18
|
|
17
19
|
module Rulp
|
18
20
|
attr_accessor :expressions
|
@@ -22,11 +24,15 @@ module Rulp
|
|
22
24
|
GLPK = ::GLPK
|
23
25
|
SCIP = ::SCIP
|
24
26
|
CBC = ::CBC
|
27
|
+
PSCIP = ::PSCIP
|
28
|
+
PCBC = ::PCBC
|
25
29
|
|
26
30
|
SOLVERS = {
|
27
|
-
GLPK
|
28
|
-
SCIP
|
29
|
-
|
31
|
+
GLPK => Glpk,
|
32
|
+
SCIP => Scip,
|
33
|
+
PSCIP => PScip,
|
34
|
+
PCBC => PCbc,
|
35
|
+
CBC => Cbc
|
30
36
|
}
|
31
37
|
|
32
38
|
def self.Glpk(lp)
|
@@ -41,6 +47,14 @@ module Rulp
|
|
41
47
|
lp.solve_with(SCIP) rescue nil
|
42
48
|
end
|
43
49
|
|
50
|
+
def self.Pcbc(lp)
|
51
|
+
lp.solve_with(PCBC) rescue nil
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.Pscip(lp)
|
55
|
+
lp.solve_with(PSCIP) rescue nil
|
56
|
+
end
|
57
|
+
|
44
58
|
def self.Max(objective_expression)
|
45
59
|
"Creating maximization problem".log :info
|
46
60
|
Problem.new(Rulp::MAX, objective_expression)
|
data/lib/solvers/pcbc.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
class PCbc < Solver
|
2
|
+
def solve(open_solution=false)
|
3
|
+
system("#{executable} #{@filename} threads 8 branch solution #{@outfile}")
|
4
|
+
`open #{@outfile}` if open_solution
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.executable
|
8
|
+
:cbc
|
9
|
+
end
|
10
|
+
|
11
|
+
def store_results(variables)
|
12
|
+
rows = IO.read(@outfile).split("\n")
|
13
|
+
objective = rows[0].split(/\s+/)[-1].to_f
|
14
|
+
vars_by_name = {}
|
15
|
+
rows[1..-1].each do |row|
|
16
|
+
cols = row.strip.split(/\s+/)
|
17
|
+
vars_by_name[cols[1].to_s] = cols[2].to_f
|
18
|
+
end
|
19
|
+
variables.each do |var|
|
20
|
+
var.value = vars_by_name[var.to_s].to_f
|
21
|
+
end
|
22
|
+
return objective
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class PScip < Solver
|
2
|
+
|
3
|
+
def self.executable
|
4
|
+
:fscip
|
5
|
+
end
|
6
|
+
|
7
|
+
def solve(open_solution=false)
|
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
|
+
`open #{@outfile}` if open_solution
|
12
|
+
end
|
13
|
+
|
14
|
+
def store_results(variables)
|
15
|
+
results = IO.read(@outfile)
|
16
|
+
rows = results.split("\n")
|
17
|
+
|
18
|
+
objective = rows[1].split(/\s+/)[-1].to_f
|
19
|
+
|
20
|
+
vars_by_name = {}
|
21
|
+
rows[1..-1].each do |row|
|
22
|
+
cols = row.strip.split(/\s+/)
|
23
|
+
vars_by_name[cols[0].to_s] = cols[1].to_f
|
24
|
+
end
|
25
|
+
variables.each do |var|
|
26
|
+
var.value = vars_by_name[var.to_s].to_f
|
27
|
+
end
|
28
|
+
|
29
|
+
return objective
|
30
|
+
end
|
31
|
+
end
|
data/lib/solvers/solvers.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.10
|
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-03-
|
11
|
+
date: 2015-03-27 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,8 @@ files:
|
|
34
34
|
- lib/rulp/rulp_initializers.rb
|
35
35
|
- lib/solvers/cbc.rb
|
36
36
|
- lib/solvers/glpk.rb
|
37
|
+
- lib/solvers/pcbc.rb
|
38
|
+
- lib/solvers/pscip.rb
|
37
39
|
- lib/solvers/scip.rb
|
38
40
|
- lib/solvers/solvers.rb
|
39
41
|
- test/test_basic_suite.rb
|