1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2011 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 |
|
---|
22 | using HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Encodings.ScheduleEncoding;
|
---|
25 | using HeuristicLab.Encodings.ScheduleEncoding.PermutationWithRepetition;
|
---|
26 | using HeuristicLab.Optimization;
|
---|
27 | using HeuristicLab.Parameters;
|
---|
28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
29 |
|
---|
30 | namespace 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<PWREncoding>, IStochasticOperator, IJSSPOperator {
|
---|
34 | public ILookupParameter<IRandom> RandomParameter {
|
---|
35 | get { return (LookupParameter<IRandom>)Parameters["Random"]; }
|
---|
36 | }
|
---|
37 | public ILookupParameter<ItemList<Job>> JobDataParameter {
|
---|
38 | get { return (LookupParameter<ItemList<Job>>)Parameters["JobData"]; }
|
---|
39 | }
|
---|
40 |
|
---|
41 | [StorableConstructor]
|
---|
42 | protected PWRDecoder(bool deserializing) : base(deserializing) { }
|
---|
43 | protected PWRDecoder(PWRDecoder original, Cloner cloner)
|
---|
44 | : base(original, cloner) {
|
---|
45 | }
|
---|
46 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
47 | return new PWRDecoder(this, cloner);
|
---|
48 | }
|
---|
49 |
|
---|
50 | public PWRDecoder()
|
---|
51 | : base() {
|
---|
52 | Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
|
---|
53 | Parameters.Add(new LookupParameter<ItemList<Job>>("JobData", "Job data taken from the JSSP - Instance."));
|
---|
54 | ScheduleEncodingParameter.ActualName = "PermutationWithRepetition";
|
---|
55 | }
|
---|
56 |
|
---|
57 | public override Schedule CreateScheduleFromEncoding(PWREncoding solution) {
|
---|
58 | ItemList<Job> jobs = (ItemList<Job>)JobDataParameter.ActualValue.Clone();
|
---|
59 | Schedule resultingSchedule = new Schedule(jobs[0].Tasks.Count);
|
---|
60 | foreach (int jobNr in solution.PermutationWithRepetition) {
|
---|
61 | int i = 0;
|
---|
62 | while (jobs[jobNr].Tasks[i].IsScheduled) i++;
|
---|
63 | Task currentTask = jobs[jobNr].Tasks[i];
|
---|
64 | double startTime = GTAlgorithmUtils.ComputeEarliestStartTime(currentTask, resultingSchedule);
|
---|
65 | currentTask.IsScheduled = true;
|
---|
66 | resultingSchedule.ScheduleTask(currentTask.ResourceNr, startTime, currentTask.Duration, currentTask.JobNr);
|
---|
67 | }
|
---|
68 | return resultingSchedule;
|
---|
69 | }
|
---|
70 |
|
---|
71 | public override IOperation Apply() {
|
---|
72 | return base.Apply();
|
---|
73 | }
|
---|
74 | }
|
---|
75 | }
|
---|