2p/srclib/minimiza.c
/**
    AFNDMinimiza
    Input:
        AFND *afnd: pointer to a dfa object
    Returns:
        dfa object, or NULL in error case
    Advanced description:
        It returns the minimum expression of the DFA passed as argument

*/
AFNDMinimiza
Input:
AFND *afnd: pointer to a dfa object
Returns:
dfa object, or NULL in error case
Advanced description:
It returns the minimum expression of the DFA passed as argument
AFNDMinimiza Input : AFND * afnd : pointer to a dfa object Returns : dfa object or NULL in error case Advanced description : It returns the minimum expression of the DFA passed as argument
AFND *AFNDMinimiza(AFND *afnd){
    if (!afnd){
        return NULL;
    }
    size_t nstates, alph_sz;
    tuple *t;
    uint8_t ***trans_tb = get_nfa_transition_table(afnd);
    uint8_t *i_states = get_initial_states(afnd, &nstates);
    uint8_t init = 0;
    for (size_t j = 0; i_states[j] == 0; init = ++j);
    uint8_t *f_states = get_final_states(afnd, &nstates);
    char **state_names = get_states_names(afnd, &nstates);
    char **alphabet = get_alphabet(afnd, &alph_sz);
    size_t n_acc;
    uint8_t *acc;
    trans_tb = __delete_unacc_states(trans_tb, nstates, init, alph_sz, &n_acc, &acc);
    __update_metadata(acc, nstates, n_acc, &i_states, &f_states, &state_names);
    distinct **d_mtx = __calc_distinct_mtx(trans_tb, f_states, n_acc, alph_sz);
    size_t dfa_states;
    row *min_dfa = __get_min_dfa(trans_tb, d_mtx, i_states, f_states, n_acc, alph_sz, &dfa_states);
    AFND *dfa = get_dfa_object(min_dfa, alphabet, alph_sz, dfa_states, nstates, state_names);
    for (size_t i = 0; i < n_acc; i++) {
        for (size_t j = 0; j < n_acc; j++) {
            while( (t = llist_pop(d_mtx[i][j].lst)) ){
                free(t);
            }
            llist_destroy(d_mtx[i][j].lst);
            llist_delete(d_mtx[i][j].lst);
        }
        free(d_mtx[i]);
    }
    free(d_mtx);
    for (size_t i = 0; i < dfa_states; i++) {
        for (size_t j = 0; j < alph_sz; j++) {
            cstate_remove(min_dfa[i].state_to[j]);
        }
        free(min_dfa[i].state_to);
        cstate_remove(min_dfa[i].state_from);
    }
    free(acc);
    free(min_dfa);
    free(f_states);
    free(i_states);
    free(state_names);
    free(alphabet);
    delete_nfa_transition_table(trans_tb, n_acc, alph_sz);
    return dfa;
}
AFND * AFNDMinimiza ( AFND * afnd ) { if ( ! afnd ) { return NULL ; } size_t nstates , alph_sz ; tuple * t ; uint8_t * * * trans_tb = get_nfa_transition_table ( afnd ) ; uint8_t * i_states = get_initial_states ( afnd , & nstates ) ; uint8_t init = 0 ; for ( size_t j = 0 ; i_states [ j ] == 0 ; init = ++ j ) ; uint8_t * f_states = get_final_states ( afnd , & nstates ) ; char * * state_names = get_states_names ( afnd , & nstates ) ; char * * alphabet = get_alphabet ( afnd , & alph_sz ) ; size_t n_acc ; uint8_t * acc ; trans_tb = __delete_unacc_states ( trans_tb , nstates , init , alph_sz , & n_acc , & acc ) ; __update_metadata ( acc , nstates , n_acc , & i_states , & f_states , & state_names ) ; distinct * * d_mtx = __calc_distinct_mtx ( trans_tb , f_states , n_acc , alph_sz ) ; size_t dfa_states ; row * min_dfa = __get_min_dfa ( trans_tb , d_mtx , i_states , f_states , n_acc , alph_sz , & dfa_states ) ; AFND * dfa = get_dfa_object ( min_dfa , alphabet , alph_sz , dfa_states , nstates , state_names ) ; for ( size_t i = 0 ; i < n_acc ; i ++ ) { for ( size_t j = 0 ; j < n_acc ; j ++ ) { while ( ( t = llist_pop ( d_mtx [ i ] [ j ] . lst ) ) ) { free ( t ) ; } llist_destroy ( d_mtx [ i ] [ j ] . lst ) ; llist_delete ( d_mtx [ i ] [ j ] . lst ) ; } free ( d_mtx [ i ] ) ; } free ( d_mtx ) ; for ( size_t i = 0 ; i < dfa_states ; i ++ ) { for ( size_t j = 0 ; j < alph_sz ; j ++ ) { cstate_remove ( min_dfa [ i ] . state_to [ j ] ) ; } free ( min_dfa [ i ] . state_to ) ; cstate_remove ( min_dfa [ i ] . state_from ) ; } free ( acc ) ; free ( min_dfa ) ; free ( f_states ) ; free ( i_states ) ; free ( state_names ) ; free ( alphabet ) ; delete_nfa_transition_table ( trans_tb , n_acc , alph_sz ) ; return dfa ; }
AFNDMinimiza
Input:
AFND *afnd: pointer to a dfa object
Returns:
dfa object, or NULL in error case
Advanced description:
It returns the minimum expression of the DFA passed as argument
AFNDMinimiza Input : AFND * afnd : pointer to a dfa object Returns : dfa object or NULL in error case Advanced description : It returns the minimum expression of the DFA passed as argument
// Fill our structures from the AFND object information
 //// Get the DFA transition table
 //// Get the initial state
 //// Get the set of final states
 //// Get the names of the states
 //// Get alphabet of the NDFA
 // Delete unaccesibles states.
 //// Update initials, finals and names (arrays can be shifted)
 // Calculate undistinguishable state matrix
 // Build the transition table of the minimum DFA, merging equivalent states
 // Translate our table to the AFND object this function has to return
 // Free's resources
