/// <summary> /// A method to display the minimum and maximum number of times a worker was scheduled. It should take no parameters and return nothing /// </summary> private void timesScheduled() { LinkedListCell <Worker> SearchCell = workerQueue.SetToFront(); int MAX = 0; int MIN = SearchCell.Data.TimesScheduled; // start value for the minimum int searchValue; try { while (true) { searchValue = SearchCell.Data.TimesScheduled; if (searchValue > MAX) { MAX = searchValue; } if (searchValue < MIN) { MIN = searchValue; } SearchCell = workerQueue.AdvanceElement(); } } catch (Exception) { MessageBox.Show("All Workers were scheduled at least " + MIN + " times and at most " + MAX + " times."); return; } }
// Advance the current element to the next element following the current element // If the current element is already past the end of the queue, it should do nothing public LinkedListCell <T> AdvanceElement() { if (pastEndQueue) { return(CurrentElement); } CurCellPreceding = CurCellPreceding.Next; return(CurCellPreceding.Next); }
/// <summary> /// A method to search the queue for the first worker qualified for a given task, and move that worker to the end of the queue. /// This method will take as its only parameter an int identifying the task. It will return the worker it found. If you get to /// the end of the queue without finding a qualified worker, throw an InvalidOperationException containing an appropriate message /// (you will need to use the constructor that takes a string parameter). /// </summary> private LinkedListCell <Worker> Search(int task) { LinkedListCell <Worker> SearchCell = workerQueue.SetToFront(); for (int i = 0; i < numberOfWorkers; i++) { if (SearchCell.Data.qualified(task)) { workerQueue.CurrentElement.Data.oneMoreTime(); return(SearchCell); } SearchCell = workerQueue.AdvanceElement(); } throw new InvalidOperationException("Unable to find Qualified worker for task " + task); }
// Enqueue an element at the back public void Enqueue(T x) { LinkedListCell <T> newCell = new LinkedListCell <T>(); newCell.Data = x; if (headerCell.Next == null) { headerCell.Next = newCell; lastCell = newCell; return; } // Incrememnt the Current Cell and set the new cell as the back cell CurCellPreceding = lastCell; lastCell.Next = newCell; lastCell = newCell; CurCellPreceding.Next = lastCell; }
/// <summary> /// Event Handler for Compute Schedule Button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void uxComputeSchedule_Click(object sender, EventArgs e) { string fileName = uxTextBox.Text; workerQueue = readInput(fileName); int daysTotal = (int)uxNumericUpDown.Value; if (uxSaveDialog.ShowDialog() == DialogResult.OK) { try { string saveFile = uxSaveDialog.FileName; using (StreamWriter output = new StreamWriter(saveFile)) { // Starts first row of CSV File output.Write(","); for (int i = 0; i < tasks; i++) { output.Write(i + ","); } output.WriteLine(); LinkedListCell <Worker> SearchCell = workerQueue.SetToFront(); for (int days = 1; days <= daysTotal; days++) { output.Write((days).ToString() + ','); for (int j = 0; j < tasks; j++) { SearchCell = Search(j); output.Write(SearchCell.Data.Name + ','); SearchCell = workerQueue.MoveToBack(); SearchCell = workerQueue.SetToFront(); } output.WriteLine(); } timesScheduled(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
// Move the current element to the back of the queue public LinkedListCell <T> MoveToBack() { if (pastEndQueue) { throw new InvalidOperationException(); } if (CurrentElement == lastCell) { return(CurrentElement); } lastCell.Next = CurrentElement; CurCellPreceding.Next = CurrentElement.Next; lastCell = lastCell.Next; lastCell.Next = null; return(CurrentElement); }
// Set the current element to be the element at the front of the queue public LinkedListCell <T> SetToFront() { CurCellPreceding = headerCell; return(CurCellPreceding.Next); }
// Initial Searchable Queue construction public SearchableQueue() { CurCellPreceding = headerCell; lastCell = headerCell; }