Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/05/15 16:20:55 (8 years ago)
Author:
pfleck
Message:

#2269

  • Implemented full wiring of ALPS.
  • Created new AlpsGeneticAlgorithmMainOperator instead of using a modified GeneticAlgorithmMainLoop because of wiring issues.
  • Separated LayerCreator into generic LastScopeCloner and ResultsHistoryWiper.
File:
1 moved

Legend:

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

    r13123 r13124  
    2222using System;
    2323using System.Linq;
    24 using HeuristicLab.Analysis;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Core;
    27 using HeuristicLab.Data;
    2826using HeuristicLab.Operators;
    29 using HeuristicLab.Optimization;
    3027using HeuristicLab.Parameters;
    3128using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3229
    3330namespace HeuristicLab.Algorithms.ALPS {
    34   [Item("LayerCreator", "An operator which creates a new layer by cloning the current oldest one.")]
     31  [Item("LastScopeCloner", "An operator that creates a new scope by cloning the current last one.")]
    3532  [StorableClass]
    36   public sealed class LayerCreator : SingleSuccessorOperator {
    37     private ILookupParameter<IntValue> OpenLayersParameter {
    38       get { return (ILookupParameter<IntValue>)Parameters["OpenLayers"]; }
    39     }
    40     public OperatorParameter NewLayerOperatorParameter {
    41       get { return (OperatorParameter)Parameters["NewLayerOperator"]; }
     33  public sealed class LastScopeCloner : SingleSuccessorOperator {
     34    public OperatorParameter NewScopeOperatorParameter {
     35      get { return (OperatorParameter)Parameters["NewScopeOperator"]; }
    4236    }
    4337
    44     public IOperator NewLayerOperator {
    45       get { return NewLayerOperatorParameter.Value; }
    46       set { NewLayerOperatorParameter.Value = value; }
     38    public IOperator NewScopeOperator {
     39      get { return NewScopeOperatorParameter.Value; }
     40      set { NewScopeOperatorParameter.Value = value; }
    4741    }
    4842
    4943    [StorableConstructor]
    50     private LayerCreator(bool deserializing) : base(deserializing) { }
     44    private LastScopeCloner(bool deserializing) : base(deserializing) { }
    5145
    52     private LayerCreator(LayerCreator original, Cloner cloner)
     46    private LastScopeCloner(LastScopeCloner original, Cloner cloner)
    5347      : base(original, cloner) {
    5448    }
    55     public LayerCreator()
    56       : base() {
    57       Parameters.Add(new LookupParameter<IntValue>("OpenLayers"));
    58       Parameters.Add(new OperatorParameter("NewLayerOperator"));
     49    public override IDeepCloneable Clone(Cloner cloner) {
     50      return new LastScopeCloner(this, cloner);
    5951    }
    6052
    61     public override IDeepCloneable Clone(Cloner cloner) {
    62       return new LayerCreator(this, cloner);
     53    public LastScopeCloner()
     54      : base() {
     55      Parameters.Add(new OperatorParameter("NewScopeOperator", "An Operator that is performed on the new scope."));
    6356    }
    6457
    6558    public override IOperation Apply() {
    66       var layersScope = ExecutionContext.Scope.SubScopes;
    67       if (layersScope.Count < 1)
     59      var scopes = ExecutionContext.Scope.SubScopes;
     60      if (scopes.Count < 1)
    6861        throw new ArgumentException("At least one layer must exist.");
    6962
    70       var newLayer = (IScope)layersScope.Last().Clone();
     63      var newScope = (IScope)scopes.Last().Clone();
    7164
    72       int number;
    73       if (int.TryParse(newLayer.Name, out number))
    74         newLayer.Name = (number + 1).ToString();
     65      int scopeNumber;
     66      if (int.TryParse(newScope.Name, out scopeNumber))
     67        newScope.Name = (scopeNumber + 1).ToString();
    7568
    76       layersScope.Add(newLayer);
     69      scopes.Add(newScope);
    7770
    78       // Set new layer number
    79       newLayer.Variables["Layer"].Value = new IntValue(OpenLayersParameter.ActualValue.Value);
    80 
    81       // Decrement ages, because MainOperator is goint to increment it
    82       foreach (var solution in newLayer.SubScopes)
    83         ((DoubleValue)solution.Variables["Age"].Value).Value -= 1;
    84 
    85       // Reset existing values in the results to NaN to symbolize that no layer existed during that duration
    86       var results = (ResultCollection)newLayer.Variables["LayerResults"].Value;
    87       ResetResults(results);
    8871
    8972      var next = new OperationCollection(base.Apply());
    90       next.Insert(0, ExecutionContext.CreateChildOperation(NewLayerOperator, newLayer));
     73      next.Insert(0, ExecutionContext.CreateChildOperation(NewScopeOperator, newScope));
    9174      return next;
    92     }
    93 
    94     private void ResetResults(ResultCollection results) {
    95       var values = results.Select(r => r.Value);
    96 
    97       // Reset all values within results in results
    98       foreach (var resultsCollection in values.OfType<ResultCollection>())
    99         ResetResults(resultsCollection);
    100 
    101       // Reset values
    102       foreach (var dataTable in values.OfType<DataTable>()) {
    103         foreach (var row in dataTable.Rows)
    104           for (int i = 0; i < row.Values.Count; i++)
    105             row.Values[i] = double.NaN;
    106       }
    10775    }
    10876  }
Note: See TracChangeset for help on using the changeset viewer.