WSF
P6DofTunerGAManager.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 2017 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 P6DOFTUNERGAMANAGER_HPP
13#define P6DOFTUNERGAMANAGER_HPP
14
15#include "p6dof_export.h"
16
17#include <vector>
18
20#include "UtRandom.hpp"
21
22class P6DOF_EXPORT P6dofTunerGAManager
23{
24public:
26
27 void Advance(std::vector<P6DofTunerGASpecimen::PidLogElement>& aSimData);
28
29 // Set the number of specimens in each population.
30 void SetPopulationSize(size_t aPopulationSize) { mPopulationSize = aPopulationSize; }
31 size_t GetPopulationSize() const { return mPopulationSize; }
32
33 // Set total number of generations to use in optimizations.
34 void SetMaxGenerationCount(size_t aMaxGenCount) { mMaxGenerations = aMaxGenCount; }
35 size_t GetMaxGenerationCount() const { return mMaxGenerations; }
36
37 // Set the ratio of specimens in the population that will be carried over to the next generation.
38 // Value is clamped between 0.0 and 1.0. Recommend values above 0.7 to make sure that enough "fit"
39 // specimens survive into the next generation. The remaining population that is not carried over is
40 // randomly generated to expand the search area.
41 void SetCarryOverFraction(double aCarryOverFrac);
42 double GetCarryOverFraction() const { return mCarryOverFraction; }
43
44 // Sets the probability that a single "gene" in a specimen chromosome will spontaneously mutate.
45 // Value is clamped between 0.0 and 1.0. Recommend values between 0.02 and 0.1. Mutation expands
46 // search space by creating changes in existing specimens.
47 void SetMutationProbability(double aMutProb);
48 double GetMutationProbability() const { return mMutationProbability; }
49
50 // Set the probability that two specimens will be "crossed" exchanging elements of their
51 // chromosomes. Value is clamped between 0.0 and 1.0. Recommend value between 0.5 and 0.8.
52 // Crossover takes traits from 2 specimens and swaps them in an attempt to create a superior
53 // specimen.
54 void SetCrossOverProbability(double aCrossOverProb);
55 double GetCrossOverProbability() const { return mCrossOverProbability; }
56
57 // Creates population by copying parent specimen. Specimen limits are preserved,
58 // but their traits are generated by calling each specimen's Generate() method.
59 void InitializePopulation(const P6DofTunerGASpecimen& aSpecimen);
60
61 bool IsComplete() const { return mCompleted; }
62
63 P6DofTunerGASpecimen GetOptimum() const { return mOptimum; }
64
65 P6DofTunerGASpecimen& GetCurrentSpecimen() { return mPopulation[mCurrentSpecimen]; }
66
67 size_t GetProgress() const { return mCurrentSpecimen + mCurrentGeneration * mPopulationSize; }
68
69private:
70 // Chose next population based on objective values and the carry over fraction.
71 void SelectNextPopulation();
72
73 size_t mPopulationSize;
74 size_t mMaxGenerations;
75 double mCarryOverFraction;
76 double mMutationProbability;
77 double mCrossOverProbability;
78
79 size_t mCurrentSpecimen;
80 size_t mCurrentGeneration;
81
82 std::vector<P6DofTunerGASpecimen> mPopulation;
83 P6DofTunerGASpecimen mParentSpecimen;
84 P6DofTunerGASpecimen mOptimum;
85 bool mCompleted;
86 ut::Random mRandom;
87};
88
89#endif
Definition P6DofTunerGASpecimen.hpp:23
double GetCrossOverProbability() const
Definition P6DofTunerGAManager.hpp:55
P6DofTunerGASpecimen & GetCurrentSpecimen()
Definition P6DofTunerGAManager.hpp:65
double GetCarryOverFraction() const
Definition P6DofTunerGAManager.hpp:42
void SetMaxGenerationCount(size_t aMaxGenCount)
Definition P6DofTunerGAManager.hpp:34
void SetPopulationSize(size_t aPopulationSize)
Definition P6DofTunerGAManager.hpp:30
size_t GetMaxGenerationCount() const
Definition P6DofTunerGAManager.hpp:35
void Advance(std::vector< P6DofTunerGASpecimen::PidLogElement > &aSimData)
Definition P6DofTunerGAManager.cpp:26
double GetMutationProbability() const
Definition P6DofTunerGAManager.hpp:48
P6DofTunerGASpecimen GetOptimum() const
Definition P6DofTunerGAManager.hpp:63
size_t GetPopulationSize() const
Definition P6DofTunerGAManager.hpp:31
bool IsComplete() const
Definition P6DofTunerGAManager.hpp:61
P6dofTunerGAManager()
Definition P6DofTunerGAManager.cpp:14
size_t GetProgress() const
Definition P6DofTunerGAManager.hpp:67
Copyrights Multiple, All Rights Reserved