Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/16/13 13:13:41 (12 years ago)
Author:
spimming
Message:

#1888:

  • Merged revisions from trunk
Location:
branches/OaaS
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/OaaS

  • branches/OaaS/HeuristicLab.Operators/3.3/AlgorithmOperator.cs

    r7259 r9363  
    3131  [Item("AlgorithmOperator", "An operator which represents an algorithm represented as an operator graph.")]
    3232  [StorableClass]
    33   public abstract class AlgorithmOperator : SingleSuccessorOperator {
     33  public abstract class AlgorithmOperator : SingleSuccessorOperator, IOperatorGraphOperator {
    3434    public static new Image StaticItemImage {
    3535      get { return HeuristicLab.Common.Resources.VSImageLibrary.Module; }
  • branches/OaaS/HeuristicLab.Operators/3.3/CheckedMultiOperator.cs

    r7259 r9363  
    3030  [Item("CheckedMultiOperator", "A base class for operators which apply arbitrary many other operators of a specific type that can be checked or unchecked.")]
    3131  [StorableClass]
    32   public abstract class CheckedMultiOperator<T> : MultiOperator<T> where T : class, IOperator {
     32  public abstract class CheckedMultiOperator<T> : MultiOperator<T>, ICheckedMultiOperator<T> where T : class, IOperator {
    3333    /// <summary>
    3434    /// Gets the operators of the checked multi operator
  • branches/OaaS/HeuristicLab.Operators/3.3/DataReducer.cs

    r7395 r9363  
    7070      var values = ParameterToReduce.ActualValue;
    7171      if (values.Count() > 0) {
    72         if (values.All(x => x.GetType() == typeof(IntValue))) {
    73           List<IntValue> intValues = new List<IntValue>();
    74           values.ForEach(x => intValues.Add((IntValue)x));
    75           CalculateResult(intValues);
    76         } else if (values.All(x => x.GetType() == typeof(DoubleValue))) {
    77           List<DoubleValue> doubleValues = new List<DoubleValue>();
    78           values.ForEach(x => doubleValues.Add((DoubleValue)x));
    79           CalculateResult(doubleValues);
    80         } else if (values.All(x => x.GetType() == typeof(TimeSpanValue))) {
    81           List<TimeSpanValue> timeSpanValues = new List<TimeSpanValue>();
    82           values.ForEach(x => timeSpanValues.Add((TimeSpanValue)x));
    83           CalculateResult(timeSpanValues);
     72        if (values.All(x => typeof(IntValue).IsAssignableFrom(x.GetType()))) {
     73          CalculateResult(values.OfType<IntValue>().Select(x => x.Value), values.First().GetType());
     74        } else if (values.All(x => typeof(DoubleValue).IsAssignableFrom(x.GetType()))) {
     75          CalculateResult(values.OfType<DoubleValue>().Select(x => x.Value), values.First().GetType());
     76        } else if (values.All(x => typeof(TimeSpanValue).IsAssignableFrom(x.GetType()))) {
     77          CalculateResult(values.OfType<TimeSpanValue>().Select(x => x.Value), values.First().GetType());
    8478        } else {
    8579          throw new ArgumentException(string.Format("Type {0} is not supported by the DataReducer.", values.First().GetType()));
     
    8983    }
    9084
    91     private void CalculateResult(List<IntValue> values) {
    92       int result = 1;
    93       if (TargetParameter.ActualValue == null) TargetParameter.ActualValue = new IntValue();
    94       IntValue target = (IntValue)TargetParameter.ActualValue;
    95 
     85    #region integer reduction
     86    private void CalculateResult(IEnumerable<int> values, Type targetType) {
     87      int result;
    9688      switch (ReductionOperation.Value.Value) {
    9789        case ReductionOperations.Sum:
    98           result = values.Sum(x => x.Value);
    99           break;
    100         case ReductionOperations.Prod:
    101           values.ForEach(x => result *= x.Value);
    102           break;
    103         case ReductionOperations.Avg:
    104           result = (int)Math.Round(values.Average(x => x.Value));
    105           break;
    106         case ReductionOperations.Min:
    107           result = values.Min(x => x.Value);
    108           break;
    109         case ReductionOperations.Max:
    110           result = values.Max(x => x.Value);
    111           break;
    112         default:
    113           throw new InvalidOperationException(string.Format("Operation {0} is not supported as ReductionOperation for type: {1}.", ReductionOperation.Value.Value, result.GetType()));
    114       }
    115 
     90          result = values.Sum();
     91          break;
     92        case ReductionOperations.Product:
     93          result = values.Aggregate(1, (x, y) => x * y);
     94          break;
     95        case ReductionOperations.Count:
     96          result = values.Count();
     97          break;
     98        case ReductionOperations.Min:
     99          result = values.Min();
     100          break;
     101        case ReductionOperations.Max:
     102          result = values.Max();
     103          break;
     104        case ReductionOperations.Avg:
     105          result = (int)Math.Round(values.Average());
     106          break;
     107        case ReductionOperations.Assign:
     108          result = values.Last();
     109          break;
     110        default:
     111          throw new InvalidOperationException(string.Format("Operation {0} is not supported as ReductionOperation for type: {1}.", ReductionOperation.Value.Value, targetType));
     112      }
     113
     114      IntValue target;
    116115      switch (TargetOperation.Value.Value) {
    117         case ReductionOperations.Assign:
     116        case ReductionOperations.Sum:
     117          target = InitializeTarget<IntValue, int>(targetType, 0);
     118          target.Value += result;
     119          break;
     120        case ReductionOperations.Product:
     121          target = InitializeTarget<IntValue, int>(targetType, 1);
     122          target.Value = target.Value * result;
     123          break;
     124        case ReductionOperations.Min:
     125          target = InitializeTarget<IntValue, int>(targetType, int.MaxValue);
     126          target.Value = Math.Min(target.Value, result);
     127          break;
     128        case ReductionOperations.Max:
     129          target = InitializeTarget<IntValue, int>(targetType, int.MinValue);
     130          target.Value = Math.Max(target.Value, result);
     131          break;
     132        case ReductionOperations.Avg:
     133          target = InitializeTarget<IntValue, int>(targetType, result);
     134          target.Value = (int)Math.Round((target.Value + result) / 2.0);
     135          break;
     136        case ReductionOperations.Assign:
     137          target = InitializeTarget<IntValue, int>(targetType, 0);
    118138          target.Value = result;
    119139          break;
    120         case ReductionOperations.Sum:
     140        default:
     141          throw new InvalidOperationException(string.Format("Operation {0} is not supported as TargetOperation for type: {1}.", TargetOperation.Value.Value, targetType));
     142      }
     143    }
     144    #endregion
     145    #region double reduction
     146    private void CalculateResult(IEnumerable<double> values, Type targetType) {
     147      double result;
     148      switch (ReductionOperation.Value.Value) {
     149        case ReductionOperations.Sum:
     150          result = values.Sum();
     151          break;
     152        case ReductionOperations.Product:
     153          result = values.Aggregate(1.0, (x, y) => x * y);
     154          break;
     155        case ReductionOperations.Count:
     156          result = values.Count();
     157          break;
     158        case ReductionOperations.Min:
     159          result = values.Min();
     160          break;
     161        case ReductionOperations.Max:
     162          result = values.Max();
     163          break;
     164        case ReductionOperations.Avg:
     165          result = values.Average();
     166          break;
     167        case ReductionOperations.Assign:
     168          result = values.Last();
     169          break;
     170        default:
     171          throw new InvalidOperationException(string.Format("Operation {0} is not supported as ReductionOperation for type: {1}.", ReductionOperation.Value.Value, targetType));
     172      }
     173
     174      DoubleValue target;
     175      switch (TargetOperation.Value.Value) {
     176        case ReductionOperations.Sum:
     177          target = InitializeTarget<DoubleValue, double>(targetType, 0.0);
    121178          target.Value += result;
    122179          break;
    123         case ReductionOperations.Prod:
    124           if (target.Value == 0) target.Value = 1;
    125           target.Value *= result;
    126           break;
    127         default:
    128           throw new InvalidOperationException(string.Format("Operation {0} is not supported as TargetOperation for type: {1}.", TargetOperation.Value.Value, result.GetType()));
    129       }
    130     }
    131 
    132     private void CalculateResult(List<DoubleValue> values) {
    133       double result = 1.0;
    134       if (TargetParameter.ActualValue == null) TargetParameter.ActualValue = new DoubleValue();
    135       DoubleValue target = (DoubleValue)TargetParameter.ActualValue;
    136 
     180        case ReductionOperations.Product:
     181          target = InitializeTarget<DoubleValue, double>(targetType, 1.0);
     182          target.Value = target.Value * result;
     183          break;
     184        case ReductionOperations.Min:
     185          target = InitializeTarget<DoubleValue, double>(targetType, double.MaxValue);
     186          target.Value = Math.Min(target.Value, result);
     187          break;
     188        case ReductionOperations.Max:
     189          target = InitializeTarget<DoubleValue, double>(targetType, double.MinValue);
     190          target.Value = Math.Max(target.Value, result);
     191          break;
     192        case ReductionOperations.Avg:
     193          target = InitializeTarget<DoubleValue, double>(targetType, result);
     194          target.Value = (target.Value + result) / 2.0;
     195          break;
     196        case ReductionOperations.Assign:
     197          target = InitializeTarget<DoubleValue, double>(targetType, 0.0);
     198          target.Value = result;
     199          break;
     200        default:
     201          throw new InvalidOperationException(string.Format("Operation {0} is not supported as TargetOperation for type: {1}.", TargetOperation.Value.Value, targetType));
     202      }
     203    }
     204    #endregion
     205    #region TimeSpan reduction
     206    private void CalculateResult(IEnumerable<TimeSpan> values, Type targetType) {
     207      TimeSpan result;
    137208      switch (ReductionOperation.Value.Value) {
    138209        case ReductionOperations.Sum:
    139           result = values.Sum(x => x.Value);
    140           break;
    141         case ReductionOperations.Prod:
    142           values.ForEach(x => result *= x.Value);
    143           break;
    144         case ReductionOperations.Avg:
    145           result = values.Average(x => x.Value);
    146           break;
    147         case ReductionOperations.Min:
    148           result = values.Min(x => x.Value);
    149           break;
    150         case ReductionOperations.Max:
    151           result = values.Max(x => x.Value);
    152           break;
    153         default:
    154           throw new InvalidOperationException(string.Format("Operation {0} is not supported as ReductionOperation for type: {1}.", ReductionOperation.Value.Value, result.GetType()));
    155       }
    156 
     210          result = values.Aggregate(new TimeSpan(), (x, y) => x + y);
     211          break;
     212        case ReductionOperations.Min:
     213          result = values.Min();
     214          break;
     215        case ReductionOperations.Max:
     216          result = values.Max();
     217          break;
     218        case ReductionOperations.Avg:
     219          result = TimeSpan.FromMilliseconds(values.Average(x => x.TotalMilliseconds));
     220          break;
     221        case ReductionOperations.Assign:
     222          result = values.Last();
     223          break;
     224        default:
     225          throw new InvalidOperationException(string.Format("Operation {0} is not supported as ReductionOperation for type: {1}.", ReductionOperation.Value.Value, targetType));
     226      }
     227
     228      TimeSpanValue target;
    157229      switch (TargetOperation.Value.Value) {
    158         case ReductionOperations.Assign:
     230        case ReductionOperations.Sum:
     231          target = InitializeTarget<TimeSpanValue, TimeSpan>(targetType, new TimeSpan());
     232          target.Value += result;
     233          break;
     234        case ReductionOperations.Min:
     235          target = InitializeTarget<TimeSpanValue, TimeSpan>(targetType, TimeSpan.MaxValue);
     236          target.Value = target.Value < result ? target.Value : result;
     237          break;
     238        case ReductionOperations.Max:
     239          target = InitializeTarget<TimeSpanValue, TimeSpan>(targetType, TimeSpan.MinValue);
     240          target.Value = target.Value > result ? target.Value : result;
     241          break;
     242        case ReductionOperations.Avg:
     243          target = InitializeTarget<TimeSpanValue, TimeSpan>(targetType, result);
     244          target.Value = TimeSpan.FromMilliseconds((target.Value.TotalMilliseconds + result.TotalMilliseconds) / 2);
     245          break;
     246        case ReductionOperations.Assign:
     247          target = InitializeTarget<TimeSpanValue, TimeSpan>(targetType, new TimeSpan());
    159248          target.Value = result;
    160249          break;
    161         case ReductionOperations.Sum:
    162           target.Value += result;
    163           break;
    164         case ReductionOperations.Prod:
    165           if (target.Value == 0.0) target.Value = 1.0;
    166           target.Value *= result;
    167           break;
    168         default:
    169           throw new InvalidOperationException(string.Format("Operation {0} is not supported as TargetOperation for type: {1}.", TargetOperation.Value.Value, result.GetType()));
    170       }
    171     }
    172 
    173     private void CalculateResult(List<TimeSpanValue> values) {
    174       TimeSpan result = TimeSpan.Zero;
    175       if (TargetParameter.ActualValue == null) TargetParameter.ActualValue = new TimeSpanValue();
    176       TimeSpanValue target = (TimeSpanValue)TargetParameter.ActualValue;
    177 
    178       switch (ReductionOperation.Value.Value) {
    179         case ReductionOperations.Sum:
    180           values.ForEach(x => result = result.Add(x.Value));
    181           break;
    182         case ReductionOperations.Avg:
    183           double avg = values.Average(x => x.Value.TotalMilliseconds);
    184           result = TimeSpan.FromMilliseconds(avg);
    185           break;
    186         case ReductionOperations.Min:
    187           result = values.Min(x => x.Value);
    188           break;
    189         case ReductionOperations.Max:
    190           result = values.Max(x => x.Value);
    191           break;
    192         default:
    193           throw new InvalidOperationException(string.Format("Operation {0} is not supported as ReductionOperation for type: {1}.", ReductionOperation.Value.Value, result.GetType()));
    194       }
    195 
    196       switch (TargetOperation.Value.Value) {
    197         case ReductionOperations.Assign:
    198           target.Value = result;
    199           break;
    200         case ReductionOperations.Sum:
    201           target.Value += result;
    202           break;
    203         default:
    204           throw new InvalidOperationException(string.Format("Operation {0} is not supported as TargetOperation for type: {1}.", TargetOperation.Value.Value, result.GetType()));
    205       }
    206     }
     250        default:
     251          throw new InvalidOperationException(string.Format("Operation {0} is not supported as TargetOperation for type: {1}.", TargetOperation.Value.Value, targetType));
     252      }
     253    }
     254    #endregion
     255
     256    #region helpers
     257    private T1 InitializeTarget<T1, T2>(Type targetType, T2 initialValue)
     258      where T1 : ValueTypeValue<T2>
     259      where T2 : struct {
     260      T1 target = (T1)TargetParameter.ActualValue;
     261      if (target == null) {
     262        target = (T1)Activator.CreateInstance(targetType);
     263        TargetParameter.ActualValue = target;
     264        target.Value = initialValue;
     265      }
     266      return target;
     267    }
     268    #endregion
    207269  }
    208270}
  • branches/OaaS/HeuristicLab.Operators/3.3/HeuristicLab.Operators-3.3.csproj

    r7395 r9363  
    221221  -->
    222222  <PropertyGroup>
    223     <PreBuildEvent>set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
     223   <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
    224224set ProjectDir=$(ProjectDir)
    225225set SolutionDir=$(SolutionDir)
     
    228228call PreBuildEvent.cmd
    229229</PreBuildEvent>
     230<PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">
     231export ProjectDir=$(ProjectDir)
     232export SolutionDir=$(SolutionDir)
     233
     234$SolutionDir/PreBuildEvent.sh
     235</PreBuildEvent>
    230236  </PropertyGroup>
    231237</Project>
  • branches/OaaS/HeuristicLab.Operators/3.3/MultiOperator.cs

    r7259 r9363  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    2422using HeuristicLab.Collections;
    2523using HeuristicLab.Common;
     
    2725using HeuristicLab.Parameters;
    2826using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using System;
     28using System.Collections.Generic;
    2929
    3030namespace HeuristicLab.Operators {
     
    4747          operators = value;
    4848          RegisterOperatorsEvents();
     49          UpdateOperatorParameters();
    4950        }
    5051      }
  • branches/OaaS/HeuristicLab.Operators/3.3/Operator.cs

    r7259 r9363  
    2222using System;
    2323using System.Drawing;
     24using System.Linq;
    2425using System.Threading;
    2526using HeuristicLab.Common;
     
    119120        ExecutionContext = context;
    120121        this.cancellationToken = cancellationToken;
    121         foreach (IParameter param in Parameters)
     122        foreach (ILookupParameter param in Parameters.OfType<ILookupParameter>())
    122123          param.ExecutionContext = context;
    123124        IOperation next = Apply();
     
    126127      }
    127128      finally {
    128         foreach (IParameter param in Parameters)
     129        foreach (ILookupParameter param in Parameters.OfType<ILookupParameter>())
    129130          param.ExecutionContext = null;
    130131        ExecutionContext = null;
  • branches/OaaS/HeuristicLab.Operators/3.3/Plugin.cs.frame

    r7259 r9363  
    2626  /// Plugin class for HeuristicLab.Operators plugin.
    2727  /// </summary>
    28   [Plugin("HeuristicLab.Operators", "3.3.6.$WCREV$")]
     28  [Plugin("HeuristicLab.Operators", "3.3.7.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Operators-3.3.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.Collections", "3.3")]
  • branches/OaaS/HeuristicLab.Operators/3.3/Properties/AssemblyInfo.cs.frame

    r7259 r9363  
    5454// by using the '*' as shown below:
    5555[assembly: AssemblyVersion("3.3.0.0")]
    56 [assembly: AssemblyFileVersion("3.3.6.$WCREV$")]
     56[assembly: AssemblyFileVersion("3.3.7.$WCREV$")]
  • branches/OaaS/HeuristicLab.Operators/3.3/ReductionOperations.cs

    r7395 r9363  
    2222namespace HeuristicLab.Operators {
    2323  public enum ReductionOperations {
    24     Assign,
    2524    Sum,
    26     Prod,
     25    Product,
     26    Count,
    2727    Min,
    2828    Max,
    29     Avg
     29    Avg,
     30    Assign
    3031  }
    3132}
  • branches/OaaS/HeuristicLab.Operators/3.3/SubScopesCounter.cs

    r7259 r9363  
    2727
    2828namespace HeuristicLab.Operators {
    29   [Item("SubScopesCounter", "Counts the number of direct sub-scopes and increments the value given in the parameter.")]
     29  [Item("SubScopesCounter", "Counts the number of direct sub-scopes and increments or assigns it to the value given in the parameter.")]
    3030  [StorableClass]
    3131  public class SubScopesCounter : SingleSuccessorOperator {
     
    3333    public ILookupParameter<IntValue> ValueParameter {
    3434      get { return (ILookupParameter<IntValue>)Parameters["Value"]; }
     35    }
     36    public IValueParameter<BoolValue> AccumulateParameter {
     37      get { return (IValueParameter<BoolValue>)Parameters["Accumulate"]; }
    3538    }
    3639
     
    4144    }
    4245    public SubScopesCounter() {
    43       Parameters.Add(new LookupParameter<IntValue>("Value", "The value that should be incremented by the number of direct sub-scopes. It will be created in the current scope if the value is not found."));
     46      Parameters.Add(new LookupParameter<IntValue>("Value", "The value that should be incremented by the number of direct sub-scopes. It will be created in the current scope if the value is not found. If Accumulate is set to false, the number of direct sub-scopes is assigned and not accumulated."));
     47      Parameters.Add(new ValueParameter<BoolValue>("Accumulate", "True if the number of direct sub-scopes should be accumulated, false if the number should be assigned.", new BoolValue(true)));
     48    }
     49
     50    [StorableHook(HookType.AfterDeserialization)]
     51    private void AfterDeserialization() {
     52      // BackwardsCompatibility3.3
     53      #region Backwards compatible code, remove with 3.4
     54      if (!Parameters.ContainsKey("Accumulate"))
     55        Parameters.Add(new ValueParameter<BoolValue>("Accumulate", "True if the number of direct sub-scopes should be accumulated, false if the number should be assigned.", new BoolValue(true)));
     56      #endregion
    4457    }
    4558
     
    4962
    5063    public override IOperation Apply() {
    51       int increment = ExecutionContext.Scope.SubScopes.Count;
     64      int count = ExecutionContext.Scope.SubScopes.Count;
    5265      if (ValueParameter.ActualValue == null) ValueParameter.ActualValue = new IntValue();
    53       ValueParameter.ActualValue.Value += increment;
     66      if (AccumulateParameter.Value.Value) ValueParameter.ActualValue.Value += count;
     67      else ValueParameter.ActualValue.Value = count;
    5468      return base.Apply();
    5569    }
Note: See TracChangeset for help on using the changeset viewer.