[6475] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16565] | 3 | * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6475] | 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;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
| 24 |
|
---|
| 25 | namespace HeuristicLab.Encodings.ScheduleEncoding {
|
---|
| 26 | public static class GTAlgorithmUtils {
|
---|
| 27 |
|
---|
| 28 | public static ItemList<Task> GetEarliestNotScheduledTasks(ItemList<Job> jobData) {
|
---|
| 29 | ItemList<Task> result = new ItemList<Task>();
|
---|
| 30 | foreach (Job j in jobData) {
|
---|
| 31 | foreach (Task t in j.Tasks) {
|
---|
| 32 | if (!t.IsScheduled) {
|
---|
| 33 | result.Add(t);
|
---|
| 34 | break;
|
---|
| 35 | }
|
---|
| 36 | }
|
---|
| 37 | }
|
---|
| 38 | return result;
|
---|
| 39 | }
|
---|
| 40 | public static Task GetTaskWithMinimalEC(ItemList<Task> earliestTasksList, Schedule schedule) {
|
---|
| 41 | double minEct = double.MaxValue;
|
---|
| 42 | Task result = null;
|
---|
| 43 | foreach (Task t in earliestTasksList) {
|
---|
| 44 | double ect = ComputeEarliestCompletionTime(t, schedule);
|
---|
| 45 | if (ect < minEct) {
|
---|
| 46 | result = t;
|
---|
| 47 | minEct = ect;
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
| 50 | return result;
|
---|
| 51 | }
|
---|
| 52 | public static ItemList<Task> GetConflictSetForTask(Task conflictedTask, ItemList<Task> earliestTasksList, ItemList<Job> jobData, Schedule schedule) {
|
---|
| 53 | ItemList<Task> result = new ItemList<Task>();
|
---|
| 54 | double conflictedCompletionTime = ComputeEarliestCompletionTime(conflictedTask, schedule);
|
---|
| 55 | result.Add(conflictedTask);
|
---|
| 56 | foreach (Task t in earliestTasksList) {
|
---|
| 57 | if (t.ResourceNr == conflictedTask.ResourceNr) {
|
---|
| 58 | if (ComputeEarliestStartTime(t, schedule) < conflictedCompletionTime)
|
---|
| 59 | result.Add(t);
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 | return result;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | public static double ComputeEarliestStartTime(Task t, Schedule schedule) {
|
---|
| 66 | ScheduledTask previousTask = schedule.GetLastScheduledTaskForJobNr(t.JobNr);
|
---|
| 67 | Resource affectedResource = schedule.Resources[t.ResourceNr];
|
---|
| 68 | double lastMachineEndTime = affectedResource.TotalDuration;
|
---|
| 69 | double previousJobTaskEndTime = 0;
|
---|
| 70 | if (previousTask != null)
|
---|
| 71 | previousJobTaskEndTime = previousTask.EndTime;
|
---|
| 72 |
|
---|
| 73 | return Math.Max(previousJobTaskEndTime, lastMachineEndTime);
|
---|
| 74 | }
|
---|
| 75 | public static double ComputeEarliestCompletionTime(Task t, Schedule schedule) {
|
---|
| 76 | return ComputeEarliestStartTime(t, schedule) + t.Duration;
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 | }
|
---|