1 | using System;
|
---|
2 | using System.Linq;
|
---|
3 | using HeuristicLab.Common;
|
---|
4 | using HeuristicLab.Core;
|
---|
5 | using HeuristicLab.Data;
|
---|
6 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
7 | using HeuristicLab.Optimization;
|
---|
8 | using HeuristicLab.Parameters;
|
---|
9 |
|
---|
10 | namespace HeuristicLab.Algorithms.SAPBA.Strategies {
|
---|
11 | public class IndividualStrategy : StrategyBase {
|
---|
12 | public const string SampledIndividualsParameterName = "SampledIndividals";
|
---|
13 | public IFixedValueParameter<IntValue> SampledIndividualsParameter => Parameters[SampledIndividualsParameterName] as IFixedValueParameter<IntValue>;
|
---|
14 | public IntValue SampledIndividuals => SampledIndividualsParameter.Value;
|
---|
15 |
|
---|
16 | #region Constructors
|
---|
17 | private IndividualStrategy(IndividualStrategy original, Cloner cloner) : base(original, cloner) {
|
---|
18 | }
|
---|
19 | public IndividualStrategy() {
|
---|
20 | Parameters.Add(new FixedValueParameter<IntValue>(SampledIndividualsParameterName, "The number of individuals that are sampled each generation", new IntValue(3)));
|
---|
21 | }
|
---|
22 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
23 | return new IndividualStrategy(this, cloner);
|
---|
24 | }
|
---|
25 | #endregion
|
---|
26 |
|
---|
27 | public override double Evaluate(RealVector r, IRandom random) {
|
---|
28 | return EstimateSample(r, random).Item2;
|
---|
29 | }
|
---|
30 |
|
---|
31 | protected override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, ResultCollection globalResults, IRandom random) {
|
---|
32 | }
|
---|
33 |
|
---|
34 | protected override void ProcessPopulation(Individual[] individuals, double[] qualities, IRandom random) {
|
---|
35 | var samples = individuals.Zip(qualities, (individual, d) => new Tuple<Individual, double>(individual, d)).OrderBy(t => Algorithm.Problem.Maximization ? -t.Item2 : t.Item2).Take(SampledIndividuals.Value).Select(t => t.Item1.RealVector());
|
---|
36 | foreach (var indi in samples) EvaluateSample(indi, random);
|
---|
37 | BuildRegressionSolution(random);
|
---|
38 | }
|
---|
39 |
|
---|
40 | protected override void Initialize() {
|
---|
41 | }
|
---|
42 | }
|
---|
43 | }
|
---|