Free cookie consent management tool by TermsFeed Policy Generator

source: branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Covering/DoDeletionBeforeCovering.cs @ 11299

Last change on this file since 11299 was 9194, checked in by sforsten, 12 years ago

#1980:

  • added necessary interface ICondition, IAction, IInput
  • removed not used class MatchSelector and interface IMatchSelector
  • added constructors to ItemDictionary
  • added new encoding
File size: 5.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Encodings.ConditionActionEncoding {
31  [Item("DoDeletionBeforeCoveringOperator", "Description missing")]
32  [StorableClass]
33  public class DoDeletionBeforeCoveringOperator : SingleSuccessorOperator {
34
35    #region Parameter Properties
36    public ILookupParameter<ItemArray<IClassifier>> ClassifiersParameter {
37      get { return (ILookupParameter<ItemArray<IClassifier>>)Parameters["Classifiers"]; }
38    }
39    public ILookupParameter<ItemArray<BoolValue>> MatchConditionParameter {
40      get { return (ILookupParameter<ItemArray<BoolValue>>)Parameters["MatchCondition"]; }
41    }
42    public ILookupParameter<IntValue> MinimalNumberOfUniqueActionsParameter {
43      get { return (ILookupParameter<IntValue>)Parameters["MinimalNumberOfUniqueActions"]; }
44    }
45    public ILookupParameter<IntValue> CurrentPopulationSizeParameter {
46      get { return (ILookupParameter<IntValue>)Parameters["CurrentPopulationSize"]; }
47    }
48    public ILookupParameter<IntValue> PopulationSizeParameter {
49      get { return (ILookupParameter<IntValue>)Parameters["PopulationSize"]; }
50    }
51    public IValueLookupParameter<BoolValue> DoDeletionParameter {
52      get { return (IValueLookupParameter<BoolValue>)Parameters["DoDeletion"]; }
53    }
54    public IValueLookupParameter<IntValue> NumberToDeleteParameter {
55      get { return (IValueLookupParameter<IntValue>)Parameters["NumberToDelete"]; }
56    }
57    public ILookupParameter<IClassifierComparer> ClassifierComparerParameter {
58      get { return (ILookupParameter<IClassifierComparer>)Parameters["ClassifierComparer"]; }
59    }
60    #endregion
61
62    [StorableConstructor]
63    protected DoDeletionBeforeCoveringOperator(bool deserializing) : base(deserializing) { }
64    protected DoDeletionBeforeCoveringOperator(DoDeletionBeforeCoveringOperator original, Cloner cloner)
65      : base(original, cloner) {
66    }
67    public DoDeletionBeforeCoveringOperator()
68      : base() {
69      Parameters.Add(new ScopeTreeLookupParameter<IClassifier>("Classifiers"));
70      Parameters.Add(new ScopeTreeLookupParameter<BoolValue>("MatchCondition"));
71      Parameters.Add(new LookupParameter<IntValue>("MinimalNumberOfUniqueActions"));
72      Parameters.Add(new LookupParameter<IntValue>("CurrentPopulationSize"));
73      Parameters.Add(new LookupParameter<IntValue>("PopulationSize"));
74      Parameters.Add(new ValueLookupParameter<BoolValue>("DoDeletion"));
75      Parameters.Add(new ValueLookupParameter<IntValue>("NumberToDelete"));
76      Parameters.Add(new LookupParameter<IClassifierComparer>("ClassifierComparer"));
77    }
78    public override IDeepCloneable Clone(Cloner cloner) {
79      return new DoDeletionBeforeCoveringOperator(this, cloner);
80    }
81
82    public override IOperation Apply() {
83      IItemSet<IAction> uniqueActions = new ItemSet<IAction>(ClassifierComparerParameter.ActualValue);
84      var classifiers = ClassifiersParameter.ActualValue;
85      var matchcondition = MatchConditionParameter.ActualValue;
86
87      if (classifiers.Length != matchcondition.Length) {
88        throw new ArgumentException("Number of classifiers is not equal to the number of 'MatchCondition' variables.");
89      }
90
91      for (int i = 0; i < classifiers.Length; i++) {
92        if (matchcondition[i].Value) {
93          uniqueActions.Add(classifiers[i].Action);
94        }
95      }
96
97      int populationAfterCovering = MinimalNumberOfUniqueActionsParameter.ActualValue.Value
98                                    - uniqueActions.Count
99                                    + CurrentPopulationSizeParameter.ActualValue.Value;
100      BoolValue doDeletion = new BoolValue(populationAfterCovering > PopulationSizeParameter.ActualValue.Value);
101      if (doDeletion.Value) {
102        NumberToDeleteParameter.ActualValue = new IntValue(populationAfterCovering - PopulationSizeParameter.ActualValue.Value);
103      } else {
104        NumberToDeleteParameter.ActualValue = new IntValue(0);
105      }
106      DoDeletionParameter.ActualValue = doDeletion;
107      return base.Apply();
108    }
109  }
110}
Note: See TracBrowser for help on using the repository browser.