コード例 #1
0
ファイル: gl_state.cpp プロジェクト: LibreGames/bear
/**
 * \brief Builds a collection of vertices representing a given polygon as a
 *        collection of triangles.
 * \param v The vertices of the polygon to convert.
 */
bear::visual::gl_state::position_vector
bear::visual::gl_state::polygon_to_triangles( const position_vector& v ) const
{
  CLAW_PRECOND( v.size() >= 3 );

  position_vector result;
  result.reserve( 3 * (v.size() - 2) );

  const position_vector::const_iterator root_vertex( v.begin() );
  position_vector::const_iterator first_vertex( root_vertex + 1 );
  position_vector::const_iterator second_vertex( root_vertex + 2 );

  do
    {
      result.push_back( *root_vertex );
      result.push_back( *first_vertex );
      result.push_back( *second_vertex );

      ++first_vertex;
      ++second_vertex;
    }
  while ( second_vertex != v.end() );

  return result;
} // gl_state::polygon_to_triangles()
コード例 #2
0
/*
 * 深度优先搜索遍历图的递归实现
 */
static void DFS(Graph G, int i, int *visited)
{                                   
    int w; 

    visited[i] = 1;
    printf("%c ", G.vexs[i]);
    // 遍历该顶点的所有邻接顶点。若是没有访问过,那么继续往下走
    for (w = first_vertex(G, i); w >= 0; w = next_vertix(G, i, w))
    {
        if (!visited[w])
            DFS(G, w, visited);
    }
       
}
コード例 #3
0
int main(int argc, char const* argv[]) {
    if (argc < 2) {
        std::cout << "usage: " << argv[0] << " num_vertices < input\n";
        return EXIT_FAILURE;
    }

    unsigned int num_vertices = boost::lexical_cast<unsigned int>(argv[1]);
    std::istream_iterator<unsigned int> first_vertex(std::cin), last_vertex;
    boost::directed_graph<> graph;
    build_graph(graph, num_vertices, first_vertex, last_vertex);

    cycle_printer<std::ostream> visitor(std::cout);
    boost::hawick_circuits(graph, visitor);

    return EXIT_SUCCESS;
}
コード例 #4
0
/*
 * 广度优先搜索(类似于树的层次遍历)
 */
void BFS(Graph G)
{
    int head = 0;
    int rear = 0;
    int queue[MAX];     // 辅组队列
    int visited[MAX];   // 顶点访问标记
    int i, j, k;

    for (i = 0; i < G.vexnum; i++)
        visited[i] = 0;

    printf("BFS: ");
    for (i = 0; i < G.vexnum; i++)
    {
        if (!visited[i])
        {
            visited[i] = 1;
            printf("%c ", G.vexs[i]);
            queue[rear++] = i;  // 入队列
        }
        while (head != rear) 
        {
            j = queue[head++];  // 出队列
            for (k = first_vertex(G, j); k >= 0; k = next_vertix(G, j, k)) //k是为访问的邻接顶点
            {
                if (!visited[k])
                {
                    visited[k] = 1;
                    printf("%c ", G.vexs[k]);
                    queue[rear++] = k;
                }
            }
        }
    }
    printf("\n");
}
コード例 #5
0
ファイル: antcol.c プロジェクト: CarlaNL/Projeto
static void ant_rlf(gcp_solution_t *sol, gcp_t *problem) {/*{{{*/

	int i, j;
	int colornumber = 0;	/* number of colors used */
	int colored = 0;		/* number of colored vertex */
	int v, new_v;			/* vertex to be colored */
	int nn;					/* keep number of non-neighbors of v */
	double *probb;			/* probabilities for choosing a vertex */
	
/*{{{*/
	static int *degree = NULL;
	static int **adj = NULL;
	static int *ctr = NULL;
	if (!ctr) {
		degree = malloc_(sizeof(int) * problem->size);
		adj = malloc_(sizeof(int*) * problem->size);
	}

	for (i = 0; i < problem->size; i++) {
		degree[i] = problem->degree[i];

		if (!ctr) {
			adj[i] = malloc(sizeof(int) * problem->size);
		}

		for (j = 0; j < problem->size; j++) {
			adj[i][j] = problem->adj[i][j];
//			adj[j][i] = problem->adj[j][i];
		}
	}
	ctr = degree;
/*}}}*/

	while (colored < problem->size) {

		v = first_vertex(degree, problem->size);

		sol->color[v] = colornumber;
        sol->nodes_color[colornumber]++;
		colored++;

		nn = problem->size - degree[v] - 1;
		for (i = 0; i < problem->size; i++) {
			if (!adj[v][i] && (degree[i] == OUT)) {
				nn--;
			}
		}

		while (nn > 0) {
			
            /* choose new_v, non neighbor of v that is not OUT with probability p */
			/*
            probb = calculate_probbs(v, problem->size, colornumber, degree, 
							adj, sol->color, problem->alpha, problem->beta);
	        new_v = choose_vertex(probb, problem->size);
			*/
			new_v = 0;
            while (v==new_v || (degree[new_v]==OUT) || adj[new_v][v]) new_v++;
			for (i = new_v; i < problem->size; i++) {
				if ((i != v) && !adj[v][i] && (degree[i] != OUT) && (degree[i] > degree[new_v]))
					new_v = i;						
			}
			

			sol->color[new_v] = colornumber;
			sol->nodes_color[colornumber]++;
			colored++;

			contract(v, new_v, degree, adj, problem->size, &nn);

			nn--;

		}

		remove_(v, degree, adj, problem->size);
		colornumber++;

	}

	sol->spent_time = current_usertime_secs();
	sol->ncolors = colornumber;

}/*}}}*/