Changeset 6406 for branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/JobShopSchedulingProblem.cs
- Timestamp:
- 06/10/11 16:18:44 (13 years ago)
- Location:
- branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3
- Property svn:ignore
-
old new 2 2 bin 3 3 obj 4 HeuristicLab.Problems.Scheduling-3.3.csproj.user
-
- Property svn:ignore
-
branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/JobShopSchedulingProblem.cs
r6364 r6406 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 25 using System.Text; 24 using System.IO; 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.Encodings.ScheduleEncoding.JobSequenceMatrix; 31 using HeuristicLab.Encodings.ScheduleEncoding.PermutationWithRepetition; 32 using HeuristicLab.Encodings.ScheduleEncoding.PriorityRulesVector; 33 using HeuristicLab.Parameters; 26 34 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 using HeuristicLab.Core;28 using HeuristicLab.Optimization;29 using HeuristicLab.Common;30 using System.Drawing;31 using HeuristicLab.Data;32 using System.IO;33 using HeuristicLab.Problems.Scheduling.Evaluators;34 using HeuristicLab.Parameters;35 using HeuristicLab.Problems.Scheduling.Analyzers;36 35 using HeuristicLab.PluginInfrastructure; 37 using HeuristicLab.Encodings.SchedulingEncoding;38 using HeuristicLab.Encodings.SchedulingEncoding.Interfaces;39 using HeuristicLab.Encodings.SchedulingEncoding.JobSequenceMatrix;40 using HeuristicLab.Encodings.PermutationEncoding;41 using HeuristicLab.Encodings.SchedulingEncoding.PriorityRulesVector;42 using HeuristicLab.Encodings.SchedulingEncoding.PermutationWithRepetition;43 using HeuristicLab.Problems.Scheduling.Decoders;44 36 45 37 namespace HeuristicLab.Problems.Scheduling { … … 48 40 [StorableClass] 49 41 public sealed class JobShopSchedulingProblem : SchedulingProblem { 42 #region Parameter Properties 43 public ValueParameter<ItemList<Job>> JobDataParameter { 44 get { return (ValueParameter<ItemList<Job>>)Parameters["JobData"]; } 45 } 46 public OptionalValueParameter<Schedule> BestKnownSolutionParameter { 47 get { return (OptionalValueParameter<Schedule>)Parameters["BestKnownSolution"]; } 48 } 49 50 public ValueParameter<IntValue> JobsParameter { 51 get { return (ValueParameter<IntValue>)Parameters["Jobs"]; } 52 } 53 public ValueParameter<IntValue> ResourcesParameter { 54 get { return (ValueParameter<IntValue>)Parameters["Resources"]; } 55 } 56 public ValueParameter<SchedulingEvaluator> SolutionEvaluatorParameter { 57 get { return (ValueParameter<SchedulingEvaluator>)Parameters["SolutionEvaluator"]; } 58 } 59 public ValueParameter<BoolValue> DueDatesParameter { 60 get { return (ValueParameter<BoolValue>)Parameters["DueDates"]; } 61 } 62 #endregion 63 64 #region Properties 65 public ItemList<Job> JobData { 66 get { return JobDataParameter.Value; } 67 set { JobDataParameter.Value = value; } 68 } 69 public Schedule BestKnownSolution { 70 get { return BestKnownSolutionParameter.Value; } 71 set { BestKnownSolutionParameter.Value = value; } 72 } 73 public IntValue Jobs { 74 get { return JobsParameter.Value; } 75 set { JobsParameter.Value = value; } 76 } 77 public IntValue Resources { 78 get { return ResourcesParameter.Value; } 79 set { ResourcesParameter.Value = value; } 80 } 81 public SchedulingEvaluator SolutionEvaluator { 82 get { return SolutionEvaluatorParameter.Value; } 83 set { SolutionEvaluatorParameter.Value = value; } 84 } 85 public BoolValue DueDates { 86 get { return DueDatesParameter.Value; } 87 set { DueDatesParameter.Value = value; } 88 } 89 #endregion 90 91 public JobShopSchedulingProblem() 92 : base(new SchedulingEvaluationAlgorithm(), new JSMRandomCreator()) { 93 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>())); 94 Parameters.Add(new OptionalValueParameter<Schedule>("BestKnownSolution", "The best known solution of this JSSP instance.")); 95 96 Parameters.Add(new ValueParameter<IntValue>("Jobs", "The number of jobs used in this JSSP instance.", new IntValue())); 97 Parameters.Add(new ValueParameter<IntValue>("Resources", "The number of resources used this JSSP instance.", new IntValue())); 98 Parameters.Add(new ValueParameter<BoolValue>("DueDates", "Determines whether the problem instance uses due dates or not.", new BoolValue())); 99 Parameters.Add(new ValueParameter<SchedulingEvaluator>("SolutionEvaluator", "The evaluator used to determine the quality of a solution.", new MakespanEvaluator())); 100 101 InitializeOperators(); 102 InitializeProblemInstance(); 103 } 104 50 105 [StorableConstructor] 51 106 private JobShopSchedulingProblem(bool deserializing) : base(deserializing) { } 52 107 private JobShopSchedulingProblem(JobShopSchedulingProblem original, Cloner cloner) 53 108 : base(original, cloner) { 54 this.Jobs = cloner.Clone(original.Jobs);55 this.Resources = cloner.Clone(original.Resources);56 this.JobData = cloner.Clone(original.JobData);57 this.SolutionEvaluator = cloner.Clone(original.SolutionEvaluator);58 this.DueDates = cloner.Clone(original.DueDates);59 109 } 60 110 public override IDeepCloneable Clone(Cloner cloner) { 61 111 return new JobShopSchedulingProblem(this, cloner); 62 }63 64 65 #region Parameter Properties66 public ValueParameter<ItemList<Job>> JobDataParameter {67 get { return (ValueParameter<ItemList<Job>>)Parameters["JobData"]; }68 }69 public OptionalValueParameter<Schedule> BestKnownSolutionParameter {70 get { return (OptionalValueParameter<Schedule>)Parameters["BestKnownSolution"]; }71 }72 73 public ValueParameter<IntValue> JobsParameter {74 get { return (ValueParameter<IntValue>)Parameters["Jobs"]; }75 }76 public ValueParameter<IntValue> ResourcesParameter {77 get { return (ValueParameter<IntValue>)Parameters["Resources"]; }78 }79 public ValueParameter<SchedulingEvaluator> SolutionEvaluatorParameter {80 get { return (ValueParameter<SchedulingEvaluator>)Parameters["SolutionEvaluator"]; }81 }82 public ValueParameter<BoolValue> DueDatesParameter {83 get { return (ValueParameter<BoolValue>)Parameters["DueDates"]; }84 }85 #endregion86 87 #region Properties88 public ItemList<Job> JobData {89 get { return JobDataParameter.Value; }90 set { JobDataParameter.Value = value; }91 }92 public Schedule BestKnownSolution {93 get { return BestKnownSolutionParameter.Value; }94 set { BestKnownSolutionParameter.Value = value; }95 }96 public IntValue Jobs {97 get { return JobsParameter.Value; }98 set { JobsParameter.Value = value; }99 }100 public IntValue Resources {101 get { return ResourcesParameter.Value; }102 set { ResourcesParameter.Value = value; }103 }104 public SchedulingEvaluator SolutionEvaluator {105 get { return SolutionEvaluatorParameter.Value; }106 set { SolutionEvaluatorParameter.Value = value; }107 }108 public BoolValue DueDates {109 get { return DueDatesParameter.Value; }110 set { DueDatesParameter.Value = value; }111 }112 #endregion113 114 115 public JobShopSchedulingProblem()116 : base(new SchedulingEvaluationAlgorithm (), new JSMRandomCreator ()) {117 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>()));118 Parameters.Add(new OptionalValueParameter<Schedule>("BestKnownSolution", "The best known solution of this JSSP instance."));119 120 Parameters.Add(new ValueParameter<IntValue>("Jobs", "The number of jobs used in this JSSP instance.", new IntValue()));121 Parameters.Add(new ValueParameter<IntValue>("Resources", "The number of resources used this JSSP instance.", new IntValue()));122 Parameters.Add(new ValueParameter<BoolValue>("DueDates", "Determines whether the problem instance uses due dates or not.", new BoolValue()));123 Parameters.Add(new ValueParameter<SchedulingEvaluator>("SolutionEvaluator", "The evaluator used to determine the quality of a solution.", new MakespanEvaluator()));124 125 InitializeOperators();126 InitializeProblemInstance();127 112 } 128 113 … … 131 116 InitializeOperators(); 132 117 } 118 119 protected override void OnEvaluatorChanged() { 120 base.OnEvaluatorChanged(); 121 } 133 122 #endregion 134 123 135 124 #region Helpers 136 private void InitializeProblemInstance 137 Jobs = new IntValue (10);138 Resources = new IntValue (10);139 BestKnownQuality = new DoubleValue 125 private void InitializeProblemInstance() { 126 Jobs = new IntValue(10); 127 Resources = new IntValue(10); 128 BestKnownQuality = new DoubleValue(930); 140 129 JobData = new ItemList<Job>(); 141 130 List<string> data = new List<string> … … 167 156 if (SolutionCreator.GetType().Equals(typeof(JSMRandomCreator))) { 168 157 Operators.AddRange(ApplicationManager.Manager.GetInstances<IJSMOperator>()); 169 ((SchedulingEvaluationAlgorithm)this.EvaluatorParameter.ActualValue).InitializeOperatorGraph<JSMEncoding>(new JSMDecoder()); 158 JSMDecoder decoder = new JSMDecoder(); 159 ((SchedulingEvaluationAlgorithm)this.EvaluatorParameter.ActualValue).InitializeOperatorGraph<JSMEncoding>(decoder); 170 160 } else { 171 161 if (SolutionCreator.GetType().Equals(typeof(PRVRandomCreator))) { 172 162 Operators.AddRange(ApplicationManager.Manager.GetInstances<IPRVOperator>()); 173 ((SchedulingEvaluationAlgorithm)this.EvaluatorParameter.ActualValue).InitializeOperatorGraph<PRVEncoding>(new PRVDecoder()); 163 PRVDecoder decoder = new PRVDecoder(); 164 ((SchedulingEvaluationAlgorithm)this.EvaluatorParameter.ActualValue).InitializeOperatorGraph<PRVEncoding>(decoder); 174 165 } else { 175 166 if (SolutionCreator.GetType().Equals(typeof(PWRRandomCreator))) { 176 167 Operators.AddRange(ApplicationManager.Manager.GetInstances<IPWROperator>()); 177 ((SchedulingEvaluationAlgorithm)this.EvaluatorParameter.ActualValue).InitializeOperatorGraph<PWREncoding>(new PWRDecoder()); 168 PWRDecoder decoder = new PWRDecoder(); 169 ((SchedulingEvaluationAlgorithm)this.EvaluatorParameter.ActualValue).InitializeOperatorGraph<PWREncoding>(decoder); 178 170 } 179 171 } … … 197 189 } 198 190 private int[] GetIntArray(List<string> data) { 199 int[] arr = new int 200 for (int i = 0; i < data.Count; i++ 191 int[] arr = new int[data.Count]; 192 for (int i = 0; i < data.Count; i++) { 201 193 arr[i] = Int32.Parse(data[i]); 202 194 } 203 195 return arr; 204 196 } 205 private Job CreateJobFromData (List<string> data, int jobCount){197 private Job CreateJobFromData(List<string> data, int jobCount) { 206 198 DoubleValue dueDate = null; 207 199 int dataCount = data.Count; … … 233 225 if (data.Count > 0 && ((int)data[0][0] >= 48 && (int)data[0][0] <= 57)) { 234 226 int jobCount = 0; 235 Jobs = new IntValue 236 Resources = new IntValue 227 Jobs = new IntValue(Int32.Parse(data[0])); 228 Resources = new IntValue(Int32.Parse(data[1])); 237 229 //data[2] = bestKnownQuality (double) 238 230 //data[3] = dueDates (0|1) 239 231 DueDates.Value = false; 240 232 if (data.Count > 2) 241 BestKnownQualityParameter.ActualValue = new DoubleValue(Double.Parse 233 BestKnownQualityParameter.ActualValue = new DoubleValue(Double.Parse(data[2])); 242 234 if (data.Count > 3 && data[3] == "1") 243 235 DueDates.Value = true; … … 265 257 JSMEncoding solution = new JSMEncoding(); 266 258 while (!solutionFile.EndOfStream && !solutionFound) { 267 259 268 260 string line = solutionFile.ReadLine(); 269 261 List<string> data = SplitString(line); … … 274 266 data = SplitString(line); 275 267 while (data != null && data.Count > 0 && ((int)data[0][0] >= 48 && (int)data[0][0] <= 57)) { 276 Permutation p = new Permutation(PermutationTypes.Absolute, GetIntArray 268 Permutation p = new Permutation(PermutationTypes.Absolute, GetIntArray(data)); 277 269 solution.JobSequenceMatrix.Add(p); 278 270
Note: See TracChangeset
for help on using the changeset viewer.