Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/17/19 16:03:57 (6 years ago)
Author:
mkommend
Message:

#2521: Merged trunk changes and adapted programmable problem templates for combined solutions.

Location:
branches/2521_ProblemRefactoring
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring

  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization

  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/MultiObjectiveProblem.cs

    r16751 r16801  
    6464
    6565    protected override void OnOperatorsChanged() {
    66       base.OnOperatorsChanged();
    6766      if (Encoding != null) {
    6867        PruneSingleObjectiveOperators(Encoding);
     
    7473        }
    7574      }
     75      base.OnOperatorsChanged();
    7676    }
    7777
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/MultiEncodingCreator.cs

    r16753 r16801  
    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   internal sealed class MultiEncodingCreator : MultiEncodingOperator<ISolutionCreator>, ISolutionCreator<CombinedSolution> {
     32  internal sealed class MultiEncodingCreator : MultiEncodingOperator<ISolutionCreator>, ISolutionCreator<CombinedSolution>, IStochasticOperator {
     33    public ILookupParameter<IRandom> RandomParameter {
     34      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
     35    }
     36
     37    public override string OperatorPrefix => "Creator";
    3238
    3339    [StorableConstructor]
    3440    private MultiEncodingCreator(StorableConstructorFlag _) : base(_) { }
    3541    private MultiEncodingCreator(MultiEncodingCreator original, Cloner cloner) : base(original, cloner) { }
    36     public MultiEncodingCreator() : base() { }
     42    public MultiEncodingCreator() : base(){
     43      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator used by the individual operators."));
     44    }
    3745
    3846    public override IDeepCloneable Clone(Cloner cloner) {
    3947      return new MultiEncodingCreator(this, cloner);
     48    }
     49
     50    [StorableHook(HookType.AfterDeserialization)]
     51    private void AfterDeserialization() {
     52      if (!Parameters.ContainsKey("Random")) {
     53        Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator used by the individual operators."));
     54      }
    4055    }
    4156
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/MultiEncodingCrossover.cs

    r16753 r16801  
    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   internal sealed class MultiEncodingCrossover : MultiEncodingOperator<ICrossover>, ICrossover {
     30  internal 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";
    3036
    3137    [StorableConstructor]
    3238    private MultiEncodingCrossover(StorableConstructorFlag _) : base(_) { }
    3339    private MultiEncodingCrossover(MultiEncodingCrossover original, Cloner cloner) : base(original, cloner) { }
    34     public MultiEncodingCrossover() : base() { }
     40    public MultiEncodingCrossover() : base() {
     41      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator used by the individual operators."));
     42    }
    3543
    3644    public override IDeepCloneable Clone(Cloner cloner) { return new MultiEncodingCrossover(this, cloner); }
    3745
     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    }
    3852
    3953    public override IOperation InstrumentedApply() {
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/MultiEncodingManipulator.cs

    r16753 r16801  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
     25using HeuristicLab.Parameters;
    2526
    2627namespace HeuristicLab.Optimization {
     
    2829  [StorableType("574D0530-47E8-4FD9-8AC8-B8EA2DE3C203")]
    2930  internal sealed class MultiEncodingManipulator : MultiEncodingOperator<IManipulator>, IManipulator {
     31    public ILookupParameter<IRandom> RandomParameter {
     32      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
     33    }
     34
     35    public override string OperatorPrefix => "Manipulator";
    3036    [StorableConstructor]
    3137    private MultiEncodingManipulator(StorableConstructorFlag _) : base(_) { }
    3238    private MultiEncodingManipulator(MultiEncodingManipulator original, Cloner cloner) : base(original, cloner) { }
    33     public MultiEncodingManipulator() : base() { }
     39
     40    public MultiEncodingManipulator() : base() {
     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 MultiEncodingManipulator(this, cloner); }
    3645
     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    }
     52
    3753  }
    3854}
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/MultiEncodingOperator.cs

    r16753 r16801  
    2222using System;
    2323using System.Linq;
     24using HEAL.Attic;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    2627using HeuristicLab.Operators;
    2728using HeuristicLab.Parameters;
    28 using HEAL.Attic;
    2929
    3030namespace HeuristicLab.Optimization {
     
    3939    }
    4040
     41    public abstract string OperatorPrefix { get; }
     42
    4143    [StorableConstructor]
    4244    protected MultiEncodingOperator(StorableConstructorFlag _) : base(_) { }
     
    4951
    5052    public override IOperation InstrumentedApply() {
    51       var operations = Parameters.Select(p => p.ActualValue).OfType<IOperator>().Select(op => ExecutionContext.CreateOperation(op));
     53      var operations = Parameters.Select(p => p.ActualValue).OfType<IOperator>().Select(op => ExecutionContext.CreateChildOperation(op));
    5254      return new OperationCollection(operations);
    5355    }
    5456
    5557    public virtual void AddEncoding(IEncoding encoding) {
    56       if (Parameters.ContainsKey(encoding.Name)) throw new ArgumentException(string.Format("Encoding {0} was already added.", encoding.Name));
     58      if (Parameters.ContainsKey(OperatorPrefix + "." + encoding.Name)) throw new ArgumentException(string.Format("Encoding {0} was already added.", encoding.Name));
    5759
    5860      encoding.OperatorsChanged += Encoding_OperatorsChanged;
    5961
    60       var param = new ConstrainedValueParameter<T>(encoding.Name, new ItemSet<T>(encoding.Operators.OfType<T>()));
     62      var param = new ConstrainedValueParameter<T>(OperatorPrefix + "." + encoding.Name, new ItemSet<T>(encoding.Operators.OfType<T>()));
    6163      param.Value = param.ValidValues.First();
    6264      Parameters.Add(param);
     
    6668      if (!Parameters.ContainsKey(encoding.Name)) throw new ArgumentException(string.Format("Encoding {0} was not added to the MultiEncoding.", encoding.Name));
    6769      encoding.OperatorsChanged -= Encoding_OperatorsChanged;
    68       return Parameters.Remove(encoding.Name);
     70      return Parameters.Remove(OperatorPrefix + "." + encoding.Name);
    6971    }
    7072
    7173    protected IConstrainedValueParameter<T> GetParameter(IEncoding encoding) {
    72       if (!Parameters.ContainsKey(encoding.Name)) throw new ArgumentException(string.Format("Encoding {0} was not added to the MultiEncoding.", encoding.Name));
     74      if (!Parameters.ContainsKey(OperatorPrefix + "." + encoding.Name)) throw new ArgumentException(string.Format("Encoding {0} was not added to the MultiEncoding.", encoding.Name));
    7375
    74       return (IConstrainedValueParameter<T>)Parameters[encoding.Name];
     76      return (IConstrainedValueParameter<T>)Parameters[OperatorPrefix + "." + encoding.Name];
    7577    }
    7678
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveProblem.cs

    r16751 r16801  
    125125
    126126    protected override void OnOperatorsChanged() {
    127       base.OnOperatorsChanged();
    128127      if (Encoding != null) {
    129128        PruneMultiObjectiveOperators(Encoding);
     
    135134        }
    136135      }
     136      base.OnOperatorsChanged();
    137137    }
    138138
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/MetaOptimizers/BatchRun.cs

    r16724 r16801  
    112112    // BackwardsCompatibility3.3
    113113    #region Backwards compatible code (remove with 3.4)
    114     [Storable(Name ="algorithm")]
     114    [Storable(OldName = "algorithm")]
    115115    private IAlgorithm algorithm {
    116116      set { optimizer = value; }
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems/Problem.cs

    r16724 r16801  
    8484    // BackwardsCompatibility3.3
    8585    #region Backwards compatible code, remove with 3.4
    86     [Storable(Name = "Operators")]
     86    [Storable(OldName = "Operators")]
    8787    private IEnumerable<IOperator> StorableOperators {
    8888      set {
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/RunCollection.cs

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