- Timestamp:
- 12/08/15 14:31:05 (9 years ago)
- Location:
- branches/ProblemRefactoring/HeuristicLab.Problems.Scheduling/3.3
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProblemRefactoring/HeuristicLab.Problems.Scheduling/3.3/HeuristicLab.Problems.Scheduling-3.3.csproj
r13437 r13443 114 114 <Compile Include="Analyzers\BestSchedulingSolutionAnalyzer.cs" /> 115 115 <Compile Include="Analyzers\SchedulingAnalyzer.cs" /> 116 <Compile Include="Decoders\JSMForcingStrategy.cs" />117 <Compile Include="Decoders\JSMDecoder.cs" />118 <Compile Include="Decoders\JSMDecodingErrorPolicy.cs" />119 <Compile Include="Decoders\JSMDecodingErrorPolicyTypes.cs" />120 <Compile Include="Decoders\JSMForcingStrategyTypes.cs" />121 <Compile Include="Decoders\PRVDecoder.cs" />122 <Compile Include="Decoders\PWRDecoder.cs" />123 <Compile Include="Decoders\ScheduleDecoder.cs" />124 116 <Compile Include="Evaluators\MeanTardinessEvaluator.cs" /> 125 117 <Compile Include="Evaluators\MakespanEvaluator.cs" /> 126 118 <Compile Include="Evaluators\ScheduleEvaluator.cs" /> 127 119 <Compile Include="Interfaces\IJSSPOperator.cs" /> 128 <Compile Include="Interfaces\IScheduleDecoder.cs" />129 120 <Compile Include="Interfaces\IScheduleEvaluator.cs" /> 130 121 <Compile Include="Interfaces\ISchedulingEvaluator.cs" /> … … 210 201 <Project>{3540E29E-4793-49E7-8EE2-FEA7F61C3994}</Project> 211 202 <Name>HeuristicLab.Problems.Instances-3.3</Name> 203 <Private>False</Private> 204 </ProjectReference> 205 <ProjectReference Include="..\..\HeuristicLab.Random\3.3\HeuristicLab.Random-3.3.csproj"> 206 <Project>{f4539fb6-4708-40c9-be64-0a1390aea197}</Project> 207 <Name>HeuristicLab.Random-3.3</Name> 212 208 <Private>False</Private> 213 209 </ProjectReference> -
branches/ProblemRefactoring/HeuristicLab.Problems.Scheduling/3.3/JobShopSchedulingProblem new.cs
r13437 r13443 26 26 using HeuristicLab.Data; 27 27 using HeuristicLab.Encodings.PermutationEncoding; 28 using HeuristicLab.Encodings.Schedule;29 28 using HeuristicLab.Encodings.ScheduleEncoding; 30 29 using HeuristicLab.Optimization; 31 30 using HeuristicLab.Parameters; 32 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 33 using HeuristicLab.PluginInfrastructure;34 32 using HeuristicLab.Problems.Instances; 35 33 … … 95 93 get { return (IFixedValueParameter<IntValue>)Parameters["Resources"]; } 96 94 } 97 public IValueParameter<IScheduleEvaluator> ScheduleEvaluatorParameter {98 get { return (IValueParameter<IScheduleEvaluator>)Parameters["ScheduleEvaluator"]; }99 }100 public OptionalValueParameter<IScheduleDecoder> ScheduleDecoderParameter {101 get { return (OptionalValueParameter<IScheduleDecoder>)Parameters["ScheduleDecoder"]; }102 }103 95 #endregion 104 96 … … 118 110 get { return ResourcesParameter.Value.Value; } 119 111 set { ResourcesParameter.Value.Value = value; } 120 }121 public IScheduleEvaluator ScheduleEvaluator {122 get { return ScheduleEvaluatorParameter.Value; }123 set { ScheduleEvaluatorParameter.Value = value; }124 }125 public IScheduleDecoder ScheduleDecoder {126 get { return ScheduleDecoderParameter.Value; }127 set { ScheduleDecoderParameter.Value = value; }128 112 } 129 113 #endregion … … 151 135 Parameters.Add(new FixedValueParameter<IntValue>("Jobs", "The number of jobs used in this JSSP instance.", new IntValue())); 152 136 Parameters.Add(new FixedValueParameter<IntValue>("Resources", "The number of resources used in this JSSP instance.", new IntValue())); 153 Parameters.Add(new ValueParameter<IScheduleEvaluator>("ScheduleEvaluator", "The evaluator used to determine the quality of a solution.", new MakespanEvaluator()));154 Parameters.Add(new OptionalValueParameter<IScheduleDecoder>("ScheduleDecoder", "The operator that decodes the representation and creates a schedule.", new JSMDecoder()));155 137 156 138 Encoding = new DirectScheduleEncoding(); … … 162 144 163 145 public override double Evaluate(ISchedule solution, IRandom random) { 164 //TODO change to decoder 165 var schedule = (Schedule)solution; 146 var schedule = Encoding.Decode(solution, JobData); 166 147 return MakespanEvaluator.GetMakespan(schedule); 167 148 } … … 194 175 } 195 176 private void ScheduleEvaluatorParameter_ValueChanged(object sender, EventArgs eventArgs) { 196 ScheduleEvaluator.QualityParameter.ActualNameChanged += ScheduleEvaluator_QualityParameter_ActualNameChanged;177 //ScheduleEvaluator.QualityParameter.ActualNameChanged += ScheduleEvaluator_QualityParameter_ActualNameChanged; 197 178 ParameterizeOperators(); 198 179 } … … 205 186 } 206 187 private void ScheduleDecoderParameter_ValueChanged(object sender, EventArgs eventArgs) { 207 if (ScheduleDecoder != null) ScheduleDecoder.ScheduleParameter.ActualNameChanged += ScheduleDecoder_ScheduleParameter_ActualNameChanged;188 //if (ScheduleDecoder != null) ScheduleDecoder.ScheduleParameter.ActualNameChanged += ScheduleDecoder_ScheduleParameter_ActualNameChanged; 208 189 ParameterizeOperators(); 209 190 } … … 222 203 223 204 private void ApplyEncoding() { 224 if (SolutionCreator.GetType() == typeof(JSMRandomCreator)) {225 Operators.AddRange(ApplicationManager.Manager.GetInstances<IJSMOperator>());226 ScheduleDecoder = new JSMDecoder();227 } else if (SolutionCreator.GetType() == typeof(PRVRandomCreator)) {228 Operators.AddRange(ApplicationManager.Manager.GetInstances<IPRVOperator>());229 ScheduleDecoder = new PRVDecoder();230 } else if (SolutionCreator.GetType() == typeof(PWRRandomCreator)) {231 Operators.AddRange(ApplicationManager.Manager.GetInstances<IPWROperator>());232 ScheduleDecoder = new PWRDecoder();233 } else if (SolutionCreator.GetType() == typeof(DirectScheduleRandomCreator)) {234 Operators.AddRange(ApplicationManager.Manager.GetInstances<IDirectScheduleOperator>());235 ScheduleDecoder = null;236 }205 //if (SolutionCreator.GetType() == typeof(JSMRandomCreator)) { 206 // Operators.AddRange(ApplicationManager.Manager.GetInstances<IJSMOperator>()); 207 // ScheduleDecoder = new JSMDecoder(); 208 //} else if (SolutionCreator.GetType() == typeof(PRVRandomCreator)) { 209 // Operators.AddRange(ApplicationManager.Manager.GetInstances<IPRVOperator>()); 210 // ScheduleDecoder = new PRVDecoder(); 211 //} else if (SolutionCreator.GetType() == typeof(PWRRandomCreator)) { 212 // Operators.AddRange(ApplicationManager.Manager.GetInstances<IPWROperator>()); 213 // ScheduleDecoder = new PWRDecoder(); 214 //} else if (SolutionCreator.GetType() == typeof(DirectScheduleRandomCreator)) { 215 // Operators.AddRange(ApplicationManager.Manager.GetInstances<IDirectScheduleOperator>()); 216 // ScheduleDecoder = null; 217 //} 237 218 } 238 219 … … 301 282 BestKnownQuality = data.BestKnownQuality ?? double.NaN; 302 283 if (data.BestKnownSchedule != null) { 303 var enc = new JSMEncoding(); 304 enc.JobSequenceMatrix = new ItemList<Permutation>(data.Resources); 284 var enc = new JSMEncoding(0); 305 285 for (int i = 0; i < data.Resources; i++) { 306 enc.JobSequenceMatrix [i] = new Permutation(PermutationTypes.Absolute, new int[data.Jobs]);286 enc.JobSequenceMatrix.Add(new Permutation(PermutationTypes.Absolute, new int[data.Jobs])); 307 287 for (int j = 0; j < data.Jobs; j++) { 308 288 enc.JobSequenceMatrix[i][j] = data.BestKnownSchedule[i, j]; 309 289 } 310 290 } 311 BestKnownSolution = new JSMDecoder().CreateScheduleFromEncoding(enc, jobData);312 if (ScheduleEvaluator is MeanTardinessEvaluator)313 BestKnownQuality = MeanTardinessEvaluator.GetMeanTardiness(BestKnownSolution, jobData);314 else if (ScheduleEvaluator is MakespanEvaluator)315 BestKnownQuality = MakespanEvaluator.GetMakespan(BestKnownSolution);291 BestKnownSolution = JSMDecoder.DecodeSchedule(enc, jobData, JSMDecodingErrorPolicyTypes.RandomPolicy, JSMForcingStrategyTypes.SwapForcing); 292 //if (ScheduleEvaluator is MeanTardinessEvaluator) 293 // BestKnownQuality = MeanTardinessEvaluator.GetMeanTardiness(BestKnownSolution, jobData); 294 //else if (ScheduleEvaluator is MakespanEvaluator) 295 // BestKnownQuality = MakespanEvaluator.GetMakespan(BestKnownSolution); 316 296 } 317 297 -
branches/ProblemRefactoring/HeuristicLab.Problems.Scheduling/3.3/JobShopSchedulingProblem.cs
r13437 r13443 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 22 using System; 23 using System.Drawing; 24 using System.Linq; 25 using HeuristicLab.Common; 26 using HeuristicLab.Core; 27 using HeuristicLab.Data; 28 using HeuristicLab.Encodings.PermutationEncoding; 29 using HeuristicLab.Encodings.ScheduleEncoding; 30 using HeuristicLab.Parameters; 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 using HeuristicLab.PluginInfrastructure; 33 using HeuristicLab.Problems.Instances; 34 35 namespace HeuristicLab.Problems.Scheduling { 36 [Item("Job Shop Scheduling Problem (JSSP)", "Represents a standard Job Shop Scheduling Problem")] 37 [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 120)] 38 [StorableClass] 39 public sealed class JobShopSchedulingProblem : SchedulingProblem, IProblemInstanceConsumer<JSSPData>, IProblemInstanceExporter<JSSPData>, IStorableContent { 40 #region Default Instance 41 private static readonly JSSPData DefaultInstance = new JSSPData() { 42 Jobs = 10, 43 Resources = 10, 44 BestKnownQuality = 930, 45 ProcessingTimes = new double[,] { 46 { 29, 78, 9, 36, 49, 11, 62, 56, 44, 21 }, 47 { 43, 90, 75, 11, 69, 28, 46, 46, 72, 30 }, 48 { 91, 85, 39, 74, 90, 10, 12, 89, 45, 33 }, 49 { 81, 95, 71, 99, 9, 52, 85, 98, 22, 43 }, 50 { 14, 6, 22, 61, 26, 69, 21, 49, 72, 53 }, 51 { 84, 2, 52, 95, 48, 72, 47, 65, 6, 25 }, 52 { 46, 37, 61, 13, 32, 21, 32, 89, 30, 55 }, 53 { 31, 86, 46, 74, 32, 88, 19, 48, 36, 79 }, 54 { 76, 69, 76, 51, 85, 11, 40, 89, 26, 74 }, 55 { 85, 13, 61, 7, 64, 76, 47, 52, 90, 45 } 56 }, 57 Demands = new int[,] { 58 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 59 { 0, 2, 4, 9, 3, 1, 6, 5, 7, 8 }, 60 { 1, 0, 3, 2, 8, 5, 7, 6, 9, 4 }, 61 { 1, 2, 0, 4, 6, 8, 7, 3, 9, 5 }, 62 { 2, 0, 1, 5, 3, 4, 8, 7, 9, 6 }, 63 { 2, 1, 5, 3, 8, 9, 0, 6, 4, 7 }, 64 { 1, 0, 3, 2, 6, 5, 9, 8, 7, 4 }, 65 { 2, 0, 1, 5, 4, 6, 8, 9, 7, 3 }, 66 { 0, 1, 3, 5, 2, 9, 6, 7, 4, 8 }, 67 { 1, 0, 2, 6, 8, 9, 5, 3, 4, 7 } 68 } 69 }; 70 #endregion 71 72 public string Filename { get; set; } 73 public override Image ItemImage { 74 get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; } 75 } 76 77 #region Parameter Properties 78 public IValueParameter<ItemList<Job>> JobDataParameter { 79 get { return (IValueParameter<ItemList<Job>>)Parameters["JobData"]; } 80 } 81 public OptionalValueParameter<Schedule> BestKnownSolutionParameter { 82 get { return (OptionalValueParameter<Schedule>)Parameters["BestKnownSolution"]; } 83 } 84 85 public IFixedValueParameter<IntValue> JobsParameter { 86 get { return (IFixedValueParameter<IntValue>)Parameters["Jobs"]; } 87 } 88 public IFixedValueParameter<IntValue> ResourcesParameter { 89 get { return (IFixedValueParameter<IntValue>)Parameters["Resources"]; } 90 } 91 public IValueParameter<IScheduleEvaluator> ScheduleEvaluatorParameter { 92 get { return (IValueParameter<IScheduleEvaluator>)Parameters["ScheduleEvaluator"]; } 93 } 94 public OptionalValueParameter<IScheduleDecoder> ScheduleDecoderParameter { 95 get { return (OptionalValueParameter<IScheduleDecoder>)Parameters["ScheduleDecoder"]; } 96 } 97 #endregion 98 99 #region Properties 100 public ItemList<Job> JobData { 101 get { return JobDataParameter.Value; } 102 set { JobDataParameter.Value = value; } 103 } 104 public Schedule BestKnownSolution { 105 get { return BestKnownSolutionParameter.Value; } 106 set { BestKnownSolutionParameter.Value = value; } 107 } 108 public int Jobs { 109 get { return JobsParameter.Value.Value; } 110 set { JobsParameter.Value.Value = value; } 111 } 112 public int Resources { 113 get { return ResourcesParameter.Value.Value; } 114 set { ResourcesParameter.Value.Value = value; } 115 } 116 public IScheduleEvaluator ScheduleEvaluator { 117 get { return ScheduleEvaluatorParameter.Value; } 118 set { ScheduleEvaluatorParameter.Value = value; } 119 } 120 public IScheduleDecoder ScheduleDecoder { 121 get { return ScheduleDecoderParameter.Value; } 122 set { ScheduleDecoderParameter.Value = value; } 123 } 124 #endregion 125 126 [StorableConstructor] 127 private JobShopSchedulingProblem(bool deserializing) : base(deserializing) { } 128 private JobShopSchedulingProblem(JobShopSchedulingProblem original, Cloner cloner) 129 : base(original, cloner) { 130 RegisterEventHandlers(); 131 } 132 public JobShopSchedulingProblem() 133 : base(new SchedulingEvaluator(), new JSMRandomCreator()) { 134 Parameters.Add(new ValueParameter<ItemList<Job>>("JobData", "Jobdata defining the precedence relationships and the duration of the tasks in this JSSP-Instance.", new ItemList<Job>())); 135 Parameters.Add(new OptionalValueParameter<Schedule>("BestKnownSolution", "The best known solution of this JSSP instance.")); 136 137 Parameters.Add(new FixedValueParameter<IntValue>("Jobs", "The number of jobs used in this JSSP instance.", new IntValue())); 138 Parameters.Add(new FixedValueParameter<IntValue>("Resources", "The number of resources used in this JSSP instance.", new IntValue())); 139 Parameters.Add(new ValueParameter<IScheduleEvaluator>("ScheduleEvaluator", "The evaluator used to determine the quality of a solution.", new MakespanEvaluator())); 140 Parameters.Add(new OptionalValueParameter<IScheduleDecoder>("ScheduleDecoder", "The operator that decodes the representation and creates a schedule.", new JSMDecoder())); 141 142 EvaluatorParameter.GetsCollected = false; 143 EvaluatorParameter.Hidden = true; 144 ScheduleDecoderParameter.Hidden = true; 145 146 InitializeOperators(); 147 Load(DefaultInstance); 148 RegisterEventHandlers(); 149 } 150 151 public override IDeepCloneable Clone(Cloner cloner) { 152 return new JobShopSchedulingProblem(this, cloner); 153 } 154 155 [StorableHook(HookType.AfterDeserialization)] 156 private void AfterDeserialization() { 157 RegisterEventHandlers(); 158 } 159 160 private void RegisterEventHandlers() { 161 ScheduleEvaluatorParameter.ValueChanged += ScheduleEvaluatorParameter_ValueChanged; 162 ScheduleEvaluator.QualityParameter.ActualNameChanged += ScheduleEvaluator_QualityParameter_ActualNameChanged; 163 SolutionCreator.ScheduleParameter.ActualNameChanged += SolutionCreator_SchedulingEncodingParameter_ActualNameChanged; 164 ScheduleDecoderParameter.ValueChanged += ScheduleDecoderParameter_ValueChanged; 165 if (ScheduleDecoder != null) ScheduleDecoder.ScheduleParameter.ActualNameChanged += ScheduleDecoder_ScheduleParameter_ActualNameChanged; 166 } 167 168 #region Events 169 protected override void OnSolutionCreatorChanged() { 170 SolutionCreator.ScheduleParameter.ActualNameChanged += SolutionCreator_SchedulingEncodingParameter_ActualNameChanged; 171 InitializeOperators(); 172 } 173 protected override void OnEvaluatorChanged() { 174 base.OnEvaluatorChanged(); 175 ParameterizeOperators(); 176 } 177 private void ScheduleEvaluatorParameter_ValueChanged(object sender, EventArgs eventArgs) { 178 ScheduleEvaluator.QualityParameter.ActualNameChanged += ScheduleEvaluator_QualityParameter_ActualNameChanged; 179 ParameterizeOperators(); 180 } 181 private void ScheduleEvaluator_QualityParameter_ActualNameChanged(object sender, EventArgs eventArgs) { 182 ParameterizeOperators(); 183 } 184 185 private void SolutionCreator_SchedulingEncodingParameter_ActualNameChanged(object sender, EventArgs eventArgs) { 186 ParameterizeOperators(); 187 } 188 private void ScheduleDecoderParameter_ValueChanged(object sender, EventArgs eventArgs) { 189 if (ScheduleDecoder != null) ScheduleDecoder.ScheduleParameter.ActualNameChanged += ScheduleDecoder_ScheduleParameter_ActualNameChanged; 190 ParameterizeOperators(); 191 } 192 private void ScheduleDecoder_ScheduleParameter_ActualNameChanged(object sender, EventArgs eventArgs) { 193 ParameterizeOperators(); 194 } 195 #endregion 196 197 #region Problem Instance Handling 198 public void Load(JSSPData data) { 199 var jobData = new ItemList<Job>(data.Jobs); 200 for (int j = 0; j < data.Jobs; j++) { 201 var job = new Job(j, data.DueDates != null ? data.DueDates[j] : double.MaxValue); 202 for (int t = 0; t < data.Resources; t++) { 203 job.Tasks.Add(new Task(t, data.Demands[j, t], j, data.ProcessingTimes[j, t])); 204 } 205 jobData.Add(job); 206 } 207 208 BestKnownQuality = data.BestKnownQuality.HasValue ? new DoubleValue(data.BestKnownQuality.Value) : null; 209 if (data.BestKnownSchedule != null) { 210 var enc = new JSMEncoding(); 211 enc.JobSequenceMatrix = new ItemList<Permutation>(data.Resources); 212 for (int i = 0; i < data.Resources; i++) { 213 enc.JobSequenceMatrix[i] = new Permutation(PermutationTypes.Absolute, new int[data.Jobs]); 214 for (int j = 0; j < data.Jobs; j++) { 215 enc.JobSequenceMatrix[i][j] = data.BestKnownSchedule[i, j]; 216 } 217 } 218 BestKnownSolution = new JSMDecoder().CreateScheduleFromEncoding(enc, jobData); 219 if (ScheduleEvaluator is MeanTardinessEvaluator) 220 BestKnownQuality = new DoubleValue(MeanTardinessEvaluator.GetMeanTardiness(BestKnownSolution, jobData)); 221 else if (ScheduleEvaluator is MakespanEvaluator) 222 BestKnownQuality = new DoubleValue(MakespanEvaluator.GetMakespan(BestKnownSolution)); 223 } 224 225 JobData = jobData; 226 Jobs = data.Jobs; 227 Resources = data.Resources; 228 } 229 230 public JSSPData Export() { 231 var result = new JSSPData { 232 Name = Name, 233 Description = Description, 234 Jobs = Jobs, 235 Resources = Resources, 236 ProcessingTimes = new double[Jobs, Resources], 237 Demands = new int[Jobs, Resources], 238 DueDates = new double[Jobs] 239 }; 240 241 foreach (var job in JobData) { 242 var counter = 0; 243 result.DueDates[job.Index] = job.DueDate; 244 foreach (var task in job.Tasks) { 245 result.ProcessingTimes[task.JobNr, counter] = task.Duration; 246 result.Demands[task.JobNr, counter] = task.ResourceNr; 247 counter++; 248 } 249 } 250 return result; 251 } 252 #endregion 253 254 #region Helpers 255 private void InitializeOperators() { 256 Operators.Clear(); 257 ApplyEncoding(); 258 Operators.Add(new BestSchedulingSolutionAnalyzer()); 259 ParameterizeOperators(); 260 } 261 262 private void ApplyEncoding() { 263 if (SolutionCreator.GetType() == typeof(JSMRandomCreator)) { 264 Operators.AddRange(ApplicationManager.Manager.GetInstances<IJSMOperator>()); 265 ScheduleDecoder = new JSMDecoder(); 266 } else if (SolutionCreator.GetType() == typeof(PRVRandomCreator)) { 267 Operators.AddRange(ApplicationManager.Manager.GetInstances<IPRVOperator>()); 268 ScheduleDecoder = new PRVDecoder(); 269 } else if (SolutionCreator.GetType() == typeof(PWRRandomCreator)) { 270 Operators.AddRange(ApplicationManager.Manager.GetInstances<IPWROperator>()); 271 ScheduleDecoder = new PWRDecoder(); 272 } else if (SolutionCreator.GetType() == typeof(DirectScheduleRandomCreator)) { 273 Operators.AddRange(ApplicationManager.Manager.GetInstances<IDirectScheduleOperator>()); 274 ScheduleDecoder = null; 275 } 276 } 277 278 private void ParameterizeOperators() { 279 Evaluator.ScheduleDecoderParameter.ActualName = ScheduleDecoderParameter.Name; 280 Evaluator.ScheduleDecoderParameter.Hidden = true; 281 Evaluator.ScheduleEvaluatorParameter.ActualName = ScheduleEvaluatorParameter.Name; 282 Evaluator.ScheduleEvaluatorParameter.Hidden = true; 283 Evaluator.QualityParameter.ActualName = ScheduleEvaluator.QualityParameter.ActualName; 284 Evaluator.QualityParameter.Hidden = true; 285 286 if (ScheduleDecoder != null) 287 ScheduleDecoder.ScheduleEncodingParameter.ActualName = SolutionCreator.ScheduleParameter.ActualName; 288 289 if (ScheduleDecoder != null) { 290 ScheduleEvaluator.ScheduleParameter.ActualName = ScheduleDecoder.ScheduleParameter.ActualName; 291 ScheduleEvaluator.ScheduleParameter.Hidden = true; 292 } else if (SolutionCreator is DirectScheduleRandomCreator) { 293 var directEvaluator = (DirectScheduleRandomCreator)SolutionCreator; 294 ScheduleEvaluator.ScheduleParameter.ActualName = directEvaluator.ScheduleParameter.ActualName; 295 ScheduleEvaluator.ScheduleParameter.Hidden = true; 296 } else { 297 ScheduleEvaluator.ScheduleParameter.ActualName = ScheduleEvaluator.ScheduleParameter.Name; 298 ScheduleEvaluator.ScheduleParameter.Hidden = false; 299 } 300 301 foreach (var op in Operators.OfType<IScheduleManipulator>()) { 302 op.ScheduleParameter.ActualName = SolutionCreator.ScheduleParameter.ActualName; 303 op.ScheduleParameter.Hidden = true; 304 } 305 306 foreach (var op in Operators.OfType<IScheduleCrossover>()) { 307 op.ChildParameter.ActualName = SolutionCreator.ScheduleParameter.ActualName; 308 op.ChildParameter.Hidden = true; 309 op.ParentsParameter.ActualName = SolutionCreator.ScheduleParameter.ActualName; 310 op.ParentsParameter.Hidden = true; 311 } 312 313 foreach (var op in Operators.OfType<BestSchedulingSolutionAnalyzer>()) { 314 op.QualityParameter.ActualName = ScheduleEvaluator.QualityParameter.ActualName; 315 if (ScheduleDecoder != null) { 316 op.ScheduleParameter.ActualName = ScheduleDecoder.ScheduleParameter.ActualName; 317 op.ScheduleParameter.Hidden = true; 318 } else if (SolutionCreator is DirectScheduleRandomCreator) { 319 op.ScheduleParameter.ActualName = ((DirectScheduleRandomCreator)SolutionCreator).ScheduleParameter.ActualName; 320 op.ScheduleParameter.Hidden = true; 321 } else { 322 op.ScheduleParameter.ActualName = op.ScheduleParameter.Name; 323 op.ScheduleParameter.Hidden = false; 324 } 325 } 326 } 327 #endregion 328 329 } 330 } 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 22 //using System; 23 //using System.Drawing; 24 //using System.Linq; 25 //using HeuristicLab.Common; 26 //using HeuristicLab.Core; 27 //using HeuristicLab.Data; 28 //using HeuristicLab.Encodings.PermutationEncoding; 29 //using HeuristicLab.Encodings.ScheduleEncoding; 30 //using HeuristicLab.Parameters; 31 //using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 //using HeuristicLab.PluginInfrastructure; 33 //using HeuristicLab.Problems.Instances; 34 35 //namespace HeuristicLab.Problems.Scheduling { 36 // [Item("Job Shop Scheduling Problem (JSSP)", "Represents a standard Job Shop Scheduling Problem")] 37 // [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 120)] 38 // [StorableClass] 39 // public sealed class JobShopSchedulingProblem : SchedulingProblem, IProblemInstanceConsumer<JSSPData>, IProblemInstanceExporter<JSSPData>, IStorableContent { 40 // #region Default Instance 41 // private static readonly JSSPData DefaultInstance = new JSSPData() { 42 // Jobs = 10, 43 // Resources = 10, 44 // BestKnownQuality = 930, 45 // ProcessingTimes = new double[,] { 46 // { 29, 78, 9, 36, 49, 11, 62, 56, 44, 21 }, 47 // { 43, 90, 75, 11, 69, 28, 46, 46, 72, 30 }, 48 // { 91, 85, 39, 74, 90, 10, 12, 89, 45, 33 }, 49 // { 81, 95, 71, 99, 9, 52, 85, 98, 22, 43 }, 50 // { 14, 6, 22, 61, 26, 69, 21, 49, 72, 53 }, 51 // { 84, 2, 52, 95, 48, 72, 47, 65, 6, 25 }, 52 // { 46, 37, 61, 13, 32, 21, 32, 89, 30, 55 }, 53 // { 31, 86, 46, 74, 32, 88, 19, 48, 36, 79 }, 54 // { 76, 69, 76, 51, 85, 11, 40, 89, 26, 74 }, 55 // { 85, 13, 61, 7, 64, 76, 47, 52, 90, 45 } 56 // }, 57 // Demands = new int[,] { 58 // { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 59 // { 0, 2, 4, 9, 3, 1, 6, 5, 7, 8 }, 60 // { 1, 0, 3, 2, 8, 5, 7, 6, 9, 4 }, 61 // { 1, 2, 0, 4, 6, 8, 7, 3, 9, 5 }, 62 // { 2, 0, 1, 5, 3, 4, 8, 7, 9, 6 }, 63 // { 2, 1, 5, 3, 8, 9, 0, 6, 4, 7 }, 64 // { 1, 0, 3, 2, 6, 5, 9, 8, 7, 4 }, 65 // { 2, 0, 1, 5, 4, 6, 8, 9, 7, 3 }, 66 // { 0, 1, 3, 5, 2, 9, 6, 7, 4, 8 }, 67 // { 1, 0, 2, 6, 8, 9, 5, 3, 4, 7 } 68 // } 69 // }; 70 // #endregion 71 72 // public string Filename { get; set; } 73 // public override Image ItemImage { 74 // get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; } 75 // } 76 77 // #region Parameter Properties 78 // public IValueParameter<ItemList<Job>> JobDataParameter { 79 // get { return (IValueParameter<ItemList<Job>>)Parameters["JobData"]; } 80 // } 81 // public OptionalValueParameter<Schedule> BestKnownSolutionParameter { 82 // get { return (OptionalValueParameter<Schedule>)Parameters["BestKnownSolution"]; } 83 // } 84 85 // public IFixedValueParameter<IntValue> JobsParameter { 86 // get { return (IFixedValueParameter<IntValue>)Parameters["Jobs"]; } 87 // } 88 // public IFixedValueParameter<IntValue> ResourcesParameter { 89 // get { return (IFixedValueParameter<IntValue>)Parameters["Resources"]; } 90 // } 91 // public IValueParameter<IScheduleEvaluator> ScheduleEvaluatorParameter { 92 // get { return (IValueParameter<IScheduleEvaluator>)Parameters["ScheduleEvaluator"]; } 93 // } 94 // public OptionalValueParameter<IScheduleDecoder> ScheduleDecoderParameter { 95 // get { return (OptionalValueParameter<IScheduleDecoder>)Parameters["ScheduleDecoder"]; } 96 // } 97 // #endregion 98 99 // #region Properties 100 // public ItemList<Job> JobData { 101 // get { return JobDataParameter.Value; } 102 // set { JobDataParameter.Value = value; } 103 // } 104 // public Schedule BestKnownSolution { 105 // get { return BestKnownSolutionParameter.Value; } 106 // set { BestKnownSolutionParameter.Value = value; } 107 // } 108 // public int Jobs { 109 // get { return JobsParameter.Value.Value; } 110 // set { JobsParameter.Value.Value = value; } 111 // } 112 // public int Resources { 113 // get { return ResourcesParameter.Value.Value; } 114 // set { ResourcesParameter.Value.Value = value; } 115 // } 116 // public IScheduleEvaluator ScheduleEvaluator { 117 // get { return ScheduleEvaluatorParameter.Value; } 118 // set { ScheduleEvaluatorParameter.Value = value; } 119 // } 120 // public IScheduleDecoder ScheduleDecoder { 121 // get { return ScheduleDecoderParameter.Value; } 122 // set { ScheduleDecoderParameter.Value = value; } 123 // } 124 // #endregion 125 126 // [StorableConstructor] 127 // private JobShopSchedulingProblem(bool deserializing) : base(deserializing) { } 128 // private JobShopSchedulingProblem(JobShopSchedulingProblem original, Cloner cloner) 129 // : base(original, cloner) { 130 // RegisterEventHandlers(); 131 // } 132 // public JobShopSchedulingProblem() 133 // : base(new SchedulingEvaluator(), new JSMRandomCreator()) { 134 // Parameters.Add(new ValueParameter<ItemList<Job>>("JobData", "Jobdata defining the precedence relationships and the duration of the tasks in this JSSP-Instance.", new ItemList<Job>())); 135 // Parameters.Add(new OptionalValueParameter<Schedule>("BestKnownSolution", "The best known solution of this JSSP instance.")); 136 137 // Parameters.Add(new FixedValueParameter<IntValue>("Jobs", "The number of jobs used in this JSSP instance.", new IntValue())); 138 // Parameters.Add(new FixedValueParameter<IntValue>("Resources", "The number of resources used in this JSSP instance.", new IntValue())); 139 // Parameters.Add(new ValueParameter<IScheduleEvaluator>("ScheduleEvaluator", "The evaluator used to determine the quality of a solution.", new MakespanEvaluator())); 140 // Parameters.Add(new OptionalValueParameter<IScheduleDecoder>("ScheduleDecoder", "The operator that decodes the representation and creates a schedule.", new JSMDecoder())); 141 142 // EvaluatorParameter.GetsCollected = false; 143 // EvaluatorParameter.Hidden = true; 144 // ScheduleDecoderParameter.Hidden = true; 145 146 // InitializeOperators(); 147 // Load(DefaultInstance); 148 // RegisterEventHandlers(); 149 // } 150 151 // public override IDeepCloneable Clone(Cloner cloner) { 152 // return new JobShopSchedulingProblem(this, cloner); 153 // } 154 155 // [StorableHook(HookType.AfterDeserialization)] 156 // private void AfterDeserialization() { 157 // RegisterEventHandlers(); 158 // } 159 160 // private void RegisterEventHandlers() { 161 // ScheduleEvaluatorParameter.ValueChanged += ScheduleEvaluatorParameter_ValueChanged; 162 // ScheduleEvaluator.QualityParameter.ActualNameChanged += ScheduleEvaluator_QualityParameter_ActualNameChanged; 163 // SolutionCreator.ScheduleParameter.ActualNameChanged += SolutionCreator_SchedulingEncodingParameter_ActualNameChanged; 164 // ScheduleDecoderParameter.ValueChanged += ScheduleDecoderParameter_ValueChanged; 165 // if (ScheduleDecoder != null) ScheduleDecoder.ScheduleParameter.ActualNameChanged += ScheduleDecoder_ScheduleParameter_ActualNameChanged; 166 // } 167 168 // #region Events 169 // protected override void OnSolutionCreatorChanged() { 170 // SolutionCreator.ScheduleParameter.ActualNameChanged += SolutionCreator_SchedulingEncodingParameter_ActualNameChanged; 171 // InitializeOperators(); 172 // } 173 // protected override void OnEvaluatorChanged() { 174 // base.OnEvaluatorChanged(); 175 // ParameterizeOperators(); 176 // } 177 // private void ScheduleEvaluatorParameter_ValueChanged(object sender, EventArgs eventArgs) { 178 // ScheduleEvaluator.QualityParameter.ActualNameChanged += ScheduleEvaluator_QualityParameter_ActualNameChanged; 179 // ParameterizeOperators(); 180 // } 181 // private void ScheduleEvaluator_QualityParameter_ActualNameChanged(object sender, EventArgs eventArgs) { 182 // ParameterizeOperators(); 183 // } 184 185 // private void SolutionCreator_SchedulingEncodingParameter_ActualNameChanged(object sender, EventArgs eventArgs) { 186 // ParameterizeOperators(); 187 // } 188 // private void ScheduleDecoderParameter_ValueChanged(object sender, EventArgs eventArgs) { 189 // if (ScheduleDecoder != null) ScheduleDecoder.ScheduleParameter.ActualNameChanged += ScheduleDecoder_ScheduleParameter_ActualNameChanged; 190 // ParameterizeOperators(); 191 // } 192 // private void ScheduleDecoder_ScheduleParameter_ActualNameChanged(object sender, EventArgs eventArgs) { 193 // ParameterizeOperators(); 194 // } 195 // #endregion 196 197 // #region Problem Instance Handling 198 // public void Load(JSSPData data) { 199 // var jobData = new ItemList<Job>(data.Jobs); 200 // for (int j = 0; j < data.Jobs; j++) { 201 // var job = new Job(j, data.DueDates != null ? data.DueDates[j] : double.MaxValue); 202 // for (int t = 0; t < data.Resources; t++) { 203 // job.Tasks.Add(new Task(t, data.Demands[j, t], j, data.ProcessingTimes[j, t])); 204 // } 205 // jobData.Add(job); 206 // } 207 208 // BestKnownQuality = data.BestKnownQuality.HasValue ? new DoubleValue(data.BestKnownQuality.Value) : null; 209 // if (data.BestKnownSchedule != null) { 210 // var enc = new JSMEncoding(0); 211 // for (int i = 0; i < data.Resources; i++) { 212 // enc.JobSequenceMatrix.Add(new Permutation(PermutationTypes.Absolute, new int[data.Jobs])); 213 // for (int j = 0; j < data.Jobs; j++) { 214 // enc.JobSequenceMatrix[i][j] = data.BestKnownSchedule[i, j]; 215 // } 216 // } 217 // BestKnownSolution = JSMDecoder.DecodeSchedule(enc, jobData, JSMDecodingErrorPolicyTypes.RandomPolicy, JSMForcingStrategyTypes.SwapForcing); 218 // if (ScheduleEvaluator is MeanTardinessEvaluator) 219 // BestKnownQuality = new DoubleValue(MeanTardinessEvaluator.GetMeanTardiness(BestKnownSolution, jobData)); 220 // else if (ScheduleEvaluator is MakespanEvaluator) 221 // BestKnownQuality = new DoubleValue(MakespanEvaluator.GetMakespan(BestKnownSolution)); 222 // } 223 224 // JobData = jobData; 225 // Jobs = data.Jobs; 226 // Resources = data.Resources; 227 // } 228 229 // public JSSPData Export() { 230 // var result = new JSSPData { 231 // Name = Name, 232 // Description = Description, 233 // Jobs = Jobs, 234 // Resources = Resources, 235 // ProcessingTimes = new double[Jobs, Resources], 236 // Demands = new int[Jobs, Resources], 237 // DueDates = new double[Jobs] 238 // }; 239 240 // foreach (var job in JobData) { 241 // var counter = 0; 242 // result.DueDates[job.Index] = job.DueDate; 243 // foreach (var task in job.Tasks) { 244 // result.ProcessingTimes[task.JobNr, counter] = task.Duration; 245 // result.Demands[task.JobNr, counter] = task.ResourceNr; 246 // counter++; 247 // } 248 // } 249 // return result; 250 // } 251 // #endregion 252 253 // #region Helpers 254 // private void InitializeOperators() { 255 // Operators.Clear(); 256 // ApplyEncoding(); 257 // Operators.Add(new BestSchedulingSolutionAnalyzer()); 258 // ParameterizeOperators(); 259 // } 260 261 // private void ApplyEncoding() { 262 // if (SolutionCreator.GetType() == typeof(JSMRandomCreator)) { 263 // Operators.AddRange(ApplicationManager.Manager.GetInstances<IJSMOperator>()); 264 // ScheduleDecoder = new JSMDecoder(); 265 // } else if (SolutionCreator.GetType() == typeof(PRVRandomCreator)) { 266 // Operators.AddRange(ApplicationManager.Manager.GetInstances<IPRVOperator>()); 267 // ScheduleDecoder = new PRVDecoder(); 268 // } else if (SolutionCreator.GetType() == typeof(PWRRandomCreator)) { 269 // Operators.AddRange(ApplicationManager.Manager.GetInstances<IPWROperator>()); 270 // ScheduleDecoder = new PWRDecoder(); 271 // } else if (SolutionCreator.GetType() == typeof(DirectScheduleRandomCreator)) { 272 // Operators.AddRange(ApplicationManager.Manager.GetInstances<IDirectScheduleOperator>()); 273 // ScheduleDecoder = null; 274 // } 275 // } 276 277 // private void ParameterizeOperators() { 278 // Evaluator.ScheduleDecoderParameter.ActualName = ScheduleDecoderParameter.Name; 279 // Evaluator.ScheduleDecoderParameter.Hidden = true; 280 // Evaluator.ScheduleEvaluatorParameter.ActualName = ScheduleEvaluatorParameter.Name; 281 // Evaluator.ScheduleEvaluatorParameter.Hidden = true; 282 // Evaluator.QualityParameter.ActualName = ScheduleEvaluator.QualityParameter.ActualName; 283 // Evaluator.QualityParameter.Hidden = true; 284 285 // if (ScheduleDecoder != null) 286 // ScheduleDecoder.ScheduleEncodingParameter.ActualName = SolutionCreator.ScheduleParameter.ActualName; 287 288 // if (ScheduleDecoder != null) { 289 // ScheduleEvaluator.ScheduleParameter.ActualName = ScheduleDecoder.ScheduleParameter.ActualName; 290 // ScheduleEvaluator.ScheduleParameter.Hidden = true; 291 // } else if (SolutionCreator is DirectScheduleRandomCreator) { 292 // var directEvaluator = (DirectScheduleRandomCreator)SolutionCreator; 293 // ScheduleEvaluator.ScheduleParameter.ActualName = directEvaluator.ScheduleParameter.ActualName; 294 // ScheduleEvaluator.ScheduleParameter.Hidden = true; 295 // } else { 296 // ScheduleEvaluator.ScheduleParameter.ActualName = ScheduleEvaluator.ScheduleParameter.Name; 297 // ScheduleEvaluator.ScheduleParameter.Hidden = false; 298 // } 299 300 // foreach (var op in Operators.OfType<IScheduleManipulator>()) { 301 // op.ScheduleParameter.ActualName = SolutionCreator.ScheduleParameter.ActualName; 302 // op.ScheduleParameter.Hidden = true; 303 // } 304 305 // foreach (var op in Operators.OfType<IScheduleCrossover>()) { 306 // op.ChildParameter.ActualName = SolutionCreator.ScheduleParameter.ActualName; 307 // op.ChildParameter.Hidden = true; 308 // op.ParentsParameter.ActualName = SolutionCreator.ScheduleParameter.ActualName; 309 // op.ParentsParameter.Hidden = true; 310 // } 311 312 // foreach (var op in Operators.OfType<BestSchedulingSolutionAnalyzer>()) { 313 // op.QualityParameter.ActualName = ScheduleEvaluator.QualityParameter.ActualName; 314 // if (ScheduleDecoder != null) { 315 // op.ScheduleParameter.ActualName = ScheduleDecoder.ScheduleParameter.ActualName; 316 // op.ScheduleParameter.Hidden = true; 317 // } else if (SolutionCreator is DirectScheduleRandomCreator) { 318 // op.ScheduleParameter.ActualName = ((DirectScheduleRandomCreator)SolutionCreator).ScheduleParameter.ActualName; 319 // op.ScheduleParameter.Hidden = true; 320 // } else { 321 // op.ScheduleParameter.ActualName = op.ScheduleParameter.Name; 322 // op.ScheduleParameter.Hidden = false; 323 // } 324 // } 325 // } 326 // #endregion 327 328 // } 329 //} -
branches/ProblemRefactoring/HeuristicLab.Problems.Scheduling/3.3/SchedulingProblem.cs
r12012 r13443 1 #region License Information2 / * HeuristicLab3 * 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 modify8 * it under the terms of the GNU General Public License as published by9 * the Free Software Foundation, either version 3 of the License, or10 * (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 of14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15 * GNU General Public License for more details.16 *17 * You should have received a copy of the GNU General Public License18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.19 */20 #endregion1 //#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 21 22 using HeuristicLab.Common;23 using HeuristicLab.Core;24 using HeuristicLab.Encodings.ScheduleEncoding;25 using HeuristicLab.Optimization;26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;22 //using HeuristicLab.Common; 23 //using HeuristicLab.Core; 24 //using HeuristicLab.Encodings.ScheduleEncoding; 25 //using HeuristicLab.Optimization; 26 //using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 27 28 namespace HeuristicLab.Problems.Scheduling {29 [Item("SchedulingProblem", "Abstract class that represents a Scheduling Problem")]30 [StorableClass]31 public abstract class SchedulingProblem : SingleObjectiveHeuristicOptimizationProblem<ISchedulingEvaluator, IScheduleCreator> {32 [StorableConstructor]33 protected SchedulingProblem(bool deserializing) : base(deserializing) { }34 protected SchedulingProblem(SchedulingProblem original, Cloner cloner) : base(original, cloner) { }35 protected SchedulingProblem(ISchedulingEvaluator evaluator, IScheduleCreator creator) : base(evaluator, creator) { }36 }37 }28 //namespace HeuristicLab.Problems.Scheduling { 29 // [Item("SchedulingProblem", "Abstract class that represents a Scheduling Problem")] 30 // [StorableClass] 31 // public abstract class SchedulingProblem : SingleObjectiveHeuristicOptimizationProblem<ISchedulingEvaluator, IScheduleCreator> { 32 // [StorableConstructor] 33 // protected SchedulingProblem(bool deserializing) : base(deserializing) { } 34 // protected SchedulingProblem(SchedulingProblem original, Cloner cloner) : base(original, cloner) { } 35 // protected SchedulingProblem(ISchedulingEvaluator evaluator, IScheduleCreator creator) : base(evaluator, creator) { } 36 // } 37 //}
Note: See TracChangeset
for help on using the changeset viewer.