Class: RubyAi::Search::Edge

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_ai/search/edge.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_vertex:, end_vertex:, cost:) ⇒ Edge

Returns a new instance of Edge.



6
7
8
9
10
# File 'lib/ruby_ai/search/edge.rb', line 6

def initialize(start_vertex:, end_vertex:, cost:)
  @start_vertex = start_vertex
  @end_vertex = end_vertex
  @cost = cost
end

Instance Attribute Details

#costObject (readonly)

Returns the value of attribute cost.



4
5
6
# File 'lib/ruby_ai/search/edge.rb', line 4

def cost
  @cost
end

#end_vertexObject (readonly)

Returns the value of attribute end_vertex.



4
5
6
# File 'lib/ruby_ai/search/edge.rb', line 4

def end_vertex
  @end_vertex
end

#start_vertexObject (readonly)

Returns the value of attribute start_vertex.



4
5
6
# File 'lib/ruby_ai/search/edge.rb', line 4

def start_vertex
  @start_vertex
end

Instance Method Details

#==(other) ⇒ Object



12
13
14
15
16
17
# File 'lib/ruby_ai/search/edge.rb', line 12

def ==(other)
  self.class == other.class && 
  @start_vertex == other.start_vertex &&
  @end_vertex   == other.end_vertex &&
  @cost         == other.cost 
end

#to_sObject



19
20
21
# File 'lib/ruby_ai/search/edge.rb', line 19

def to_s
  "edge: #{@start_vertex} (#{@cost}) #{@end_vertex}"
end