Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/LayerCreator.cs @ 11813

Last change on this file since 11813 was 11609, checked in by pfleck, 10 years ago

#2269

  • Fixed Bugs with Per-Layer-Results.
  • Fixed Bugs in EldersSelector.
  • Added LayerCreator instead of LastSubScopeCloner for avoiding operators for some temporary hacks.
File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Analysis;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Data;
29using HeuristicLab.Operators;
30using HeuristicLab.Parameters;
31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
32
33namespace HeuristicLab.Algorithms.ALPS {
34  [Item("LayerCreator", "An operator which creates a new layer by cloning the oldest one and setting the variables accordingly.")]
35  [StorableClass]
36  public sealed class LayerCreator : SingleSuccessorOperator {
37
38    /*private static readonly ISet<string> SavedVariables = new HashSet<string>{
39      "LocalRandom", "Layer", "LayerEvaluatedSolutions", "NumSubScopes"
40    };*/
41
42    private ILookupParameter<IntValue> OpenLayersParameter {
43      get { return (ILookupParameter<IntValue>)Parameters["OpenLayers"]; }
44    }
45
46    [StorableConstructor]
47    private LayerCreator(bool deserializing) : base(deserializing) { }
48
49    private LayerCreator(LayerCreator original, Cloner cloner)
50      : base(original, cloner) {
51    }
52    public LayerCreator()
53      : base() {
54      Parameters.Add(new LookupParameter<IntValue>("OpenLayers"));
55    }
56
57    public override IDeepCloneable Clone(Cloner cloner) {
58      return new LayerCreator(this, cloner);
59    }
60
61    public override IOperation Apply() {
62      var scopes = ExecutionContext.Scope.SubScopes;
63      if (scopes.Count < 1)
64        throw new ArgumentException("At least one sub-scope must exist.");
65
66      var lastSubScope = scopes.Last();
67      var clone = (IScope)lastSubScope.Clone(new Cloner());
68
69      int number;
70      if (int.TryParse(clone.Name, out number))
71        clone.Name = (number + 1).ToString();
72
73      scopes.Add(clone);
74
75      clone.Variables["Layer"].Value = new IntValue(OpenLayersParameter.ActualValue.Value);
76      foreach (var solution in clone.SubScopes)
77        ((IntValue)solution.Variables["Age"].Value).Value -= 1; // Decrement age, because MainOperator is goint to increment it
78      //foreach (var variable in clone.Variables.Where(v => !SavedVariables.Contains(v.Name)))
79      //  variable.Value = null;
80
81      //HACK: delete old values from quality table
82      /*var rows = ((DataTable)clone.Variables["Qualities"].Value).Rows;
83      var last = rows.Last();
84      rows.Clear();
85      rows.Add(last);*/
86
87      return base.Apply();
88    }
89
90  }
91}
Note: See TracBrowser for help on using the repository browser.