Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7325


Ignore:
Timestamp:
01/13/12 14:21:43 (13 years ago)
Author:
ascheibe
Message:

#1745 added result storing operations for the reducer

Location:
branches/HiveHiveEngine
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveHiveEngine/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/ParallelIslandGeneticAlgorithmMainLoop.cs

    r7323 r7325  
    271271      generationsReducer.TargetParameterName.Value = new StringValue("Generations");
    272272      generationsReducer.ReductionOperation.Value = new ReductionType(ReductionTypes.Min);
     273      generationsReducer.TargetOperation.Value = new TargetOperationType(TargetOperationTypes.Sum);
    273274
    274275      evaluatedSolutionsReducer.Name = "Increment Evaluated Solutions";
     
    276277      evaluatedSolutionsReducer.TargetParameterName.Value = new StringValue(EvaluatedSolutionsParameter.Name);
    277278      evaluatedSolutionsReducer.ReductionOperation.Value = new ReductionType(ReductionTypes.Sum);
     279      evaluatedSolutionsReducer.TargetOperation.Value = new TargetOperationType(TargetOperationTypes.Sum);
    278280
    279281      emigrantsSelector.Name = "Emigrants Selector (placeholder)";
  • branches/HiveHiveEngine/HeuristicLab.Operators/3.3/HeuristicLab.Operators-3.3.csproj

    r7323 r7325  
    118118    <Compile Include="Assigner.cs" />
    119119    <Compile Include="AlgorithmOperator.cs" />
     120    <Compile Include="TargetOperationType.cs" />
     121    <Compile Include="TargetOperationTypes.cs" />
    120122    <Compile Include="IntDataReducer.cs" />
    121123    <Compile Include="ReductionType.cs" />
  • branches/HiveHiveEngine/HeuristicLab.Operators/3.3/IntDataReducer.cs

    r7323 r7325  
    3232  [StorableClass]
    3333  public sealed class IntDataReducer : SingleSuccessorOperator {
     34    #region Parameter Properties
    3435    public ScopeTreeLookupParameter<IntValue> ParameterToReduce {
    3536      get { return (ScopeTreeLookupParameter<IntValue>)Parameters["ParameterToReduce"]; }
     
    4445      get { return (ValueParameter<ReductionType>)Parameters["ReductionOperation"]; }
    4546    }
     47    public ValueParameter<TargetOperationType> TargetOperation {
     48      get { return (ValueParameter<TargetOperationType>)Parameters["TargetOperation"]; }
     49    }
     50    #endregion
    4651
    4752    [StorableConstructor]
     
    5257    public IntDataReducer()
    5358      : base() {
    54       Parameters.Add(new ScopeTreeLookupParameter<IntValue>("ParameterToReduce", "The actual parameter defined by TargetParameterName."));
    55       Parameters.Add(new ValueLookupParameter<StringValue>("TargetParameterName", "Parameter name to add the value to.", new StringValue(string.Empty)));
     59      #region Create parameters
     60      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("ParameterToReduce", "The parameter on which the reduction operation should be applied."));
     61      Parameters.Add(new ValueLookupParameter<StringValue>("TargetParameterName", "Parameter to store the result in.", new StringValue(string.Empty)));
    5662      Parameters.Add(new LookupParameter<IntValue>("TargetParameter", "The actual parameter defined by TargetParameterName."));
    5763      Parameters.Add(new ValueParameter<ReductionType>("ReductionOperation", "The reduction operation to perform."));
     64      Parameters.Add(new ValueParameter<TargetOperationType>("TargetOperation", "The target operation to perform."));
     65      #endregion
    5866    }
    5967
     
    6977        if (TargetParameter.ActualValue == null) TargetParameter.ActualValue = new IntValue();
    7078
    71         int result;
     79        int result = 1;
    7280        switch (ReductionOperation.Value.Value) {
    7381          case ReductionTypes.Sum:
     
    7583            break;
    7684          case ReductionTypes.Prod:
    77             result = 1;
    7885            intValues.ForEach(x => result *= x.Value);
    7986            break;
     
    8794            result = intValues.Max(x => x.Value);
    8895            break;
    89           default:
    90             throw new ArgumentException("Unknown ReductionType: " + ReductionOperation.Value.Value);
    9196        }
    92         //TODO: there should be at least a Set, Add and Mul operation
    93         TargetParameter.ActualValue.Value += result;
     97
     98        switch (TargetOperation.Value.Value) {
     99          case TargetOperationTypes.Set:
     100            TargetParameter.ActualValue.Value = result;
     101            break;
     102          case TargetOperationTypes.Sum:
     103            TargetParameter.ActualValue.Value += result;
     104            break;
     105          case TargetOperationTypes.Prod:
     106            if (TargetParameter.ActualValue.Value == 0) TargetParameter.ActualValue.Value = 1;
     107            TargetParameter.ActualValue.Value *= result;
     108            break;
     109        }
    94110      }
    95111      return base.Apply();
Note: See TracChangeset for help on using the changeset viewer.