Exemplo n.º 1
0
Arquivo: args.c Projeto: blabos/Comp
int get_args(char* filename, args_t* args) {
    FILE* fp;

    int ret = 0;

    if ((fp = fopen(filename, "r")) != NULL) {
        ret =  get_mode(fp, args)
            && get_states(fp, args)
            && get_symbols(fp, args)
            && get_transitions(fp, args);
        
        fclose(fp);
    }

    return ret;
}
Exemplo n.º 2
0
Matrice creer_matrice_transistions(Automate* a, char c){
  Automate * abis = creer_automate_etats_0_n(a);
  int n = taille_ensemble(get_etats(abis));	
  Matrice m = creer_matrice(n);
  tree t=tree_creat();
  tree_set(t, c);
  m->mot = t;

  int i, j;
  for(i = 0; i < m->taille; i++){
    for(j = 0; j< m->taille; j++){
      m->tab[i][j] = INFINI;
    }
  } 

  Table_iterateur it1;
  Ensemble_iterateur it2;
  for ( it1 = premier_iterateur_table(get_transitions(abis));
	! iterateur_ensemble_est_vide(it1);
	it1 = iterateur_suivant_ensemble(it1)
	){
    Cle * cle = (Cle*) get_cle(it1);
    Ensemble * fins = (Ensemble*) get_valeur(it1);
    int tmp = get_lettre_cle(cle);
  
    if(tmp == (int)c){
      for( it2 = premier_iterateur_ensemble(fins);
	   ! iterateur_ensemble_est_vide(it2);
	   it2 = iterateur_suivant_ensemble(it2)
	   ){
	int f = get_element(it2);
	int cout = get_cout_cle(cle)==0 ? 0: 1;
	m->tab[get_origine_cle(cle)][f] = cout;
      }
    }
  }
  liberer_automate(abis);
  return m;
}
Exemplo n.º 3
0
static void get_transitions(TransitionSystem *model, State *src, State *dest)
{
	if (NULL != src && src->id != 0) //dont make transitions from the pseudo initial state
	{


//		fprintf(stdout, "trans: %d -> %d\n", src->id, dest->id);
		Transition *t = malloc(sizeof(Transition));
		if(!t)
		{
			fprintf(stderr, "malloc failed!\n");
			exit(1);
		}
		t->src = src->id;
//		if (dest == &PSEUDO_END) //replace transition to pseudo end with transition to itself
//			t->dest = src->id;
//		else
			t->dest = dest->id;

		model->transition_size++;
		model->transitions = realloc(model->transitions, sizeof(Transition *) * model->transition_size);
		if(!model->transitions)
		{
			fprintf(stderr, "malloc failed!\n");
			exit(1);
		}
		model->transitions[model->transition_size - 1] = t;

	}

	for (int i = 0; i < dest->children_size; i++)
	{
		if (dest->children[i] == NULL)
			continue;
		get_transitions(model, dest, dest->children[i]);
	}
}
void creergraphe(Automate *a){
  FILE* f=fopen("./auto.gv","w+");
  fprintf(f, "digraph graphe {\n\trankdir=S;\n\tsize=\"8,5\"\n\tnode [shape = doublecircle];\n\t");
  Ensemble_iterateur it;
  for(it = premier_iterateur_ensemble(get_finaux(a));
      ! iterateur_ensemble_est_vide( it );
      it = iterateur_suivant_ensemble( it )){
    fprintf(f, "%d ", (int)get_element( it));
  }
  fprintf(f,";\n\t");
  
  fprintf(f,"\n\tnode [shape = circle];\n\t"); 
  Table_iterateur it2;
  for( it2 = premier_iterateur_table(get_transitions( a ));
       ! iterateur_ensemble_est_vide( it2 );
       it2 = iterateur_suivant_ensemble( it2 )
       ){
    Cle * cle = (Cle*) get_cle( it2 );
    Ensemble * fins = (Ensemble*) get_valeur( it2 );
    for( it = premier_iterateur_ensemble( fins );
	 ! iterateur_ensemble_est_vide( it );
	 it = iterateur_suivant_ensemble( it )
	 ){ 
      int fin = get_element( it );
      fprintf(f,"%d",(int)get_origine_cle(cle));
    
      fprintf(f," -> ");
      fprintf(f,"%d",(int)fin);

      fprintf(f," [ label =\"");  
      char lettre=get_lettre_cle(cle);
      fprintf(f,"%c",lettre);

    
      fprintf(f, ":");
      fprintf(f,"%d",get_cout_cle(cle));

      fprintf(f,"\"];\n\t");
    }
  }   
  fprintf(f,"node [shape = point];\n\t");
  for(it = premier_iterateur_ensemble(get_initiaux(a));
      ! iterateur_ensemble_est_vide( it );
      it = iterateur_suivant_ensemble( it )){
    fprintf(f,"i%d ",(int)get_element(it));
  } 
  fprintf(f,";\n\t");
  for(it = premier_iterateur_ensemble(get_initiaux(a));
      ! iterateur_ensemble_est_vide( it );
      it = iterateur_suivant_ensemble( it )){
    fprintf(f,"i%d",(int)get_element(it));
    fprintf(f," -> ");
    fprintf(f,"%d",(int)get_element(it));

    fprintf(f," [ label =\"start\" ];\n\t");
  }
  
  fprintf(f,"}\n");
  fclose(f);

}
Exemplo n.º 5
0
void create_bdds(TransitionSystem *model)
{
//	printf("%d\ttotal states before merge\n", initial_numstates);
//	merge_similar_parents(&PSEUDO_END);
//	merge_similar_children(model->pseudo_initial); //merging children spoiles the calculation of support
	model->states_size = assign_id_and_collect_labels(model, model->pseudo_initial);
//	printf("%d\ttotal states after merge\n", model->states_size);
//	printf("%d\tstates removed\n", initial_numstates - model->states_size);

	get_transitions(model, NULL, model->pseudo_initial);

	init_buddy(model->states_size);

	int state_vars = ceil_of_log2_of(model->states_size);
	int bdd_vars = state_vars * 2;
	bdd_setvarnum(bdd_vars);

	BDD unprimed2primed = bdd_addref(0);
	model->states_bdds = malloc(sizeof(int *) * model->states_size);
	model->states_primed_bdds = malloc(sizeof(int *) * model->states_size);
	model->all_states = bdd_addref(0);

	//encode states as binary functions
	for (int i = 1; i < model->states_size; i++) {
		BDD tmp = bdd_addref(1);
		BDD tmpp = bdd_addref(1);
		for (int j = 0; j < state_vars; j++) {
			int test = (i >> (state_vars - 1 - j)) & 1;
			if (test == 1) {
				tmp = f_bdd_and_with(tmp, bdd_ithvar(j));
				tmpp = f_bdd_and_with(tmpp, bdd_ithvar(j + state_vars));
			} else {
				tmp = f_bdd_and_with(tmp, bdd_nithvar(j));
				tmpp = f_bdd_and_with(tmpp, bdd_nithvar(j + state_vars));
			}
		}
		model->states_bdds[i] = bdd_addref(tmp);
		model->states_primed_bdds[i] = bdd_addref(tmpp);

		model->all_states = f_bdd_or_with(model->all_states, tmp);

		BDD tt = bdd_addref(bdd_and(tmp, tmpp));
		unprimed2primed = f_bdd_or_with(unprimed2primed, tt);
		bdd_delref(tt);
		bdd_delref(tmp);
		bdd_delref(tmpp);
	}
	model->pseudo_end = model->states_bdds[PSEUDO_END.id];
	//remove pseudo end
	BDD tmp = bdd_addref(model->all_states);
	bdd_delref(model->all_states);
	model->all_states = bdd_apply(tmp, model->pseudo_end, bddop_diff);
	bdd_delref(tmp);

	model->unprimed2primed = bdd_addref(unprimed2primed);
	bdd_delref(unprimed2primed);

	//create helper of unprimed and primed variables
	BDD unprimed_vars = bdd_addref(1);
	BDD primed_vars = bdd_addref(1);
	for (int i = 0; i < state_vars; i++) {
		unprimed_vars = f_bdd_and_with(unprimed_vars, bdd_ithvar(i));
		primed_vars = f_bdd_and_with(primed_vars, bdd_ithvar(i + state_vars));
	}
	model->unprimed_vars = unprimed_vars;
	model->primed_vars = primed_vars;

	//create function for transitions
	BDD transitions_bdd = bdd_addref(0);
	for (int i = 0; i < model->transition_size; i++)
	{
//		printf("(%d, %d), ", model->transitions[i]->src, model->transitions[i]->dest);
		BDD tt = bdd_addref(bdd_and(model->states_bdds[model->transitions[i]->src], model->states_primed_bdds[model->transitions[i]->dest]));
		transitions_bdd = f_bdd_or_with(transitions_bdd, tt);
		bdd_delref(tt);
	}
	//transition from end to end to complete Kripke structure
//	BDD tt = bdd_addref(bdd_and(model->states_bdds[PSEUDO_END.id], model->states_primed_bdds[PSEUDO_END.id]));
//	transitions_bdd = f_bdd_or_with(transitions_bdd, tt);
//	bdd_delref(tt);

	model->initial_states = 0;
	State *child;
//	printf("children %d\n", model->pseudo_initial->children_size);
	for (int i = 0; i < model->pseudo_initial->children_size; i++)
	{
		child = model->pseudo_initial->children[i];
		if (child == NULL)
			continue; // removed
		model->initial_states = f_bdd_or_with(model->initial_states, model->states_bdds[child->id]);
	}

	model->transitions_bdd = transitions_bdd;

	for (int i = 0; i < model->activities_size; i++)
	{
		Labels *l = model->labels[i];
		l->states_bdd = bdd_addref(0);
		for (int j = 0; j < l->states_size; j++)
		{
			l->states_bdd = f_bdd_or_with(l->states_bdd, model->states_bdds[l->states[j]]);
		}

	}

}