Exemple #1
0
        CreateMaxFlowData()
        {
            var graph      = new AdjacencyListGraph <string>();
            var vertexData = new List <string>()
            {
                "A",
                "B",
                "C",
                "D",
                "E",
                "F",
                "G",
            };

            var vertexs = new Dictionary <string, AdjacencyVertex <string> >();

            foreach (var data in vertexData)
            {
                vertexs.Add(data, graph.CreateVertex(data));
            }

            var edges = new List <FlowEdge <string> >();

            edges.Add(new FlowEdge <string>(vertexs["A"], vertexs["B"], 3));
            edges.Add(new FlowEdge <string>(vertexs["A"], vertexs["D"], 3));

            edges.Add(new FlowEdge <string>(vertexs["B"], vertexs["C"], 4));

            edges.Add(new FlowEdge <string>(vertexs["C"], vertexs["A"], 3));
            edges.Add(new FlowEdge <string>(vertexs["C"], vertexs["D"], 1));
            edges.Add(new FlowEdge <string>(vertexs["C"], vertexs["E"], 2));

            edges.Add(new FlowEdge <string>(vertexs["D"], vertexs["E"], 2));
            edges.Add(new FlowEdge <string>(vertexs["D"], vertexs["F"], 6));


            edges.Add(new FlowEdge <string>(vertexs["E"], vertexs["B"], 1));
            edges.Add(new FlowEdge <string>(vertexs["E"], vertexs["G"], 1));

            edges.Add(new FlowEdge <string>(vertexs["F"], vertexs["G"], 9));

            for (int i = edges.Count - 1; i >= 0; i--)
            {
                edges.Add(edges[i].GetRevolution());
            }

            graph.CreatGraph(vertexs.Values, edges);

            return(new Tuple <AdjacencyListGraph <string>
                              , AdjacencyVertex <string>
                              , AdjacencyVertex <string> >(graph, vertexs["A"], vertexs["G"]));
        }
Exemple #2
0
        /// <summary>
        /// 这样插入vertex,只有上面,左边,左上,右上4种vertex可能有边。
        /// </summary>
        /// <param name="vertexIndex"></param>
        private void AddVertex(int xDimension, int yDimension)
        {
            var key    = GetVertexIndex(xDimension, yDimension) + 1;
            var vertex = _graph.CreateVertex(key);

            _graph.AddVertex(vertex);

            var count = 0;

            var upperLeft = GetVertex(xDimension - 1, yDimension - 1);

            if (upperLeft != null)
            {
                count++;
                _graph.AddEdge(vertex, upperLeft);
            }

            var upper = GetVertex(xDimension, yDimension - 1);

            if (upper != null)
            {
                count++;
                _graph.AddEdge(vertex, upper);
            }

            var upperRight = GetVertex(xDimension + 1, yDimension - 1);

            if (upperRight != null)
            {
                count++;
                _graph.AddEdge(vertex, upperRight);
            }

            var left = GetVertex(xDimension - 1, yDimension);

            if (left != null)
            {
                count++;
                _graph.AddEdge(vertex, left);
            }

            Console.WriteLine($"vertex:{key}  legeCount:{count}");
        }