Ignore:
Timestamp:
05/04/19 08:22:42 (14 months ago)
Author:
gkronber
Message:

#2925 merged r16661:16890 from trunk to branch

Location:
branches/2925_AutoDiffForDynamicalModels
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • branches/2925_AutoDiffForDynamicalModels

  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Optimization

  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Optimization/3.3/BasicProblems/BasicProblem.cs

    r16662 r16892  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HEAL.Attic;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
     28using HeuristicLab.Data;
    2729using HeuristicLab.Parameters;
    28 using HEAL.Attic;
    2930
    3031namespace HeuristicLab.Optimization {
     
    157158      OnOperatorsChanged();
    158159    }
     160
     161    protected override IEnumerable<KeyValuePair<string, IItem>> GetCollectedValues(IValueParameter param) {
     162      if (param.Value == null) yield break;
     163      if (param.GetsCollected) {
     164        if (param == EncodingParameter) // store only the name of the encoding
     165          yield return new KeyValuePair<string, IItem>(String.Empty, new StringValue(EncodingParameter.Value.Name));
     166        else yield return new KeyValuePair<string, IItem>(String.Empty, param.Value);
     167      }
     168      var parameterizedItem = param.Value as IParameterizedItem;
     169      if (parameterizedItem != null) {
     170        var children = new Dictionary<string, IItem>();
     171        parameterizedItem.CollectParameterValues(children);
     172        foreach (var child in children) yield return child;
     173      }
     174    }
    159175  }
    160176}
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Optimization/3.3/BasicProblems/Encoding.cs

    r16665 r16892  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HEAL.Attic;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Parameters;
    28 using HEAL.Attic;
    2929
    3030namespace HeuristicLab.Optimization {
     
    9292    protected Encoding(string name)
    9393      : base(name) {
    94       Parameters.Add(new FixedValueParameter<ReadOnlyItemSet<IOperator>>(name + ".Operators", "The operators that the encoding specifies.", encodingOperators.AsReadOnly()));
     94      Parameters.Add(new FixedValueParameter<ReadOnlyItemSet<IOperator>>(name + ".Operators", "The operators that the encoding specifies.", encodingOperators.AsReadOnly()) {
     95        GetsCollected = false
     96      });
    9597    }
    9698
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Optimization/3.3/BasicProblems/MultiObjectiveBasicProblem.cs

    r16662 r16892  
    2121
    2222using System.Linq;
     23using HEAL.Attic;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.Data;
    2627using HeuristicLab.Parameters;
    27 using HEAL.Attic;
    2828
    2929namespace HeuristicLab.Optimization {
     
    5959   
    6060    protected override void OnOperatorsChanged() {
    61       base.OnOperatorsChanged();
    6261      if (Encoding != null) {
    6362        PruneSingleObjectiveOperators(Encoding);
     
    6968        }
    7069      }
     70      base.OnOperatorsChanged();
    7171    }
    7272
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Optimization/3.3/BasicProblems/Operators/MultiEncodingCreator.cs

    r16662 r16892  
    2222using System;
    2323using System.Linq;
     24using HEAL.Attic;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    26 using HEAL.Attic;
     27using HeuristicLab.Parameters;
    2728
    2829namespace HeuristicLab.Optimization {
    2930  [Item("MultiEncodingCreator", "Contains solution creators that together create a multi-encoding.")]
    3031  [StorableType("E261B506-6F74-4BC4-8164-5ACE20FBC319")]
    31   public sealed class MultiEncodingCreator : MultiEncodingOperator<ISolutionCreator>, ISolutionCreator {
     32  public sealed class MultiEncodingCreator : MultiEncodingOperator<ISolutionCreator>, ISolutionCreator, IStochasticOperator {
     33    public ILookupParameter<IRandom> RandomParameter {
     34      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
     35    }
     36
     37    public override string OperatorPrefix => "Creator";
     38
    3239    [StorableConstructor]
    3340    private MultiEncodingCreator(StorableConstructorFlag _) : base(_) { }
    3441
    3542    private MultiEncodingCreator(MultiEncodingCreator original, Cloner cloner) : base(original, cloner) { }
    36     public MultiEncodingCreator() { }
     43    public MultiEncodingCreator() {
     44      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator used by the individual operators."));
     45    }
    3746
    3847    public override IDeepCloneable Clone(Cloner cloner) {
    3948      return new MultiEncodingCreator(this, cloner);
     49    }
     50
     51    [StorableHook(HookType.AfterDeserialization)]
     52    private void AfterDeserialization() {
     53      if (!Parameters.ContainsKey("Random")) {
     54        Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator used by the individual operators."));
     55      }
    4056    }
    4157
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Optimization/3.3/BasicProblems/Operators/MultiEncodingCrossover.cs

    r16662 r16892  
    2020#endregion
    2121
     22using HEAL.Attic;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    24 using HEAL.Attic;
     25using HeuristicLab.Parameters;
    2526
    2627namespace HeuristicLab.Optimization {
    2728  [Item("MultiEncoding Crossover", "Applies different crossovers to cross a multi-encoding.")]
    2829  [StorableType("BB0A04E2-899D-460C-82A2-5E4CEEDE8996")]
    29   public sealed class MultiEncodingCrossover : MultiEncodingOperator<ICrossover>, ICrossover {
     30  public sealed class MultiEncodingCrossover : MultiEncodingOperator<ICrossover>, ICrossover, IStochasticOperator {
     31    public ILookupParameter<IRandom> RandomParameter {
     32      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
     33    }
     34
     35    public override string OperatorPrefix => "Crossover";
     36
    3037    [StorableConstructor]
    3138    private MultiEncodingCrossover(StorableConstructorFlag _) : base(_) { }
    3239    private MultiEncodingCrossover(MultiEncodingCrossover original, Cloner cloner) : base(original, cloner) { }
    33     public MultiEncodingCrossover() { }
     40    public MultiEncodingCrossover() {
     41      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator used by the individual operators."));
     42    }
    3443
    3544    public override IDeepCloneable Clone(Cloner cloner) { return new MultiEncodingCrossover(this, cloner); }
     45
     46    [StorableHook(HookType.AfterDeserialization)]
     47    private void AfterDeserialization() {
     48      if (!Parameters.ContainsKey("Random")) {
     49        Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator used by the individual operators."));
     50      }
     51    }
    3652  }
    3753}
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Optimization/3.3/BasicProblems/Operators/MultiEncodingManipulator.cs

    r16662 r16892  
    2020#endregion
    2121
     22using HEAL.Attic;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    24 using HEAL.Attic;
     25using HeuristicLab.Parameters;
    2526
    2627namespace HeuristicLab.Optimization {
    2728  [Item("MultiEncoding Manipulator", "Applies different manipulators to change a multi-encoding.")]
    2829  [StorableType("574D0530-47E8-4FD9-8AC8-B8EA2DE3C203")]
    29   public sealed class MultiEncodingManipulator : MultiEncodingOperator<IManipulator>, IManipulator {
     30  public sealed class MultiEncodingManipulator : MultiEncodingOperator<IManipulator>, IManipulator, IStochasticOperator {
     31    public ILookupParameter<IRandom> RandomParameter {
     32      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
     33    }
     34
     35    public override string OperatorPrefix => "Manipulator";
     36
    3037    [StorableConstructor]
    3138    private MultiEncodingManipulator(StorableConstructorFlag _) : base(_) { }
    3239    private MultiEncodingManipulator(MultiEncodingManipulator original, Cloner cloner)
    3340      : base(original, cloner) { }
    34     public MultiEncodingManipulator() { }
     41    public MultiEncodingManipulator() {
     42      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator used by the individual operators."));
     43    }
    3544
    3645    public override IDeepCloneable Clone(Cloner cloner) { return new MultiEncodingManipulator(this, cloner); }
    3746
     47    [StorableHook(HookType.AfterDeserialization)]
     48    private void AfterDeserialization() {
     49      if (!Parameters.ContainsKey("Random")) {
     50        Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator used by the individual operators."));
     51      }
     52    }
     53
    3854  }
    3955}
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Optimization/3.3/BasicProblems/Operators/MultiEncodingOperator.cs

    r16662 r16892  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HEAL.Attic;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Operators;
    2829using HeuristicLab.Parameters;
    29 using HEAL.Attic;
    3030
    3131namespace HeuristicLab.Optimization {
     
    3939    }
    4040
     41    public abstract string OperatorPrefix { get; }
     42
    4143    [StorableConstructor]
    42     protected MultiEncodingOperator(StorableConstructorFlag _) : base(_) {
    43     }
    44 
     44    protected MultiEncodingOperator(StorableConstructorFlag _) : base(_) { }
    4545    protected MultiEncodingOperator(MultiEncodingOperator<T> original, Cloner cloner)
    4646      : base(original, cloner) {
     
    4949        encoding.OperatorsChanged += Encoding_OperatorsChanged;
    5050    }
    51 
    5251    protected MultiEncodingOperator() : base() { }
    5352
    5453    [StorableHook(HookType.AfterDeserialization)]
    5554    private void AfterDeserialization() {
    56       foreach (var encoding in encodings)
     55      foreach (var encoding in encodings) {
     56        // BackwardsCompatibility3.3
     57        #region Backwards compatible code, remove with 3.4
     58        if (Parameters.ContainsKey(encoding.Name) && !Parameters.ContainsKey(OperatorPrefix + "." + encoding.Name)) {
     59          var oldParam = (IConstrainedValueParameter<T>)Parameters[encoding.Name];
     60          var selected = oldParam.Value;
     61          Parameters.Remove(oldParam);
     62          var newParam = new ConstrainedValueParameter<T>(OperatorPrefix + "." + encoding.Name, new ItemSet<T>(oldParam.ValidValues));
     63          newParam.Value = selected;
     64          Parameters.Add(newParam);
     65          oldParam.ValidValues.Clear();
     66        }
     67        #endregion
    5768        encoding.OperatorsChanged += Encoding_OperatorsChanged;
     69      }
    5870    }
    5971
    60 
    6172    public override IOperation Apply() {
    62       var operations = Parameters.Select(p => p.ActualValue).OfType<IOperator>().Select(op => ExecutionContext.CreateOperation(op));
     73      var operations = Parameters.Select(p => p.ActualValue).OfType<IOperator>().Select(op => ExecutionContext.CreateChildOperation(op));
    6374      return new OperationCollection(operations);
    6475    }
    6576
    6677    public virtual void AddEncoding(IEncoding encoding) {
    67       if (Parameters.ContainsKey(encoding.Name)) throw new ArgumentException(string.Format("Encoding {0} was already added.", encoding.Name));
     78      if (Parameters.ContainsKey(OperatorPrefix + "." + encoding.Name)) throw new ArgumentException(string.Format("Encoding {0} was already added.", encoding.Name));
    6879
    6980      encodings.Add(encoding);
    7081      encoding.OperatorsChanged += Encoding_OperatorsChanged;
    7182
    72       var param = new ConstrainedValueParameter<T>(encoding.Name, new ItemSet<T>(encoding.Operators.OfType<T>()));
     83      var param = new ConstrainedValueParameter<T>(OperatorPrefix + "." + encoding.Name, new ItemSet<T>(encoding.Operators.OfType<T>()));
    7384      param.Value = param.ValidValues.First();
    7485      Parameters.Add(param);
     
    7889      if (!encodings.Remove(encoding)) throw new ArgumentException(string.Format("Encoding {0} was not added to the MultiEncoding.", encoding.Name));
    7990      encoding.OperatorsChanged -= Encoding_OperatorsChanged;
    80       return Parameters.Remove(encoding.Name);
     91      return Parameters.Remove(OperatorPrefix + "." + encoding.Name);
    8192    }
    8293
    8394    protected IConstrainedValueParameter<T> GetParameter(IEncoding encoding) {
    84       if (!Parameters.ContainsKey(encoding.Name)) throw new ArgumentException(string.Format("Encoding {0} was not added to the MultiEncoding.", encoding.Name));
     95      if (!Parameters.ContainsKey(OperatorPrefix + "." + encoding.Name)) throw new ArgumentException(string.Format("Encoding {0} was not added to the MultiEncoding.", encoding.Name));
    8596
    86       return (IConstrainedValueParameter<T>)Parameters[encoding.Name];
     97      return (IConstrainedValueParameter<T>)Parameters[OperatorPrefix + "." + encoding.Name];
    8798    }
    8899
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveBasicProblem.cs

    r16662 r16892  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HEAL.Attic;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Data;
    2829using HeuristicLab.Parameters;
    29 using HEAL.Attic;
    3030
    3131namespace HeuristicLab.Optimization {
     
    9595
    9696    protected override void OnOperatorsChanged() {
    97       base.OnOperatorsChanged();
    9897      if (Encoding != null) {
    9998        PruneMultiObjectiveOperators(Encoding);
     
    105104        }
    106105      }
     106      base.OnOperatorsChanged();
    107107    }
    108108
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Optimization/3.3/MetaOptimizers/BatchRun.cs

    r16662 r16892  
    112112    // BackwardsCompatibility3.3
    113113    #region Backwards compatible code (remove with 3.4)
    114     [Storable(AllowOneWay = true)]
     114    [Storable(OldName = "algorithm")]
    115115    private IAlgorithm algorithm {
    116116      set { optimizer = value; }
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Optimization/3.3/Problems/Problem.cs

    r16662 r16892  
    2323using System.Collections.Generic;
    2424using System.Drawing;
     25using HEAL.Attic;
    2526using HeuristicLab.Collections;
    2627using HeuristicLab.Common;
     
    2829using HeuristicLab.Data;
    2930using HeuristicLab.Parameters;
    30 using HEAL.Attic;
    3131
    3232namespace HeuristicLab.Optimization {
     
    5252    protected Problem()
    5353      : base() {
    54       Parameters.Add(new FixedValueParameter<ItemCollection<IItem>>(OperatorsParameterName, "The operators and items that the problem provides to the algorithms.", new ItemCollection<IItem>(), false));
     54      Parameters.Add(new FixedValueParameter<ItemCollection<IItem>>(OperatorsParameterName, "The operators and items that the problem provides to the algorithms.", new ItemCollection<IItem>()) { GetsCollected = false });
    5555      OperatorsParameter.Hidden = true;
    5656      RegisterEventHandlers();
     
    6666        if (operators != null) {
    6767          Parameters.Remove(OperatorsParameterName);
    68           Parameters.Add(new FixedValueParameter<ItemCollection<IItem>>(OperatorsParameterName, "The operators and items that the problem provides to the algorithms.", new ItemCollection<IItem>(operators), false));
     68          Parameters.Add(new FixedValueParameter<ItemCollection<IItem>>(OperatorsParameterName, "The operators and items that the problem provides to the algorithms.", new ItemCollection<IItem>(operators)) { GetsCollected = false });
    6969          OperatorsParameter.Hidden = true;
    7070        }
     
    8484    // BackwardsCompatibility3.3
    8585    #region Backwards compatible code, remove with 3.4
    86     [Storable(Name = "Operators", AllowOneWay = true)]
     86    [Storable(OldName = "Operators")]
    8787    private IEnumerable<IOperator> StorableOperators {
    8888      set {
     
    9595        //necessary to convert old experiments files where no parameter was used for saving the operators
    9696        if (!Parameters.ContainsKey(OperatorsParameterName)) {
    97           Parameters.Add(new FixedValueParameter<ItemCollection<IItem>>(OperatorsParameterName, "The operators and items that the problem provides to the algorithms.", new ItemCollection<IItem>(), false));
     97          Parameters.Add(new FixedValueParameter<ItemCollection<IItem>>(OperatorsParameterName, "The operators and items that the problem provides to the algorithms.", new ItemCollection<IItem>()) { GetsCollected = false });
    9898          OperatorsParameter.Hidden = true;
    9999        }
     
    107107        #region Backwards compatible code, remove with 3.4
    108108        if (!Parameters.ContainsKey(OperatorsParameterName)) {
    109           Parameters.Add(new FixedValueParameter<ItemCollection<IItem>>(OperatorsParameterName, "The operators and items that the problem provides to the algorithms.", new ItemCollection<IItem>(), false));
     109          Parameters.Add(new FixedValueParameter<ItemCollection<IItem>>(OperatorsParameterName, "The operators and items that the problem provides to the algorithms.", new ItemCollection<IItem>()) { GetsCollected = false });
    110110          OperatorsParameter.Hidden = true;
    111111        }
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Optimization/3.3/Problems/UserDefinedProblem.cs

    r16662 r16892  
    2525using System.Linq;
    2626using System.Threading;
     27using HEAL.Attic;
    2728using HeuristicLab.Collections;
    2829using HeuristicLab.Common;
     
    3031using HeuristicLab.Data;
    3132using HeuristicLab.Parameters;
    32 using HEAL.Attic;
    3333using HeuristicLab.PluginInfrastructure;
    3434
     
    130130        ItemList<IOperator> tmp = ((ValueParameter<ItemList<IOperator>>)Parameters["Operators"]).Value;
    131131        Parameters.Remove("Operators");
    132         Parameters.Add(new ValueParameter<ItemList<IItem>>("Operators", "The operators and items that the problem provides to the algorithms.", new ItemList<IItem>(tmp), false));
     132        Parameters.Add(new ValueParameter<ItemList<IItem>>("Operators", "The operators and items that the problem provides to the algorithms.", new ItemList<IItem>(tmp)) { GetsCollected = false });
    133133      }
    134134      #endregion
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Optimization/3.3/RunCollection.cs

    r16662 r16892  
    125125    // BackwardsCompatibility3.3
    126126    #region Backwards compatible code, remove with 3.4
    127     [Storable(AllowOneWay = true)]
     127    [Storable(OldName = "AlgorithmName")]
    128128    private string AlgorithmName {
    129129      set { optimizerName = value; }
Note: See TracChangeset for help on using the changeset viewer.