WSF
WsfSixDOF_TunerGAManager.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2020 Infoscitex, a DCS Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef WSFSIXDOFTUNERGAMANAGER_HPP
13#define WSFSIXDOFTUNERGAMANAGER_HPP
14
15#include "wsf_six_dof_export.h"
16
17#include <vector>
18
19#include "UtRandom.hpp"
21
22namespace wsf
23{
24namespace six_dof
25{
26class WSF_SIX_DOF_EXPORT TunerGAManager
27{
28public:
29 TunerGAManager() = default;
30
31 void Advance(std::vector<TunerGASpecimen::PidLogElement>& aSimData);
32
33 // Set the number of specimens in each population.
34 void SetPopulationSize(size_t aPopulationSize) { mPopulationSize = aPopulationSize; }
35 size_t GetPopulationSize() const { return mPopulationSize; }
36
37 // Set total number of generations to use in optimizations.
38 void SetMaxGenerationCount(size_t aMaxGenCount) { mMaxGenerations = aMaxGenCount; }
39 size_t GetMaxGenerationCount() const { return mMaxGenerations; }
40
41 // Set the ratio of specimens in the population that will be carried over to the next generation.
42 // Value is clamped between 0.0 and 1.0. Recommend values above 0.7 to make sure that enough "fit"
43 // specimens survive into the next generation. The remaining population that is not carried over is
44 // randomly generated to expand the search area.
45 void SetCarryOverFraction(double aCarryOverFrac);
46 double GetCarryOverFraction() const { return mCarryOverFraction; }
47
48 // Sets the probability that a single "gene" in a specimen chromosome will spontaneously mutate.
49 // Value is clamped between 0.0 and 1.0. Recommend values between 0.02 and 0.1. Mutation expands
50 // search space by creating changes in existing specimens.
51 void SetMutationProbability(double aMutProb);
52 double GetMutationProbability() const { return mMutationProbability; }
53
54 // Set the probability that two specimens will be "crossed" exchanging elements of their
55 // chromosomes. Value is clamped between 0.0 and 1.0. Recommend value between 0.5 and 0.8.
56 // Crossover takes traits from 2 specimens and swaps them in an attempt to create a superior
57 // specimen.
58 void SetCrossOverProbability(double aCrossOverProb);
59 double GetCrossOverProbability() const { return mCrossOverProbability; }
60
61 // Creates population by copying parent specimen. Specimen limits are preserved,
62 // but their traits are generated by calling each specimen's Generate() method.
63 void InitializePopulation(const TunerGASpecimen& aSpecimen);
64
65 bool IsComplete() const { return mCompleted; }
66
67 TunerGASpecimen GetOptimum() const { return mOptimum; }
68
69 TunerGASpecimen& GetCurrentSpecimen() { return mPopulation[mCurrentSpecimen]; }
70
71 size_t GetProgress() const { return mCurrentSpecimen + mCurrentGeneration * mPopulationSize; }
72
73private:
74 // Chose next population based on objective values and the carry over fraction.
75 void SelectNextPopulation();
76
77 size_t mPopulationSize = 25;
78 size_t mMaxGenerations = 50;
79 double mCarryOverFraction = 1.0;
80 double mMutationProbability = 0.02;
81 double mCrossOverProbability = 0.7;
82
83 size_t mCurrentSpecimen = 0;
84 size_t mCurrentGeneration = 0;
85
86 bool mCompleted = false;
87
88 std::vector<TunerGASpecimen> mPopulation;
89
90 TunerGASpecimen mParentSpecimen;
91 TunerGASpecimen mOptimum;
92
93 ut::Random mRandom;
94};
95} // namespace six_dof
96} // namespace wsf
97
98#endif
TunerGASpecimen GetOptimum() const
Definition WsfSixDOF_TunerGAManager.hpp:67
void SetPopulationSize(size_t aPopulationSize)
Definition WsfSixDOF_TunerGAManager.hpp:34
size_t GetPopulationSize() const
Definition WsfSixDOF_TunerGAManager.hpp:35
void Advance(std::vector< TunerGASpecimen::PidLogElement > &aSimData)
Definition WsfSixDOF_TunerGAManager.cpp:14
void SetMaxGenerationCount(size_t aMaxGenCount)
Definition WsfSixDOF_TunerGAManager.hpp:38
size_t GetProgress() const
Definition WsfSixDOF_TunerGAManager.hpp:71
TunerGASpecimen & GetCurrentSpecimen()
Definition WsfSixDOF_TunerGAManager.hpp:69
double GetMutationProbability() const
Definition WsfSixDOF_TunerGAManager.hpp:52
double GetCrossOverProbability() const
Definition WsfSixDOF_TunerGAManager.hpp:59
size_t GetMaxGenerationCount() const
Definition WsfSixDOF_TunerGAManager.hpp:39
bool IsComplete() const
Definition WsfSixDOF_TunerGAManager.hpp:65
double GetCarryOverFraction() const
Definition WsfSixDOF_TunerGAManager.hpp:46
Definition WsfSixDOF_TunerGASpecimen.hpp:27
Definition WsfSA_Processor.hpp:35
Function definitions for those who need run-time access to the version.
Definition WsfComm.cpp:32
Copyrights Multiple, All Rights Reserved