Changeset 13435 for branches/ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding
- Timestamp:
- 12/04/15 10:35:04 (9 years ago)
- Location:
- branches/ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/DirectScheduleRandomCreator.cs
r12012 r13435 63 63 Parameters.Add(new ValueLookupParameter<IntValue>("Resources", "The number of resources used in this problem instance.")); 64 64 Parameters.Add(new LookupParameter<ItemList<Job>>("JobData", "Job data taken from the JSSP - Instance.")); 65 Schedule EncodingParameter.ActualName = "Schedule";65 ScheduleParameter.ActualName = "Schedule"; 66 66 } 67 67 … … 82 82 83 83 84 protected override ISchedule EncodingCreateSolution() {84 protected override ISchedule CreateSolution() { 85 85 try { 86 86 var jobData = (ItemList<Job>)JobDataParameter.ActualValue.Clone(); -
branches/ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Job.cs
r12012 r13435 31 31 [Item("Job", "Represents a composition of tasks that require processing in a scheduling problem.")] 32 32 [StorableClass] 33 public class Job : Item, INotifyPropertyChanged {33 public sealed class Job : Item, INotifyPropertyChanged { 34 34 35 35 [Storable(Name = "DueDate")] … … 38 38 get { return dueDate; } 39 39 set { 40 bool changed = dueDate != value;40 if (dueDate == value) return; 41 41 dueDate = value; 42 if (changed) { 43 OnPropertyChanged("DueDate"); 44 OnToStringChanged(); 45 } 42 OnPropertyChanged("DueDate"); 43 OnToStringChanged(); 46 44 } 47 45 } … … 52 50 get { return index; } 53 51 set { 54 bool changed = index != value;52 if (index == value) return; 55 53 index = value; 56 if (changed) { 57 OnPropertyChanged("Index"); 58 OnToStringChanged(); 59 } 54 OnPropertyChanged("Index"); 55 OnToStringChanged(); 60 56 } 61 57 } … … 65 61 public ItemList<Task> Tasks { 66 62 get { return tasks; } 67 set { 68 bool changed = tasks != value; 63 private set { 69 64 tasks = value; 70 if (changed)OnPropertyChanged("Tasks");65 OnPropertyChanged("Tasks"); 71 66 } 72 67 } 73 68 74 69 [StorableConstructor] 75 pr otectedJob(bool deserializing) : base(deserializing) { }76 pr otectedJob(Job original, Cloner cloner)70 private Job(bool deserializing) : base(deserializing) { } 71 private Job(Job original, Cloner cloner) 77 72 : base(original, cloner) { 78 73 this.dueDate = original.DueDate; … … 151 146 } 152 147 153 internal Task GetPreviousTask(Task t) {154 if (t.TaskNr == 0) return null;155 return Tasks[t.TaskNr - 1];156 }157 158 148 public event EventHandler TasksChanged; 159 pr otected virtualvoid OnTasksChanged() {149 private void OnTasksChanged() { 160 150 var handler = TasksChanged; 161 151 if (handler != null) handler(this, EventArgs.Empty); … … 163 153 164 154 public event PropertyChangedEventHandler PropertyChanged; 165 pr otected virtualvoid OnPropertyChanged(string propertyName) {155 private void OnPropertyChanged(string propertyName) { 166 156 var handler = PropertyChanged; 167 157 if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); -
branches/ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Manipulators/DirectScheduleManipulator.cs
r12012 r13435 35 35 public DirectScheduleManipulator() 36 36 : base() { 37 Schedule EncodingParameter.ActualName = "Schedule";37 ScheduleParameter.ActualName = "Schedule"; 38 38 } 39 39 … … 41 41 42 42 public override IOperation InstrumentedApply() { 43 var schedule = Schedule EncodingParameter.ActualValue as Schedule;43 var schedule = ScheduleParameter.ActualValue as Schedule; 44 44 if (schedule == null) throw new InvalidOperationException("ScheduleEncoding was not found or is not of type Schedule."); 45 45 Manipulate(RandomParameter.ActualValue, schedule); -
branches/ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Resource.cs
r12012 r13435 20 20 #endregion 21 21 22 using System.Linq; 22 23 using System.Text; 23 24 using HeuristicLab.Common; … … 28 29 [Item("ResourceClass", "Represents a resource used in scheduling problems.")] 29 30 [StorableClass] 30 public class Resource : Item {31 public sealed class Resource : Item { 31 32 32 33 [Storable] 33 public int Index { 34 get; 35 set; 36 } 34 public int Index { get; private set; } 37 35 [Storable] 38 public ItemList<ScheduledTask> Tasks { 39 get; 40 set; 36 public ItemList<ScheduledTask> Tasks { get; private set; } 37 38 //TODO why does a Ressource has a duration? 39 public double TotalDuration { 40 get { 41 if (Tasks.Count == 0) return 0.0; 42 return Tasks.Max(t => t.EndTime); 43 } 41 44 } 42 45 43 46 [StorableConstructor] 44 pr otectedResource(bool deserializing) : base(deserializing) { }45 pr otectedResource(Resource original, Cloner cloner)47 private Resource(bool deserializing) : base(deserializing) { } 48 private Resource(Resource original, Cloner cloner) 46 49 : base(original, cloner) { 47 50 this.Index = original.Index; … … 58 61 } 59 62 60 public double TotalDuration {61 get {62 double result = 0;63 foreach (ScheduledTask t in Tasks) {64 if (t.EndTime > result)65 result = t.EndTime;66 }67 return result;68 }69 }70 71 63 public override string ToString() { 72 64 StringBuilder sb = new StringBuilder(); 73 65 sb.Append("Resource#" + Index + " [ "); 74 66 foreach (ScheduledTask t in Tasks) { 75 sb.Append(t + " ");67 sb.Append(t + " "); 76 68 } 77 69 sb.Append("]"); -
branches/ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Schedule.cs
r12012 r13435 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; 27 using HeuristicLab.Data;28 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 28 … … 31 30 [Item("Schedule", "Represents the general solution for scheduling problems.")] 32 31 [StorableClass] 33 public class Schedule : NamedItem, ISchedule Encoding{32 public class Schedule : NamedItem, ISchedule { 34 33 35 34 #region Properties … … 38 37 public ItemList<Resource> Resources { 39 38 get { return resources; } 40 set {41 if (resources != null) DeregisterResourcesEvents();42 resources = value;43 if (resources != null) RegisterResourcesEvents();44 OnResourcesChanged();45 }46 39 } 47 40 [Storable] 48 private DoubleValue quality;49 public DoubleValue Quality {41 private double quality; 42 public double Quality { 50 43 get { return quality; } 51 44 set { 52 if (quality != value) { 53 if (quality != null) DeregisterQualityEvents(); 54 quality = value; 55 if (quality != null) RegisterQualityEvents(); 56 OnQualityChanged(); 57 } 45 if (quality == value) return; 46 quality = value; 47 OnQualityChanged(); 58 48 } 59 49 } … … 66 56 protected Schedule(Schedule original, Cloner cloner) 67 57 : base(original, cloner) { 68 this.Resources = cloner.Clone(original.Resources); 69 this.Quality = cloner.Clone(original.Quality); 58 this.resources = cloner.Clone(original.Resources); 59 this.quality = original.Quality; 60 //TODO clone 70 61 this.lastScheduledTaskOfJob = new Dictionary<int, ScheduledTask>(original.lastScheduledTaskOfJob); 62 63 RegisterResourcesEvents(); 71 64 } 72 65 public Schedule(int nrOfResources) { 73 Resources = new ItemList<Resource>();66 resources = new ItemList<Resource>(); 74 67 for (int i = 0; i < nrOfResources; i++) { 75 68 Resources.Add(new Resource(i)); 76 69 } 77 70 lastScheduledTaskOfJob = new Dictionary<int, ScheduledTask>(); 71 72 RegisterResourcesEvents(); 78 73 } 79 74 … … 89 84 changed(this, EventArgs.Empty); 90 85 } 91 private void RegisterQualityEvents() {92 Quality.ValueChanged += new EventHandler(Quality_ValueChanged);93 }94 private void DeregisterQualityEvents() {95 Quality.ValueChanged -= new EventHandler(Quality_ValueChanged);96 }97 private void Quality_ValueChanged(object sender, EventArgs e) {98 OnQualityChanged();99 }100 86 101 87 public event EventHandler ResourcesChanged; … … 107 93 private void RegisterResourcesEvents() { 108 94 Resources.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(Resources_PropertyChanged); 109 }110 private void DeregisterResourcesEvents() {111 Resources.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(Resources_PropertyChanged);112 95 } 113 96 private void Resources_PropertyChanged(object sender, EventArgs e) { … … 154 137 return sb.ToString(); 155 138 } 156 157 public double CalculateMakespan() {158 double quality = 0;159 foreach (Resource r in Resources) {160 if (r.TotalDuration > quality) {161 quality = r.TotalDuration;162 }163 }164 return quality;165 }166 139 } 167 140 }
Note: See TracChangeset
for help on using the changeset viewer.