public void Run(string[] args) { string inputFileName = "../../Data/Project02/" + args[0]; string encodedFileName = "../../Data/Project02/" + args[1]; string decodedFileName = "../../Data/Project02/" + args[2]; // load input data Vector <char> inputData = null; DataSerializer <char> .LoadVectorFromTextFile(inputFileName, ref inputData); // create a coder HuffmanCoding coder = new HuffmanCoding(); // encode input data Vector <string> encodedData = null; encodedData = coder.Encode(inputData); // write the encoded data to file DataSerializer <string> .SaveVectorToTextFile(encodedFileName, encodedData); // reload the encoded data from file DataSerializer <string> .LoadVectorFromTextFile(encodedFileName, ref encodedData); // decode the encoded data Vector <char> decodedData = null; decodedData = coder.Decode(encodedData); // write the decoded data to file DataSerializer <char> .SaveVectorToTextFile(decodedFileName, decodedData); // reload the decodedData from file DataSerializer <char> .LoadVectorFromTextFile(decodedFileName, ref decodedData); // validating the coding result, i.e. checking whether inputData = decodedData if (inputData.Count != decodedData.Count) { Console.WriteLine("Input data is not identical to decoded data -- Coding method does not work accurately!"); } else { int i; for (i = 0; i < inputData.Count; i++) { if (!inputData[i].Equals(decodedData[i])) { Console.WriteLine("Input data is not identical to decoded data -- Coding method does not work accurately!"); break; } } if (i == inputData.Count) { Console.WriteLine("Coding method works accurately!"); } } Console.Read(); }
public void Run(string[] args) { string inputFilename = "../../Data/Project01/" + args[0]; string bubbleSortOutputFilename = "../../Data/Project01/" + "BubbleSort_" + args[0]; string quickSortOutputFilename = "../../Data/Project01/" + "QuickSort_" + args[0]; Vector <int> vector = null; DataSerializer <int> .LoadVectorFromTextFile(inputFilename, ref vector); if (vector == null) { Console.WriteLine("Failed to load data from input file"); return; } //let's check the capacity & count now Console.WriteLine("Vector Capacity is {0}", vector.Capacity); Console.WriteLine("Vector Count is {0}", vector.Count); //Let's sort Vector in ascending order using Bubble Sort algorithm var memBefore1 = Process.GetCurrentProcess().WorkingSet64; Stopwatch s1 = new Stopwatch(); s1.Start(); Vector <int> bubbleSortedIndices = vector.BubbleSortIndex(); s1.Stop(); var memAfter1 = Process.GetCurrentProcess().WorkingSet64; Console.WriteLine("execution time of Bubble Sort = " + s1.ElapsedMilliseconds + ", and memory =" + (memAfter1 - memBefore1) / 1024.0); // write the sorted indices to file Console.WriteLine("Data has been sorted using Bubble Sort algorithm"); DataSerializer <int> .SaveVectorToTextFile(bubbleSortOutputFilename, bubbleSortedIndices); Console.WriteLine(string.Format("Result of Bubble Sort algorithm has been stored to {0}", bubbleSortOutputFilename)); //Let's sort Vector in ascending order using Quick Sort algorithm var memBefore2 = Process.GetCurrentProcess().WorkingSet64; Stopwatch s2 = new Stopwatch(); s2.Start(); Vector <int> quickSortedIndices = vector.QuickSortIndex(); s2.Stop(); var memAfter2 = Process.GetCurrentProcess().WorkingSet64; Console.WriteLine("execution time of Quick Sort = " + s2.ElapsedMilliseconds + ", and memory =" + (memAfter2 - memBefore2) / 1024.0); // write the sorted indices to file Console.WriteLine("Data has been sorted using Quick Sort algorithm"); DataSerializer <int> .SaveVectorToTextFile(quickSortOutputFilename, quickSortedIndices); Console.WriteLine(string.Format("Result of Quick Sort algorithm has been stored to {0}", quickSortOutputFilename)); Console.Read(); }
public void Run(string[] args) { //Note: args[0] is the input file name -- make sure to change it as needed, currently 1H.txt if (args.Length < 1) { Console.WriteLine("input file name is missing"); return; } Vector <int> vector = null; string inputFileName = args[0]; string outputFileName = "S_1H.txt"; DataSerializer <int> .LoadVectorFromTextFile(inputFileName, ref vector); if (vector == null) { Console.WriteLine("Failed to load data from input file"); return; } //let's check the capacity & count now Console.WriteLine("Vector Capacity is {0}", vector.Capacity); Console.WriteLine("Vector Count is {0}", vector.Count); //Let's sort Vector elements ascending? var memBefore = Process.GetCurrentProcess().WorkingSet64; Stopwatch s = new Stopwatch(); s.Start(); vector.Sort(); s.Stop(); var memAfter = Process.GetCurrentProcess().WorkingSet64; Console.WriteLine("cpu = " + s.ElapsedMilliseconds + ", and memory =" + (memAfter - memBefore) / 1024.0 + " memory before =" + memBefore + ", and memory after = " + memAfter); Console.WriteLine("Data has been sorted"); DataSerializer <int> .SaveVectorToTextFile(outputFileName, vector); Console.WriteLine(string.Format("Data has been stored to {0}", outputFileName)); //Now can we try to sort the vector elements descending? Console.Read(); }
public void Run(string[] args) { if (args.Length < 2) { Console.WriteLine("Expected two params"); return; } string inputFilename = "../../Data/Week01/" + args[0]; SortingAlgorithm sortingAlgorithm = (SortingAlgorithm)Enum.Parse(typeof(SortingAlgorithm), args[1]); string outputFilename = "../../Data/Week01/" + args[1] + "_" + args[0]; Vector <int> vector = null; DataSerializer <int> .LoadVectorFromTextFile(inputFilename, ref vector); if (vector == null) { Console.WriteLine("Failed to load data from input file"); return; } //let's check the capacity & count now Console.WriteLine("Vector Capacity is {0}", vector.Capacity); Console.WriteLine("Vector Count is {0}", vector.Count); //Let's sort Vector elements ascending? var memBefore = Process.GetCurrentProcess().WorkingSet64; Stopwatch s = new Stopwatch(); s.Start(); vector.Sort(sortingAlgorithm); //This is the same as calling vector.Sort with an ascending order comparer s.Stop(); var memAfter = Process.GetCurrentProcess().WorkingSet64; Console.WriteLine("execution time = " + s.ElapsedMilliseconds + ", and memory =" + (memAfter - memBefore) / 1024.0); DataSerializer <int> .SaveVectorToTextFile(outputFilename, vector); Console.ReadLine(); }
public void Run(string[] args) { //Note: args[0] is the input file name -- make sure to change it as needed, currently 1H.txt if (args.Length < 1) { Console.WriteLine("input file name is missing"); return; } Vector <int> vector = null; string inputFileName = args[0]; string outputFileName = "S_1H.txt"; DataSerializer <int> .LoadVectorFromTextFile(inputFileName, ref vector); if (vector == null) { Console.WriteLine("Failed to load data from input file"); return; } //let's check the capacity & count now Console.WriteLine("Vector Capacity is {0}", vector.Capacity); Console.WriteLine("Vector Count is {0}", vector.Count); //Let's sort Vector elements ascending? // Task 1 c vector.Sort(); Console.WriteLine("Data has been sorted"); DataSerializer <int> .SaveVectorToTextFile(outputFileName, vector); Console.WriteLine(string.Format("Data has been stored to {0}", outputFileName)); Console.Read(); }
public void Run(string[] args) { //Note: args[0] is the input file name -- make sure to change it as needed, currently 1H.txt if (args.Length < 2) { Console.WriteLine("input and/or output file name(s) is(are) missing"); return; } Vector <int> vector = null; string inputFileName = args[0]; string outputFileName = args[1]; DataSerializer <int> .LoadVectorFromTextFile(inputFileName, ref vector); if (vector == null) { Console.WriteLine("Failed to load data from input file"); return; } // check the state of capacity and count properties Console.WriteLine("Vector Capacity is {0}", vector.Capacity); Console.WriteLine("Vector Count is {0}", vector.Count); Console.WriteLine(vector); vector.Sort(); Console.WriteLine(vector); DataSerializer <int> .SaveVectorToTextFile(outputFileName, vector); Console.WriteLine(string.Format("Data has been stored to {0}", outputFileName)); Console.Read(); }
public void Run(string[] args) { if (args.Length < 2) { Console.WriteLine("Expected two params"); return; } string inputFilename = "../../Data/Project01/" + args[0]; SortingAlgorithm sortingAlgorithm = (SortingAlgorithm)Enum.Parse(typeof(SortingAlgorithm), args[1]); string outputFilename = "../../Data/Project01/" + "S_" + args[0]; Vector <int> vector = null; DataSerializer <int> .LoadVectorFromTextFile(inputFilename, ref vector); if (vector == null) { Console.WriteLine("Failed to load data from input file"); return; } //let's check the capacity & count now Console.WriteLine("Vector Capacity is {0}", vector.Capacity); Console.WriteLine("Vector Count is {0}", vector.Count); ///// var averageMemory = 0; var totalMemory = 0; Stopwatch s = new Stopwatch(); s.Start(); long memBefore = 0; long memAfter = 0; for (int i = 0; i < 5; i++) { GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); memBefore = Process.GetCurrentProcess().WorkingSet64; vector.Sort(sortingAlgorithm); //This is the same as calling vector.Sort with an ascending order comparer memAfter = Process.GetCurrentProcess().WorkingSet64; totalMemory += (int)memAfter - (int)memBefore; } s.Stop(); averageMemory = totalMemory / 5; Console.WriteLine("execution time = " + s.ElapsedMilliseconds + ", and memory =" + averageMemory / 1024.0); /// //Let's sort Vector elements ascending? memBefore = Process.GetCurrentProcess().WorkingSet64; GC.Collect(); memAfter = Process.GetCurrentProcess().WorkingSet64; Console.WriteLine("memory =" + (memAfter - memBefore) / 1024.0); memBefore = Process.GetCurrentProcess().WorkingSet64; //100M s = new Stopwatch(); s.Start(); vector.Sort(sortingAlgorithm); //This is the same as calling vector.Sort with an ascending order comparer //GC clean 80M s.Stop(); memAfter = Process.GetCurrentProcess().WorkingSet64; //102M //102-100 //102 - 80 not very accurate!!!! Console.WriteLine("execution time = " + s.ElapsedMilliseconds + ", and memory =" + (memAfter - memBefore) / 1024.0); DataSerializer <int> .SaveVectorToTextFile(outputFilename, vector); }
public void Run(string[] args) { SetClass <SetClass <int> > ps = new SetClass <SetClass <int> >(new Vector <SetClass <int> >()); ps.Data.Add(new SetClass <int>(new Vector <int>())); ps.Data[0].Data.Add(1); ps.Data[0].Data.Add(2); ps.Data.Add(new SetClass <int>(new Vector <int>())); ps.Data[1].Data.Add(3); ps.Data[1].Data.Add(4); ps.Data.Add(new SetClass <int>(new Vector <int>())); ps.Data[2].Data.Add(5); string s = ps.ToString(); Vector <Tuple <int, int> > abc = new Vector <Tuple <int, int> >(); abc.Add(new Tuple <int, int>(3, 4)); if (args.Length < 2) { Console.WriteLine("Expected at least two params"); return; } string opName = args[0]; OperationEnum op = (OperationEnum)Enum.Parse(typeof(OperationEnum), opName); string setAPath = "../../Data/Project01/" + args[1]; SetClass <int> setB = null; int element = 0; if (op == OperationEnum.MEMBERSHIP) { element = int.Parse(args[2]); } else if (args.Length == 3) { string setBPath = "../../Data/Project01/" + args[2]; Vector <int> setBData = null; DataSerializer <int> .LoadVectorFromTextFile(setBPath, ref setBData); if (setBData == null) { Console.WriteLine("Failed to load data from input file"); return; } setB = new SetClass <int>(setBData); } Vector <int> setAData = null; DataSerializer <int> .LoadVectorFromTextFile(setAPath, ref setAData); if (setAData == null) { Console.WriteLine("Failed to load data from input file"); return; } SetClass <int> setA = new SetClass <int>(setAData); switch (op) { case OperationEnum.CARTESIAN: Console.WriteLine( string.Format("Cartesian of SetA- {0}, Set B- {1}, is = {2} ", setA.Data.ToString(), setB.Data.ToString(), setA.CartesianProduct <int>(setB).Data.ToString() ) ); break; case OperationEnum.MEMBERSHIP: Console.WriteLine(string.Format("Check membership of {0}, is {1}", element, setA.Membership(element))); break; case OperationEnum.SUBSET: Console.WriteLine(string.Format("Check subset of {0} in {1}, and result = {2}", setA.Data.ToString(), setB.Data.ToString(), setA.IsSubsetOf(setB) ) ); break; case OperationEnum.INTERESECTION: var setC = setA.IntersectionWith(setB); Console.WriteLine(string.Format("Interesection of A- {0}, with B- {1} is {2}", setA.Data.ToString(), setB.Data.ToString(), setC.Data.ToString() )); DataSerializer <int> .SaveVectorToTextFile("f1.txt", setC.Data); break; case OperationEnum.SUPERSET: Console.WriteLine(string.Format("Check power of {0}, result = {1}", setA.Data.ToString(), setA.Powerset() )); break; } }