Пример #1
0
// 1 color a 3 node, 2 edge graph
// the node with the most edges should be spilled
void test_chaitin_spill() {
    DEBUG_PRINT("\ntest_chaitin_spill:\n");
    DEBUG_PRINT("  creating graph...\n");

    graph* g = create_graph();

    vertex* a = graph_add_vertex(g, 'a');
    vertex* b = graph_add_vertex(g, 'b');
    vertex* c = graph_add_vertex(g, 'c');

    graph_add_edge(a, b);
    graph_add_edge(a, c);
    
    assert(a->color == -1);
    assert(b->color == -1);
    assert(c->color == -1);

    DEBUG_PRINT("  coloring graph...\n");

    color_graph(g, 1);

    #ifdef DEBUG
    print_graph(g);
    #endif

    assert(a->color == -1); // spilled node
    assert(b->color == 0);
    assert(c->color == 0);

    destroy_graph(g);

    printf("+ algorithm test (spill) passed!\n");
}
Пример #2
0
int
main ()
{
  printf ("Creating a directed graph: \n");
  graph_t graph = create_graph (V);

  add_edge (graph, 0, 1);
  add_edge (graph, 0, 4);
  add_edge (graph, 1, 2);
  add_edge (graph, 1, 3);
  add_edge (graph, 1, 4);
  add_edge (graph, 2, 3);
  add_edge (graph, 3, 4);
  add_edge (graph, 4, 0);
  add_edge (graph, 5, 0);
  add_edge (graph, 6, 0);

  display_graph (graph);

  printf ("Removing edges from vertix 1:\n");
  remove_edge (graph, 1, 2);
  remove_edge (graph, 1, 3);
  remove_edge (graph, 1, 4);

  display_graph (graph);
  destroy_graph (graph);

  return 0;
}
Пример #3
0
int main(void) {
    int T;
    scanf("%d", &T);
    int i;
    for(i = 0; i < T; i++) {
        Graph *graph = (Graph *)malloc(sizeof(Graph));
        int vertex_num, edge_num;
        scanf("%d %d", &vertex_num, &edge_num);
        graph->vertex_num = vertex_num;
        graph->in_degrees = (int *)malloc(sizeof(int) * graph->vertex_num);
        memset(graph->in_degrees, 0, sizeof(int) * graph->vertex_num);
        graph->adj_lists = (Edge **)malloc(sizeof(Edge *) * graph->vertex_num);
        memset(graph->adj_lists, 0, sizeof(Edge *) * graph->vertex_num);
        int k;
        for(k = 0; k < edge_num; k++) {
            int from, to;
            scanf("%d %d", &from, &to);
            from--; to--;
            Edge *edge = create_edge(to, graph->adj_lists[from]);
            graph->adj_lists[from] = edge;
            graph->in_degrees[to] += 1;
        }
        if(is_dag(graph)) {
            printf("Correct\n");
        }
        else {
            printf("Wrong\n");
        }
        destroy_graph(graph);
    }
    return 0;
}
Пример #4
0
gboolean te_stop(void)
{
    destroy_graph(transition_graph);
    
#if SUPPORT_HEARTBEAT
    if(is_heartbeat_cluster()) {
	stonithd_signoff();
    }
#endif	
    crm_free(te_uuid);
}
Пример #5
0
// create and use a simple graph
void test_graph() {
    DEBUG_PRINT("\ntest_graph:\n");
    DEBUG_PRINT("  creating graph...\n");

    // allocate a new graph
    graph* my_graph = create_graph();
    assert(my_graph != NULL);
    assert(my_graph->size == 0);
    assert(my_graph->vertices == NULL);

    DEBUG_PRINT("  adding a new vertex...\n");

    // add a vertex
    vertex* first_node = graph_add_vertex(my_graph, 'a');
    assert(my_graph->size == 1);
    assert(my_graph->vertices == first_node);
    assert(first_node->color == -1);
    assert(first_node->removed == 0);
    assert(first_node->element == 'a');
    assert(first_node->num_edges == 0);
    assert(first_node->edges == NULL);
    assert(first_node->next == NULL);

    DEBUG_PRINT("  adding edge to a new vertex...\n");

    vertex* second_node = graph_add_vertex(my_graph, 'b');
    assert(my_graph->size == 2);
    // add edge from 'a' to 'b'
    graph_add_edge(first_node, second_node);
    assert(first_node->edges->to == second_node);
    assert(first_node->edges->next == NULL);
    assert(second_node->edges->to == first_node);
    
    // print it
    #ifdef DEBUG
    print_graph(my_graph);
    #endif
    
    DEBUG_PRINT("  freeing graph...\n");

    // free the graph
    destroy_graph(my_graph);

    printf("+ graph test passed!\n");
}
Пример #6
0
/* init graph */
PWdgraph init_graph(FILE *fp) {
    size_t v, w, vertex_num, edge_num;
    double weight;

    fscanf(fp, "%zu", &(vertex_num));
    fscanf(fp, "%zu", &(edge_num));
    PWdgraph g = _malloc_graph(vertex_num, edge_num);
    for(int i=0;i<g->edge_num;i++) {
        if(EOF == fscanf(fp, "%zu%zu%lf", &v, &w, &weight)) {
            destroy_graph(g);
            return NULL;
        }
        PEdge edge = _malloc_edge(v, w, weight, g->adjs[v]);
        g->adjs[v] = edge;
    }

    return g;
}
Пример #7
0
static void
process_next_job(void* data)
{
	crm_graph_t *transition = (crm_graph_t *)data;
	enum transition_status graph_rc;

	qb_enter();

	if (!graph_updated) {
		qb_loop_job_add(NULL, QB_LOOP_MED, transition, process_next_job);
		qb_leave();
		return;
	}

	graph_updated = FALSE;
	graph_rc = run_graph(transition);

	qb_log(LOG_DEBUG, "run_graph returned: %s", transition_status(graph_rc));

	if (graph_rc == transition_active || graph_rc == transition_pending) {
		qb_loop_job_add(NULL, QB_LOOP_MED, transition, process_next_job);
		qb_leave();
		return;
	}

	if (graph_rc != transition_complete) {
		qb_log(LOG_ERR, "Transition failed: %s",
		       transition_status(graph_rc));
	}
	destroy_graph(transition);

	// we don't want to free the input xml
	working_set->input = NULL;
	cleanup_alloc_calculations(working_set);
	free(working_set);
	working_set = NULL;

	completed_fn(run_user_data, graph_rc);

	qb_leave();
	return;
}
Пример #8
0
int main(void)
{
    TGPtr pgraph;
    int nedge;
    int Edges[][3] = {
        {1, 2, 6}, {2, 1, 6}, {1, 3, 1}, {3, 1, 1},
        {1, 4, 5}, {4, 1, 5}, {2, 5, 3}, {5, 2, 3},
        {2, 3, 5}, {3, 2, 5}, {3, 4, 5}, {4, 3, 5},
        {3, 5, 6}, {5, 3, 6}, {3, 6, 4}, {6, 3, 4},
        {4, 6, 2}, {6, 4, 2}, {5, 6, 6}, {6, 5, 6}
    };

    nedge = sizeof(Edges)/sizeof(Edges[0]);
    //printf("%d\n", vexcnt(Edges, nedge));

    pgraph = gcreate(Edges, nedge);

    mst_kruskal(pgraph);
    output_mst(pgraph);

    destroy_graph(pgraph);
    system("pause");
    return 0;
}
Пример #9
0
static bool recreate_graph(struct af_instance *af, struct mp_audio *config)
{
    void *tmp = talloc_new(NULL);
    struct priv *p = af->priv;
    AVFilterContext *in = NULL, *out = NULL, *f_format = NULL;

    if (bstr0(p->cfg_graph).len == 0) {
        MP_FATAL(af, "lavfi: no filter graph set\n");
        return false;
    }

    destroy_graph(af);
    MP_VERBOSE(af, "lavfi: create graph: '%s'\n", p->cfg_graph);

    AVFilterGraph *graph = avfilter_graph_alloc();
    if (!graph)
        goto error;

    if (mp_set_avopts(af->log, graph, p->cfg_avopts) < 0)
        goto error;

    AVFilterInOut *outputs = avfilter_inout_alloc();
    AVFilterInOut *inputs  = avfilter_inout_alloc();
    if (!outputs || !inputs)
        goto error;

    // Build list of acceptable output sample formats. libavfilter will insert
    // conversion filters if needed.
    static const enum AVSampleFormat sample_fmts[] = {
        AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32,
        AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL,
        AV_SAMPLE_FMT_U8P, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S32P,
        AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_DBLP,
        AV_SAMPLE_FMT_NONE
    };
    char *fmtstr = talloc_strdup(tmp, "");
    for (int n = 0; sample_fmts[n] != AV_SAMPLE_FMT_NONE; n++) {
        const char *name = av_get_sample_fmt_name(sample_fmts[n]);
        if (name) {
            const char *s = fmtstr[0] ? "|" : "";
            fmtstr = talloc_asprintf_append_buffer(fmtstr, "%s%s", s, name);
        }
    }

    char *src_args = talloc_asprintf(tmp,
        "sample_rate=%d:sample_fmt=%s:time_base=%d/%d:"
        "channel_layout=0x%"PRIx64,  config->rate,
        av_get_sample_fmt_name(af_to_avformat(config->format)),
        1, config->rate, mp_chmap_to_lavc(&config->channels));

    if (avfilter_graph_create_filter(&in, avfilter_get_by_name("abuffer"),
                                     "src", src_args, NULL, graph) < 0)
        goto error;

    if (avfilter_graph_create_filter(&out, avfilter_get_by_name("abuffersink"),
                                     "out", NULL, NULL, graph) < 0)
        goto error;

    if (avfilter_graph_create_filter(&f_format, avfilter_get_by_name("aformat"),
                                     "format", fmtstr, NULL, graph) < 0)
        goto error;

    if (avfilter_link(f_format, 0, out, 0) < 0)
        goto error;

    outputs->name = av_strdup("in");
    outputs->filter_ctx = in;

    inputs->name = av_strdup("out");
    inputs->filter_ctx = f_format;

    if (graph_parse(graph, p->cfg_graph, inputs, outputs, NULL) < 0)
        goto error;

    if (avfilter_graph_config(graph, NULL) < 0)
        goto error;

    p->in = in;
    p->out = out;
    p->graph = graph;

    assert(out->nb_inputs == 1);
    assert(in->nb_outputs == 1);

    talloc_free(tmp);
    return true;

error:
    MP_FATAL(af, "Can't configure libavfilter graph.\n");
    avfilter_graph_free(&graph);
    talloc_free(tmp);
    return false;
}
Пример #10
0
/*	 A_TE_START, A_TE_STOP, A_TE_RESTART	*/
void
do_te_control(long long action,
              enum crmd_fsa_cause cause,
              enum crmd_fsa_state cur_state,
              enum crmd_fsa_input current_input, fsa_data_t * msg_data)
{
    gboolean init_ok = TRUE;

    if (action & A_TE_STOP) {
        if (transition_graph) {
            destroy_graph(transition_graph);
            transition_graph = NULL;
        }

        if (fsa_cib_conn) {
            fsa_cib_conn->cmds->del_notify_callback(
                fsa_cib_conn, T_CIB_DIFF_NOTIFY, te_update_diff);
        }

        clear_bit(fsa_input_register, te_subsystem->flag_connected);
        crm_info("Transitioner is now inactive");
    }

    if ((action & A_TE_START) == 0) {
        return;

    } else if (is_set(fsa_input_register, te_subsystem->flag_connected)) {
        crm_debug("The transitioner is already active");
        return;

    } else if ((action & A_TE_START) && cur_state == S_STOPPING) {
        crm_info("Ignoring request to start %s while shutting down", te_subsystem->name);
        return;
    }

    te_uuid = crm_generate_uuid();
    crm_info("Registering TE UUID: %s", te_uuid);

    if (transition_trigger == NULL) {
        transition_trigger = mainloop_add_trigger(G_PRIORITY_LOW, te_graph_trigger, NULL);
    }

    if (pcmk_ok !=
        fsa_cib_conn->cmds->add_notify_callback(fsa_cib_conn, T_CIB_DIFF_NOTIFY, te_update_diff)) {
        crm_err("Could not set CIB notification callback");
        init_ok = FALSE;
    }

    if (pcmk_ok != fsa_cib_conn->cmds->set_op_callback(fsa_cib_conn, global_cib_callback)) {
        crm_err("Could not set CIB global callback");
        init_ok = FALSE;
    }

    if (init_ok) {
        set_graph_functions(&te_graph_fns);

        if (transition_graph) {
            destroy_graph(transition_graph);
        }

        /* create a blank one */
        crm_debug("Transitioner is now active");
        transition_graph = create_blank_graph();
        set_bit(fsa_input_register, te_subsystem->flag_connected);
    }
}
Пример #11
0
Path build_held_karp_path(const Point *points, const unsigned int points_count)
{
	Graph *graph = NULL;

	Path res;
	// encode subset of original verticies as bits in first index: i-th bit == 1 => point i is in subset.
	float C[MAX_COMBINATIONS_COUNT][MAX_HELD_KARP_POINTS];
	short best_points[MAX_COMBINATIONS_COUNT][MAX_HELD_KARP_POINTS];
	unsigned int set_size = 0;

	if (points_count <= 1)	{
		res.points[0] = 0;
		return res;
	}
	graph = construct_graph(points, points_count);

	C[1][0] = 0;

	for (set_size = 1; set_size < points_count; ++set_size) {
		unsigned int shifted_subset = 0;
		for (shifted_subset = 1; shifted_subset < (1 << (points_count - 1)); ++shifted_subset) {
			int end_point_index = 0;
			const int subset = (shifted_subset << 1) | 1;
			if (one_bits_count(shifted_subset) !=  set_size) {
				continue;
			}
			C[subset][0] = FLT_MAX;
			for (end_point_index = 1; end_point_index < points_count; ++end_point_index) {
				if (is_bit_set(subset, end_point_index)) {
					const int subset_without_endpoint = subset & (~(1 << end_point_index));
					int i = 0;
					C[subset][end_point_index] = FLT_MAX;
					for (i = 0; i < points_count; ++i) {
						if (is_bit_set(subset, i) && i != end_point_index) {
							const float curr_cost = C[subset_without_endpoint][i] + graph->distances[i][end_point_index];
							if (C[subset][end_point_index] > curr_cost) {
								C[subset][end_point_index] = curr_cost;
								best_points[subset][end_point_index] = i;
							}
						}
					}
				}
			}
		}
	}
	{
		// select last edge for making a loop
		const int all_subset = (0xFFFFFFFF >> (32 - points_count));
		
		int i = 0;
		C[all_subset][0] = FLT_MAX;
		best_points[all_subset][0] = -1;

		for (i = 1; i < points_count; ++i) {
			const float curr_cost = C[all_subset][i] + graph->distances[i][0];
			if (C[all_subset][0] > curr_cost) {
				C[all_subset][0] = curr_cost;
				best_points[all_subset][0] = i;
			}
		}
	}

	{
		// traverse back best points matrix to restore full path
		int current_subset = (0xFFFFFFFF >> (32 - points_count));
		int curr_traverse_point = 0;
		int path_point = 0;

		res.points[path_point] = best_points[current_subset][0];
		curr_traverse_point = res.points[path_point];
		
		for (path_point = 1; path_point < points_count; ++path_point) {
			res.points[path_point] = best_points[current_subset][curr_traverse_point];

			current_subset = current_subset & (~(1 << curr_traverse_point));
			curr_traverse_point = res.points[path_point];
		}
	}
	
	destroy_graph(graph);
	res.size = points_count;
	return res;
}
Пример #12
0
GraphType*          assign_operator_graph(GraphType** g1, GraphType* g2) {
    if (g1 != NULL) destroy_graph(*g1);
    return (*g1 = g2);
}
Пример #13
0
GraphType*          assign_operator_graph(GraphType** g1, GraphType* g2) {
    if (*g1 != NULL) destroy_graph(*g1); //gcDef(*g1, GRAPH_T);
    gcRef(g2, GRAPH_T);
    return (*g1 = g2);
}
Пример #14
0
/*	 A_TE_START, A_TE_STOP, A_TE_RESTART	*/
void
do_te_control(long long action,
	      enum crmd_fsa_cause cause,
	      enum crmd_fsa_state cur_state,
	      enum crmd_fsa_input current_input,
	      fsa_data_t *msg_data)
{
    int dummy;
    gboolean init_ok = TRUE;
	
    cl_uuid_t new_uuid;
    char uuid_str[UU_UNPARSE_SIZEOF];
	
    if(action & A_TE_STOP) {
	if(transition_graph) {
	    destroy_graph(transition_graph);
	    transition_graph = NULL;
	}

	if(fsa_cib_conn && cib_ok != fsa_cib_conn->cmds->del_notify_callback(
	       fsa_cib_conn, T_CIB_DIFF_NOTIFY, te_update_diff)) {
	    crm_err("Could not unset CIB notification callback");
	}

	clear_bit_inplace(fsa_input_register, te_subsystem->flag_connected);
	crm_info("Transitioner is now inactive");
	
	if(stonith_src) {
	    GCHSource *source = stonith_src;
	    crm_info("Disconnecting STONITH...");
	    stonith_src = NULL; /* so that we don't try to reconnect */
	    G_main_del_IPC_Channel(source);
	    stonithd_signoff();	    
	}
    }

    if((action & A_TE_START) == 0) {
	return;

    } else if(is_set(fsa_input_register, te_subsystem->flag_connected)) {
	crm_debug("The transitioner is already active");
	return;

    } else if((action & A_TE_START) && cur_state == S_STOPPING) {
	crm_info("Ignoring request to start %s while shutting down",
		 te_subsystem->name);
	return;
    }	

    cl_uuid_generate(&new_uuid);
    cl_uuid_unparse(&new_uuid, uuid_str);
    te_uuid = crm_strdup(uuid_str);
    crm_info("Registering TE UUID: %s", te_uuid);
	
    if(transition_trigger == NULL) {
	transition_trigger = mainloop_add_trigger(
	    G_PRIORITY_LOW, te_graph_trigger, NULL);
    }

    if(stonith_reconnect == NULL) {
	stonith_reconnect = mainloop_add_trigger(
	    G_PRIORITY_LOW, te_connect_stonith, &dummy);
    }
		    
    if(cib_ok != fsa_cib_conn->cmds->add_notify_callback(
	   fsa_cib_conn, T_CIB_DIFF_NOTIFY, te_update_diff)) {
	crm_err("Could not set CIB notification callback");
	init_ok = FALSE;
    }

    if(cib_ok != fsa_cib_conn->cmds->set_op_callback(fsa_cib_conn, global_cib_callback)) {
	crm_err("Could not set CIB global callback");
	init_ok = FALSE;
    }
    
    if(init_ok) {
	mainloop_set_trigger(stonith_reconnect);

	set_graph_functions(&te_graph_fns);

	if(transition_graph) {
	    destroy_graph(transition_graph);			    
	}
			
	/* create a blank one */
	crm_debug("Transitioner is now active");
	transition_graph = create_blank_graph();
	set_bit_inplace(fsa_input_register, te_subsystem->flag_connected);
    }
}
int main()
{
	graph_link gl;

	init_graph(&gl);

	insert_vertex(&gl, 'A');
	insert_vertex(&gl, 'B');
	insert_vertex(&gl, 'C');
	insert_vertex(&gl, 'D');
	insert_vertex(&gl, 'E');
	insert_vertex(&gl, 'F');
	insert_vertex(&gl, 'G');
	insert_vertex(&gl, 'H');
	insert_vertex(&gl, 'I');
	insert_vertex(&gl, 'J');
	insert_vertex(&gl, 'K');
	insert_vertex(&gl, 'L');
	insert_vertex(&gl, 'M');

	insert_edge(&gl, 'A', 'B');
	insert_edge(&gl, 'A', 'C');
	insert_edge(&gl, 'A', 'F');
	insert_edge(&gl, 'A', 'L');
	insert_edge(&gl, 'B', 'M');
	insert_edge(&gl, 'L', 'J');
	insert_edge(&gl, 'L', 'M');
	insert_edge(&gl, 'J', 'M');

	insert_edge(&gl, 'D', 'E');

	insert_edge(&gl, 'G', 'H');
	insert_edge(&gl, 'G', 'I');
	insert_edge(&gl, 'G', 'K');
	insert_edge(&gl, 'H', 'K');

	printf("\n");
	show_graph(&gl);

	printf("Depth First Search(DFS) all nodes of the graph: \n");
	depth_first_search(&gl, 'D');
	printf("Nul\n");

	printf("Breadth First Search(BFS) all nodes of the graph: \n");
	breadth_first_search(&gl, 'A');
	printf("Nul\n");

	printf("Non connect graph DFS: \n");
	components(&gl);
	printf("Nul\n");

	//int v = get_first_neighbor(&gl, 'A');
	//printf("The first neighbor node of 'A' is: %d\n", v);

	//int v1 = get_next_neighbor(&gl, 'B', 'E');
	//printf("The next neighbor node of 'B' and 'E' is: %d\n", v1);
	//printf("\n");

	//delete_edge(&gl, 'B', 'C');
	//show_graph(&gl);

	//delete_vertex(&gl, 'C');
	destroy_graph(&gl);
}
Пример #16
0
/*	 A_TE_INVOKE, A_TE_CANCEL	*/
void
do_te_invoke(long long action,
	     enum crmd_fsa_cause cause,
	     enum crmd_fsa_state cur_state,
	     enum crmd_fsa_input current_input,
	     fsa_data_t *msg_data)
{
	if(AM_I_DC == FALSE) {
		crm_err("Not DC: No need to invoke the TE (anymore): %s",
			fsa_action2string(action));
		return;
		
	} else if(fsa_state != S_TRANSITION_ENGINE && (action & A_TE_INVOKE)) {
		crm_err("No need to invoke the TE (%s) in state %s",
			fsa_action2string(action),
			fsa_state2string(fsa_state));
		return;
	}

	if(action & A_TE_CANCEL) {
		crm_debug("Cancelling the transition: %s",
			  transition_graph->complete?"inactive":"active");
		abort_transition(INFINITY, tg_restart, "Peer Cancelled", NULL);
		if(transition_graph && transition_graph->complete == FALSE) {
		    crmd_fsa_stall(NULL);
		}

	} else if(action & A_TE_HALT) {
		crm_debug("Halting the transition: %s",
			  transition_graph->complete?"inactive":"active");
		abort_transition(INFINITY, tg_stop, "Peer Halt", NULL);
		if(transition_graph && transition_graph->complete == FALSE) {
		    crmd_fsa_stall(NULL);
		}
		
	} else if(action & A_TE_INVOKE) {
		const char *value = NULL;
		xmlNode *graph_data = NULL;
		ha_msg_input_t *input = fsa_typed_data(fsa_dt_ha_msg);
		const char *ref = crm_element_value(input->msg, XML_ATTR_REFERENCE);
		const char *graph_file = crm_element_value(input->msg, F_CRM_TGRAPH);
		const char *graph_input = crm_element_value(input->msg, F_CRM_TGRAPH_INPUT);

		if(graph_file == NULL && input->xml == NULL) {			
		    crm_log_xml_err(input->msg, "Bad command");
		    register_fsa_error(C_FSA_INTERNAL, I_FAIL, NULL);
		    return;
		}
		
		if(transition_graph && transition_graph->complete == FALSE) {
			crm_info("Another transition is already active");
			abort_transition(INFINITY, tg_restart, "Transition Active", NULL);
			return;
		}

		if(fsa_pe_ref == NULL || safe_str_neq(fsa_pe_ref, ref)) {
		    crm_info("Transition is redundant: %s vs. %s", crm_str(fsa_pe_ref), crm_str(ref));
		    abort_transition(INFINITY, tg_restart, "Transition Redundant", NULL);
		}
		
		graph_data = input->xml;
		
		if(graph_data == NULL && graph_file != NULL) {
		    graph_data = filename2xml(graph_file);
		}

		if (is_timer_started(transition_timer)) {
		    crm_debug("The transitioner wait for a transition timer");
		    return;
		}

		CRM_CHECK(graph_data != NULL,
			  crm_err("Input raised by %s is invalid", msg_data->origin);
			  crm_log_xml_err(input->msg, "Bad command");
			  return);
		
		destroy_graph(transition_graph);
		transition_graph = unpack_graph(graph_data, graph_input);
		CRM_CHECK(transition_graph != NULL, transition_graph = create_blank_graph(); return);
		crm_info("Processing graph %d (ref=%s) derived from %s", transition_graph->id, ref, graph_input);
		
		value = crm_element_value(graph_data, "failed-stop-offset");
		if(value) {
		    crm_free(failed_stop_offset);
		    failed_stop_offset = crm_strdup(value);
		}
		
		value = crm_element_value(graph_data, "failed-start-offset");
		if(value) {
		    crm_free(failed_start_offset);
		    failed_start_offset = crm_strdup(value);
		}
		
		trigger_graph();
		print_graph(LOG_DEBUG_2, transition_graph);
		
		if(graph_data != input->xml) {
		    free_xml(graph_data);
		}	
	}
}
Пример #17
0
int main(int argc, char *argv[]) {

	int nv, ne, i, ind1, ind2, len;
	double mf;
	FILE *fp, *fp_meas;
	int tt;

	char str1[256] = "";
	char *sg;
	char *ms_f;
	char *of;
	int legacy = 0;
	int ii = 1;

	sf *sf;

	if (argc < 4) {
		printf(
				"Usage: exampleProgram nameSizeGraph nameFileValues outputFile \n");
		exit(-1);
	}
	if (argc >= 4){
		if (!strcmp("-l",argv[ii])){
			legacy = 1;
			ii++;
			printf("Legacy output mode\n");
		}
	}
	sg = argv[ii++];
	ms_f = argv[ii++];
	of = argv[ii++];
	if ((fp = fopen(sg, "r")) == NULL) {
		printf("Error (Reading): unable to open .size!\n");
		return (0);
	}
	if ((fp_meas = fopen(ms_f, "r")) == NULL) {
		printf("Error (Reading): unable to open measuring function file!\n");
		return (0);
	}

	tt = fscanf(fp, "%d\n %d\n", &nv, &ne);

	Graph *G = new_graph(nv);

	for (i = 0; i < nv; i++) {
		tt = fscanf(fp_meas, "%lf", &mf);
		graph_add_node(G,mf);
	}

	printf("Done\n");

	int x, y;
	for (i = 0; i < ne; i++) {
		tt = fscanf(fp, "%d %d \n", &ind1, &ind2);
		x = ind1;
		y = ind2;
		add_new_edge_graph(G,x,y);
	}

	fclose(fp);
	fclose(fp_meas);

	sf = newDeltaStarReductionAlgorithm(G);

	printf("Delta star reduction: done\n");

	destroy_graph(G);

	write_ang_pt(sf, of, legacy);

	printf("Sf printed\n");

	sf_destroy(sf);

	return 0;

}
Пример #18
0
static void uninit(struct af_instance *af)
{
    destroy_graph(af);
}
Пример #19
0
static bool recreate_graph(struct af_instance *af, struct mp_audio *config)
{
    void *tmp = talloc_new(NULL);
    struct priv *p = af->priv;
    AVFilterContext *in = NULL, *out = NULL;
    int r;

    if (bstr0(p->cfg_graph).len == 0) {
        mp_msg(MSGT_AFILTER, MSGL_FATAL, "lavfi: no filter graph set\n");
        return false;
    }

    destroy_graph(af);
    mp_msg(MSGT_AFILTER, MSGL_V, "lavfi: create graph: '%s'\n", p->cfg_graph);

    AVFilterGraph *graph = avfilter_graph_alloc();
    if (!graph)
        goto error;

    if (parse_avopts(graph, p->cfg_avopts) < 0) {
        mp_msg(MSGT_VFILTER, MSGL_FATAL, "lavfi: could not set opts: '%s'\n",
               p->cfg_avopts);
        goto error;
    }

    AVFilterInOut *outputs = avfilter_inout_alloc();
    AVFilterInOut *inputs  = avfilter_inout_alloc();
    if (!outputs || !inputs)
        goto error;

    char *src_args = talloc_asprintf(tmp,
        "sample_rate=%d:sample_fmt=%s:channels=%d:time_base=%d/%d:"
        "channel_layout=0x%"PRIx64,  config->rate,
        av_get_sample_fmt_name(af_to_avformat(config->format)),
        config->channels.num, 1, config->rate,
        mp_chmap_to_lavc(&config->channels));

    if (avfilter_graph_create_filter(&in, avfilter_get_by_name("abuffer"),
                                     "src", src_args, NULL, graph) < 0)
        goto error;

    if (avfilter_graph_create_filter(&out, avfilter_get_by_name("abuffersink"),
                                     "out", NULL, NULL, graph) < 0)
        goto error;

    static const enum AVSampleFormat sample_fmts[] = {
        AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32,
        AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL,
        AV_SAMPLE_FMT_U8P, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S32P,
        AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_DBLP,
        AV_SAMPLE_FMT_NONE
    };
    r = av_opt_set_int_list(out, "sample_fmts", sample_fmts,
                            AV_SAMPLE_FMT_NONE, AV_OPT_SEARCH_CHILDREN);
    if (r < 0)
        goto error;

    r = av_opt_set_int(out, "all_channel_counts", 1, AV_OPT_SEARCH_CHILDREN);
    if (r < 0)
        goto error;

    outputs->name = av_strdup("in");
    outputs->filter_ctx = in;

    inputs->name = av_strdup("out");
    inputs->filter_ctx = out;

    if (graph_parse(graph, p->cfg_graph, inputs, outputs, NULL) < 0)
        goto error;

    if (avfilter_graph_config(graph, NULL) < 0)
        goto error;

    p->in = in;
    p->out = out;
    p->graph = graph;

    assert(out->nb_inputs == 1);
    assert(in->nb_outputs == 1);

    talloc_free(tmp);
    return true;

error:
    mp_msg(MSGT_AFILTER, MSGL_FATAL, "Can't configure libavfilter graph.\n");
    avfilter_graph_free(&graph);
    talloc_free(tmp);
    return false;
}