[9105] | 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 |
|
---|
[9110] | 22 | using System;
|
---|
[9105] | 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("DoDeletionBeforeCoveringOperator", "Description missing")]
|
---|
| 32 | [StorableClass]
|
---|
| 33 | public class DoDeletionBeforeCoveringOperator : SingleSuccessorOperator {
|
---|
| 34 |
|
---|
| 35 | #region Parameter Properties
|
---|
[9110] | 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 | }
|
---|
[9105] | 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 | }
|
---|
[9194] | 57 | public ILookupParameter<IClassifierComparer> ClassifierComparerParameter {
|
---|
| 58 | get { return (ILookupParameter<IClassifierComparer>)Parameters["ClassifierComparer"]; }
|
---|
| 59 | }
|
---|
[9105] | 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() {
|
---|
[9110] | 69 | Parameters.Add(new ScopeTreeLookupParameter<IClassifier>("Classifiers"));
|
---|
| 70 | Parameters.Add(new ScopeTreeLookupParameter<BoolValue>("MatchCondition"));
|
---|
[9105] | 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"));
|
---|
[9194] | 76 | Parameters.Add(new LookupParameter<IClassifierComparer>("ClassifierComparer"));
|
---|
[9105] | 77 | }
|
---|
| 78 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 79 | return new DoDeletionBeforeCoveringOperator(this, cloner);
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | public override IOperation Apply() {
|
---|
[9194] | 83 | IItemSet<IAction> uniqueActions = new ItemSet<IAction>(ClassifierComparerParameter.ActualValue);
|
---|
[9110] | 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 |
|
---|
[9105] | 97 | int populationAfterCovering = MinimalNumberOfUniqueActionsParameter.ActualValue.Value
|
---|
[9110] | 98 | - uniqueActions.Count
|
---|
[9105] | 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 | } |
---|