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 | using HeuristicLab.Problems.Binary;
|
---|
10 |
|
---|
11 | namespace HeuristicLab.Networks.FeatureSelection_Network {
|
---|
12 | public class SelectionProblem : BinaryProblem {
|
---|
13 | private Func<BinaryVector, double> eval;
|
---|
14 |
|
---|
15 | protected SelectionProblem(SelectionProblem original, Cloner cloner)
|
---|
16 | : base(original, cloner) {
|
---|
17 | }
|
---|
18 | [StorableConstructor]
|
---|
19 | protected SelectionProblem(bool deserializing) : base(deserializing) { }
|
---|
20 |
|
---|
21 | public SelectionProblem(Func<BinaryVector, double> eval, bool maximization)
|
---|
22 | : base() {
|
---|
23 | this.maximization = maximization;
|
---|
24 | this.eval = eval;
|
---|
25 |
|
---|
26 |
|
---|
27 | var lengthParam = new ValueParameter<IntValue>("Length");
|
---|
28 |
|
---|
29 |
|
---|
30 | lengthParam.ValueChanged += (o, s) => { Length = lengthParam.Value.Value; };
|
---|
31 | // we cannot use the fixed value parameter from BinaryProblem in the network
|
---|
32 | Parameters.Remove("Length");
|
---|
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(BinaryVector vector, IRandom random) {
|
---|
41 | return eval(vector);
|
---|
42 |
|
---|
43 | }
|
---|
44 |
|
---|
45 | private readonly bool maximization;
|
---|
46 | public override bool Maximization {
|
---|
47 | get { return maximization; }
|
---|
48 | }
|
---|
49 | }
|
---|
50 | }
|
---|