Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ProblemRefactoring/HeuristicLab.Problems.Scheduling/3.3/Decoders/PWRDecoder.cs @ 13437

Last change on this file since 13437 was 13437, checked in by mkommend, 8 years ago

#2521: Added encodings for schedules.

File size: 3.1 KB
Line 
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
22using System;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Encodings.ScheduleEncoding;
26using HeuristicLab.Optimization;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Problems.Scheduling {
31  [Item("PWRDecoder", "An item used to convert a PWR-individual into a generalized schedule.")]
32  [StorableClass]
33  public class PWRDecoder : ScheduleDecoder, IStochasticOperator, IJSSPOperator {
34
35    public ILookupParameter<IRandom> RandomParameter {
36      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
37    }
38    public ILookupParameter<ItemList<Job>> JobDataParameter {
39      get { return (LookupParameter<ItemList<Job>>)Parameters["JobData"]; }
40    }
41
42    [StorableConstructor]
43    protected PWRDecoder(bool deserializing) : base(deserializing) { }
44    protected PWRDecoder(PWRDecoder original, Cloner cloner) : base(original, cloner) { }
45    public PWRDecoder()
46      : base() {
47      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
48      Parameters.Add(new LookupParameter<ItemList<Job>>("JobData", "Job data taken from the JSSP - Instance."));
49      ScheduleEncodingParameter.ActualName = "PermutationWithRepetition";
50    }
51
52    public override IDeepCloneable Clone(Cloner cloner) {
53      return new PWRDecoder(this, cloner);
54    }
55
56    public override Schedule CreateScheduleFromEncoding(ISchedule encoding) {
57      var solution = encoding as PWREncoding;
58      if (solution == null) throw new InvalidOperationException("Encoding is not of type PWREncoding");
59
60      var jobs = (ItemList<Job>)JobDataParameter.ActualValue.Clone();
61      var resultingSchedule = new Schedule(jobs[0].Tasks.Count);
62      foreach (int jobNr in solution.PermutationWithRepetition) {
63        int i = 0;
64        while (jobs[jobNr].Tasks[i].IsScheduled) i++;
65        Task currentTask = jobs[jobNr].Tasks[i];
66        double startTime = GTAlgorithmUtils.ComputeEarliestStartTime(currentTask, resultingSchedule);
67        currentTask.IsScheduled = true;
68        resultingSchedule.ScheduleTask(currentTask.ResourceNr, startTime, currentTask.Duration, currentTask.JobNr);
69      }
70      return resultingSchedule;
71    }
72  }
73}
Note: See TracBrowser for help on using the repository browser.