Class: Ravensat::DimacsEncoder
- Inherits:
-
Object
- Object
- Ravensat::DimacsEncoder
- Defined in:
- lib/ravensat/dimacs/dimacs_encoder.rb
Instance Attribute Summary collapse
-
#name_table ⇒ Object
readonly
Returns the value of attribute name_table.
Instance Method Summary collapse
-
#initialize ⇒ DimacsEncoder
constructor
A new instance of DimacsEncoder.
- #set_dimacs_name(formula) ⇒ Object
- #to_dimacs(formula) ⇒ Object
Constructor Details
#initialize ⇒ DimacsEncoder
Returns a new instance of DimacsEncoder.
4 5 6 |
# File 'lib/ravensat/dimacs/dimacs_encoder.rb', line 4 def initialize @name_table = {} end |
Instance Attribute Details
#name_table ⇒ Object (readonly)
Returns the value of attribute name_table.
3 4 5 |
# File 'lib/ravensat/dimacs/dimacs_encoder.rb', line 3 def name_table @name_table end |
Instance Method Details
#set_dimacs_name(formula) ⇒ Object
22 23 24 25 26 |
# File 'lib/ravensat/dimacs/dimacs_encoder.rb', line 22 def set_dimacs_name(formula) formula.vars.each_with_index do |node, i| node.dimacs_name = (i+1).to_s end end |
#to_dimacs(formula) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ravensat/dimacs/dimacs_encoder.rb', line 8 def to_dimacs(formula) dimacs_header = "p cnf #{formula.vars_size} #{formula.clauses_size}\n" dimacs_body = "" return nil unless formula.cnf? set_dimacs_name(formula) formula.each_by_descriptive do |node| dimacs_body << node.to_dimacs end dimacs_header + dimacs_body end |