RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
RGroupGa.h
Go to the documentation of this file.
1//
2// Copyright (C) 2020 Gareth Jones, Glysade LLC
3//
4// @@ All Rights Reserved @@
5// This file is part of the RDKit.
6// The contents are covered by the terms of the BSD license
7// which is included in the file license.txt, found at the root
8// of the RDKit source tree.
9//
10
11#ifndef RGROUPDECOMPGA_H_
12#define RGROUPDECOMPGA_H_
13
14#include <vector>
15#include <memory>
16#include <map>
17#include <chrono>
18
19#include "../../../External/GA/ga/StringChromosome.h"
20#include "../../../External/GA/ga/GaBase.h"
21#include "../../../External/GA/ga/GaOperation.h"
22#include "../../../External/GA/ga/LinkedPopLinearSel.h"
23#include "../../../External/GA/ga/IntegerStringChromosomePolicy.h"
25#include "RGroupScore.h"
26
27namespace RDKit {
28
29using namespace GapeGa;
30using namespace std;
31
32class RGroupDecompositionChromosome;
33class RGroupGa;
34struct RGroupDecompData;
35
38
39typedef enum {
41 Crossover = 0x02,
42 Create = 0x04,
44
45class RGroupDecompositionChromosome : public IntegerStringChromosome {
46 public:
48
49 double getFitness() const { return fitness; }
50
51 OperationName getOperationName() const { return operationName; }
52
53 void setOperationName(OperationName operationName) {
54 this->operationName = operationName;
55 }
56
57 std::string info() const;
58
59 double score();
60
62
63 bool isOk() { return true; }
64
65 void decode();
66
67 void copyGene(const StringChromosomeBase &other) override;
68
70 return fingerprintVarianceScoreData;
71 }
72
73 const vector<size_t> &getPermutation() const { return permutation; }
74
75 const RGroupGa &getRGroupGA() const { return rGroupGa; }
76
77 private:
79 delete;
81 const RGroupDecompositionChromosome &other) = delete;
82 double fitness;
83 FingerprintVarianceScoreData fingerprintVarianceScoreData;
84 OperationName operationName = Create;
85 vector<size_t> permutation;
86
87 RGroupGa &rGroupGa;
88};
89
90struct GaResult {
92
93 GaResult(const double score, const vector<vector<size_t>> &permutations)
96
98
99 // Copy constructor required by MSVC for future<GaResult>
101};
102
104 public:
105 RGroupGa(const RGroupDecompData &rGroupData,
106 const chrono::steady_clock::time_point *const t0 = nullptr);
107
108 IntegerStringChromosomePolicy &getChromosomePolicy() {
109 return chromosomePolicy;
110 }
111
112 int chromosomeLength() const { return chromLength; }
113
114 int numberDecompositions() const { return numberDecomps; }
115
116 GaResult run(int runNumber = 1);
117
118 vector<GaResult> runBatch();
119
120 shared_ptr<RGroupDecompositionChromosome> createChromosome();
121
122 const RGroupDecompData &getRGroupData() const { return rGroupData; }
123
124 const vector<shared_ptr<GaOperation<RGroupDecompositionChromosome>>>
126
127 unsigned int numberPermutations() const { return numPermutations; }
128
129 private:
130 RGroupGa(const RGroupGa &other) = delete;
131 RGroupGa &operator=(const RGroupGa &other) = delete;
132 const RGroupDecompData &rGroupData;
133
134 IntegerStringChromosomePolicy chromosomePolicy;
135 int numberOperations;
136 int numberOperationsWithoutImprovement;
137 int chromLength;
138 unsigned int numPermutations;
139 int numberDecomps;
140 const chrono::steady_clock::time_point *const t0;
141
142 void createOperations();
143
144 static void rGroupMutateOperation(
145 const std::vector<std::shared_ptr<RGroupDecompositionChromosome>>
146 &parents,
147 std::vector<std::shared_ptr<RGroupDecompositionChromosome>> &children);
148 static void rGroupCrossoverOperation(
149 const std::vector<std::shared_ptr<RGroupDecompositionChromosome>>
150 &parents,
151 std::vector<std::shared_ptr<RGroupDecompositionChromosome>> &children);
152};
153
156
158 FingerprintVarianceScoreData &fingerprintVarianceScoreData);
159
160} // namespace RDKit
161
162#endif // RGROUPDECOMPGA_H_
const vector< size_t > & getPermutation() const
Definition RGroupGa.h:73
RGroupDecompositionChromosome(RGroupGa &rGroupGa)
OperationName getOperationName() const
Definition RGroupGa.h:51
void setOperationName(OperationName operationName)
Definition RGroupGa.h:53
const RGroupGa & getRGroupGA() const
Definition RGroupGa.h:75
void copyGene(const StringChromosomeBase &other) override
FingerprintVarianceScoreData & getFingerprintVarianceScoreData()
Definition RGroupGa.h:69
IntegerStringChromosomePolicy & getChromosomePolicy()
Definition RGroupGa.h:108
vector< GaResult > runBatch()
const RGroupDecompData & getRGroupData() const
Definition RGroupGa.h:122
int chromosomeLength() const
Definition RGroupGa.h:112
const vector< shared_ptr< GaOperation< RGroupDecompositionChromosome > > > getOperations() const
int numberDecompositions() const
Definition RGroupGa.h:114
shared_ptr< RGroupDecompositionChromosome > createChromosome()
RGroupGa(const RGroupDecompData &rGroupData, const chrono::steady_clock::time_point *const t0=nullptr)
GaResult run(int runNumber=1)
unsigned int numberPermutations() const
Definition RGroupGa.h:127
#define RDKIT_RGROUPDECOMPOSITION_EXPORT
Definition export.h:433
Std stuff.
bool rdvalue_is(const RDValue_cast_t)
void copyVarianceData(const FingerprintVarianceScoreData &fromData, FingerprintVarianceScoreData &toData)
OperationName
Definition RGroupGa.h:39
@ Crossover
Definition RGroupGa.h:41
@ Create
Definition RGroupGa.h:42
@ RgroupMutate
Definition RGroupGa.h:40
void clearVarianceData(FingerprintVarianceScoreData &fingerprintVarianceScoreData)
LinkedPopLinearSel< RGroupDecompositionChromosome, RGroupGa > RGroupGaPopulation
Definition RGroupGa.h:37
RGroupScorer rGroupScorer
Definition RGroupGa.h:91
GaResult & operator=(const GaResult &other)
GaResult(const double score, const vector< vector< size_t > > &permutations)
Definition RGroupGa.h:93
GaResult(const GaResult &other)
Definition RGroupGa.h:95