Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1329:

  • Removed unnecessary DueDates parameter
  • Changed ValueParameter to FixedValueParameter for Jobs and Resources
  • Made Job and Task INotifyPropertyChanged
  • Added a JobView and TaskView
File size: 9.9 KB
RevLine 
[6121]1#region License Information
2/* HeuristicLab
[8603]3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[6121]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
[6412]22using System.Drawing;
[6406]23using HeuristicLab.Common;
[6121]24using HeuristicLab.Core;
25using HeuristicLab.Data;
[6406]26using HeuristicLab.Encodings.PermutationEncoding;
27using HeuristicLab.Encodings.ScheduleEncoding;
28using HeuristicLab.Encodings.ScheduleEncoding.JobSequenceMatrix;
29using HeuristicLab.Encodings.ScheduleEncoding.PermutationWithRepetition;
30using HeuristicLab.Encodings.ScheduleEncoding.PriorityRulesVector;
[6121]31using HeuristicLab.Parameters;
[6406]32using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[6121]33using HeuristicLab.PluginInfrastructure;
[8882]34using HeuristicLab.Problems.Instances;
[6121]35
36namespace HeuristicLab.Problems.Scheduling {
[8882]37  [Item("Job Shop Scheduling Problem", "Represents a standard Job Shop Scheduling Problem")]
[6121]38  [Creatable("Problems")]
39  [StorableClass]
[8882]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
[6121]73    #region Parameter Properties
[6293]74    public ValueParameter<ItemList<Job>> JobDataParameter {
75      get { return (ValueParameter<ItemList<Job>>)Parameters["JobData"]; }
[6121]76    }
[6177]77    public OptionalValueParameter<Schedule> BestKnownSolutionParameter {
78      get { return (OptionalValueParameter<Schedule>)Parameters["BestKnownSolution"]; }
[6121]79    }
[6266]80
[8886]81    public IFixedValueParameter<IntValue> JobsParameter {
82      get { return (IFixedValueParameter<IntValue>)Parameters["Jobs"]; }
[6293]83    }
[8886]84    public IFixedValueParameter<IntValue> ResourcesParameter {
85      get { return (IFixedValueParameter<IntValue>)Parameters["Resources"]; }
[6293]86    }
[6364]87    public ValueParameter<SchedulingEvaluator> SolutionEvaluatorParameter {
88      get { return (ValueParameter<SchedulingEvaluator>)Parameters["SolutionEvaluator"]; }
89    }
[6121]90    #endregion
91
92    #region Properties
[6293]93    public ItemList<Job> JobData {
94      get { return JobDataParameter.Value; }
95      set { JobDataParameter.Value = value; }
[6121]96    }
[6177]97    public Schedule BestKnownSolution {
[6121]98      get { return BestKnownSolutionParameter.Value; }
99      set { BestKnownSolutionParameter.Value = value; }
100    }
[8886]101    public int Jobs {
102      get { return JobsParameter.Value.Value; }
103      set { JobsParameter.Value.Value = value; }
[6293]104    }
[8886]105    public int Resources {
106      get { return ResourcesParameter.Value.Value; }
107      set { ResourcesParameter.Value.Value = value; }
[6293]108    }
[6364]109    public SchedulingEvaluator SolutionEvaluator {
110      get { return SolutionEvaluatorParameter.Value; }
111      set { SolutionEvaluatorParameter.Value = value; }
112    }
[6412]113    public override Image ItemImage {
114      get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; }
115    }
116    public string Filename { get; set; }
[6121]117    #endregion
118
119    public JobShopSchedulingProblem()
[6406]120      : base(new SchedulingEvaluationAlgorithm(), new JSMRandomCreator()) {
[6293]121      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>()));
122      Parameters.Add(new OptionalValueParameter<Schedule>("BestKnownSolution", "The best known solution of this JSSP instance."));
[6364]123
[8886]124      Parameters.Add(new FixedValueParameter<IntValue>("Jobs", "The number of jobs used in this JSSP instance.", new IntValue()));
125      Parameters.Add(new FixedValueParameter<IntValue>("Resources", "The number of resources used in this JSSP instance.", new IntValue()));
[6364]126      Parameters.Add(new ValueParameter<SchedulingEvaluator>("SolutionEvaluator", "The evaluator used to determine the quality of a solution.", new MakespanEvaluator()));
127
128      InitializeOperators();
[8882]129      Load(DefaultInstance);
[6121]130    }
131
[6406]132    [StorableConstructor]
133    private JobShopSchedulingProblem(bool deserializing) : base(deserializing) { }
134    private JobShopSchedulingProblem(JobShopSchedulingProblem original, Cloner cloner)
135      : base(original, cloner) {
136    }
137    public override IDeepCloneable Clone(Cloner cloner) {
138      return new JobShopSchedulingProblem(this, cloner);
139    }
140
[6121]141    #region Events
[6177]142    protected override void OnSolutionCreatorChanged() {
143      InitializeOperators();
144    }
[8882]145    #endregion
[6406]146
[8882]147    #region Problem Instance Handling
148    public void Load(JSSPData data) {
149      var jobData = new ItemList<Job>(data.Jobs);
150      for (int j = 0; j < data.Jobs; j++) {
151        var job = new Job(j, data.DueDates != null ? data.DueDates[j] : double.MaxValue);
152        for (int t = 0; t < data.Resources; t++) {
153          job.Tasks.Add(new Task(t, data.Demands[j, t], j, data.ProcessingTimes[j, t]));
154        }
155        jobData.Add(job);
156      }
157
158      if (data.BestKnownQuality.HasValue) BestKnownQuality = new DoubleValue(data.BestKnownQuality.Value);
159      else BestKnownQuality = null;
160      if (data.BestKnownSchedule != null) {
161        var enc = new JSMEncoding();
162        enc.JobSequenceMatrix = new ItemList<Permutation>(data.Resources);
163        for (int i = 0; i < data.Resources; i++) {
164          enc.JobSequenceMatrix[i] = new Permutation(PermutationTypes.Absolute, new int[data.Jobs]);
165          for (int j = 0; j < data.Jobs; j++) {
166            enc.JobSequenceMatrix[i][j] = data.BestKnownSchedule[i, j];
167          }
168        }
169        BestKnownSolution = new JSMDecoder().CreateScheduleFromEncoding(enc, jobData);
170        if (SolutionEvaluator is MeanTardinessEvaluator)
171          BestKnownQuality = new DoubleValue(MeanTardinessEvaluator.GetMeanTardiness(BestKnownSolution, jobData));
172        else if (SolutionEvaluator is MakespanEvaluator)
173          BestKnownQuality = new DoubleValue(MakespanEvaluator.GetMakespan(BestKnownSolution));
174      }
175
176      JobData = jobData;
[8886]177      Jobs = data.Jobs;
178      Resources = data.Resources;
[6406]179    }
[6121]180
[8882]181    public JSSPData Export() {
182      var result = new JSSPData {
183        Name = Name,
184        Description = Description,
[8886]185        Jobs = Jobs,
186        Resources = Resources,
187        ProcessingTimes = new double[Jobs, Resources],
188        Demands = new int[Jobs, Resources],
189        DueDates = new double[Jobs]
[8882]190      };
[6364]191
[8882]192      foreach (var job in JobData) {
193        var counter = 0;
[8886]194        result.DueDates[job.Index] = job.DueDate;
[8882]195        foreach (var task in job.Tasks) {
196          result.ProcessingTimes[task.JobNr, counter] = task.Duration;
197          result.Demands[task.JobNr, counter] = task.ResourceNr;
198          counter++;
199        }
[6364]200      }
[8882]201      return result;
[6364]202    }
[8882]203    #endregion
[6364]204
[8882]205    #region Helpers
[6121]206    private void InitializeOperators() {
[6177]207      Operators.Clear();
208      ApplyEncoding();
[6121]209      Operators.Add(new BestSchedulingSolutionAnalyzer());
210    }
211
[6177]212    private void ApplyEncoding() {
[8882]213      if (SolutionCreator.GetType() == typeof(JSMRandomCreator)) {
[6364]214        Operators.AddRange(ApplicationManager.Manager.GetInstances<IJSMOperator>());
[8882]215        var decoder = new JSMDecoder();
216        ((SchedulingEvaluationAlgorithm)EvaluatorParameter.ActualValue).InitializeOperatorGraph(decoder);
217      } else if (SolutionCreator.GetType() == typeof(PRVRandomCreator)) {
218        Operators.AddRange(ApplicationManager.Manager.GetInstances<IPRVOperator>());
219        var decoder = new PRVDecoder();
220        ((SchedulingEvaluationAlgorithm)EvaluatorParameter.ActualValue).InitializeOperatorGraph(decoder);
221      } else if (SolutionCreator.GetType() == typeof(PWRRandomCreator)) {
222        Operators.AddRange(ApplicationManager.Manager.GetInstances<IPWROperator>());
223        var decoder = new PWRDecoder();
224        ((SchedulingEvaluationAlgorithm)EvaluatorParameter.ActualValue).InitializeOperatorGraph(decoder);
225      } else if (SolutionCreator.GetType() == typeof(DirectScheduleRandomCreator)) {
226        Operators.AddRange(ApplicationManager.Manager.GetInstances<IDirectScheduleOperator>());
227        ((SchedulingEvaluationAlgorithm)EvaluatorParameter.ActualValue).InitializeOperatorGraph<Schedule>();
[6177]228      }
229    }
[6121]230    #endregion
231
232  }
233}
Note: See TracBrowser for help on using the repository browser.