Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleDecoder.cs @ 16532

Last change on this file since 16532 was 13469, checked in by mkommend, 9 years ago

#2521: Refactored problem base classes and adapted scheduling encoding, scheduling problem and unit tests.

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.Operators;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Encodings.ScheduleEncoding {
30  [Item("ScheduleDecoder", "A schedule decoder translates a respresentation into an actual schedule.")]
31  [StorableClass]
32  public abstract class ScheduleDecoder<TSchedule> : SingleSuccessorOperator, IScheduleDecoder<TSchedule>
33  where TSchedule : class, ISchedule {
34
35    public ILookupParameter<ISchedule> ScheduleEncodingParameter {
36      get { return (ILookupParameter<ISchedule>)Parameters["EncodedSchedule"]; }
37    }
38    public ILookupParameter<Schedule> ScheduleParameter {
39      get { return (ILookupParameter<Schedule>)Parameters["Schedule"]; }
40    }
41    public ILookupParameter<ItemList<Job>> JobDataParameter {
42      get { return (LookupParameter<ItemList<Job>>)Parameters["JobData"]; }
43    }
44
45    [StorableConstructor]
46    protected ScheduleDecoder(bool deserializing) : base(deserializing) { }
47    protected ScheduleDecoder(ScheduleDecoder<TSchedule> original, Cloner cloner) : base(original, cloner) { }
48    public ScheduleDecoder()
49      : base() {
50      Parameters.Add(new LookupParameter<ISchedule>("EncodedSchedule", "The new scheduling solution represented as encoding."));
51      Parameters.Add(new LookupParameter<Schedule>("Schedule", "The decoded scheduling solution represented as generalized schedule."));
52      Parameters.Add(new LookupParameter<ItemList<Job>>("JobData", "Job data taken from the JSSP - Instance."));
53    }
54
55    public Schedule DecodeSchedule(ISchedule schedule, ItemList<Job> jobData) {
56      TSchedule solution = schedule as TSchedule;
57      if (solution == null) throw new InvalidOperationException("Encoding is not of type " + typeof(TSchedule).GetPrettyName());
58      return DecodeSchedule(solution, jobData);
59    }
60    public abstract Schedule DecodeSchedule(TSchedule schedule, ItemList<Job> jobData);
61
62    public override IOperation Apply() {
63      Schedule result = DecodeSchedule(ScheduleEncodingParameter.ActualValue, JobDataParameter.ActualValue);
64      ScheduleParameter.ActualValue = result;
65      return base.Apply();
66    }
67  }
68}
Note: See TracBrowser for help on using the repository browser.