Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file was 17461, checked in by abeham, 4 years ago

#2521: worked on scheduling problem

File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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 HEAL.Attic;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Operators;
27using HeuristicLab.Parameters;
28
29namespace HeuristicLab.Encodings.ScheduleEncoding {
30  [Item("ScheduleDecoder", "A schedule decoder translates a respresentation into an actual schedule.")]
31  [StorableType("57A68F4B-4B35-4DB4-9B5E-D5154DD46E45")]
32  public abstract class ScheduleDecoder<TSchedule> : SingleSuccessorOperator, IScheduleDecoder<TSchedule>
33  where TSchedule : class, IScheduleSolution {
34
35    public ILookupParameter<IScheduleSolution> ScheduleEncodingParameter {
36      get { return (ILookupParameter<IScheduleSolution>)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(StorableConstructorFlag _) : base(_) { }
47    protected ScheduleDecoder(ScheduleDecoder<TSchedule> original, Cloner cloner) : base(original, cloner) { }
48    public ScheduleDecoder()
49      : base() {
50      Parameters.Add(new LookupParameter<IScheduleSolution>("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(IScheduleSolution 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.