コード例 #1
0
ファイル: maiallocator.cpp プロジェクト: rongals/CRAI
void MAIAllocator::Finish() {

  gsl_vector_complex_free(Hchan);
  gsl_matrix_complex_free(Hmat);
  gsl_matrix_complex_free(huu);
  gsl_matrix_uint_free(Hperm);
  gsl_permutation_free(p);
  gsl_vector_free(huserabs);
  gsl_vector_uint_free(nextcarr);
  gsl_vector_uint_free( usedcarr);
  gsl_vector_uint_free( errs );
  gsl_matrix_free(habs);

  gsl_matrix_uint_free(signature_frequencies);
  gsl_matrix_uint_free(signature_frequencies_init);

  gsl_matrix_free(signature_powers);

  gsl_rng_free(ran);

  gsl_matrix_complex_free(transform_mat);


  switch (Mode()) {
    
  case 4:
    // destroy the Kernel
    pKernel->Shutdown() ;
    delete pKernel;    
    break;
  }    

}
コード例 #2
0
ファイル: hungarian.cpp プロジェクト: bengheng/Expose
/*!
Computes assignment matrix for M.
*/
int Hungarian(const gsl_matrix * const M, const bool convToMinAsg,
              gsl_matrix * const Assignment)
{
	int res, z0_r, z0_c;
	bool done = false;
	unsigned int next = STEP1;
	gsl_vector_uint *rowCov, *colCov;
	gsl_matrix_uint *mask;
	gsl_matrix_int  *path;
	gsl_matrix *MCopy;

	MCopy = gsl_matrix_alloc(M->size1, M->size2);
	gsl_matrix_memcpy(MCopy, M);
	if(convToMinAsg == true)
	{
		res = ConvertToMinAsg(MCopy);
		if(res != GSL_SUCCESS) return res;
	}

	// Allocate memory
	rowCov = gsl_vector_uint_alloc(M->size1);
	colCov = gsl_vector_uint_alloc(M->size2);
	mask = gsl_matrix_uint_alloc(M->size1, M->size2);
	path = gsl_matrix_int_calloc(ceil(((float)(mask->size1*mask->size2))/2), 2 );

	// Initialize
	gsl_vector_uint_set_all(rowCov, UNCOVERED);
	gsl_vector_uint_set_all(colCov, UNCOVERED);
	gsl_matrix_uint_set_all(mask, UNMASKED);

	while(done == false)
	{
		switch(next)
		{
			case STEP1:
				next = Step1(MCopy);
				#ifdef VERBOSE
					Matrix_print_with_mask(MCopy, mask, rowCov, colCov, "Post Step 1");
					PrintCover( rowCov, colCov, "Post Step 1 Cover");
				#endif
				break;
			case STEP2:
				next = Step2(MCopy, mask, rowCov, colCov);
				#ifdef VERBOSE
					Matrix_print_with_mask(MCopy, mask, rowCov, colCov, "Post Step 2");
					PrintCover( rowCov, colCov, "Post Step 2 Cover");
				#endif
				break;
			case STEP3:
				next = Step3(MCopy, mask, colCov);
				#ifdef VERBOSE
					Matrix_print_with_mask(MCopy, mask, rowCov, colCov, "Post Step 3");
					PrintCover( rowCov, colCov, "Post Step 3 Cover");
				#endif
				break;
			case STEP4:
				next = Step4(MCopy, mask, rowCov, colCov, &z0_r, &z0_c);
				#ifdef VERBOSE
					Matrix_print_with_mask(MCopy, mask, rowCov, colCov, "Post Step 4");
					PrintCover( rowCov, colCov, "Post Step 4 Cover");
				#endif
				break;
			case STEP5:
				next = Step5(mask, path, rowCov, colCov, z0_r, z0_c); 
				#ifdef VERBOSE
					Matrix_print_with_mask(MCopy, mask, rowCov, colCov, "Post Step 5");
					PrintCover( rowCov, colCov, "Post Step 5 Cover");
				#endif
				break;
			case STEP6:
				next = Step6(MCopy, rowCov, colCov);
				#ifdef VERBOSE
					Matrix_print_with_mask(MCopy, mask, rowCov, colCov, "Post Step 6");
					PrintCover( rowCov, colCov, "Post Step 6 Cover");
				#endif
				break;
			case DONE:
				#ifdef VERBOSE
					Matrix_print_with_mask(MCopy, mask, rowCov, colCov, "DONE");
				#endif
				UpdateAssignment(mask, Assignment);
				done = true;
				break;
			default:
				done = true;
				fprintf(stderr, "Error!\n");
		}
	}

	// Release memory
	gsl_matrix_free(MCopy);
	gsl_vector_uint_free(rowCov);
	gsl_vector_uint_free(colCov);
	gsl_matrix_uint_free(mask);
	gsl_matrix_int_free(path);

	return GSL_SUCCESS;
}
コード例 #3
0
ファイル: main.cpp プロジェクト: bengheng/Expose
int main(int argc, char **argv)
{
	FILE *fid;
	int choice;
	// gsl_matrix_complex *A, *B;
	gsl_matrix *A = NULL, *B = NULL;
	gsl_matrix_uint *Assignment;
	float score;
	unsigned int testcount, steps;
	struct timeval start, stop, elapsed;

	//if((argc != 2 && atoi(argv[1]) != 8) || (argc != 3 && atoi(argv[1]) == 8))
	if(argc != 2)
	{
		printf("Enter test case #.\n");
		return 0;
	}

	fid = fopen("perfd.log", "w");
	if(fid == NULL)
		return 0;

	for(steps = 50; steps <= 1000; steps += 50)
	{
		for(testcount = 0; testcount < 10; testcount++)
		{
			if((gettimeofday(&start, NULL)) == -1)
			{
				perror("gettimeofday");
				exit(1);
			}

			choice = atoi(argv[1]);
			switch(choice)
			{
				case 1:
					//testcase1(&A, &B);
					break;
				case 2:	testcase2(&A, &B); break;
				case 3: testcase3(&A, &B); break;
				case 4: testcase4(&A, &B); break;
				case 5: testcase5(&A, &B); break;
				case 6: testcase6(&A, &B); break;
				case 7: testcase7(&A, &B); break;
				case 8: testcase8(&A, &B, steps); break;
				default:
					printf("Invalid choice.\n");
					return 0;
			}

			if(A != NULL && B != NULL)
			{	
				//PrintGSLMatrixComplex(A, "Input A");
				//PrintGSLMatrixComplex(B, "Input B");
				Assignment = gsl_matrix_uint_alloc(A->size1, A->size2);
				//EigenDecomp(A, B, P);
				score = 0;
				Umeyama(A, B, Assignment, &score);
				//PrintGSLMatrixUint(Assignment, "Assignment");
	
				//printf("SCORE: %f\n", score);
	
				if((gettimeofday(&stop, NULL)) == -1)
				{
					perror("gettimeofday");
					exit(1);
				}

				// Compute elapsed time
				timeval_subtract(&elapsed, &stop, &start);
				fprintf(stderr, "%d\t%d\t%ld\n", steps, testcount, elapsed.tv_sec*1000000 + elapsed.tv_usec);
				fprintf(fid, "%d\t%d\t%ld\n", steps, testcount, elapsed.tv_sec*1000000 + elapsed.tv_usec);
				fflush(stderr); fflush(fid);

				gsl_matrix_uint_free(Assignment);
				//gsl_matrix_complex_free(A);
				//gsl_matrix_complex_free(B);
				gsl_matrix_free(A);
				gsl_matrix_free(B);
			}
		}
	}
	fclose(fid);

	return 0;
}