Class: LogicTools::NodeVar

Inherits:
Node
  • Object
show all
Defined in:
lib/logic_tools/logictree.rb

Overview

Represents a variable node.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#cover?, #distribute, #each, #each_line, #each_maxterm, #each_minterm, #eql?, #flatten, #flatten_deep, #get_variables, #hash, #include?, #inspect, #is_parent?, #reduce, #simplify, #size, #to_cover, #to_std_conjunctive, #to_std_disjunctive, #to_sum_product

Constructor Details

#initialize(name) ⇒ NodeVar

Creates a node with variable name.



378
379
380
381
382
# File 'lib/logic_tools/logictree.rb', line 378

def initialize(name)
    @variable = Variable.get(name)
    # @sym = @variable.to_s.to_sym
    @sym = nil
end

Instance Attribute Details

#variableObject (readonly)

The variable held by the node.



375
376
377
# File 'lib/logic_tools/logictree.rb', line 375

def variable
  @variable
end

Instance Method Details

#==(node) ⇒ Object

Compares with node.



416
417
418
419
# File 'lib/logic_tools/logictree.rb', line 416

def ==(node) # :nodoc:
    return false unless node.is_a?(NodeVar)
    return self.variable == node.variable
end

#evalObject

Computes the value of the node.



398
399
400
# File 'lib/logic_tools/logictree.rb', line 398

def eval()
    return @variable.value
end

#get_variablesRecurseObject

Gets the variables, recursively, without postprocessing.

Returns the variables into sets of arrays with possible doublon


411
412
413
# File 'lib/logic_tools/logictree.rb', line 411

def get_variablesRecurse() # :nodoc:
    return [ @variable ]
end

#opObject

Gets the operator.

Default: +nil+ (none).


387
388
389
# File 'lib/logic_tools/logictree.rb', line 387

def op
    :variable
end

#to_sObject

Converts to a string.



422
423
424
425
426
427
428
# File 'lib/logic_tools/logictree.rb', line 422

def to_s # :nodoc:
    result = variable.to_s
    # Variables using more than one character are parenthesized
    # to avoid confunsion with the AND operator.
    result = "{" + result + "}" if (result.size > 1)
    return result
end

#to_symObject

Converts to a symbol.



403
404
405
406
# File 'lib/logic_tools/logictree.rb', line 403

def to_sym # :nodoc:
    @sym = @variable.to_s.to_sym unless @sym
    return @sym
end