[6406] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[11594] | 3 | * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6406] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
[6293] | 23 | using HeuristicLab.Core;
|
---|
[6406] | 24 | using HeuristicLab.Encodings.ScheduleEncoding;
|
---|
[6293] | 25 |
|
---|
[6406] | 26 | namespace HeuristicLab.Problems.Scheduling {
|
---|
[6293] | 27 | public static class GTAlgorithmUtils {
|
---|
| 28 |
|
---|
| 29 | public static ItemList<Task> GetEarliestNotScheduledTasks(ItemList<Job> jobData) {
|
---|
| 30 | ItemList<Task> result = new ItemList<Task>();
|
---|
| 31 | foreach (Job j in jobData) {
|
---|
| 32 | foreach (Task t in j.Tasks) {
|
---|
[6412] | 33 | if (!t.IsScheduled) {
|
---|
[6293] | 34 | result.Add(t);
|
---|
| 35 | break;
|
---|
| 36 | }
|
---|
| 37 | }
|
---|
| 38 | }
|
---|
| 39 | return result;
|
---|
| 40 | }
|
---|
| 41 | public static Task GetTaskWithMinimalEC(ItemList<Task> earliestTasksList, Schedule schedule) {
|
---|
| 42 | double minEct = double.MaxValue;
|
---|
| 43 | Task result = null;
|
---|
| 44 | foreach (Task t in earliestTasksList) {
|
---|
| 45 | double ect = ComputeEarliestCompletionTime(t, schedule);
|
---|
| 46 | if (ect < minEct) {
|
---|
| 47 | result = t;
|
---|
| 48 | minEct = ect;
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 | return result;
|
---|
| 52 | }
|
---|
| 53 | public static ItemList<Task> GetConflictSetForTask(Task conflictedTask, ItemList<Task> earliestTasksList, ItemList<Job> jobData, Schedule schedule) {
|
---|
| 54 | ItemList<Task> result = new ItemList<Task>();
|
---|
| 55 | double conflictedCompletionTime = ComputeEarliestCompletionTime(conflictedTask, schedule);
|
---|
| 56 | result.Add(conflictedTask);
|
---|
| 57 | foreach (Task t in earliestTasksList) {
|
---|
[6412] | 58 | if (t.ResourceNr == conflictedTask.ResourceNr) {
|
---|
[6293] | 59 | if (ComputeEarliestStartTime(t, schedule) < conflictedCompletionTime)
|
---|
| 60 | result.Add(t);
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 | return result;
|
---|
| 64 | }
|
---|
[6406] | 65 |
|
---|
[6293] | 66 | public static double ComputeEarliestStartTime(Task t, Schedule schedule) {
|
---|
[6412] | 67 | ScheduledTask previousTask = schedule.GetLastScheduledTaskForJobNr(t.JobNr);
|
---|
| 68 | Resource affectedResource = schedule.Resources[t.ResourceNr];
|
---|
| 69 | double lastMachineEndTime = affectedResource.TotalDuration;
|
---|
[6293] | 70 | double previousJobTaskEndTime = 0;
|
---|
| 71 | if (previousTask != null)
|
---|
[6412] | 72 | previousJobTaskEndTime = previousTask.EndTime;
|
---|
[6293] | 73 |
|
---|
| 74 | return Math.Max(previousJobTaskEndTime, lastMachineEndTime);
|
---|
| 75 | }
|
---|
| 76 | public static double ComputeEarliestCompletionTime(Task t, Schedule schedule) {
|
---|
[6412] | 77 | return ComputeEarliestStartTime(t, schedule) + t.Duration;
|
---|
[6293] | 78 | }
|
---|
| 79 | }
|
---|
| 80 | }
|
---|