/// <summary> /// Pings the size of the graph by expanding from specified <c>pingSources</c> until number of reached nodes is increasing. <see cref="freeGraphPingType"/> /// </summary> /// <param name="graph">The graph that is probed.</param> /// <param name="pingSources">The ping sources - nodes to start ping expansion from.</param> /// <param name="bothDirections">if set to <c>true</c> if will expand trough both backward and forward links. Otherwise propagates forward</param> /// <param name="pingType">Type of the ping operation</param> /// <param name="pingLimit">The ping limit - after which the expansion will stop.</param> /// <returns>Value according to specified <c>pingType</c> or 0 on failure</returns> public static Double PingGraphSize(this freeGraph graph, IEnumerable <freeGraphNodeBase> pingSources, Boolean bothDirections, freeGraphPingType pingType, Int32 pingLimit = 100) { List <String> nodeNames = new List <string>(); List <String> centralNodes = new List <string>(); if (pingType == freeGraphPingType.unisonPingLength) { foreach (var p in pingSources) { centralNodes.Add(p.name); nodeNames.Add(p.name); } freeGraphNodeBase ps = pingSources.First(); var lst = new List <freeGraphNodeBase>(); // { ps }; lst.Add(ps); pingSources = lst; } List <Int32> pingResults = new List <int>(); List <Int32> pingedNodes = new List <int>(); foreach (var p in pingSources) { if (pingType != freeGraphPingType.unisonPingLength) { nodeNames = new List <string>(); centralNodes = new List <string>(); nodeNames.Add(p.name); centralNodes.Add(p.name); } Int32 pingSize = 1; Int32 c = 0; while (c < pingLimit) { var result = graph.GetLinkedNodes(centralNodes, 1, bothDirections); Int32 nCount = nodeNames.Count; foreach (var res in result) { centralNodes = new List <string>(); if (!nodeNames.Contains(res.name)) { nodeNames.Add(res.name); centralNodes.Add(res.name); } } if (nodeNames.Count > nCount) { pingSize++; } else if (nodeNames.Count == nCount) { break; } c++; if (pingSize > pingLimit) { break; } } pingResults.Add(pingSize); pingedNodes.Add(nodeNames.Count); } if (pingResults.Count > 0) { switch (pingType) { case freeGraphPingType.averagePingLength: return(pingResults.Average()); case freeGraphPingType.maximumPingLength: return(pingResults.Max()); case freeGraphPingType.unisonPingLength: return(pingResults.Max()); break; case freeGraphPingType.numberOfPingedNodes: return(nodeNames.Count); break; } } return(0); }
/// <summary> /// Pings the size of the graph by expanding from specified <c>pingSources</c> until number of reached nodes is increasing. <see cref="freeGraphPingType" /> /// </summary> /// <param name="graph">The graph that is probed.</param> /// <param name="pingSource">The ping source.</param> /// <param name="bothDirections">if set to <c>true</c> if will expand trough both backward and forward links</param> /// <param name="pingType">Type of the ping operation</param> /// <param name="pingLimit">The ping limit - after which the expansion will stop.</param> /// <returns> /// Value according to specified <c>pingType</c> or 0 on failure /// </returns> public static Double PingGraphSize(this freeGraph graph, freeGraphNodeBase pingSource, Boolean bothDirections, freeGraphPingType pingType, Int32 pingLimit = 100) { return(PingGraphSize(graph, new List <freeGraphNodeBase> { pingSource }, bothDirections, pingType, pingLimit)); }