Class: DpllSolver::Formulas::Clause
- Inherits:
-
Object
- Object
- DpllSolver::Formulas::Clause
- Defined in:
- lib/dpll_solver/formulas/clause.rb
Instance Attribute Summary collapse
-
#literals ⇒ Object
Returns the value of attribute literals.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #add(literal) ⇒ Object
- #delete(literal) ⇒ Object
- #empty? ⇒ Boolean
- #get_unit_literal ⇒ Object
- #include?(literal) ⇒ Boolean
-
#initialize(*args) ⇒ Clause
constructor
A new instance of Clause.
- #to_s ⇒ Object
- #union(other) ⇒ Object
- #unit? ⇒ Boolean
Constructor Details
#initialize(*args) ⇒ Clause
Returns a new instance of Clause.
5 6 7 |
# File 'lib/dpll_solver/formulas/clause.rb', line 5 def initialize(*args) @literals = Set.new(args) end |
Instance Attribute Details
#literals ⇒ Object
Returns the value of attribute literals.
4 5 6 |
# File 'lib/dpll_solver/formulas/clause.rb', line 4 def literals @literals end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
42 43 44 |
# File 'lib/dpll_solver/formulas/clause.rb', line 42 def ==(other) other.class == self.class && other.literals == @literals end |
#add(literal) ⇒ Object
9 10 11 12 |
# File 'lib/dpll_solver/formulas/clause.rb', line 9 def add(literal) @literals.add(literal) self end |
#delete(literal) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/dpll_solver/formulas/clause.rb', line 14 def delete(literal) literal_array = @literals.to_a literal_array.delete(literal) @literals = Set.new(literal_array) self end |
#empty? ⇒ Boolean
25 26 27 |
# File 'lib/dpll_solver/formulas/clause.rb', line 25 def empty? @literals.empty? end |
#get_unit_literal ⇒ Object
38 39 40 |
# File 'lib/dpll_solver/formulas/clause.rb', line 38 def get_unit_literal @literals.first if unit? end |
#include?(literal) ⇒ Boolean
29 30 31 |
# File 'lib/dpll_solver/formulas/clause.rb', line 29 def include?(literal) @literals.to_a.include?(literal) end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/dpll_solver/formulas/clause.rb', line 46 def to_s "{#{@literals.to_a.map(&:to_s).join(', ')}}" end |
#union(other) ⇒ Object
33 34 35 36 |
# File 'lib/dpll_solver/formulas/clause.rb', line 33 def union(other) @literals = @literals + other.literals self end |
#unit? ⇒ Boolean
21 22 23 |
# File 'lib/dpll_solver/formulas/clause.rb', line 21 def unit? @literals.count == 1 end |