[9110] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Data;
|
---|
| 26 | using HeuristicLab.Operators;
|
---|
| 27 | using HeuristicLab.Parameters;
|
---|
| 28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Encodings.ConditionActionEncoding {
|
---|
| 31 | [Item("CheckGASubsumptionOperator", "Description missing")]
|
---|
| 32 | [StorableClass]
|
---|
| 33 | public class CheckGASubsumptionOperator : SingleSuccessorOperator {
|
---|
| 34 |
|
---|
| 35 | #region Parameter Properties
|
---|
| 36 | public ILookupParameter<IClassifier> ChildClassifiersParameter {
|
---|
| 37 | get { return (ILookupParameter<IClassifier>)Parameters["ChildClassifiers"]; }
|
---|
| 38 | }
|
---|
| 39 | public ILookupParameter<ItemArray<IClassifier>> ParentsClassifiersParameter {
|
---|
| 40 | get { return (ILookupParameter<ItemArray<IClassifier>>)Parameters["Classifiers"]; }
|
---|
| 41 | }
|
---|
| 42 | public ILookupParameter<ItemArray<IntValue>> NumerositiesParameter {
|
---|
| 43 | get { return (ILookupParameter<ItemArray<IntValue>>)Parameters["Numerosities"]; }
|
---|
| 44 | }
|
---|
| 45 | public ILookupParameter<ItemArray<IntValue>> ExperiencesParameter {
|
---|
| 46 | get { return (ILookupParameter<ItemArray<IntValue>>)Parameters["Experiences"]; }
|
---|
| 47 | }
|
---|
| 48 | public ILookupParameter<ItemArray<DoubleValue>> ErrorsParameter {
|
---|
| 49 | get { return (ILookupParameter<ItemArray<DoubleValue>>)Parameters["Errors"]; }
|
---|
| 50 | }
|
---|
| 51 | public ILookupParameter<ItemArray<IntValue>> TempIDParameter {
|
---|
| 52 | get { return (ILookupParameter<ItemArray<IntValue>>)Parameters["TempID"]; }
|
---|
| 53 | }
|
---|
| 54 | public ILookupParameter<DoubleValue> ErrorZeroParameter {
|
---|
| 55 | get { return (ILookupParameter<DoubleValue>)Parameters["ErrorZero"]; }
|
---|
| 56 | }
|
---|
| 57 | public ILookupParameter<IntValue> ThetaSubsumptionParameter {
|
---|
| 58 | get { return (ILookupParameter<IntValue>)Parameters["ThetaSubsumption"]; }
|
---|
| 59 | }
|
---|
| 60 | public IValueLookupParameter<IntValue> SubsumedByParameter {
|
---|
| 61 | get { return (IValueLookupParameter<IntValue>)Parameters["SubsumedBy"]; }
|
---|
| 62 | }
|
---|
| 63 | public IValueLookupParameter<BoolValue> SubsumedParameter {
|
---|
| 64 | get { return (IValueLookupParameter<BoolValue>)Parameters["Subsumed"]; }
|
---|
| 65 | }
|
---|
| 66 | #endregion
|
---|
| 67 |
|
---|
| 68 | [StorableConstructor]
|
---|
| 69 | protected CheckGASubsumptionOperator(bool deserializing) : base(deserializing) { }
|
---|
| 70 | protected CheckGASubsumptionOperator(CheckGASubsumptionOperator original, Cloner cloner)
|
---|
| 71 | : base(original, cloner) {
|
---|
| 72 | }
|
---|
| 73 | public CheckGASubsumptionOperator()
|
---|
| 74 | : base() {
|
---|
| 75 | Parameters.Add(new LookupParameter<IClassifier>("ChildClassifiers"));
|
---|
| 76 | Parameters.Add(new ScopeTreeLookupParameter<IClassifier>("Classifiers"));
|
---|
| 77 | Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Numerosities"));
|
---|
| 78 | Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Experiences"));
|
---|
| 79 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Errors"));
|
---|
| 80 | Parameters.Add(new ScopeTreeLookupParameter<IntValue>("TempID"));
|
---|
| 81 | Parameters.Add(new LookupParameter<DoubleValue>("ErrorZero"));
|
---|
| 82 | Parameters.Add(new LookupParameter<IntValue>("ThetaSubsumption"));
|
---|
| 83 | Parameters.Add(new ValueLookupParameter<IntValue>("SubsumedBy"));
|
---|
| 84 | Parameters.Add(new ValueLookupParameter<BoolValue>("Subsumed"));
|
---|
| 85 | }
|
---|
| 86 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 87 | return new CheckGASubsumptionOperator(this, cloner);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | public override IOperation Apply() {
|
---|
| 91 | var child = ChildClassifiersParameter.ActualValue;
|
---|
| 92 | var parents = ParentsClassifiersParameter.ActualValue;
|
---|
| 93 | var numerosities = NumerositiesParameter.ActualValue;
|
---|
| 94 | var experiences = ExperiencesParameter.ActualValue;
|
---|
| 95 | var tempIDs = TempIDParameter.ActualValue;
|
---|
| 96 | var errors = ErrorsParameter.ActualValue;
|
---|
| 97 | if (errors.Length != parents.Length || errors.Length != numerosities.Length
|
---|
| 98 | || errors.Length != experiences.Length || errors.Length != tempIDs.Length) {
|
---|
| 99 | throw new ArgumentException("The number of classifiers, error, numerosity, tempIDs and experience values is not equal.");
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | SubsumedByParameter.ActualValue = new IntValue(-1);
|
---|
| 103 | SubsumedParameter.ActualValue = new BoolValue(false);
|
---|
| 104 |
|
---|
| 105 | for (int i = 0; i < parents.Length; i++) {
|
---|
| 106 | IClassifier curParent = parents[i];
|
---|
[9194] | 107 | if (curParent.MatchAction(child.Action)) {
|
---|
[9110] | 108 | if (CouldSubsume(experiences[i], errors[i])) {
|
---|
| 109 | if (curParent.IsMoreGeneral(child)) {
|
---|
| 110 | SubsumedByParameter.ActualValue.Value = i;
|
---|
| 111 | SubsumedParameter.ActualValue.Value = true;
|
---|
| 112 | break;
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | return base.Apply();
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | private bool CouldSubsume(IntValue exp, DoubleValue error) {
|
---|
| 122 | return exp.Value > ThetaSubsumptionParameter.ActualValue.Value && error.Value < ErrorZeroParameter.ActualValue.Value;
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 | }
|
---|