Esempio n. 1
0
static void bmz8_traverse(bmz8_config_data_t *bmz8, cmph_uint8 * used_edges, cmph_uint32 v, cmph_uint8 * unused_edge_index, cmph_uint8 * visited)
{
	graph_iterator_t it = graph_neighbors_it(bmz8->graph, v);
	cmph_uint32 neighbor = 0;
	while((neighbor = graph_next_neighbor(bmz8->graph, &it)) != GRAPH_NO_NEIGHBOR)
	{
     	        if(GETBIT(visited,neighbor)) continue;
		//DEBUGP("Visiting neighbor %u\n", neighbor);
		*unused_edge_index = next_unused_edge(bmz8, used_edges, *unused_edge_index);
		bmz8->g[neighbor] = (cmph_uint8)(*unused_edge_index - bmz8->g[v]);
		//if (bmz8->g[neighbor] >= bmz8->m) bmz8->g[neighbor] += bmz8->m;
		SETBIT(visited, neighbor);
		(*unused_edge_index)++;
		bmz8_traverse(bmz8, used_edges, neighbor, unused_edge_index, visited);

	}
}
Esempio n. 2
0
static void chm_traverse(chm_config_data_t *chm, cmph_uint8 *visited, cmph_uint32 v)
{

    graph_iterator_t it = graph_neighbors_it(chm->graph, v);
    cmph_uint32 neighbor = 0;
    SETBIT(visited,v);

    DEBUGP("Visiting vertex %u\n", v);
    while((neighbor = graph_next_neighbor(chm->graph, &it)) != GRAPH_NO_NEIGHBOR)
    {
        DEBUGP("Visiting neighbor %u\n", neighbor);
        if(GETBIT(visited,neighbor)) continue;
        DEBUGP("Visiting neighbor %u\n", neighbor);
        DEBUGP("Visiting edge %u->%u with id %u\n", v, neighbor, graph_edge_id(chm->graph, v, neighbor));
        chm->g[neighbor] = graph_edge_id(chm->graph, v, neighbor) - chm->g[v];
        DEBUGP("g is %u (%u - %u mod %u)\n", chm->g[neighbor], graph_edge_id(chm->graph, v, neighbor), chm->g[v], chm->m);
        chm_traverse(chm, visited, neighbor);
    }
}
Esempio n. 3
0
static cmph_uint8 bmz8_traverse_critical_nodes_heuristic(bmz8_config_data_t *bmz8, cmph_uint32 v, cmph_uint8 * biggest_g_value, cmph_uint8 * biggest_edge_value, cmph_uint8 * used_edges, cmph_uint8 * visited)
{
        cmph_uint8 next_g;
	cmph_uint32 u;
	cmph_uint32 lav;
	cmph_uint8 collision;
	cmph_uint8 * unused_g_values = NULL;
	cmph_uint8 unused_g_values_capacity = 0;
	cmph_uint8 nunused_g_values = 0;
	vqueue_t * q = vqueue_new((cmph_uint32)(graph_ncritical_nodes(bmz8->graph)));
	graph_iterator_t it, it1;

	DEBUGP("Labelling critical vertices\n");
	bmz8->g[v] = (cmph_uint8)(ceil ((double)(*biggest_edge_value)/2) - 1);
	SETBIT(visited, v);
	next_g    = (cmph_uint8)floor((double)(*biggest_edge_value/2));
	vqueue_insert(q, v);
	while(!vqueue_is_empty(q))
	{
		v = vqueue_remove(q);
		it = graph_neighbors_it(bmz8->graph, v);
		while ((u = graph_next_neighbor(bmz8->graph, &it)) != GRAPH_NO_NEIGHBOR)
		{
               	        if (graph_node_is_critical(bmz8->graph, u) && (!GETBIT(visited,u)))
			{
			        cmph_uint8 next_g_index = 0;
			        collision = 1;
			        while(collision) // lookahead to resolve collisions
				{
				        if (next_g_index < nunused_g_values)
					{
					        next_g = unused_g_values[next_g_index++];
					}
					else
					{
					        next_g = (cmph_uint8)(*biggest_g_value + 1);
						next_g_index = 255;//UINT_MAX;
					}
					it1 = graph_neighbors_it(bmz8->graph, u);
					collision = 0;
					while((lav = graph_next_neighbor(bmz8->graph, &it1)) != GRAPH_NO_NEIGHBOR)
					{
  					        if (graph_node_is_critical(bmz8->graph, lav) && GETBIT(visited,lav))
						{
   						        if(next_g + bmz8->g[lav] >= bmz8->m)
							{
							        vqueue_destroy(q);
								free(unused_g_values);
								return 1; // restart mapping step.
							}
							if (GETBIT(used_edges, (next_g + bmz8->g[lav])))
							{
							        collision = 1;
								break;
							}
						}
					}
					if(collision && (next_g > *biggest_g_value)) // saving the current g value stored in next_g.
					{
					        if(nunused_g_values == unused_g_values_capacity)
						{
							unused_g_values = (cmph_uint8*)realloc(unused_g_values, ((size_t)(unused_g_values_capacity + BUFSIZ))*sizeof(cmph_uint8));
						        unused_g_values_capacity += (cmph_uint8)BUFSIZ;
						}
						unused_g_values[nunused_g_values++] = next_g;

					}
 					if (next_g > *biggest_g_value) *biggest_g_value = next_g;
				}

				next_g_index--;
				if (next_g_index < nunused_g_values) unused_g_values[next_g_index] = unused_g_values[--nunused_g_values];

				// Marking used edges...
				it1 = graph_neighbors_it(bmz8->graph, u);
				while((lav = graph_next_neighbor(bmz8->graph, &it1)) != GRAPH_NO_NEIGHBOR)
				{
                 		        if (graph_node_is_critical(bmz8->graph, lav) && GETBIT(visited, lav))
					{
                   			        SETBIT(used_edges,(next_g + bmz8->g[lav]));
						if(next_g + bmz8->g[lav] > *biggest_edge_value)
                                                    *biggest_edge_value = (cmph_uint8)(next_g + bmz8->g[lav]);
					}
				}

				bmz8->g[u] = next_g; // Labelling vertex u.
				SETBIT(visited, u);
			      	vqueue_insert(q, u);

			}
	        }

	}
	vqueue_destroy(q);
	free(unused_g_values);
	return 0;
}
Esempio n. 4
0
static cmph_uint8 bmz8_traverse_critical_nodes(bmz8_config_data_t *bmz8, cmph_uint32 v, cmph_uint8 * biggest_g_value, cmph_uint8 * biggest_edge_value, cmph_uint8 * used_edges, cmph_uint8 * visited)
{
        cmph_uint8 next_g;
	cmph_uint32 u;   /* Auxiliary vertex */
	cmph_uint32 lav; /* lookahead vertex */
	cmph_uint8 collision;
	vqueue_t * q = vqueue_new((cmph_uint32)(graph_ncritical_nodes(bmz8->graph)));
	graph_iterator_t it, it1;

	DEBUGP("Labelling critical vertices\n");
	bmz8->g[v] = (cmph_uint8)(ceil ((double)(*biggest_edge_value)/2) - 1);
	SETBIT(visited, v);
	next_g    = (cmph_uint8)floor((double)(*biggest_edge_value/2)); /* next_g is incremented in the do..while statement*/
	vqueue_insert(q, v);
	while(!vqueue_is_empty(q))
	{
		v = vqueue_remove(q);
		it = graph_neighbors_it(bmz8->graph, v);
		while ((u = graph_next_neighbor(bmz8->graph, &it)) != GRAPH_NO_NEIGHBOR)
		{
               	        if (graph_node_is_critical(bmz8->graph, u) && (!GETBIT(visited,u)))
			{
			        collision = 1;
			        while(collision) // lookahead to resolve collisions
				{
 				        next_g = (cmph_uint8)(*biggest_g_value + 1);
					it1 = graph_neighbors_it(bmz8->graph, u);
					collision = 0;
					while((lav = graph_next_neighbor(bmz8->graph, &it1)) != GRAPH_NO_NEIGHBOR)
					{
  					        if (graph_node_is_critical(bmz8->graph, lav) && GETBIT(visited,lav))
						{
   						        if(next_g + bmz8->g[lav] >= bmz8->m)
							{
							        vqueue_destroy(q);
								return 1; // restart mapping step.
							}
							if (GETBIT(used_edges, (next_g + bmz8->g[lav])))
							{
							        collision = 1;
								break;
							}
						}
					}
 					if (next_g > *biggest_g_value) *biggest_g_value = next_g;
				}
				// Marking used edges...
				it1 = graph_neighbors_it(bmz8->graph, u);
				while((lav = graph_next_neighbor(bmz8->graph, &it1)) != GRAPH_NO_NEIGHBOR)
				{
                 		        if (graph_node_is_critical(bmz8->graph, lav) && GETBIT(visited, lav))
					{
                   			        SETBIT(used_edges,(next_g + bmz8->g[lav]));

						if(next_g + bmz8->g[lav] > *biggest_edge_value)
                                                    *biggest_edge_value = (cmph_uint8)(next_g + bmz8->g[lav]);
					}
				}
				bmz8->g[u] = next_g; // Labelling vertex u.
				SETBIT(visited,u);
			        vqueue_insert(q, u);
			}
	        }

	}
	vqueue_destroy(q);
	return 0;
}