コード例 #1
0
ファイル: Turnel1.c プロジェクト: sanghoon66/SoCRobotWar
TSEND CTurnel1::Missioning(_us (*img)[256], int now){
	switch(now){
	case 0:
		m_send = Step2(img);
		break;
	case 1:
		m_send = Step3(img);
		break;
	case 2:
		m_send = Step3(img);
		break;
	case 3:
		m_send = Step4(img);
		break;
	}
	return m_send;
}
コード例 #2
0
ファイル: edgeColor4.cpp プロジェクト: pantuza/mestrado
    int edge_coloring(FILE *file, FILE *out)
    {
        int i,j;

        fscanf(file, "%d %d",&n,&m);
        for (i=0;i<n;i++)
            vertexDegree[i]=0;
        for (i=0;i<m;i++)
        {
            fscanf(file, "%d %d",&firstVertex[i],&secondVertex[i]);
            vertexDegree[firstVertex[i]]++;
            vertexDegree[secondVertex[i]]++;
        }

        //Step 1

        degree=vertexDegree[0];
        for (i=1;i<n;i++)
            if (degree<vertexDegree[i])
                degree=vertexDegree[i];

        for (i=0;i<n;i++)
            for (j=1;j<=degree+1;j++)
                vertexAcrossColor[i][j]=(-1);

        // Step 2
        for (i=0;i<m;i++)
            Step3(firstVertex[i],secondVertex[i]);

        int colors[100];
        for(i=0;i<100;i++)
            colors[i] = 0;

        //Output results
        DEBUG1(printf("Edge & color\n"));
        if (out != NULL)
            fprintf(out, "%d %d\n", n,m);
        for (i=0;i<n;i++)
            for (j=1;j<=degree+1;j++)
                if (vertexAcrossColor[i][j]>i)
                {
                    colors[j]++;
                    DEBUG1(printf("%d %d %d\n",i,vertexAcrossColor[i][j],j));
                    if (out != NULL)
                        fprintf(out,"%d %d %d\n",i,vertexAcrossColor[i][j],j);
                }

        int numColors = 0;
        for(i=0;i<100;i++)
            if(colors[i] > 0)
                numColors++;
        return numColors;

    }
コード例 #3
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;
}