Ejemplo n.º 1
0
    public static double ComputeEarliestStartTime(Task t, Schedule schedule) {
      ScheduledTask previousTask = schedule.GetLastScheduledTaskForJobNr(t.JobNr);
      Resource affectedResource = schedule.Resources[t.ResourceNr];
      double lastMachineEndTime = affectedResource.TotalDuration;
      double previousJobTaskEndTime = 0;
      if (previousTask != null)
        previousJobTaskEndTime = previousTask.EndTime;

      return Math.Max(previousJobTaskEndTime, lastMachineEndTime);
    }
 public static Schedule Apply(int jobs, int resources, PWREncoding pwr, ItemList<Job> jobData) {
   var resultingSchedule = new Schedule(jobData[0].Tasks.Count);
   foreach (int jobNr in pwr.PermutationWithRepetition) {
     int i = 0;
     while (jobData[jobNr].Tasks[i].IsScheduled) i++;
     Task currentTask = jobData[jobNr].Tasks[i];
     double startTime = GTAlgorithmUtils.ComputeEarliestStartTime(currentTask, resultingSchedule);
     currentTask.IsScheduled = true;
     resultingSchedule.ScheduleTask(currentTask.ResourceNr, startTime, currentTask.Duration, currentTask.JobNr);
   }
   return resultingSchedule;
 }
Ejemplo n.º 3
0
 public static ItemList<Task> GetConflictSetForTask(Task conflictedTask, ItemList<Task> earliestTasksList, ItemList<Job> jobData, Schedule schedule) {
   ItemList<Task> result = new ItemList<Task>();
   double conflictedCompletionTime = ComputeEarliestCompletionTime(conflictedTask, schedule);
   result.Add(conflictedTask);
   foreach (Task t in earliestTasksList) {
     if (t.ResourceNr == conflictedTask.ResourceNr) {
       if (ComputeEarliestStartTime(t, schedule) < conflictedCompletionTime)
         result.Add(t);
     }
   }
   return result;
 }
Ejemplo n.º 4
0
 //earliest start time
 private Task ESTRule(ItemList<Task> tasks, Schedule schedule) {
   Task currentResult = RandomRule(tasks);
   double currentEST = double.MaxValue;
   foreach (Task t in tasks) {
     double est = GTAlgorithmUtils.ComputeEarliestStartTime(t, schedule);
     if (est < currentEST) {
       currentEST = est;
       currentResult = t;
     }
   }
   return currentResult;
 }
Ejemplo n.º 5
0
 public static Task GetTaskWithMinimalEC(ItemList<Task> earliestTasksList, Schedule schedule) {
   double minEct = double.MaxValue;
   Task result = null;
   foreach (Task t in earliestTasksList) {
     double ect = ComputeEarliestCompletionTime(t, schedule);
     if (ect < minEct) {
       result = t;
       minEct = ect;
     }
   }
   return result;
 }
Ejemplo n.º 6
0
    public override Schedule CreateScheduleFromEncoding(IScheduleEncoding encoding) {
      var solution = encoding as PWREncoding;
      if (solution == null) throw new InvalidOperationException("Encoding is not of type PWREncoding");

      var jobs = (ItemList<Job>)JobDataParameter.ActualValue.Clone();
      var resultingSchedule = new Schedule(jobs[0].Tasks.Count);
      foreach (int jobNr in solution.PermutationWithRepetition) {
        int i = 0;
        while (jobs[jobNr].Tasks[i].IsScheduled) i++;
        Task currentTask = jobs[jobNr].Tasks[i];
        double startTime = GTAlgorithmUtils.ComputeEarliestStartTime(currentTask, resultingSchedule);
        currentTask.IsScheduled = true;
        resultingSchedule.ScheduleTask(currentTask.ResourceNr, startTime, currentTask.Duration, currentTask.JobNr);
      }
      return resultingSchedule;
    }
Ejemplo n.º 7
0
 protected override double Evaluate(Schedule schedule) {
   return GetMeanTardiness(schedule, JobDataParameter.ActualValue);
 }
Ejemplo n.º 8
0
 public static double GetMeanTardiness(Schedule schedule, ItemList<Job> jobData) {
   return schedule.Resources
     .Select(r => Math.Max(0, r.Tasks.Last().EndTime - jobData[r.Tasks.Last().JobNr].DueDate))
     .Average();
 }
Ejemplo n.º 9
0
 private Schedule(Schedule original, Cloner cloner)
   : base(original, cloner) {
   this.Resources = cloner.Clone(original.Resources);
   this.Quality = cloner.Clone(original.Quality);
   this.lastScheduledTaskOfJob = new Dictionary<int, ScheduledTask>(original.lastScheduledTaskOfJob);
 }
Ejemplo n.º 10
0
 protected abstract double Evaluate(Schedule schedule);
Ejemplo n.º 11
0
 public static double ComputeEarliestCompletionTime(Task t, Schedule schedule) {
   return ComputeEarliestStartTime(t, schedule) + t.Duration;
 }
Ejemplo n.º 12
0
    public override Schedule CreateScheduleFromEncoding(IScheduleEncoding encoding) {
      var solution = encoding as PRVEncoding;
      if (solution == null) throw new InvalidOperationException("Encoding is not of type PWREncoding");

      var jobs = (ItemList<Job>)JobDataParameter.ActualValue.Clone();
      var resultingSchedule = new Schedule(jobs[0].Tasks.Count);

      //Reset scheduled tasks in result
      foreach (Job j in jobs) {
        foreach (Task t in j.Tasks) {
          t.IsScheduled = false;
        }
      }

      //GT-Algorithm
      //STEP 0 - Compute a list of "earliest operations"
      ItemList<Task> earliestTasksList = GTAlgorithmUtils.GetEarliestNotScheduledTasks(jobs);
      //int currentDecisionIndex = 0;
      while (earliestTasksList.Count > 0) {
        //STEP 1 - Get earliest not scheduled operation with minimal earliest completing time
        Task minimal = GTAlgorithmUtils.GetTaskWithMinimalEC(earliestTasksList, resultingSchedule);

        //STEP 2 - Compute a conflict set of all operations that can be scheduled on the machine the previously selected operation runs on
        ItemList<Task> conflictSet = GTAlgorithmUtils.GetConflictSetForTask(minimal, earliestTasksList, jobs, resultingSchedule);

        //STEP 3 - Select an operation from the conflict set (various methods depending on how the algorithm should work..)
        //Task selectedTask = SelectTaskFromConflictSet(conflictSet, solution.PriorityRulesVector [currentDecisionIndex++], solution.NrOfRules.Value);
        Task selectedTask = SelectTaskFromConflictSet(conflictSet, solution.PriorityRulesVector[minimal.JobNr], solution.NrOfRules.Value, resultingSchedule, jobs);

        //STEP 4 - Adding the selected operation to the current schedule
        selectedTask.IsScheduled = true;
        double startTime = GTAlgorithmUtils.ComputeEarliestStartTime(selectedTask, resultingSchedule);
        resultingSchedule.ScheduleTask(selectedTask.ResourceNr, startTime, selectedTask.Duration, selectedTask.JobNr);

        //STEP 5 - Back to STEP 1
        earliestTasksList = GTAlgorithmUtils.GetEarliestNotScheduledTasks(jobs);
      }

      return resultingSchedule;
    }
Ejemplo n.º 13
0
    private Task SelectTaskFromConflictSet(ItemList<Task> conflictSet, int ruleIndex, int nrOfRules, Schedule schedule, ItemList<Job> jobs) {
      if (conflictSet.Count == 1)
        return conflictSet[0];

      ruleIndex = ruleIndex % nrOfRules;
      switch (ruleIndex) {
        case 0: return FILORule(conflictSet);
        case 1: return ESTRule(conflictSet, schedule);
        case 2: return SPTRule(conflictSet);
        case 3: return LPTRule(conflictSet);
        case 4: return MWRRule(conflictSet, jobs);
        case 5: return LWRRule(conflictSet, jobs);
        case 6: return MORRule(conflictSet, jobs);
        case 7: return LORRule(conflictSet, jobs);
        case 8: return FIFORule(conflictSet);
        case 9: return RandomRule(conflictSet);
        default: return RandomRule(conflictSet);
      }
    }
Ejemplo n.º 14
0
    public Schedule CreateScheduleFromEncoding(JSMEncoding solution, ItemList<Job> jobData) {
      ItemList<Permutation> jobSequenceMatrix = solution.JobSequenceMatrix;

      var jobs = (ItemList<Job>)jobData.Clone();
      var resultingSchedule = new Schedule(jobs[0].Tasks.Count);

      //Reset scheduled tasks in result
      foreach (Job j in jobs) {
        foreach (Task t in j.Tasks) {
          t.IsScheduled = false;
        }
      }

      //GT-Algorithm
      //STEP 0 - Compute a list of "earliest operations"
      ItemList<Task> earliestTasksList = GTAlgorithmUtils.GetEarliestNotScheduledTasks(jobs);
      while (earliestTasksList.Count > 0) {
        //STEP 1 - Get earliest not scheduled operation with minimal earliest completing time
        Task minimal = GTAlgorithmUtils.GetTaskWithMinimalEC(earliestTasksList, resultingSchedule);
        int conflictedResourceNr = minimal.ResourceNr;
        Resource conflictedResource = resultingSchedule.Resources[conflictedResourceNr];

        //STEP 2 - Compute a conflict set of all operations that can be scheduled on the conflicted resource
        ItemList<Task> conflictSet = GTAlgorithmUtils.GetConflictSetForTask(minimal, earliestTasksList, jobs, resultingSchedule);

        //STEP 3 - Select a task from the conflict set
        int progressOnResource = conflictedResource.Tasks.Count;
        Task selectedTask = SelectTaskFromConflictSet(conflictedResourceNr, progressOnResource, conflictSet, jobSequenceMatrix);

        //STEP 4 - Add the selected task to the current schedule 
        selectedTask.IsScheduled = true;
        double startTime = GTAlgorithmUtils.ComputeEarliestStartTime(selectedTask, resultingSchedule);
        resultingSchedule.ScheduleTask(selectedTask.ResourceNr, startTime, selectedTask.Duration, selectedTask.JobNr);

        //STEP 5 - Back to STEP 1
        earliestTasksList = GTAlgorithmUtils.GetEarliestNotScheduledTasks(jobs);
      }

      return resultingSchedule;
    }
Ejemplo n.º 15
0
 protected override double Evaluate(Schedule schedule) {
   return GetMakespan(schedule);
 }
Ejemplo n.º 16
0
 public static double GetMakespan(Schedule schedule) {
   return schedule.Resources.Select(r => r.TotalDuration).Max();
 }