⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hitsfitness.cpp

📁 ROSETTA C++库是一个C++类库和例程集合
💻 CPP
字号:
// HitsFitness.cpp: implementation of the HitsFitness class.
//
//////////////////////////////////////////////////////////////////////

#include <stdafx.h> // Added 980901 by Aleksander 踙rn.
#include "../copyright.h" // Added 000323 by Aleksander 豩rn.

#include "HitsFitness.h"
#include <kernel/system/assert.h>


//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

HitsFitness::HitsFitness(Context &c)
: context(c), costs(c.parameters.costs), fbias(c.parameters.bias)
{
	//sum_costs = std::accumulate(w.begin(), w.end(), 0.0);
	sum_costs = 0.0;
	for(unsigned int i = 0; i < context.elems_used; i++)
		sum_costs += costs[context.real_index[i]];
}

HitsFitness::~HitsFitness()
{

}

float HitsFitness::term1(EABitset * b)
{
	assert(b != NULL);
	float count = 0;
  for(int i = 0; i < b->size(); i++){
    if(b->get(i)){
      count += costs[context.real_index[i]];
    }
  }

  return b->term1 = (sum_costs - count)/sum_costs;
}

float HitsFitness::term2(EABitset * b)
{
  b->cover = context.covers(b);
  return (float)(b->term2 = b->cover/(context.sum_set_weights));
}

double HitsFitness::eval(Individual * ind)
{
	EABitset * b = (EABitset*)ind;

  double t1 = b->reeval ? term1(b) : b->term1;
  double t2 = b->reeval ? term2(b) : b->term2;

  if(b->reeval){
    eval_count++;
		b->reeval = false;
	}

  return (1-fbias) * t1 + fbias * (t2 > context.parameters.hit_fraction ? 
	  context.parameters.hit_fraction : t2);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -