// main.c// Copyright (C) 2023 Mark Bowron// Verify k- and k_f-numbers for each GE monoid.// 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    "topologies.h"int main(int argc, const char * argv[]){    FILE       *input = NULL;    uint32_t   *point_closures;    int         j, k, kf, n, spacesize, space, ge_monoid;    int       **ge_k, **ge_kf;    KZ        **kz;    KFZ       **kfz;// Allocate memory for the struct that stores KFZ(A) for all A in X.    kz = (KZ **)malloc(9 * sizeof(KZ *));    if (kz==0)    {        printf("\nCould not allocate space for kz.\n");        exit(0);    }    kfz = (KFZ **)malloc(9 * sizeof(KFZ *));    if (kfz==0)    {        printf("\nCould not allocate space for kfz.\n");        exit(0);    }    for (spacesize = 0; spacesize < 9; spacesize++)    {        if (spacesize < 2)        {            kz[spacesize] = NULL;            kfz[spacesize] = NULL;            continue;        }        kz[spacesize] = CreateKZ(spacesize);        kfz[spacesize] = CreateKFZ(spacesize);    }    ge_k = (int **)malloc(8 * sizeof(int *));    if (ge_k==0)    {        printf("\nCould not allocate space for ge_k.\n");        exit(0);    }    ge_kf = (int **)malloc(8 * sizeof(int *));    if (ge_kf==0)    {        printf("\nCould not allocate space for ge_kf.\n");        exit(0);    }    for (j=0; j<8; j++)    {        ge_k[j] = (int *)malloc(15 * sizeof(int));        if (ge_k[j]==0)        {            printf("\nCould not allocate space for ge_k[%d].\n", j);            exit(0);        }        for (n=0; n<15; n++) ge_k[j][n] = 0;        ge_kf[j] = (int *)malloc(35 * sizeof(int));        if (ge_kf[j]==0)        {            printf("\nCould not allocate space for ge_kf[%d].\n", j);            exit(0);        }        for (n=0; n<35; n++) ge_kf[j][n] = 0;    }// Sets are represented by unsigned 32-bit binary integers with leading zeros.// Assuming X = {0,1,...,n-1} the element k is in A iff the coefficient of 2^k in the// binary integer representing A is 1 (i.e., the bits of the binary integer representing// A are in reverse order compared to X).    point_closures = (uint32_t *)malloc(spacesize * sizeof(uint32_t));    if (point_closures==0)    {        printf("\nCould not allocate space for point_closures.\n");        exit(0);    }// The input file contains all nonhomeomorphic spaces.    for (spacesize = 2; spacesize < 9; spacesize++)    {        switch (spacesize)        {            case 2:                input = fopen("2-spaces.txt", "r");                if (input==0)                {                    printf("\nCould not open file 2-spaces.txt for input.\n");                    exit(0);                }                break;            case 3:                input = fopen("3-spaces.txt", "r");                if (input==0)                {                    printf("\nCould not open file 3-spaces.txt for input.\n");                    exit(0);                }                break;            case 4:                input = fopen("4-spaces.txt", "r");                if (input==0)                {                    printf("\nCould not open file 4-spaces.txt for input.\n");                    exit(0);                }                break;            case 5:                input = fopen("5-spaces.txt", "r");                if (input==0)                {                    printf("\nCould not open file 5-spaces.txt for input.\n");                    exit(0);                }                break;            case 6:                input = fopen("6-spaces.txt", "r");                if (input==0)                {                    printf("\nCould not open file 6-spaces.txt for input.\n");                    exit(0);                }                break;            case 7:                input = fopen("7-spaces.txt", "r");                if (input==0)                {                    printf("\nCould not open file 7-spaces.txt for input.\n");                    exit(0);                }                break;            case 8:                input = fopen("8-spaces.txt", "r");                if (input==0)                {                    printf("\nCould not open file 8-spaces.txt for input.\n");                    exit(0);                }        }        space = 0;        while (space < spaces[spacesize])        {// Each line of input has the closure of every singleton.  These can alternatively be// regarded as smallest open neighborhoods.  Either interpretation yields all// nonhomeomorphic spaces of cardinality = spacesize, but any given line does not// in general produce the same space under the two.// Read the current line of input into the point_closures array.            for (j=0; j<spacesize; j++) fscanf(input, "%" PRIu32, &point_closures[j]);// Need KFZ(A) for all A in X to get the k- and k_f-numbers of X.            ComputeKFZ(kfz[spacesize],spacesize,point_closures);            k = KFZtoKNum(kfz[spacesize],spacesize);            kf = KFZtoKFNum(kfz[spacesize],spacesize);// Need KZ(A) for all A in X to get the GE monoid so we copy it from KFZ(A).            CopyKZfromKFZ(kz[spacesize],kfz[spacesize],spacesize);            ge_monoid = GE(kz[spacesize],spacesize,point_closures);            if (!ge_k[ge_monoid][k]) ge_k[ge_monoid][k] = spacesize;            if (!ge_kf[ge_monoid][kf]) ge_kf[ge_monoid][kf] = spacesize;            space++;        }        fclose(input);    }// Print the results.    printf("\nSmallest cardinality for each GE monoid and k-number combination:\n\n");    printf("|(D,2)| = 1\n");    printf("|(P,4)| = %d\n", ge_k[2][4]);    printf("|(P,6)| = %d\n", ge_k[2][6]);    printf("|(EO,4)| = %d\n", ge_k[3][4]);    printf("|(EO,6)| = %d\n", ge_k[3][6]);    printf("|(EO,8)| = %d\n", ge_k[3][8]);    printf("|(ED,4)| = %d\n", ge_k[4][4]);    printf("|(ED,6)| = %d\n", ge_k[4][6]);    printf("|(ED,8)| = %d\n", ge_k[4][8]);    printf("|(ED,10)| = %d\n", ge_k[4][10]);    printf("|(OU,4)| = %d\n", ge_k[5][4]);    printf("|(OU,6)| = %d\n", ge_k[5][6]);    printf("|(OU,8)| = %d\n", ge_k[5][8]);    printf("|(OU,10)| = %d\n", ge_k[5][10]);    printf("|(GE,8)| = %d\n", ge_k[6][8]);    printf("|(GE,10)| = %d\n", ge_k[6][10]);    printf("|(GE,12)| = %d\n", ge_k[6][12]);    printf("|(GE,14)| = %d\n", ge_k[6][14]);    printf("|(KD,10)| = %d\n", ge_k[7][10]);    printf("|(KD,12)| = %d\n", ge_k[7][12]);    printf("|(KD,14)| = %d\n\n", ge_k[7][14]);    printf("\nSmallest cardinality for each GE monoid and k_f-number combination:\n\n");    printf("|(D,2)| = 1\n");    printf("|(D,4)| = %d\n", ge_kf[1][4]);    printf("|(P,4)| = %d\n", ge_kf[2][4]);    printf("|(P,6)| = %d\n", ge_kf[2][6]);    printf("|(P,10)| = %d\n", ge_kf[2][10]);    printf("|(EO,4)| = %d\n", ge_kf[3][4]);    printf("|(EO,6)| = %d\n", ge_kf[3][6]);    printf("|(EO,8)| = %d\n", ge_kf[3][8]);    printf("|(EO,10)| = %d\n", ge_kf[3][10]);    printf("|(EO,16)| = %d\n", ge_kf[3][16]);    printf("|(ED,4)| = %d\n", ge_kf[4][4]);    printf("|(ED,6)| = %d\n", ge_kf[4][6]);    printf("|(ED,10)| = %d\n", ge_kf[4][10]);    printf("|(ED,16)| = %d\n", ge_kf[4][16]);    printf("|(ED,22)| = %d\n", ge_kf[4][22]);    printf("|(OU,8)| = %d\n", ge_kf[5][8]);    printf("|(OU,10)| = %d\n", ge_kf[5][10]);    printf("|(OU,14)| = %d\n", ge_kf[5][14]);    printf("|(OU,16)| = %d\n", ge_kf[5][16]);    printf("|(OU,20)| = %d\n", ge_kf[5][20]);    printf("|(GE,10)| = %d\n", ge_kf[6][10]);    printf("|(GE,14)| = %d\n", ge_kf[6][14]);    printf("|(GE,16)| = %d\n", ge_kf[6][16]);    printf("|(GE,18)| = %d\n", ge_kf[6][18]);    printf("|(GE,20)| = %d\n", ge_kf[6][20]);    printf("|(GE,22)| = %d\n", ge_kf[6][22]);    printf("|(GE,24)| = %d\n", ge_kf[6][24]);    printf("|(GE,26)| = %d\n", ge_kf[6][26]);    printf("|(GE,28)| = %d\n", ge_kf[6][28]);    printf("|(GE,30)| = %d\n", ge_kf[6][30]);    printf("|(GE,32)| = %d\n", ge_kf[6][32]);    printf("|(GE,34)| = %d\n", ge_kf[6][34]);    printf("|(KD,18)| = %d\n", ge_kf[7][18]);    printf("|(KD,22)| = %d\n", ge_kf[7][22]);    printf("|(KD,28)| = %d\n\n", ge_kf[7][28]);    free(point_closures);    for (j=0; j<8; j++)    {        free(ge_k[j]);        free(ge_kf[j]);    }    free(ge_k);    free(ge_kf);    for (spacesize = 2; spacesize < 9; spacesize++)    {        FreeKZ(kz[spacesize]);        FreeKFZ(kfz[spacesize]);    }    free(kz);    free(kfz);}