void GlobalSurprisingSeq::genotypeToPhenotype(EARepresentation *gen) { EACharString* stringGen(dynamic_cast<EACharString*>(gen)); for(int i(0);i < stringGen->getGenotypeSize();i++) { stringGen->addPhenotype(stringGen->getString(i)); } }
const char* testClient(void* parameters) { struct workerTask* worker = (struct workerTask*)parameters; uint16_t randContext[3]; for(int i = 0; i < 3; i++) { randContext[i] = time(NULL) ^ worker->workerID; } if(!worker->conn) { //spread the load from new connections so the server won't be overloaded usleep(erand48(randContext) * 1000 + 1000*worker->connOpenDelay); worker->conn = storage_connect(worker->hostname, worker->port); if(!worker->conn) { printf("storage_connect failed\n"); return ece297strerror(errno); } int result = storage_auth(worker->username, worker->password, worker->conn); if(result == -1) { printf("storage_auth failed\n"); storage_disconnect(worker->conn); worker->conn = NULL; return ece297strerror(errno); } } uint64_t loopCount = worker->numKeys; if(worker->type == kClientRunWorkload) { loopCount = worker->count; } uint64_t period = 0; //0 throughput = no limit if(worker->throughput) { period = (1/worker->throughput) * 1000000; //start at a random time usleep(erand48(randContext) * period); } struct timeval next; gettimeofday(&next, NULL); for(uint64_t i = 0; i < loopCount; i++) { if(worker->throughput) { int64_t timeRemaining = -uSElapsed(&next); if(timeRemaining > 0) { usleep((uint32_t)timeRemaining); } uint64_t newTime = next.tv_usec + period; next.tv_sec += newTime / 1000000; next.tv_usec = newTime % 1000000; } switch (worker->type) { case kClientAddKeys: { char keyBuf[20]; //as per ECE297 spec stringGen(worker->startingKey + i, worker->keySecret, keyBuf, sizeof(keyBuf)); struct storage_record record; memset(&record.metadata, 0, sizeof(record.metadata)); stringGen(worker->startingKey + i, worker->valueSecret, record.value, sizeof(record.value)); struct timeval start; gettimeofday(&start, NULL); if(storage_set(worker->table, keyBuf, &record, worker->conn) == -1) { printf("storage_set failed\n"); return ece297strerror(errno); } recordLatency(timeElapsed(&start), worker->latencyResults); break; } case kClientRunWorkload: { //WATCH the floating point promotion - it must be cast to a uint64_t BEFORE adding worker->startingKey uint64_t keyIndex = ((uint64_t)(erand48(randContext) * worker->numKeys)) + worker->startingKey; char keyBuf[20]; //as per ECE297 spec stringGen(keyIndex, worker->keySecret, keyBuf, sizeof(keyBuf)); char expectedValue[1024]; stringGen(keyIndex, worker->valueSecret, expectedValue, sizeof(expectedValue)); struct timeval start; gettimeofday(&start, NULL); struct storage_record rec; if(storage_get(worker->table, keyBuf, &rec, worker->conn) == -1) { printf("storage_get failed (key index = %u)\n", keyIndex); return ece297strerror(errno); } if(strcmp(rec.value, expectedValue)) { return "Server returned incorrect key"; } recordLatency(timeElapsed(&start), worker->latencyResults); } } } return NULL; }
void GlobalSurprisingSeq::fitFct(EARepresentation *gen) { EACharString* stringGen(dynamic_cast<EACharString*>(gen)); std::list<int> fitList; std::vector<int> test; std::vector<std::vector<int> >symbolsList; std::vector<int> symbol; firstOfGen = true; for(int k(0); k < stringGen->getPhenotypeSize();k++) { test = stringGen->getString(k); for(int i = 0; i < stringGen->getLength(); i++) { for(int j(i+1); j < stringGen->getLength(); j++) { symbol.push_back(test[j]); symbol.push_back(test[i]); symbol.push_back(i-j-1); // symbolsList.push_back(symbol); symbol.clear(); } } // Save the size to check if it's surprising int beforSize(symbolsList.size()); // Eliminate duplicates std::sort(symbolsList.begin(),symbolsList.end()); symbolsList.erase(std::unique(symbolsList.begin(),symbolsList.end()),symbolsList.end()); // Push fit value fitList.push_back(symbolsList.size()); //Surprising test if(beforSize == symbolsList.size()) { QString ret; ret.clear(); for(int j(0); j < length ;j++) ret += (QString::number(test[j]) + ", "); if(firstOfGen == true) { firstOfGen = false; emit resultFound(ret); } } symbolsList.clear(); } gen->setFitList(fitList); }