Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2645_ContextAlgorithms/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/Model2/SolutionScope.cs @ 16147

Last change on this file since 16147 was 15625, checked in by abeham, 7 years ago

#2654: implemented generic context-based genetic algorithm

File size: 1.2 KB
Line 
1using HeuristicLab.Common;
2using HeuristicLab.Core;
3using HeuristicLab.Data;
4using HeuristicLab.Optimization.Model2;
5using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
6
7namespace HeuristicLab.Algorithms.GeneticAlgorithm.Model2 {
8  [Item("GA Solution Scope", "")]
9  [StorableClass]
10  public class SolutionScope : Scope, ISolutionScope {
11
12    [Storable]
13    private Variable fitness;
14    public double Fitness {
15      get { return ((DoubleValue)fitness.Value).Value; }
16      set { ((DoubleValue)fitness.Value).Value = value; }
17    }
18
19    [StorableConstructor]
20    protected SolutionScope(bool deserializing) : base(deserializing) { }
21    protected SolutionScope(SolutionScope original, Cloner cloner)
22    : base(original, cloner) {
23      fitness = cloner.Clone(original.fitness);
24    }
25    public SolutionScope(string fitnessName) : this(fitnessName, double.NaN) { }
26    public SolutionScope(string fitnessName, double fitness) {
27      this.fitness = new Variable(fitnessName, new DoubleValue(fitness));
28      Variables.Add(this.fitness);
29    }
30
31    public override IDeepCloneable Clone(Cloner cloner) {
32      return new SolutionScope(this, cloner);
33    }
34  }
35}
Note: See TracBrowser for help on using the repository browser.