// main.c
// Copyright (C) 2023 Mark Bowron

// Count local orderings on KFZ for each psi-number.

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.


#include    <stdio.h>
#include    <stdlib.h>
#include    <inttypes.h>
#include    <stdbool.h>
#include    <string.h>
#include    "set_operators.h"
#include    "set_families.h"
#include    "set_relations.h"
#include    "collapses.h"
#include    "local_orderings_274.h"


int main(int argc, const char * argv[])
{
    int       **equals, count[71] = {0}, total = 0;
    int         j, k, m;
    KFZenum     kfz_key = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
    KFZenum    *kfz = &kfz_key;

    equals = (int **)malloc(17 * sizeof(int *));
    if (equals==0)
    {
        printf("\nCould not allocate space for equals.\n");
        exit(0);
    }
    for (j=0; j<17; j++)
    {
        equals[j] = (int *)malloc(17 * sizeof(int));
        if (equals[j]==0)
        {
            printf("\nCould not allocate space for equals[%d].\n", j);
            exit(0);
        }
        for (k=0; k<17; k++) equals[j][k] = 0;
    }

    for (j=0; j<274; j++)
    {
        for (k=0; k<17; k++)
            for (m=0; m<17; m++)
                equals[k][m] = 0;
        for (k=0; k<16; k++)
            for (m=k+1; m<17; m++)
            {
                if (local_orderings_on_kfz[j][k][m]*local_orderings_on_kfz[j][m][k])
                {
                    equals[k][m] = 1;
                    equals[m][k] = 1;
                }
            }
        count[PsiArrayKFZ(equals,kfz)]++;
    }

    for (j=1; j<71; j++)
    {
        printf("%d\t%d\n", j, count[j]);
        total = total + count[j];
    }

    printf("\nKFZ has %d local orderings.", total);

    for (j=0; j<17; j++) free(equals[j]);
    free(equals);
    printf("\n\n");
    return EXIT_SUCCESS;
}
