annotate lib/Graph/PathsTraversal.pm @ 2:17fef9d80c97 draft

Deleted selected files
author deepakjadmin
date Wed, 20 Jan 2016 09:11:43 -0500
parents 2abf0d43254d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1 package Graph::PathsTraversal;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
2 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
3 # $RCSfile: PathsTraversal.pm,v $
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
4 # $Date: 2015/02/28 20:49:06 $
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
5 # $Revision: 1.29 $
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
6 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
7 # Author: Manish Sud <msud@san.rr.com>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
8 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
9 # Copyright (C) 2015 Manish Sud. All rights reserved.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
10 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
11 # This file is part of MayaChemTools.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
12 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
13 # MayaChemTools is free software; you can redistribute it and/or modify it under
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
14 # the terms of the GNU Lesser General Public License as published by the Free
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
15 # Software Foundation; either version 3 of the License, or (at your option) any
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
16 # later version.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
17 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
18 # MayaChemTools is distributed in the hope that it will be useful, but without
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
19 # any warranty; without even the implied warranty of merchantability of fitness
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
20 # for a particular purpose. See the GNU Lesser General Public License for more
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
21 # details.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
22 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
23 # You should have received a copy of the GNU Lesser General Public License
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
24 # along with MayaChemTools; if not, see <http://www.gnu.org/licenses/> or
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
25 # write to the Free Software Foundation Inc., 59 Temple Place, Suite 330,
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
26 # Boston, MA, 02111-1307, USA.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
27 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
28
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
29 use strict;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
30 use Carp;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
31 use Exporter;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
32 use Graph;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
33 use Graph::Path;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
34
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
35 use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
36
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
37 @ISA = qw(Exporter);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
38 @EXPORT = qw();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
39 @EXPORT_OK = qw();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
40
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
41 %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
42
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
43 # Setup class variables...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
44 my($ClassName);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
45 _InitializeClass();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
46
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
47 # Overload Perl functions...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
48 use overload '""' => 'StringifyPathsTraversal';
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
49
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
50 # Class constructor...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
51 sub new {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
52 my($Class, $Graph) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
53
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
54 # Initialize object...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
55 my $This = {};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
56 bless $This, ref($Class) || $Class;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
57 $This->_InitializePathsTraversal($Graph);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
58
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
59 return $This;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
60 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
61
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
62 # Initialize object data...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
63 sub _InitializePathsTraversal {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
64 my($This, $Graph) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
65
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
66 # Graph object...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
67 $This->{Graph} = $Graph;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
68
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
69 # Traversal mode: Vertex or Path
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
70 $This->{TraversalMode} = '';
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
71
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
72 # Traversal type: DFS, DFSWithLimit, BFS, BFSWithLimit...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
73 $This->{TraversalType} = '';
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
74
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
75 # For finding root vertex and controlling search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
76 my(@VertexIDs);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
77 @VertexIDs = $This->{Graph}->GetVertices();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
78 %{$This->{VerticesToVisit}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
79 @{$This->{VerticesToVisit}}{ @VertexIDs } = @VertexIDs;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
80
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
81 # Root vertex of all visited vertices...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
82 %{$This->{VerticesRoots}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
83
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
84 # Visited vertices...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
85 %{$This->{VisitedVertices}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
86
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
87 # Finished vertices...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
88 %{$This->{FinishedVertices}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
89
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
90 # List of active vertices during DFS/BFS search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
91 @{$This->{ActiveVertices}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
92
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
93 # List of ordered vertices traversed during DFS/BFS search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
94 @{$This->{Vertices}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
95
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
96 # Vertex neighbors during traversal...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
97 %{$This->{VerticesNeighbors}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
98
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
99 # Vertices depth from root...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
100 %{$This->{VerticesDepth}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
101
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
102 # Predecessor of each vertex during vertex traversal. For root vertex, it's root itself...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
103 %{$This->{VerticesPredecessors}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
104
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
105 # Successors of each vertex during vertex traversal...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
106 %{$This->{VerticesSuccessors}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
107
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
108 # Vertices at different neighborhood levels during vertex traversal...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
109 @{$This->{VerticesNeighborhoods}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
110
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
111 # Vertices, along with their successors, at different neighborhood levels during vertex traversal...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
112 @{$This->{VerticesNeighborhoodsWithSuccessors}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
113
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
114 # Visited edges during Path TraversalMode...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
115 %{$This->{VisitedEdges}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
116 %{$This->{VisitedEdges}->{From}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
117 %{$This->{VisitedEdges}->{To}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
118
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
119 # Vertex path during Path TraversalMode...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
120 %{$This->{VerticesPaths}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
121
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
122 # Allow cycles in paths during VertexNeighborhood TraversalMode. By default, cycles are not allowed
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
123 # during vertex traversal: a vertex is only visited once during BFS search for neighborhoods. For
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
124 # neighborhood vertices search during successors identification, vertex cycles are explicity allowed
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
125 # to indentify all successors.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
126 $This->{AllowVertexCycles} = 0;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
127
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
128 # Allow cycles in paths during Path TraversalMode...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
129 $This->{AllowPathCycles} = 1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
130
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
131 # Cycle closure vertices during Path TraversalMode...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
132 %{$This->{CycleClosureVertices}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
133
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
134 # Paths traversed during search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
135 @{$This->{Paths}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
136
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
137 return $This;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
138 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
139
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
140 # Initialize class ...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
141 sub _InitializeClass {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
142 #Class name...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
143 $ClassName = __PACKAGE__;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
144 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
145
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
146 # Perform a depth first search (DFS)...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
147 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
148 sub PerformDepthFirstSearch {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
149 my($This, $RootVertexID) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
150
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
151 if (defined $RootVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
152 if (!$This->{Graph}->HasVertex($RootVertexID)) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
153 carp "Warning: ${ClassName}->PerformDepthFirstSearch: No search performed: Vertex $RootVertexID doesn't exist...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
154 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
155 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
156 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
157 return $This->_PerformVertexSearch("DFS", $RootVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
158 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
159
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
160 # Perform a depth first search (DFS) with limit on depth...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
161 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
162 sub PerformDepthFirstSearchWithLimit {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
163 my($This, $DepthLimit, $RootVertexID) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
164
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
165 if (!defined $DepthLimit) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
166 carp "Warning: ${ClassName}->PerformDepthFirstSearchWithLimit: No search performed: Depth limit must be specified...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
167 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
168 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
169 if ($DepthLimit < 0) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
170 carp "Warning: ${ClassName}->PerformDepthFirstSearchWithLimit: No search performed: Specified depth limit, $DepthLimit, must be a positive integer...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
171 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
172 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
173 if (defined $RootVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
174 if (!$This->{Graph}->HasVertex($RootVertexID)) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
175 carp "Warning: ${ClassName}->PerformDepthFirstSearchWithLimit: No search performed: Vertex $RootVertexID doesn't exist...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
176 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
177 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
178 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
179 return $This->_PerformVertexSearch("DFSWithLimit", $RootVertexID, $DepthLimit);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
180 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
181
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
182 # Perform a breadth first search (BFS)...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
183 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
184 sub PerformBreadthFirstSearch {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
185 my($This, $RootVertexID) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
186
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
187 if (defined $RootVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
188 if (!$This->{Graph}->HasVertex($RootVertexID)) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
189 carp "Warning: ${ClassName}->PerformBreadthFirstSearch: No search performed: Vertex $RootVertexID doesn't exist...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
190 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
191 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
192 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
193 return $This->_PerformVertexSearch("BFS", $RootVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
194 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
195
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
196 # Perform a breadth first search (BFS) with limit...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
197 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
198 sub PerformBreadthFirstSearchWithLimit {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
199 my($This, $DepthLimit, $RootVertexID) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
200
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
201 if (!defined $DepthLimit) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
202 carp "Warning: ${ClassName}->PerformBreadthFirstSearchWithLimit: No search performed: Depth limit must be specified...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
203 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
204 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
205 if ($DepthLimit < 0) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
206 carp "Warning: ${ClassName}->PerformBreadthFirstSearchWithLimit: No search performed: Specified depth limit, $DepthLimit, must be a positive integer...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
207 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
208 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
209 if (defined $RootVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
210 if (!$This->{Graph}->HasVertex($RootVertexID)) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
211 carp "Warning: ${ClassName}->PerformDepthFirstSearchWithLimit: No search performed: Vertex $RootVertexID doesn't exist...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
212 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
213 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
214 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
215 return $This->_PerformVertexSearch("BFSWithLimit", $RootVertexID, $DepthLimit);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
216 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
217
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
218 # Perform appropriate vertex search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
219 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
220 sub _PerformVertexSearch {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
221 my($This, $SearchType, $RootVertexID, $DepthLimit, $TargetVertexID) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
222
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
223 # Setup search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
224 $This->{TraversalMode} = 'Vertex';
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
225 $This->{TraversalType} = $SearchType;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
226
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
227 if (defined $RootVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
228 $This->{RootVertex} = $RootVertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
229 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
230 if (defined $DepthLimit) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
231 $This->{DepthLimit} = $DepthLimit;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
232 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
233 if (defined $TargetVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
234 $This->{TargetVertex} = $TargetVertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
235 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
236
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
237 # Perform search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
238 return $This->_TraverseGraph();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
239 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
240
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
241 # Perform DFS or BFS traversal with or without any limits...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
242 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
243 sub _TraverseGraph {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
244 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
245 my($ProcessingVertices, $CurrentVertexID, $NeighborVertexID, $VertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
246
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
247 if ($This->{TraversalMode} !~ /^(Vertex|Path|VertexNeighborhood)$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
248 return $This;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
249 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
250
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
251 $ProcessingVertices = 1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
252
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
253 VERTICES: while ($ProcessingVertices) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
254 # Set root vertex...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
255 if (!@{$This->{ActiveVertices}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
256 my($RootVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
257
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
258 $RootVertexID = $This->_GetRootVertex();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
259 if (!defined $RootVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
260 $ProcessingVertices = 0; next VERTICES;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
261 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
262 $This->_ProcessVisitedVertex($RootVertexID, $RootVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
263 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
264
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
265 # Get current active vertex...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
266 $CurrentVertexID = $This->_GetActiveVertex();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
267 if (!defined $CurrentVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
268 $ProcessingVertices = 0; next VERTICES;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
269 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
270
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
271 # Get next available neighbor of current vertex...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
272 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
273 $NeighborVertexID = $This->_GetNeighborVertex($CurrentVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
274
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
275 # Process neighbor or current vertex...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
276 if (defined $NeighborVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
277 $This->_ProcessVisitedVertex($NeighborVertexID, $CurrentVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
278 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
279 else {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
280 # Finished with all neighbors for current vertex...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
281 $This->_ProcessFinishedVertex($CurrentVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
282 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
283 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
284 return $This;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
285 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
286
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
287 # Get root vertex to start the search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
288 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
289 # Notes:
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
290 # . User specification of root vertex forces traversal in a specific connected component
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
291 # of graph; To traverse find all connected components, perform traversal without specification of
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
292 # a root vertex.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
293 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
294 sub _GetRootVertex {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
295 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
296 my($RootVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
297
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
298 # Check for specified root vertex and constrain traversal to specific connected
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
299 # component by setting root limit...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
300 if (exists $This->{RootVertex}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
301 $RootVertexID = $This->{RootVertex};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
302 delete $This->{RootVertex};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
303 $This->{RootVertexSpecified} = 1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
304
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
305 return $RootVertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
306 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
307 # Traversal limited to connected component containing specified root vertex...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
308 if (exists $This->{RootVertexSpecified}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
309 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
310 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
311
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
312 # Use first vertex in sorted available vertices list to get root vertex. Vertex
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
313 # with largest degree could also be used as root vertex. However, for all
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
314 # practical purposes, any arbitrary vertex can be used as root vertex to
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
315 # start search for another disconnected component of the graph.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
316 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
317 my(@VerticesToVisit);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
318
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
319 $RootVertexID = undef; @VerticesToVisit = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
320 @VerticesToVisit = sort { $a <=> $b } keys %{$This->{VerticesToVisit}};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
321 if (@VerticesToVisit) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
322 $RootVertexID = $VerticesToVisit[0];
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
323 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
324 return $RootVertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
325 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
326
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
327 # Get current or new active vertex for DFS/BFS traversals...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
328 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
329 sub _GetActiveVertex {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
330 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
331 my($ActiveVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
332
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
333 $ActiveVertexID = undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
334 if ($This->{TraversalType} =~ /^(DFS|DFSWithLimit)$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
335 # For DFS, it's last vertex in LIFO queue...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
336 $ActiveVertexID = $This->{ActiveVertices}[-1];
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
337 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
338 elsif ($This->{TraversalType} =~ /^(BFS|BFSWithLimit)$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
339 # For BFS, it's first vertex in FIFO queue...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
340 $ActiveVertexID = $This->{ActiveVertices}[0];
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
341 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
342 return $ActiveVertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
343 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
344
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
345 # Get available neigbor of specified vertex...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
346 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
347 sub _GetNeighborVertex {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
348 my($This, $VertexID) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
349
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
350 # Retrieve neighbors for vertex...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
351 if (!exists $This->{VerticesNeighbors}{$VertexID}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
352 @{$This->{VerticesNeighbors}{$VertexID}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
353
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
354 if (exists $This->{DepthLimit}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
355 # Only collect neighbors to visit below specified depth limit...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
356 if ($This->{VerticesDepth}{$VertexID} < $This->{DepthLimit}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
357 push @{$This->{VerticesNeighbors}{$VertexID}}, $This->{Graph}->GetNeighbors($VertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
358 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
359 else {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
360 if (!exists $This->{RootVertexSpecified}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
361 # Mark all other downstream neighbor vertices to be ignored from any further
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
362 # processing and avoid selection of a new root...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
363 $This->_IgnoreDownstreamNeighbors($VertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
364 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
365 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
366 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
367 elsif (exists $This->{TargetVertex}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
368 if ($VertexID != $This->{TargetVertex}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
369 push @{$This->{VerticesNeighbors}{$VertexID}}, $This->{Graph}->GetNeighbors($VertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
370 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
371 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
372 else {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
373 push @{$This->{VerticesNeighbors}{$VertexID}}, $This->{Graph}->GetNeighbors($VertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
374 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
375 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
376
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
377 if ($This->{TraversalMode} =~ /^Path$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
378 # Get available neighbor for path search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
379 return $This->_GetNeighborVertexDuringPathTraversal($VertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
380 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
381 elsif ($This->{TraversalMode} =~ /^Vertex$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
382 # Get unvisited neighbor for vertex search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
383 return $This->_GetNeighborVertexDuringVertexTraversal($VertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
384 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
385 elsif ($This->{TraversalMode} =~ /^VertexNeighborhood$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
386 # Get available neighbor during vertex neighborhood search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
387 return $This->_GetNeighborVertexDuringVertexNeighborhoodTraversal($VertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
388 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
389 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
390 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
391
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
392 # Get unvisited neighbor of specified vertex during vertex traversal...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
393 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
394 sub _GetNeighborVertexDuringVertexTraversal {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
395 my($This, $VertexID) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
396 my($NeighborVertexID, $UnvisitedNeighborVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
397
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
398 # Get unvisited neighbor...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
399 $UnvisitedNeighborVertexID = undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
400 NEIGHBOR: for $NeighborVertexID (@{$This->{VerticesNeighbors}{$VertexID}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
401 if (!exists $This->{VisitedVertices}{$NeighborVertexID}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
402 $UnvisitedNeighborVertexID = $NeighborVertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
403 last NEIGHBOR;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
404 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
405 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
406 return $UnvisitedNeighborVertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
407 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
408
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
409 # Get available neighbor of specified vertex during vertex neighborhood traversal...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
410 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
411 sub _GetNeighborVertexDuringVertexNeighborhoodTraversal {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
412 my($This, $VertexID) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
413 my($NeighborVertexID, $UnvisitedNeighborVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
414
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
415 # Get available neighbor...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
416 $UnvisitedNeighborVertexID = undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
417 NEIGHBOR: for $NeighborVertexID (@{$This->{VerticesNeighbors}{$VertexID}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
418 if (!exists $This->{VisitedVertices}{$NeighborVertexID}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
419 $UnvisitedNeighborVertexID = $NeighborVertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
420 last NEIGHBOR;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
421 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
422 # Look for any unvisited edge back to visited vertex...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
423 if ($This->_IsVisitedEdge($VertexID, $NeighborVertexID) || $This->_IsVisitedEdge($NeighborVertexID, $VertexID)) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
424 next NEIGHBOR;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
425 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
426 # Check its depth...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
427 if (exists $This->{DepthLimit}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
428 if (($This->{VerticesDepth}{$VertexID} + 1) > $This->{DepthLimit}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
429 next NEIGHBOR;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
430 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
431 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
432 # Its an edge that makes a cycle during BFS search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
433 if ($This->{AllowVertexCycles}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
434 $This->{CycleClosureVertices}{$NeighborVertexID} = 1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
435 $UnvisitedNeighborVertexID = $NeighborVertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
436 last NEIGHBOR;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
437 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
438 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
439 return $UnvisitedNeighborVertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
440 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
441
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
442 # Get available neighbor of specified vertex during path traversal...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
443 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
444 sub _GetNeighborVertexDuringPathTraversal {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
445 my($This, $VertexID) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
446 my($NeighborVertexID, $UnvisitedNeighborVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
447
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
448 # Get unvisited neighbor...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
449 $UnvisitedNeighborVertexID = undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
450 NEIGHBOR: for $NeighborVertexID (@{$This->{VerticesNeighbors}{$VertexID}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
451 if (!exists $This->{VisitedVertices}{$NeighborVertexID}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
452 # An unvisited vertex...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
453 $UnvisitedNeighborVertexID = $NeighborVertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
454 last NEIGHBOR;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
455 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
456 # Look for any unvisited edge back to visited vertex...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
457 if ($This->_IsVisitedEdge($VertexID, $NeighborVertexID) || $This->_IsVisitedEdge($NeighborVertexID, $VertexID)) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
458 next NEIGHBOR;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
459 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
460 # Check its depth...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
461 if (exists $This->{DepthLimit}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
462 if (($This->{VerticesDepth}{$VertexID} + 1) >= $This->{DepthLimit}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
463 next NEIGHBOR;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
464 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
465 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
466
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
467 # It's the edge final edge of a cycle in case $NeighborVertexID is already in the path; otherwise, it's
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
468 # part of the path from a different direction in a cycle or a left over vertex during Limit search.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
469 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
470 if ($This->_IsCycleClosureEdge($VertexID, $NeighborVertexID)) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
471 if ($This->{AllowPathCycles}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
472 $This->{CycleClosureVertices}{$NeighborVertexID} = 1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
473 $UnvisitedNeighborVertexID = $NeighborVertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
474 last NEIGHBOR;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
475 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
476 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
477 else {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
478 $UnvisitedNeighborVertexID = $NeighborVertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
479 last NEIGHBOR;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
480 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
481 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
482 return $UnvisitedNeighborVertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
483 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
484
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
485 # Process visited vertex...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
486 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
487 sub _ProcessVisitedVertex {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
488 my($This, $VertexID, $PredecessorVertexID) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
489
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
490 if (!exists $This->{VisitedVertices}{$VertexID}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
491 # Add it to active vertices list...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
492 push @{$This->{ActiveVertices}}, $VertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
493
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
494 # Mark vertex as visited vertex and take it out from the list of vertices to visit...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
495 $This->{VisitedVertices}{$VertexID} = 1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
496 delete $This->{VerticesToVisit}{$VertexID};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
497 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
498
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
499 # Set up root vertex, predecessor vertex and distance from root...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
500 if ($VertexID == $PredecessorVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
501 $This->{VerticesRoots}{$VertexID} = $VertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
502
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
503 $This->{VerticesPredecessors}{$VertexID} = $VertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
504 if (!exists $This->{VerticesSuccessors}{$VertexID}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
505 @{$This->{VerticesSuccessors}{$VertexID}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
506 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
507
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
508 $This->{VerticesDepth}{$VertexID} = 0;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
509
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
510 if ($This->{TraversalMode} =~ /^Path$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
511 $This->_ProcessVisitedPath($VertexID, $PredecessorVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
512 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
513 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
514 else {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
515 $This->{VerticesRoots}{$VertexID} = $This->{VerticesRoots}{$PredecessorVertexID};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
516
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
517 $This->{VerticesPredecessors}{$VertexID} = $PredecessorVertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
518 if (!exists $This->{VerticesSuccessors}{$PredecessorVertexID}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
519 @{$This->{VerticesSuccessors}{$PredecessorVertexID}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
520 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
521 push @{$This->{VerticesSuccessors}{$PredecessorVertexID}}, $VertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
522
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
523 if (!exists $This->{VerticesDepth}{$VertexID}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
524 $This->{VerticesDepth}{$VertexID} = $This->{VerticesDepth}{$PredecessorVertexID} + 1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
525 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
526
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
527 if ($This->{TraversalMode} =~ /^Path$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
528 $This->_ProcessVisitedPath($VertexID, $PredecessorVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
529 $This->_ProcessVisitedEdge($PredecessorVertexID, $VertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
530 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
531 elsif ($This->{TraversalMode} =~ /^VertexNeighborhood$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
532 $This->_ProcessVisitedEdge($PredecessorVertexID, $VertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
533 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
534 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
535 return $This;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
536 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
537
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
538 # Process visited path...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
539 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
540 sub _ProcessVisitedPath {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
541 my($This, $VertexID, $PredecessorVertexID) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
542
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
543 # Initialize VerticesPath...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
544 if (!exists $This->{VerticesPaths}{$VertexID}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
545 @{$This->{VerticesPaths}{$VertexID}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
546 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
547
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
548 if ($VertexID == $PredecessorVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
549 # Starting of a path from root...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
550 push @{$This->{VerticesPaths}{$VertexID}}, $VertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
551 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
552 else {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
553 # Setup path for a vertex using path information from predecessor vertex...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
554 if (exists $This->{CycleClosureVertices}{$PredecessorVertexID}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
555 # Start of a new path from predecessor vertex...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
556 push @{$This->{VerticesPaths}{$VertexID}}, "${PredecessorVertexID}-${VertexID}";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
557 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
558 else {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
559 my($PredecessorVertexPath);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
560 for $PredecessorVertexPath (@{$This->{VerticesPaths}{$PredecessorVertexID}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
561 push @{$This->{VerticesPaths}{$VertexID}}, "${PredecessorVertexPath}-${VertexID}";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
562 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
563 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
564 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
565 return $This;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
566 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
567
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
568 # Process visited edge...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
569 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
570 sub _ProcessVisitedEdge {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
571 my($This, $VertexID1, $VertexID2) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
572
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
573 if (!exists $This->{VisitedEdges}->{From}->{$VertexID1}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
574 %{$This->{VisitedEdges}->{From}->{$VertexID1}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
575 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
576 $This->{VisitedEdges}->{From}->{$VertexID1}->{$VertexID2} = $VertexID2;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
577
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
578 if (!exists $This->{VisitedEdges}->{To}->{$VertexID2}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
579 %{$This->{VisitedEdges}->{To}->{$VertexID2}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
580 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
581 $This->{VisitedEdges}->{To}->{$VertexID2}->{$VertexID1} = $VertexID1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
582
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
583 return $This;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
584 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
585
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
586 # Finished processing active vertex...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
587 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
588 sub _ProcessFinishedVertex {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
589 my($This, $VertexID) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
590
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
591 if (!exists $This->{FinishedVertices}{$VertexID}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
592 $This->{FinishedVertices}{$VertexID} = $VertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
593 # Add vertex to list of vertices found by traversal...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
594 push @{$This->{Vertices}}, $VertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
595 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
596
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
597 # Any active vertices left...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
598 if (!@{$This->{ActiveVertices}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
599 return $This;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
600 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
601
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
602 # Take it off active vertices list...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
603 if ($This->{TraversalType} =~ /^(DFS|DFSWithLimit)$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
604 # For DFS, it's last vertex in LIFO queue...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
605 pop @{$This->{ActiveVertices}};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
606 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
607 elsif ($This->{TraversalType} =~ /^(BFS|BFSWithLimit)$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
608 # For BFS, it's first vertex in FIFO queue...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
609 shift @{$This->{ActiveVertices}};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
610 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
611 return $This;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
612 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
613
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
614 # Mark all other downstream neighbor vertices to be ignored from any further
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
615 # processing...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
616 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
617 sub _IgnoreDownstreamNeighbors {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
618 my($This, $VertexID, $PredecessorVertexID) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
619
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
620 if (exists $This->{VerticesToVisit}{$VertexID}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
621 # Mark vertex as visited vertex and take it out from the list of vertices to visit...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
622 $This->{VisitedVertices}{$VertexID} = 1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
623 delete $This->{VerticesToVisit}{$VertexID};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
624
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
625 if (defined($PredecessorVertexID) && $This->{TraversalMode} =~ /^(Path|VertexNeighborhood)$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
626 $This->_ProcessVisitedEdge($VertexID, $PredecessorVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
627 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
628 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
629 my($NeighborVertexID, @NeighborsVertexIDs);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
630
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
631 @NeighborsVertexIDs = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
632 @NeighborsVertexIDs = $This->{Graph}->GetNeighbors($VertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
633 NEIGHBOR: for $NeighborVertexID (@NeighborsVertexIDs) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
634 if (!exists $This->{VerticesToVisit}{$NeighborVertexID}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
635 # Avoid going back to predecessor vertex which has already been ignored...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
636 next NEIGHBOR;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
637 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
638 $This->_IgnoreDownstreamNeighbors($NeighborVertexID, $VertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
639 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
640 return $This;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
641 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
642
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
643 # Is it a visited edge?
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
644 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
645 sub _IsVisitedEdge {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
646 my($This, $VertexID1, $VertexID2) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
647
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
648 if (exists $This->{VisitedEdges}->{From}->{$VertexID1}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
649 if (exists $This->{VisitedEdges}->{From}->{$VertexID1}->{$VertexID2}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
650 return 1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
651 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
652 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
653 elsif (exists $This->{VisitedEdges}->{To}->{$VertexID2}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
654 if (exists $This->{VisitedEdges}->{To}->{$VertexID2}->{$VertexID1}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
655 return 1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
656 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
657 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
658 return 0;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
659 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
660
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
661 # Is it a cycle closure edge?
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
662 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
663 # Notes:
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
664 # . Presence of VertexID2 in DFS path traversed for VertexID1 make it a cycle
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
665 # closure edge...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
666 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
667 sub _IsCycleClosureEdge {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
668 my($This, $VertexID1, $VertexID2) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
669
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
670 if (!exists $This->{VerticesPaths}{$VertexID1}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
671 return 0;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
672 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
673 my($Path);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
674 for $Path (@{$This->{VerticesPaths}{$VertexID1}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
675 if (($Path =~ /-$VertexID2-/ || $Path =~ /^$VertexID2-/ || $Path =~ /-$VertexID2$/)) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
676 return 1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
677 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
678 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
679 return 0;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
680 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
681
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
682 # Search paths starting from a specified vertex with no sharing of edges in paths traversed.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
683 # By default, cycles are included in paths. A path containing a cycle is terminated at a vertex
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
684 # completing the cycle.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
685 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
686 sub PerformPathsSearch {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
687 my($This, $StartVertexID, $AllowCycles) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
688
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
689 # Make sure start vertex is defined...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
690 if (!defined $StartVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
691 carp "Warning: ${ClassName}->PerformPathsSearch: No paths search performed: Start vertex must be specified...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
692 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
693 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
694
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
695 # Make sure start vertex is valid...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
696 if (!$This->{Graph}->HasVertex($StartVertexID)) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
697 carp "Warning: ${ClassName}->PerformPathsSearch: No paths search performed: Vertex $StartVertexID doesn't exist...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
698 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
699 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
700
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
701 if (!defined $AllowCycles) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
702 $AllowCycles = 1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
703 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
704
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
705 # Perform paths search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
706 return $This->_PerformPathsSearch("AllLengths", $StartVertexID, $AllowCycles);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
707 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
708
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
709 # Search paths starting from a specified vertex with length upto a specified length
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
710 # with no sharing of edges in paths traversed...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
711 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
712 # By default, cycles are included in paths. A path containing a cycle is terminated at a vertex
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
713 # completing the cycle.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
714 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
715 sub PerformPathsSearchWithLengthUpto {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
716 my($This, $StartVertexID, $Length, $AllowCycles) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
717
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
718 return $This->_PerformPathsSearchWithLength("LengthUpto", $StartVertexID, $Length, $AllowCycles);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
719 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
720
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
721 # Search paths starting from a specified vertex with specified length
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
722 # with no sharing of edges in paths traversed...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
723 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
724 # By default, cycles are included in paths. A path containing a cycle is terminated at a vertex
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
725 # completing the cycle.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
726 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
727 sub PerformPathsSearchWithLength {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
728 my($This, $StartVertexID, $Length, $AllowCycles) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
729
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
730 return $This->_PerformPathsSearchWithLength("Length", $StartVertexID, $Length, $AllowCycles);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
731 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
732
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
733
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
734 # Search paths starting from a specified vertex with length upto a specified length
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
735 # with no sharing of edges in paths traversed...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
736 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
737 # By default, cycles are included in paths. A path containing a cycle is terminated at a vertex
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
738 # completing the cycle.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
739 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
740 sub _PerformPathsSearchWithLength {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
741 my($This, $Mode, $StartVertexID, $Length, $AllowCycles) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
742
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
743 # Make sure both start vertex and length are defined...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
744 if (!defined $StartVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
745 carp "Warning: ${ClassName}->_PerformPathsSearchWithLength: No paths search performed: Start vertex must be specified...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
746 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
747 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
748 if (!defined $Length) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
749 carp "Warning: ${ClassName}->_PerformPathsSearchWithLength: No paths search performed: Length must be specified...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
750 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
751 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
752
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
753 if (!defined $AllowCycles) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
754 $AllowCycles = 1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
755 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
756
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
757 # Make sure both start vertex and length are valid...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
758 if (!$This->{Graph}->HasVertex($StartVertexID)) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
759 carp "Warning: ${ClassName}->_PerformPathsSearchWithLength: No paths search performed: Vertex $StartVertexID doesn't exist...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
760 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
761 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
762
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
763 if ($Length < 1) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
764 carp "Warning: ${ClassName}->_PerformPathsSearchWithLength: No paths search performed: Specified length, $Length, must be a positive integer with value greater than 1...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
765 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
766 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
767
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
768 # Perform paths search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
769 return $This->_PerformPathsSearch($Mode, $StartVertexID, $AllowCycles, $Length);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
770 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
771
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
772 # Search all paths starting from a specified vertex with sharing of edges in paths traversed...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
773 # By default, cycles are included in paths. A path containing a cycle is terminated at a vertex
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
774 # completing the cycle.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
775 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
776 sub PerformAllPathsSearch {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
777 my($This, $StartVertexID, $AllowCycles) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
778
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
779 # Make sure start vertex is defined...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
780 if (!defined $StartVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
781 carp "Warning: ${ClassName}->PerformAllPathsSearch: No paths search performed: Start vertex must be specified...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
782 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
783 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
784
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
785 # Make sure start vertex is valid...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
786 if (!$This->{Graph}->HasVertex($StartVertexID)) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
787 carp "Warning: ${ClassName}->PerformAllPathsSearch: No paths search performed: Vertex $StartVertexID doesn't exist...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
788 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
789 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
790
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
791 if (!defined $AllowCycles) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
792 $AllowCycles = 1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
793 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
794
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
795 # Perform paths search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
796 return $This->_PerformAllPathsSearch("AllLengths", $StartVertexID, $AllowCycles);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
797 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
798
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
799 # Search all paths starting from a specified vertex with length upto a specified length with sharing of
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
800 # edges in paths traversed.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
801 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
802 # By default, cycles are included in paths. A path containing a cycle is terminated at a vertex
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
803 # completing the cycle.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
804 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
805 sub PerformAllPathsSearchWithLengthUpto {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
806 my($This, $StartVertexID, $Length, $AllowCycles) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
807
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
808 return $This->_PerformAllPathsSearchWithLength("LengthUpto", $StartVertexID, $Length, $AllowCycles);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
809 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
810
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
811 # Search all paths starting from a specified vertex with specified length with sharing of
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
812 # edges in paths traversed.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
813 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
814 # By default, cycles are included in paths. A path containing a cycle is terminated at a vertex
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
815 # completing the cycle.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
816 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
817 sub PerformAllPathsSearchWithLength {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
818 my($This, $StartVertexID, $Length, $AllowCycles) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
819
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
820 return $This->_PerformAllPathsSearchWithLength("Length", $StartVertexID, $Length, $AllowCycles);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
821 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
822
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
823 # Search all paths starting from a specified vertex with length upto a specified length with sharing of
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
824 # edges in paths traversed.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
825 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
826 # By default, cycles are included in paths. A path containing a cycle is terminated at a vertex
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
827 # completing the cycle.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
828 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
829 sub _PerformAllPathsSearchWithLength {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
830 my($This, $Mode, $StartVertexID, $Length, $AllowCycles) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
831
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
832 # Make sure both start vertex and length are defined...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
833 if (!defined $StartVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
834 carp "Warning: ${ClassName}->_PerformAllPathsSearchWithLength: No paths search performed: Start vertex must be specified...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
835 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
836 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
837 if (!defined $Length) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
838 carp "Warning: ${ClassName}->_PerformAllPathsSearchWithLength: No paths search performed: Length must be specified...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
839 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
840 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
841
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
842 if (!defined $AllowCycles) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
843 $AllowCycles = 1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
844 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
845
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
846 # Make sure both start vertex and length are valid...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
847 if (!$This->{Graph}->HasVertex($StartVertexID)) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
848 carp "Warning: ${ClassName}->_PerformAllPathsSearchWithLength: No paths search performed: Vertex $StartVertexID doesn't exist...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
849 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
850 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
851
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
852 if ($Length < 1) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
853 carp "Warning: ${ClassName}->_PerformAllPathsSearchWithLength: No paths search performed: Specified length, $Length, must be a positive integer with value greater than 1...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
854 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
855 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
856
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
857 # Perform paths search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
858 return $This->_PerformAllPathsSearch($Mode, $StartVertexID, $AllowCycles, $Length);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
859 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
860
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
861 # Search paths between two vertices...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
862 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
863 sub PerformPathsSearchBetween {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
864 my($This, $StartVertexID, $EndVertexID) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
865
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
866 # Make sure start and end vertices are defined...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
867 if (!defined $StartVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
868 carp "Warning: ${ClassName}->PerformPathsSearchBetweeb: No paths search performed: Start vertex must be specified...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
869 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
870 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
871 if (!defined $EndVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
872 carp "Warning: ${ClassName}->PerformPathsSearchBetweeb: No paths search performed: EndVertex vertex must be specified...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
873 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
874 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
875 # Make sure start and end vertices are valid...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
876 if (!$This->{Graph}->HasVertex($StartVertexID)) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
877 carp "Warning: ${ClassName}->PerformPathsSearchBetween: No paths search performed: Vertex $StartVertexID doesn't exist...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
878 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
879 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
880 if (!$This->{Graph}->HasVertex($EndVertexID)) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
881 carp "Warning: ${ClassName}->PerformPathsSearchBetween: No paths search performed: Vertex $EndVertexID doesn't exist...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
882 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
883 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
884
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
885 # Perform paths search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
886 return $This->_PerformPathsSearchBetween($StartVertexID, $EndVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
887 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
888
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
889 # Search paths starting from root vertex with no sharing of edges...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
890 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
891 # Notes:
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
892 # . Possible paths searche modes are: DFSPathsWithLimit, DFSPaths. And each
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
893 # of these modes supports any combination of two options: CommonEdges, Cycles.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
894 # Default for CommonEdges - No; Cycles - No.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
895 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
896 sub _PerformPathsSearch {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
897 my($This, $Mode, $RootVertexID, $AllowCycles, $Length) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
898
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
899 # Perform DFS path search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
900
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
901 $This->{TraversalMode} = 'Path';
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
902
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
903 if ($Mode =~ /^(LengthUpto|Length)$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
904 my($DepthLimit);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
905
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
906 $DepthLimit = $Length - 1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
907 $This->{TraversalType} = 'DFSWithLimit';
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
908 $This->{DepthLimit} = $DepthLimit;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
909 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
910 else {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
911 $This->{TraversalType} = 'DFS';
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
912 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
913 if (defined $RootVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
914 $This->{RootVertex} = $RootVertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
915 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
916
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
917 $This->{AllowPathCycles} = $AllowCycles;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
918
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
919 # Perform search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
920 $This->_TraverseGraph();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
921
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
922 # Make sure traversal did get the root vertex...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
923 if (!exists $This->{VerticesDepth}{$RootVertexID}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
924 return $This;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
925 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
926 if ($Mode =~ /^Length$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
927 push @{$This->{Paths}}, $This->_CollectPathsTraversedDuringPathsSearchWithLength($Length);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
928 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
929 else {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
930 push @{$This->{Paths}}, $This->_CollectPathsTraversedDuringPathsSearch();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
931 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
932
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
933 return $This;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
934 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
935
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
936 # Search all paths starting from root vertex with sharing of edges...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
937 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
938 sub _PerformAllPathsSearch {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
939 my($This, $Mode, $RootVertexID, $AllowCycles, $Length) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
940
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
941 # Perform DFS path search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
942
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
943 $This->{TraversalMode} = 'AllPaths';
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
944
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
945 if ($Mode =~ /^(LengthUpto|Length)$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
946 my($DepthLimit);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
947
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
948 $DepthLimit = $Length - 1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
949 $This->{TraversalType} = 'DFSWithLimit';
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
950 $This->{DepthLimit} = $DepthLimit;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
951 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
952 else {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
953 $This->{TraversalType} = 'DFS';
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
954 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
955 $This->{RootVertex} = $RootVertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
956 $This->{AllowPathCycles} = $AllowCycles;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
957
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
958 # Traverse all paths search using DFS search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
959 $This->_TraverseAllPathsInGraph($Mode, $Length);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
960
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
961 return $This;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
962 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
963
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
964 # Travese all paths in graph starting from a specified root vertex...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
965 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
966 sub _TraverseAllPathsInGraph {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
967 my($This, $Mode, $Length) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
968
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
969 if ($This->{TraversalMode} !~ /^AllPaths$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
970 return $This;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
971 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
972 my($CurrentVertexID, $PredecessorVertexID, $CurrentDepth, $CurrentPath);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
973
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
974 $CurrentVertexID = $This->{RootVertex};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
975 $PredecessorVertexID = $CurrentVertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
976 $CurrentDepth = 0;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
977 $CurrentPath = "$CurrentVertexID";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
978
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
979 $This->_TraverseAllPaths($CurrentVertexID, $PredecessorVertexID, $CurrentDepth, $CurrentPath);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
980
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
981 if ($Mode =~ /^Length$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
982 push @{$This->{Paths}}, $This->_CollectPathsTraversedDuringPathsSearchWithLength($Length);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
983 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
984 else {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
985 push @{$This->{Paths}}, $This->_CollectPathsTraversedDuringPathsSearch();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
986 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
987
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
988 return $This;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
989 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
990
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
991 # Traverse and collect all paths recuresively..
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
992 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
993 sub _TraverseAllPaths {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
994 my($This, $CurrentVertexID, $PredecessorVertexID, $CurrentDepth, $CurrentPath) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
995
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
996 # Save path traversed for current vertex..
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
997 if (!exists $This->{VerticesPaths}{$CurrentVertexID}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
998 @{$This->{VerticesPaths}{$CurrentVertexID}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
999 $This->{VerticesDepth}{$CurrentVertexID} = 0;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1000 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1001 push @{$This->{VerticesPaths}{$CurrentVertexID}}, $CurrentPath;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1002 $This->{VerticesDepth}{$CurrentVertexID} = $CurrentDepth;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1003
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1004 $CurrentDepth++;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1005 if (exists $This->{DepthLimit}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1006 if ($CurrentDepth > $This->{DepthLimit}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1007 # Nothing more to do...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1008 return $This;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1009 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1010 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1011 my($NeighborVertexID, $NewPath);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1012
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1013 NEIGHBOR: for $NeighborVertexID ($This->{Graph}->GetNeighbors($CurrentVertexID)) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1014 if ($NeighborVertexID == $PredecessorVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1015 next NEIGHBOR;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1016 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1017 if ($This->_IsVertexInTraversedPath($NeighborVertexID, $CurrentPath)) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1018 # It's a cycle...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1019 if ($This->{AllowPathCycles}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1020 $NewPath = "${CurrentPath}-${NeighborVertexID}";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1021 if (!exists $This->{VerticesPaths}{$NeighborVertexID}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1022 @{$This->{VerticesPaths}{$NeighborVertexID}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1023 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1024 push @{$This->{VerticesPaths}{$NeighborVertexID}}, $NewPath;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1025 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1026 next NEIGHBOR;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1027 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1028 $NewPath = "${CurrentPath}-${NeighborVertexID}";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1029 $This->_TraverseAllPaths($NeighborVertexID, $CurrentVertexID, $CurrentDepth, $NewPath);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1030 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1031 return $This;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1032 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1033
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1034 # Is vertex already in traversed path?
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1035 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1036 sub _IsVertexInTraversedPath {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1037 my($This, $VertexID, $Path) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1038
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1039 return ($Path =~ /-$VertexID-/ || $Path =~ /^$VertexID-/ || $Path =~ /-$VertexID$/) ? 1 : 0;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1040 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1041
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1042 # Collect all paths traversed during Path TraversalMode and sort 'em in
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1043 # ascending order of lengths
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1044 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1045 sub _CollectPathsTraversedDuringPathsSearch {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1046 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1047 my($VertexID, @Paths, @SortedPaths);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1048
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1049 @Paths = (); @SortedPaths = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1050
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1051 # Create path objects from path vertex strings...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1052 for $VertexID (keys %{$This->{VerticesPaths}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1053 push @Paths, map { new Graph::Path(split /-/, $_) } @{$This->{VerticesPaths}{$VertexID}};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1054 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1055
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1056 # Sort paths in ascending order of lengths...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1057 push @SortedPaths, sort { $a->GetLength() <=> $b->GetLength() } @Paths;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1058
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1059 return @SortedPaths;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1060 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1061
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1062 # Collect paths traversed during Path TraversalMode with specific length...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1063 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1064 sub _CollectPathsTraversedDuringPathsSearchWithLength {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1065 my($This, $Length) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1066 my($VertexID, $Depth, $PathString, @VertexIDs, @Paths);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1067
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1068 @Paths = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1069 $Depth = $Length - 1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1070
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1071 # Create path objects from path vertex strings...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1072 VERTEXID: for $VertexID (keys %{$This->{VerticesPaths}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1073 if ($This->{VerticesDepth}{$VertexID} != $Depth) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1074 next VERTEXID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1075 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1076 # For vertices involved in cycles, the path might also contain some shorter paths. So check
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1077 # the lengths before its collection...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1078 PATHSTRING: for $PathString (@{$This->{VerticesPaths}{$VertexID}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1079 @VertexIDs = split /-/, $PathString;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1080 if ($Length != @VertexIDs) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1081 next PATHSTRING;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1082 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1083 push @Paths, new Graph::Path(@VertexIDs);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1084 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1085 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1086 return @Paths;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1087 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1088
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1089 # Collect paths traversed during Vertex TraversalMode...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1090 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1091 sub _CollectPathsTraversedDuringVertexSearch {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1092 my($This, $RootVertexID) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1093 my($Depth, @Paths, @VerticesAtDepth);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1094 @Paths = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1095
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1096 # Get vertices at specific depths...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1097 @VerticesAtDepth = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1098 @VerticesAtDepth = $This->_CollectVerticesAtSpecificDepths();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1099 if (!@VerticesAtDepth) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1100 return @Paths;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1101 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1102
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1103 # Make sure search found only one root vertex and it corresponds to
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1104 # what was specified...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1105 $Depth = 0;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1106 if ((@{$VerticesAtDepth[$Depth]} > 1) || ($VerticesAtDepth[$Depth][0] != $RootVertexID)) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1107 carp "Warning: ${ClassName}->_PerformPathsSearch: No paths found: Root vertex, $VerticesAtDepth[$Depth][0], identified by paths traversal doen't match specified root vertex $RootVertexID...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1108 return @Paths;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1109 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1110
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1111 # Setup root vertex at depth 0. And set its path...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1112 my($Path, $VertexID, $SuccessorVertexID, @VertexIDs, %PathAtVertex);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1113 %PathAtVertex = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1114 $PathAtVertex{$RootVertexID} = new Graph::Path($RootVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1115
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1116 for $Depth (0 .. $#VerticesAtDepth) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1117 # Go over all vertices at current depth...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1118 VERTEX: for $VertexID (@{$VerticesAtDepth[$Depth]}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1119 if (!exists $This->{VerticesSuccessors}{$VertexID}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1120 next VERTEX;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1121 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1122 # Get vertices for current path...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1123 @VertexIDs = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1124 push @VertexIDs, $PathAtVertex{$VertexID}->GetVertices;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1125
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1126 # Expand path to successor vertex found during traversal...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1127 for $SuccessorVertexID (@{$This->{VerticesSuccessors}{$VertexID}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1128 $Path = new Graph::Path(@VertexIDs);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1129 $Path->AddVertex($SuccessorVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1130 $PathAtVertex{$SuccessorVertexID} = $Path;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1131 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1132 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1133 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1134 # Sort paths in ascending order of lengths...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1135 push @Paths, sort { $a->GetLength() <=> $b->GetLength() } values %PathAtVertex;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1136
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1137 return @Paths;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1138 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1139
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1140 # Collect vertices at specific depths. Depth values start from 0...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1141 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1142 sub _CollectVerticesAtSpecificDepths {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1143 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1144 my($VertexID, $Depth, @VerticesAtDepth);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1145
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1146 @VerticesAtDepth = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1147 while (($VertexID, $Depth) = each %{$This->{VerticesDepth}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1148 push @{$VerticesAtDepth[$Depth]}, $VertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1149 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1150 return @VerticesAtDepth;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1151 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1152
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1153 # Collect vertices, along with their successors, at specific depths and return a list containing references to
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1154 # lists with first value corresponding to vertex ID and second value a reference to a list containing
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1155 # its successors.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1156 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1157 # Depth values start from 0...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1158 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1159 sub _CollectVerticesWithSuccessorsAtSpecificDepths {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1160 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1161 my($VertexID, $Depth, @VerticesWithSuccessorsAtDepth);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1162
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1163 @VerticesWithSuccessorsAtDepth = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1164 while (($VertexID, $Depth) = each %{$This->{VerticesDepth}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1165 my(@VertexWithSuccessors, @VertexSuccessors);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1166
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1167 @VertexWithSuccessors = (); @VertexSuccessors = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1168 if (exists $This->{VerticesSuccessors}{$VertexID}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1169 push @VertexSuccessors, @{$This->{VerticesSuccessors}{$VertexID}};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1170 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1171 push @VertexWithSuccessors, ($VertexID, \@VertexSuccessors);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1172 # Multiple entries for a vertex and its successors could be present at a specific depth...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1173 push @{$VerticesWithSuccessorsAtDepth[$Depth]}, \@VertexWithSuccessors;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1174 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1175 return @VerticesWithSuccessorsAtDepth;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1176 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1177
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1178 # Search paths between two vertices...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1179 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1180 sub _PerformPathsSearchBetween {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1181 my($This, $RootVertexID, $TargetVertexID) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1182 my($DepthLimit);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1183
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1184 # Perform a targeted DFS search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1185 $DepthLimit = undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1186 $This->_PerformVertexSearch("DFS", $RootVertexID, $DepthLimit, $TargetVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1187
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1188 my($Path);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1189 $Path = $This->_CollectPathBetween($RootVertexID, $TargetVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1190
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1191 if (defined $Path) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1192 push @{$This->{Paths}}, $Path;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1193 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1194 return $This;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1195 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1196
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1197 # Collect path between root and target vertex after the search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1198 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1199 sub _CollectPathBetween {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1200 my($This, $RootVertexID, $TargetVertexID) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1201
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1202 # Does a path from root to target vertex exist?
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1203 if (!(exists($This->{VerticesRoots}{$TargetVertexID}) && ($This->{VerticesRoots}{$TargetVertexID} == $RootVertexID))) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1204 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1205 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1206
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1207 # Add target vertex ID path vertices...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1208 my($VertexID, $Path, @VertexIDs);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1209 @VertexIDs = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1210 $VertexID = $TargetVertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1211 push @VertexIDs, $VertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1212
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1213 # Backtrack to root vertex ID...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1214 while ($This->{VerticesPredecessors}{$VertexID} != $VertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1215 $VertexID = $This->{VerticesPredecessors}{$VertexID};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1216 push @VertexIDs, $VertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1217 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1218
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1219 # Create path from target to root and reverse it...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1220 $Path = new Graph::Path(@VertexIDs);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1221 $Path->Reverse();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1222
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1223 return $Path;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1224 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1225
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1226 # Search vertices around specified root vertex with in specific neighborhood radius...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1227 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1228 sub PerformNeighborhoodVerticesSearchWithRadiusUpto {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1229 my($This, $StartVertexID, $Radius) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1230
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1231 # Make sure both start vertex and radius are defined...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1232 if (!defined $StartVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1233 carp "Warning: ${ClassName}->PerformNeighborhoodVerticesSearchWithRadiusUpto: No vertices search performed: Start vertex must be specified...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1234 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1235 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1236 if (!defined $Radius) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1237 carp "Warning: ${ClassName}->PerformNeighborhoodVerticesSearchWithRadiusUpto: No vertices search performed: Radius must be specified...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1238 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1239 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1240
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1241 # Make sure both start vertex and length are valid...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1242 if (!$This->{Graph}->HasVertex($StartVertexID)) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1243 carp "Warning: ${ClassName}->PerformNeighborhoodVerticesSearchWithRadiusUpto: No vertices search performed: Vertex $StartVertexID doesn't exist...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1244 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1245 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1246 if ($Radius < 0) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1247 carp "Warning: ${ClassName}->PerformNeighborhoodVerticesSearchWithRadiusUpto: No vertices search performed: Specified radius, $Radius, must be a positive integer...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1248 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1249 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1250
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1251 # Perform vertices search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1252 return $This->_PerformNeighborhoodVerticesSearch("RadiusUpto", $StartVertexID, $Radius);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1253 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1254
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1255 # Search vertices around specified root vertex...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1256 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1257 sub PerformNeighborhoodVerticesSearch {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1258 my($This, $StartVertexID) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1259
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1260 # Make sure start vertex is defined...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1261 if (!defined $StartVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1262 carp "Warning: ${ClassName}->PerformNeighborhoodVerticesSearch: No vertices search performed: Start vertex must be specified...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1263 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1264 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1265
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1266 # Make sure start vertex is valid...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1267 if (!$This->{Graph}->HasVertex($StartVertexID)) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1268 carp "Warning: ${ClassName}->PerformNeighborhoodVerticesSearch: No vertices search performed: Vertex $StartVertexID doesn't exist...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1269 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1270 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1271 # Perform vertices search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1272 return $This->_PerformNeighborhoodVerticesSearch("AllRadii", $StartVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1273 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1274
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1275 # Search vertices around specified root vertex with in specific neighborhood radius along with
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1276 # identification of successors of each vertex found during the search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1277 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1278 sub PerformNeighborhoodVerticesSearchWithSuccessorsAndRadiusUpto {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1279 my($This, $StartVertexID, $Radius) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1280
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1281 # Make sure both start vertex and radius are defined...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1282 if (!defined $StartVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1283 carp "Warning: ${ClassName}->PerformNeighborhoodVerticesSearchWithSuccessorsAndRadiusUpto: No vertices search performed: Start vertex must be specified...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1284 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1285 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1286 if (!defined $Radius) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1287 carp "Warning: ${ClassName}->PerformNeighborhoodVerticesSearchWithSuccessorsAndRadiusUpto: No vertices search performed: Radius must be specified...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1288 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1289 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1290
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1291 # Make sure both start vertex and length are valid...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1292 if (!$This->{Graph}->HasVertex($StartVertexID)) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1293 carp "Warning: ${ClassName}->PerformNeighborhoodVerticesSearchWithSuccessorsAndRadiusUpto: No vertices search performed: Vertex $StartVertexID doesn't exist...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1294 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1295 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1296 if ($Radius < 0) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1297 carp "Warning: ${ClassName}->PerformNeighborhoodVerticesSearchWithSuccessorsAndRadiusUpto: No vertices search performed: Specified radius, $Radius, must be a positive integer...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1298 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1299 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1300
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1301 # Perform vertices search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1302 return $This->_PerformNeighborhoodVerticesSearch("WithSuccessorsAndRadiusUpto", $StartVertexID, $Radius);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1303 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1304
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1305 # Search vertices around specified root vertex along with identification of
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1306 # successors of each vertex found during the search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1307 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1308 sub PerformNeighborhoodVerticesSearchWithSuccessors {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1309 my($This, $StartVertexID) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1310
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1311 # Make sure start vertex is defined...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1312 if (!defined $StartVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1313 carp "Warning: ${ClassName}->PerformNeighborhoodVerticesSearchWithSuccessors: No vertices search performed: Start vertex must be specified...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1314 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1315 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1316
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1317 # Make sure start vertex is valid...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1318 if (!$This->{Graph}->HasVertex($StartVertexID)) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1319 carp "Warning: ${ClassName}->PerformNeighborhoodVerticesSearchWithSuccessors: No vertices search performed: Vertex $StartVertexID doesn't exist...";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1320 return undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1321 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1322 # Perform vertices search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1323 return $This->_PerformNeighborhoodVerticesSearch("WithSuccessorsAndAllRadii", $StartVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1324 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1325
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1326 # Search vertices at successive neighborhood radii levels...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1327 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1328 sub _PerformNeighborhoodVerticesSearch {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1329 my($This, $Mode, $RootVertexID, $Radius) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1330 my($DepthLimit, $AllowCycles);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1331
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1332 $DepthLimit = defined $Radius ? $Radius : undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1333 $AllowCycles = undef;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1334
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1335 # Perform BFS search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1336 if ($Mode =~ /^RadiusUpto$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1337 $This->_PerformVertexNeighborhoodSearch("BFSWithLimit", $RootVertexID, $DepthLimit);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1338 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1339 elsif ($Mode =~ /^(AllRadii)$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1340 $This->_PerformVertexNeighborhoodSearch("BFS", $RootVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1341 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1342 elsif ($Mode =~ /^WithSuccessorsAndRadiusUpto$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1343 $AllowCycles = 1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1344 $This->_PerformVertexNeighborhoodSearch("BFSWithLimit", $RootVertexID, $DepthLimit, $AllowCycles);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1345 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1346 elsif ($Mode =~ /^WithSuccessorsAndAllRadii$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1347 $AllowCycles = 1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1348 $This->_PerformVertexNeighborhoodSearch("BFSWithLimit", $RootVertexID, $DepthLimit, $AllowCycles);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1349 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1350
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1351 # Make sure traversal did get the root vertex...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1352 if (!exists $This->{VerticesDepth}{$RootVertexID}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1353 return $This;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1354 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1355
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1356 if ($Mode =~ /^(RadiusUpto|AllRadii)$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1357 push @{$This->{VerticesNeighborhoods}}, $This->_CollectVerticesAtSpecificDepths();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1358 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1359 elsif ($Mode =~ /^(WithSuccessorsAndRadiusUpto|WithSuccessorsAndAllRadii)$/i) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1360 push @{$This->{VerticesNeighborhoodsWithSuccessors}}, $This->_CollectVerticesWithSuccessorsAtSpecificDepths();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1361 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1362
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1363 return $This;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1364 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1365
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1366 # Perform appropriate vertex search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1367 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1368 sub _PerformVertexNeighborhoodSearch {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1369 my($This, $SearchType, $RootVertexID, $DepthLimit, $AllowCycles) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1370
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1371 # Setup search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1372 $This->{TraversalMode} = 'VertexNeighborhood';
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1373 $This->{TraversalType} = $SearchType;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1374
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1375 if (defined $RootVertexID) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1376 $This->{RootVertex} = $RootVertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1377 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1378 if (defined $DepthLimit) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1379 $This->{DepthLimit} = $DepthLimit;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1380 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1381 if (defined $AllowCycles) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1382 $This->{AllowVertexCycles} = $AllowCycles;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1383 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1384
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1385 # Perform search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1386 return $This->_TraverseGraph();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1387 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1388
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1389 # Get orderded list of vertices after DFS/BFS search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1390 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1391 sub GetVertices {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1392 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1393
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1394 return wantarray ? @{$This->{Vertices}} : scalar @{$This->{Vertices}};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1395 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1396
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1397 # Get a hash list containing vertex and root vertex as key/value pair for all vertices
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1398 # ordered using DFS/BFS search available via GetVertices method...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1399 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1400 sub GetVerticesRoots {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1401 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1402
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1403 return %{$This->{VerticesRoots}};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1404 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1405
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1406 # Get a list containing lists of vertices in connected components of graph after DFS/BFS
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1407 # search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1408 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1409 # Note:
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1410 # . List is sorted in descending order of number of vertices in each connected component.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1411 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1412 sub GetConnectedComponentsVertices {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1413 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1414 my($VertexID, $VertexRoot, @ConnectedVertices, %VerticesAtRoot);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1415
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1416 @ConnectedVertices = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1417 %VerticesAtRoot = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1418 for $VertexID (@{$This->{Vertices}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1419 $VertexRoot = $This->{VerticesRoots}{$VertexID};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1420 if (!exists $VerticesAtRoot{$VertexRoot}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1421 @{$VerticesAtRoot{$VertexRoot}} = ();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1422 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1423 push @{$VerticesAtRoot{$VertexRoot}}, $VertexID;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1424 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1425 push @ConnectedVertices, sort { @{$b} <=> @{$a} } values %VerticesAtRoot;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1426
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1427 return wantarray ? @ConnectedVertices : scalar @ConnectedVertices;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1428 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1429
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1430 # Get predecessor vertices...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1431 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1432 sub GetVerticesPredecessors {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1433 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1434
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1435 return %{$This->{VerticesPredecessors}};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1436 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1437
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1438 # Get a hash list containing vertex and depth from root vertex as key/value pair for all vertices
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1439 # ordered using DFS/BFS search available via GetVertices method...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1440 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1441 sub GetVerticesDepth {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1442 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1443
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1444 return %{$This->{VerticesDepth}};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1445 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1446
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1447 # Get paths found during paths search...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1448 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1449 sub GetPaths {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1450 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1451
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1452 return wantarray ? @{$This->{Paths}} : scalar @{$This->{Paths}};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1453 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1454
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1455 # Get vertices collected at various neighborhood radii...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1456 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1457 sub GetVerticesNeighborhoods {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1458 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1459
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1460 return wantarray ? @{$This->{VerticesNeighborhoods}} : scalar @{$This->{VerticesNeighborhoods}};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1461 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1462
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1463 # Get vertices, along with their successor vertices, collected at various neighborhood radii as
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1464 # a list containing references to lists with first value corresponding to vertex ID and second value
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1465 # a reference to a list containing its successors.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1466 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1467 sub GetVerticesNeighborhoodsWithSuccessors {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1468 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1469
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1470 return wantarray ? @{$This->{VerticesNeighborhoodsWithSuccessors}} : scalar @{$This->{VerticesNeighborhoodsWithSuccessors}};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1471 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1472
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1473 # Return a string containg data for PathsTraversal object...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1474 sub StringifyPathsTraversal {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1475 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1476 my($PathsTraversalString);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1477
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1478 $PathsTraversalString = "PathsTraversalMode: " . $This->{TraversalMode};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1479 $PathsTraversalString .= "; PathsTraversalType: " . $This->{TraversalType};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1480
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1481 # Vertices ordered by traversal...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1482 $PathsTraversalString .= "; Vertices: " . join(' ', @{$This->{Vertices}});
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1483
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1484 # Stringify depths of vertices...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1485 $PathsTraversalString .= "; " . $This->StringifyVerticesDepth();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1486
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1487 # Stringify roots of vertices...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1488 $PathsTraversalString .= "; " . $This->StringifyVerticesRoots();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1489
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1490 # Stringify predecessor of vertices...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1491 $PathsTraversalString .= "; " . $This->StringifyVerticesPredecessors();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1492
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1493 # Stringify successor vertices...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1494 $PathsTraversalString .= "; " . $This->StringifyVerticesSuccessors();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1495
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1496 # Stringify paths...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1497 $PathsTraversalString .= "; " . $This->StringifyPaths();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1498
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1499 # Stringify vertices neighborhoods...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1500 $PathsTraversalString .= "; " . $This->StringifyVerticesNeighborhoods();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1501
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1502 # Stringify vertices neighborhoods with successors...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1503 $PathsTraversalString .= "; " . $This->StringifyVerticesNeighborhoodsWithSuccessors();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1504
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1505 return $PathsTraversalString;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1506 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1507
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1508 # Stringify vertices depth...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1509 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1510 sub StringifyVerticesDepth {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1511 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1512 my($VertexID, $VertexDepth, $DepthString);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1513
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1514 if (!@{$This->{Vertices}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1515 $DepthString = "<Vertex-Depth>: None";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1516 return $DepthString;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1517 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1518
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1519 $DepthString = "<Vertex-Depth>: ";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1520 for $VertexID (@{$This->{Vertices}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1521 $VertexDepth = $This->{VerticesDepth}{$VertexID};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1522 $DepthString .= " <$VertexID-$VertexDepth>";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1523 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1524 return $DepthString;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1525 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1526
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1527 # Stringify roots of vertices...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1528 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1529 sub StringifyVerticesRoots {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1530 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1531 my($VertexID, $RootVertexID, $RootsString);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1532
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1533 if (!@{$This->{Vertices}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1534 $RootsString = "<Vertex-RootVertex>: None";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1535 return $RootsString;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1536 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1537
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1538 $RootsString = "<Vertex-RootVertex>: ";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1539 for $VertexID (@{$This->{Vertices}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1540 $RootVertexID = $This->{VerticesRoots}{$VertexID};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1541 $RootsString .= " <$VertexID-$RootVertexID>";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1542 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1543 return $RootsString;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1544 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1545
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1546 # Stringify predecessor of vertices...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1547 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1548 sub StringifyVerticesPredecessors {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1549 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1550 my($VertexID, $PredecessorVertexID, $PredecessorString);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1551
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1552 if (!@{$This->{Vertices}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1553 $PredecessorString = "<Vertex-PredecessorVertex>: None";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1554 return $PredecessorString;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1555 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1556
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1557 $PredecessorString = "<Vertex-PredecessorVertex>: ";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1558 for $VertexID (@{$This->{Vertices}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1559 $PredecessorVertexID = $This->{VerticesPredecessors}{$VertexID};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1560 $PredecessorString .= " <$VertexID-$PredecessorVertexID>";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1561 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1562 return $PredecessorString;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1563 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1564
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1565 # Stringify successor vertices...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1566 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1567 sub StringifyVerticesSuccessors {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1568 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1569 my($VertexID, $SuccessorString, $VerticesSuccessorsString);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1570
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1571 if (!@{$This->{Vertices}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1572 $SuccessorString = "<Vertex-VerticesSuccessorsList>: None";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1573 return $SuccessorString;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1574 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1575
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1576 $SuccessorString = "<Vertex-VerticesSuccessorsList>: ";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1577 for $VertexID (@{$This->{Vertices}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1578 if (exists($This->{VerticesSuccessors}{$VertexID}) && @{$This->{VerticesSuccessors}{$VertexID}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1579 $VerticesSuccessorsString = join(',', @{$This->{VerticesSuccessors}{$VertexID}});
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1580 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1581 else {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1582 $VerticesSuccessorsString = "None";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1583 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1584 $SuccessorString .= " <$VertexID-$VerticesSuccessorsString>";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1585 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1586 return $SuccessorString;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1587 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1588
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1589 # Strinigify paths...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1590 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1591 sub StringifyPaths {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1592 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1593 my($PathsString, $Path);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1594
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1595 if (!@{$This->{Paths}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1596 $PathsString = "Paths: None";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1597 return $PathsString;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1598 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1599
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1600 my($FirstPath);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1601 $PathsString = "Paths: ";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1602 $FirstPath = 1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1603 for $Path (@{$This->{Paths}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1604 if ($FirstPath) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1605 $FirstPath = 0;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1606 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1607 else {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1608 $PathsString .= " ";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1609 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1610 $PathsString .= "<" . join('-', $Path->GetVertices()) . ">";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1611 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1612 return $PathsString;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1613 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1614
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1615 # Strinigify vertices neighborhoods...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1616 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1617 sub StringifyVerticesNeighborhoods {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1618 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1619 my($NeighborhoodsString, $NeighborhoodVerticesString, $Radius);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1620
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1621 if (!@{$This->{VerticesNeighborhoods}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1622 $NeighborhoodsString = "<NeighborhoodRadius-NeighborhoodVerticesList>: None";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1623 return $NeighborhoodsString;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1624 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1625 $NeighborhoodsString = "<NeighborhoodRadius-NeighborhoodVerticesList>:";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1626 for $Radius (0 .. $#{$This->{VerticesNeighborhoods}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1627 $NeighborhoodVerticesString = join(',', @{$This->{VerticesNeighborhoods}[$Radius]});
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1628 $NeighborhoodsString .= " <$Radius-$NeighborhoodVerticesString>";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1629 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1630
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1631 return $NeighborhoodsString;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1632 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1633
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1634 # Strinigify vertices neighborhoods...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1635 #
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1636 sub StringifyVerticesNeighborhoodsWithSuccessors {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1637 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1638 my($NeighborhoodsString, $NeighborhoodVertexSuccessorsString, $Radius, $NeighborhoodVertericesWithSuccessorsRef, $NeighborhoodVertexWithSuccessorsRef, $VertexID, $NeighborhoodVertexSuccessorsRef);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1639
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1640 if (!@{$This->{VerticesNeighborhoodsWithSuccessors}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1641 $NeighborhoodsString = "<NeighborhoodRadius-NeighborhoodVertex-NeighborhoodVerticeSuccessorsList>: None";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1642 return $NeighborhoodsString;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1643 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1644 $NeighborhoodsString = "<NeighborhoodRadius-NeighborhoodVertex-NeighborhoodVerticeSuccessorsList>: None";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1645
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1646 $Radius = 0;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1647 for $NeighborhoodVertericesWithSuccessorsRef (@{$This->{VerticesNeighborhoodsWithSuccessors}}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1648 for $NeighborhoodVertexWithSuccessorsRef (@{$NeighborhoodVertericesWithSuccessorsRef}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1649 ($VertexID, $NeighborhoodVertexSuccessorsRef) = @{$NeighborhoodVertexWithSuccessorsRef};
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1650 $NeighborhoodVertexSuccessorsString = 'None';
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1651 if (@{$NeighborhoodVertexSuccessorsRef}) {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1652 $NeighborhoodVertexSuccessorsString = join(',', @{$NeighborhoodVertexSuccessorsRef});
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1653 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1654 $NeighborhoodsString .= " <$Radius-$VertexID-$NeighborhoodVertexSuccessorsString>";
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1655 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1656 $Radius++;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1657 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1658 return $NeighborhoodsString;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1659 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1660
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1661 # Return a reference to new paths traversal object...
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1662 sub Copy {
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1663 my($This) = @_;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1664 my($NewPathsTraversal);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1665
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1666 $NewPathsTraversal = Storable::dclone($This);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1667
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1668 return $NewPathsTraversal;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1669 }
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1670
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1671 1;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1672
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1673 __END__
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1674
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1675 =head1 NAME
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1676
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1677 PathsTraversal
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1678
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1679 =head1 SYNOPSIS
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1680
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1681 use Graph::PathsTraversal;
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1682
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1683 use Graph::PathsTraversal qw(:all);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1684
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1685 =head1 DESCRIPTION
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1686
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1687 B<PathsTraversal> class provides the following methods:
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1688
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1689 new, Copy, GetConnectedComponentsVertices, GetPaths, GetVertices,
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1690 GetVerticesDepth, GetVerticesNeighborhoods,
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1691 GetVerticesNeighborhoodsWithSuccessors, GetVerticesPredecessors, GetVerticesRoots,
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1692 PerformAllPathsSearch, PerformAllPathsSearchWithLength,
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1693 PerformAllPathsSearchWithLengthUpto, PerformBreadthFirstSearch,
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1694 PerformBreadthFirstSearchWithLimit, PerformDepthFirstSearch,
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1695 PerformDepthFirstSearchWithLimit, PerformNeighborhoodVerticesSearch,
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1696 PerformNeighborhoodVerticesSearchWithRadiusUpto,
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1697 PerformNeighborhoodVerticesSearchWithSuccessors,
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1698 PerformNeighborhoodVerticesSearchWithSuccessorsAndRadiusUpto, PerformPathsSearch,
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1699 PerformPathsSearchBetween, PerformPathsSearchWithLength,
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1700 PerformPathsSearchWithLengthUpto, StringifyPaths, StringifyPathsTraversal,
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1701 StringifyVerticesDepth, StringifyVerticesNeighborhoods,
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1702 StringifyVerticesNeighborhoodsWithSuccessors, StringifyVerticesPredecessors,
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1703 StringifyVerticesRoots, StringifyVerticesSuccessors
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1704
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1705 =head2 METHODS
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1706
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1707 =over 4
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1708
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1709 =item B<new>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1710
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1711 $PathsTraversal = new Graph::PathsTraversal($Graph);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1712
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1713 Using specified I<Graph>, B<new> method creates a new B<PathsTraversal> object and returns
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1714 newly created B<PathsTraversal> object.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1715
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1716 =item B<Copy>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1717
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1718 $PathsTraversal = $PathsTraversal->Copy();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1719
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1720 Copies I<PathsTraversal> and its associated data using B<Storable::dclone> and returns a new
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1721 B<PathsTraversal> object.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1722
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1723 =item B<GetConnectedComponentsVertices>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1724
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1725 @Components = $PathsTraversal->GetConnectedComponentsVertices();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1726 $NumOfComponents = $PathsTraversal->GetConnectedComponentsVertices();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1727
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1728 Returns an array of B<Components> containing references to arrays of vertex IDs corresponding
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1729 to connected components of graph after a search. In scalar context, the number of connected
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1730 components is returned.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1731
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1732 Connected B<Components> is sorted in descending order of number of vertices in each
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1733 connected component.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1734
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1735 =item B<GetPaths>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1736
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1737 @Paths = $PathsTraversal->GetPaths();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1738 $NumOfPaths = $PathsTraversal->GetPaths();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1739
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1740 Returns an array of B<Paths> containing references to arrays of vertex IDs corresponding to
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1741 to paths traversed in a graph after a search. In scalar context, number of paths is returned.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1742
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1743 B<Paths> array is sorted in ascending order of path lengths.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1744
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1745 =item B<GetVertices>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1746
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1747 @Vertices = $PathsTraversal->GetVertices();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1748 $NumOfVertices = $PathsTraversal->GetVertices();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1749
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1750 Returns an array containing an ordered list of vertex IDs traversed during a search. In
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1751 scalar context, the number of vertices is returned.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1752
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1753 =item B<GetVerticesDepth>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1754
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1755 %VerticesDepth = $PathsTraversal->GetVerticesDepth();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1756
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1757 Returns a hash I<VerticesDepth> containing vertex ID and depth from root vertex as a key and
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1758 value pair for all vertices traversed during a search.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1759
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1760 =item B<GetVerticesNeighborhoods>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1761
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1762 @VerticesNeighborhoods =
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1763 $PathsTraversal->GetVerticesNeighborhoods();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1764 $NumOfVerticesNeighborhoods =
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1765 $PathsTraversal->GetVerticesNeighborhoods();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1766
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1767 Returns an array I<VerticesNeighborhoods> containing references to arrays corresponding
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1768 to vertices collected at various neighborhood radii around a specified vertex during a vertex
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1769 neighborhood search. In scalar context, the number of neighborhoods is returned.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1770
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1771 =item B<GetVerticesNeighborhoodsWithSuccessors>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1772
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1773 @VerticesNeighborhoodsWithSucceessors =
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1774 $PathsTraversal->GetVerticesNeighborhoodsWithSuccessors();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1775 $NumOfVerticesNeighborhoodsWithSucceessors =
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1776 $PathsTraversal->GetVerticesNeighborhoodsWithSuccessors();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1777
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1778 Returns an array I<VerticesNeighborhoodsWithSucceessors> containing references to arrays
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1779 with first value corresponding to vertex IDs corresponding to a vertex at a specific neighborhood
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1780 radius level and second value a reference to an arraty containing its successors.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1781
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1782 =item B<GetVerticesPredecessors>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1783
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1784 %VerticesPredecessors = $PathsTraversal->GetVerticesPredecessors();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1785
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1786 Returns a hash I<VerticesPredecessors> containing vertex ID and predecessor vertex ID as key
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1787 and value pair for all vertices traversed during a search.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1788
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1789 =item B<GetVerticesRoots>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1790
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1791 %VerticesRoots = $PathsTraversal->GetVerticesRoots();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1792
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1793 Returns a hash I<VerticesPredecessors> containing vertex ID and root vertex ID as a key
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1794 and value pair for all vertices traversed during a search.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1795
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1796 =item B<PerformAllPathsSearch>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1797
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1798 $PathsTraversal->PerformAllPathsSearch($StartVertexID, [$AllowCycles]);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1799
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1800 Searches all paths starting from a I<StartVertexID> with sharing of edges in paths traversed and
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1801 returns I<PathsTraversal>.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1802
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1803 By default, cycles are included in paths. A path containing a cycle is terminated at a vertex
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1804 completing the cycle.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1805
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1806 =item B<PerformAllPathsSearchWithLength>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1807
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1808 $PathsTraversal->PerformAllPathsSearchWithLength($StartVertexID,
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1809 $Length, [$AllowCycles]);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1810
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1811 Searches all paths starting from I<StartVertexID> of specific I<Length> with sharing of
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1812 edges in paths traversed and returns I<PathsTraversal>.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1813
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1814 By default, cycles are included in paths. A path containing a cycle is terminated at a vertex
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1815 completing the cycle.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1816
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1817 =item B<PerformAllPathsSearchWithLengthUpto>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1818
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1819 $PathsTraversal->PerformAllPathsSearchWithLengthUpto($StartVertexID,
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1820 $Length, [$AllowCycles]);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1821
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1822 Searches all paths starting from I<StartVertexID> of length upto a I<Length> with sharing of
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1823 edges in paths traversed and returns I<PathsTraversal>.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1824
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1825 By default, cycles are included in paths. A path containing a cycle is terminated at a vertex
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1826 completing the cycle.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1827
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1828 =item B<PerformBreadthFirstSearch>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1829
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1830 $PathsTraversal->PerformBreadthFirstSearch();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1831
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1832 Performs Breadth First Search (BFS) and returns I<PathsTraversal>.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1833
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1834 =item B<PerformBreadthFirstSearchWithLimit>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1835
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1836 $PathsTraversal->PerformBreadthFirstSearchWithLimit($DepthLimit,
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1837 [$RootVertexID]);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1838
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1839 Performs BFS with depth up to I<DepthLimit> starting at I<RootVertexID> and returns
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1840 I<PathsTraversal>. By default, root vertex ID corresponds to an arbitrary vertex.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1841
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1842 =item B<PerformDepthFirstSearch>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1843
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1844 $Return = $PathsTraversal->PerformDepthFirstSearch();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1845
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1846 Performs Depth First Search (DFS) and returns I<PathsTraversal>.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1847
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1848 =item B<PerformDepthFirstSearchWithLimit>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1849
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1850 $PathsTraversal->PerformDepthFirstSearchWithLimit($DepthLimit,
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1851 [$RootVertexID]);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1852
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1853 Performs DFS with depth up to I<DepthLimit> starting at I<RootVertexID> and returns
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1854 I<PathsTraversal>. By default, root vertex ID corresponds to an arbitrary vertex.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1855
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1856 =item B<PerformNeighborhoodVerticesSearch>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1857
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1858 $PathsTraversal->PerformNeighborhoodVerticesSearch($StartVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1859
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1860 Searches vertices around I<StartVertexID> at all neighborhood radii and returns
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1861 I<PathsTraversal> object.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1862
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1863 =item B<PerformNeighborhoodVerticesSearchWithRadiusUpto>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1864
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1865 $PathsTraversal->PerformNeighborhoodVerticesSearchWithRadiusUpto(
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1866 $StartVertexID, $Radius);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1867
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1868 Searches vertices around I<StartVertexID> with neighborhood radius up to I<Radius> and returns
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1869 I<PathsTraversal> object.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1870
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1871 =item B<PerformNeighborhoodVerticesSearchWithSuccessors>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1872
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1873 $PathsTraversal->PerformNeighborhoodVerticesSearchWithSuccessors(
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1874 $StartVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1875
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1876 Searches vertices around I<StartVertexID> at all neighborhood radii along with identification of
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1877 successor vertices for each vertex found during the traversal and returns I<PathsTraversal>.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1878
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1879 =item B<PerformNeighborhoodVerticesSearchWithSuccessorsAndRadiusUpto>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1880
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1881 $PathsTraversal->
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1882 PerformNeighborhoodVerticesSearchWithSuccessorsAndRadiusUpto(
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1883 $StartVertexID, $Radius);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1884
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1885 Searches vertices around I<StartVertexID> with neighborhood radius upto I<Radius> along with
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1886 identification of successor vertices for each vertex found during the traversal and returns
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1887 I<PathsTraversal>.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1888
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1889 =item B<PerformPathsSearch>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1890
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1891 $PathsTraversal->PerformPathsSearch($StartVertexID, [$AllowCycles]);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1892
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1893 Searches paths starting from I<StartVertexID> with no sharing of edges in paths traversed and
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1894 returns I<PathsTraversal>.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1895
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1896 By default, cycles are included in paths. A path containing a cycle is terminated at a vertex
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1897 completing the cycle.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1898
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1899 =item B<PerformPathsSearchBetween>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1900
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1901 $PathsTraversal->PerformPathsSearchBetween($StartVertexID, $EndVertexID);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1902
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1903 Searches paths between I<StartVertexID> and I<EndVertexID> and returns I<PathsTraversal>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1904
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1905 =item B<PerformPathsSearchWithLength>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1906
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1907 $PathsTraversal->PerformPathsSearchWithLength($StartVertexID, $Length,
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1908 [$AllowCycles]);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1909
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1910 Searches paths starting from I<StartVertexID> with length I<Length> with no sharing of
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1911 edges in paths traversed and returns I<PathsTraversal>.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1912
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1913 By default, cycles are included in paths. A path containing a cycle is terminated at a vertex
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1914 completing the cycle.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1915
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1916 =item B<PerformPathsSearchWithLengthUpto>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1917
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1918 $PathsTraversal->PerformPathsSearchWithLengthUpto($StartVertexID, $Length,
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1919 [$AllowCycles]);
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1920
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1921 Searches paths starting from I<StartVertexID> with length upto I<Length> with no sharing of
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1922 edges in paths traversed and returns I<PathsTraversal>.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1923
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1924 By default, cycles are included in paths. A path containing a cycle is terminated at a vertex
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1925 completing the cycle.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1926
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1927 =item B<StringifyPaths>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1928
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1929 $String = $PathsTraversal->StringifyPaths();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1930
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1931 Returns a string containing information about traversed paths in I<PathsTraversal> object
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1932
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1933 =item B<StringifyPathsTraversal>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1934
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1935 $String = $PathsTraversal->StringifyPathsTraversal();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1936
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1937 Returns a string containing information about I<PathsTraversal> object.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1938
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1939 =item B<StringifyVerticesDepth>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1940
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1941 $String = $PathsTraversal->StringifyVerticesDepth();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1942
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1943 Returns a string containing information about depth of vertices found during search by
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1944 I<PathsTraversal> object.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1945
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1946 =item B<StringifyVerticesNeighborhoods>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1947
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1948 $String = $PathsTraversal->StringifyVerticesNeighborhoods();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1949
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1950 Returns a string containing information about neighborhoods of vertices found during search by
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1951 I<PathsTraversal> object.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1952
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1953 =item B<StringifyVerticesNeighborhoodsWithSuccessors>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1954
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1955 $String = $PathsTraversal->StringifyVerticesNeighborhoodsWithSuccessors();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1956
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1957 Returns a string containing information about neighborhoods of vertices along with their successors
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1958 found during search by I<PathsTraversal> object.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1959
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1960 =item B<StringifyVerticesPredecessors>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1961
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1962 $String = $PathsTraversal->StringifyVerticesPredecessors();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1963
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1964 Returns a string containing information about predecessors of vertices found during search by
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1965 I<PathsTraversal> object.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1966
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1967 =item B<StringifyVerticesRoots>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1968
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1969 $String = $PathsTraversal->StringifyVerticesRoots();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1970
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1971 Returns a string containing information about roots of vertices found during search by
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1972 I<PathsTraversal> object.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1973
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1974 =item B<StringifyVerticesSuccessors>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1975
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1976 $String = $PathsTraversal->StringifyVerticesSuccessors();
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1977
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1978 Returns a string containing information about successors of vertices found during search by
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1979 I<PathsTraversal> object.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1980
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1981 =back
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1982
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1983 =head1 AUTHOR
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1984
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1985 Manish Sud <msud@san.rr.com>
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1986
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1987 =head1 SEE ALSO
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1988
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1989 Graph.pm, Path.pm
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1990
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1991 =head1 COPYRIGHT
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1992
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1993 Copyright (C) 2015 Manish Sud. All rights reserved.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1994
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1995 This file is part of MayaChemTools.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1996
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1997 MayaChemTools is free software; you can redistribute it and/or modify it under
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1998 the terms of the GNU Lesser General Public License as published by the Free
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
1999 Software Foundation; either version 3 of the License, or (at your option)
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
2000 any later version.
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
2001
2abf0d43254d Uploaded
deepakjadmin
parents:
diff changeset
2002 =cut