PacketSource_t * createPacketSource(long mean, int numSources, short seed) { PacketSource_t * packetSource = (PacketSource_t *)malloc(sizeof(PacketSource_t)); packetSource->uniformGen = (UniformGenerator_t *)malloc(sizeof(UniformGenerator_t) * numSources); packetSource->uniformSeed = (UniformGenerator_t *)malloc(sizeof(UniformGenerator_t) * numSources); packetSource->uniformCounts = (long *)malloc(sizeof(long) * numSources); packetSource->exponentialGen = (ExponentialGenerator_t *)malloc(sizeof(ExponentialGenerator_t) * numSources); packetSource->exponentialSeed = (UniformGenerator_t *)malloc(sizeof(UniformGenerator_t) * numSources); packetSource->exponentialCounts = (long *)malloc(sizeof(long) * numSources); long exponentialMeans[numSources]; ExponentialGenerator_t meanGen; meanGen.mean = mean; initGenerator(&(meanGen.randGen)); for(short i = 0; i < seed; i++){ genExponentialRand(&meanGen); } long tmpMean = 0; for(int i = 0; i < numSources; i++){ exponentialMeans[i] = genExponentialRand(&meanGen); tmpMean += exponentialMeans[i]; } tmpMean -= (mean*numSources); tmpMean /= numSources; const int BIG_NUM = 100000000; for( int i = 0; i < numSources; i++) { initGenerator(&(packetSource->uniformGen[i].randGen)); packetSource->uniformGen[i].maxValue= 2*mean + 1; packetSource->uniformGen[i].randGen.seed = ((1+i) & 0xFF); initGenerator(&(packetSource->uniformSeed[i].randGen)); packetSource->uniformSeed[i].maxValue= (BIG_NUM + 1); packetSource->uniformSeed[i].randGen.seed = ((1+i) & 0xFF); initGenerator(&(packetSource->exponentialGen[i].randGen)); packetSource->exponentialGen[i].mean = exponentialMeans[i]-tmpMean; packetSource->exponentialGen[i].randGen.seed = ((1+i) & 0xFF); initGenerator(&(packetSource->exponentialSeed[i].randGen)); packetSource->exponentialSeed[i].maxValue= BIG_NUM + 1; packetSource->exponentialSeed[i].randGen.seed = ((1+i) & 0xFF); packetSource->uniformCounts[i] = 0; packetSource->exponentialCounts[i] = 0; for( short j = 0; j < seed; j++ ) { getUniformRand(&(packetSource->uniformSeed[i])); getUniformRand(&(packetSource->exponentialSeed[i])); } } return packetSource; }
void GeneticAlgorithm::run() { initGenerator(); for (int i = 0; i < GA_MAXITER; i++) { QList<double> *points = new QList<double>(); for( int j = 0; j < GA_POWER; j++){ points->append(m_genotype.at(j).x); } emit updatePoints(points); reproductionOperator(); mutationOperator(); reductionOperator(); QVector<gene> tmp = m_genotype; tmp.removeAll(tmp.first()); if (tmp.isEmpty()) { qDebug() << "EARLY END"; qDebug() << "Total iterations: " << i; break; } } qDebug() << "Result:" << m_genotype.last().fitness; }
int Processor::start(int argc, char **argv) { //get the path of exe dir path = argv[0]; int pos = path.find_last_of("/")+1; if (pos > 0 ){ path = path.substr(0, pos); }else{ path = ""; } fileName = argv[1]; //ONI file bool isDisplay = false; //display or not the depth scene if(argc>2) isDisplay=true; //get the name of file without path pos = fileName.find_last_of("/") +1; if (pos < 0 ) pos = 0; fileName = fileName.substr(pos); dateStart = fileName.substr(0,fileName.find(".")); //Get the config std::string tmp = path + "config.xml"; const char *filename = tmp.c_str(); TiXmlDocument config(filename); if (!config.LoadFile()) { printf("Error while loading config!\n"); return 1; } TiXmlElement *root, *video, *faceDetection; root = config.FirstChildElement( "config" ); int fps = 24; bool active = false; const char* cascadeFile; if (root) { video = root->FirstChildElement("video"); fps = atoi(video->Attribute("fps2d")); faceDetection = root->FirstChildElement("faceDetection"); active = faceDetection->Attribute("active"); cascadeFile = faceDetection->Attribute("cascadeFile"); tmp = path + cascadeFile; cascadeFile = tmp.c_str(); } MovingObject::init(active, cascadeFile); //create directory for media instance->dir = "movieData/"+fileName.substr(0,fileName.find_last_of(".")); mkdir("movieData", 0777); mkdir((dir).c_str(), 0777); mkdir((dir+"/2D").c_str(), 0777); mkdir((dir+"/3D").c_str(), 0777); XnStatus rc = XN_STATUS_OK; xn::DepthGenerator g_DepthGenerator; xn::UserGenerator g_UserGenerator; xn::ImageGenerator g_image; //Init context and all Node/Generator rc = context.Init(); CHECK_RC(rc, "Init"); context.SetGlobalMirror(true); //mirror image rc = context.OpenFileRecording(argv[1]); CHECK_RC(rc, "InitFromONI"); rc = context.FindExistingNode(XN_NODE_TYPE_DEPTH, g_DepthGenerator); CHECK_RC(rc, "Find depth generator"); rc = context.FindExistingNode(XN_NODE_TYPE_USER, g_UserGenerator); if(rc!=XN_STATUS_OK){ rc = g_UserGenerator.Create(context); CHECK_RC(rc, "UserGenerator"); } rc = context.FindExistingNode(XN_NODE_TYPE_IMAGE, g_image); CHECK_RC(rc, "Find image generator"); initGenerator(g_UserGenerator, g_DepthGenerator); if (!g_UserGenerator.IsCapabilitySupported(XN_CAPABILITY_SKELETON) || !g_UserGenerator.IsCapabilitySupported(XN_CAPABILITY_POSE_DETECTION)) { printf("User generator doesn't support either skeleton or pose detection.\n"); return XN_STATUS_ERROR; } XnBool isSupported = g_DepthGenerator.IsCapabilitySupported("AlternativeViewPoint"); if(TRUE == isSupported) { XnStatus res = g_DepthGenerator.GetAlternativeViewPointCap().SetViewPoint(g_image); if(XN_STATUS_OK != res) { printf("Getting and setting AlternativeViewPoint failed: %s\n", xnGetStatusString(res)); } } else { printf("AlternativeViewPoint not supported\n"); } g_UserGenerator.GetSkeletonCap().SetSkeletonProfile(XN_SKEL_PROFILE_ALL); //Init Player xn::Player player; xn::NodeInfoList list; rc = context.EnumerateExistingNodes(list); if (rc == XN_STATUS_OK) { for (xn::NodeInfoList::Iterator it = list.Begin(); it != list.End(); ++it) { switch ((*it).GetDescription().Type) { case XN_NODE_TYPE_PLAYER: (*it).GetInstance(player); } } }else{ printf("Player error: %s\n", xnGetStatusString(rc)); } //Create a Generators contains all generators gen = new Generators(g_UserGenerator, g_DepthGenerator, g_image, player); strNodeName = g_image.GetName(); createXML(); //Create a XMLDocument //Start the Nodes/Generators rc = context.StartGeneratingAll(); CHECK_RC(rc, "StartGenerating"); //Set callbacks functions : NewUser & LostUser XnCallbackHandle hUserCBs; g_UserGenerator.RegisterUserCallbacks(Processor::NewUser, Processor::LostUser, NULL, hUserCBs); XnUInt32 nFrame, nFrameTot; instance->gen->player.GetNumFrames(instance->strNodeName, nFrameTot); //Loop each frames with windows output or not if (!isDisplay){ while(nFrame != nFrameTot -2){ //update current frame id instance->gen->player.TellFrame(instance->strNodeName,nFrame); // Read next available data instance->context.WaitAndUpdateAll(); //Update sequence if there is someone in the scene if (instance->hasUserInSight) instance->sequence->update(); } CleanupExit(); }else{ //Start the GL to display Depth image glInit(&argc, argv); glutMainLoop(); } }