[8887] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12012] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[8887] | 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 |
|
---|
[13469] | 22 | using System;
|
---|
[8887] | 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Operators;
|
---|
| 26 | using HeuristicLab.Parameters;
|
---|
| 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 28 |
|
---|
[13443] | 29 | namespace HeuristicLab.Encodings.ScheduleEncoding {
|
---|
[8887] | 30 | [Item("ScheduleDecoder", "A schedule decoder translates a respresentation into an actual schedule.")]
|
---|
| 31 | [StorableClass]
|
---|
[13469] | 32 | public abstract class ScheduleDecoder<TSchedule> : SingleSuccessorOperator, IScheduleDecoder<TSchedule>
|
---|
| 33 | where TSchedule : class, ISchedule {
|
---|
[8887] | 34 |
|
---|
[13435] | 35 | public ILookupParameter<ISchedule> ScheduleEncodingParameter {
|
---|
[13443] | 36 | get { return (ILookupParameter<ISchedule>)Parameters["EncodedSchedule"]; }
|
---|
[8887] | 37 | }
|
---|
| 38 | public ILookupParameter<Schedule> ScheduleParameter {
|
---|
| 39 | get { return (ILookupParameter<Schedule>)Parameters["Schedule"]; }
|
---|
| 40 | }
|
---|
[13443] | 41 | public ILookupParameter<ItemList<Job>> JobDataParameter {
|
---|
| 42 | get { return (LookupParameter<ItemList<Job>>)Parameters["JobData"]; }
|
---|
| 43 | }
|
---|
[8887] | 44 |
|
---|
| 45 | [StorableConstructor]
|
---|
| 46 | protected ScheduleDecoder(bool deserializing) : base(deserializing) { }
|
---|
[13469] | 47 | protected ScheduleDecoder(ScheduleDecoder<TSchedule> original, Cloner cloner) : base(original, cloner) { }
|
---|
[8887] | 48 | public ScheduleDecoder()
|
---|
| 49 | : base() {
|
---|
[13443] | 50 | Parameters.Add(new LookupParameter<ISchedule>("EncodedSchedule", "The new scheduling solution represented as encoding."));
|
---|
[8887] | 51 | Parameters.Add(new LookupParameter<Schedule>("Schedule", "The decoded scheduling solution represented as generalized schedule."));
|
---|
[13443] | 52 | Parameters.Add(new LookupParameter<ItemList<Job>>("JobData", "Job data taken from the JSSP - Instance."));
|
---|
[8887] | 53 | }
|
---|
| 54 |
|
---|
[13469] | 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);
|
---|
[8887] | 61 |
|
---|
| 62 | public override IOperation Apply() {
|
---|
[13443] | 63 | Schedule result = DecodeSchedule(ScheduleEncodingParameter.ActualValue, JobDataParameter.ActualValue);
|
---|
[8887] | 64 | ScheduleParameter.ActualValue = result;
|
---|
| 65 | return base.Apply();
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | }
|
---|