Class: Pacer::Neo4j2::Algo::BlockEstimateEvaluator

Inherits:
Object
  • Object
show all
Includes:
EstimateEvaluator
Defined in:
lib/pacer-neo4j2/algo/block_estimate_evaluator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block, graph, default) ⇒ BlockEstimateEvaluator

Returns a new instance of BlockEstimateEvaluator.



11
12
13
14
15
# File 'lib/pacer-neo4j2/algo/block_estimate_evaluator.rb', line 11

def initialize(block, graph, default)
  @block = block
  @graph = graph
  @default = default.to_f
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



9
10
11
# File 'lib/pacer-neo4j2/algo/block_estimate_evaluator.rb', line 9

def block
  @block
end

#defaultObject (readonly)

Returns the value of attribute default.



9
10
11
# File 'lib/pacer-neo4j2/algo/block_estimate_evaluator.rb', line 9

def default
  @default
end

#graphObject (readonly)

Returns the value of attribute graph.



9
10
11
# File 'lib/pacer-neo4j2/algo/block_estimate_evaluator.rb', line 9

def graph
  @graph
end

Instance Method Details

#getCost(node, goal) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pacer-neo4j2/algo/block_estimate_evaluator.rb', line 17

def getCost(node, goal)
  node = Pacer::Wrappers::VertexWrapper.new graph, Neo4j2Vertex.new(node, graph.blueprints_graph)
  goal = Pacer::Wrappers::VertexWrapper.new graph, Neo4j2Vertex.new(goal, graph.blueprints_graph)
  result = block.call node, goal
  if result.is_a? Numeric
    result.to_f
  elsif default
    default
  else
    fail Pacer::ClientError, "No estimate returned and no default specified: #{ result.inspect }"
  end
end