void MainWindow::ConnectNewDomain(Domain *newDomain) { if (testDomain) { disconnect(testDomain, SIGNAL(Message(QString)), this, SLOT(displayOutput(QString))); disconnect(testDomain, SIGNAL(Instructions(QString)), ui->statusBar, SLOT(showMessage(QString))); disconnect(testDomain, SIGNAL(ToolFinishedDrawing()), ui->statusBar, SLOT(clearMessage())); disconnect(testDomain, SIGNAL(MouseX(float)), this, SLOT(showMouseX(float))); disconnect(testDomain, SIGNAL(MouseY(float)), this, SLOT(showMouseY(float))); disconnect(testDomain, SIGNAL(CircleToolStatsSet(float,float,float)), this, SLOT(showCircleStats(float,float,float))); disconnect(testDomain, SIGNAL(NumNodesDomain(int)), this, SLOT(showNumNodes(int))); disconnect(testDomain, SIGNAL(NumElementsDomain(int)), this, SLOT(showNumElements(int))); disconnect(testDomain, SIGNAL(NumNodesSelected(int)), this, SLOT(showNumSelectedNodes(int))); disconnect(testDomain, SIGNAL(NumElementsSelected(int)), this, SLOT(showNumSelectedElements(int))); disconnect(testDomain, SIGNAL(ToolFinishedDrawing()), glStatusBar, SLOT(clearMessage())); disconnect(testDomain, SIGNAL(EmitMessage(QString)), this, SLOT(displayOutput(QString))); disconnect(testDomain, SIGNAL(UndoAvailable(bool)), ui->undoButton, SLOT(setEnabled(bool))); disconnect(testDomain, SIGNAL(RedoAvailable(bool)), ui->redoButton, SLOT(setEnabled(bool))); } connect(newDomain, SIGNAL(Message(QString)), this, SLOT(displayOutput(QString))); connect(newDomain, SIGNAL(Instructions(QString)), ui->statusBar, SLOT(showMessage(QString))); connect(newDomain, SIGNAL(ToolFinishedDrawing()), ui->statusBar, SLOT(clearMessage())); connect(newDomain, SIGNAL(MouseX(float)), this, SLOT(showMouseX(float))); connect(newDomain, SIGNAL(MouseY(float)), this, SLOT(showMouseY(float))); connect(newDomain, SIGNAL(CircleToolStatsSet(float,float,float)), this, SLOT(showCircleStats(float,float,float))); connect(newDomain, SIGNAL(NumNodesDomain(int)), this, SLOT(showNumNodes(int))); connect(newDomain, SIGNAL(NumElementsDomain(int)), this, SLOT(showNumElements(int))); connect(newDomain, SIGNAL(NumNodesSelected(int)), this, SLOT(showNumSelectedNodes(int))); connect(newDomain, SIGNAL(NumElementsSelected(int)), this, SLOT(showNumSelectedElements(int))); connect(newDomain, SIGNAL(ToolFinishedDrawing()), glStatusBar, SLOT(clearMessage())); connect(newDomain, SIGNAL(EmitMessage(QString)), this, SLOT(displayOutput(QString))); connect(newDomain, SIGNAL(UndoAvailable(bool)), ui->undoButton, SLOT(setEnabled(bool))); connect(newDomain, SIGNAL(RedoAvailable(bool)), ui->redoButton, SLOT(setEnabled(bool))); }
/** * Entry point of program. */ int main(int argc, char ** argv) { init(); while(true) // Keep app running { setupGame(); while(game.lives) // New Round { setupRound(); while(!game.gameover) // Neither player missed the ball { getInput(); processAI(); moveBall(); displayOutput(); // Sleep PA_CheckLid(); PA_WaitForVBL(); } postRound(); } postGame(); } return 0; }
void SFNetworkView::updateView() { if ( !PNetwork ) return; if ( !UpdateDisplay ) return; SFRetina& Retina = PNetwork->getRetina(); UINT32 RetinaWidth = Retina.getWidth(); HDC DC = GetDC( Handle); HDC BackBufferDC = CreateCompatibleDC( DC); SelectObject( BackBufferDC , BackBuffer); PatBlt( BackBufferDC, 0,0, ClientRect.right , ClientRect.bottom, WHITENESS); HDC RetinaDC = Retina.startDraw(DC); BitBlt( BackBufferDC , 0, 0, Retina.getWidth() , Retina.getWidth() , RetinaDC , 0, 0, SRCCOPY); Retina.endDraw(); std::vector<SFLayer>& Layers = PNetwork->getLayers(); UINT32 OffsetX = RetinaWidth + 2 ; UINT32 OffsetY = RetinaWidth + 2; for ( UINT32 I = 0 ; I < Layers.size() ; I++ ) { displayOutput(BackBufferDC , Layers[I].getWidth() , Layers[I].getOutput(), Layers[I].getTargetOutput() == NULL ? Layers[I].getSnapshot():Layers[I].getTargetOutput() , OffsetX, 0 ); OffsetX += Layers[I].getWidth() + 2 ; } OffsetX *= 2; if ( SelectedLayer == -1 ) displayReconstruction(BackBufferDC, Layers[0] , Layers[0].getOutput() , 0 , OffsetY); else displayWeights( BackBufferDC , Layers[SelectedLayer], 0, OffsetY); OffsetY += RetinaWidth + 2; char Buf[256]; sprintf_s( Buf , 256 , "%d" , PNetwork->getTrainingCount() ); TextOutA( BackBufferDC , RetinaWidth + 4 , RetinaWidth + 5 , Buf, strlen(Buf) ); StretchBlt( DC , 0, 0, ClientRect.right , (OffsetY * ClientRect.right) / OffsetX , BackBufferDC, 0, 0, OffsetX , OffsetY ,SRCCOPY); DeleteDC(BackBufferDC); ReleaseDC(Handle,DC); Scale = (float)ClientRect.right / (float)OffsetX; }
int readInput(FILE *input_file, char file_name[], int values[], int desired_number) { int count = 0; int value = 0; int array_size; input_file = fopen(file_name, "r"); if (feof(input_file) != 0) { printf("Error: can't open file\n"); return -1; } else { printf("File opened successfully\n"); } //Get the first line of the file, which gives the size of the array while (fscanf(input_file, "%d", &value) != EOF) { if (count == 0)//The first value is being read { array_size = value - 1;//So that the later ones start at the correct index } else { values[count - 1] = value; } count++; } fclose(input_file); int delta; clock_t t1, t2; t1 = clock(); int recursive_result = recursiveBinarySearch(values, desired_number, 0, array_size); t2 = clock(); delta = t2 - t1; int delta1; clock_t t3, t4; t3 = clock(); int iterative_result = iterativeBinarySearch(values, desired_number, array_size); t4 = clock(); delta1 = t3 - t4; displayOutput(values, array_size, recursive_result, delta, delta1, iterative_result); return 0; }
void TransliteratorAPITest::keyboardAux(Transliterator *t, UnicodeString DATA[], UnicodeString& s, int32_t begin, int32_t end) { UTransPosition index={0, 0, 0, 0}; UErrorCode status=U_ZERO_ERROR; for (int32_t i=begin; i<end; i=i+5) { UnicodeString log; if (DATA[i+0] != "") { log = s + " + " + DATA[i] + " -> "; index.contextStart=getInt(DATA[i+2]); index.contextLimit=index.limit=getInt(DATA[i+3]); index.start=getInt(DATA[i+4]); t->transliterate(s, index, DATA[i+0], status); if(U_FAILURE(status)){ errln("FAIL: " + t->getID()+ ".transliterate(Replaceable, int32_t[], UnicodeString, UErrorCode)-->" + (UnicodeString)u_errorName(status)); continue; } log = s + " => "; t->finishTransliteration(s, index); } // Show the start index '{' and the cursor '|' displayOutput(s, DATA[i+1], log, index); } }
void TransliteratorAPITest::TestKeyboardTransliterator3(){ UnicodeString s="This is the main string"; UnicodeString Data[] = { "0", "0", "0", "This is the main string", "1", "3", "2", UnicodeString("Th\\u0069s is the main string", ""), "20", "21", "20", UnicodeString("Th\\u0069s is the mai\\u006E string", "") }; UErrorCode status=U_ZERO_ERROR; UParseError parseError; UTransPosition index={0, 0, 0, 0}; logln("Testing transliterate(Replaceable, int32_t, UErrorCode)"); Transliterator *t=Transliterator::createInstance("Any-Hex", UTRANS_FORWARD, parseError, status); if(t == 0 || U_FAILURE(status)) { errln("Error creating transliterator %s", u_errorName(status)); delete t; return; } for(uint32_t i=0; i<sizeof(Data)/sizeof(Data[0]); i=i+4){ UnicodeString log; index.contextStart=getInt(Data[i+0]); index.contextLimit=index.limit=getInt(Data[i+1]); index.start=getInt(Data[i+2]); t->transliterate(s, index, status); if(U_FAILURE(status)){ errln("FAIL: " + t->getID()+ ".transliterate(Replaceable, int32_t[], UErrorCode)-->" + (UnicodeString)u_errorName(status)); continue; } t->finishTransliteration(s, index); log = s + " => "; // Show the start index '{' and the cursor '|' displayOutput(s, Data[i+3], log, index); } delete t; }
void MainWindow::timeout(){ ui->progressBar->setMaximum( ui->spinBoxSampleCount->value()); ui->progressBar->setValue(vision->getSampleCount()); if(!camera.ready){ trace("Connecting to cameras..."); if(RESULT_OK != camera.setup(cvSize(176,144))){ trace("-FAILED"); }else{ trace("+OK"); on_pushButtonLoad_clicked(); cvNamedWindow( "left"); cvNamedWindow( "right"); cvNamedWindow( "rectified", 1 ); cvNamedWindow( "depth", 1 ); ui->pushButtonCalibrate->setEnabled(true); }; }else{ if(RESULT_OK == camera.capture()){ cvShowImage("left",camera.frames[0]); cvShowImage("right",camera.frames[1]); }; ui->pushButtonSave->setEnabled(vision->getCalibrationDone()); if(vision->getCalibrationStarted()){ if(sampleTimeout < 0){ sampleTimeout = ui->spinBoxInterval->value()*1000; trace(tr("Processing sample %1 of %2 Finding chessboard corners ...").arg(vision->getSampleCount()+1).arg(ui->spinBoxSampleCount->value())); int result = vision->calibrationAddSample(camera.getFramesGray(0),camera.getFramesGray(1)); if(RESULT_OK == result){ trace("+OK"); if(vision->getSampleCount() >= ui->spinBoxSampleCount->value()){ vision->calibrationEnd(); ui->pushButtonCalibrate->setEnabled(true); trace("Calibration Done !"); } }else{ trace("-FAIL Try a different position. Chessboard should be visible on both cameras."); } }else{ ui->lcdNumber->display(sampleTimeout/1000); sampleTimeout -= timer.interval(); } }else{ if(vision->getCalibrationDone()) displayOutput(); } } }
void new_displayOutput(void *ptr) { displayOutput(ptr); }
int main (int argc, char **argv, char **environ) { char *queue = NULL, *host = NULL, *jobName = NULL, *user = NULL; LS_LONG_INT jobId; int options; struct jobInfoEnt *jInfo; char *outFile; char fflag = FALSE; int cc; int rc; rc = _i18n_init (I18N_CAT_MIN); if (lsb_init (argv[0]) < 0) { lsb_perror ("lsb_init"); exit (-1); } while ((cc = getopt (argc, argv, "Vhfq:m:J:")) != EOF) { switch (cc) { case 'q': if (queue || host || jobName) oneOf (argv[0]); queue = optarg; break; case 'm': if (queue || host || jobName) oneOf (argv[0]); host = optarg; break; case 'J': if (queue || host || jobName) oneOf (argv[0]); jobName = optarg; break; case 'V': fputs (_LS_VERSION_, stderr); exit (0); case 'f': fflag = TRUE; break; case 'h': default: usage (argv[0]); } } jobId = 0; options = LAST_JOB; if (argc >= optind + 1) { if (queue || host || jobName) { oneOf (argv[0]); } else if ((argc > 2 && !fflag) || (argc > 3 && fflag)) usage (argv[0]); if (getOneJobId (argv[optind], &jobId, 0)) { usage (argv[0]); } options = 0; } if (lsb_openjobinfo (jobId, jobName, NULL, queue, host, options) < 0 || (jInfo = lsb_readjobinfo (NULL)) == NULL) { if (jobId != 0 || jobName != NULL) { user = ALL_USERS; if (lsb_openjobinfo (jobId, jobName, user, queue, host, options) < 0 || (jInfo = lsb_readjobinfo (NULL)) == NULL) { jobInfoErr (jobId, jobName, NULL, queue, host, options); exit (-1); } } else { jobInfoErr (jobId, jobName, NULL, queue, host, options); exit (-1); } } lsb_closejobinfo (); if (jobId && jInfo->jobId != jobId) { lsberrno = LSBE_JOB_ARRAY; lsb_perror ("bpeek"); exit (-1); } if ((jInfo->submit.options & SUB_INTERACTIVE) && !(jInfo->submit.options & (SUB_OUT_FILE | SUB_ERR_FILE))) { fprintf (stderr, _i18n_msg_get (ls_catd, NL_SETN, 2456, "Job <%s> : Cannot bpeek an interactive job.\n"), /* catgets 2456 */ lsb_jobid2str (jInfo->jobId)); exit (-1); } if (IS_PEND (jInfo->status) || jInfo->execUsername[0] == '\0') { fprintf (stderr, _i18n_msg_get (ls_catd, NL_SETN, 2454, "Job <%s> : Not yet started.\n"), /* catgets 2454 */ lsb_jobid2str (jInfo->jobId)); exit (-1); } if (IS_FINISH (jInfo->status)) { fprintf (stderr, _i18n_msg_get (ls_catd, NL_SETN, 2455, "Job <%s> : Already finished.\n"), /* catgets 2455 */ lsb_jobid2str (jInfo->jobId)); exit (-1); } if ((outFile = lsb_peekjob (jInfo->jobId)) == NULL) { char msg[50]; sprintf (msg, "%s <%s>", I18N_Job, lsb_jobid2str (jInfo->jobId)); lsb_perror (msg); exit (-1); } displayOutput (outFile, jInfo, fflag, environ); _i18n_end (ls_catd); exit (0); }
void TransliteratorAPITest::TestKeyboardTransliterator1(){ UnicodeString Data[]={ //insertion, buffer "a", UnicodeString("\\u0061", "") , "bbb", UnicodeString("\\u0061\\u0062\\u0062\\u0062", "") , "ca", UnicodeString("\\u0061\\u0062\\u0062\\u0062\\u0063\\u0061", "") , " ", UnicodeString("\\u0061\\u0062\\u0062\\u0062\\u0063\\u0061\\u0020", "") , "", UnicodeString("\\u0061\\u0062\\u0062\\u0062\\u0063\\u0061\\u0020", "") , "a", UnicodeString("\\u0061", "") , "b", UnicodeString("\\u0061\\u0062", "") , "z", UnicodeString("\\u0061\\u0062\\u007A", "") , "", UnicodeString("\\u0061\\u0062\\u007A", "") }; UParseError parseError; UErrorCode status = U_ZERO_ERROR; Transliterator* t=Transliterator::createInstance("Any-Hex", UTRANS_FORWARD, parseError, status); if(U_FAILURE(status)) { errln("Error creating transliterator %s", u_errorName(status)); delete t; return; } //keyboardAux(t, Data); UTransPosition index={0, 0, 0, 0}; UnicodeString s; uint32_t i; logln("Testing transliterate(Replaceable, int32_t, UnicodeString, UErrorCode)"); for (i=0; i<10; i=i+2) { UnicodeString log; if (Data[i+0] != "") { log = s + " + " + Data[i+0] + " -> "; t->transliterate(s, index, Data[i+0], status); if(U_FAILURE(status)){ errln("FAIL: " + t->getID()+ ".transliterate(Replaceable, int32_t[], UnicodeString, UErrorCode)-->" + (UnicodeString)u_errorName(status)); continue; } }else { log = s + " => "; t->finishTransliteration(s, index); } // Show the start index '{' and the cursor '|' displayOutput(s, Data[i+1], log, index); } s=""; status=U_ZERO_ERROR; index.contextStart = index.contextLimit = index.start = index.limit = 0; logln("Testing transliterate(Replaceable, int32_t, UChar, UErrorCode)"); for(i=10; i<sizeof(Data)/sizeof(Data[0]); i=i+2){ UnicodeString log; if (Data[i+0] != "") { log = s + " + " + Data[i+0] + " -> "; UChar c=Data[i+0].charAt(0); t->transliterate(s, index, c, status); if(U_FAILURE(status)) errln("FAIL: " + t->getID()+ ".transliterate(Replaceable, int32_t[], UChar, UErrorCode)-->" + (UnicodeString)u_errorName(status)); continue; }else { log = s + " => "; t->finishTransliteration(s, index); } // Show the start index '{' and the cursor '|' displayOutput(s, Data[i+1], log, index); } delete t; }
/* telemetryCallback This is called whenever a new telemetry message is received. We should store this any waypoint info received and perform analysis on it once all planes have received new data. */ void telemetryCallback(const AU_UAV_ROS::TelemetryUpdate::ConstPtr& msg) { //make sure the sim isn't lagging somehow and still reporting dead planes if(isDead[msg->planeID]) return; //store the telemetry information received previousUpdatesMap[msg->planeID] = latestUpdatesMap[msg->planeID]; latestUpdatesMap[msg->planeID] = *msg; //if all UAVs have an update, run some analysis on this timestep if(msg->planeID == maxAlivePlane) { //get the current time delta = ros::Time::now() - startTime; struct AU_UAV_ROS::waypoint current, other; //perform calculations on each plane for(int id = 0; id <= lastPlaneID; id++) { //nothing to do... WHEN YOU'RE DEAD! if(isDead[id]) continue; //change to waypoint format other.latitude = previousUpdatesMap[id].currentLatitude; other.longitude = previousUpdatesMap[id].currentLongitude; other.altitude = previousUpdatesMap[id].currentAltitude; current.latitude = latestUpdatesMap[id].currentLatitude; current.longitude = latestUpdatesMap[id].currentLongitude; current.altitude = latestUpdatesMap[id].currentAltitude; //add the distance traveled double d = distanceBetween(current, other); distanceTraveled[id] = distanceTraveled[id] + d; //totalDistTraveled = totalDistTraveled + d; distSinceLastWP[id] = distSinceLastWP[id] + d; //empty any items from the queue we've reached while(!waypointQueues[id].empty() && distanceBetween(waypointQueues[id].front(), current) < COLLISION_THRESHOLD) { //the front item is reached, pop it and increase our waypoints reached struct AU_UAV_ROS::waypoint temp = waypointQueues[id].front(); waypointQueues[id].pop(); if(waypointQueues[id].empty()) { //we ran out of points x_x } else { //add the last waypoint to our minimum distance minimumTravelDistance[id] = minimumTravelDistance[id] + waypointMinTravelDist[id]; totalMinDist = totalMinDist + waypointMinTravelDist[id]; waypointMinTravelDist[id] = distanceBetween(temp, waypointQueues[id].front()); } //modify scoring values waypointsAchieved[id]++; waypointsTotal++; score += WAYPOINT_SCORE; //set our distance traveled for waypoints waypointDistTraveled[id] = waypointDistTraveled[id] + distSinceLastWP[id]; totalDistTraveled = totalDistTraveled + distSinceLastWP[id]; distSinceLastWP[id] = 0; } //time to check for collisions with any other UAVs for(int otherID = 0; otherID < id; otherID++) { //we assume the wreckage disapates very quickly... lol if(isDead[otherID]) continue; other.latitude = latestUpdatesMap[otherID].currentLatitude; other.longitude = latestUpdatesMap[otherID].currentLongitude; other.altitude = latestUpdatesMap[otherID].currentAltitude; //check for a conflict double d = distanceBetween(current, other); if(d < CONFLICT_THRESHOLD) { //we detected a conflict, increase counter and subtract some points numConflicts++; score = score + CONFLICT_SCORE; } //check for collisions if(d < COLLISION_THRESHOLD) { //fire & death awaits these two planes... planesToDelete.push(id); planesToDelete.push(otherID); //increment our collision counter numCollisions++; //no score penalty, losing a couple planes will be bad enough } } } //we've parsed everything, delete some planes and display a new output to screen while(!planesToDelete.empty()) { int id = planesToDelete.front(); planesToDelete.pop(); //we're already dead, nothing to do about it if(isDead[id]) continue; else { //delete the simulated plane //construct the service request AU_UAV_ROS::DeleteSimulatedPlane srv; srv.request.planeID = id; //send the request printf("\nRequesting to delete plane...\n"); if(deleteSimulatedPlaneClient.call(srv)) { //printf("Plane with ID #%d has been deleted!\n", planeID); } else { ROS_ERROR("Did not receive a response from simulator"); } //mark us dead timeOfDeath[id] = delta; isDead[id] = true; deadPlaneCount++; } //if our max plane ID is a dead plane, we no longer receive updates, so we need //to be waiting on a new max for updating the screen while(maxAlivePlane >= 0 && isDead[maxAlivePlane]) { //decrement our valu maxAlivePlane--; } //check to make sure not all planes are dead if(maxAlivePlane < 0) { displayOutput(); endEvaluation(); } } //dump our info displayOutput(); //check for the end of times if((delta).toSec() > TIME_LIMIT) { //our time is up, time to write to files and wrap everything up endEvaluation(); } } }