Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11678


Ignore:
Timestamp:
12/10/14 12:42:59 (9 years ago)
Author:
pfleck
Message:

#2269

  • Fixed bug when updating crossovers and mutators.
  • Made DataReducers Reduction- and TargetOperationParameter to ValueLookupParameter. This enables ALPS to make the age determination configurable.
Location:
branches/ALPS
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithm.cs

    r11676 r11678  
    2121
    2222using System;
    23 using System.Collections;
    2423using System.Collections.Generic;
    2524using System.Linq;
     
    414413    }
    415414    private void ParameterizeMainLoop() {
    416       //MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
    417       //MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
    418       //MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    419       //MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    420415      MainLoop.MainOperator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
    421416      MainLoop.MainOperator.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
     
    500495      if (oldCrossover != null) {
    501496        var crossover = CrossoverParameter.ValidValues.FirstOrDefault(c => c.GetType() == oldCrossover.GetType());
    502         CrossoverParameter.Value = crossover;
     497        if (crossover != null)
     498          CrossoverParameter.Value = crossover;
     499        else
     500          oldCrossover = null;
    503501      }
    504502      if (oldCrossover == null && defaultCrossover != null)
     
    514512      if (oldMutator != null) {
    515513        var mutator = MutatorParameter.ValidValues.FirstOrDefault(m => m.GetType() == oldMutator.GetType());
    516         MutatorParameter.Value = mutator;
     514        if (mutator != null)
     515          MutatorParameter.Value = mutator;
    517516      }
    518517    }
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithmMainLoop.cs

    r11676 r11678  
    175175      ageCalculator.ParameterToReduce.ActualName = "Age";
    176176      ageCalculator.TargetParameter.ActualName = "Age";
    177       ageCalculator.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Max);
     177      ageCalculator.ReductionOperation.Value = null;
     178      ageCalculator.ReductionOperation.ActualName = "AgeInheritance";
    178179      ageCalculator.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign);
    179180      crossover.Successor = ageCalculator;
  • branches/ALPS/HeuristicLab.Operators/3.3/DataReducer.cs

    r11171 r11678  
    4040      get { return (LookupParameter<IItem>)Parameters["TargetParameter"]; }
    4141    }
    42     public ValueParameter<ReductionOperation> ReductionOperation {
    43       get { return (ValueParameter<ReductionOperation>)Parameters["ReductionOperation"]; }
    44     }
    45     public ValueParameter<ReductionOperation> TargetOperation {
    46       get { return (ValueParameter<ReductionOperation>)Parameters["TargetOperation"]; }
     42    public ValueLookupParameter<ReductionOperation> ReductionOperation {
     43      get { return (ValueLookupParameter<ReductionOperation>)Parameters["ReductionOperation"]; }
     44    }
     45    public ValueLookupParameter<ReductionOperation> TargetOperation {
     46      get { return (ValueLookupParameter<ReductionOperation>)Parameters["TargetOperation"]; }
    4747    }
    4848    #endregion
     
    5858      Parameters.Add(new ScopeTreeLookupParameter<IItem>("ParameterToReduce", "The parameter on which the reduction operation should be applied."));
    5959      Parameters.Add(new LookupParameter<IItem>("TargetParameter", "The target variable in which the reduced value should be stored."));
    60       Parameters.Add(new ValueParameter<ReductionOperation>("ReductionOperation", "The operation which is applied on the parameters to reduce."));
    61       Parameters.Add(new ValueParameter<ReductionOperation>("TargetOperation", "The operation used to apply the reduced value to the target variable."));
     60      Parameters.Add(new ValueLookupParameter<ReductionOperation>("ReductionOperation", "The operation which is applied on the parameters to reduce.", new ReductionOperation()));
     61      Parameters.Add(new ValueLookupParameter<ReductionOperation>("TargetOperation", "The operation used to apply the reduced value to the target variable.", new ReductionOperation()));
    6262      #endregion
    6363    }
     
    6565    public override IDeepCloneable Clone(Cloner cloner) {
    6666      return new DataReducer(this, cloner);
     67    }
     68
     69    [StorableHook(HookType.AfterDeserialization)]
     70    private void AfterDeserialization() {
     71      // BackwardsCompatibility3.3
     72      var oldReductionOperation = Parameters["ReductionOperation"] as ValueParameter<ReductionOperation>;
     73      if (oldReductionOperation != null) {
     74        Parameters.Remove("ReductionOperation");
     75        Parameters.Add(new ValueLookupParameter<ReductionOperation>("ReductionOperation", "The operation which is applied on the parameters to reduce.", oldReductionOperation.Value));
     76      }
     77      var oldTargetOperation = Parameters["TargetOperation"] as ValueParameter<ReductionOperation>;
     78      if (oldTargetOperation != null) {
     79        Parameters.Remove("TargetOperation");
     80        Parameters.Add(new ValueLookupParameter<ReductionOperation>("TargetOperation", "The operation used to apply the reduced value to the target variable.", oldTargetOperation.Value));
     81      }
    6782    }
    6883
     
    89104    private void CalculateResult(IEnumerable<int> values, Type targetType) {
    90105      int result;
    91       switch (ReductionOperation.Value.Value) {
     106      switch (ReductionOperation.ActualValue.Value) {
    92107        case ReductionOperations.Sum:
    93108          result = values.Sum();
     
    116131
    117132      IntValue target;
    118       switch (TargetOperation.Value.Value) {
     133      switch (TargetOperation.ActualValue.Value) {
    119134        case ReductionOperations.Sum:
    120135          target = InitializeTarget<IntValue, int>(targetType, 0);
     
    149164    private void CalculateResult(IEnumerable<double> values, Type targetType) {
    150165      double result;
    151       switch (ReductionOperation.Value.Value) {
     166      switch (ReductionOperation.ActualValue.Value) {
    152167        case ReductionOperations.Sum:
    153168          result = values.Sum();
     
    176191
    177192      DoubleValue target;
    178       switch (TargetOperation.Value.Value) {
     193      switch (TargetOperation.ActualValue.Value) {
    179194        case ReductionOperations.Sum:
    180195          target = InitializeTarget<DoubleValue, double>(targetType, 0.0);
     
    209224    private void CalculateResult(IEnumerable<TimeSpan> values, Type targetType) {
    210225      TimeSpan result;
    211       switch (ReductionOperation.Value.Value) {
     226      switch (ReductionOperation.ActualValue.Value) {
    212227        case ReductionOperations.Sum:
    213228          result = values.Aggregate(new TimeSpan(), (x, y) => x + y);
     
    230245
    231246      TimeSpanValue target;
    232       switch (TargetOperation.Value.Value) {
     247      switch (TargetOperation.ActualValue.Value) {
    233248        case ReductionOperations.Sum:
    234249          target = InitializeTarget<TimeSpanValue, TimeSpan>(targetType, new TimeSpan());
     
    259274    private void CalculateResult(IEnumerable<bool> values, Type targetType) {
    260275      bool result;
    261       switch (ReductionOperation.Value.Value) {
     276      switch (ReductionOperation.ActualValue.Value) {
    262277        case ReductionOperations.All:
    263278          result = values.All(x => x);
     
    271286
    272287      BoolValue target;
    273       switch (TargetOperation.Value.Value) {
     288      switch (TargetOperation.ActualValue.Value) {
    274289        case ReductionOperations.Assign:
    275290          target = InitializeTarget<BoolValue, bool>(targetType, true);
Note: See TracChangeset for help on using the changeset viewer.