| 131 | } |
| 132 | |
| 133 | std::unique_ptr<GeneticAlgorithm> GeneticAlgorithmFactory::build( |
| 134 | Options const& _options, |
| 135 | size_t _populationSize |
| 136 | ) |
| 137 | { |
| 138 | assert(_populationSize > 0); |
| 139 | |
| 140 | switch (_options.algorithm) |
| 141 | { |
| 142 | case Algorithm::Random: |
| 143 | { |
| 144 | double elitePoolSize = 1.0 / double(_populationSize); |
| 145 | |
| 146 | if (_options.randomElitePoolSize.has_value()) |
| 147 | elitePoolSize = _options.randomElitePoolSize.value(); |
| 148 | |
| 149 | return std::make_unique<RandomAlgorithm>(RandomAlgorithm::Options{ |
| 150 | /* elitePoolSize = */ elitePoolSize, |
| 151 | /* minChromosomeLength = */ _options.minChromosomeLength, |
| 152 | /* maxChromosomeLength = */ _options.maxChromosomeLength, |
| 153 | }); |
| 154 | } |
| 155 | case Algorithm::GEWEP: |
| 156 | { |
| 157 | double percentGenesToRandomise = 1.0 / double(_options.maxChromosomeLength); |
| 158 | double percentGenesToAddOrDelete = percentGenesToRandomise; |
| 159 | |
| 160 | if (_options.gewepGenesToRandomise.has_value()) |
| 161 | percentGenesToRandomise = _options.gewepGenesToRandomise.value(); |
| 162 | if (_options.gewepGenesToAddOrDelete.has_value()) |
| 163 | percentGenesToAddOrDelete = _options.gewepGenesToAddOrDelete.value(); |
| 164 | |
| 165 | return std::make_unique<GenerationalElitistWithExclusivePools>(GenerationalElitistWithExclusivePools::Options{ |
| 166 | /* mutationPoolSize = */ _options.gewepMutationPoolSize, |
| 167 | /* crossoverPoolSize = */ _options.gewepCrossoverPoolSize, |
| 168 | /* randomisationChance = */ _options.gewepRandomisationChance, |
| 169 | /* deletionVsAdditionChance = */ _options.gewepDeletionVsAdditionChance, |
| 170 | /* percentGenesToRandomise = */ percentGenesToRandomise, |
| 171 | /* percentGenesToAddOrDelete = */ percentGenesToAddOrDelete, |
| 172 | /* crossover = */ _options.crossover, |
| 173 | /* uniformCrossoverSwapChance = */ _options.uniformCrossoverSwapChance, |
| 174 | }); |
| 175 | } |
| 176 | case Algorithm::Classic: |
| 177 | { |
| 178 | return std::make_unique<ClassicGeneticAlgorithm>(ClassicGeneticAlgorithm::Options{ |
| 179 | /* elitePoolSize = */ _options.classicElitePoolSize, |
| 180 | /* crossoverChance = */ _options.classicCrossoverChance, |
| 181 | /* mutationChance = */ _options.classicMutationChance, |
| 182 | /* deletionChance = */ _options.classicDeletionChance, |
| 183 | /* additionChance = */ _options.classicAdditionChance, |
| 184 | /* crossover = */ _options.crossover, |
| 185 | /* uniformCrossoverSwapChance = */ _options.uniformCrossoverSwapChance, |
| 186 | }); |
| 187 | } |
| 188 | default: |
| 189 | assertThrow(false, solidity::util::Exception, "Invalid Algorithm value."); |
| 190 | } |
nothing calls this directly
no test coverage detected