void Node::createChildren() { for(int k = (f+1)/2; k < f; k++){ if( generators[k] & (!semigroup[2*k-f]) & (3*k != 2*f) & (4*k != 3*f) & (f-k < multiplicity)){ spawnChild(k); } } }
static const char * cygterm_init(void *frontend_handle, void **backend_handle, Conf *conf, char *unused_host, int unused_port, char **realhost, int nodelay, int keepalive) { /* XXX: I'm not sure if it is OK to overload Plug like this. * cygterm_accepting should only be used for the listening socket * (local->a) while the cygterm_closing, cygterm_receive, and cygterm_sent * should be used only for the actual connection (local->s). */ static const struct plug_function_table fn_table = { cygterm_log, cygterm_closing, cygterm_receive, cygterm_sent, cygterm_accepting }; Local local; const char *command; char cmdline[2 * MAX_PATH]; int cport; const char *err; int cmdlinelen; cygterm_debug("top"); local = snew(struct cygterm_backend_data); local->fn = &fn_table; local->a = NULL; local->s = NULL; local->conf = conf; local->editing = 0; local->echoing = 0; local->exitcode = 0; *backend_handle = local; local->frontend = frontend_handle; /* set up listen socket for communication with child */ cygterm_debug("setupCygTerm"); /* let sk use INADDR_LOOPBACK and let WinSock choose a port */ local->a = sk_newlistener(0, 0, (Plug)local, 1, ADDRTYPE_IPV4); if ((err = sk_socket_error(local->a)) != NULL) goto fail_free; /* now, get the port that WinSock chose */ /* XXX: Is there another function in PuTTY to do this? */ cygterm_debug("getting port"); cport = sk_getport(local->a); if (cport == -1) { err = "Failed to get port number for cthelper"; goto fail_close; } if (strchr(conf_get_str(local->conf, CONF_termtype), ' ')) { err = "term type contains spaces"; goto fail_close; } /* Build cthelper command line */ if(conf_get_int(conf, CONF_cygterm64)) { cmdlinelen = sprintf(cmdline, CTHELPER64" %u %s ", cport, conf_get_str(local->conf, CONF_termtype)); } else { cmdlinelen = sprintf(cmdline, CTHELPER" %u %s ", cport, conf_get_str(local->conf, CONF_termtype)); } cmdlinelen += makeAttributes(cmdline + cmdlinelen, conf); command = conf_get_str(conf, CONF_cygcmd); cygterm_debug("command is :%s:", command); /* A command of "." or "-" tells us to pass no command arguments to * cthelper which will then run the user's shell under Cygwin. */ if ((command[0]=='-'||command[0]=='.') && command[1]=='\0') ; else if (cmdlinelen + strlen(command) + 2 > sizeof cmdline) { err = "command is too long"; goto fail_close; } else { cmdlinelen += sprintf(cmdline + cmdlinelen, " %s", command); } /* Add the Cygwin /bin path to the PATH. */ if (conf_get_int(conf, CONF_cygautopath)) { char *cygwinBinPath = getCygwinBin(conf_get_int(conf, CONF_cygterm64)); if (!cygwinBinPath) { /* we'll try anyway */ cygterm_debug("cygwin bin directory not found"); } else { cygterm_debug("found cygwin directory: %s", cygwinBinPath); appendPath(cygwinBinPath); sfree(cygwinBinPath); } } cygterm_debug("starting cthelper: %s", cmdline); if ((err = spawnChild(cmdline, &local->pi, &local->ctl))) goto fail_close; /* This should be set to the local hostname, Apparently, realhost is used * only to set the window title. */ strcpy(*realhost = smalloc(sizeof CYGTERM_NAME), CYGTERM_NAME); cygterm_debug("OK"); return 0; fail_close: sk_close(local->a); fail_free: sfree(local); return err; }
void Organism::evolve() { // user-mediated evolution procedure char key = 0; drawTree(leftChild != NULL && !leftChild->terminal, midChild != NULL && !midChild->terminal, rightChild != NULL && !rightChild->terminal); // grow the parent and two children until a key is pressed // try a new child while this is happening Organism *newChild = spawnChild(); assert(newChild != NULL); do { // repeat this loop until the space key is pressed plotAt(vc.numxpixels/2, vc.numypixels*3/4); nextGen(); if (leftChild == NULL) leftChild = spawnChild(); // make new left child else leftChild->plotAt(vc.numxpixels/6, vc.numypixels/3); assert(leftChild != NULL); leftChild->nextGen(); if (midChild == NULL) midChild = spawnChild(); // make new mid child else midChild->plotAt(vc.numxpixels/2, vc.numypixels/4); assert(leftChild != NULL); midChild->nextGen(); if (rightChild == NULL) rightChild = spawnChild(); // make new left child else rightChild->plotAt(vc.numxpixels*5/6, vc.numypixels/3); assert(leftChild != NULL); rightChild->nextGen(); terminal = 0; // if the node was terminal before, its not now if (newChild->age < 25) newChild->nextGen(); else if (leftChild->terminal == 1 && newChild->fitness()*0.7 > leftChild->fitness()) { // replace the left child with the new child delete leftChild; leftChild = newChild; newChild = spawnChild(); assert(newChild != NULL); } else if (midChild->terminal == 1 && newChild->fitness()*0.7 > midChild->fitness()) { // replace the left child with the new child delete midChild; midChild = newChild; newChild = spawnChild(); assert(newChild != NULL); } else if (rightChild->terminal == 1 && newChild->fitness()*0.7 > rightChild->fitness()) { // replace the left child with the new child delete rightChild; rightChild = newChild; newChild = spawnChild(); assert(newChild != NULL); } else if (newChild->age > 50) { // new child is 50 generations old and still has not promoted delete newChild; newChild = spawnChild(); assert(newChild != NULL); } else newChild->nextGen(); if (kbhit()) { // read the key and see what needs to be done key = getch(); if (_stackavail() > 0x0400) { // only process child branch if there is enough stack space if (key == 'A' || key == 'a') leftChild->evolve(); else if (key == 'G' || key == 'g') midChild->evolve(); else if (key == 'L' || key == 'l') rightChild->evolve(); drawTree(leftChild != NULL && !leftChild->terminal, midChild != NULL && !midChild->terminal, rightChild != NULL && !rightChild->terminal); }; // if } else key = 0; } while (key != ' '); delete newChild; }; // Organism::evolve()
/** \fn runOneJob */ bool jobWindow::runOneJob( ADMJob &job) { bool r=false; uint32_t version; job.startTime=ADM_getSecondsSinceEpoch(); job.status=ADM_JOB_RUNNING; ADM_commandSocket *runSocket=NULL; ADMJob::jobUpdate(job); refreshList(); ADM_socketMessage msg; uint32_t v; // 1- Start listening to socket // 2- Spawn child string ScriptFullPath; #ifdef _WIN32 #define MKCLI() "avidemux_cli.exe" #define MKQT() "avidemux.exe" string slash=string("\\"); #else #define MKCLI() "avidemux3_cli" #define MKQT() "avidemux3_qt4" string slash=string("/"); #endif ScriptFullPath=string(ADM_getJobDir())+slash+string(job.scriptName); const char *avidemuxVersion=MKCLI(); if(ui.checkBoxUseQt4->isChecked()) { avidemuxVersion=MKQT(); } if(false==spawnChild(avidemuxVersion,ScriptFullPath,job.outputFileName)) { ADM_error("Cannot spawn child\n"); r=false; goto done; } // 3- Wait for connect... runSocket=mySocket.waitForConnect(6*1000); if(!runSocket) { ADM_error("No connect\n"); goto done; } if(!runSocket->handshake()) { popup("Cannot handshake"); goto done; } // 4- wait for complete and/or success message while(1) { if(!runSocket->isAlive()) { ADM_info("Exiting loop\n"); break; } if(runSocket->pollMessage(msg)) { ADM_info("Got a new message %d\n",msg.command); switch(msg.command) { case ADM_socketCommand_End: if(msg.getPayloadAsUint32_t(&v)) { r=(bool)v; ADM_info("Result is %d\n",r); goto done; }else { ADM_error("Can read End payload \n"); } break; case ADM_socketCommand_Progress: if(msg.getPayloadAsUint32_t(&v)) { printf("Progress %d %%\n",(int)v); dialog->setPercent(v); }else { ADM_error("Can read End payload \n"); } break; default: ADM_error("Unknown command\n"); break; } } ADM_assert(dialog); QApplication::processEvents(); ADM_usleep(1000*1000); // Refresh once per sec } ADM_info("** End of slave process **\n"); ADM_info("** End of slave process **\n"); ADM_info("** End of slave process **\n"); // 5-Done, do the cleanup done: if(r) job.status=ADM_JOB_OK; else job.status=ADM_JOB_KO; job.endTime=ADM_getSecondsSinceEpoch(); ADMJob::jobUpdate(job); if(runSocket) delete runSocket; refreshList(); ADM_info("Running job id = %d\n",job.id); return r; }