Esempio n. 1
0
        public List <NodePath> VerticesCoverPaths()
        {
            BipartiteGraph bipartite      = new BipartiteGraph(Graph.Nodes);
            var            match          = bipartite.MaxMatch().ToList();
            PassingClosure passingClosure = new PassingClosure(Graph.Nodes);

            for (var i = 0; i < match.Count; ++i)
            {
                match[i] = passingClosure.Path(Graph.Start.Quid, match[i].First) + match[i] + passingClosure.Path(match[i].Last, Graph.End.Quid);
            }
            return(match);
        }
Esempio n. 2
0
        public IEnumerable <NodePath> MaxMatch()
        {
            matching = BuildMatching();

            int ans = 0;

            foreach (var u in bipartite[0].Keys)
            {
                if (matching[0][u] == null)
                {
                    vis  = BuildVis();
                    ans += Dfs(u, 0);
                }
            }

            List <NodePath> paths = new List <NodePath>();

            foreach (var p in matching[0])
            {
                if (p.Value != null)
                {
                    paths.Add(closure.Path(p.Key, p.Value));
                }
            }
            for (var i = 0; i < paths.Count;)
            {
                bool update = false;
                var  j      = i + 1;
                while (j < paths.Count)
                {
                    if (paths[i].Last == paths[j].First)
                    {
                        paths[i] = paths[i] + paths[j];
                        paths.RemoveAt(j);
                        update = true;
                    }
                    else
                    {
                        ++j;
                    }
                }
                //i = update ? i + 1 : i;
                i = update ? i : i + 1;
            }
            return(paths);
        }