Пример #1
0
int main()
{
    srand(time(NULL));

    getInputs();
    loadFile();

    if(algorithmChoice == 0)
    {
        for(int j = 0; j < 5; j++)
        {
            vector<TurnPointChrom*>* chromPool = new vector<TurnPointChrom*>();
            for(int i = 0; i < poolSize; i++) chromPool->push_back(new TurnPointChrom(mapSize, collisionMap));
            vector<TurnPointChrom*>* endChroms = mainGALoop(chromPool);
            printResults(endChroms);
            for(int i = 0; i < poolSize; i++) delete endChroms->at(i);
            delete endChroms;
        }
    }
    else
    {
        TurnPointChrom* result = annealing();
        printResults(result);
        delete result;
    }
    for(int i = 0; i < mapSize; i++)
        delete collisionMap[i];
    delete collisionMap;
}
Пример #2
0
void ps::testRR(int *testcycles){
	std::cout << "RR (1 PROCESSOR)" << std::endl;
	printResults(testcycles,runRR(testcycles));
	std::cout << std::endl;
	std::cout << "RR (4 PROCESSORS)" << std::endl;
	printResults(testcycles,runRRmult(testcycles));
	std::cout << std::endl;
}
Пример #3
0
void ps::testFIFO(int *testcycles){
	std::cout << "FIFO (1 PROCESSOR)" << std::endl;
	printResults(testcycles,runFIFO(testcycles));
	std::cout << std::endl;
	std::cout << "FIFO (4 PROCESSORS)" << std::endl;
	printResults(testcycles,runFIFOmult(testcycles));
	std::cout << std::endl;
}
Пример #4
0
void ps::testLRT(int *testcycles){
	std::cout << "LRT (1 PROCESSOR)" << std::endl;
	printResults(testcycles,runLRT(testcycles));
	std::cout << std::endl;
	std::cout << "LRT (4 PROCESSORS)" << std::endl;
	printResults(testcycles,runLRTmult(testcycles));
	std::cout << std::endl;
}
Пример #5
0
void ps::testSJF(int *testcycles){
	std::cout << "SJF (1 PROCESSOR)" << std::endl;
	printResults(testcycles,runSJF(testcycles));
	std::cout << std::endl;
	std::cout << "SJF (4 PROCESSORS)" << std::endl;
	printResults(testcycles,runSJFmult(testcycles));
	std::cout << std::endl;
}
Пример #6
0
int main()
{
    std::cout<<std::endl;
    printResults("Forth of July Weekend", "July");
    printResults("Elements of programming", "Element");
    printResults("Happily ever after", "happy"); // comparions are case sensitive
    printResults("Happily ever after", "app");
    std::cout<<std::endl;
    return 0;
}
Пример #7
0
int main(int argc, const char * argv[])
{
	A* a1 = new A();
	A* a2 = new A();
	std::vector<B*> objects = {
		new B(1, a1),
		new B(2, a2),
		new B(3, a1),
		new B(4, a2),
		new B(5, a1),
		new B(6, nullptr)
	};
	std::vector<B*> result;
	
	// predicate0
	std::copy_if(objects.begin(), objects.end(), std::back_inserter(result), predicate0);
	printResults("predicate0", result);
	
	// Functor
	std::copy_if(objects.begin(), objects.end(), std::back_inserter(result), Functor(a1));
	printResults("Functor(a1)", result);
	std::copy_if(objects.begin(), objects.end(), std::back_inserter(result), Functor(a2));
	printResults("Functor(a2)", result);
	
	// predicate1
	auto predicate1 = [a2](B* b) -> bool {return b->getA() == a2;};
	std::copy_if(objects.begin(), objects.end(), std::back_inserter(result), predicate1);
	printResults("predicate1", result);
	
	// predicate2
	auto predicate2 = [a1](B* b) -> bool {
		return std::equal_to<A*>()(b->getA(), a1);
	};
	std::copy_if(objects.begin(), objects.end(), std::back_inserter(result), predicate2);
	printResults("predicate2", result);
	
	// FunctorWrapper
	std::copy_if(objects.begin(), objects.end(), std::back_inserter(result), FunctorWrapper(std::equal_to<A*>(), a2));
	printResults("FunctorWrapper", result);
	
	// predicate3
	auto equalToA1 = std::bind(std::equal_to<A*>(), std::placeholders::_1, a1);
	auto predicate3 = [equalToA1](B* b) -> bool {
		return equalToA1(b->getA());
	};
	std::copy_if(objects.begin(), objects.end(), std::back_inserter(result), predicate3);
	printResults("predicate3", result);
	
	// ComposingWrapper + MethodWrapper
	std::copy_if(objects.begin(), objects.end(), std::back_inserter(result), ComposingWrapper(equalToA1, MethodWrapper(static_cast<A*(B::*)()>(&B::getA))));
	printResults("ComposingWrapper + MethodWrapper", result);
	
	// predicate4
	auto predicate4 = std::bind(std::equal_to<A*>(), std::bind(static_cast<A*(B::*)() const>(&B::getA), std::placeholders::_1), a2);
	std::copy_if(objects.begin(), objects.end(), std::back_inserter(result), predicate4);
	printResults("predicate4", result);
}
Пример #8
0
int main(int argc, char **argv)
{
    const char *conninfo;
    PGconn     *conn;
    PGresult   *res;
    if (argc > 1)
        conninfo = argv[1];
    else
        conninfo = "dbname = postgres";

    openConn(conninfo, &conn);
    begin(conn);

    res = exec(conn, "select id, short_desc from articles limit 10",  PGRES_TUPLES_OK);

    printResults(res);

    PQclear(res);

    res = exec(conn, "CLOSE myportal", PGRES_COMMAND_OK);
    PQclear(res);

    res = exec(conn, "END", PGRES_COMMAND_OK);
    PQclear(res);

    PQfinish(conn);

    return 0;
}
Пример #9
0
void TestSuite::runTests()
{
    cerr << string(m_IndentLevel, ' ') << "Running suite " << getName() << endl;
    for (unsigned i = 0; i < m_Tests.size(); ++i) {
        cerr << string(m_IndentLevel, ' ') << "  Running " 
                << m_Tests[i]->getName() << endl;
        try {
            m_Tests[i]->runTests();
            aggregateStatistics(*m_Tests[i]);
            m_Tests[i]->printResults();
        } catch (Exception& ex) {
            cerr << string(m_IndentLevel, ' ') << ex.getStr() << endl;
            setFailed();
        } catch (std::exception& ex) {
            cerr << string(m_IndentLevel, ' ') << "    ---->> failed, std::exception: "
                    << ex.what() << endl;
            setFailed();
        } catch (...) {
            cerr << string(m_IndentLevel, ' ') <<
                "    ---->> failed, exception caught" << endl;
            setFailed();
        }
    }
    
    printResults();
}
Пример #10
0
void benchmarkFile(char *filename)
{
    clock_t begin, end;
    double time_spent;
    
    json_token *tokens = calloc(sizeof(json_token), 3000000);
    
    json_parser parser;
    json_parser_init(&parser);
    
    
    parser.tokens = tokens;
    parser.maxTokens = 3000000;
    
    
    parser_from_file(&parser, filename);
    
    
    
    
    begin = clock();
    
    /* parse the json document */
    parse_json(&parser, RFC4627);
    
    
    end = clock();
    time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
    
    printResults(&parser, filename, time_spent);
    
    file_parser_free(&parser);
    
    free(tokens);
}
int main() {
    int getWord(FILE *, char[]);
    int binarySearch(int, int, char [], int max, char [][max]);
    void addToList(char[], int max, char [][max], int[], int, int);
    void printResults(FILE *, int max, char [][max], int[], int);
    char wordList[MaxWords][MaxWordBuffer], word[MaxWordBuffer];
    int frequency[MaxWords], numWords = 0;

    FILE * in = fopen("passage.txt", "r");
    if (in == NULL) {
        printf("Cannot find file\n");
        exit(1);
    }

    FILE * out = fopen("output.txt", "w");
    if (out == NULL) {
        printf("Cannot create output file\n");
        exit(2);
    }

    for (int h = 1; h <= MaxWords ; h++) frequency[h] = 0;

    while (getWord(in, word) != 0) {
        int loc = binarySearch (0, numWords-1, word, MaxWordBuffer, wordList);
        if (strcmp(word, wordList[loc]) == 0) ++frequency[loc]; //word found
        else //this is a new word
            if (numWords < MaxWords) { //if table is not full
                addToList(word, MaxWordBuffer, wordList, frequency, loc, numWords-1);
                ++numWords;
            }
            else fprintf(out, "'%s' not added to table\n", word);
    }
    printResults(out, MaxWordBuffer, wordList, frequency, numWords);
} // end main
Пример #12
0
int main(int Argc, char ** Argv)

{  
   getArgs(Argc,Argv);
   processData();
   printResults();
} //
Пример #13
0
int main () {
	srand (time (NULL));
	int numGames, numPlayers;
	Card deck[NUM_CARDS];
	Card hand[MAX_PLAYER][HAND_SIZE];
	getGameInfo (&numGames);
	initFile (numGames);
	for (int i = 0; i < numGames; i++) {
		getNumPlayers (&numPlayers);
		int handScores[numPlayers][1 + HAND_SIZE];
		memset(handScores, 0, numPlayers * (1 + HAND_SIZE) * sizeof(int));
		int bestHandIndices[numPlayers];
		memset (bestHandIndices, 0, numPlayers*sizeof(int));
		int *numTied = (int *)malloc(sizeof(int));
		*numTied = 0;
		printfName (i + 1, numPlayers);
		initDeck (deck);
		shuffleDeck (deck);
		dealHands (deck, hand, numPlayers);
		evaluateWinner (hand, numPlayers, handScores, bestHandIndices, numTied);
		for (int j = 0; j < numPlayers; j++) {
			printResults (&hand[j][0], HAND_SIZE, j, handScores);
		}
		printWinner (i + 1, hand, numPlayers, handScores, bestHandIndices, *numTied);
	}
}
int testmassiveclassification::execute()
{
	if (!MVTApp::startStore()) {mLogger.print("Failed to start store\n"); return RC_NOACCESS;}
	mSession = MVTApp::startSession();
	mLargeClass=0;

	if(mpArgs->get_param("largeclass",mLargeClass))
	{
		if(mLargeClass>COUNT_CLASS)
		{
			mLogger.out()<<"Invalid parameter value. -largeclass should not be greater than "<<COUNT_CLASS<<"running with default values";
			mLargeClass=0;
		}
		mLogger.out()<<endl<<mLargeClass<<" classes will have all the pins";
	}
	
	createProps(COUNT_PROP);
	defineClasses(COUNT_CLASS);
	createPins(COUNT_PIN);
	printResults();

	mSession->terminate();
	MVTApp::stopStore();
	return RC_OK;
}
	void printResults(VECTOR_ELEMENT_TYPE *pResult, int lambda, int idx, int varIdx)
	{
		FILE *file = openOutFile();
		if (!file)
			return;

		const char *pTag = idx >= 0 ? "+++++++++++++++++++" : (pResult ? "-------------------" : "===================");
		fprintf(file, "Total: %2d: %s %s = %d  ppp = %2d\n", nSolutions, pTag, pResult ? "lambdaToSplit" : "lambdaMin", lambda, ppp);
		for (int i = 0; i < PRINT_RES_EQU_NUMB; i++) {
			CEquation *pMyEqu = pMyEquA[i];
			if (!pMyEqu)
				continue;

			fprintf(file, "%d:  m_nVar = %d  right part = %d  solved = %3s\n", i, pMyEqu->numbVar(),
				pMyEqu->rightPart(), pMyEqu->solved() ? "Yes" : "No");
		}

		if (idx >= 0)
			nSolutions++;

		if (pResult)
			printResults(file, pResult, printResNumVar, varIdx);

		fclose(file);
	}
Пример #16
0
void Parser::parse() {
	
	start();
	lastEval(evaluate);
	printResults();

}
Пример #17
0
	void IMGDock::applyConformation(const vector < int > & conf, bool verbose)
	{
		int frag = 0; int bond = 0;

		resetRotations(); // reset all angles to zero and apply given conformation AFTER doing this !!

		for (Size i = 0; i < conf.size(); i++)
		{
			int diff_angle = conf[i] - current_conformation_[i];
			if (diff_angle != 0)
			{
				frag = bond_information_[i][0];
				bond = bond_information_[i][1];
				if (!global_rotation_ || i >= 3)
				{
					rotateLigandFragment(frag, bond, diff_angle);
				}
				else
				{
					rotateLigand(i, diff_angle);
				}
				current_conformation_[i] += diff_angle;
			}
			if (current_conformation_[i] != 0)
			{
				max_rotated_pos_ = i; // largest index of already changed bond
			}
		}
		if (verbose)
		{
			update();
			printResults();
		}
	}
Пример #18
0
int main(){
    
    while (1){
        
        switch (menu()) {
            case 0:
                return 0;
                
            default:
                /* Obliczanie wartości
                 * ! Poprawić
                 */
                quickValue = countValueQuickly();
                elementByElementValue = countValueElementByElement();
                /* ! Poprawić i  zrobic wypisanie tych danych. */
                powValue = countValueUsingPow();
                /* Wyliczenie bledow względnych funkcji wolnej i sprytnej */
                errorQuick = ((quickValue - powValue) / powValue) * 100;
                errorElementByElement = ((elementByElementValue - powValue) / powValue) * 100;
                
                printResults();
                
                break;
        }
    }
}
    private: void worldUpdate(){
        physics::LinkPtr head = model->GetLink("head_neck");
        #if(PRINT_DEBUG)
        cout << "Updating HIC for time " << world->GetSimTime() << endl;
        #endif
        updateMaximumHic(false);

        if(world->GetSimTime().Float() >= 2.0){
          #if(PRINT_DEBUG)
          cout << "Scenario completed. Updating results" << endl;
          #endif
          event::Events::DisconnectWorldUpdateBegin(this->connection);

           // Drain the HIC calculation
           for (unsigned int i = 0; i < ACC_HISTORY_MAX; ++i) {
              updateMaximumHic(true);
           }

          // Disconnect the sensors
          for(unsigned int i = 0; i < boost::size(contacts); ++i){
            sensors::SensorPtr sensor = sensors::SensorManager::Instance()->GetSensor(world->GetName() + "::" + model->GetScopedName()
                                                       + "::" + contacts[i]);
            if(sensor == nullptr){
              cout << "Could not find sensor " << contacts[i] << endl;
              continue;
            }
            sensor->SetActive(false);
            sensor->DisconnectUpdated(sensorConnections[i]);
          }
          sensorConnections.clear();
          printResults();
          exit(0);
        }
    }
Пример #20
0
int main(int argc, char* argv[]){

	char* fileName = argv[1];
	Board board = parseFile(fileName);
	iterateBoard(board);
	printResults(board);
	cleanAll(board);
	return 0;
}
Пример #21
0
int main(int argc, char** argv)
{
	const char* test_name = NULL;
	int i = 1;
	test_suite suite;

	test_runner = run_test_in_child;
	fallback_function = exit_fallback;

	while (i < argc) {
		if (*(argv[i]) != '-') {
			test_name = argv[i];
			break;
		} else {
			switch (*(argv[i]+1)) {
				case 'f':
					test_runner = run_test_in_child;
					break;
				case 's':
					test_runner = run_test;
					break;
				case 'S':
					test_runner = run_test_with_siglongjmp;
					fallback_function = siglongjmp_fallback;
					break;
				case 'v':
					verbose_mode = TRUE;
					break;
				case 'h':
					printUsage(argv[0]);
					return OK;
				default:
					fprintf(stderr, "Invalid option: %s\n", argv[i]);
					printUsage(argv[0]);
					return USAGE;
			}
		}
		++i;
	}

	if (!init_testing()) {
		fprintf(stderr, "Unable to initialize testing runtime\n");
		return TEST_INIT;
	}

	suite = get_suite();

	if (!run_tests(suite, test_name)) {
		return TEST_NOT_FOUND;
	}

	printResults();
	release_suite(suite);

	return (cleanup_testing()) ? OK : TEST_CLEANUP;
}
Пример #22
0
// executed for each packet in the pcap file
void sigproc(int sig) {
  static int called = 0;

  if(called) return; else called = 1;
  shutdown_app = 1;

  closePcapFile();
  printResults(0);
  terminateDetection();
  exit(0);
}
Пример #23
0
/*typedef struct ListDeque ListDeque;
*/
void Run_Tests(){
    int testNum = 1;
    UnitTestResult testResults;
    
    initTestResult(&testResults, testNum++, "testInitListDeque");
    testInitListDeque(&testResults);
    printResults(&testResults);

    initTestResult(&testResults, testNum++, "testaddFrontListDeque");
    testaddFrontListDeque(&testResults);
    printResults(&testResults);

    initTestResult(&testResults, testNum++, "testaddBackListDeque");
    testaddBackListDeque(&testResults);
    printResults(&testResults);

    initTestResult(&testResults, testNum++, "testfreeListDeque");
    testfreeListDeque(&testResults);
    printResults(&testResults);
}
Пример #24
0
void doTests()
{
    int patient;
    char ch;
    float num;
    cin >> ch;
    while (ch >= 'A' && ch <= 'C'){
        cin >> num;
        printResults(ch, num);
        cin >> ch;
   }
}
Пример #25
0
void BellmanFord(struct Graph* graph, int src)
{
    int V = graph->V;
    int E = graph->E;
    int dist[graph->V];
 
	InitializeGraph(dist, V, src);
	RelaxEdges(graph, dist, V, E);
	CheckNegativeWeightCycle(graph, dist, E); 
    printResults(dist, V);
 
}
/**
* The simulateFight function simulates the fight based on the previously entered data
* @param fighterOne the name of the first fighter
* @param fighterTwo the name of the second fighter
* @param fighterOneWinChance the chance of the first fighter winning
* @param fighterTwoWinChance the chance of the second fighter winning
*/
void simFight( char *fighterOne, char *fighterTwo, double fighterOneWinChance, double fighterTwoWinChance ){
    
    int fighterOneWin[SIM_TIMES] = { 0 }; /* array to store if fighter one won */
    int fighterTwoWin[SIM_TIMES] = { 0 }; /* array to store if fighter two won */
    int *fighterOneSuccess = 0; /* the amount of times fighter one won */
    int *fighterTwoSuccess = 0; /* the amount of times fighter two won */
    int i; /* loop contol variable */
    int r; /* random number */
    
    /* uses the time to get the random number */
    srand(time(NULL));
    
    fighterOneWinChance *= 100;
    fighterTwoWinChance *= 100;
    
    /* gets a random number and checks to see if it falls between fighter ones win chance */
    for( i = 0; i < SIM_TIMES; i++ ){
        r = rand() % 100;
        if( r <= (int)fighterOneWinChance ){
            fighterOneWin[i]++;
        }
    }
    
    /* adds one every time the random number fell between fighter ones win chance */
    for( i = 0; i < SIM_TIMES; i++ ){
        if( fighterOneWin[i] > 0 ){
            fighterOneSuccess++;
        }
    }
    
    /* gets a random number and checks to see if it falls between fighter twos win chance */
    for( i = 0; i < SIM_TIMES; i++ ){
        r = rand() % 100;
        if( r <= (int)fighterTwoWinChance ){
            fighterTwoWin[i]++;
        }
    }
    
    /* adds one every time the random number fell between fighter twos win chance */
    for( i = 0; i < SIM_TIMES; i++ ){
        if( fighterTwoWin[i] > 0 ){
            fighterTwoSuccess++;
        }
    }
    
    /* calls the function to print the results */
    printResults( fighterOne, fighterTwo, fighterOneSuccess, fighterTwoSuccess );
    
    #ifdef TEST_FUNCTION
    printf( "Fighter number one won %i times.\n", *fighterOneSuccess );
    printf( "Fighter number two won %i times.\n", *fighterTwoSuccess );
    #endif
}
Пример #27
0
void doDamerauLevenshteinAnalysis(Array<Array<char> >& sourcedata, 
      Array<Array<char> >& templatedata) {
   
   if (xlen <= 0) {
      Array<double> sresults;
      usual_thing(sresults, sourcedata, templatedata);
      printResults(sresults, sourcedata, templatedata);
   } else {
      Array<Array<double> > mresults;
      unusual_thing(mresults, sourcedata, templatedata, xlen);
      printResultsSubString(mresults, sourcedata, templatedata);
   }
}
Пример #28
0
int main() {
    ArtistData artists[MaxCandidates + 1];
    VoteCount count;
    FILE *in = fopen("votes.txt", "r");
    FILE *out = fopen("results.txt", "w");

    initialize(artists, MaxCandidates, in);
    count = processVotes(artists, MaxCandidates, in, out);
    printResults(artists, MaxCandidates, count, out);

    fclose(in);
    fclose(out);
}
Пример #29
0
int main(int argc, char* argv[]) {
  if (argc < 2) {
    fprintf(stderr, "Usage: %s <m> [<numTrials> <alpha> <epsilon>]\n", argv[0]);
    fprintf(stderr, "  m is the problem size\n");
    fprintf(stderr, "  numTrials is the number of trials to run\n");
    fprintf(stderr, "  alpha is the scalar multiplier\n");
    fprintf(stderr, "  epsilon is the tolerance for verification\n");
    exit(0);
  }

  m = atoi(argv[1]);
  if (argc >= 3) {
    numTrials = atoi(argv[2]);
    if (argc >= 4) {
      alpha = atof(argv[3]);
      if (argc >= 5) {
        epsilon = atof(argv[4]);
      }
    }
  }
  

  printConfiguration();
  elemType* const __restrict A = (elemType*)malloc(m*sizeof(elemType));
  elemType* const __restrict B = (elemType*)malloc(m*sizeof(elemType));
  elemType* const __restrict C = (elemType*)malloc(m*sizeof(elemType));
  
  initVectors(B, C);

  double execTime[numTrials];

  int trial;
  for (trial=0; trial<numTrials; trial++) {
    double startTime = getCurrentTime();

    int j;
    double* __restrict APtr = A;
    const double* __restrict BPtr = B;
    const double* __restrict CPtr = C;
    for (j=0; j<m; j++) {
      *(APtr++) = *(BPtr++) + alpha * *(CPtr++);
    }
    
    execTime[trial] = getCurrentTime() - startTime;
  }

  int validAnswer = verifyResults(A, B, C);
  printResults(validAnswer, execTime);

  return 0;
}
Пример #30
0
int Host::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QThread::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: printResults((*reinterpret_cast< QHostInfo(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 1;
    }
    return _id;
}