Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OptimizationNetworks/HeuristicLab.Networks/3.3/FeatureSelection Network/SelectionProblem.cs @ 12323

Last change on this file since 12323 was 12323, checked in by mkommend, 10 years ago

#2205: Added simple optimization network for solving features selection problems.

File size: 1.5 KB
Line 
1using System;
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Data;
5using HeuristicLab.Encodings.BinaryVectorEncoding;
6using HeuristicLab.Optimization;
7using HeuristicLab.Parameters;
8using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9
10namespace HeuristicLab.Networks.FeatureSelection_Network {
11  public class SelectionProblem : SingleObjectiveBasicProblem<BinaryVectorEncoding> {
12    private Func<BinaryVector, double> eval;
13
14    public virtual int Length {
15      get { return Encoding.Length; }
16      set { Encoding.Length = value; }
17    }
18
19    protected SelectionProblem(SelectionProblem original, Cloner cloner)
20      : base(original, cloner) {
21    }
22    [StorableConstructor]
23    protected SelectionProblem(bool deserializing) : base(deserializing) { }
24
25    public SelectionProblem(Func<BinaryVector, double> eval, bool maximization)
26      : base() {
27      this.maximization = maximization;
28      this.eval = eval;
29
30
31      var lengthParam = new ValueParameter<IntValue>("Length");
32      lengthParam.ValueChanged += (o, s) => { Length = lengthParam.Value.Value; };
33      Parameters.Add(lengthParam);
34    }
35
36    public override IDeepCloneable Clone(Cloner cloner) {
37      return new SelectionProblem(this, cloner);
38    }
39
40    public override double Evaluate(Individual individual, IRandom random) {
41      return eval(individual.BinaryVector());
42    }
43
44    private readonly bool maximization;
45    public override bool Maximization {
46      get { return maximization; }
47    }
48  }
49}
Note: See TracBrowser for help on using the repository browser.