private static LinkedList1 <UOPair <HlaMsr1> > MakeUnphased(UOPair <LinkedList1 <HlaMsr1> > phaseGrounded)
        {
            LinkedList1 <UOPair <HlaMsr1> > unphased = null;

            foreach (var pair in SpecialFunctions.EnumerateTwo(phaseGrounded.First, phaseGrounded.Second))
            {
                unphased = LinkedList1 <UOPair <HlaMsr1> > .GetInstance(UOPair <HlaMsr1> .GetInstance(pair.Key, pair.Value), unphased);
            }
            return(unphased);
        }
        public static IEnumerable <PidAndHlaSet> GetEnumerationDense(TextReader inputTextReader)
        {
            foreach (var pidAndHlaRecord in SpecialFunctions.ReadDelimitedFile(inputTextReader, new { pid = "", A1 = "", A2 = "", B1 = "", B2 = "", C1 = "", C2 = "" }, new char[] { '\t' }, true))
            {
                PidAndHlaSet pidAndHlaSet = new PidAndHlaSet();
                pidAndHlaSet.Pid           = pidAndHlaRecord.pid;
                pidAndHlaSet.WarningSet    = new HashSet <string>();
                pidAndHlaSet.HlaUopairList = LinkedList1 <UOPair <HlaMsr1> > .GetInstance(
                    UOPair <HlaMsr1> .GetInstance(CreateHla(pidAndHlaRecord.C1, ref pidAndHlaSet.WarningSet), CreateHla(pidAndHlaRecord.C2, ref pidAndHlaSet.WarningSet)),
                    UOPair <HlaMsr1> .GetInstance(CreateHla(pidAndHlaRecord.B1, ref pidAndHlaSet.WarningSet), CreateHla(pidAndHlaRecord.B2, ref pidAndHlaSet.WarningSet)),
                    UOPair <HlaMsr1> .GetInstance(CreateHla(pidAndHlaRecord.A1, ref pidAndHlaSet.WarningSet), CreateHla(pidAndHlaRecord.A2, ref pidAndHlaSet.WarningSet)));

                pidAndHlaSet.ClassList = new List <string> {
                    "C", "B", "A"
                };
                yield return(pidAndHlaSet);
            }
        }
        private static PidAndHlaSet CreatePidAndHlaSet(string previousPid, Dictionary <string, List <HlaMsr1> > classToHlaList, HashSet <string> warningSet)
        {
            SpecialFunctions.CheckCondition(new HashSet <string>(classToHlaList.Keys).SetEquals(new HashSet <string> {
                "A", "B", "C"
            }), "Expect Hla's for exactly classes A,B, & C. " + previousPid);
            SpecialFunctions.CheckCondition(classToHlaList.Values.All(list => list.Count == 2), "Expect two hla lines for each Hla class. " + previousPid);
            PidAndHlaSet pidAndHlaSet = new PidAndHlaSet();

            pidAndHlaSet.Pid           = previousPid;
            pidAndHlaSet.WarningSet    = warningSet;
            pidAndHlaSet.HlaUopairList = LinkedList1 <UOPair <HlaMsr1> > .GetInstance(
                UOPair <HlaMsr1> .GetInstance(classToHlaList["C"][0], classToHlaList["C"][1]),
                UOPair <HlaMsr1> .GetInstance(classToHlaList["B"][0], classToHlaList["B"][1]),
                UOPair <HlaMsr1> .GetInstance(classToHlaList["A"][0], classToHlaList["A"][1]));

            pidAndHlaSet.ClassList = new List <string> {
                "C", "B", "A"
            };
            return(pidAndHlaSet);
        }
        private IEnumerable <KeyValuePair <LinkedList1 <HlaMsr1>, KeyValuePair <double, bool> > > ExpandHlaList(LinkedList1 <HlaMsr1> hlaListAbstractOrGround)
        {
            if (null == hlaListAbstractOrGround)
            {
                yield return(new KeyValuePair <LinkedList1 <HlaMsr1>, KeyValuePair <double, bool> >(null, new KeyValuePair <double, bool>(1.0, false)));
            }
            else
            {
                foreach (var restOrNullExpandedAndProb in ExpandHlaList(hlaListAbstractOrGround.RestOrNull))
                {
                    foreach (var hlaAndProb in ExpandHla(hlaListAbstractOrGround.First, restOrNullExpandedAndProb.Key))
                    {
                        LinkedList1 <HlaMsr1> linkedList1 = LinkedList1 <HlaMsr1> .GetInstance(hlaAndProb.Key, restOrNullExpandedAndProb.Key);

                        double prob             = hlaAndProb.Value.Key * restOrNullExpandedAndProb.Value.Key;
                        bool   usedBackoffModel = hlaAndProb.Value.Value || restOrNullExpandedAndProb.Value.Value;
                        yield return(new KeyValuePair <LinkedList1 <HlaMsr1>, KeyValuePair <double, bool> >(linkedList1, new KeyValuePair <double, bool>(prob, usedBackoffModel)));
                    }
                }
            }
        }