Free cookie consent management tool by TermsFeed Policy Generator

source: branches/gteufl/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Job.cs @ 12337

Last change on this file since 12337 was 9456, checked in by swagner, 12 years ago

Updated copyright year and added some missing license headers (#1889)

File size: 3.3 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.ComponentModel;
23using System.Text;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Encodings.ScheduleEncoding {
29  [Item("Job", "Represents a composition of tasks that require processing in a scheduling problem.")]
30  [StorableClass]
31  public class Job : Item, INotifyPropertyChanged {
32
33    [Storable(Name = "DueDate")]
34    private double dueDate;
35    public double DueDate {
36      get { return dueDate; }
37      set {
38        bool changed = dueDate != value;
39        dueDate = value;
40        if (changed) OnPropertyChanged("DueDate");
41      }
42    }
43
44    [Storable(Name = "Index")]
45    private int index;
46    public int Index {
47      get { return index; }
48      set {
49        bool changed = index != value;
50        index = value;
51        if (changed) OnPropertyChanged("Index");
52      }
53    }
54
55    [Storable(Name = "Tasks")]
56    private ItemList<Task> tasks;
57    public ItemList<Task> Tasks {
58      get { return tasks; }
59      set {
60        bool changed = tasks != value;
61        tasks = value;
62        if (changed) OnPropertyChanged("Tasks");
63      }
64    }
65
66    [StorableConstructor]
67    protected Job(bool deserializing) : base(deserializing) { }
68    protected Job(Job original, Cloner cloner)
69      : base(original, cloner) {
70      this.DueDate = original.DueDate;
71      this.Index = original.Index;
72      this.Tasks = cloner.Clone(original.Tasks);
73    }
74    public Job() : this(-1, double.MaxValue) { }
75    public Job(int index, double dueDate)
76      : base() {
77      DueDate = dueDate;
78      Index = index;
79      Tasks = new ItemList<Task>();
80    }
81
82    public override IDeepCloneable Clone(Cloner cloner) {
83      return new Job(this, cloner);
84    }
85
86    public override string ToString() {
87      var sb = new StringBuilder();
88      sb.Append("Job#" + Index + " [ ");
89      foreach (Task t in Tasks) {
90        sb.Append(t.ToString() + " ");
91      }
92      sb.Append("{" + DueDate + "} ");
93      sb.Append("]");
94      return sb.ToString();
95    }
96
97    internal Task GetPreviousTask(Task t) {
98      if (t.TaskNr == 0) return null;
99      return Tasks[t.TaskNr - 1];
100    }
101
102    public event PropertyChangedEventHandler PropertyChanged;
103    protected virtual void OnPropertyChanged(string propertyName) {
104      var handler = PropertyChanged;
105      if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
106    }
107  }
108}
Note: See TracBrowser for help on using the repository browser.