Beta

Round Robin Job Scheduler

Description
Loading description...
Scheduling
Algorithms
  • Please sign in or sign up to leave a comment.
  • mortonfox Avatar

    I would like an explanation/clarification for the DifferentStartTimes test:

    public void DifferentStartTimes()
        {
            var startTime = new DateTime(2007, 11, 5);
            var tasks = new List<Job>() {
              new Job(Guid.NewGuid(), startTime, TimeSpan.FromSeconds(5)),
              new Job(Guid.NewGuid(), startTime + TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(5)),
              new Job(Guid.NewGuid(), startTime + TimeSpan.FromSeconds(4), TimeSpan.FromSeconds(5)),
            };
    
            var schedule = RoundRobinScheduler.CreateSchedule(startTime, TimeSpan.FromSeconds(3), new List<Job>(tasks));
    
            Assert.That(schedule.Count, Is.EqualTo(6));
            Assert.Multiple(() =>
            {
                Assert.That(schedule[0], Is.EqualTo(new Timeslot(tasks[0].Name, TimeSpan.FromSeconds(3), TimeslotType.Job)),"Timeslot 0");
                Assert.That(schedule[1], Is.EqualTo(new Timeslot(tasks[1].Name, TimeSpan.FromSeconds(3), TimeslotType.Job)),"Timeslot 1");
                Assert.That(schedule[2], Is.EqualTo(new Timeslot(tasks[0].Name, TimeSpan.FromSeconds(2), TimeslotType.Job)),"Timeslot 2");
                Assert.That(schedule[3], Is.EqualTo(new Timeslot(tasks[2].Name, TimeSpan.FromSeconds(3), TimeslotType.Job)),"Timeslot 3");
                Assert.That(schedule[4], Is.EqualTo(new Timeslot(tasks[1].Name, TimeSpan.FromSeconds(2), TimeslotType.Job)),"Timeslot 4");
                Assert.That(schedule[5], Is.EqualTo(new Timeslot(tasks[2].Name, TimeSpan.FromSeconds(2), TimeslotType.Job)),"Timeslot 5");
            });
        }
    

    After doing task 0 and task 1, it is now startTime + 6 seconds.

    However, after running their timeslots, tasks 0 and 1 are at the end of the job list. So task 2 is next on deck.

    Since task 2's arrival time is startTime + 4 seconds, which is less than the current time after the first two timeslots, why can't we run it instead of running task 0 again?

    • Voile Avatar

      New tasks are only put into the queue when they arrive. You cannot predict the future, so this cannot be done before their arrival time.

      At t = 0: The queue is [], running task0

      At t = 2: task1 arrives, the queue is [task1]

      At t = 3: window finishes but task0 is not done yet, put task0 at the end; task1 is now executed, the queue is [task0]

      At t = 4: task2 arrives, the queue is [task0, task2]

      At t = 6: window finishes but task1 is not done yet, put task1 at the end; task0 is now executed, the queue is [task2, task1]

      ...

    • mortonfox Avatar
      Question marked resolved by mortonfox 2 years ago
  • mortonfox Avatar

    Please update the struct definition in the description:

        public struct Job
        {
            public Guid Name { get; private set; }
            public TimeSpan TimeToPerform { get; set; }
            public DateTime StartTime { get; }
            public Job(Guid name, TimeSpan timeToPerform, DateTime startTime)
            {
                Name = name;
                TimeToPerform = timeToPerform;
                StartTime = startTime;
            }
        }
    

    It appears that StartTime is now ArrivalTime instead.

  • Voile Avatar

    What happens if a task has just executed till the end of the window (and is scheduled to be moved to the end of the list) when there is another task that arrives at the same time? Which task should be queued first?

    • MacStan Avatar

      Good point, I've added explicit instruction in the description - new task should be added before the one that has just finished. I've also added new test case for this.

    • MacStan Avatar

      Forgot to mark issue as resolved.

      Issue marked resolved by MacStan 2 years ago
  • Voile Avatar
    src/Solution.cs(6,22): error CS0246: The type or namespace name 'ScheduleRecord' could not be found (are you missing a using directive or an assembly reference?)
    

    Is ScheduleRecord not pre-defined?

    Also, the actual fields in ScheduleRecord is different from what is provided in the description:

        public readonly record struct ScheduleRecord(Guid Name, TimeSpan Time, bool IsWait);
    

    It is actually

        public readonly record struct ScheduleRecord(Guid Name, TimeSpan ExecutionTime, TimeslotType Type);
    

    Job also has different fields specified at the top and at the bottom.

    • Voile Avatar

      Actual tests apparently uses Timeslot instead, and random tests apparently uses its own Timeslot. Note that two record struct defined in different places but with the same fields are not considered equality comparable, so Timeslot should be defined somewhere else (in a same namespace. Why aren't all the classes namespaced?) and provided to the user.

    • MacStan Avatar

      Thanks for pointing this out. I've done some renaming before publishing and forgotten to update the description. Description should be ok now. There is only one Timeslot used both by solution and test cases, it's in preloaded classes. I've ommited namespaces as they are not neccessary and only take space in this case. Is there any advantage they provide?

    • MacStan Avatar

      Forgot to mark issue as resolved.

      Issue marked resolved by MacStan 2 years ago