Ejemplo n.º 1
0
        internal static BidirectionalGraph <TEdgeData> CreateSubGraph <TEdgeData>(this BidirectionalGraphDirectNodeAccess <TEdgeData> graph,
                                                                                  Dictionary <long, bool> nodesOfSubGraph)
        {
            var newGraph = new BidirectionalGraph <TEdgeData>();

            foreach (var node in nodesOfSubGraph)
            {
                var newInEdges = newGraph.GetOrCreateInEdges(node.Key);
                foreach (var inEdge in graph.InEdges(node.Key))
                {
                    if (nodesOfSubGraph.ContainsKey(inEdge.Source))
                    {
                        newInEdges.Add(inEdge);
                    }
                }
                var newOutEdges = newGraph.GetOrCreateOutEdges(node.Key);
                foreach (var outEdge in graph.OutEdges(node.Key))
                {
                    if (nodesOfSubGraph.ContainsKey(outEdge.Target))
                    {
                        newOutEdges.Add(outEdge);
                    }
                }
            }
            return(newGraph);
        }
Ejemplo n.º 2
0
 public override IEnumerable <Edge <TEdgeData> > OutEdges(long vertex)
 {
     if (_ignoreNodeFunc == null && _ignoreEdgeFunc == null)
     {
         return(_baseGraph.OutEdges(vertex));
     }
     if (_ignoreNodeFunc != null && _ignoreEdgeFunc == null && !_ignoreNodeFunc(vertex))
     {
         return(_baseGraph.OutEdges(vertex));
     }
     if (_ignoreNodeFunc != null && _ignoreNodeFunc(vertex))
     {
         return(new Edge <TEdgeData> [0]);
     }
     return(FilteredOutEdges(vertex));
 }