Exemple #1
0
        private static long RunSort(Programmers programmer, Langs lang, sortAlgos algo, string pathToInput)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            //String command = programPath + "\" " + NameFromAlgo(algo) + " " + pathToInput;

            Process process = new Process();

            process.StartInfo.FileName = GetProgramPath(programmer, lang);
            if (programmer == Programmers.Andrew)
            {
                process.StartInfo.Arguments = GetOptionalFirstArg(programmer, lang) + " " + NameFromAlgo(programmer, algo) + " " + pathToInput;
            }
            else
            {
                process.StartInfo.Arguments = GetOptionalFirstArg(programmer, lang) + " " + pathToInput + " " + NameFromAlgo(programmer, algo);
            }
            process.Start();

            /*ProcessStartInfo cmdsi = new ProcessStartInfo("cmd.exe");
             * cmdsi.Arguments = command;
             * Process cmd = Process.Start(cmdsi);*/

            process.WaitForExit();

            watch.Stop();
            long elapsedMs = watch.ElapsedMilliseconds;

            return(elapsedMs);
        }
Exemple #2
0
        static bool ParseCmdArgs(string[] args, out sortAlgos sortAlgo, out string inputPath)
        {
            sortAlgo  = sortAlgos.NotYetSet;
            inputPath = "";

            if (args.Length < 2)
            {
                System.Console.WriteLine("Requires two arguments, only " + args.Length + " provided");
                System.Console.WriteLine("Correct Usage: Sort [insertion/bubble/merge] [C:\\Path\\To\\Input.file]");
                return(false);
            }

            string argAlgo = args[0];
            string argPath = args[1];

            switch (argAlgo)
            {
            case "insertion":
                sortAlgo = sortAlgos.Insertion;
                break;

            case "bubble":
                sortAlgo = sortAlgos.Bubble;
                break;

            case "merge":
                sortAlgo = sortAlgos.Merge;
                break;

            case "selection":
                sortAlgo = sortAlgos.Selection;
                break;

            default:
                System.Console.WriteLine(argAlgo + " is not a valid sorting algorithm.");
                System.Console.WriteLine("Correct Usage: Sort [insertion/bubble/merge] [C:\\Path\\To\\Input.file]");
                return(false);
            }

            if (File.Exists(argPath) == false)
            {
                System.Console.WriteLine("Specified input path invalid or does not exist.");
                System.Console.WriteLine("Correct Usage: Sort [insertion/bubble/merge] [C:\\Path\\To\\Input.file]");
                return(false);
            }
            inputPath = argPath;

            return(true);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            Random rand = new Random();

            int[,,] numTimesRun = new int[3, 2, 3];

            System.Console.WriteLine("algo\tprog\tlang\tresult");

            while (!Finished(numTimesRun, numIterations))
            {
                int algoNum;
                int progNum;
                int langNum;

                // Generate values randomly, ignoring them if they've already been done
                do
                {
                    algoNum = rand.Next(0, 3);
                    progNum = rand.Next(0, 2);
                    langNum = rand.Next(0, 3);
                } while (ComboDone(numTimesRun, numIterations, algoNum, progNum, langNum));

                numTimesRun[algoNum, progNum, langNum]++;

                sortAlgos   algo = (sortAlgos)algoNum;
                Programmers prog = (Programmers)progNum;
                Langs       lang = (Langs)langNum;

                long result = RunSort(prog, lang, algo, inputPath);

                System.Console.Write(algo.ToString() + "\t");
                System.Console.Write(prog.ToString() + "\t");
                System.Console.Write(lang.ToString() + "\t");
                System.Console.WriteLine(result);
            }

            System.Console.ReadKey();
            System.Console.ReadKey();
            System.Console.ReadKey();
        }
Exemple #4
0
        private static string NameFromAlgo(Programmers programmer, sortAlgos algo)
        {
            if (programmer == Programmers.Andrew)
            {
                switch (algo)
                {
                case sortAlgos.Insertion:
                    return("insertion");

                case sortAlgos.Bubble:
                    return("bubble");

                case sortAlgos.Merge:
                    return("merge");

                case sortAlgos.Selection:
                    return("selection");
                }
            }
            else
            {
                switch (algo)
                {
                case sortAlgos.Insertion:
                    return("1");

                case sortAlgos.Bubble:
                    return("2");

                case sortAlgos.Merge:
                    return("4");

                case sortAlgos.Selection:
                    return("3");
                }
            }

            return("");
        }