Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }