Example #1
0
/**
 * Resize method that calls Dijkstra algorithm for each Vertex inside
 * the Vertexes set of the Graph
 */
void graph_shortest_path(PPMImage *image, int *path)
{
    Graph graph;
    init_graph(&graph, image);
    pri_queue_t priq_s;
    priq_init(&priq_s, graph.list_size);

    int i, x, y, dest;
    Energy *distance = calloc(graph.list_size, sizeof(Energy));
    int *previous = calloc(graph.list_size, sizeof(int));
    Energy shortest_distance;
    shortest_distance = ENERGY_MAX;

    for(x = 0; x < image->width; x++)
    {
        i = XY2POS(image, x, image->height - 1);

        dest = dijkstra(&graph, i, &priq_s,
                distance, previous, shortest_distance);

#ifdef OPT_GRAPH_SHORTEST_PATH_BREAK
        if(dest == BREAK)
            continue;
        else
#endif
            if(dest < 0)
            {
                fprintf(stderr, "There is no path\n");
                exit(EXIT_FAILURE);
            }

        if (distance[dest] < shortest_distance)
        {
            shortest_distance = distance[dest];
            y = 0;
            while(dest != i)
            {
                path[y++] = POS2X(dest, image);
                dest = previous[dest];
            }
            path[y] = POS2X(i, image);
            // assert path length
            ASSERT_TRUE(y == image->height - 1,
                    fprintf(stderr,
                            "ASSERT: Path length error (must to be %d): %d\n",
                            image->height - 1, y)
            );
        }
    }

    priq_free(&priq_s);
    free_graph(&graph);
    free(distance);
    free(previous);
}
Example #2
0
void
pktsched_init(void)
{
	init_machclk();
	if (machclk_freq == 0) {
		panic("%s: no CPU clock available!\n", __func__);
		/* NOTREACHED */
	}

	tcq_init();
	qfq_init();
#if PKTSCHED_PRIQ
	priq_init();
#endif /* PKTSCHED_PRIQ */
#if PKTSCHED_FAIRQ
	fairq_init();
#endif /* PKTSCHED_FAIRQ */
#if PKTSCHED_CBQ
	cbq_init();
#endif /* PKTSCHED_CBQ */
#if PKTSCHED_HFSC
	hfsc_init();
#endif /* PKTSCHED_HFSC */
}