verify.c 4.7 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * Revision Control Information
 *
 * $Source$
 * $Author$
 * $Revision$
 * $Date$
 *
 */
/*
 */

#include "espresso.h"

15 16 17
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
/*
 *  verify -- check that all minterms of F are contained in (Fold u Dold)
 *  and that all minterms of Fold are contained in (F u Dold).
 */
bool verify(F, Fold, Dold)
pcover F, Fold, Dold;
{
    pcube p, last, *FD;
    bool verify_error = FALSE;

    /* Make sure the function didn't grow too large */
    FD = cube2list(Fold, Dold);
    foreach_set(F, last, p)
    if (! cube_is_covered(FD, p)) {
        printf("some minterm in F is not covered by Fold u Dold\n");
        verify_error = TRUE;
        if (verbose_debug) printf("%s\n", pc1(p)); else break;
    }
    free_cubelist(FD);

    /* Make sure minimized function covers the original function */
    FD = cube2list(F, Dold);
    foreach_set(Fold, last, p)
    if (! cube_is_covered(FD, p)) {
        printf("some minterm in Fold is not covered by F u Dold\n");
        verify_error = TRUE;
        if (verbose_debug) printf("%s\n", pc1(p)); else break;
    }
    free_cubelist(FD);

    return verify_error;
}



/*
 *  PLA_verify -- verify that two PLA's are identical
 *
 *  If names are given, row and column permutations are done to make
 *  the comparison meaningful.
 *
 */
bool PLA_verify(PLA1, PLA2)
pPLA PLA1, PLA2;
{
    /* Check if both have names given; if so, attempt to permute to
     * match the names
     */
    if (PLA1->label != NULL && PLA1->label[0] != NULL &&
       PLA2->label != NULL && PLA2->label[0] != NULL) {
    PLA_permute(PLA1, PLA2);
    } else {
    (void) fprintf(stderr, "Warning: cannot permute columns without names\n");
    return TRUE;
    }

    if (PLA1->F->sf_size != PLA2->F->sf_size) {
    (void) fprintf(stderr, "PLA_verify: PLA's are not the same size\n");
    return TRUE;
    }

    return verify(PLA2->F, PLA1->F, PLA1->D);
}



/*
 *  Permute the columns of PLA1 so that they match the order of PLA2
 *  Discard any columns of PLA1 which are not in PLA2
 *  Association is strictly by the names of the columns of the cover.
 */
Alan Mishchenko committed
89
void PLA_permute(PLA1, PLA2)
Alan Mishchenko committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
pPLA PLA1, PLA2;
{
    register int i, j, *permute, npermute;
    register char *labi;
    char **label;

    /* determine which columns of PLA1 to save, and place these in the list
     * "permute"; the order in this list is the final output order
     */
    npermute = 0;
    permute = ALLOC(int, PLA2->F->sf_size);
    for(i = 0; i < PLA2->F->sf_size; i++) {
    labi = PLA2->label[i];
    for(j = 0; j < PLA1->F->sf_size; j++) {
        if (strcmp(labi, PLA1->label[j]) == 0) {
        permute[npermute++] = j;
        break;
        }
    }
    }

    /* permute columns */
    if (PLA1->F != NULL) {
    PLA1->F = sf_permute(PLA1->F, permute, npermute);
    }
    if (PLA1->R != NULL) {
    PLA1->R = sf_permute(PLA1->R, permute, npermute);
    }
    if (PLA1->D != NULL) {
    PLA1->D = sf_permute(PLA1->D, permute, npermute);
    }

    /* permute the labels */
    label = ALLOC(char *, cube.size);
    for(i = 0; i < npermute; i++) {
    label[i] = PLA1->label[permute[i]];
    }
    for(i = npermute; i < cube.size; i++) {
    label[i] = NULL;
    }
    FREE(PLA1->label);
    PLA1->label = label;

    FREE(permute);
}



/*
 *  check_consistency -- test that the ON-set, OFF-set and DC-set form
 *  a partition of the boolean space.
 */
bool check_consistency(PLA)
pPLA PLA;
{
    bool verify_error = FALSE;
    pcover T;

    T = cv_intersect(PLA->F, PLA->D);
    if (T->count == 0)
    printf("ON-SET and DC-SET are disjoint\n");
    else {
    printf("Some minterm(s) belong to both the ON-SET and DC-SET !\n");
    if (verbose_debug)
        cprint(T);
    verify_error = TRUE;
    }
    (void) fflush(stdout);
    free_cover(T);

    T = cv_intersect(PLA->F, PLA->R);
    if (T->count == 0)
    printf("ON-SET and OFF-SET are disjoint\n");
    else {
    printf("Some minterm(s) belong to both the ON-SET and OFF-SET !\n");
    if (verbose_debug)
        cprint(T);
    verify_error = TRUE;
    }
    (void) fflush(stdout);
    free_cover(T);

    T = cv_intersect(PLA->D, PLA->R);
    if (T->count == 0)
    printf("DC-SET and OFF-SET are disjoint\n");
    else {
    printf("Some minterm(s) belong to both the OFF-SET and DC-SET !\n");
    if (verbose_debug)
        cprint(T);
    verify_error = TRUE;
    }
    (void) fflush(stdout);
    free_cover(T);

    if (tautology(cube3list(PLA->F, PLA->D, PLA->R)))
    printf("Union of ON-SET, OFF-SET and DC-SET is the universe\n");
    else {
    T = complement(cube3list(PLA->F, PLA->D, PLA->R));
    printf("There are minterms left unspecified !\n");
    if (verbose_debug)
        cprint(T);
    verify_error = TRUE;
    free_cover(T);
    }
    (void) fflush(stdout);
    return verify_error;
}
197 198
ABC_NAMESPACE_IMPL_END