Пример #1
0
        private List <List <Edge> > GetGraphMatchings(UndirectedGraph graph)
        {
            var matchings = new List <List <Edge> >();
            var matching  = new Blossom(graph).MaximumMatching();

            matchings.Add(matching);

            matching.Sort((e1, e2) => graph.SortEdgesByColored(e1, e2));
            var listOfEdgesToDelete = matching.Select(e => new List <Edge>()
            {
                e
            }).ToList();

            while (listOfEdgesToDelete.Count > 0)
            {
                var edgesToDelete = listOfEdgesToDelete[0];
                listOfEdgesToDelete.RemoveAt(0);

                matching = GetGraphMatching(graph, edgesToDelete);
                matchings.Add(matching);
                if (matchings.Count >= callsLimit)
                {
                    return(matchings);
                }

                matching.Sort((e1, e2) => graph.SortEdgesByColored(e1, e2));
                foreach (var edge in matching)
                {
                    var newEdgesToDelete = edgesToDelete.ConvertAll(e => new Edge(e));
                    newEdgesToDelete.Add(edge);
                    listOfEdgesToDelete.Add(newEdgesToDelete);
                }
            }
            return(matchings);
        }
Пример #2
0
        private List <Edge> GetGraphMatching(UndirectedGraph graph, List <Edge> edgesToDelete)
        {
            var graphPrim = new UndirectedGraph(graph);

            graphPrim.RemoveEdges(edgesToDelete);
            var matching = new Blossom(graphPrim).MaximumMatching();

            return(matching);
        }