Class: Solver
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#outfile ⇒ Object
readonly
Returns the value of attribute outfile.
-
#unsuccessful ⇒ Object
Returns the value of attribute unsuccessful.
Class Method Summary collapse
Instance Method Summary collapse
- #exec(command) ⇒ Object
- #executable ⇒ Object
- #get_output_filename ⇒ Object
-
#initialize(filename, options) ⇒ Solver
constructor
A new instance of Solver.
- #next_pipe ⇒ Object
- #remove_lp_file ⇒ Object
- #remove_sol_file ⇒ Object
- #solver_exists? ⇒ Boolean
- #store_results(variables) ⇒ Object
- #with_pipe(pipe) ⇒ Object
Constructor Details
#initialize(filename, options) ⇒ Solver
Returns a new instance of Solver.
5 6 7 8 9 10 11 |
# File 'lib/solvers/solver.rb', line 5 def initialize(filename, ) @options = @filename = filename @outfile = get_output_filename raise StandardError.new("Couldn't find solver #{executable}!") if `which #{executable}`.length == 0 @solver_exists = true end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
2 3 4 |
# File 'lib/solvers/solver.rb', line 2 def @options end |
#outfile ⇒ Object (readonly)
Returns the value of attribute outfile.
2 3 4 |
# File 'lib/solvers/solver.rb', line 2 def outfile @outfile end |
#unsuccessful ⇒ Object
Returns the value of attribute unsuccessful.
3 4 5 |
# File 'lib/solvers/solver.rb', line 3 def unsuccessful @unsuccessful end |
Class Method Details
.exists? ⇒ Boolean
41 42 43 |
# File 'lib/solvers/solver.rb', line 41 def self.exists? return `which #{self.executable}`.length != 0 end |
Instance Method Details
#exec(command) ⇒ Object
25 26 27 |
# File 'lib/solvers/solver.rb', line 25 def exec(command) Rulp.exec(command) end |
#executable ⇒ Object
21 22 23 |
# File 'lib/solvers/solver.rb', line 21 def executable self.class.executable end |
#get_output_filename ⇒ Object
13 14 15 |
# File 'lib/solvers/solver.rb', line 13 def get_output_filename "/tmp/rulp-#{Random.rand(0..1000)}.sol" end |
#next_pipe ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/solvers/solver.rb', line 45 def next_pipe filename = "./tmp/_rulp_pipe" file_index = 1 file_index += 1 while File.exists?("#{filename}_#{file_index}") pipe = "#{filename}_#{file_index}" `mkfifo #{pipe}` pipe end |
#remove_lp_file ⇒ Object
29 30 31 |
# File 'lib/solvers/solver.rb', line 29 def remove_lp_file FileUtils.rm(@filename) end |
#remove_sol_file ⇒ Object
33 34 35 |
# File 'lib/solvers/solver.rb', line 33 def remove_sol_file FileUtils.rm(@outfile) end |
#solver_exists? ⇒ Boolean
37 38 39 |
# File 'lib/solvers/solver.rb', line 37 def solver_exists? @solver_exists || false end |
#store_results(variables) ⇒ Object
17 18 19 |
# File 'lib/solvers/solver.rb', line 17 def store_results(variables) puts "Not yet implemented" end |
#with_pipe(pipe) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/solvers/solver.rb', line 54 def with_pipe(pipe) output = open(pipe, 'w+') thread = Thread.new{ yield output output.flush } return thread, output end |