本文整理汇总了C++中GAGenome::userData方法的典型用法代码示例。如果您正苦于以下问题:C++ GAGenome::userData方法的具体用法?C++ GAGenome::userData怎么用?C++ GAGenome::userData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GAGenome
的用法示例。
在下文中一共展示了GAGenome::userData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: return
float
objective(GAGenome & c) {
GA2DBinaryStringGenome & genome = (GA2DBinaryStringGenome &)c;
short **pattern = (short **)c.userData();
float value=0.0;
for(int i=0; i<genome.width(); i++)
for(int j=0; j<genome.height(); j++)
value += (float)(genome.gene(i,j) == pattern[i][j]);
return(value);
}
示例2: Objective
/**
* The objective is the distance
*/
float Objective(GAGenome & g)
{
double x1, y1, z1;
double x2, y2, z2;
GeneticExperience *experience = (GeneticExperience *)g.userData();
if (experience == NULL) {
cout << "Score: unable to find the experience" << endl;
return 0;
}
cout << "Scoring... " << flush;
experience->updateSplines(g);
VREPClient &vrep = experience->getVrep();
//Main Loop
vrep.start();
x1 = vrep.readPositionTrackerX();
y1 = vrep.readPositionTrackerY();
z1 = vrep.readPositionTrackerZ();
for (double t=0; t<SIMULATION_TIME; t+=0.02) {
//Display state
//Do next step
vrep.nextStep();
//Compute motors move
primitive_step(vrep, experience->getSplines());
}
x2 = vrep.readPositionTrackerX();
y2 = vrep.readPositionTrackerY();
z2 = vrep.readPositionTrackerZ();
//End simulation
vrep.stop();
double score = sqrt(pow(x1-x2,2)+pow(y1-y2,2)+pow(z1-z2,2));
cout << score << endl;
return score;
}