• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ fitness_vector类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: exp

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

	double g = 0;

	f[0] = 1 - exp(-4*x[0])*pow(sin(6*m_pi*x[0]),6);

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


示例17: generate_weights

//Generate a random weights vector whose sum of all elements is equal to 1
void generate_weights(fitness_vector & weights)
{
	
	rng_double drng = rng_generator::get<rng_double>();
	
	//generate n random numbers between 0 and 1 and store in weights where n = weights.size()
	std::generate(weights.begin(), weights.end(), std::bind(fRand, drng));
	
	//caculate the sum of all elements of weights vector
	double sum = std::accumulate(weights.begin(), weights.end(), 0.0);
	
	//divide each element of weights vector by the calculated sum to make the sum of all elements equal to 1
	std::transform(weights.begin(), weights.end(), weights.begin(),
	    std::bind1st(std::multiplies<double>(),1/sum));

}
开发者ID:DinCahill,项目名称:pagmo,代码行数:17,代码来源:test_decompose.cpp


示例18: cos

/// Implementation of the objective function.
void levy5::objfun_impl(fitness_vector &f, const decision_vector &x) const
{
	pagmo_assert(f.size() == 1);
	decision_vector::size_type n = x.size();
	double isum = 0.0;
	double jsum = 0.0;
	f[0] = 0;

	for ( decision_vector::size_type j=0; j<n; j+=2 ) {
		for ( int i=1; i<=5; i++ ) {
			isum += (double)(i) * cos((double)(i-1)*x[j] + (double)(i));
			jsum += (double)(i) * cos((double)(i+1)*x[j+1] + (double)(i));
		}
	}

	f[0] = isum*jsum;
	for ( decision_vector::size_type j=0; j<n; j+=2 )
		f[0] += pow(x[j] + 1.42513,2) + pow(x[j+1] + 0.80032,2);

}
开发者ID:YS-L,项目名称:pagmo,代码行数:21,代码来源:levy5.cpp


示例19: objfun_impl

/// Implementation of the objective function.
void sch::objfun_impl(fitness_vector &f, const decision_vector &x) const
{
	pagmo_assert(f.size() == 2 && x.size() == 1);
	f[0] = x[0]*x[0];
	f[1] = (x[0]-2) * (x[0]-2);
}
开发者ID:DinCahill,项目名称:pagmo,代码行数:7,代码来源:sch.cpp


示例20: c

/// Implementation of the objective functions.
/// (Wraps over the original implementation)
void con2mo::objfun_impl(fitness_vector &f, const decision_vector &x) const
{
	constraint_vector c(m_original_problem->get_c_dimension(),0.);
	m_original_problem->compute_constraints(c,x);

	decision_vector original_f(m_original_problem->get_f_dimension(),0.);
	m_original_problem->objfun(original_f,x);

	f_size_type original_nbr_obj = original_f.size();
	c_size_type number_of_constraints = c.size();
	c_size_type number_of_eq_constraints = number_of_constraints - m_original_problem->get_ic_dimension();
	c_size_type number_of_violated_constraints = 0;
	
	// computes the number of satisfied constraints
	if(m_method==OBJ_CSTRS){
		for(c_size_type i=0; i<number_of_constraints; i++){
			if(!m_original_problem->test_constraint(c,i))
				number_of_violated_constraints += 1;
		}
	}

	// modify equality constraints to behave as inequality constraints:

	const std::vector<double> &c_tol = m_original_problem->get_c_tol();

	for(c_size_type i=0; i<number_of_constraints; i++) {
		if(i<number_of_eq_constraints){
			c[i] = std::abs(c[i]) - c_tol.at(i);
		}
		else{
			c[i] = c[i] - c_tol.at(i);
		}
	}

	// clean the fitness vector
	for(f_size_type i=0; i<f.size(); i++) {
		f[i] = 0.;
	}

	// in all cases, the first objectives holds the initial objectives
	for(f_size_type i=0; i<original_nbr_obj; i++) {
		f[i] = original_f.at(i);
	}

	switch(m_method)
	{
	case OBJ_CSTRS:
	{

		for(c_size_type i=0; i<number_of_constraints; i++) {
			if(c.at(i) > 0.) {
				f[original_nbr_obj+i] = c.at(i);
			} else if(number_of_violated_constraints != 0) {
				f[original_nbr_obj+i] = number_of_violated_constraints;
			} else {
				f[original_nbr_obj+i] = 0.;
				for(f_size_type j=0; j<original_nbr_obj; j++) {
					f[original_nbr_obj+i] += original_f.at(j);
				}
			}
		}
		break;
	}
	case OBJ_CSTRSVIO:
	{
		for(c_size_type i=0; i<number_of_constraints; i++) {
			if(c.at(i) > 0.) {
				f[original_nbr_obj] += c.at(i);
			}
		}
		break;
	}
	case OBJ_EQVIO_INEQVIO:
	{
		// treating equality constraints
		for(c_size_type i=0; i<number_of_eq_constraints; i++) {
			if(c.at(i) > 0.) {
				f[original_nbr_obj] += c.at(i);
			}
		}

		for(c_size_type i=number_of_eq_constraints; i<number_of_constraints; i++) {
			if(c.at(i) > 0.) {
				f[original_nbr_obj+1] += c.at(i);
			}
		}
		break;
	}
	default:
		pagmo_throw(value_error, "Error: There are only 3 methods for the constrained to multi-objective!");
		break;
	}
}
开发者ID:DinCahill,项目名称:pagmo,代码行数:95,代码来源:con2mo.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ fixed类代码示例发布时间:2022-05-31
下一篇:
C++ filebuf类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap