コード例 #1
0
        public static aceRelationMatrix <String, String, Double> GetIDMatrix(this freeGraph graph)
        {
            List <freeGraphNodeBase> nodes = graph.nodes;

            List <String> nodeIDs = nodes.Select(x => x.name).ToList();

            aceRelationMatrix <String, String, Double> output = new aceRelationMatrix <String, String, Double>(nodeIDs, nodeIDs, 0);

            foreach (freeGraphNodeBase node in nodes)
            {
                var links = graph.GetLinks(node.name, true, true);

                foreach (freeGraphLinkBase link in links.links)
                {
                    if (link.nodeNameA == node.name)
                    {
                        output[link.nodeNameA, link.nodeNameB] += link.weight;
                    }
                    else
                    {
                        output[link.nodeNameB, link.nodeNameA] += link.weight;
                    }
                }
            }

            return(output);
        }
コード例 #2
0
        public static freeGraph GetGraphSection(this freeGraph source, List <String> node_names, String name, String description = "")
        {
            var nodes = source.GetNodes(node_names);

            freeGraph output = new freeGraph()
            {
                name        = name,
                description = description
            };

            foreach (var node in nodes)
            {
                output.AddNode(node.name, node.weight, node.type);
            }

            foreach (var node in nodes)
            {
                var links = source.GetLinks(node.name, true, false, 1);
                foreach (var link in links)
                {
                    if (node_names.Contains(link.nodeB.name))
                    {
                        output.AddLink(node.name, link.nodeB.name, link.linkBase.weight, link.linkBase.type);
                    }
                }
            }

            return(output);
        }
コード例 #3
0
        /// <summary>
        /// Merges specified cloud into this one by summing overlaping node and link weights and picks type that is greater
        /// </summary>
        /// <param name="x">The x.</param>
        public void AddCloud(freeGraph x)
        {
            foreach (var i in x.nodes)
            {
                AddNodeOrSum(i);
            }

            foreach (var i in x.links)
            {
                AddLinkOrSum(i);
            }
        }
コード例 #4
0
        public List <freeGraphNodeBase> GetOverlap(freeGraph second)
        {
            List <freeGraphNodeBase> output = new List <freeGraphNodeBase>();

            foreach (freeGraphNodeBase node in nodes)
            {
                if (second.ContainsNode(node.name, true))
                {
                    output.Add(node);
                }
            }

            return(output);
        }
コード例 #5
0
        public static aceRelationMatrix <String, String, Int32> GetIDMatrix(this freeGraph graph, Int32 scoreFactor)
        {
            List <freeGraphNodeBase> nodes = graph.nodes;

            List <String> nodeIDs = nodes.Select(x => x.name).ToList();

            aceRelationMatrix <String, String, Double> output      = GetIDMatrix(graph);
            aceRelationMatrix <String, String, Int32>  outputInt32 = new aceRelationMatrix <string, string, Int32>(output.GetXAxis(), output.GetYAxis(), 0);

            foreach (string kx in output.GetXAxis())
            {
                foreach (string ky in output.GetYAxis())
                {
                    outputInt32[kx, ky] = Convert.ToInt32(output[kx, ky] * scoreFactor);
                }
            }


            return(outputInt32);
        }
コード例 #6
0
 //public freeGraphReport() { }
 /// <summary>
 /// Initializes a new instance of the <see cref="freeGraphReport"/> class and performs analysis on <c>graph</c>
 /// </summary>
 /// <param name="graph">The graph.</param>
 public freeGraphReport(freeGraph graph)
 {
     Deploy(graph);
 }
コード例 #7
0
        /// <summary>
        /// Populates the graph report
        /// </summary>
        /// <param name="graph">The graph.</param>
        public void Deploy(freeGraph graph)
        {
            name = graph.name;

            description = "Analysis of graph [" + graph.name + "] structure and other key metrics: " + graph.description;

            List <Double> ws = new List <double>();
            //instanceCountCollection<freeGraphNodeBase> linkPerNodeFrequency = new instanceCountCollection<freeGraphNodeBase>();
            aceDictionarySet <Int32, freeGraphNodeBase> nodesByNumberOfLinks = new aceDictionarySet <int, freeGraphNodeBase>();

            foreach (var node in graph.nodes)
            {
                ws.Add(node.weight);

                Int32 lc = graph.CountLinks(node.name, true, true);
                nodesByNumberOfLinks.Add(lc, node);
            }

            if (!ws.Any())
            {
                EmptyGraph = true;
                return;
            }

            TotalWeight = ws.Sum();
            AvgWeight   = ws.Average();
            StdWeight   = ws.GetStdDeviation(false);

            NodeCount = graph.nodes.Count;
            LinkRatio = graph.links.GetRatio(graph.nodes);

            List <String> processed       = new List <String>();
            List <Int32>  linkFrequencies = nodesByNumberOfLinks.Keys.OrderByDescending(x => x).ToList();

            Int32 maxLinkFreq = linkFrequencies.Max();

            foreach (Int32 freq in linkFrequencies)
            {
                List <freeGraphNodeBase> nextSet = nodesByNumberOfLinks[freq].ToList();
                foreach (freeGraphNodeBase n in nextSet)
                {
                    if (!processed.Contains(n.name))
                    {
                        var             result = graph.GetLinkedNodes(new String[] { n.name }, 100, true, true, false);
                        freeGraphIsland island = new freeGraphIsland();
                        island.Add(result);

                        if (island.type != freeGraphIslandType.none)
                        {
                            islands.Add(island);
                            processed.AddRange(island.nodes);
                        }

                        //result.ForEach(x => processed.Add(x.name));
                    }
                }
            }

            List <freeGraphIsland> _binodal   = new List <freeGraphIsland>();
            List <freeGraphIsland> _trinodal  = new List <freeGraphIsland>();
            List <freeGraphIsland> _polinodal = new List <freeGraphIsland>();

            freeGraphIsland continent = null;

            if (islands.Any())
            {
                Int32 max = 0;
                continent = islands.First();
                foreach (var island in islands)
                {
                    Int32 nc = island.nodes.Count;
                    if (nc == 2)
                    {
                        Binodal += nc;
                        BinodalN++;
                    }
                    if (nc == 3)
                    {
                        Trinodal += nc;
                        TrinodalN++;
                    }
                    if (nc > 3)
                    {
                        Polinodal += nc;
                        PolinodalN++;
                    }
                    if (max < nc)
                    {
                        max       = nc;
                        continent = island;
                    }
                }
            }

            AllIslands = islands.Count;

            PolinodalRatio = Polinodal.GetRatio(graph.nodes.Count);

            if (continent != null)
            {
                var contNodes = graph.nodes.Where(x => continent.nodes.Contains(x.name)).ToList();

                //var contNodes = ;

                ContinentMass = continent.nodes.Count;
                Double cw = contNodes.Sum(x => x.weight);
                ContinentWeightRate = cw.GetRatio(TotalWeight);
                ContinentMassRate   = continent.nodes.Count.GetRatio(graph.nodes.Count);

                ContinentSize = graph.PingGraphSize(nodesByNumberOfLinks[maxLinkFreq], true, freeGraphPingType.maximumPingLength);
            }

            MainIsland = continent;
        }
コード例 #8
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="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);
        }
コード例 #9
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));
 }
コード例 #10
0
        /// <summary>
        /// Transforms the free graph into relationship matrix
        /// </summary>
        /// <param name="graph">The graph.</param>
        /// <returns></returns>
        public static aceRelationMatrix <freeGraphNodeBase, freeGraphNodeBase, Double> GetMatrix(this freeGraph graph)
        {
            List <freeGraphNodeBase> nodes = graph.nodes;

            aceRelationMatrix <freeGraphNodeBase, freeGraphNodeBase, Double> output = new aceRelationMatrix <freeGraphNodeBase, freeGraphNodeBase, Double>(nodes, nodes, 0);

            foreach (freeGraphNodeBase node in nodes)
            {
                var links = graph.GetLinks(node.name, true, true);

                foreach (freeGraphLinkBase link in links.links)
                {
                    var nodeA = graph.GetNode(link.nodeNameA);
                    var nodeB = graph.GetNode(link.nodeNameB);

                    if (link.nodeNameA == node.name)
                    {
                        output[nodeA, nodeB] += link.weight;
                    }
                    else
                    {
                        output[nodeB, nodeA] += link.weight;
                    }
                }
            }

            return(output);
        }