From 58d041926de60e8587c5049b54797bc9acb8e06b Mon Sep 17 00:00:00 2001 From: Tayyab Zahid Date: Sun, 2 Feb 2014 15:21:19 +0500 Subject: [PATCH 1/2] Algo finds all possible routes to the destination from source --- app/models/busstop_node.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/busstop_node.rb b/app/models/busstop_node.rb index 1f340cf..7629953 100644 --- a/app/models/busstop_node.rb +++ b/app/models/busstop_node.rb @@ -165,6 +165,7 @@ def self.allUnvisitedNode end def self.findRoute(startID,endID) + allRoutesFound = Array.new if not (Route.all.count > 0) puts "No Routes Exist." return false; @@ -197,7 +198,9 @@ def self.findRoute(startID,endID) print "#{currentNode.to_yaml}" print "Algo complete" @@graph = [] - return pathRoute + allRoutesFound << pathRoute + pathRoute.pop + currentNode = pathRoute.pop end unVisitedNodes = self.allUnvisitedNode shortestDistance = 999999999999999 @@ -231,7 +234,7 @@ def self.findRoute(startID,endID) "\n\n\n" else currentNode == nil puts "end of algo. Reached Back to sourceNode." - return false #end of algo. Reached Back to sourceNode. ###Should Return pathRoute.### + return allRoutesFound #end of algo. Reached Back to sourceNode. ###Should Return pathRoute.### end end #remove this if condition in future. From 9c2460c2aa4c6e4a006974b099e953b75ddf089e Mon Sep 17 00:00:00 2001 From: Saad Masood Date: Sun, 2 Feb 2014 16:53:01 +0500 Subject: [PATCH 2/2] Initail Work for multiple route finding. Needs more time. --- app/models/busstop_node.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/models/busstop_node.rb b/app/models/busstop_node.rb index 7629953..ed94c11 100644 --- a/app/models/busstop_node.rb +++ b/app/models/busstop_node.rb @@ -195,12 +195,15 @@ def self.findRoute(startID,endID) while true #break and retrun `pathRoute` if we have reached the destinationNode. if currentNode.id == destNode.id + currentNode.visited = false #we might arrive on this through a different route. print "#{currentNode.to_yaml}" print "Algo complete" - @@graph = [] - allRoutesFound << pathRoute - pathRoute.pop - currentNode = pathRoute.pop + newPathFound = Array.new + newPathFound = pathRoute.map(&:dup) + allRoutesFound << newPathFound + #set the current node to go to. + #Required. Please Implement before calling this method. + raise "Method Imcomplete." end unVisitedNodes = self.allUnvisitedNode shortestDistance = 999999999999999