public BipartiteGraph(Dictionary <string, Node> graph) { bipartite = new List <Dictionary <string, Node> > { new Dictionary <string, Node>(), new Dictionary <string, Node>() }; closure = new PassingClosure(graph); var g = closure.AddPassingClosure(graph); //build bipartite graph vertices for (int i = 0; i < 2; ++i) { foreach (var u in g.Values) { Node node = new Node(u); // bipartite[i].Add(u.Quid, u); bipartite[i][node.Quid] = node; } } //build graph edges foreach (var u in g.Keys) { foreach (var v in g[u].To) { bipartite[0][u].To.Add(bipartite[1][v].Quid); bipartite[1][v].To.Add(bipartite[0][u].Quid); } } }
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); }