Changeset 8882 for trunk/sources/HeuristicLab.Problems.Scheduling
- Timestamp:
- 11/08/12 13:31:18 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.Scheduling/3.3
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.Scheduling/3.3/Evaluators/MakespanEvaluator.cs
r8603 r8882 20 20 #endregion 21 21 22 using System.Linq; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 41 42 public MakespanEvaluator() : base() { } 42 43 43 protected override DoubleValue evaluate(Schedule schedule) { 44 DoubleValue quality = new DoubleValue(0); 45 foreach (Resource r in schedule.Resources) { 46 if (r.TotalDuration > quality.Value) { 47 quality.Value = r.TotalDuration; 48 } 49 } 50 return quality; 44 public static double GetMakespan(Schedule schedule) { 45 return schedule.Resources.Select(r => r.TotalDuration).Max(); 46 } 47 48 protected override DoubleValue Evaluate(Schedule schedule) { 49 return new DoubleValue(GetMakespan(schedule)); 51 50 } 52 51 -
trunk/sources/HeuristicLab.Problems.Scheduling/3.3/Evaluators/MeanTardinessEvaluator.cs
r8603 r8882 20 20 #endregion 21 21 22 using System; 23 using System.Linq; 22 24 using HeuristicLab.Common; 23 25 using HeuristicLab.Core; … … 31 33 [StorableClass] 32 34 public class MeanTardinessEvaluator : SchedulingEvaluator, IJSSPOperator { 35 33 36 [StorableConstructor] 34 37 protected MeanTardinessEvaluator(bool deserializing) : base(deserializing) { } 35 protected MeanTardinessEvaluator(MeanTardinessEvaluator original, Cloner cloner) 36 : base(original, cloner) { 37 } 38 protected MeanTardinessEvaluator(MeanTardinessEvaluator original, Cloner cloner) : base(original, cloner) { } 38 39 public override IDeepCloneable Clone(Cloner cloner) { 39 40 return new MeanTardinessEvaluator(this, cloner); … … 45 46 } 46 47 #endregion 47 #region Properties48 public ItemList<Job> JobData {49 get { return JobDataParameter.ActualValue; }50 }51 #endregion52 48 53 49 public MeanTardinessEvaluator() … … 56 52 } 57 53 58 protected override DoubleValue evaluate(Schedule schedule) { 59 double totalTardiness = 0; 60 foreach (Resource r in schedule.Resources) { 61 double tardiness = r.Tasks[r.Tasks.Count - 1].EndTime - JobData[r.Tasks[r.Tasks.Count - 1].JobNr].DueDate; 62 if (tardiness > 0) 63 totalTardiness += tardiness; 64 } 65 return new DoubleValue(totalTardiness / schedule.Resources.Count); 54 public static double GetMeanTardiness(Schedule schedule, ItemList<Job> jobData) { 55 return schedule.Resources 56 .Select(r => Math.Max(0, r.Tasks.Last().EndTime - jobData[r.Tasks.Last().JobNr].DueDate)) 57 .Average(); 66 58 } 67 59 68 p ublic override IOperation Apply() {69 return base.Apply();60 protected override DoubleValue Evaluate(Schedule schedule) { 61 return new DoubleValue(GetMeanTardiness(schedule, JobDataParameter.ActualValue)); 70 62 } 71 63 } -
trunk/sources/HeuristicLab.Problems.Scheduling/3.3/Evaluators/SchedulingEvaluator.cs
r8603 r8882 61 61 } 62 62 63 protected abstract DoubleValue evaluate(Schedule schedule);63 protected abstract DoubleValue Evaluate(Schedule schedule); 64 64 65 65 public override IOperation Apply() { 66 66 Schedule schedule = ScheduleParameter.ActualValue; 67 QualityParameter.ActualValue = evaluate(schedule);67 QualityParameter.ActualValue = Evaluate(schedule); 68 68 return base.Apply(); 69 69 } -
trunk/sources/HeuristicLab.Problems.Scheduling/3.3/HeuristicLab.Problems.Scheduling-3.3.csproj
r8800 r8882 193 193 <Private>False</Private> 194 194 </ProjectReference> 195 <ProjectReference Include="..\..\HeuristicLab.Problems.Instances\3.3\HeuristicLab.Problems.Instances-3.3.csproj"> 196 <Project>{3540E29E-4793-49E7-8EE2-FEA7F61C3994}</Project> 197 <Name>HeuristicLab.Problems.Instances-3.3</Name> 198 <Private>False</Private> 199 </ProjectReference> 195 200 </ItemGroup> 196 201 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
trunk/sources/HeuristicLab.Problems.Scheduling/3.3/JobShopSchedulingProblem.cs
r8603 r8882 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 22 using System.Drawing; 25 using System.IO;26 23 using HeuristicLab.Common; 27 24 using HeuristicLab.Core; … … 35 32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 36 33 using HeuristicLab.PluginInfrastructure; 34 using HeuristicLab.Problems.Instances; 37 35 38 36 namespace HeuristicLab.Problems.Scheduling { 39 [Item("Job Shop Scheduling Problem", "Represents a standard JobShop Scheduling Problem")]37 [Item("Job Shop Scheduling Problem", "Represents a standard Job Shop Scheduling Problem")] 40 38 [Creatable("Problems")] 41 39 [StorableClass] 42 public sealed class JobShopSchedulingProblem : SchedulingProblem, IStorableContent { 40 public sealed class JobShopSchedulingProblem : SchedulingProblem, IProblemInstanceConsumer<JSSPData>, IProblemInstanceExporter<JSSPData>, IStorableContent { 41 #region Default Instance 42 private static readonly JSSPData DefaultInstance = new JSSPData() { 43 Jobs = 10, 44 Resources = 10, 45 BestKnownQuality = 930, 46 ProcessingTimes = new double[,] { 47 { 29, 78, 9, 36, 49, 11, 62, 56, 44, 21 }, 48 { 43, 90, 75, 11, 69, 28, 46, 46, 72, 30 }, 49 { 91, 85, 39, 74, 90, 10, 12, 89, 45, 33 }, 50 { 81, 95, 71, 99, 9, 52, 85, 98, 22, 43 }, 51 { 14, 6, 22, 61, 26, 69, 21, 49, 72, 53 }, 52 { 84, 2, 52, 95, 48, 72, 47, 65, 6, 25 }, 53 { 46, 37, 61, 13, 32, 21, 32, 89, 30, 55 }, 54 { 31, 86, 46, 74, 32, 88, 19, 48, 36, 79 }, 55 { 76, 69, 76, 51, 85, 11, 40, 89, 26, 74 }, 56 { 85, 13, 61, 7, 64, 76, 47, 52, 90, 45 } 57 }, 58 Demands = new int[,] { 59 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 60 { 0, 2, 4, 9, 3, 1, 6, 5, 7, 8 }, 61 { 1, 0, 3, 2, 8, 5, 7, 6, 9, 4 }, 62 { 1, 2, 0, 4, 6, 8, 7, 3, 9, 5 }, 63 { 2, 0, 1, 5, 3, 4, 8, 7, 9, 6 }, 64 { 2, 1, 5, 3, 8, 9, 0, 6, 4, 7 }, 65 { 1, 0, 3, 2, 6, 5, 9, 8, 7, 4 }, 66 { 2, 0, 1, 5, 4, 6, 8, 9, 7, 3 }, 67 { 0, 1, 3, 5, 2, 9, 6, 7, 4, 8 }, 68 { 1, 0, 2, 6, 8, 9, 5, 3, 4, 7 } 69 } 70 }; 71 #endregion 72 43 73 #region Parameter Properties 44 74 public ValueParameter<ItemList<Job>> JobDataParameter { … … 105 135 106 136 InitializeOperators(); 107 InitializeProblemInstance();137 Load(DefaultInstance); 108 138 } 109 139 … … 121 151 InitializeOperators(); 122 152 } 123 124 protected override void OnEvaluatorChanged() { 125 base.OnEvaluatorChanged(); 153 #endregion 154 155 #region Problem Instance Handling 156 public void Load(JSSPData data) { 157 var jobData = new ItemList<Job>(data.Jobs); 158 for (int j = 0; j < data.Jobs; j++) { 159 var job = new Job(j, data.DueDates != null ? data.DueDates[j] : double.MaxValue); 160 for (int t = 0; t < data.Resources; t++) { 161 job.Tasks.Add(new Task(t, data.Demands[j, t], j, data.ProcessingTimes[j, t])); 162 } 163 jobData.Add(job); 164 } 165 166 if (data.BestKnownQuality.HasValue) BestKnownQuality = new DoubleValue(data.BestKnownQuality.Value); 167 else BestKnownQuality = null; 168 if (data.BestKnownSchedule != null) { 169 var enc = new JSMEncoding(); 170 enc.JobSequenceMatrix = new ItemList<Permutation>(data.Resources); 171 for (int i = 0; i < data.Resources; i++) { 172 enc.JobSequenceMatrix[i] = new Permutation(PermutationTypes.Absolute, new int[data.Jobs]); 173 for (int j = 0; j < data.Jobs; j++) { 174 enc.JobSequenceMatrix[i][j] = data.BestKnownSchedule[i, j]; 175 } 176 } 177 BestKnownSolution = new JSMDecoder().CreateScheduleFromEncoding(enc, jobData); 178 if (SolutionEvaluator is MeanTardinessEvaluator) 179 BestKnownQuality = new DoubleValue(MeanTardinessEvaluator.GetMeanTardiness(BestKnownSolution, jobData)); 180 else if (SolutionEvaluator is MakespanEvaluator) 181 BestKnownQuality = new DoubleValue(MakespanEvaluator.GetMakespan(BestKnownSolution)); 182 } 183 184 JobData = jobData; 185 Jobs = new IntValue(data.Jobs); 186 Resources = new IntValue(data.Resources); 187 DueDates = new BoolValue(data.DueDates != null); 188 } 189 190 public JSSPData Export() { 191 var result = new JSSPData { 192 Name = Name, 193 Description = Description, 194 Jobs = Jobs.Value, 195 Resources = Resources.Value, 196 ProcessingTimes = new double[Jobs.Value, Resources.Value], 197 Demands = new int[Jobs.Value, Resources.Value], 198 DueDates = (DueDates.Value ? new double[Jobs.Value] : null) 199 }; 200 201 foreach (var job in JobData) { 202 var counter = 0; 203 if (DueDates.Value) result.DueDates[job.Index] = job.DueDate; 204 foreach (var task in job.Tasks) { 205 result.ProcessingTimes[task.JobNr, counter] = task.Duration; 206 result.Demands[task.JobNr, counter] = task.ResourceNr; 207 counter++; 208 } 209 } 210 return result; 126 211 } 127 212 #endregion 128 213 129 214 #region Helpers 130 private void InitializeProblemInstance() {131 Jobs = new IntValue(10);132 Resources = new IntValue(10);133 BestKnownQuality = new DoubleValue(930);134 JobData = new ItemList<Job>();135 List<string> data = new List<string>136 {"0 29 1 78 2 9 3 36 4 49 5 11 6 62 7 56 8 44 9 21",137 "0 43 2 90 4 75 9 11 3 69 1 28 6 46 5 46 7 72 8 30",138 "1 91 0 85 3 39 2 74 8 90 5 10 7 12 6 89 9 45 4 33",139 "1 81 2 95 0 71 4 99 6 9 8 52 7 85 3 98 9 22 5 43",140 "2 14 0 6 1 22 5 61 3 26 4 69 8 21 7 49 9 72 6 53",141 "2 84 1 2 5 52 3 95 8 48 9 72 0 47 6 65 4 6 7 25",142 "1 46 0 37 3 61 2 13 6 32 5 21 9 32 8 89 7 30 4 55",143 "2 31 0 86 1 46 5 74 4 32 6 88 8 19 9 48 7 36 3 79",144 "0 76 1 69 3 76 5 51 2 85 9 11 6 40 7 89 4 26 8 74",145 "1 85 0 13 2 61 6 7 8 64 9 76 5 47 3 52 4 90 7 45" };146 147 int jobCount = 0;148 foreach (string s in data) {149 List<string> split = SplitString(s);150 JobData.Add(CreateJobFromData(split, jobCount++));151 }152 }153 154 215 private void InitializeOperators() { 155 216 Operators.Clear(); … … 159 220 160 221 private void ApplyEncoding() { 161 if (SolutionCreator.GetType() .Equals(typeof(JSMRandomCreator))) {222 if (SolutionCreator.GetType() == typeof(JSMRandomCreator)) { 162 223 Operators.AddRange(ApplicationManager.Manager.GetInstances<IJSMOperator>()); 163 JSMDecoder decoder = new JSMDecoder(); 164 ((SchedulingEvaluationAlgorithm)this.EvaluatorParameter.ActualValue).InitializeOperatorGraph<JSMEncoding>(decoder); 165 } else { 166 if (SolutionCreator.GetType().Equals(typeof(PRVRandomCreator))) { 167 Operators.AddRange(ApplicationManager.Manager.GetInstances<IPRVOperator>()); 168 PRVDecoder decoder = new PRVDecoder(); 169 ((SchedulingEvaluationAlgorithm)this.EvaluatorParameter.ActualValue).InitializeOperatorGraph<PRVEncoding>(decoder); 170 } else { 171 if (SolutionCreator.GetType().Equals(typeof(PWRRandomCreator))) { 172 Operators.AddRange(ApplicationManager.Manager.GetInstances<IPWROperator>()); 173 PWRDecoder decoder = new PWRDecoder(); 174 ((SchedulingEvaluationAlgorithm)this.EvaluatorParameter.ActualValue).InitializeOperatorGraph<PWREncoding>(decoder); 175 } else { 176 if (SolutionCreator.GetType().Equals(typeof(DirectScheduleRandomCreator))) { 177 Operators.AddRange(ApplicationManager.Manager.GetInstances<IDirectScheduleOperator>()); 178 ((SchedulingEvaluationAlgorithm)this.EvaluatorParameter.ActualValue).InitializeOperatorGraph<Schedule>(); 179 } 180 } 181 } 182 } 183 } 184 #endregion 185 186 #region Importmethods 187 private List<string> SplitString(string line) { 188 if (line == null) 189 return null; 190 List<string> data = new List<string>(line.Split(' ')); 191 List<string> result = new List<string>(); 192 193 foreach (string s in data) { 194 if (!String.IsNullOrEmpty(s) && s != "" && s != " ") 195 result.Add(s); 196 } 197 198 return result; 199 } 200 private int[] GetIntArray(List<string> data) { 201 int[] arr = new int[data.Count]; 202 for (int i = 0; i < data.Count; i++) { 203 arr[i] = Int32.Parse(data[i]); 204 } 205 return arr; 206 } 207 private Job CreateJobFromData(List<string> data, int jobCount) { 208 double dueDate = 0; 209 int dataCount = data.Count; 210 if (DueDates.Value) { 211 dueDate = Double.Parse(data[data.Count - 1]); 212 dataCount--; 213 } 214 Job j = new Job(jobCount, dueDate); 215 for (int i = 0; i < dataCount; i++) { 216 Task t = new Task(i / 2, Int32.Parse(data[i]), jobCount, Double.Parse(data[i + 1])); 217 j.Tasks.Add(t); 218 i++; 219 }//for 220 return j; 221 } 222 223 public void ImportFromORLibrary(string fileName) { 224 if (!File.Exists(fileName)) 225 return; 226 StreamReader problemFile = new StreamReader(fileName); 227 //assures that the parser only reads the first problem instance given in the file 228 bool problemFound = false; 229 230 JobData = new ItemList<Job>(); 231 232 while (!problemFile.EndOfStream && !problemFound) { 233 string line = problemFile.ReadLine(); 234 List<string> data = SplitString(line); 235 if (data.Count > 0 && ((int)data[0][0] >= 48 && (int)data[0][0] <= 57)) { 236 int jobCount = 0; 237 Jobs = new IntValue(Int32.Parse(data[0])); 238 Resources = new IntValue(Int32.Parse(data[1])); 239 //data[2] = bestKnownQuality (double) 240 //data[3] = dueDates (0|1) 241 DueDates.Value = false; 242 if (data.Count > 2) 243 BestKnownQualityParameter.ActualValue = new DoubleValue(Double.Parse(data[2])); 244 if (data.Count > 3 && data[3] == "1") 245 DueDates.Value = true; 246 line = problemFile.ReadLine(); 247 data = SplitString(line); 248 while (!problemFile.EndOfStream && data.Count > 0 && ((int)data[0][0] >= 48 && (int)data[0][0] <= 57)) { 249 Job j = CreateJobFromData(data, jobCount); 250 this.JobData.Add(j); 251 jobCount++; 252 line = problemFile.ReadLine(); 253 data = SplitString(line); 254 }//while 255 problemFound = true; 256 }//if 257 }//while 258 problemFile.Close(); 259 } 260 261 public void ImportJSMSolution(string fileName) { 262 if (!File.Exists(fileName)) 263 return; 264 StreamReader solutionFile = new StreamReader(fileName); 265 //assures that the parser only reads the first solution instance given in the file 266 bool solutionFound = false; 267 JSMEncoding solution = new JSMEncoding(); 268 while (!solutionFile.EndOfStream && !solutionFound) { 269 270 string line = solutionFile.ReadLine(); 271 List<string> data = SplitString(line); 272 if (data.Count > 0 && ((int)data[0][0] >= 48 && (int)data[0][0] <= 57)) { 273 if (data.Count > 2) 274 BestKnownQualityParameter.ActualValue = new DoubleValue(Double.Parse(data[2])); 275 line = solutionFile.ReadLine(); 276 data = SplitString(line); 277 while (data != null && data.Count > 0 && ((int)data[0][0] >= 48 && (int)data[0][0] <= 57)) { 278 Permutation p = new Permutation(PermutationTypes.Absolute, GetIntArray(data)); 279 solution.JobSequenceMatrix.Add(p); 280 281 line = solutionFile.ReadLine(); 282 data = SplitString(line); 283 }//while 284 solutionFound = true; 285 }//if 286 }//while 287 solutionFile.Close(); 288 289 JSMDecoder decoder = new JSMDecoder(); 290 Schedule result = decoder.CreateScheduleFromEncoding(solution, JobData); 291 BestKnownSolution = result; 224 var decoder = new JSMDecoder(); 225 ((SchedulingEvaluationAlgorithm)EvaluatorParameter.ActualValue).InitializeOperatorGraph(decoder); 226 } else if (SolutionCreator.GetType() == typeof(PRVRandomCreator)) { 227 Operators.AddRange(ApplicationManager.Manager.GetInstances<IPRVOperator>()); 228 var decoder = new PRVDecoder(); 229 ((SchedulingEvaluationAlgorithm)EvaluatorParameter.ActualValue).InitializeOperatorGraph(decoder); 230 } else if (SolutionCreator.GetType() == typeof(PWRRandomCreator)) { 231 Operators.AddRange(ApplicationManager.Manager.GetInstances<IPWROperator>()); 232 var decoder = new PWRDecoder(); 233 ((SchedulingEvaluationAlgorithm)EvaluatorParameter.ActualValue).InitializeOperatorGraph(decoder); 234 } else if (SolutionCreator.GetType() == typeof(DirectScheduleRandomCreator)) { 235 Operators.AddRange(ApplicationManager.Manager.GetInstances<IDirectScheduleOperator>()); 236 ((SchedulingEvaluationAlgorithm)EvaluatorParameter.ActualValue).InitializeOperatorGraph<Schedule>(); 237 } 292 238 } 293 239 #endregion -
trunk/sources/HeuristicLab.Problems.Scheduling/3.3/Plugin.cs.frame
r8603 r8882 37 37 [PluginDependency("HeuristicLab.Parameters", "3.3")] 38 38 [PluginDependency("HeuristicLab.Persistence", "3.3")] 39 [PluginDependency("HeuristicLab.Problems.Instances", "3.3")] 39 40 public class HeuristicLabProblemsSchedulingPlugin : PluginBase { 40 41 }
Note: See TracChangeset
for help on using the changeset viewer.