rulp 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51fa526dd152f836d5b5e6f4658352847828fa8e
4
- data.tar.gz: 0858e2314d40ee7d7ac6e085634bfeb064d1d9f2
3
+ metadata.gz: 94d1b4aeebe550905d47cc889f958df9b241242f
4
+ data.tar.gz: 2d32d06eac07ad13c4f9efccd4fe7231c7fca44d
5
5
  SHA512:
6
- metadata.gz: 5c0fdb11528ae4ce52edf332902b0941fc4c298c2a06d21f41b11da96d8d8216e7f495a96a47587dd0588563981ed656af74468dcc06b9cd7be5f27682fc5363
7
- data.tar.gz: 6603c3523a9a755eef88ad563d71ab27282a37cc539edcb733a765cefdf0c4f57e81c74308d57af5b2f7d099e662a95523ed9a511b77e0a15a5495b197b72d6a
6
+ metadata.gz: bbd24354398f8ab0ddedea6340a833f3c5cc3b4c9171e18b98dffa050ac5b4482c93067ad5295efd1416ea662ec5d700b97573977d8616e82651448466116a86
7
+ data.tar.gz: 61e76aea75b4f67f2a2aa76f8b3c7c21bcfc63af3d7966919386f3cff41d1d1a6f2eac7cd1d2bacf32b2abe49ee2e70489d3e471c779437f5010dd52b173d6c9
data/lib/helpers/log.rb CHANGED
@@ -34,6 +34,14 @@ module Rulp
34
34
  @@level || :info
35
35
  end
36
36
 
37
+ def self.print_solver_outputs
38
+ @@solver_level
39
+ end
40
+
41
+ def self.print_solver_outputs=(value)
42
+ @@solver_level = value
43
+ end
44
+
37
45
  def self.log(level, message)
38
46
  if(LEVELS[level].to_i <= LEVELS[self.level])
39
47
  puts("[#{colorize(level)}] #{message}")
@@ -58,6 +66,7 @@ module Rulp
58
66
  end
59
67
 
60
68
  self.level = :info
69
+ self.print_solver_outputs = true
61
70
 
62
71
  class ::String
63
72
  def log(level)
data/lib/rulp/rulp.rb CHANGED
@@ -64,6 +64,11 @@ module Rulp
64
64
  solver_class.exists? if(solver_class)
65
65
  end
66
66
 
67
+
68
+ def self.exec(command)
69
+ system("#{command} #{Rulp::Logger.print_solver_outputs ? "" : "&> /dev/null"}")
70
+ end
71
+
67
72
  class Problem
68
73
  def initialize(objective, objective_expression)
69
74
  @objective = objective
@@ -142,12 +147,12 @@ module Rulp
142
147
  "Writing problem".log(:info)
143
148
  IO.write(filename, self)
144
149
 
145
- `open #{filename}` if options[:open_definition]
150
+ Rulp.exec("open #{filename}") if options[:open_definition]
146
151
 
147
152
  "Solving problem".log(:info)
148
153
  _, time = _profile{ solver.solve }
149
154
 
150
- `open #{solver.outfile}` if options[:open_solution]
155
+ Rulp.exec("open #{solver.outfile}") if options[:open_solution]
151
156
 
152
157
  "Solver took #{time}".log(:debug)
153
158
 
data/lib/solvers/cbc.rb CHANGED
@@ -10,7 +10,7 @@ class Cbc < Solver
10
10
  options[:node_limit] ? "maxN #{options[:node_limit]}":""
11
11
  ]
12
12
 
13
- system(command)
13
+ exec(command)
14
14
  end
15
15
 
16
16
  def self.executable
data/lib/solvers/glpk.rb CHANGED
@@ -2,7 +2,7 @@ class Glpk < Solver
2
2
  def solve
3
3
  command = "#{executable} --lp #{@filename} %s --cuts --write #{@outfile}"
4
4
  command %= options[:gap] ? "--mipgap #{options[:gap]}" : ""
5
- system(command)
5
+ exec(command)
6
6
  end
7
7
 
8
8
  def self.executable
@@ -5,7 +5,7 @@ class Gurobi < Solver
5
5
  options[:gap] ? "MipGap=#{options[:gap]}":"",
6
6
  options[:node_limit] ? "NodeLimit=#{options[:node_limit]}":""
7
7
  ]
8
- system(command)
8
+ exec(command)
9
9
  end
10
10
 
11
11
  def self.executable
data/lib/solvers/scip.rb CHANGED
@@ -6,11 +6,14 @@ class Scip < Solver
6
6
  def solve
7
7
  settings = settings_file
8
8
  if options[:parallel]
9
- command = "touch /tmp/fscip_params; rm #{@outfile}; fscip /tmp/fscip_params #{@filename} -fsol #{@outfile} -s #{settings}"
9
+ exec("touch /tmp/fscip_params")
10
+ exec("rm #{@outfile}")
11
+ command = "fscip /tmp/fscip_params #{@filename} -fsol #{@outfile} -s #{settings}"
10
12
  else
11
- command = "rm #{@outfile}; #{executable} -f #{@filename} -l #{@outfile} -s #{settings}"
13
+ exec("rm #{@outfile}")
14
+ command = "#{executable} -f #{@filename} -l #{@outfile} -s #{settings}"
12
15
  end
13
- system(command)
16
+ exec(command)
14
17
  end
15
18
 
16
19
  def settings_file
@@ -21,6 +21,10 @@ class Solver
21
21
  self.class.executable
22
22
  end
23
23
 
24
+ def exec(command)
25
+ Rulp.exec(command)
26
+ end
27
+
24
28
  def solver_exists?
25
29
  @solver_exists || false
26
30
  end
data/test/test_helper.rb CHANGED
@@ -4,7 +4,7 @@ gem "minitest"
4
4
  require "minitest/autorun"
5
5
 
6
6
  Rulp::Logger::level = :off
7
-
7
+ Rulp::Logger::print_solver_outputs = false
8
8
 
9
9
  def each_solver
10
10
  [:scip, :cbc, :glpk, :gurobi].each do |solver|
@@ -12,7 +12,7 @@ def each_solver
12
12
  if Rulp::solver_exists?(solver)
13
13
  yield(solver)
14
14
  else
15
- puts "Couldn't find solver #{solver}"
15
+ "Couldn't find solver #{solver}".log(:info)
16
16
  end
17
17
  end
18
18
  end
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.16
4
+ version: 0.0.17
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-10-07 00:00:00.000000000 Z
11
+ date: 2015-11-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple Ruby LP description DSL
14
14
  email: wc@pico.net.nz