Class: Solver
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(filename, options) ⇒ Solver
Returns a new instance of Solver.
7
8
9
10
11
12
|
# File 'lib/solvers/solver.rb', line 7
def initialize(filename, options)
@options = options
@filename = filename
@outfile = get_output_filename
raise StandardError.new("Couldn't find solver #{executable}!") if `which #{executable}`.length == 0
end
|
Instance Attribute Details
Returns the value of attribute filename.
4
5
6
|
# File 'lib/solvers/solver.rb', line 4
def filename
@filename
end
|
#model_status ⇒ Object
Returns the value of attribute model_status.
5
6
7
|
# File 'lib/solvers/solver.rb', line 5
def model_status
@model_status
end
|
Returns the value of attribute options.
4
5
6
|
# File 'lib/solvers/solver.rb', line 4
def options
@options
end
|
Returns the value of attribute outfile.
4
5
6
|
# File 'lib/solvers/solver.rb', line 4
def outfile
@outfile
end
|
#unsuccessful ⇒ Object
Returns the value of attribute unsuccessful.
5
6
7
|
# File 'lib/solvers/solver.rb', line 5
def unsuccessful
@unsuccessful
end
|
Class Method Details
.exists? ⇒ Boolean
38
39
40
|
# File 'lib/solvers/solver.rb', line 38
def self.exists?
return `which #{self.executable}`.length != 0
end
|
Instance Method Details
#exec(command) ⇒ Object
26
27
28
|
# File 'lib/solvers/solver.rb', line 26
def exec(command)
Rulp.exec(command)
end
|
#executable ⇒ Object
22
23
24
|
# File 'lib/solvers/solver.rb', line 22
def executable
self.class.executable
end
|
#get_output_filename ⇒ Object
14
15
16
|
# File 'lib/solvers/solver.rb', line 14
def get_output_filename
"/tmp/rulp-#{Random.rand(0..1000)}.sol"
end
|
#next_pipe ⇒ Object
42
43
44
45
46
47
48
49
|
# File 'lib/solvers/solver.rb', line 42
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
30
31
32
|
# File 'lib/solvers/solver.rb', line 30
def remove_lp_file
FileUtils.rm(@filename)
end
|
#remove_sol_file ⇒ Object
34
35
36
|
# File 'lib/solvers/solver.rb', line 34
def remove_sol_file
FileUtils.rm(@outfile)
end
|
#store_results(variables) ⇒ Object
18
19
20
|
# File 'lib/solvers/solver.rb', line 18
def store_results(variables)
puts "Not yet implemented"
end
|
#with_pipe(pipe) ⇒ Object
51
52
53
54
55
56
57
58
|
# File 'lib/solvers/solver.rb', line 51
def with_pipe(pipe)
output = open(pipe, 'w+')
thread = Thread.new{
yield output
output.flush
}
return thread, output
end
|