Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ScopedAlgorithms/HeuristicLab.Encodings.ScheduleEncoding/3.3/Task.cs @ 15870

Last change on this file since 15870 was 13437, checked in by mkommend, 9 years ago

#2521: Added encodings for schedules.

File size: 4.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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) {
41          OnPropertyChanged("TaskNr");
42          OnToStringChanged();
43        }
44      }
45    }
46    [Storable(Name = "ResourceNr")]
47    private int resourceNr;
48    public int ResourceNr {
49      get { return resourceNr; }
50      set {
51        bool changed = resourceNr != value;
52        resourceNr = value;
53        if (changed) {
54          OnPropertyChanged("ResourceNr");
55          OnToStringChanged();
56        }
57      }
58    }
59
60    //this has to be exactly the number of the job which the task belongs to
61    //otherwise everything breaks and wrong results are calculated
62    [Storable(Name = "JobNr")]
63    private int jobNr;
64    public int JobNr {
65      get { return jobNr; }
66      set {
67        bool changed = jobNr != value;
68        jobNr = value;
69        if (changed) OnPropertyChanged("JobNr");
70      }
71    }
72
73    [Storable(Name = "Duration")]
74    private double duration;
75    public double Duration {
76      get { return duration; }
77      set {
78        bool changed = duration != value;
79        duration = value;
80        if (changed) OnPropertyChanged("Duration");
81      }
82    }
83
84    [Storable(Name = "IsScheduled")]
85    private bool isScheduled;
86    public bool IsScheduled {
87      get { return isScheduled; }
88      set {
89        bool changed = isScheduled != value;
90        isScheduled = value;
91        if (changed) OnPropertyChanged("IsScheduled");
92      }
93    }
94
95    [StorableConstructor]
96    protected Task(bool deserializing) : base(deserializing) { }
97    protected Task(Task original, Cloner cloner)
98      : base(original, cloner) {
99      this.resourceNr = original.ResourceNr;
100      this.jobNr = original.JobNr;
101      this.duration = original.Duration;
102      this.taskNr = original.TaskNr;
103      this.isScheduled = original.IsScheduled;
104    }
105    public Task() : this(-1, -1, -1, 0) { }
106    public Task(int taskNr, int resNr, int jobNr, double duration)
107      : base() {
108      this.duration = duration;
109      this.resourceNr = resNr;
110      this.jobNr = jobNr;
111      this.taskNr = taskNr;
112      this.isScheduled = false;
113    }
114
115    public override IDeepCloneable Clone(Cloner cloner) {
116      return new Task(this, cloner);
117    }
118
119    public override string ToString() {
120      StringBuilder sb = new StringBuilder();
121      sb.Append("[" + TaskNr + "," + ResourceNr + "]");
122      return sb.ToString();
123    }
124
125    public event PropertyChangedEventHandler PropertyChanged;
126    protected virtual void OnPropertyChanged(string propertyName) {
127      var handler = PropertyChanged;
128      if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
129    }
130  }
131}
Note: See TracBrowser for help on using the repository browser.