Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.Scheduling/3.3/Decoders/GTAlgorithmUtils.cs @ 10744

Last change on this file since 10744 was 9462, checked in by swagner, 12 years ago

Updated copyright year and incremented version of plugins, applications and assembly files (#1889)

File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
22using System;
23using HeuristicLab.Core;
24using HeuristicLab.Encodings.ScheduleEncoding;
25
26namespace HeuristicLab.Problems.Scheduling {
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) {
33          if (!t.IsScheduled) {
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) {
58        if (t.ResourceNr == conflictedTask.ResourceNr) {
59          if (ComputeEarliestStartTime(t, schedule) < conflictedCompletionTime)
60            result.Add(t);
61        }
62      }
63      return result;
64    }
65
66    public static double ComputeEarliestStartTime(Task t, Schedule schedule) {
67      ScheduledTask previousTask = schedule.GetLastScheduledTaskForJobNr(t.JobNr);
68      Resource affectedResource = schedule.Resources[t.ResourceNr];
69      double lastMachineEndTime = affectedResource.TotalDuration;
70      double previousJobTaskEndTime = 0;
71      if (previousTask != null)
72        previousJobTaskEndTime = previousTask.EndTime;
73
74      return Math.Max(previousJobTaskEndTime, lastMachineEndTime);
75    }
76    public static double ComputeEarliestCompletionTime(Task t, Schedule schedule) {
77      return ComputeEarliestStartTime(t, schedule) + t.Duration;
78    }
79  }
80}
Note: See TracBrowser for help on using the repository browser.