Changeset 9038
- Timestamp:
- 12/12/12 13:09:21 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/3.3/OperatorGraph.cs
r7259 r9038 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 24 25 using HeuristicLab.Collections; … … 244 245 } 245 246 #endregion 247 248 // <summary> 249 /// Iterates an operator graph so that it jumps from the intial operator to all other operators and yields each operator it touches. 250 /// Cycles are detected and not iterated twice. 251 /// </summary> 252 /// <returns>An enumeration of all the operators that could be found.</returns> 253 public IEnumerable<IOperator> Iterate() { 254 if (InitialOperator == null) yield break; 255 256 var open = new Stack<IOperator>(); 257 var visited = new HashSet<IOperator>(); 258 open.Push(InitialOperator); 259 260 while (open.Any()) { 261 IOperator current = open.Pop(); 262 if (visited.Contains(current)) continue; 263 visited.Add(current); 264 265 foreach (var parameter in current.Parameters.OfType<IValueParameter>()) { 266 if (!typeof(IOperator).IsAssignableFrom(parameter.DataType)) continue; 267 if (parameter.Value == null) continue; 268 269 open.Push((IOperator)parameter.Value); 270 } 271 272 yield return current; 273 } 274 } 246 275 } 247 276 }
Note: See TracChangeset
for help on using the changeset viewer.