Пример #1
0
 /// <summary>
 /// The GetResidualEdge method.
 /// </summary>
 /// <param name="edge">
 /// The edge.
 /// </param>
 /// <returns>
 /// Returns GraphEdge object which is a residual edge to given edge.
 /// </returns>
 private GraphEdge GetResidualEdge(GraphEdge edge)
 {
     GraphNode gnode = this.nodeSet.FindByName(edge.NodeTo.VertexId);
     GraphEdge edgeResidual = gnode.Neighbours.FindByName(edge.NodeTo.VertexId, edge.NodeFrom.VertexId);
     return edgeResidual;
 }
Пример #2
0
        /// <summary>
        /// The add directed edge.
        /// </summary>
        /// <param name="from">
        /// The from.
        /// </param>
        /// <param name="to">
        /// The to.
        /// </param>
        /// <param name="flow">
        /// The flow.
        /// </param>
        internal void AddDirectedEdge(GraphNode from, GraphNode to, int flow)
        {
            if (from == null || to == null)
            {
                return;
            }

            if (from.VertexId.Equals(to.VertexId))
            {
                return;
            }

            var edge = new GraphEdge
                {
                    NodeFrom = @from,
                    NodeTo = to,
                    Capacity = flow,
                    MaxCapacity = flow,
                    IsResidual = false,
                    IsVisible = true
                };
            from.Neighbours.Add(edge);
            GraphEdge edgeResidual = to.Neighbours.FindByName(to.VertexId, from.VertexId);
            if (edgeResidual == null)
            {
                var edgeRes = new GraphEdge
                    {
                       NodeFrom = to, NodeTo = @from, Capacity = 0, IsResidual = true, IsVisible = true
                    };
                to.Neighbours.Add(edgeRes);
            }

            this.edges++;
        }