示例#1
0
    //Driver code for Whiteboard//
    public static void Main()
    {
        LinkedList1 l1 = new LinkedList1();

        l1.Insert(8);
        l1.Insert(8);
        l1.Insert(3);
        l1.Insert(2);
        l1.Insert(1);

        LinkedList1 l2 = new LinkedList1();

        l2.Insert(1);
        l2.Insert(1);
        l2.Insert(1);
        l2.Insert(9);
        l2.Insert(10);


        LinkedList1 l3 = new LinkedList1();

        l3.Insert(12);
        l3.Insert(9);
        l3.Insert(7);
        l3.Insert(10);
        l3.Insert(10);



        Console.WriteLine($"{l1.AscendingDescendingOrNone(l1)}, {l1}");

        Console.WriteLine($"{l2.AscendingDescendingOrNone(l2)}, {l2}");

        Console.WriteLine($"{l3.AscendingDescendingOrNone(l3)}, {l3}");
    }
示例#2
0
        private void btnLinkedList_Click(object sender, EventArgs e) //LINKED LIST BUTTON
        {
            //Declaring a new instance of Linked List and displaying properties to the Windows Form
            LinkedList1 LinkList = new LinkedList1();

            richTextBox2.AppendText(LinkList.AccessTime + "        ");
            richTextBox2.AppendText(LinkList.SearchTime + "\n");
            richTextBox2.AppendText(LinkList.InsertTime + "        ");
            richTextBox2.AppendText(LinkList.DeleteTime + "\n");
            richTextBox2.AppendText(LinkList.SpaceComplexity + "\n");
            richTextBox2.AppendText("*All Big-O values represent worst-case scenarios unless otherwise noted");

            //Displaying the Advantages and Disadvantages of Linked List to the Windows Form
            richTextBox1.AppendText("LINKED LIST: \n");
            richTextBox1.AppendText(LinkList.Advantages("A linked List is a data structure that represents a sequence of nodes.  " +
                                                        "In a singly linked list, each node points to the next node in the linked list.  " +
                                                        "A double linked list gives each pointers to both the next node and the previous node.  "));
            richTextBox1.AppendText("\n\n");
            richTextBox1.AppendText(LinkList.Disadvantages("Unlike an array a linked list does not provide " +
                                                           "constant time access to a particular “index” within the list.  " +
                                                           "In order to find the Kth element in a list you would have to iterate through K elements.  "));

            //Displaying extra notes from a rich text file in the bin
            using (StreamReader Reader = new StreamReader(@"C:\Users\Clayt\source\repos\CSC205\CSC205_StudyProject\CSC205_StudyProject\bin\LinkedList.rtf"))
            {
                while (!Reader.EndOfStream)
                {
                    richTextBox5.AppendText(Reader.ReadLine());
                }
            }
        }
        internal static UnphasedExpansion GetInstance(LinkedList1 <UOPair <HlaMsr1> > unphase, double prob, bool usedLowerResModel, string badHlaNameOrNull)
        {
            UnphasedExpansion unphasedExpansion = new UnphasedExpansion();

            unphasedExpansion.Unphrase          = unphase;
            unphasedExpansion.Prob              = prob;
            unphasedExpansion.UsedLowerResModel = usedLowerResModel;
            unphasedExpansion.BadHlaNameOrNull  = badHlaNameOrNull;
            return(unphasedExpansion);
        }
        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);
        }
示例#5
0
        public List <Dictionary <HlaMsr1, double> > PullOutTheRowsOfInterest(LinkedList1 <HlaMsr1> linkedList1)
        {
            List <Dictionary <HlaMsr1, double> > rowsOfInterst = new List <Dictionary <HlaMsr1, double> >();

            rowsOfInterst.Add(PredictorNameOrInterceptToTargetToWeight[""]); //The intercept
            if (null != linkedList1)
            {
                foreach (HlaMsr1 predictorHla in linkedList1)
                {
                    Dictionary <HlaMsr1, double> rowOfInterest;
                    if (PredictorNameOrInterceptToTargetToWeight.TryGetValue(predictorHla.ToString(/*withParen*/ false), out rowOfInterest))
                    {
                        rowsOfInterst.Add(rowOfInterest);
                    }
                }
            }
            return(rowsOfInterst);
        }
        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 void CreateNoAnswerAnswer(PidAndHlaSet pidAndHlaSet, HlaNotInModelException e)
        {
            PhaseToLogProb   = new Dictionary <UOPair <LinkedList1 <HlaMsr1> >, double>();
            UnphaseToLogProb = new Dictionary <LinkedList1 <UOPair <HlaMsr1> >, double>();

            BadHlaMsr1NameOrNull = e.HlaName;
            UsedLowerResModel    = true;

            var phaseGrounded = UOPair <LinkedList1 <HlaMsr1> > .GetInstance(
                LinkedList1 <HlaMsr1> .GetInstanceFromList(pidAndHlaSet.HlaUopairList.Select(pair => pair.First).ToList()),
                LinkedList1 <HlaMsr1> .GetInstanceFromList(pidAndHlaSet.HlaUopairList.Select(pair => pair.Second).ToList())
                );

            var unphasedGrounded = pidAndHlaSet.HlaUopairList;

            double logProb = double.NaN;

            LogSum(PhaseToLogProb, phaseGrounded, logProb);
            LogSum(UnphaseToLogProb, unphasedGrounded, logProb);
        }
        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);
        }
示例#9
0
        public void CanReturnAscending()
        {
            // Arrange
            LinkedList1 l1 = new LinkedList1();

            l1.Insert(8);
            l1.Insert(8);
            l1.Insert(3);
            l1.Insert(2);
            l1.Insert(1);

            // Act


            string value = l1.AscendingDescendingOrNone(l1).ToString();

            string expected = "Ascending to code heaven";

            // Assert
            Assert.Equal(expected, value);
        }
示例#10
0
        public void CanReturnNoneOfTheAbove()
        {
            // Arrange
            LinkedList1 l3 = new LinkedList1();

            l3.Insert(12);
            l3.Insert(9);
            l3.Insert(7);
            l3.Insert(10);
            l3.Insert(10);

            // Act


            string value = l3.AscendingDescendingOrNone(l3).ToString();

            string expected = "None of the above";

            // Assert
            Assert.Equal(expected, value);
        }
示例#11
0
        public void CanReturnDescending()
        {
            // Arrange
            LinkedList1 l2 = new LinkedList1();

            l2.Insert(1);
            l2.Insert(1);
            l2.Insert(1);
            l2.Insert(9);
            l2.Insert(10);

            // Act


            string value = l2.AscendingDescendingOrNone(l2).ToString();

            string expected = "Descending to madness";

            // Assert
            Assert.Equal(expected, value);
        }
        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)));
                    }
                }
            }
        }
示例#13
0
        static private Dictionary <string, Ethnicity> Init()
        {
            Dictionary <string, Ethnicity> ethnicityNameToEthnicity = new Dictionary <string, Ethnicity>();

            using (TextReader textReader = Linkdis.OpenResource("datafileList.txt"))
            {
                foreach (var row in SpecialFunctions.ReadDelimitedFile(textReader, new { Ethnicity = "", Class = "", HlaLengthList = "", FileName = "" }, new char[] { '\t' }, true))
                {
                    Ethnicity ethnicity          = ethnicityNameToEthnicity.GetValueOrDefault(row.Ethnicity.ToLowerInvariant());
                    EClass    eclass             = ethnicity.HlaClassNameToEClass.GetValueOrDefault(row.Class);
                    var       hlaLengthListQuery =
                        from hlaLengthAsString in row.HlaLengthList.Split(' ')
                        select int.Parse(hlaLengthAsString);

                    LinkedList1 <int> hlaLengthList = LinkedList1 <int> .GetInstanceFromList(hlaLengthListQuery.ToList());


                    TableInfo tableInfo = eclass.HlaLengthListToTableInfo.GetValueOrDefault(hlaLengthList);
                    tableInfo.HlaMsr1Factory = HlaMsr1Factory.GetFactory(hlaLengthList);
                    tableInfo.LoadTable(row.FileName, row.Class);
                }
            }
            return(ethnicityNameToEthnicity);
        }
        private IEnumerable <KeyValuePair <HlaMsr1, double> > ExpandHla(TableInfo tableInfo, HlaMsr1 hlaAbstractOrGround, LinkedList1 <HlaMsr1> linkedList1)
        {
            HashSet <HlaMsr1> groundSet = new HashSet <HlaMsr1>();

            foreach (HlaMsr1 term in hlaAbstractOrGround.TermList(tableInfo.HlaMsr1Factory))
            {
                List <HlaMsr1> groundHlaList;
                if (tableInfo.AbstractHlaToGroundHlaList.TryGetValue(term, out groundHlaList))
                {
                    if (groundHlaList.Count == 1 && groundHlaList.First().Equals(term))
                    {
                        groundSet.AddNew(term);
                    }
                    else
                    {
                        foreach (HlaMsr1 ground in groundHlaList)
                        {
                            groundSet.AddNew(ground);
                        }
                    }
                }
            }

            if (groundSet.Count == 0)
            {
                yield break;
            }


            List <Dictionary <HlaMsr1, double> > rowsOfInterest = tableInfo.PullOutTheRowsOfInterest(linkedList1);
            //!!!for each list of rowsOfInterest we could cache the sum of exp's to speed things up


            //!!!This could be made faster by giving a serial number to each HLA and then doing the calcuations in arrays in which the serial number is the index.
            Dictionary <HlaMsr1, double> hlaToTotal = new Dictionary <HlaMsr1, double>();

            foreach (Dictionary <HlaMsr1, double> hlaToWeight in rowsOfInterest)
            {
                foreach (KeyValuePair <HlaMsr1, double> hlaAndWeight in hlaToWeight)
                {
                    hlaToTotal[hlaAndWeight.Key] = hlaToTotal.GetValueOrDefault(hlaAndWeight.Key) + hlaAndWeight.Value;
                }
            }
            Dictionary <HlaMsr1, double> hlaToExpTotal = new Dictionary <HlaMsr1, double>();
            double totalOfExpsPlus1 = 1;

            foreach (KeyValuePair <HlaMsr1, double> hlaAndTotal in hlaToTotal)
            {
                double exp = Math.Exp(hlaAndTotal.Value);
                totalOfExpsPlus1 += Math.Exp(hlaAndTotal.Value);
                hlaToExpTotal.Add(hlaAndTotal.Key, exp);
            }



            foreach (HlaMsr1 hlaGround in groundSet)
            {
                double prob = hlaToExpTotal[hlaGround] / totalOfExpsPlus1;
                yield return(new KeyValuePair <HlaMsr1, double>(hlaGround, prob));
            }
        }
示例#15
0
        static void Main(string[] args)
        {
            LinkedList1 <int> list1 = new LinkedList1 <int>();

            try
            {
                list1.ListAdded += delegate(object o, ArrayChangedEvent <int> arg)
                {
                    Console.WriteLine($"A new data was added to the list: {arg.Data}");
                };
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }

            Console.WriteLine("Add 1, 2, 3");
            try
            {
                list1.Add(1);
                list1.Add(2);
                list1.Add(3);
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }


            Console.WriteLine("Add 5 after 1");
            list1.Insert(0, 5);
            foreach (int l in list1)
            {
                Console.WriteLine($"{l}");
            }

            Console.WriteLine("Add 7 after 5, 7 after 2 and 7 in the end");
            try
            {
                list1.Insert(2, 7);
                list1.Insert(4, 7);
                list1.Add(7);
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }

            foreach (int l in list1)
            {
                Console.WriteLine($"{l}");
            }

            Console.WriteLine("Remove first 7");
            try
            {
                list1.ListRemoved += delegate(object o, ArrayChangedEvent <int> arg)
                {
                    Console.WriteLine($"A data removed: {arg.Data}");
                };
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }

            try
            {
                list1.Remove(7);
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }

            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }

            foreach (int l in list1)
            {
                Console.WriteLine($"{l}");
            }


            Console.WriteLine("Remove all data \'7\'");
            try
            {
                list1.RemoveAll(7);
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }

            foreach (int l in list1)
            {
                Console.WriteLine($"{l}");
            }

            Console.WriteLine("Remove index 2");
            try
            {
                list1.RemoveAt(2);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }

            foreach (int l in list1)
            {
                Console.WriteLine($"{l}");
            }

            Console.WriteLine("Remove index 5");
            list1.RemoveAt(5);
            foreach (int l in list1)
            {
                Console.WriteLine($"{l}");
            }

            Console.WriteLine("Add 6, 1, 7, 8, 4, 2, 1, 9");
            try
            {
                list1.Add(6);
                list1.Add(1);
                list1.Add(7);
                list1.Add(8);
                list1.Add(4);
                list1.Add(2);
                list1.Add(1);
                list1.Add(9);
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }


            Console.WriteLine("Print first element");
            try
            {
                list1.ListFirst += delegate(object o, ArrayChangedEvent <int> arg)
                {
                    Console.WriteLine($"First element: {arg.Data}");
                };
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }

            try
            {
                list1.First();
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }

            Console.WriteLine("Print last element");
            try
            {
                list1.ListLast += delegate(object o, ArrayChangedEvent <int> arg)
                {
                    Console.WriteLine($"Last element: {arg.Data}");
                };
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }
            try
            {
                list1.Last();
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }

            foreach (int l in list1)
            {
                Console.WriteLine($"{l}");
            }
            Console.WriteLine("Find index of data \'8\' and \'6\'");
            try
            {
                Console.WriteLine($"Index of '8': {list1.IndexOf(8)}");
                Console.WriteLine($"Index of '6': {list1.IndexOf(6)}");
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }


            Console.WriteLine("Find all data \'1\'");
            try
            {
                foreach (int l in list1.FindAll(1))
                {
                    Console.WriteLine($"{l}");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }

            Console.WriteLine("Find index of data \'1\' after index 3");
            try
            {
                Console.WriteLine($"Index of '1': {list1.IndexOf(1, 3)}");
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }


            Console.WriteLine("Clear");
            try
            {
                list1.ListCleared += delegate
                {
                    Console.WriteLine("List cleared");
                };
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }

            try
            {
                list1.Clear();
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }


            Console.WriteLine("Remove data \'1\'");
            try
            {
                list1.ListRemoved += delegate
                {
                    Console.WriteLine("No data to remove");
                };
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }
            try
            {
                list1.Remove(1);
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }

            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }


            Console.ReadKey();
        }
        internal Dictionary <LinkedList1 <HlaMsr1>, KeyValuePair <double, bool> > CreateHlaListToProb(LinkedList1 <HlaMsr1> hlaListAbstractOrGround)
        {
            var hlaListGroundAndProbEnum = ExpandHlaList(hlaListAbstractOrGround);

            return(hlaListGroundAndProbEnum.ToDictionary(hlaListGroundAndProb => hlaListGroundAndProb.Key, hlaListGroundAndProb => hlaListGroundAndProb.Value));
        }
        private IEnumerable <KeyValuePair <HlaMsr1, KeyValuePair <double, bool> > > ExpandHla(HlaMsr1 hlaAbstractOrGround, LinkedList1 <HlaMsr1> linkedList1)
        {
            //Reference: http://en.wikipedia.org/wiki/Multinomial_logit#Model

            //Dictionary<string, Dictionary<HlaMsr1, double>> predictorNameToTargetHlaToWeight = Ethnicity.ClassNamePredictorNameOrInterceptToTargetToWeight[hlaAbstractOrGround.ClassName];
            EClass eclass = Ethnicity.HlaClassNameToEClass[hlaAbstractOrGround.ClassName];


            bool usedLowerResModel = false;

            foreach (LinkedList1 <int> hlaLengthList in eclass.HlaLengthListSorted())
            {
                bool      anyReturned = false;
                TableInfo tableInfo   = eclass.HlaLengthListToTableInfo[hlaLengthList];
                foreach (var hlaAndProb in ExpandHla(tableInfo, hlaAbstractOrGround, linkedList1))
                {
                    anyReturned = true;
                    yield return(new KeyValuePair <HlaMsr1, KeyValuePair <double, bool> >(hlaAndProb.Key, new KeyValuePair <double, bool>(hlaAndProb.Value, usedLowerResModel)));
                }
                if (anyReturned)
                {
                    yield break; // really yield break, not yield return or return;
                }
                usedLowerResModel = true;
            }
            throw new HlaNotInModelException(hlaAbstractOrGround.Name, string.Format("Can't find {0} or any prefix in any model", hlaAbstractOrGround.ToString(/*withParen*/ true)));
        }