Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/25/10 06:35:43 (14 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • worked on algorithms
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.SGA/3.3/SGA.cs

    r2864 r2865  
    2020#endregion
    2121
     22using System;
     23using System.Linq;
    2224using HeuristicLab.Core;
    2325using HeuristicLab.Data;
     
    2729using HeuristicLab.Parameters;
    2830using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    29 using System;
    3031
    3132namespace HeuristicLab.SGA {
     
    4041    [Storable]
    4142    private SGAOperator sgaOperator;
     43
     44    private ConstrainedValueParameter<ICrossover> CrossoverOperatorParameter {
     45      get { return (ConstrainedValueParameter<ICrossover>)Parameters["CrossoverOperator"]; }
     46    }
     47    private ConstrainedValueParameter<IManipulator> MutationOperatorParameter {
     48      get { return (ConstrainedValueParameter<IManipulator>)Parameters["MutationOperator"]; }
     49    }
    4250
    4351    public override Type ProblemType {
     
    5462      Parameters.Add(new ValueParameter<BoolData>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolData(true)));
    5563      Parameters.Add(new ValueParameter<IntData>("PopulationSize", "The size of the population of solutions.", new IntData(100)));
    56       Parameters.Add(new OperatorParameter("CrossoverOperator", "The operator used to cross solutions."));
     64      Parameters.Add(new ConstrainedValueParameter<ICrossover>("CrossoverOperator", "The operator used to cross solutions."));
    5765      Parameters.Add(new ValueParameter<DoubleData>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new DoubleData(0.05)));
    58       Parameters.Add(new OperatorParameter("MutationOperator", "The operator used to mutate solutions."));
     66      Parameters.Add(new ConstrainedValueParameter<IManipulator>("MutationOperator", "The operator used to mutate solutions."));
    5967      Parameters.Add(new ValueParameter<IntData>("Elites", "The numer of elite solutions which are kept in each generation.", new IntData(1)));
    6068      Parameters.Add(new ValueParameter<IntData>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntData(1000)));
     
    103111    protected override void OnProblemChanged() {
    104112      if (Problem.SolutionCreator is IStochasticOperator) ((IStochasticOperator)Problem.SolutionCreator).RandomParameter.ActualName = "Random";
     113      if (Problem.Evaluator is IStochasticOperator) ((IStochasticOperator)Problem.Evaluator).RandomParameter.ActualName = "Random";
     114      Problem.Operators.Where(x => x is IStochasticOperator).Select(x => (x as IStochasticOperator).RandomParameter.ActualName = "Random");
     115
    105116      populationCreator.SolutionCreatorParameter.Value = Problem.SolutionCreator;
    106117      populationCreator.SolutionEvaluatorParameter.Value = Problem.Evaluator;
    107118      sgaOperator.MaximizationParameter.Value = Problem.Maximization;
    108       sgaOperator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.Name;
     119      sgaOperator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    109120      sgaOperator.SolutionEvaluatorParameter.Value = Problem.Evaluator;
     121
     122      CrossoverOperatorParameter.ValidValues.Clear();
     123      var crossovers = from o in Problem.Operators
     124                       where o is ICrossover
     125                       select (ICrossover)o;
     126      foreach (ICrossover crossover in crossovers)
     127        CrossoverOperatorParameter.ValidValues.Add(crossover);
     128
     129      MutationOperatorParameter.ValidValues.Clear();
     130      var mutators = from o in Problem.Operators
     131                     where o is IManipulator
     132                     select (IManipulator)o;
     133      foreach (IManipulator mutator in mutators)
     134        MutationOperatorParameter.ValidValues.Add(mutator);
     135
    110136      base.OnProblemChanged();
    111137    }
     
    116142    }
    117143    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
     144      if (Problem.Evaluator is IStochasticOperator) ((IStochasticOperator)Problem.Evaluator).RandomParameter.ActualName = "Random";
    118145      populationCreator.SolutionEvaluatorParameter.Value = Problem.Evaluator;
    119       sgaOperator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.Name;
     146      sgaOperator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    120147      sgaOperator.SolutionEvaluatorParameter.Value = Problem.Evaluator;
    121148      base.Problem_EvaluatorChanged(sender, e);
Note: See TracChangeset for help on using the changeset viewer.