#region License Information /* HeuristicLab * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Operators; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Encodings.ConditionActionEncoding { [Item("ConditionActionSolutionAnalyzer", "")] [StorableClass] public abstract class XCSSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer { public bool EnabledByDefault { get { return true; } } public ScopeTreeLookupParameter ClassifierParameter { get { return (ScopeTreeLookupParameter)Parameters["Classifier"]; } } public ScopeTreeLookupParameter PredictionParameter { get { return (ScopeTreeLookupParameter)Parameters["Prediction"]; } } public ScopeTreeLookupParameter ErrorParameter { get { return (ScopeTreeLookupParameter)Parameters["Error"]; } } public ScopeTreeLookupParameter FitnessParameter { get { return (ScopeTreeLookupParameter)Parameters["Fitness"]; } } public ScopeTreeLookupParameter ExperienceParameter { get { return (ScopeTreeLookupParameter)Parameters["Experience"]; } } public ScopeTreeLookupParameter TimestampParameter { get { return (ScopeTreeLookupParameter)Parameters["Timestamp"]; } } public ScopeTreeLookupParameter AverageActionSetSizeParameter { get { return (ScopeTreeLookupParameter)Parameters["AverageActionSetSize"]; } } public ScopeTreeLookupParameter NumerosityParameter { get { return (ScopeTreeLookupParameter)Parameters["Numerosity"]; } } public LookupParameter ProblemDataParameter { get { return (LookupParameter)Parameters["ProblemData"]; } } public ValueLookupParameter ResultsParameter { get { return (ValueLookupParameter)Parameters["Results"]; } } public ILookupParameter ClassifierComparerParameter { get { return (ILookupParameter)Parameters["ClassifierComparer"]; } } public ResultCollection Results { get { return ResultsParameter.ActualValue; } } [StorableConstructor] protected XCSSolutionAnalyzer(bool deserializing) : base(deserializing) { } protected XCSSolutionAnalyzer(XCSSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { } public XCSSolutionAnalyzer() : base() { Parameters.Add(new ScopeTreeLookupParameter("Classifier", "")); Parameters.Add(new ScopeTreeLookupParameter("Prediction", "")); Parameters.Add(new ScopeTreeLookupParameter("Error", "")); Parameters.Add(new ScopeTreeLookupParameter("Fitness", "")); Parameters.Add(new ScopeTreeLookupParameter("Experience", "")); Parameters.Add(new ScopeTreeLookupParameter("Timestamp", "")); Parameters.Add(new ScopeTreeLookupParameter("AverageActionSetSize", "")); Parameters.Add(new ScopeTreeLookupParameter("Numerosity", "")); Parameters.Add(new LookupParameter("ProblemData", "")); Parameters.Add(new ValueLookupParameter("Results", "The result collection where the solution should be stored.")); Parameters.Add(new LookupParameter("ClassifierComparer")); } public override IOperation Apply() { ItemArray classifiers = ClassifierParameter.ActualValue; ItemArray predictions = PredictionParameter.ActualValue; ItemArray errors = ErrorParameter.ActualValue; ItemArray fitnesses = FitnessParameter.ActualValue; ItemArray experiences = ExperienceParameter.ActualValue; ItemArray timestamps = TimestampParameter.ActualValue; ItemArray averageActionSetSizes = AverageActionSetSizeParameter.ActualValue; ItemArray numerosities = NumerosityParameter.ActualValue; IConditionActionProblemData problemData = ProblemDataParameter.ActualValue; ItemCollection xcsClassifiers = new ItemCollection(); for (int i = 0; i < classifiers.Length; i++) { xcsClassifiers.Add(new XCSClassifier(classifiers[i], predictions[i], errors[i], fitnesses[i], experiences[i], timestamps[i], averageActionSetSizes[i], numerosities[i])); } XCSModel xcsModel = new XCSModel(xcsClassifiers); xcsModel.ClassifierComparer = ClassifierComparerParameter.ActualValue; UseCurrentXCSSolution(xcsModel.CreateConditionActionSolution(problemData)); return base.Apply(); } protected abstract void UseCurrentXCSSolution(IXCSSolution xcsSolution); } }