Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.Scheduling/3.3/JobShopSchedulingProblem.cs @ 8882

Last change on this file since 8882 was 8882, checked in by abeham, 11 years ago

#1329:

  • Added JSSPData class to problem instances
  • Added problem instance provider for some ORLIB JSSP instances (abz, ft, la01-20)
  • Adapted JSSP to load and export jssp problems
  • Adapted JSSP problem view to derive from ProblemView
  • Added static methods to MakespanEvaluator and MeanTardinessEvaluator
  • Fixed a bug in PRVUniformOnePositionManipulator
File size: 10.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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
22using System.Drawing;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Encodings.PermutationEncoding;
27using HeuristicLab.Encodings.ScheduleEncoding;
28using HeuristicLab.Encodings.ScheduleEncoding.JobSequenceMatrix;
29using HeuristicLab.Encodings.ScheduleEncoding.PermutationWithRepetition;
30using HeuristicLab.Encodings.ScheduleEncoding.PriorityRulesVector;
31using HeuristicLab.Parameters;
32using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
33using HeuristicLab.PluginInfrastructure;
34using HeuristicLab.Problems.Instances;
35
36namespace HeuristicLab.Problems.Scheduling {
37  [Item("Job Shop Scheduling Problem", "Represents a standard Job Shop Scheduling Problem")]
38  [Creatable("Problems")]
39  [StorableClass]
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
73    #region Parameter Properties
74    public ValueParameter<ItemList<Job>> JobDataParameter {
75      get { return (ValueParameter<ItemList<Job>>)Parameters["JobData"]; }
76    }
77    public OptionalValueParameter<Schedule> BestKnownSolutionParameter {
78      get { return (OptionalValueParameter<Schedule>)Parameters["BestKnownSolution"]; }
79    }
80
81    public ValueParameter<IntValue> JobsParameter {
82      get { return (ValueParameter<IntValue>)Parameters["Jobs"]; }
83    }
84    public ValueParameter<IntValue> ResourcesParameter {
85      get { return (ValueParameter<IntValue>)Parameters["Resources"]; }
86    }
87    public ValueParameter<SchedulingEvaluator> SolutionEvaluatorParameter {
88      get { return (ValueParameter<SchedulingEvaluator>)Parameters["SolutionEvaluator"]; }
89    }
90    public ValueParameter<BoolValue> DueDatesParameter {
91      get { return (ValueParameter<BoolValue>)Parameters["DueDates"]; }
92    }
93    #endregion
94
95    #region Properties
96    public ItemList<Job> JobData {
97      get { return JobDataParameter.Value; }
98      set { JobDataParameter.Value = value; }
99    }
100    public Schedule BestKnownSolution {
101      get { return BestKnownSolutionParameter.Value; }
102      set { BestKnownSolutionParameter.Value = value; }
103    }
104    public IntValue Jobs {
105      get { return JobsParameter.Value; }
106      set { JobsParameter.Value = value; }
107    }
108    public IntValue Resources {
109      get { return ResourcesParameter.Value; }
110      set { ResourcesParameter.Value = value; }
111    }
112    public SchedulingEvaluator SolutionEvaluator {
113      get { return SolutionEvaluatorParameter.Value; }
114      set { SolutionEvaluatorParameter.Value = value; }
115    }
116    public BoolValue DueDates {
117      get { return DueDatesParameter.Value; }
118      set { DueDatesParameter.Value = value; }
119    }
120    public override Image ItemImage {
121      get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; }
122    }
123    public string Filename { get; set; }
124    #endregion
125
126    public JobShopSchedulingProblem()
127      : base(new SchedulingEvaluationAlgorithm(), new JSMRandomCreator()) {
128      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>()));
129      Parameters.Add(new OptionalValueParameter<Schedule>("BestKnownSolution", "The best known solution of this JSSP instance."));
130
131      Parameters.Add(new ValueParameter<IntValue>("Jobs", "The number of jobs used in this JSSP instance.", new IntValue()));
132      Parameters.Add(new ValueParameter<IntValue>("Resources", "The number of resources used in this JSSP instance.", new IntValue()));
133      Parameters.Add(new ValueParameter<BoolValue>("DueDates", "Determines whether the problem instance uses due dates or not.", new BoolValue()));
134      Parameters.Add(new ValueParameter<SchedulingEvaluator>("SolutionEvaluator", "The evaluator used to determine the quality of a solution.", new MakespanEvaluator()));
135
136      InitializeOperators();
137      Load(DefaultInstance);
138    }
139
140    [StorableConstructor]
141    private JobShopSchedulingProblem(bool deserializing) : base(deserializing) { }
142    private JobShopSchedulingProblem(JobShopSchedulingProblem original, Cloner cloner)
143      : base(original, cloner) {
144    }
145    public override IDeepCloneable Clone(Cloner cloner) {
146      return new JobShopSchedulingProblem(this, cloner);
147    }
148
149    #region Events
150    protected override void OnSolutionCreatorChanged() {
151      InitializeOperators();
152    }
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;
211    }
212    #endregion
213
214    #region Helpers
215    private void InitializeOperators() {
216      Operators.Clear();
217      ApplyEncoding();
218      Operators.Add(new BestSchedulingSolutionAnalyzer());
219    }
220
221    private void ApplyEncoding() {
222      if (SolutionCreator.GetType() == typeof(JSMRandomCreator)) {
223        Operators.AddRange(ApplicationManager.Manager.GetInstances<IJSMOperator>());
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      }
238    }
239    #endregion
240
241  }
242}
Note: See TracBrowser for help on using the repository browser.