static List <List <InternodeMessage> > FindInfeasibleMessagesCombinations(ISolver solver, IDictionary <NodeId, Node> nodes, List <InternodeMessage> messages, List <FixedConstraint> fixedConstraints, HashSet <string> allowInstacesMergingForRoles) { var ret = new List <HashSet <InternodeMessage> >(); Func <HashSet <InternodeMessage>, bool> combinationIsInfeasible = comb => ret.Any(alreadyFoundCombination => comb.IsSupersetOf(alreadyFoundCombination)); for (var combinationLength = 2; combinationLength < Math.Min(10, (messages.Count - 1)); ++combinationLength) { var newCombinationCandidates = (from comb in LinqUtils.GetPowerSet(messages, combinationLength) let combDict = new HashSet <InternodeMessage>(comb) where !combinationIsInfeasible(combDict) select combDict).ToArray(); var newCombinations = from combDict in newCombinationCandidates.AsParallel() let solution = solverFn(solver, nodes, new InternodeMessagesMap(nodes, combDict.ToList()), combDict.ToList(), fixedConstraints, allowInstacesMergingForRoles) where solution.Status == SolutionStatus.Infeasible select combDict; ret.AddRange(newCombinations.ToArray()); } return(ret.Select(d => d.ToList()).ToList()); }
static List <Dictionary <NodeId, Node> > FindInfeasibleNodeCombinations(ISolver solver, IDictionary <NodeId, Node> nodes, List <InternodeMessage> messages, List <FixedConstraint> fixedConstraints, HashSet <string> allowInstacesMergingForRoles) { var infeasibleNodeCombinations = new List <Dictionary <NodeId, Node> >(); Func <Dictionary <NodeId, Node>, bool> combinationIsInfeasible = comb => infeasibleNodeCombinations.Any(alreadyFoundCombination => comb.Contains(alreadyFoundCombination)); for (var combinationLength = 2; combinationLength <= nodes.Count; ++combinationLength) { var newCombinations = from comb in LinqUtils.GetPowerSet(nodes.ToArray()) let combDict = comb.ToDictionary(x => x.Key, x => x.Value) where combDict.Count == combinationLength where !combinationIsInfeasible(combDict) let relevantMessages = messages.Where(m => m.IsRelevant(combDict)).ToList() let combSolution = solverFn(solver, combDict, new InternodeMessagesMap(combDict, relevantMessages), relevantMessages, fixedConstraints, allowInstacesMergingForRoles) where combSolution.Status == SolutionStatus.Infeasible select combDict; infeasibleNodeCombinations.AddRange(newCombinations); } return(infeasibleNodeCombinations); }