maneuver 0.0.2pre → 0.0.3pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,21 +27,28 @@ module Maneuver
27
27
  nil
28
28
  end
29
29
 
30
- def self.path(from, to, edge_algorithm = nil)
30
+ def self.path(graph, from, to, edge_algorithm = nil)
31
31
  return from if from == to
32
32
  self.prep_node
33
33
  nodes_to_check = []
34
34
  visited = [from]
35
- from.outgoing_edges.each { |edge| edge.to._fs_parent = from; nodes_to_check << edge.to }
35
+ from.outgoing_edges.each do |edge|
36
+ if graph.edges.include? edge
37
+ edge.to._fs_parent = from;
38
+ nodes_to_check << edge.to
39
+ end
40
+ end
36
41
  while !nodes_to_check.empty?
37
42
  node = self.get_node nodes_to_check
38
43
  return self.reconstruct_path(to) if node == to
39
44
  node.outgoing_edges.each do |e|
40
- test = e.to
41
- unless visited.include? test
42
- test._fs_parent = node
43
- visited << test
44
- nodes_to_check.unshift test
45
+ if graph.edges.include? e
46
+ test = e.to
47
+ unless visited.include? test
48
+ test._fs_parent = node
49
+ visited << test
50
+ nodes_to_check.unshift test
51
+ end
45
52
  end
46
53
  end
47
54
  end
@@ -11,11 +11,11 @@ module Maneuver
11
11
  end
12
12
 
13
13
  def insert_nodes(*nodes)
14
- nodes.each { |n| @nodes << n unless @nodes.include? n }
14
+ nodes.flatten.each { |n| @nodes << n unless @nodes.include? n }
15
15
  end
16
16
 
17
17
  def insert_edges(*edges)
18
- edges.each do |e|
18
+ edges.flatten.each do |e|
19
19
  unless has_edge e
20
20
  @edges << e
21
21
  @nodes << e.to unless @nodes.include? e.to
@@ -34,7 +34,18 @@ module Maneuver
34
34
  def path(from, to, search_algorithm, cost_algorithm = nil)
35
35
  search = Maneuver.search_algorithms[search_algorithm]
36
36
  raise "Unknown Search Algorithm: #{search_algorithm}" unless search
37
- search.path(from, to, cost_algorithm)
37
+ search.path(self, from, to, cost_algorithm)
38
+ end
39
+
40
+ def edge_between(from, to)
41
+ from.outgoing_edges.select {|e| e.to == to && @edges.include?(e) }.first
42
+ end
43
+
44
+ def clone
45
+ g = self.class.new
46
+ g.insert_edges @edges
47
+ g.insert_nodes @nodes
48
+ return g
38
49
  end
39
50
  end
40
51
  end
data/lib/maneuver/node.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  module Maneuver
2
2
  class Node
3
- attr_reader :edges
4
- def initialize(*args)
3
+ attr_reader :edges, :id
4
+ def initialize(id)
5
+ @id = id
5
6
  @edges = []
6
7
  end
7
8
 
@@ -1,6 +1,6 @@
1
1
  module Maneuver
2
2
  class SearchAlgorithm
3
- def self.path(from, to, cost_algorithm = nil)
3
+ def self.path(graph, from, to, cost_algorithm = nil)
4
4
  nil
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maneuver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2pre
4
+ version: 0.0.3pre
5
5
  prerelease: 5
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-19 00:00:00.000000000 Z
12
+ date: 2013-04-05 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A simple graph library with path planning.
15
15
  email: kayle@moremagic.io
@@ -46,8 +46,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
46
  version: 1.3.1
47
47
  requirements: []
48
48
  rubyforge_project:
49
- rubygems_version: 1.8.24
49
+ rubygems_version: 1.8.23
50
50
  signing_key:
51
51
  specification_version: 3
52
52
  summary: Graph and Path Planning
53
53
  test_files: []
54
+ has_rdoc: