Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/PriorityRulesVector/PriorityRulesVectorEncoding.cs @ 17461

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

#2521: worked on scheduling problem

File size: 4.1 KB
Line 
1#region License Information
2
3/* HeuristicLab
4 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
5 *
6 * This file is part of HeuristicLab.
7 *
8 * HeuristicLab is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * HeuristicLab is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#endregion
23
24using System;
25using System.Collections.Generic;
26using System.Linq;
27using HEAL.Attic;
28using HeuristicLab.Common;
29using HeuristicLab.Core;
30using HeuristicLab.Data;
31using HeuristicLab.Parameters;
32using HeuristicLab.PluginInfrastructure;
33
34namespace HeuristicLab.Encodings.ScheduleEncoding {
35  [StorableType("9C419EE5-F3A8-4F06-8263-7D37D3AE1C72")]
36  public sealed class PriorityRulesVectorEncoding : ScheduleEncoding<PRV> {
37
38    private IFixedValueParameter<IntValue> numberOfRulesParameter;
39    public IFixedValueParameter<IntValue> NumberOfRulesParameter {
40      get { return numberOfRulesParameter; }
41      set {
42        if (value == null) throw new ArgumentNullException("Number of Rules parameter must not be null.");
43        if (value.Value == null) throw new ArgumentNullException("Number of Rules parameter value must not be null.");
44        if (numberOfRulesParameter == value) return;
45
46        if (numberOfRulesParameter != null) Parameters.Remove(numberOfRulesParameter);
47        numberOfRulesParameter = value;
48        Parameters.Add(numberOfRulesParameter);
49        OnNumberOfRulesParameterChanged();
50      }
51    }
52
53
54    [StorableConstructor]
55    private PriorityRulesVectorEncoding(StorableConstructorFlag _) : base(_) { }
56    private PriorityRulesVectorEncoding(PriorityRulesVectorEncoding original, Cloner cloner) : base(original, cloner) { }
57    public override IDeepCloneable Clone(Cloner cloner) {
58      return new PriorityRulesVectorEncoding(this, cloner);
59    }
60
61    public PriorityRulesVectorEncoding()
62      : base("PRV") {
63      //TODO change to meaningful value
64      numberOfRulesParameter = new FixedValueParameter<IntValue>(Name + ".NumberOfRules", new IntValue(10));
65      Parameters.Add(numberOfRulesParameter);
66
67      SolutionCreator = new PRVRandomCreator();
68      Decoder = new PRVDecoder();
69      DiscoverOperators();
70    }
71
72    private void OnNumberOfRulesParameterChanged() {
73      ConfigureOperators(Operators);
74    }
75
76    #region Operator Discovery
77    private static readonly IEnumerable<Type> encodingSpecificOperatorTypes;
78    static PriorityRulesVectorEncoding() {
79      encodingSpecificOperatorTypes = new List<Type>() {
80          typeof (IPRVOperator)
81      };
82    }
83    private void DiscoverOperators() {
84      var assembly = typeof(IDirectScheduleOperator).Assembly;
85      var discoveredTypes = ApplicationManager.Manager.GetTypes(encodingSpecificOperatorTypes, assembly, true, false, false);
86      var operators = discoveredTypes.Select(t => (IOperator)Activator.CreateInstance(t));
87      var newOperators = operators.Except(Operators, new TypeEqualityComparer<IOperator>()).ToList();
88
89      ConfigureOperators(newOperators);
90      foreach (var @operator in newOperators)
91        AddOperator(@operator);
92    }
93
94    public override void ConfigureOperators(IEnumerable<IItem> operators) {
95      base.ConfigureOperators(operators);
96      ConfigureRulesParameter(operators.OfType<IPRVRulesOperator>());
97    }
98
99    private void ConfigureRulesParameter(IEnumerable<IPRVRulesOperator> rulesOperators) {
100      foreach (var rulesOperator in rulesOperators)
101        rulesOperator.NumberOfRulesParameter.ActualName = numberOfRulesParameter.Name;
102    }
103
104    #endregion
105  }
106}
Note: See TracBrowser for help on using the repository browser.