Class: Solver
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#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
- #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 |
# 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 end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
2 3 4 |
# File 'lib/solvers/solver.rb', line 2 def filename @filename end |
#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
36 37 38 |
# File 'lib/solvers/solver.rb', line 36 def self.exists? return `which #{self.executable}`.length != 0 end |
Instance Method Details
#exec(command) ⇒ Object
24 25 26 |
# File 'lib/solvers/solver.rb', line 24 def exec(command) Rulp.exec(command) end |
#executable ⇒ Object
20 21 22 |
# File 'lib/solvers/solver.rb', line 20 def executable self.class.executable end |
#get_output_filename ⇒ Object
12 13 14 |
# File 'lib/solvers/solver.rb', line 12 def get_output_filename "/tmp/rulp-#{Random.rand(0..1000)}.sol" end |
#next_pipe ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/solvers/solver.rb', line 40 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
28 29 30 |
# File 'lib/solvers/solver.rb', line 28 def remove_lp_file FileUtils.rm(@filename) end |
#remove_sol_file ⇒ Object
32 33 34 |
# File 'lib/solvers/solver.rb', line 32 def remove_sol_file FileUtils.rm(@outfile) end |
#store_results(variables) ⇒ Object
16 17 18 |
# File 'lib/solvers/solver.rb', line 16 def store_results(variables) puts "Not yet implemented" end |
#with_pipe(pipe) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/solvers/solver.rb', line 49 def with_pipe(pipe) output = open(pipe, 'w+') thread = Thread.new{ yield output output.flush } return thread, output end |