// 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); } } } }
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; }