Free cookie consent management tool by TermsFeed Policy Generator

source: branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Subsumption/ExecuteGASubsumptionOperator.cs @ 11813

Last change on this file since 11813 was 9110, checked in by sforsten, 12 years ago

#1980:

  • added GA subsumption
  • simplified deletion before covering
  • simplified XCSDeletionOperator
File size: 3.3 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 System.Collections.Generic;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Operators;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Encodings.ConditionActionEncoding {
32  [Item("ExecuteGASubsumptionOperator", "Description missing")]
33  [StorableClass]
34  public class ExecuteGASubsumptionOperator : SingleSuccessorOperator {
35
36    #region Parameter Properties
37    public ILookupParameter<ItemArray<IntValue>> TempIDParameter {
38      get { return (ILookupParameter<ItemArray<IntValue>>)Parameters["TempID"]; }
39    }
40    public ILookupParameter<ItemArray<IntValue>> NumerositiesParameter {
41      get { return (ILookupParameter<ItemArray<IntValue>>)Parameters["Numerosities"]; }
42    }
43    public ILookupParameter<ItemArray<IntValue>> SubsumedByParameter {
44      get { return (ILookupParameter<ItemArray<IntValue>>)Parameters["SubsumedBy"]; }
45    }
46    #endregion
47
48    [StorableConstructor]
49    protected ExecuteGASubsumptionOperator(bool deserializing) : base(deserializing) { }
50    protected ExecuteGASubsumptionOperator(ExecuteGASubsumptionOperator original, Cloner cloner)
51      : base(original, cloner) {
52    }
53    public ExecuteGASubsumptionOperator()
54      : base() {
55      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("TempID"));
56      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Numerosities"));
57      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("SubsumedBy"));
58    }
59    public override IDeepCloneable Clone(Cloner cloner) {
60      return new ExecuteGASubsumptionOperator(this, cloner);
61    }
62
63    public override IOperation Apply() {
64      var tempId = TempIDParameter.ActualValue;
65      var numerosities = NumerositiesParameter.ActualValue;
66      var subsumedBy = SubsumedByParameter.ActualValue;
67
68      if (tempId.Length != numerosities.Length || tempId.Length != subsumedBy.Length) {
69        throw new ArgumentException("The number of tempId, numerosity and subsumedBy values is not equal.");
70      }
71
72      IList<int> ids = new List<int>();
73      for (int i = 0; i < tempId.Length; i++) {
74        if (subsumedBy[i].Value >= 0) {
75          ids.Add(subsumedBy[i].Value);
76          numerosities[i].Value = 0;
77        }
78      }
79
80      foreach (var id in ids) {
81        var subsumedId = tempId.FindIndex(x => x.Value == id);
82        numerosities[subsumedId].Value++;
83      }
84
85      return base.Apply();
86    }
87  }
88}
Note: See TracBrowser for help on using the repository browser.