static void Main(string[] args) { //p1^p2^p3,p2^p3^p4,p1^p3^p4,p1^p2^p4,p4^p5^p6,p4^p5^p7,p4^p6^p7 //P1^P2,P2^P3,P3^p4,p3^p5,p3^p6,p6^p7,p7^p8,p8^p1 //P1^P2,P2^P3,P3^p4,p4^p5,p5^p6,p6^p7,p7^p8,p8^p1 AccessStructure acc = new AccessStructure("P1^P2,P2^P3,P3^p4,p4^p5,p5^p6,p6^p7,p7^p8,p8^p1"); var expanded = new List <QualifiedSubset>(); var qualified = new List <QualifiedSubset>(); var thresholds = new List <ThresholdSubset>(); var remaining = new List <QualifiedSubset>(); var attempts = new List <String>(); var tryIntersect = true; ThresholdHelper.ServeThresholdDetection(acc, tryIntersect, out expanded, out qualified, out thresholds, out attempts, out remaining); //foreach (var att in attempts) //{ // Console.WriteLine(att); //} Console.WriteLine("all threshold attempts:{0}", attempts.Count); Console.WriteLine("all fixed threshold attempts:{0}", ThresholdSubset.fixedAttemptTrace.Count); Console.WriteLine("all found thresholds:"); foreach (var thre in thresholds) { Console.WriteLine(thre); } Console.WriteLine("all unique thresholds:"); foreach (var thre in ThresholdSubset.CheckInclusiveThresholds(thresholds)) { Console.WriteLine(thre); } Console.Read(); return; }
public static void ServeThresholdDetection(AccessStructure access, bool tryIntersect, out List <QualifiedSubset> expandedSet , out List <QualifiedSubset> qualifiedSet, out List <ThresholdSubset> thresholds, out List <string> attempts, out List <QualifiedSubset> notMatchingSet) { ThresholdSubset.attemptTrace = new List <string>(); ThresholdSubset.fixedAttemptTrace = new List <string>(); List <Trustee> trustees = access.GetAllParties().OrderBy(po => po.partyId).ToList(); //discover all possible expansion of the access structures List <QualifiedSubset> subsets = AccessStructure.ExpandPersonPaths(null, trustees).Distinct().ToList(); expandedSet = subsets; //return; //we don't care about longer paths which are not mentioned in the access structure int longestQualifiedSubsetAccepted = access.GetLongestLength();//GetLongestLength(access); //calculate the share of each party in qualified subsets int i = 0; List <Tuple <Trustee, int> > allsubsetsparties = new List <Tuple <Trustee, int> >(); List <QualifiedSubset> qualifiedExpandedSubset = new List <QualifiedSubset>(); Console.WriteLine("All qualified expanded subsets:"); foreach (QualifiedSubset subset in subsets) { //delete unqualified subsets based on minimum access structure if (subset.Parties.Count > longestQualifiedSubsetAccepted) { continue; } bool isqualified = AccessStructure.IsQualifiedSubset(subset, access); if (isqualified) { //add the subset to expanded qualified qualifiedExpandedSubset.Add(subset); allsubsetsparties.AddRange(subset.Parties.Select(po => new Tuple <Trustee, int>(po, subset.Parties.Count))); Console.WriteLine("{0}.\t [{1}] q:{2}", i++, subset.ToString(), isqualified); } } qualifiedSet = qualifiedExpandedSubset.ToList(); List <ThresholdSubset> thresholdsubsets = new List <ThresholdSubset>(); var normalTH = qualifiedExpandedSubset.GroupBy(po => po.Parties.Count).Select(info => new { Depth = info.Key, Count = info.Count() }); foreach (var th in normalTH) { var candidateSets = qualifiedExpandedSubset.Where(po => po.Parties.Count == th.Depth); ///find threshold in sets var threshold = ThresholdSubset.findThreshold(candidateSets, th.Depth, trustees.Count, ThresholdSubset.GetNumberOfRequiredSetsForThreshold(trustees.Count, th.Depth, candidateSets.Count()), tryIntersect); if (threshold != null && threshold.Count != 0) { thresholdsubsets.AddRange(threshold); } } var uniqueInclusiveThresholds = ThresholdSubset.CheckInclusiveThresholds(thresholdsubsets.Distinct()); foreach (ThresholdSubset th in uniqueInclusiveThresholds) { Console.WriteLine(th); var coveredsets = ThresholdSubset.ExploreAllSubsets(th); qualifiedExpandedSubset = qualifiedExpandedSubset.Except(coveredsets).ToList(); } thresholds = uniqueInclusiveThresholds.ToList(); notMatchingSet = qualifiedExpandedSubset.ToList(); attempts = ThresholdSubset.attemptTrace; }