[6475] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[9456] | 3 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6475] | 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 |
|
---|
[8886] | 22 | using System.ComponentModel;
|
---|
[6475] | 23 | using System.Text;
|
---|
| 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Encodings.ScheduleEncoding {
|
---|
| 29 | [Item("Job", "Represents a composition of tasks that require processing in a scheduling problem.")]
|
---|
| 30 | [StorableClass]
|
---|
[8886] | 31 | public class Job : Item, INotifyPropertyChanged {
|
---|
[8887] | 32 |
|
---|
| 33 | [Storable(Name = "DueDate")]
|
---|
| 34 | private double dueDate;
|
---|
[8886] | 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 | }
|
---|
[6475] | 43 |
|
---|
[8886] | 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")]
|
---|
[8887] | 56 | private ItemList<Task> tasks;
|
---|
[8886] | 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 |
|
---|
[6475] | 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 | }
|
---|
[8887] | 74 | public Job() : this(-1, double.MaxValue) { }
|
---|
[6475] | 75 | public Job(int index, double dueDate)
|
---|
| 76 | : base() {
|
---|
[8886] | 77 | DueDate = dueDate;
|
---|
[6475] | 78 | Index = index;
|
---|
| 79 | Tasks = new ItemList<Task>();
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[8887] | 82 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 83 | return new Job(this, cloner);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[6475] | 86 | public override string ToString() {
|
---|
[8886] | 87 | var sb = new StringBuilder();
|
---|
[6475] | 88 | sb.Append("Job#" + Index + " [ ");
|
---|
| 89 | foreach (Task t in Tasks) {
|
---|
| 90 | sb.Append(t.ToString() + " ");
|
---|
| 91 | }
|
---|
[7116] | 92 | sb.Append("{" + DueDate + "} ");
|
---|
[6475] | 93 | sb.Append("]");
|
---|
| 94 | return sb.ToString();
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | internal Task GetPreviousTask(Task t) {
|
---|
[8886] | 98 | if (t.TaskNr == 0) return null;
|
---|
| 99 | return Tasks[t.TaskNr - 1];
|
---|
[6475] | 100 | }
|
---|
| 101 |
|
---|
[8886] | 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 | }
|
---|
[6475] | 107 | }
|
---|
| 108 | }
|
---|