1 | using System;
|
---|
2 | using HeuristicLab.Common;
|
---|
3 | using HeuristicLab.Core;
|
---|
4 | using HeuristicLab.Data;
|
---|
5 | using HeuristicLab.Encodings.BinaryVectorEncoding;
|
---|
6 | using HeuristicLab.Optimization;
|
---|
7 | using HeuristicLab.Parameters;
|
---|
8 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
9 |
|
---|
10 | namespace 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 | }
|
---|