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


C++ fitness_vector类代码示例

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


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

示例1: is_eq

bool is_eq(const fitness_vector & f1, const fitness_vector & f2, double eps){
	if(f1.size() != f2.size()) return false;
	for(unsigned int i = 0; i < f1.size(); i++){
		if(fabs(f1[i]-f2[i])>eps) return false;
	}
	return true;
}
开发者ID:John-Colvin,项目名称:pagmo,代码行数:7,代码来源:best_solutions_test.cpp

示例2: sort

/**
 * This method should be used both as a solution to 3D cases, and as a general termination method for algorithms that reduce D-dimensional problem to 3-dimensional one.
 *
 * This is the implementation of the algorithm for computing hypervolume as it was presented by Nicola Beume et al.
 * The implementation uses std::multiset (which is based on red-black tree data structure) as a container for the sweeping front.
 * Original implementation by Beume et. al uses AVL-tree.
 * The difference is insiginificant as the important characteristics (maintaining order when traversing, self-balancing) of both structures and the asymptotic times (O(log n) updates) are guaranteed.
 * Computational complexity: O(n*log(n))
 *
 * @param[in] points vector of points containing the 3-dimensional points for which we compute the hypervolume
 * @param[in] r_point reference point for the points
 *
 * @return hypervolume.
 */
double hv3d::compute(std::vector<fitness_vector> &points, const fitness_vector &r_point) const
{
	if (m_initial_sorting) {
		sort(points.begin(), points.end(), fitness_vector_cmp(2,'<'));
	}
	double V = 0.0; // hypervolume
	double A = 0.0; // area of the sweeping plane
	std::multiset<fitness_vector, fitness_vector_cmp> T(fitness_vector_cmp(0, '>'));

	// sentinel points (r_point[0], -INF, r_point[2]) and (-INF, r_point[1], r_point[2])
	const double INF = std::numeric_limits<double>::max();
	fitness_vector sA(r_point.begin(), r_point.end()); sA[1] = -INF;
	fitness_vector sB(r_point.begin(), r_point.end()); sB[0] = -INF;

	T.insert(sA);
	T.insert(sB);
	double z3 = points[0][2];
	T.insert(points[0]);
	A = fabs((points[0][0] - r_point[0]) * (points[0][1] - r_point[1]));

	std::multiset<fitness_vector>::iterator p;
	std::multiset<fitness_vector>::iterator q;
	for(std::vector<fitness_vector>::size_type idx = 1 ; idx < points.size() ; ++idx) {
		p = T.insert(points[idx]);
		q = (p);
		++q; //setup q to be a successor of p
		if ( (*q)[1] <= (*p)[1] ) { // current point is dominated
			T.erase(p); // disregard the point from further calculation
		} else {
			V += A * fabs(z3 - (*p)[2]);
			z3 = (*p)[2];
			std::multiset<fitness_vector>::reverse_iterator rev_it(q);
			++rev_it;

			std::multiset<fitness_vector>::reverse_iterator erase_begin (rev_it);
			std::multiset<fitness_vector>::reverse_iterator rev_it_pred;
			while((*rev_it)[1] >= (*p)[1] ) {
				rev_it_pred = rev_it;
				++rev_it_pred;
				A -= fabs(((*rev_it)[0] - (*rev_it_pred)[0])*((*rev_it)[1] - (*q)[1]));
				++rev_it;
			}
			A += fabs(((*p)[0] - (*(rev_it))[0])*((*p)[1] - (*q)[1]));
			T.erase(rev_it.base(),erase_begin.base());
		}
	}
	V += A * fabs(z3 - r_point[2]);

	return V;
}
开发者ID:DinCahill,项目名称:pagmo,代码行数:64,代码来源:hv3d.cpp

示例3: verify_before_compute

/**
 * Verifies whether reference point and the hypervolume method meet certain criteria.
 *
 * @param[in] r_point fitness vector describing the reference point
 *
 * @throws value_error if reference point's and point set dimension do not agree
 */
void hypervolume::verify_before_compute(const fitness_vector &r_point, hv_algorithm::base_ptr hv_algorithm) const
{
	if ( m_points[0].size() != r_point.size() ) {
		pagmo_throw(value_error, "Point set dimensions and reference point dimension must be equal.");
	}
	hv_algorithm->verify_before_compute(m_points, r_point);
}
开发者ID:YS-L,项目名称:pagmo,代码行数:14,代码来源:hypervolume.cpp

示例4:

/**
 * Verifies whether given algorithm suits the requested data.
 *
 * @param[in] points vector of points containing the d dimensional points for which we compute the hypervolume
 * @param[in] r_point reference point for the vector of points
 *
 * @throws value_error when trying to compute the hypervolume for the dimension other than 3 or non-maximal reference point
 */
void hv3d::verify_before_compute(const std::vector<fitness_vector> &points, const fitness_vector &r_point) const
{
	if (r_point.size() != 3) {
		pagmo_throw(value_error, "Algorithm hv3d works only for 3-dimensional cases");
	}

	base::assert_minimisation(points, r_point);
}
开发者ID:DinCahill,项目名称:pagmo,代码行数:16,代码来源:hv3d.cpp

示例5: compute_original_fitness

/**
 * Computes the original fitness of the multi-objective problem. It also updates the ideal point in case
 * m_adapt_ideal is true
 *
 * @param[out] f non-decomposed fitness vector
 * @param[in] x chromosome
 */
void decompose::compute_original_fitness(fitness_vector &f, const decision_vector &x) const {
	m_original_problem->objfun(f,x);
	if (m_adapt_ideal) {
		for (fitness_vector::size_type i=0; i<f.size(); ++i) {
			if (f[i] < m_z[i]) m_z[i] = f[i];
		}
	}
}
开发者ID:DinCahill,项目名称:pagmo,代码行数:15,代码来源:decompose.cpp

示例6: tmp

/// Implementation of the objective function.
/// Add noises to the computed fitness vector.
void noisy::objfun_impl(fitness_vector &f, const decision_vector &x) const
{
	//1 - Initialize a temporary fitness vector storing one trial result
	//and we use it also to init the return value 
	fitness_vector tmp(f.size(),0.0);
	f=tmp;
	//2 - We set the seed
	m_drng.seed(m_seed+m_decision_vector_hash(x));
	//3 - We average upon multiple runs
	for (unsigned int j=0; j< m_trials; ++j) {
		m_original_problem->objfun(tmp, x);
		inject_noise_f(tmp);
		for (fitness_vector::size_type i=0; i<f.size();++i) {
			f[i] = f[i] + tmp[i] / (double)m_trials;
		}
	}
}
开发者ID:DominicDirkx,项目名称:pagmo,代码行数:19,代码来源:noisy.cpp

示例7: tmp

/// Implementation of the objective function.
/// Add noises to the decision vector before calling the actual objective function.
void robust::objfun_impl(fitness_vector &f, const decision_vector &x) const
{
	// Temporary storage used for averaging
	fitness_vector tmp(f.size(),0.0);
	f = tmp;

	// Set the seed
	m_drng.seed(m_seed);

	// Perturb decision vector and evaluate
	decision_vector x_perturbed(x);
	for(unsigned int i = 0; i < m_trials; ++i){
		inject_noise_x(x_perturbed);
		m_original_problem->objfun(tmp, x_perturbed);
		for(fitness_vector::size_type j = 0; j < f.size(); ++j){
			f[j] += tmp[j] / (double)m_trials;
		}
	}
}
开发者ID:DinCahill,项目名称:pagmo,代码行数:21,代码来源:robust.cpp

示例8: inject_noise_f

/// Apply noise on a fitness vector
void noisy::inject_noise_f(fitness_vector& f) const
{
	for(f_size_type i = 0; i < f.size(); i++){
		if(m_noise_type == NORMAL){
			f[i] += m_normal_dist(m_drng)*m_param_second+m_param_first;
		}
		else if(m_noise_type == UNIFORM){
			f[i] += m_uniform_dist(m_drng)*(m_param_second-m_param_first)+m_param_first;
		}
	}
}
开发者ID:DominicDirkx,项目名称:pagmo,代码行数:12,代码来源:noisy.cpp

示例9: objfun_impl

/// Implementation of the objective function.
void dejong::objfun_impl(fitness_vector &f, const decision_vector &x) const
{
	pagmo_assert(f.size() == 1);
	decision_vector::size_type n = x.size();
	double retval = 0.0;

	for (decision_vector::size_type i=0; i<n; i++){
		retval += x[i]*x[i];
	}
	f[0] = retval;
}
开发者ID:DominicDirkx,项目名称:pagmo,代码行数:12,代码来源:dejong.cpp

示例10: objfun_impl

/// Implementation of the objective function.
void schwefel::objfun_impl(fitness_vector &f, const decision_vector &x) const
{
	pagmo_assert(f.size() == 1);
	std::vector<double>::size_type n = x.size();
	double value=0;

	for (std::vector<double>::size_type i=0; i<n; i++){
		value += x[i] * sin(sqrt(fabs(x[i])));
		}
		f[0] = 418.9828872724338 * n - value;
}
开发者ID:DominicDirkx,项目名称:pagmo,代码行数:12,代码来源:schwefel.cpp

示例11: objfun_impl

/// Implementation of the objective function.
void rastrigin::objfun_impl(fitness_vector &f, const decision_vector &x) const
{
	pagmo_assert(f.size() == 1);
	const double omega = 2.0 * boost::math::constants::pi<double>();
	f[0] = 0;
	const decision_vector::size_type n = x.size();
	for (decision_vector::size_type i = 0; i < n; ++i) {
		f[0] += x[i] * x[i] - 10.0 * std::cos(omega * x[i]);
	}
	f[0] += 10.0 * n;
}
开发者ID:YS-L,项目名称:pagmo,代码行数:12,代码来源:rastrigin.cpp

示例12: objfun_impl

/// Implementation of the objective function.
void michalewicz::objfun_impl(fitness_vector &f, const decision_vector &x) const
{
	pagmo_assert(f.size() == 1);
	decision_vector::size_type n = x.size();
	double retval = 0.0;

	for (decision_vector::size_type i=0; i<n; i++){
		retval -= sin(x[i]) * pow(sin((i+1)*x[i]*x[i]/boost::math::constants::pi<double>()) , 2*m_m);
	}
	f[0] = retval;
}
开发者ID:YS-L,项目名称:pagmo,代码行数:12,代码来源:michalewicz.cpp

示例13: compute_decomposed_fitness

/**
 * Computes the decomposed fitness from the original multi-objective one and a weight vector
 *
 * @param[out] f decomposed fitness vector
 * @param[in] original_fit original multi-objective fitness vector
 * @param[in] weights weights vector
 */
void decompose::compute_decomposed_fitness(fitness_vector &f, const fitness_vector &original_fit, const fitness_vector &weights) const
{
	if ( (m_weights.size() != weights.size()) || (original_fit.size() != m_weights.size()) ) {
		pagmo_throw(value_error,"Check the sizes of input weights and fitness vector");
	}
	if(m_method == WEIGHTED) {
		f[0] = 0.0;
		for(base::f_size_type i = 0; i < m_original_problem->get_f_dimension(); ++i) {
			f[0]+= weights[i]*original_fit[i];
		}
	} else if (m_method == TCHEBYCHEFF) {
		f[0] = 0.0;
		double tmp,weight;
		for(base::f_size_type i = 0; i < m_original_problem->get_f_dimension(); ++i) {
			(weights[i]==0) ? (weight = 1e-4) : (weight = weights[i]); //fixes the numerical problem of 0 weights
			tmp = weight * fabs(original_fit[i] - m_z[i]);
			if(tmp > f[0]) {
				f[0] = tmp;
			}
		}
	} else { //BI method
		const double THETA = 5.0;
		double d1 = 0.0;
		double weight_norm = 0.0;
		for(base::f_size_type i = 0; i < m_original_problem->get_f_dimension(); ++i) {
			d1 += (original_fit[i] - m_z[i]) * weights[i];
			weight_norm += pow(weights[i],2);
		}
		weight_norm = sqrt(weight_norm);
		d1 = fabs(d1)/weight_norm;

		double d2 = 0.0;
		for(base::f_size_type i = 0; i < m_original_problem->get_f_dimension(); ++i) {
			d2 += pow(original_fit[i] - (m_z[i] + d1*weights[i]/weight_norm), 2);
		}
		d2 = sqrt(d2);

		f[0] = d1 + THETA * d2;
	}
}
开发者ID:DinCahill,项目名称:pagmo,代码行数:47,代码来源:decompose.cpp

示例14: get_best_contributions

hv_algorithm::base_ptr hypervolume::get_best_contributions(const fitness_vector &r_point) const
{
	switch(r_point.size()) {
		case 2:
			return hv_algorithm::base_ptr(new hv_algorithm::hv2d());
			break;
		case 3:
			return hv_algorithm::base_ptr(new hv_algorithm::hv3d());
			break;
		default:
			return hv_algorithm::base_ptr(new hv_algorithm::wfg());
	}
}
开发者ID:YS-L,项目名称:pagmo,代码行数:13,代码来源:hypervolume.cpp

示例15:

/// Implementation of the objective function.
void zdt2::objfun_impl(fitness_vector &f, const decision_vector &x) const
{
	pagmo_assert(f.size() == 2);
	pagmo_assert(x.size() == 30);

	double g = 0;

	f[0] = x[0];

	for(problem::base::size_type i = 2; i < 30; ++i) {
		g += x[i];
	}
	g = 1 + (9 * g) / 29;
	
	f[1] = g * ( 1 - (x[0]/g)*(x[0]/g));
	
}
开发者ID:toggled,项目名称:pagmo,代码行数:18,代码来源:zdt2.cpp


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