当前位置: 首页>>代码示例>>C++>>正文


C++ Generation::produce_offspring方法代码示例

本文整理汇总了C++中Generation::produce_offspring方法的典型用法代码示例。如果您正苦于以下问题:C++ Generation::produce_offspring方法的具体用法?C++ Generation::produce_offspring怎么用?C++ Generation::produce_offspring使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Generation的用法示例。


在下文中一共展示了Generation::produce_offspring方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: run_optimization

void GeneticAlgorithm::run_optimization(std::vector<exp_signal> const& signals_exp,
	                                    Spin const& spinA, Spin const& spinB,
										std::vector<int> const& param_numbers,
										std::vector<int> const& param_modes,
										std::vector<bound> const& param_bounds,
										genetic_parameters const& genetic_param,
										output_parameters const& output_param) const
{
	// Initialize the calculator of PELDOR signals
	PeldorCalculator* peldor_calc = new PeldorCalculator(genetic_param.num_avg);
	peldor_calc->calculate_spinA_excitation(signals_exp, spinA);
	// Calculate the spectrum of the spin system
	if (output_param.record_spectrum) {
		std::cout << "  Recording the spectrum... ";
		peldor_calc->save_spectrum(signals_exp, spinA, spinB, output_param);
		std::cout << "Done!" << std::endl;
	}
	// Start optimization
	int n = 1;
	std::cout << "  Optimization step " << n << "/" << genetic_param.num_generations_max << std::endl;
	// Create a first generation
	Generation* generation = new Generation(genetic_param);
	generation->create_initial_generation(param_bounds, genetic_param);
	// Score first generation
	generation->score_chromosomes(*peldor_calc, signals_exp, spinA, spinB, param_numbers, param_modes, genetic_param);
	generation->sort_chromosomes();
	std::vector<double> best_fitness; best_fitness.reserve(genetic_param.num_generations_max);
	best_fitness.push_back(generation->chromosomes[0].fitness);
	// Proceed with next generations
	for (int n = 2; n <= genetic_param.num_generations_max; ++n) { // loop over generations
		std::cout << "  Optimization step " << n << "/" << genetic_param.num_generations_max << std::endl;
		// Create next generation
		generation->produce_offspring(genetic_param, param_bounds);
		// Score the generation
		generation->score_chromosomes(*peldor_calc, signals_exp, spinA, spinB, param_numbers, param_modes, genetic_param);
		generation->sort_chromosomes();
		best_fitness.push_back(generation->chromosomes[0].fitness);
	}
	// Save the fitness of the best chromosome
	if (output_param.record_score) {
		std::cout << "  Recording the fitness vs the number of optimization steps... ";
		record_score(best_fitness, genetic_param, output_param);
		std::cout << "Done!" << std::endl;
	}
	// Save the calculated fit to the PELDOR signals for the best chromosome
	if (output_param.record_fit) {
		std::cout << "  Recording the fit to the PELDOR signals... ";
		record_fit(*peldor_calc, generation->chromosomes[0], signals_exp, spinA, spinB, param_numbers, param_modes, output_param);
		std::cout << "Done!" << std::endl;
	}
	// Save the genes of the best chromosome
	if (output_param.record_parameters) {
		std::cout << "  Recording the best values of fitting parameters... ";
		record_parameters(generation->chromosomes[0], param_numbers, param_modes, output_param);
		std::cout << "Done!" << std::endl;
	}
	// Record the calculated for-factors for the PELDOR signals
	if (output_param.record_form_factor) {
		std::cout << "  Recording the form-factors of PELDOR signals... ";
		record_form_factor(*peldor_calc, generation->chromosomes[0], signals_exp, spinA, spinB,
			               param_numbers, param_modes, output_param);
		std::cout << "Done!" << std::endl;
	}
	// Record the symmetry-related sets of fitting parameters
	if (output_param.record_symmetric_solutions) {
		std::cout << "  Recording the symmetry-related sets of fitting parameters... ";
		record_symmetric_parameters(*peldor_calc, generation->chromosomes[0], signals_exp, spinA, spinB, 
			                        param_numbers, param_modes, param_bounds, genetic_param, output_param);
		std::cout << "Done!" << std::endl;
	}
	// Record the error plots
	if (output_param.record_error_plot) {
		std::cout << "  Recording the error plot... ";
		record_error_plot(*peldor_calc, generation->chromosomes[0], signals_exp, spinA, spinB, 
			              param_numbers, param_modes, param_bounds, genetic_param, output_param);
		std::cout << "Done!" << std::endl;
	}
	// Clean up
	delete peldor_calc;
	delete generation;
}
开发者ID:dinarabdullin,项目名称:PeldorFit2015,代码行数:81,代码来源:genetic_algorithm.cpp


注:本文中的Generation::produce_offspring方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。