Exemplo n.º 1
0
/**
 * This function removes all useless transitions from the given graph. A useless
 * transitions is a transition to a state that has no transition.
 * Returns 1 the graph becomes empty; 0 otherwise.
 */
static int remove_useless_lexical_transitions(Fst2* fst2,int graph,OptimizedFst2State* optimized_states,
							Abstract_allocator prv_alloc) {
int initial=fst2->initial_states[graph];
int last=initial+fst2->number_of_states_per_graphs[graph]-1;
int cleaning_to_do=1;
if (empty_graph(graph,optimized_states,fst2)) {
	/* If the graph is already empty, there is nothing to report */
	return 0;
}
while (cleaning_to_do) {
	cleaning_to_do=0;
	for (int i=initial;i<=last;i++) {
		OptimizedFst2State s=optimized_states[i];
		int removed=remove_useless_transitions(s,optimized_states,fst2,prv_alloc);
		if (removed && !cleaning_to_do) {
			/* This state may now be useless */
			if (is_useless_state(s)) {
				/* If this is the case, we will have another round to do on this graph */
				cleaning_to_do=1;
			}
		}
	}
}
return empty_graph(graph,optimized_states,fst2);
}
Exemplo n.º 2
0
/* generate a connected graph with uniform probability, subject to some
 * constraints on the degree of the nodes. */
SEXP ide_cozman_graph(SEXP nodes, SEXP num, SEXP burn_in, SEXP max_in_degree,
    SEXP max_out_degree, SEXP max_degree, SEXP connected, SEXP debug) {

SEXP graphlist;

  switch(LENGTH(nodes)) {

    case 1:

      /* there is only one graph with 1 node, and it's empty. */
      graphlist = empty_graph(nodes, num);
      break;

    case 2:
      /* Ide-Cozman has no mixing with only 2 nodes, work around with i.i.d.
       * sampling.*/
      if (isTRUE(connected)) {

        graphlist = ic_2nodes(nodes, num, burn_in, max_in_degree,
                      max_out_degree, max_degree, connected, debug);
        break;

      }/*THEN*/

    default:

      graphlist = c_ide_cozman(nodes, num, burn_in, max_in_degree,
                    max_out_degree, max_degree, connected, debug);

  }/*SWITCH*/

  return graphlist;

}/*IDE_COZMAN_GRAPH*/
Exemplo n.º 3
0
int main(int argc, char* argv[]) {
  Adjacency_Matrix* g = (Adjacency_Matrix*) malloc(sizeof(Adjacency_Matrix));
  Adjacency_Matrix* tp;
  int* adjacency;
  empty_graph(g);

  int option, v, a1, a2;

  do {
    menu();
    scanf("%d", &option);
    switch (option) {
      case INSERT_VERTEX:
        printf("How many vertex would you like to insert? ");
        scanf("%d", &v);
        insert_vertex(g, v);
        break;
      case REMOVE_VERTEX:
        printf("Which vertex would you like to remove? ");
        scanf("%d", &v);
        remove_vertex(g, v);
        break;
      case INSERT_ARC:
        printf("First vertex: ");
        scanf("%d", &a1);
        printf("Second vertex: ");
        scanf("%d", &a2);
        insert_arc(g, a1, a2, 1);
        break;
      case REMOVE_ARC:
        printf("First vertex: ");
        scanf("%d", &a1);
        printf("Second vertex: ");
        scanf("%d", &a2);
        remove_arc(g, a1, a2);
        break;
      case VERTEX_ADJACENCY:
        printf("Which vertex would you like to verify adjacency?");
        scanf("%d", &v);
        adjacency = get_adjacency(g, v);
        print_adjacency(adjacency);
        free(adjacency);
        pause();
        break;
      case TRANSPOSE_GRAPH:
        tp = transpose_graph(g);
        print_graph(tp);
        free(tp);
        pause();
        break;
      case PRINT_GRAPH: 
        print_graph(g);
        pause();
        break;
    }
  } while (option != EXIT);

  return 0;
}
Exemplo n.º 4
0
struct pg_graph *pg_graph_new(const char *name, struct pg_brick *explore,
			      struct pg_error **error)
{
	struct pg_graph *ret = g_new(struct pg_graph, 1);

	ret->name = g_strdup(name);
	ret->all = g_hash_table_new_full(g_str_hash, g_str_equal,
					 NULL, &brick_destroy_cb);
	ret->pollable = NULL;
	if (explore && pg_graph_explore_ptr(ret, explore, error) < 0) {
		empty_graph(ret);
		pg_graph_destroy(ret);
		return NULL;
	}

	return ret;
}
Exemplo n.º 5
0
/**
 * Removes the useless graph calls, i.e. calls to an empty graph or calls
 * to a state that has no outgoing transitions.
 */
static int remove_useless_graph_calls(struct opt_graph_call* *l,OptimizedFst2State* optimized_states,Fst2* fst2,
		Abstract_allocator prv_alloc) {
int removed=0;
struct opt_graph_call* *tmp=l;
while ((*tmp)!=NULL) {
	if (empty_graph((*tmp)->graph_number,optimized_states,fst2)
			|| is_useless_state(optimized_states[(*tmp)->transition->state_number])) {
		/* We remove the graph call */
		removed=1;
		struct opt_graph_call* current=(*tmp);
		(*tmp)=current->next;
		current->next=NULL;
		free_opt_graph_call(current,prv_alloc);
	} else {
		tmp=&((*tmp)->next);
	}
}
return removed;
}