Esempio n. 1
0
        private void Initialize()
        {
            distanceToSink.Clear();
            flow.Clear();
            excess.Clear();
            activeNodes.Clear();
            sourceGroup.Clear();
            sourceGroup.AddRange(Sources);
            nodesAtDistance[0] = Set <NodeType> .FromEnumerable(Sinks);

            foreach (NodeType sink in Sinks)
            {
                distanceToSink[sink] = 0;
            }
            Set <NodeType> nodesAtDistance1 = new Set <NodeType>();

            foreach (NodeType node in graph.Nodes)
            {
                if (!Sources.Contains(node) && !Sinks.Contains(node))
                {
                    nodesAtDistance1.Add(node);
                }
            }
            nodesAtDistance[1] = nodesAtDistance1;
            foreach (NodeType source in Sources)
            {
                if (!Sinks.Contains(source))
                {
                    distanceToSink[source] = int.MaxValue;
                }
                foreach (EdgeType edge in graph.EdgesOutOf(source))
                {
                    float f = capacity(edge);
                    flow[edge] = f;
                    if (!IsSinkEdge(edge))
                    {
                        NodeType target = graph.TargetOf(edge);
                        if (!Sources.Contains(target) && !Sinks.Contains(target))
                        {
                            excess[target] += f;
                            activeNodes.Add(target);
                        }
                    }
                }
                foreach (EdgeType edge in graph.EdgesInto(source))
                {
                    if (!IsSinkEdge(edge))
                    {
                        float f = reverseCapacity(edge);
                        flow[edge] = -f;
                        NodeType target = graph.SourceOf(edge);
                        if (!Sources.Contains(target) && !Sinks.Contains(target))
                        {
                            excess[target] += f;
                            activeNodes.Add(target);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 public IEnumerable <EdgeType> EdgesOutOf(NodeType source)
 {
     foreach (EdgeType edge in graph.EdgesOutOf(source))
     {
         if (predicate(edge))
         {
             yield return(edge);
         }
     }
 }