private bool AllSetMappedCheck(Combination combination) { if (Type == ReversalType.Inputs) { BipartiteGraph <Data, Data> G = GraphBuilder.BipartiteFromTwoSets(RequestedInputsToReverse, combination, i => GetDependenciesFromInput(i), i => GetDependenciesFromInput(i)); List <(Data, Data)> Matching = MaximumMatching.Get(G); return(Matching.Count == NinRequest); } else { BipartiteGraph <Data, Data> G = GraphBuilder.BipartiteFromTwoSets(RequestedOutputsToReverse, combination, o => GetDependenciesFromOutput(o), o => GetDependenciesFromOutput(o)); List <(Data, Data)> Matching = MaximumMatching.Get(G); return(Matching.Count == NoutRequest); } }
private void ENUM_MAXIMUM_MATCHINGS(BipartiteGraph G, bool getAllMatchings) { /*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- * Step1: Find a maximum matching M of G and output M. * --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ // The maximum mathing EdgeList M = MaximumMatching.Get(G); List <string> M_String = matchingToStringList(M); M_String.Sort(); findOverconstrainedModelsReversalCost(M_String, out OverConstrainedModels, out unmappedVariables, out revCost); if (OverConstrainedModels.Count > 0) { returnTrue = true; return; } list_AllMaximumMatchings.Add(M_String); /*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- * Step2: Trim unnecessary arcs from D(G,M) by a strongly connected component decomposition algorithm. * --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ //Need further action on this to trim edges after finding SCCs in a D(G,M). Here only SCCs are found. Edges are not trimmed yet. //Graph D_GM = Get_D_GM(G.Clone(), M); //Directed graph is obtained here with reversing edges of matchingEdges. //List<List<GraphNode>> sCCs = TarjanCycleDetect.DetectCycle(D_GM); /*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- * Step3: Call ENUM_MAXIMUM_MATCHINGS_ITER(G, M, D(G,M)) * --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ if (getAllMatchings) { ENUM_MAXIMUM_MATCHINGS_ITER(G.Clone(), M, matchingToStringList(M), 0); } //list_AllPerfectMatchings.Add(M_String); filterDuplicateMatchings(); }
private void ENUM_MAXIMUM_MATCHINGS(BipartiteGraph G, bool getAllMatchings) { /*------------------------------------------------------------------------------------------------------------------- * Step1: Find a maximum matching M of G and output M. * ------------------------------------------------------------------------------------------------------------------*/ EdgeList M = MaximumMatching.Get(G); //Edges of Matching MatchingList matching = EdgeListToMatching(M); matching.Sort(); FindOverconstrainedModelsReversalCost(matching); if (OverConstrainedModels.Count > 0) { OverConstrained = true; return; } AddMatching(matching); if (MinimumCost > minimumAchievableCost) { /*------------------------------------------------------------------------------------------------------------------- * Step2: Trim unnecessary arcs from D(G,M) by a strongly connected component decomposition algorithm. * ------------------------------------------------------------------------------------------------------------------*/ //Need further action on this to trim edges after finding SCCs in a D(G,M). Here only SCCs are found. Edges are not trimmed yet. //Graph D_GM = Get_D_GM(G.Clone(), M); //Directed graph is obtained here with reversing edges of matchingEdges. //List<List<GraphNode>> sCCs = TarjanCycleDetect.DetectCycle(D_GM); /*------------------------------------------------------------------------------------------------------------------- * Step3: Call ENUM_MAXIMUM_MATCHINGS_ITER(G, M, D(G,M)) * ------------------------------------------------------------------------------------------------------------------*/ if (getAllMatchings) { ENUM_MAXIMUM_MATCHINGS_ITER(G.Clone(), M, matching, 0); } } FilterDuplicateMatchings(); }