Esempio n. 1
0
int
cook_web(string_list_ty *wlp)
{
    int             retval;
    graph_ty        *gp;
    graph_build_status_ty gb_status;

    /*
     * set interrupts to catch
     *
     * Note that tee(1) [see listing.c] must ignore them
     * for the generated messages to appear in the log file.
     */
    trace(("cook(wlp = %08lX)\n{\n", wlp));
    desist_enable();

    /*
     * Build the dependency graph.
     */
    retval = 0;
    gp = graph_new();
    gb_status = graph_build_list(gp, wlp, graph_build_preference_error, 0);
    if (option_test(OPTION_REASON))
        graph_print_statistics(gp);
    switch (gb_status)
    {
    case graph_build_status_error:
        retval = 1;
        break;

    case graph_build_status_backtrack:
        /* assert(0); */
        retval = 1;
        break;

    case graph_build_status_success:
        break;
    }

    /*
     * Walk the dependency graph.
     */
    if (retval == 0)
        graph_walk_web(gp);

    /*
     * Release any resources held by the graph.
     */
    graph_delete(gp);

    /*
     * Return the result to the caller.
     */
    trace(("return %d;\n", retval));
    trace(("}\n"));
    return retval;
}
Esempio n. 2
0
//  Frees the list allocated memory
void destroy_list(node **n) {
  node *current = *n;
  node *temp;
  while (current != NULL) {
    temp = current->next;
    graph_delete(current->bank_account);
    free(current);
    current = temp;
  }
  *n = NULL;
}
Esempio n. 3
0
int main()
{
    int t;
    int s;
    for(s=0;s<10;s++) {
	int width = (lrand48()%8)+1;
	graph_t*g = graph_new(width*width);
	for(t=0;t<width*width;t++) {
	    int x = t%width;
	    int y = t/width;
	    int w = 1;
#define R (lrand48()%32)
	    if(x>0) graph_add_edge(&g->nodes[t], &g->nodes[t-1], R, R);
	    if(x<width-1) graph_add_edge(&g->nodes[t], &g->nodes[t+1], R, R);
	    if(y>0) graph_add_edge(&g->nodes[t], &g->nodes[t-width], R, R);
	    if(y<width-1) graph_add_edge(&g->nodes[t], &g->nodes[t+width], R, R);
	}
	
	int x = graph_maxflow(g, &g->nodes[0], &g->nodes[width*width-1]);
	printf("max flow: %d\n", x);
	graph_delete(g);
    }
}
Esempio n. 4
0
void graphtest_write(void)
{
  struct graph *graph;
  
  graph = graph_new("traffic", 400, 160, GRAPH_TYPE_LINE);

/*  graph_colorize(graph, GRAPH_COLOR_DARK);
  
  graph_source_add(graph, GRAPH_MEASURE_DIFFTIME,
                   GRAPH_SOURCE_UINT, &bytes_in, "in");
  
  graph_source_add(graph, GRAPH_MEASURE_DIFFTIME, 
                   GRAPH_SOURCE_UINT, &bytes_out, "out");

  graph_drain_add(graph, GRAPH_DATA_HOURLY);
  graph_drain_add(graph, GRAPH_DATA_DAILY);
  graph_drain_add(graph, GRAPH_DATA_WEEKLY);
  graph_drain_add(graph, GRAPH_DATA_MONTHLY);
  
  graph_drain_render(graph, GRAPH_DATA_HOURLY);
  graph_drain_save(graph, GRAPH_DATA_HOURLY);
  */
  graph_delete(graph);
}
Esempio n. 5
0
GPH_ERR_E matrix_main (void)
{
   void* vtx;
   //char* saveptr = NULL;
   GRAPH_T* g;
   EDGE_T* e;
   unsigned long no;
   char* ctx = NULL;
   
   g = matrix_create (10, 10);
   //graph_edge_print (g);
   //graph_vertex_print (g);

   vtx = graph_vertex_find_i (g, 1);
   if (NULL == vtx)
   {
      fprintf (stderr, "vertext not found\n");
      return GPH_ERR_ERR;
   }
   no = 0;
   while (no < ((VTX_UD_T*)vtx)->no)
   {
      e = graph_vertex_next_edge_get (g, vtx, &ctx);
      DEBUG_EDGE_PRINT_I(g,e);
      no++;
   }
   fprintf (stderr, "Starting BFS\n");
   bfs (g, 100, bfs_vertex_func);

   tc_graph_edge_print (g);
   graphviz_description (g, "graph.lst");
   //fprintf (stderr, "Starting DFS\n");
   //dfs (g, 2, bfs_vertex_func);
   graph_delete (g);
   return GPH_ERR_OK;
}
Esempio n. 6
0
int
cook_auto_required(void)
{
    int             retval;
    graph_ty        *gp;
    graph_build_status_ty gb_status;
    graph_walk_status_ty gw_status;
    size_t          j;

    /*
     * This may have been explicitly forbidden on the command line.
     */
    if (!option_test(OPTION_INCLUDE_COOKED))
        return 0;

    retval = 0;

    option_set(OPTION_ACTION, OPTION_LEVEL_AUTO, 1);
    option_set(OPTION_TOUCH, OPTION_LEVEL_AUTO, 0);
    option_set(OPTION_REASON, OPTION_LEVEL_COOKBOOK, 0);

    /*
     * Build the dependency graph.
     */
    gp = graph_new();
    if
    (
        !option_test(OPTION_SILENT)
    &&
        option_test(OPTION_INCLUDE_COOKED_WARNING)
    )
        gp->file_pair = graph_file_pair_new(&cook_auto_list);
    gb_status =
        graph_build_list
        (
            gp,
            &cook_auto_list,
            graph_build_preference_error,
            0   /* not primary, no up-to-date commentary */
        );
    if (option_test(OPTION_REASON))
        graph_print_statistics(gp);
    switch (gb_status)
    {
    case graph_build_status_error:
        retval = -1;
        break;

    case graph_build_status_backtrack:
        /* assert(0); */
        retval = -1;
        break;

    case graph_build_status_success:
        break;
    }

    /*
     * Build a list of non-leaf cook-auto files.
     */
    string_list_destructor(&cook_auto_list_nonleaf);
    for (j = 0; j < cook_auto_list.nstrings; ++j)
    {
        string_ty       *fn;

        fn = cook_auto_list.string[j];
        if (!graph_file_leaf_p(gp, fn))
            string_list_append(&cook_auto_list_nonleaf, fn);
    }

    /*
     * Walk the dependency graph.
     */
    if (retval == 0)
    {
        gw_status = graph_walk(gp);
        switch (gw_status)
        {
        case graph_walk_status_uptodate:
        case graph_walk_status_uptodate_done:
            break;

        case graph_walk_status_done:
            retval = 1;
            break;

        case graph_walk_status_done_stop:
        case graph_walk_status_wait:
            assert(0);
            /* fall through... */

        case graph_walk_status_error:
            retval = -1;
            break;
        }
    }

    /*
     * Release any resources held by the graph.
     */
    graph_delete(gp);

    option_undo(OPTION_REASON, OPTION_LEVEL_COOKBOOK);
    option_undo(OPTION_ACTION, OPTION_LEVEL_AUTO);
    option_undo(OPTION_TOUCH, OPTION_LEVEL_AUTO);

    return retval;
}
Esempio n. 7
0
int
cook(string_list_ty *wlp)
{
    int             retval;
    graph_ty        *gp;
    graph_build_status_ty gb_status;
    graph_walk_status_ty gw_status;

    /*
     * set interrupts to catch
     *
     * Note that tee(1) [see listing.c] must ignore them
     * for the generated messages to appear in the log file.
     */
    trace(("cook(wlp = %08lX)\n{\n", wlp));
    desist_enable();

    /*
     * Build the dependency graph.
     */
    retval = 0;
    gp = graph_new();
    if
    (
        cook_auto_list_nonleaf.nstrings > 0
    &&
        cascade_used()
    &&
        option_test(OPTION_CASCADE)
    &&
        !option_test(OPTION_SILENT)
    &&
        option_test(OPTION_INCLUDE_COOKED_WARNING)
    )
    {
        gp->file_pair = graph_file_pair_new((string_list_ty *) 0);
        graph_file_pair_foreign_derived(gp->file_pair, &cook_auto_list_nonleaf);
    }
    gb_status = graph_build_list(gp, wlp, graph_build_preference_error, 1);
    if (option_test(OPTION_REASON))
        graph_print_statistics(gp);
    switch (gb_status)
    {
    case graph_build_status_error:
        retval = 1;
        break;

    case graph_build_status_backtrack:
        /* assert(0); */
        retval = 1;
        break;

    case graph_build_status_success:
        break;
    }

    /*
     * Walk the dependency graph.
     */
    if (retval == 0)
    {
        gw_status = graph_walk(gp);
        switch (gw_status)
        {
        case graph_walk_status_uptodate:
        case graph_walk_status_uptodate_done:
        case graph_walk_status_done:
            break;

        case graph_walk_status_done_stop:
        case graph_walk_status_wait:
            assert(0);
            /* fall through... */

        case graph_walk_status_error:
            retval = 1;
            break;
        }
    }

    /*
     * Release any resources held by the graph.
     */
    graph_delete(gp);

    /*
     * Return the result to the caller.
     */
    trace(("return %d;\n", retval));
    trace(("}\n"));
    return retval;
}
Esempio n. 8
0
int main(){
	struct graph* 	graph;
	struct graph* 	clone;
	char 			node_desc[NODE_DESCRIPTION_LENGTH];
	char 			edge_desc[EDGE_DESCRIPTION_LENGTH];
	struct node* 	node_asterix;
	struct node* 	node_obelix;
	struct node* 	node_idefix;
	struct node* 	node_abraracourcix;

	graph = graph_create(NODE_DESCRIPTION_LENGTH, EDGE_DESCRIPTION_LENGTH);
	graph_register_dotPrint_callback(graph, NULL, asterix_dotPrint_node, asterix_dotPrint_edge, NULL)

	/* add nodes */
	snprintf(node_desc, NODE_DESCRIPTION_LENGTH, "asterix");
	node_asterix = graph_add_node(graph, &node_desc);
	if (node_asterix == NULL){
		log_err("unable to add node to graph");
	}

	snprintf(node_desc, NODE_DESCRIPTION_LENGTH, "obelix");
	node_obelix = graph_add_node(graph, &node_desc);
	if (node_obelix == NULL){
		log_err("unable to add node to graph");
	}

	snprintf(node_desc, NODE_DESCRIPTION_LENGTH, "idefix");
	node_idefix = graph_add_node(graph, &node_desc);
	if (node_idefix == NULL){
		log_err("unable to add node to graph");
	}

	snprintf(node_desc, NODE_DESCRIPTION_LENGTH, "abraracourcix");
	node_abraracourcix = graph_add_node(graph, &node_desc);
	if (node_abraracourcix == NULL){
		log_err("unable to add node to graph");
	}

	/* add edges */
	snprintf(edge_desc, EDGE_DESCRIPTION_LENGTH, "friend");
	if (graph_add_edge(graph, node_obelix, node_asterix, &edge_desc) == NULL){
		log_err("unable to add edge to graph");
	}

	snprintf(edge_desc, EDGE_DESCRIPTION_LENGTH, "obey");
	if (graph_add_edge(graph, node_idefix, node_obelix, &edge_desc) == NULL){
		log_err("unable to add edge to graph");
	}

	snprintf(edge_desc, EDGE_DESCRIPTION_LENGTH, "rule");
	if (graph_add_edge(graph, node_abraracourcix, node_obelix, &edge_desc) == NULL){
		log_err("unable to add edge to graph");
	}

	snprintf(edge_desc, EDGE_DESCRIPTION_LENGTH, "rule");
	if (graph_add_edge(graph, node_abraracourcix, node_asterix, &edge_desc) == NULL){
		log_err("unable to add edge to graph");
	}

	clone = graph_clone(graph, asterix_copy_node, asterix_copy_edge, NULL);

	graph_delete(graph);

	/* print graph */
	if (graphPrintDot_print(clone, "asterix.dot", NULL)){
		log_err("unable to print graph to dot format");
	}

	graph_delete(clone);

	return 0;
}
Esempio n. 9
0
static int
interpret(string_list_ty *result, const string_list_ty *args,
    const struct expr_position_ty *pp, const struct opcode_context_ty *ocp)
{
    size_t          j;
    int             retval;
    graph_ty        *gp;

    (void)pp;
    (void)ocp;
    if (args->nstrings <= 1)
        return 0;

    /*
     * set interrupts to catch
     *
     * Note that tee(1) [see listing.c] must ignore them
     * for the generated messages to appear in the log file.
     */
    trace(("cando\n"));
    assert(result);
    assert(args);
    assert(args->nstrings);
    retval = 0;
    desist_enable();

    /*
     * build the graph
     */
    gp = graph_new();
    for (j = 1; j < args->nstrings; ++j)
    {
        graph_build_status_ty gb_status;

        /*
         * Build the dependency graph.
         */
        gb_status =
            graph_build
            (
                gp,
                args->string[j],
                graph_build_preference_backtrack,
                0
            );

        /*
         * it is only relevant that we know how to build this
         * graph, not that we walk it.
         */
        switch (gb_status)
        {
        case graph_build_status_error:
            retval = -1;
            break;

        case graph_build_status_backtrack:
            break;

        case graph_build_status_success:
            string_list_append(result, args->string[j]);
            break;
        }
    }

    /*
     * Release resources held by the graph.
     */
    if (option_test(OPTION_REASON))
        graph_print_statistics(gp);
    graph_delete(gp);
    return retval;
}
Esempio n. 10
0
static int
interpret(string_list_ty *result, const string_list_ty *args,
    const struct expr_position_ty *pp, const struct opcode_context_ty *ocp)
{
    size_t          j;
    int             retval;
    graph_ty        *gp;
    graph_build_status_ty gb_status;
    graph_walk_status_ty gw_status;

    trace(("cook\n"));
    (void)pp;
    (void)ocp;
    assert(result);
    assert(args);
    assert(args->nstrings);
    if (args->nstrings <= 1)
        return 0;

    /*
     * set interrupts to catch
     *
     * Note that tee(1) [see listing.c] must ignore them
     * for the generated messages to appear in the log file.
     */
    desist_enable();

    /*
     * Build the dependency graph.
     */
    retval = 0;
    gp = graph_new();
    for (j = 1; j < args->nstrings; ++j)
    {
        gb_status =
            graph_build
            (
                gp,
                args->string[j],
                graph_build_preference_backtrack,
                0
            );
        switch (gb_status)
        {
        case graph_build_status_error:
            retval = -1;
            break;

        case graph_build_status_backtrack:
            break;

        case graph_build_status_success:
            string_list_append(result, args->string[j]);
            break;
        }
    }

    /*
     * Walk the dependency graph.
     */
    if (retval >= 0)
    {
        if (option_test(OPTION_REASON))
            graph_print_statistics(gp);
        gw_status = graph_walk(gp);
        switch (gw_status)
        {
        case graph_walk_status_uptodate:
        case graph_walk_status_uptodate_done:
        case graph_walk_status_done:
            break;

        case graph_walk_status_done_stop:
        case graph_walk_status_wait:
            assert(0);
            /* fall through... */

        case graph_walk_status_error:
            retval = -1;
            break;
        }
    }

    /*
     * Release resources held by the graph.
     */
    graph_delete(gp);
    return retval;
}