Class: DpllSolver::Formulas::Clause

Inherits:
Object
  • Object
show all
Defined in:
lib/dpll_solver/formulas/clause.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#literalsObject

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

Returns:

  • (Boolean)


25
26
27
# File 'lib/dpll_solver/formulas/clause.rb', line 25

def empty?
  @literals.empty?
end

#get_unit_literalObject



38
39
40
# File 'lib/dpll_solver/formulas/clause.rb', line 38

def get_unit_literal
  @literals.first if unit?
end

#include?(literal) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/dpll_solver/formulas/clause.rb', line 29

def include?(literal)
  @literals.to_a.include?(literal)
end

#to_sObject



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

Returns:

  • (Boolean)


21
22
23
# File 'lib/dpll_solver/formulas/clause.rb', line 21

def unit?
  @literals.count == 1
end