Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Task.cs @ 8886

Last change on this file since 8886 was 8886, checked in by abeham, 11 years ago

#1329:

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