本文整理汇总了C++中Population::get方法的典型用法代码示例。如果您正苦于以下问题:C++ Population::get方法的具体用法?C++ Population::get怎么用?C++ Population::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Population
的用法示例。
在下文中一共展示了Population::get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: connect_to_cell
// handle the actual connections of a device into a cell
void UnitDiscRadio::connect_to_cell(Device* d,int cell_id) {
if(cell_id<0 || cell_id>=num_cells) return; // bounds check
Population* c = cells[cell_id];
UnitDiscDevice* udd = (UnitDiscDevice*)d->layers[id];
const flo* p = d->body->position();
bool debug = is_debug_radio && d->debug();
for(int i=0;i<c->max_id();i++) {
Device* nbrd = (Device*)c->get(i);
if(nbrd) {
const flo* nbrp = nbrd->body->position();
if(debug) post("Nbr? %d (dist=%f)\n",nbrd->uid,sqrt(range3sqr(p,nbrp)));
if(range3sqr(p,nbrp)<r_sqr) { // connect if close enough
UnitDiscDevice* nbr = (UnitDiscDevice*)nbrd->layers[id];
const flo* np = nbrd->body->position();
NbrRecord* nnr = new NbrRecord(udd,np,p);
NbrRecord* nr = new NbrRecord(nbr,p,np);
nr->backptr = nbr->neighbors.add(nnr);
nnr->backptr = udd->neighbors.add(nr);
if(debug) post("Accepted nbr %d\n",nbrd->uid);
} else {
if(debug) post("Rejected possible nbr %d\n",nbrd->uid);
}
}
}
}
示例2: main
int main(int argc, char** argv) {
//
// Load image
//
// Check input
if (argc < 2) {
std::cout << "ERROR: input filename missing or too many parameters" << std::endl;
return 1;
}
// Save input file
std::string inputFile = argv[1];
// Message
std::cout << "NOTE: configured" << std::endl;
//
// Create environment
//
// Create object
EnvImgWrite dataEnvironment;
// Max time given?
if (argc == 3)
dataEnvironment.runtime(atoi(argv[2]));
// Load base image
if (!dataEnvironment.load(inputFile)) {
std::cout << "ERROR: could not load image" << std::endl;
return 1;
}
// Message
std::cout << "NOTE: environment created" << std::endl;
//
// Create population
//
// Initial DNA (triangle)
unsigned char dnastring[] = {50, 50, 50, 128, // Semi transparent grey brush (RGB = 50 50 50, with 50% opacity)
1, 254, // Point one: (1, 254)
128, 1, // Point two: (128, 1)
254, 254, // Point three: (254, 254)
0, // And a seperator for the next gene
255, 1, 1, 128,
25, 225,
225, 225,
225, 25,
25, 25};
DNA tempDNA(dnastring, 23);
dataEnvironment.explain(&tempDNA);
// Create object
Population* dataPopulation = new PopSingleStraight(&dataEnvironment, tempDNA);
// Message
std::cout << "NOTE: population created" << std::endl;
// Evolve
try {
dataPopulation->evolve();
} catch (std::string e) {
std::cout << "ERROR: " << e << std::endl;
}
// Fetch and print the resulting DNA
const DNA* outputDNA = dataPopulation->get();
dataEnvironment.explain(outputDNA);
delete dataPopulation;
return 0;
}