Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Task.cs @ 10143

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

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

File size: 4.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("Task", "Represents a task that has to be scheduled.")]
30  [StorableClass]
31  public class Task : Item, INotifyPropertyChanged {
32
33    [Storable(Name = "TaskNr")]
34    private int taskNr;
35    public int TaskNr {
36      get { return taskNr; }
37      set {
38        bool changed = taskNr != value;
39        taskNr = value;
40        if (changed) OnPropertyChanged("TaskNr");
41      }
42    }
43    [Storable(Name = "ResourceNr")]
44    private int resourceNr;
45    public int ResourceNr {
46      get { return resourceNr; }
47      set {
48        bool changed = resourceNr != value;
49        resourceNr = value;
50        if (changed) OnPropertyChanged("ResourceNr");
51      }
52    }
53
54    [Storable(Name = "JobNr")]
55    private int jobNr;
56    public int JobNr {
57      get { return jobNr; }
58      set {
59        bool changed = jobNr != value;
60        jobNr = value;
61        if (changed) OnPropertyChanged("JobNr");
62      }
63    }
64
65    [Storable(Name = "Duration")]
66    private double duration;
67    public double Duration {
68      get { return duration; }
69      set {
70        bool changed = duration != value;
71        duration = value;
72        if (changed) OnPropertyChanged("Duration");
73      }
74    }
75
76    [Storable(Name = "IsScheduled")]
77    private bool isScheduled;
78    public bool IsScheduled {
79      get { return isScheduled; }
80      set {
81        bool changed = isScheduled != value;
82        isScheduled = value;
83        if (changed) OnPropertyChanged("IsScheduled");
84      }
85    }
86
87    [StorableConstructor]
88    protected Task(bool deserializing) : base(deserializing) { }
89    protected Task(Task original, Cloner cloner)
90      : base(original, cloner) {
91      this.ResourceNr = original.ResourceNr;
92      this.JobNr = original.JobNr;
93      this.Duration = original.Duration;
94      this.TaskNr = original.TaskNr;
95      this.IsScheduled = original.IsScheduled;
96    }
97    public Task() : this(-1, -1, -1, 0) { }
98    public Task(int taskNr, int resNr, int jobNr, double duration)
99      : base() {
100      Duration = duration;
101      ResourceNr = resNr;
102      JobNr = jobNr;
103      TaskNr = taskNr;
104      IsScheduled = false;
105    }
106
107    public override IDeepCloneable Clone(Cloner cloner) {
108      return new Task(this, cloner);
109    }
110
111    public override string ToString() {
112      StringBuilder sb = new StringBuilder();
113      sb.Append("[" + TaskNr + "," + ResourceNr + "]");
114      return sb.ToString();
115    }
116
117    public override bool Equals(object obj) {
118      if (obj.GetType() == typeof(Task))
119        return AreEqual(this, obj as Task);
120      else
121        return false;
122    }
123
124    public override int GetHashCode() {
125      return TaskNr ^ JobNr;
126    }
127
128    public static bool AreEqual(Task task1, Task task2) {
129      return (task1.Duration == task2.Duration &&
130        task1.IsScheduled == task2.IsScheduled &&
131        task1.JobNr == task2.JobNr &&
132        task1.ResourceNr == task2.ResourceNr &&
133        task1.TaskNr == task2.TaskNr);
134    }
135
136    public event PropertyChangedEventHandler PropertyChanged;
137    protected virtual void OnPropertyChanged(string propertyName) {
138      var handler = PropertyChanged;
139      if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
140    }
141  }
142}
Note: See TracBrowser for help on using the repository browser.