#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 System.Linq;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Encodings.DecisionList;
using HeuristicLab.Encodings.DecisionList.Interfaces;
using HeuristicLab.Optimization;
using HeuristicLab.Optimization.Operators.LCS;
using HeuristicLab.Optimization.Operators.LCS.DefaultRule;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
using HeuristicLab.PluginInfrastructure;
using HeuristicLab.Problems.DataAnalysis;
using HeuristicLab.Problems.Instances;
namespace HeuristicLab.Problems.DecisionListClassification {
[Item("DecisionListClassificationProblem", "")]
[StorableClass]
[Creatable("Problems")]
public class DecisionListClassificationProblem : HeuristicOptimizationProblem,
IDecisionListClassificationProblem, IGAssistProblem,
IProblemInstanceConsumer {
#region parameter properties
public FixedValueParameter MaximizationParameter {
get { return (FixedValueParameter)Parameters["Maximization"]; }
}
IParameter ISingleObjectiveHeuristicOptimizationProblem.MaximizationParameter {
get { return MaximizationParameter; }
}
public IFixedValueParameter BestKnownQualityParameter {
get { return (IFixedValueParameter)Parameters["BestKnownQuality"]; }
}
IParameter ISingleObjectiveHeuristicOptimizationProblem.BestKnownQualityParameter {
get { return BestKnownQualityParameter; }
}
public IValueParameter ProblemDataParameter {
get { return (IValueParameter)Parameters["ProblemData"]; }
}
public IFixedValueParameter SizePenaltyMinRulesParameter {
get { return (IFixedValueParameter)Parameters["SizePenaltyMinRules"]; }
}
public IFixedValueParameter InitialTheoryLengthRatioParameter {
get { return (IFixedValueParameter)Parameters["InitialTheoryLengthRatio"]; }
}
public IFixedValueParameter WeightRelaxFactorParameter {
get { return (IFixedValueParameter)Parameters["WeightRelaxFactor"]; }
}
public IFixedValueParameter ActionMutationProbabilityParameter {
get { return (IFixedValueParameter)Parameters["ActionMutationProbability"]; }
}
public IDecisionListClassificationProblemData ProblemData {
get { return ProblemDataParameter.Value; }
protected set {
ProblemDataParameter.Value = value;
}
}
IParameter IDecisionListClassificationProblem.ProblemDataParameter {
get { return ProblemDataParameter; }
}
IDecisionListClassificationProblemData IDecisionListClassificationProblem.ProblemData {
get { return ProblemData; }
}
IGAssistObjectiveEvaluator IGAssistProblem.Evaluator {
get { return Evaluator; }
}
IDecisionListEvaluator IDecisionListClassificationProblem.Evaluator {
get { return Evaluator; }
}
ISingleObjectiveEvaluator ISingleObjectiveHeuristicOptimizationProblem.Evaluator {
get { return Evaluator; }
}
#endregion
[StorableConstructor]
protected DecisionListClassificationProblem(bool deserializing) : base(deserializing) { }
protected DecisionListClassificationProblem(DecisionListClassificationProblem original, Cloner cloner)
: base(original, cloner) {
}
public override IDeepCloneable Clone(Cloner cloner) {
return new DecisionListClassificationProblem(this, cloner);
}
public DecisionListClassificationProblem()
: this(new DecisionListClassificationProblemData(new Dataset(DecisionListClassificationProblemData.defaultVariableNames, DecisionListClassificationProblemData.defaultData),
DecisionListClassificationProblemData.defaultVariableNames.Take(DecisionListClassificationProblemData.defaultVariableNames.Length - 1), DecisionListClassificationProblemData.defaultVariableNames.Last()),
new MDLEvaluator(), new SmartDecisionListCreator()) { }
public DecisionListClassificationProblem(IDecisionListClassificationProblemData problemData, IDecisionListEvaluator decisionlistEvaluator, IDecisionListCreator decisionListCreator)
: base(decisionlistEvaluator, decisionListCreator) {
Parameters.Add(new ValueParameter("ProblemData", "", problemData));
Parameters.Add(new FixedValueParameter("Maximization", "", new BoolValue(false)));
Parameters.Add(new FixedValueParameter("BestKnownQuality", "", new DoubleValue(0.5)));
Parameters.Add(new FixedValueParameter("SizePenaltyMinRules", "", new IntValue(4)));
Parameters.Add(new FixedValueParameter("ActionMutationProbability", "", new PercentValue(0.1)));
MaximizationParameter.Value.Value = Evaluator.MaximizationParameter.Value.Value;
Evaluator.MaximizationParameter.Value.ValueChanged += MaximizationParameter_ValueChanged;
Evaluator.SizePenaltyMinRulesParameter.ActualName = "SizePenaltyMinRules";
InitializeOperators();
}
private void MaximizationParameter_ValueChanged(object sender, System.EventArgs e) {
MaximizationParameter.Value.Value = Evaluator.MaximizationParameter.Value.Value;
}
private void InitializeOperators() {
foreach (var op in ApplicationManager.Manager.GetInstances())
Operators.Add(op);
foreach (var op in ApplicationManager.Manager.GetInstances())
Operators.Add(op);
foreach (var op in ApplicationManager.Manager.GetInstances())
Operators.Add(op);
ParameterizeOperators();
BestTrainingDecisionListAnalyzer analyzer = new BestTrainingDecisionListAnalyzer();
analyzer.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
analyzer.IndividualParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName;
analyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
analyzer.ResultsParameter.ActualName = "Results";
analyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
Operators.Add(analyzer);
}
private void ParameterizeOperators() {
var autoDefaultRule = Operators.OfType().First();
autoDefaultRule.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
autoDefaultRule.GAssistNichesProblemDataParameter.ActualName = ProblemDataParameter.Name;
autoDefaultRule.NicheComparerParameter.Value = new GAssistNicheComparer();
foreach (IDefaultRuleOperator op in Operators.OfType()) {
op.IndividualParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName;
op.GAssistNichesProblemDataParameter.ActualName = ProblemDataParameter.Name;
op.GAssistNichesProblemDataParameter.Hidden = true;
op.NichingParameter.ActualName = "Niching";
}
foreach (IDecisionListCrossover op in Operators.OfType()) {
op.ParentsParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName;
op.ParentsParameter.Hidden = true;
op.ChildParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName;
op.ChildParameter.Hidden = true;
}
foreach (IDecisionListManipulator op in Operators.OfType()) {
op.ChildParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName;
op.ChildParameter.Hidden = true;
op.ActionMutationProbabilityParameter.ActualName = ActionMutationProbabilityParameter.Name;
op.ActionMutationProbabilityParameter.Hidden = true;
}
}
public string NichingParameterName {
get { return "Niching"; }
}
public void Load(DecisionListClassificationProblemData data) {
Name = data.Name;
Description = data.Description;
ProblemData = data;
}
#region IDataAnalysisProblem Members
IParameter IDataAnalysisProblem.ProblemDataParameter {
get { return ProblemDataParameter; }
}
IDataAnalysisProblemData IDataAnalysisProblem.ProblemData {
get { return ProblemData; }
}
public event System.EventHandler ProblemDataChanged;
#endregion
}
}