- Timestamp:
- 11/11/12 22:57:09 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding
- Files:
-
- 1 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Crossovers/DirectScheduleCrossover.cs
r8603 r8887 28 28 [Item("DirectScheduleCrossover", "An operator which crosses two schedule representations.")] 29 29 [StorableClass] 30 public abstract class DirectScheduleCrossover : ScheduleCrossover <Schedule>, IDirectScheduleOperator {30 public abstract class DirectScheduleCrossover : ScheduleCrossover, IDirectScheduleOperator { 31 31 [StorableConstructor] 32 32 protected DirectScheduleCrossover(bool deserializing) : base(deserializing) { } … … 39 39 } 40 40 41 42 41 public ILookupParameter<ItemList<Job>> JobDataParameter { 43 42 get { return (LookupParameter<ItemList<Job>>)Parameters["JobData"]; } … … 47 46 48 47 public override IOperation Apply() { 49 ItemArray<Schedule>parents = ParentsParameter.ActualValue;48 var parents = ParentsParameter.ActualValue; 50 49 ChildParameter.ActualValue = 51 50 Cross(RandomParameter.ActualValue, parents[0] as Schedule, parents[1] as Schedule); -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Crossovers/DirectScheduleGTCrossover.cs
r8603 r8887 30 30 [StorableClass] 31 31 public class DirectScheduleGTCrossover : DirectScheduleCrossover { 32 33 public IValueLookupParameter<DoubleValue> MutationProbabilityParameter { 34 get { return (IValueLookupParameter<DoubleValue>)Parameters["MutationProbability"]; } 35 } 36 32 37 [StorableConstructor] 33 38 protected DirectScheduleGTCrossover(bool deserializing) : base(deserializing) { } 34 protected DirectScheduleGTCrossover(DirectScheduleGTCrossover original, Cloner cloner) 35 : base(original, cloner) { 39 protected DirectScheduleGTCrossover(DirectScheduleGTCrossover original, Cloner cloner) : base(original, cloner) { } 40 public DirectScheduleGTCrossover() 41 : base() { 42 Parameters.Add(new ValueLookupParameter<DoubleValue>("MutationProbability", "The probability that a task from the conflict set is chosen randomly instead of from one of the parents.")); 36 43 } 44 37 45 public override IDeepCloneable Clone(Cloner cloner) { 38 46 return new DirectScheduleGTCrossover(this, cloner); 39 47 } 40 public DirectScheduleGTCrossover()41 : base() {42 Parameters.Add(new LookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));43 }44 45 46 private LookupParameter<PercentValue> MutationProbabilityParameter {47 get { return (LookupParameter<PercentValue>)Parameters["MutationProbability"]; }48 }49 50 48 51 49 public static Schedule Apply(IRandom random, Schedule parent1, Schedule parent2, ItemList<Job> jobData, double mutProp) { 52 Schedule child = new Schedule(parent1.Resources.Count); 53 50 var child = new Schedule(parent1.Resources.Count); 54 51 55 52 //Reset scheduled tasks in result … … 75 72 int progressOnResource = conflictedResource.Tasks.Count; 76 73 Task selectedTask = null; 77 if (random.Next (100) < mutProp) {74 if (random.NextDouble() < mutProp) { 78 75 //Mutation 79 76 selectedTask = conflictSet[random.Next(conflictSet.Count)]; … … 95 92 } 96 93 97 98 94 private static Task SelectTaskFromConflictSet(ItemList<Task> conflictSet, Schedule usedParent, int conflictedResourceNr, int progressOnResource) { 99 95 //Apply Crossover … … 109 105 110 106 public override Schedule Cross(IRandom random, Schedule parent1, Schedule parent2) { 111 ItemList<Job>jobData = (ItemList<Job>)JobDataParameter.ActualValue.Clone();112 PercentValuemutProp = MutationProbabilityParameter.ActualValue;107 var jobData = (ItemList<Job>)JobDataParameter.ActualValue.Clone(); 108 var mutProp = MutationProbabilityParameter.ActualValue; 113 109 return Apply(random, parent1, parent2, jobData, mutProp.Value); 114 110 } -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/DirectScheduleRandomCreator.cs
r8603 r8887 33 33 [Item("DirectScheduleRandomCreator", "Creator class used to create schedule encoding objects.")] 34 34 [StorableClass] 35 public class DirectScheduleRandomCreator : ScheduleCreator <Schedule>, IStochasticOperator {35 public class DirectScheduleRandomCreator : ScheduleCreator, IStochasticOperator { 36 36 37 37 public ILookupParameter<IRandom> RandomParameter { … … 68 68 69 69 public static Schedule Apply(int jobs, int resources, PWREncoding pwr, ItemList<Job> jobData) { 70 ScheduleresultingSchedule = new Schedule(jobData[0].Tasks.Count);70 var resultingSchedule = new Schedule(jobData[0].Tasks.Count); 71 71 foreach (int jobNr in pwr.PermutationWithRepetition) { 72 72 int i = 0; … … 82 82 83 83 84 protected override ScheduleCreateSolution() {84 protected override IScheduleEncoding CreateSolution() { 85 85 try { 86 ItemList<Job>jobData = (ItemList<Job>)JobDataParameter.ActualValue.Clone();86 var jobData = (ItemList<Job>)JobDataParameter.ActualValue.Clone(); 87 87 return Apply(JobsParameter.ActualValue.Value, 88 88 ResourcesParameter.ActualValue.Value, 89 89 new PWREncoding(JobsParameter.ActualValue.Value, ResourcesParameter.ActualValue.Value, RandomParameter.ActualValue), 90 90 jobData); 91 } 92 catch { 91 } catch { 93 92 throw new Exception("ScheduleRandomCreator needs JobData parameter from a JSSP-Instance to create Schedule-Instances!"); 94 93 } -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Job.cs
r8886 r8887 30 30 [StorableClass] 31 31 public class Job : Item, INotifyPropertyChanged { 32 [Storable(Name = "DueDate")] private double dueDate; 32 33 [Storable(Name = "DueDate")] 34 private double dueDate; 33 35 public double DueDate { 34 36 get { return dueDate; } … … 52 54 53 55 [Storable(Name = "Tasks")] 54 private ItemList<Task> tasks; 56 private ItemList<Task> tasks; 55 57 public ItemList<Task> Tasks { 56 58 get { return tasks; } … … 70 72 this.Tasks = cloner.Clone(original.Tasks); 71 73 } 72 public override IDeepCloneable Clone(Cloner cloner) { 73 return new Job(this, cloner); 74 } 74 public Job() : this(-1, double.MaxValue) { } 75 75 public Job(int index, double dueDate) 76 76 : base() { … … 78 78 Index = index; 79 79 Tasks = new ItemList<Task>(); 80 } 81 82 public override IDeepCloneable Clone(Cloner cloner) { 83 return new Job(this, cloner); 80 84 } 81 85 -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Manipulators/DirectScheduleManipulator.cs
r8603 r8887 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 27 28 [Item("DirectScheduleManipulator", "An operator which manipulates a direct schedule representation.")] 28 29 [StorableClass] 29 public abstract class DirectScheduleManipulator : ScheduleManipulator<Schedule>, IDirectScheduleOperator { 30 public abstract class DirectScheduleManipulator : ScheduleManipulator, IDirectScheduleOperator { 31 30 32 [StorableConstructor] 31 33 protected DirectScheduleManipulator(bool deserializing) : base(deserializing) { } … … 36 38 } 37 39 40 protected abstract void Manipulate(IRandom random, Schedule individual); 38 41 39 protected abstract void Manipulate(IRandom random, Schedule individual);40 42 public override IOperation Apply() { 41 Schedule solution = ScheduleEncodingParameter.ActualValue; 42 Manipulate(RandomParameter.ActualValue, solution); 43 var schedule = ScheduleEncodingParameter.ActualValue as Schedule; 44 if (schedule == null) throw new InvalidOperationException("ScheduleEncoding was not found or is not of type Schedule."); 45 Manipulate(RandomParameter.ActualValue, schedule); 43 46 return base.Apply(); 44 47 } -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Resource.cs
r8603 r8887 29 29 [StorableClass] 30 30 public class Resource : Item { 31 public Resource(int index) 32 : base() { 33 Index = index; 34 Tasks = new ItemList<ScheduledTask>(); 35 } 31 36 32 [Storable] 37 33 public int Index { … … 44 40 set; 45 41 } 42 43 [StorableConstructor] 44 protected Resource(bool deserializing) : base(deserializing) { } 45 protected Resource(Resource original, Cloner cloner) 46 : base(original, cloner) { 47 this.Index = original.Index; 48 this.Tasks = cloner.Clone(original.Tasks); 49 } 50 public Resource(int index) 51 : base() { 52 Index = index; 53 Tasks = new ItemList<ScheduledTask>(); 54 } 55 56 public override IDeepCloneable Clone(Cloner cloner) { 57 return new Resource(this, cloner); 58 } 59 46 60 public double TotalDuration { 47 61 get { … … 53 67 return result; 54 68 } 55 }56 57 [StorableConstructor]58 protected Resource(bool deserializing) : base(deserializing) { }59 protected Resource(Resource original, Cloner cloner)60 : base(original, cloner) {61 this.Index = original.Index;62 this.Tasks = cloner.Clone(original.Tasks);63 }64 public override IDeepCloneable Clone(Cloner cloner) {65 return new Resource(this, cloner);66 69 } 67 70 … … 83 86 return false; 84 87 } 88 85 89 public override int GetHashCode() { 86 90 if (Tasks.Count == 1) … … 90 94 return 0; 91 95 } 96 92 97 private static bool AreEqual(Resource res1, Resource res2) { 93 98 if (res1.Tasks.Count != res2.Tasks.Count) -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Schedule.cs
r8603 r8887 32 32 [StorableClass] 33 33 public class Schedule : NamedItem, IScheduleEncoding { 34 34 35 #region Properties 35 36 [Storable] … … 69 70 this.lastScheduledTaskOfJob = new Dictionary<int, ScheduledTask>(original.lastScheduledTaskOfJob); 70 71 } 71 public override IDeepCloneable Clone(Cloner cloner) {72 return new Schedule(this, cloner);73 }74 72 public Schedule(int nrOfResources) { 75 73 Resources = new ItemList<Resource>(); … … 80 78 } 81 79 82 80 public override IDeepCloneable Clone(Cloner cloner) { 81 return new Schedule(this, cloner); 82 } 83 83 84 84 #region Events -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/ScheduledTask.cs
r8603 r8887 29 29 [StorableClass] 30 30 public class ScheduledTask : Item { 31 31 32 #region Properties 32 33 [Storable] … … 57 58 this.JobNr = original.JobNr; 58 59 } 59 public override IDeepCloneable Clone(Cloner cloner) {60 return new ScheduledTask(this, cloner);61 }62 63 60 public ScheduledTask(int resNr, double startTime, double duration, int jobNr) 64 61 : base() { … … 69 66 } 70 67 68 public override IDeepCloneable Clone(Cloner cloner) { 69 return new ScheduledTask(this, cloner); 70 } 71 71 72 public override string ToString() { 72 73 StringBuilder sb = new StringBuilder(); … … 74 75 return sb.ToString(); 75 76 } 76 77 77 78 78 public override bool Equals(object obj) { -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Task.cs
r8886 r8887 30 30 [StorableClass] 31 31 public class Task : Item, INotifyPropertyChanged { 32 32 33 [Storable(Name = "TaskNr")] 33 34 private int taskNr; … … 94 95 this.IsScheduled = original.IsScheduled; 95 96 } 96 public override IDeepCloneable Clone(Cloner cloner) { 97 return new Task(this, cloner); 98 } 99 100 97 public Task() : this(-1, -1, -1, 0) { } 101 98 public Task(int taskNr, int resNr, int jobNr, double duration) 102 99 : base() { … … 106 103 TaskNr = taskNr; 107 104 IsScheduled = false; 105 } 106 107 public override IDeepCloneable Clone(Cloner cloner) { 108 return new Task(this, cloner); 108 109 } 109 110 … … 120 121 return false; 121 122 } 123 122 124 public override int GetHashCode() { 123 125 return TaskNr ^ JobNr; 124 126 } 127 125 128 public static bool AreEqual(Task task1, Task task2) { 126 129 return (task1.Duration == task2.Duration &&
Note: See TracChangeset
for help on using the changeset viewer.