#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; using System.Linq; using HeuristicLab.Analysis; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Operators; using HeuristicLab.Optimization; using HeuristicLab.Optimization.Operators; using HeuristicLab.Optimization.Operators.LCS; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.PluginInfrastructure; using HeuristicLab.Random; namespace HeuristicLab.Algorithms.GAssist { /// /// A genetic algorithm. /// [Item("GAssist", "A learning classifier system.")] [Creatable("Algorithms")] [StorableClass] public sealed class GAssist : HeuristicOptimizationEngineAlgorithm, IStorableContent { public string Filename { get; set; } #region Problem Properties public override Type ProblemType { get { return typeof(IGAssistProblem); } } public new IGAssistProblem Problem { get { return (IGAssistProblem)base.Problem; } set { base.Problem = value; } } #endregion #region Parameter Properties private ValueParameter SeedParameter { get { return (ValueParameter)Parameters["Seed"]; } } private ValueParameter SetSeedRandomlyParameter { get { return (ValueParameter)Parameters["SetSeedRandomly"]; } } private ValueParameter PopulationSizeParameter { get { return (ValueParameter)Parameters["PopulationSize"]; } } public ValueParameter MDLIterationOperatorParameter { get { return (ValueParameter)Parameters["MDLIterationOperator"]; } } public IConstrainedValueParameter DefaultRuleParameter { get { return (IConstrainedValueParameter)Parameters["DefaultRule"]; } } public IConstrainedValueParameter SelectorParameter { get { return (IConstrainedValueParameter)Parameters["Selector"]; } } private ValueParameter CrossoverProbabilityParameter { get { return (ValueParameter)Parameters["CrossoverProbability"]; } } public IConstrainedValueParameter CrossoverParameter { get { return (IConstrainedValueParameter)Parameters["Crossover"]; } } private ValueParameter MutationProbabilityParameter { get { return (ValueParameter)Parameters["MutationProbability"]; } } public IConstrainedValueParameter MutatorParameter { get { return (IConstrainedValueParameter)Parameters["Mutator"]; } } private ValueParameter ElitesParameter { get { return (ValueParameter)Parameters["Elites"]; } } private ValueParameter AnalyzerParameter { get { return (ValueParameter)Parameters["Analyzer"]; } } private ValueParameter SpecialStagesParameter { get { return (ValueParameter)Parameters["SpecialStages"]; } } private ValueParameter MaximumGenerationsParameter { get { return (ValueParameter)Parameters["MaximumGenerations"]; } } private ValueParameter StartReinitializeProbabilityParameter { get { return (ValueParameter)Parameters["StartReinitializeProbability"]; } } private ValueParameter EndReinitializeProbabilityParameter { get { return (ValueParameter)Parameters["EndReinitializeProbability"]; } } public IConstrainedValueParameter ReinitializeCurveOperatorParameter { get { return (IConstrainedValueParameter)Parameters["ReinitializeCurveOperator"]; } } private ValueParameter SplitProbabilityParameter { get { return (ValueParameter)Parameters["SplitProbability"]; } } private ValueParameter MergeProbabilityParameter { get { return (ValueParameter)Parameters["MergeProbability"]; } } private ValueParameter OneProbabilityParameter { get { return (ValueParameter)Parameters["OneProbability"]; } } private ValueParameter MaximumNumberOfIntervalsParameter { get { return (ValueParameter)Parameters["MaximumNumberOfIntervals"]; } } private ValueParameter InitialNumberOfRulesParameter { get { return (ValueParameter)Parameters["InitialNumberOfRules"]; } } private ValueParameter> DiscretizersParameter { get { return (ValueParameter>)Parameters["Discretizers"]; } } public ValueParameter MDLActivationIterationParameter { get { return (ValueParameter)Parameters["MDLActivationIteration"]; } } public ValueParameter InitialTheoryLengthRatioParameter { get { return (ValueParameter)Parameters["InitialTheoryLengthRatio"]; } } public ValueParameter WeightRelaxFactorParameter { get { return (ValueParameter)Parameters["WeightRelaxFactor"]; } } public ValueParameter WeightAdaptionIterationsParameter { get { return (ValueParameter)Parameters["WeightAdaptionIterations"]; } } public ValueParameter NumberOfStrataParameter { get { return (ValueParameter)Parameters["NumberOfStrata"]; } } #endregion #region Properties public IntValue Seed { get { return SeedParameter.Value; } set { SeedParameter.Value = value; } } public BoolValue SetSeedRandomly { get { return SetSeedRandomlyParameter.Value; } set { SetSeedRandomlyParameter.Value = value; } } public IntValue PopulationSize { get { return PopulationSizeParameter.Value; } set { PopulationSizeParameter.Value = value; } } public INichingSingleObjectiveSelector Selector { get { return SelectorParameter.Value; } set { SelectorParameter.Value = value; } } public PercentValue CrossoverProbability { get { return CrossoverProbabilityParameter.Value; } set { CrossoverProbabilityParameter.Value = value; } } public ICrossover Crossover { get { return CrossoverParameter.Value; } set { CrossoverParameter.Value = value; } } public PercentValue MutationProbability { get { return MutationProbabilityParameter.Value; } set { MutationProbabilityParameter.Value = value; } } public IManipulator Mutator { get { return MutatorParameter.Value; } set { MutatorParameter.Value = value; } } public IntValue Elites { get { return ElitesParameter.Value; } set { ElitesParameter.Value = value; } } public MultiAnalyzer Analyzer { get { return AnalyzerParameter.Value; } set { AnalyzerParameter.Value = value; } } public GAssistSpecialStageMultiOperator SpecialStages { get { return SpecialStagesParameter.Value; } set { SpecialStagesParameter.Value = value; } } public IDiscreteDoubleValueModifier ReinitializeCurveOperator { get { return ReinitializeCurveOperatorParameter.Value; } set { ReinitializeCurveOperatorParameter.Value = value; } } public IntValue MaximumGenerations { get { return MaximumGenerationsParameter.Value; } set { MaximumGenerationsParameter.Value = value; } } private RandomCreator RandomCreator { get { return (RandomCreator)OperatorGraph.InitialOperator; } } private VariableCreator VariableCreator { get { return (VariableCreator)RandomCreator.Successor; } } private Placeholder InitialDefaultRuleExecution { get { return (Placeholder)VariableCreator.Successor; } } private Placeholder MDLIterationPlaceholder { get { return (Placeholder)InitialDefaultRuleExecution.Successor; } } private ILASOperator ILASOperator { get { return (ILASOperator)MDLIterationPlaceholder.Successor; } } private InitializeDiscretizersOperator InitializeDiscretizers { get { return (InitializeDiscretizersOperator)ILASOperator.Successor; } } private NicheSolutionCreator SolutionsCreator { get { return (NicheSolutionCreator)InitializeDiscretizers.Successor; } } private GAssistMainLoop GeneticAlgorithmMainLoop { get { return FindMainLoop(SolutionsCreator.Successor); } } [Storable] private BestAverageWorstQualityAnalyzer qualityAnalyzer; #endregion public GAssist() : base() { Parameters.Add(new ValueParameter("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0))); Parameters.Add(new ValueParameter("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true))); Parameters.Add(new ValueParameter("PopulationSize", "The size of the population of solutions.", new IntValue(100))); Parameters.Add(new ConstrainedValueParameter("Selector", "The operator used to select solutions for reproduction.")); Parameters.Add(new ValueParameter("CrossoverProbability", "The probability that the Crossover operator is applied on a solution.", new PercentValue(0.9))); Parameters.Add(new ConstrainedValueParameter("Crossover", "The operator used to cross solutions.")); Parameters.Add(new ValueParameter("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05))); Parameters.Add(new OptionalConstrainedValueParameter("Mutator", "The operator used to mutate solutions.")); Parameters.Add(new ValueParameter("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1))); Parameters.Add(new ValueParameter("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer())); Parameters.Add(new ValueParameter("SpecialStages", "", new GAssistSpecialStageMultiOperator())); Parameters.Add(new ValueParameter("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000))); Parameters.Add(new ValueParameter("SplitProbability", "", new PercentValue(0.05))); Parameters.Add(new ValueParameter("MergeProbability", "", new PercentValue(0.05))); Parameters.Add(new ValueParameter("StartReinitializeProbability", "", new PercentValue(0.05))); Parameters.Add(new ValueParameter("EndReinitializeProbability", "", new PercentValue(Double.Epsilon))); Parameters.Add(new ValueParameter("OneProbability", "", new PercentValue(0.75))); Parameters.Add(new ValueParameter("MaximumNumberOfIntervals", "", new IntValue(5))); Parameters.Add(new ValueParameter("InitialNumberOfRules", "", new IntValue(20))); Parameters.Add(new ValueParameter("MDLIterationOperator", "", new MDLIterationOperator())); Parameters.Add(new ConstrainedValueParameter("DefaultRule", "")); Parameters.Add(new ConstrainedValueParameter("ReinitializeCurveOperator", "")); Parameters.Add(new ValueParameter>("Discretizers", "", new ItemCollection())); Parameters.Add(new ValueParameter("MDLActivationIteration", "", new IntValue(25))); Parameters.Add(new ValueParameter("InitialTheoryLengthRatio", "", new DoubleValue(0.075))); Parameters.Add(new ValueParameter("WeightRelaxFactor", "", new DoubleValue(0.9))); Parameters.Add(new ValueParameter("WeightAdaptionIterations", "", new IntValue(10))); Parameters.Add(new ValueParameter("NumberOfStrata", "", new IntValue(2))); RandomCreator randomCreator = new RandomCreator(); VariableCreator variableCreator = new VariableCreator(); Placeholder initialDefaultRuleExecution = new Placeholder(); Placeholder mdlIterationPlaceholder = new Placeholder(); ILASOperator ilasOperator = new ILASOperator(); InitializeDiscretizersOperator initializeDiscretizers = new InitializeDiscretizersOperator(); NicheSolutionCreator solutionsCreator = new NicheSolutionCreator(); SubScopesCounter subScopesCounter = new SubScopesCounter(); ResultsCollector resultsCollector = new ResultsCollector(); GAssistMainLoop mainLoop = new GAssistMainLoop(); OperatorGraph.InitialOperator = randomCreator; randomCreator.RandomParameter.ActualName = "Random"; randomCreator.SeedParameter.ActualName = SeedParameter.Name; randomCreator.SeedParameter.Value = null; randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name; randomCreator.SetSeedRandomlyParameter.Value = null; randomCreator.Successor = variableCreator; variableCreator.CollectedValues.Add(new ValueParameter("Generations", new IntValue(0))); // Class GAssistMainLoop expects this to be called Generations variableCreator.Successor = initialDefaultRuleExecution; initialDefaultRuleExecution.Name = "Initial Default Rule Execution"; initialDefaultRuleExecution.OperatorParameter.ActualName = DefaultRuleParameter.Name; initialDefaultRuleExecution.Successor = mdlIterationPlaceholder; mdlIterationPlaceholder.Name = "MDL Iteration Operator"; mdlIterationPlaceholder.OperatorParameter.ActualName = MDLIterationOperatorParameter.Name; mdlIterationPlaceholder.Successor = ilasOperator; ilasOperator.RandomParameter.ActualName = randomCreator.RandomParameter.ActualName; ilasOperator.NumberOfStrataParameter.ActualName = NumberOfStrataParameter.Name; ilasOperator.Successor = initializeDiscretizers; initializeDiscretizers.DiscretizersParameter.ActualName = DiscretizersParameter.Name; initializeDiscretizers.Successor = solutionsCreator; solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name; solutionsCreator.Successor = subScopesCounter; subScopesCounter.Name = "Initialize EvaluatedSolutions"; subScopesCounter.ValueParameter.ActualName = "EvaluatedSolutions"; subScopesCounter.Successor = resultsCollector; resultsCollector.CollectedValues.Add(new LookupParameter("Evaluated Solutions", null, "EvaluatedSolutions")); resultsCollector.ResultsParameter.ActualName = "Results"; resultsCollector.Successor = mainLoop; mainLoop.MDLIterationParameter.ActualName = MDLIterationOperatorParameter.Name; mainLoop.DefaultRuleParameter.ActualName = DefaultRuleParameter.Name; mainLoop.SelectorParameter.ActualName = SelectorParameter.Name; mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name; mainLoop.CrossoverProbabilityParameter.ActualName = CrossoverProbabilityParameter.Name; mainLoop.ElitesParameter.ActualName = ElitesParameter.Name; mainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name; mainLoop.MutatorParameter.ActualName = MutatorParameter.Name; mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name; mainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName; mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name; mainLoop.SpecialStagesParameter.ActualName = SpecialStagesParameter.Name; mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions"; mainLoop.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name; mainLoop.ResultsParameter.ActualName = "Results"; mainLoop.ReinitializationProbabilityOperatorParameter.ActualName = ReinitializeCurveOperatorParameter.Name; foreach (INichingSingleObjectiveSelector selector in ApplicationManager.Manager.GetInstances().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name)) SelectorParameter.ValidValues.Add(selector); ParameterizeSelectors(); qualityAnalyzer = new BestAverageWorstQualityAnalyzer(); ParameterizeAnalyzers(); UpdateAnalyzers(); foreach (IDiscreteDoubleValueModifier op in ApplicationManager.Manager.GetInstances().OrderBy(x => x.Name)) { ReinitializeCurveOperatorParameter.ValidValues.Add(op); } ReinitializeCurveOperatorParameter.Value = ReinitializeCurveOperatorParameter.ValidValues.First(x => x.GetType().Equals(typeof(LinearDiscreteDoubleValueModifier))); ParameterizeReinitializeCurveOperators(); InitializeSpecialStages(); UpdateDiscretizers(); Initialize(); } private void UpdateDiscretizers() { // change to add more //DiscretizersParameter.Value.AddRange(ApplicationManager.Manager.GetInstances()); DiscretizersParameter.Value.Add(new UniformWidthDiscretizer(4)); DiscretizersParameter.Value.Add(new UniformWidthDiscretizer(5)); DiscretizersParameter.Value.Add(new UniformWidthDiscretizer(6)); DiscretizersParameter.Value.Add(new UniformWidthDiscretizer(7)); DiscretizersParameter.Value.Add(new UniformWidthDiscretizer(8)); DiscretizersParameter.Value.Add(new UniformWidthDiscretizer(10)); DiscretizersParameter.Value.Add(new UniformWidthDiscretizer(15)); DiscretizersParameter.Value.Add(new UniformWidthDiscretizer(20)); DiscretizersParameter.Value.Add(new UniformWidthDiscretizer(25)); } private void ParameterizeReinitializeCurveOperators() { foreach (IDiscreteDoubleValueModifier op in ReinitializeCurveOperatorParameter.ValidValues) { op.IndexParameter.ActualName = "Generations"; op.IndexParameter.Hidden = true; op.StartIndexParameter.Value = new IntValue(0); op.EndIndexParameter.ActualName = MaximumGenerationsParameter.Name; op.ValueParameter.ActualName = "ReinitializeProbability"; op.ValueParameter.Hidden = true; op.StartValueParameter.ActualName = StartReinitializeProbabilityParameter.Name; op.StartValueParameter.Hidden = true; op.EndValueParameter.ActualName = EndReinitializeProbabilityParameter.Name; op.EndValueParameter.Hidden = true; ParameterizeStochasticOperator(op); } } private void InitializeSpecialStages() { SpecialStages.Operators.Clear(); var splitOperator = new SplitOperator(); splitOperator.ProbabilityParameter.ActualName = SplitProbabilityParameter.Name; //change splitOperator.IndividualParameter.ActualName = "DecisionList"; SpecialStages.Operators.Add(splitOperator); var mergeOperator = new MergeOperator(); mergeOperator.ProbabilityParameter.ActualName = MergeProbabilityParameter.Name; //change mergeOperator.IndividualParameter.ActualName = "DecisionList"; SpecialStages.Operators.Add(mergeOperator); var reinitializeOperator = new ReinitializeOperator(); reinitializeOperator.ProbabilityParameter.ActualName = "ReinitializeProbability"; reinitializeOperator.DiscretizersParameter.ActualName = "Discretizers"; reinitializeOperator.OneProbabilityParameter.ActualName = OneProbabilityParameter.Name; //change reinitializeOperator.IndividualParameter.ActualName = "DecisionList"; SpecialStages.Operators.Add(reinitializeOperator); foreach (var op in SpecialStages.Operators) { op.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName; } } [StorableConstructor] private GAssist(bool deserializing) : base(deserializing) { } [StorableHook(HookType.AfterDeserialization)] private void AfterDeserialization() { Initialize(); } private GAssist(GAssist original, Cloner cloner) : base(original, cloner) { qualityAnalyzer = cloner.Clone(original.qualityAnalyzer); Initialize(); } public override IDeepCloneable Clone(Cloner cloner) { return new GAssist(this, cloner); } public override void Prepare() { if (Problem != null) base.Prepare(); } #region Events protected override void OnProblemChanged() { ParameterizeStochasticOperator(Problem.SolutionCreator); ParameterizeStochasticOperator(Problem.Evaluator); ParameterizeMDLOperator(Problem.Evaluator); ParameterizeIterationBasedOperators(Problem.Evaluator); foreach (IOperator op in Problem.Operators.OfType()) { ParameterizeStochasticOperator(op); } ParameterizeSolutionsCreator(); ParameterizeGeneticAlgorithmMainLoop(); ParameterizeMDL(); ParameterizeSelectors(); ParameterizeAnalyzers(); ParameterizeIterationBasedOperators(); UpdateDefaultRuleOperators(); UpdateCrossovers(); UpdateMutators(); UpdateAnalyzers(); Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); ILASOperator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name; InitializeDiscretizers.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name; base.OnProblemChanged(); } private void ParameterizeMDL() { MDLIterationOperatorParameter.Value.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; //change MDLIterationOperatorParameter.Value.IndividualParameter.ActualName = "DecisionList"; MDLIterationOperatorParameter.Value.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name; MDLIterationOperatorParameter.Value.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; MDLIterationOperatorParameter.Value.InitialTheoryLengthRatioParameter.ActualName = InitialTheoryLengthRatioParameter.Name; MDLIterationOperatorParameter.Value.MDLActivationIterationParameter.ActualName = MDLActivationIterationParameter.Name; MDLIterationOperatorParameter.Value.WeightAdaptionIterationsParameter.ActualName = WeightAdaptionIterationsParameter.Name; MDLIterationOperatorParameter.Value.WeightRelaxFactorParameter.ActualName = WeightRelaxFactorParameter.Name; MDLIterationOperatorParameter.Value.IterationsParameter.ActualName = "Generations"; } protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) { ParameterizeStochasticOperator(Problem.SolutionCreator); ParameterizeSolutionsCreator(); base.Problem_SolutionCreatorChanged(sender, e); } protected override void Problem_EvaluatorChanged(object sender, EventArgs e) { ParameterizeStochasticOperator(Problem.Evaluator); ParameterizeSolutionsCreator(); ParameterizeGeneticAlgorithmMainLoop(); ParameterizeSelectors(); ParameterizeAnalyzers(); Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); Problem.Evaluator.StrataParameter.ActualName = ILASOperator.StrataParameter.ActualName; base.Problem_EvaluatorChanged(sender, e); } protected override void Problem_OperatorsChanged(object sender, EventArgs e) { foreach (IOperator op in Problem.Operators.OfType()) ParameterizeStochasticOperator(op); ParameterizeIterationBasedOperators(); UpdateCrossovers(); UpdateMutators(); UpdateAnalyzers(); base.Problem_OperatorsChanged(sender, e); } private void ElitesParameter_ValueChanged(object sender, EventArgs e) { Elites.ValueChanged += new EventHandler(Elites_ValueChanged); ParameterizeSelectors(); } private void Elites_ValueChanged(object sender, EventArgs e) { ParameterizeSelectors(); } private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) { PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged); ParameterizeSelectors(); } private void PopulationSize_ValueChanged(object sender, EventArgs e) { ParameterizeSelectors(); } private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) { ParameterizeGeneticAlgorithmMainLoop(); ParameterizeSelectors(); ParameterizeAnalyzers(); } #endregion #region Helpers private void Initialize() { PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged); PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged); ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged); Elites.ValueChanged += new EventHandler(Elites_ValueChanged); if (Problem != null) { Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); } } private void ParameterizeSolutionsCreator() { SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name; SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name; SolutionsCreator.GAssistNichesProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name; // change! ((IGAssistSolutionCreator)Problem.SolutionCreatorParameter.ActualValue).DiscretizersParameter.ActualName = "Discretizers"; } private void ParameterizeGeneticAlgorithmMainLoop() { GeneticAlgorithmMainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name; GeneticAlgorithmMainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; GeneticAlgorithmMainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; } private void ParameterizeStochasticOperator(IOperator op) { IStochasticOperator stochasticOp = op as IStochasticOperator; if (stochasticOp != null) { stochasticOp.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName; stochasticOp.RandomParameter.Hidden = true; } } private void ParameterizeMDLOperator(IOperator op) { IMDLCalculatorBasedOperator stochasticOp = op as IMDLCalculatorBasedOperator; if (stochasticOp != null) { stochasticOp.MDLCalculatorParameter.ActualName = MDLIterationOperatorParameter.Value.MDLCalculatorParameter.ActualName; } } private void ParameterizeSelectors() { foreach (INichingSingleObjectiveSelector selector in SelectorParameter.ValidValues) { selector.CopySelected = new BoolValue(true); selector.NumberOfSelectedSubScopesParameter.Value = new IntValue(2 * (PopulationSizeParameter.Value.Value - ElitesParameter.Value.Value)); selector.NumberOfSelectedSubScopesParameter.Hidden = true; selector.ParentsPerChildParameter.Value = new IntValue(2); ParameterizeStochasticOperator(selector); ParameterizeIterationBasedOperators(selector); } if (Problem != null) { foreach (INichingSingleObjectiveSelector selector in SelectorParameter.ValidValues) { selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; selector.MaximizationParameter.Hidden = true; selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; selector.QualityParameter.Hidden = true; selector.NichingParameter.ActualName = Problem.NichingParameterName; selector.GAssistNichesProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name; //change selector.IndividualParameter.ActualName = "DecisionList"; } foreach (IHierarchicalSingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType()) { selector.LengthParameter.ActualName = Problem.Evaluator.LengthParameter.ActualName; } } } private void ParameterizeAnalyzers() { qualityAnalyzer.ResultsParameter.ActualName = "Results"; qualityAnalyzer.ResultsParameter.Hidden = true; if (Problem != null) { qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; qualityAnalyzer.MaximizationParameter.Hidden = true; qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; qualityAnalyzer.QualityParameter.Depth = 1; qualityAnalyzer.QualityParameter.Hidden = true; qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name; qualityAnalyzer.BestKnownQualityParameter.Hidden = true; } } private void ParameterizeIterationBasedOperators(IOperator op) { IIterationBasedOperator iterationOp = op as IIterationBasedOperator; if (iterationOp != null) { ParameterizeIterationBasedOperators(iterationOp); } } private void ParameterizeIterationBasedOperators(IIterationBasedOperator op) { op.IterationsParameter.ActualName = "Generations"; op.IterationsParameter.Hidden = true; op.MaximumIterationsParameter.ActualName = "MaximumGenerations"; op.MaximumIterationsParameter.Hidden = true; } private void ParameterizeIterationBasedOperators() { if (Problem != null) { foreach (IIterationBasedOperator op in Problem.Operators.OfType()) { ParameterizeIterationBasedOperators(op); } } } private void UpdateDefaultRuleOperators() { IDefaultRuleOperator oldDefaultRule = DefaultRuleParameter.Value; DefaultRuleParameter.ValidValues.Clear(); IDefaultRuleOperator defaultdefaultRule = Problem.Operators.OfType().FirstOrDefault(); foreach (IDefaultRuleOperator defaultRule in Problem.Operators.OfType().OrderBy(x => x.Name)) DefaultRuleParameter.ValidValues.Add(defaultRule); if (oldDefaultRule != null) { IDefaultRuleOperator defaultRule = DefaultRuleParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldDefaultRule.GetType()); if (defaultRule != null) DefaultRuleParameter.Value = defaultRule; else oldDefaultRule = null; } if (oldDefaultRule == null && defaultdefaultRule != null) { DefaultRuleParameter.Value = defaultdefaultRule; SolutionsCreator.NichingParameter.ActualName = defaultdefaultRule.NichingParameter.ActualName; } } private void UpdateCrossovers() { ICrossover oldCrossover = CrossoverParameter.Value; CrossoverParameter.ValidValues.Clear(); ICrossover defaultCrossover = Problem.Operators.OfType().FirstOrDefault(); foreach (ICrossover crossover in Problem.Operators.OfType().OrderBy(x => x.Name)) CrossoverParameter.ValidValues.Add(crossover); if (oldCrossover != null) { ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType()); if (crossover != null) CrossoverParameter.Value = crossover; else oldCrossover = null; } if (oldCrossover == null && defaultCrossover != null) CrossoverParameter.Value = defaultCrossover; } private void UpdateMutators() { IManipulator oldMutator = MutatorParameter.Value; MutatorParameter.ValidValues.Clear(); IManipulator defaultMutator = Problem.Operators.OfType().FirstOrDefault(); foreach (IManipulator mutator in Problem.Operators.OfType().OrderBy(x => x.Name)) MutatorParameter.ValidValues.Add(mutator); if (oldMutator != null) { IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType()); if (mutator != null) MutatorParameter.Value = mutator; } if (oldMutator == null && defaultMutator != null) MutatorParameter.Value = defaultMutator; } private void UpdateAnalyzers() { Analyzer.Operators.Clear(); if (Problem != null) { foreach (IAnalyzer analyzer in Problem.Operators.OfType()) { foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType()) param.Depth = 1; Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault); } } Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault); } private GAssistMainLoop FindMainLoop(IOperator start) { IOperator mainLoop = start; while (mainLoop != null && !(mainLoop is GAssistMainLoop)) mainLoop = ((SingleSuccessorOperator)mainLoop).Successor; if (mainLoop == null) return null; else return (GAssistMainLoop)mainLoop; } #endregion } }