Exemplo n.º 1
0
        /// <summary>
        /// To get next process process that shoulb be processed
        /// based on length of execution, shortest first
        /// </summary>
        /// <param name="jobQueue">job queue (jobs that need to be processed)</param>
        /// <param name="time">time used by dispatcher</param>
        /// <returns>return shortest process</returns>
        private Job NextShortestProcess(Queue<Job> jobQueue, int time)
        {
            Job job = new Job();
            int shortest = int.MaxValue;

            foreach (Job jobElt in jobQueue)
            {
                if (jobElt.arrivalTime <= time)
                {
                    if (jobElt.executionTime < shortest && jobElt.executionTime != 0)
                    {
                        job = jobElt;
                        shortest = jobElt.executionTime;
                    }
                }
            }

            return job;
        }
Exemplo n.º 2
0
        /// <summary>
        /// To get data from text file and populate job queue with those data
        /// </summary>
        /// <param name="filename">file name of text file</param>
        /// <returns>job queue populated by jobs from text file</returns>
        private Queue<Job> GetData(string filename)
        {
            Queue<Job> jobQueue = new Queue<Job>();

            if (File.Exists(filename))
            {
                FileStream inFile = new FileStream(filename, FileMode.Open, FileAccess.Read);
                StreamReader reader = new StreamReader(inFile);

                string line = reader.ReadLine();
                string[] tag = null;
                int counter = 1;
                char[] delim = { '!', '\t', '@', ' '};

                while (line != null)
                {
                    if (line == "")
                    {
                        line = reader.ReadLine();
                        continue;
                    }

                    tag = line.Split(delim, StringSplitOptions.RemoveEmptyEntries);

                    if (tag[0].StartsWith("#") || tag.Count() == 0)
                    {
                        line = reader.ReadLine();
                        continue;
                    }

                    Job job = new Job("Job " + counter, int.Parse(tag[0]), int.Parse(tag[1]));
                    jobQueue.Enqueue(job);

                    line = reader.ReadLine();
                    counter++;
                }

                reader.Close();
                inFile.Close();
            }
            else
                Console.WriteLine("File is not found...");

            return jobQueue;
        }