Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

swap roadmap fix for transport

  • Loading branch information...
commit b3ca1b326f2689868dbed8f8a0c5e6c336dc9cbb 1 parent 5be2a5c
@alexandrebini authored
Showing with 20 additions and 1 deletion.
  1. +19 −1 lib/ga/transport.rb
  2. +1 −0  spec/lib/ga/transport_spec.rb
View
20 lib/ga/transport.rb
@@ -47,8 +47,26 @@ def distance_to(start_machine, goal_machine)
def roadmap=new_roadmap
current_paths = paths
current_paths.delete_if do |r|
- new_roadmap.paths.find{ |m| m.first == r.start && m.last == r.goal }.blank?
+ new_roadmap.paths.find do |machine_pairs|
+ @schema.position_of_machine(machine_pairs.first) == r.start &&
+ @schema.position_of_machine(machine_pairs.last) == r.goal
+ end.blank?
end
+
+ new_roadmap.paths.each_with_index do |machine_pairs, index|
+ start_position = @schema.position_of_machine(machine_pairs.first)
+ goal_position = @schema.position_of_machine(machine_pairs.last)
+
+ next if current_paths[index].present? &&
+ current_paths[index].start == start_position &&
+ current_paths[index].goal == goal_position
+
+ puts "passou"
+ current_paths.insert index, PathFinder.find(start_position, goal_position)
+ end
+
+ @roadmap = new_roadmap
+ @paths = current_paths
end
end
View
1  spec/lib/ga/transport_spec.rb
@@ -109,6 +109,7 @@
paths_before = transport.paths.dup
transport.roadmap = Fabricate(:roadmap, :machines => [@machineB, @machineC, @machineD, @machineE])
+
transport.paths[0].should == paths_before[1]
transport.paths[1].should == paths_before[2]
transport.paths[2].start.should == @positionD
Please sign in to comment.
Something went wrong with that request. Please try again.