Sha256: 94f1e4bbfe050b7a9a236726fc4e7511b30b41918366f60d03b95c081ebb4bcd

Contents?: true

Size: 597 Bytes

Versions: 11

Compression:

Stored size: 597 Bytes

Contents

module Ravensat
  class DimacsEncoder
    attr_reader :name_table
    def initialize
      @name_table = {}
    end

    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

    def set_dimacs_name(formula)
      formula.vars.each_with_index do |node, i|
        node.dimacs_name = (i+1).to_s
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ravensat-1.1.1 lib/ravensat/dimacs/dimacs_encoder.rb
ravensat-1.1.0 lib/ravensat/dimacs/dimacs_encoder.rb
ravensat-1.0.9 lib/ravensat/dimacs/dimacs_encoder.rb
ravensat-1.0.8 lib/ravensat/dimacs/dimacs_encoder.rb
ravensat-1.0.7 lib/ravensat/dimacs/dimacs_encoder.rb
ravensat-1.0.6 lib/ravensat/dimacs/dimacs_encoder.rb
ravensat-1.0.5 lib/ravensat/dimacs/dimacs_encoder.rb
ravensat-1.0.4 lib/ravensat/dimacs/dimacs_encoder.rb
ravensat-1.0.3 lib/ravensat/dimacs/dimacs_encoder.rb
ravensat-1.0.2 lib/ravensat/dimacs/dimacs_encoder.rb
ravensat-1.0.1 lib/ravensat/dimacs/dimacs_encoder.rb