GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
#include"typedef.h"1#include"polyeder.h"2#include"matrix.h"3/**************************************************************************\4@---------------------------------------------------------------------------5@---------------------------------------------------------------------------6@ FILE: polyeder_tools.c7@---------------------------------------------------------------------------8@---------------------------------------------------------------------------9@10\**************************************************************************/111213/**************************************************************************\14@---------------------------------------------------------------------------15@ vertex_TYP *init_vertex(dim, wall_no)16@ int dim;17@ int wall_no;18@19@ 'init_vertex' allocates a vertex_TYP *v.20@ For v the following is allocated:21@ v->dim = dim22@ v->wall_no = wall_no23@ v->v: pointer to integer, size: dim.24@ v->wall_size: 0, if wall_no = 025@ (wall_no/extsize1 +1) * extsize1, else26@ v->wall: pointer to integer27@ size: 0, if wall_no = 028@ else (wall_no/extsize1 +1) * extsize129@30@---------------------------------------------------------------------------31@32\**************************************************************************/33vertex_TYP *init_vertex(dim, wall_no)34int dim;35int wall_no;36{37int i,j;38vertex_TYP *erg;39erg = (vertex_TYP *)malloc(sizeof(vertex_TYP));40if(dim!=0)41{42erg->v = (int *)malloc(dim *sizeof(int));43for(i=0; i<dim; i++)44erg->v[i] = 0;45}46erg->dim = dim;47erg->wall_no = wall_no;48if( wall_no > 0)49{50j = wall_no/extsize1 +1;51erg->wall_SIZE = j * extsize1;52erg->wall = (int *)malloc(erg->wall_SIZE *sizeof(int));53}54else55erg->wall_SIZE=0;5657return(erg);58}5960/* anne, 16/07/97 */61/**************************************************************************\62@---------------------------------------------------------------------------63@ word_TYP *init_word(dim)64@ int dim;65@66@ 'init_word' allocates a word_TYP *word.67@ For word the following is allocated:68@ word->word = NULL;69@ matrix_TYP *trans = init_mat(dim,1,"");70@---------------------------------------------------------------------------71@72\**************************************************************************/73word_TYP *init_word(dim)74int dim;75{76word_TYP *erg;7778erg = (word_TYP*)malloc(sizeof(word_TYP));79erg->dim = dim;80erg->word = NULL;81erg->trans = NULL;82/* erg->trans = init_mat(dim,1,""); */8384return(erg);85}8687/**************************************************************************\88@---------------------------------------------------------------------------89@ wall_TYP *init_wall(dim)90@ int dim;91@ 'init_wall' allocates a wall_TYP *w.92@ For w the following is allocated:93@ w->dim = dim94@ w->gl: pointer to integer, size: dim.95@ w->mat = NULL96@ w->product = NULL97@ w->nproduct = 098@ w->word = NULL99@ w->next_no = 0100@ w->next = NULL101@ w->ext_no = 0;102@ w->extra= NULL;103@ w->neu = 0;104@ w->paar = 0;105@---------------------------------------------------------------------------106@107\**************************************************************************/108wall_TYP *init_wall(dim)109int dim;110{111int i,j;112wall_TYP *erg;113114erg = (wall_TYP *)malloc(sizeof(wall_TYP));115erg->gl = (int *)calloc(dim ,sizeof(int));116erg->dim = dim;117erg->mat = NULL;118erg->product = NULL;119erg->nproduct = 0;120erg->word = NULL;121erg->next_no = 0; /* next 5 lines anne 8/10/97 */122erg->next = NULL;123erg->ext_no = 0;124erg->extra = NULL;125erg->neu = 0;126erg->paar = 0;127return(erg);128}129130131/**************************************************************************\132@---------------------------------------------------------------------------133@ corner_TYP *init_corner()134@135@136@137@---------------------------------------------------------------------------138@139\**************************************************************************/140141142/**************************************************************************\143@---------------------------------------------------------------------------144@ polyeder_TYP *init_polyeder(vert_no, wall_no)145@ int vert_no, wall_no;146@147@ 'init_polyeder' allocates a polyeder_TYP *P.148@ For P the following is allocated:149@ P->vert_no = vert_no;150@ P->wall_no = wall_no;151@ P->is_closed = FALSE;152@ P->vert_SIZE = (vert_no/extsize1 +1) * extsize1;153@ P->wall_SIZE = (wall_no/extsize1 +1) * extsize1;154@ P->corner = NULL;155@ P->corner_no = 0, P->corner_SIZE = 0;156@ P->vert = **vertex_TYP, size: P->vert_no.157@ P->wall = **wall_TYP, size: P->wall_no.158@159@---------------------------------------------------------------------------160@161\**************************************************************************/162polyeder_TYP *init_polyeder(vert_no, wall_no)163int vert_no, wall_no;164{165int i,j;166polyeder_TYP *erg;167168erg = (polyeder_TYP *)malloc(sizeof(polyeder_TYP));169erg->vert_no = vert_no;170erg->wall_no = wall_no;171erg->is_closed = FALSE;172erg->is_degenerate = FALSE;173j = vert_no/extsize1 +1;174j *= extsize1;175erg->vert_SIZE = j;176erg->vert = (vertex_TYP **)malloc(j*sizeof(vertex_TYP *));177for(i=0;i<erg->vert_SIZE;i++)178erg->vert[i] = NULL;179j = wall_no/extsize1 +1;180j *= extsize1;181erg->wall_SIZE = j;182erg->wall = (wall_TYP **)malloc(j*sizeof(wall_TYP *));183for(i=0;i<erg->wall_SIZE;i++)184erg->wall[i] = NULL;185erg->corner = NULL; /* next 3 lines inserted by anne */186erg->corner_no = 0;187erg->corner_SIZE = 0;188return(erg);189}190191192193194195/**************************************************************************\196@---------------------------------------------------------------------------197@ polyeder_TYP *get_polyeder(file_name)198@ char *file_name;199@200@ Read a polyeder from the file 'file_name'.201@ If 'file_name' is NULL, get+polyeder reads from standard input.202@203@204@---------------------------------------------------------------------------205@206\**************************************************************************/207polyeder_TYP *get_polyeder(file_name)208char *file_name;209{210int vertno, wallno;211int dim,wn,i,j;212polyeder_TYP *F;213FILE *infile;214215216/*------------------------------------------------------------*\217| Open input file |218\*------------------------------------------------------------*/219if ( file_name == NULL )220infile = stdin;221else222if ( (infile = fopen (file_name, "r")) == NULL ) {223fprintf (stderr, "Could not open input-file %s\n", file_name);224exit (4);225}226/*--------------------------------------------------*\227| read fundamental domain |228\*--------------------------------------------------*/229fscanf (infile, "%d", &vertno);230fscanf (infile, "%d", &wallno);231F = init_polyeder(vertno, wallno);232for(i=0;i<vertno;i++)233{234fscanf (infile, "%d", &dim);235fscanf (infile, "%d", &wn);236F->vert[i] = init_vertex(dim, wn);237for(j=0;j<dim;j++)238fscanf(infile, "%d", &F->vert[i]->v[j]);239for(j=0;j<wn;j++)240fscanf(infile, "%d", &F->vert[i]->wall[j]);241}242for(i=0;i<wallno;i++)243{244fscanf(infile, "%d", &dim);245F->wall[i] = init_wall(dim);246for(j=0;j<dim;j++)247fscanf(infile, "%d", &F->wall[i]->gl[j]);248}249fscanf(infile, "%d", &F->is_closed);250fscanf(infile, "%d", &F->is_degenerate);251252253/*------------------------------------------------------------*\254| close input file |255\*------------------------------------------------------------*/256if ( infile != stdin )257fclose (infile);258return ( F );259}260261262263/**************************************************************************\264@---------------------------------------------------------------------------265@ void put_polyeder(F)266@ polyeder_TYP *F;267@268@ prints a polyeder_TYP to standard output269@270@---------------------------------------------------------------------------271@272\**************************************************************************/273void put_polyeder(F)274polyeder_TYP *F;275{276int i,j;277printf("%d %d\n", F->vert_no, F->wall_no);278printf("\n");279for(i=0;i<F->vert_no;i++)280{281printf("%d %d\n", F->vert[i]->dim, F->vert[i]->wall_no);282for(j=0;j<F->vert[i]->dim;j++)283printf("%d ", F->vert[i]->v[j]);284printf("\n");285for(j=0;j<F->vert[i]->wall_no;j++)286printf("%d ", F->vert[i]->wall[j]);287printf("\n");288}289printf("\n");290for(i=0;i<F->wall_no;i++)291{292printf("%d\n", F->wall[i]->dim);293for(j=0;j<F->wall[i]->dim;j++)294printf("%d ", F->wall[i]->gl[j]);295printf("\n");296}297298printf("\n");299printf("%d %d\n", F->is_closed, F->is_degenerate);300fflush(stdout);301}302303304305/**************************************************************************\306@---------------------------------------------------------------------------307@ int wall_times_vertex(w, v)308@ wall_TYP *w;309@ vertex_TYP *v;310@311@ calculates the sum of v->v[i] * w->gl[i].312@313@---------------------------------------------------------------------------314@315\**************************************************************************/316int wall_times_vertex(w, v)317wall_TYP *w;318vertex_TYP *v;319{320int i,e;321e=0;322for(i=0;i<v->dim;i++)323e += (v->v[i] * w->gl[i]);324return(e);325}326327328329/**************************************************************************\330@---------------------------------------------------------------------------331@ void free_vertex(v)332@ vertex_TYP **v;333@334@ frees, what was allocated in *v and sets (*v) = NULL335@---------------------------------------------------------------------------336@337\**************************************************************************/338void free_vertex(v)339vertex_TYP **v;340{341int i;342if((*v)!= NULL)343{344free((*v)->v);345if((*v)->wall_SIZE != 0)346free((*v)->wall);347free((*v));348(*v)=NULL;349}350}351352353/**************************************************************************\354@---------------------------------------------------------------------------355@ void free_wall(v)356@ wall_TYP **v;357@358@ frees, what was allocated in *v and sets (*v) = NULL359@360@---------------------------------------------------------------------------361@362\**************************************************************************/363void free_wall(v)364wall_TYP **v;365{366int i;367368if((*v)!= NULL)369{370free((*v)->gl);371if((*v)->mat != 0)372free_mat((*v)->mat);373if((*v)->next != NULL){ /* next 7 lines anne, 8/10/97 */374for(i=0; i<(*v)->next_no; i++)375free((*v)->next[i]);376free((*v)->next);377}378if((*v)->extra != NULL){379for(i=0; i<(*v)->ext_no; i++)380free((*v)->extra[i]);381free((*v)->extra);382}383if((*v)->word != NULL){ /* next 7 lines anne, 1.4. 98 */384if((*v)->word->trans != NULL){385free_mat((*v)->word->trans); (*v)->word->trans = NULL; }386if((*v)->word->word != NULL)387free((*v)->word->word);388free((*v)->word);389}390free((*v));391if((*v)->product != NULL)392free((*v)->product);393394(*v)=NULL;395}396}397398/* anne, 16/07/97 */399/**************************************************************************\400@---------------------------------------------------------------------------401@ void free_word(word)402@ word_TYP *word;403@404@ frees, what was allocated in word and sets word = NULL405@406@---------------------------------------------------------------------------407@408\**************************************************************************/409void free_word(word)410word_TYP *word;411{412if (word != NULL){413if (word->trans != NULL)414free_mat(word->trans);415if (word->word[0] > 0 &&416word->word != NULL)417free(word->word);418free(word);419word = NULL;420}421}422423/**************************************************************************\424@---------------------------------------------------------------------------425@ wall_TYP *mat_to_wall(M)426@ matrix_TYP *M;427@428@ creates a wall_TYP *w with w->dim = M->cols429@ and the entries of w->gl equal to the entries of the first row of M.430@431@---------------------------------------------------------------------------432@433\**************************************************************************/434wall_TYP *mat_to_wall(M)435matrix_TYP *M;436{437int i;438wall_TYP *erg;439erg = init_wall(M->cols);440for(i=0;i<erg->dim;i++)441erg->gl[i] = M->array.SZ[0][i];442return(erg);443}444445446/**************************************************************************\447@---------------------------------------------------------------------------448@ void normal_wall(v)449@ wall_TYP *v;450@451@ Divides the entries of v->gl by their greatest common divisor.452@453@---------------------------------------------------------------------------454@455\**************************************************************************/456void normal_wall(v)457wall_TYP *v;458{459int i,j;460int w1,w2;461462if(v->dim>0)463{464i=0;465while(i<v->dim && v->gl[i] == 0)466i++;467if(i<v->dim)468w1 = v->gl[i];469for(j=i+1;j<v->dim && w1 != 1 && w1 != -1;j++)470{471if(v->gl[j] != 0)472{473w2 = GGT(w1, v->gl[j]);474w1 = w2;475}476}477if(w1 < 0)478w1 = -w1;479if(w1 != 0)480{481for(j=0;j<v->dim;j++)482v->gl[j] /= w1;483}484}485}486487488489490/**************************************************************************\491@---------------------------------------------------------------------------492@ void normal_vertex(v)493@ vertex_TYP *v;494@495@ Divides the entries of v->v by their greatest common divisor.496@497@---------------------------------------------------------------------------498@499\**************************************************************************/500void normal_vertex(v)501vertex_TYP *v;502{503int i,j;504int w1,w2;505506if(v->dim>0)507{508i=0;509while(i<v->dim && v->v[i] == 0)510i++;511if(i<v->dim)512w1 = v->v[i];513for(j=i+1;j<v->dim && w1 != 1 && w1 != -1;j++)514{515if(v->v[j] != 0)516{517w2 = GGT(w1, v->v[j]);518w1 = w2;519}520}521if(w1 < 0)522w1 = -w1;523if(w1 != 0)524{525for(j=0;j<v->dim;j++)526v->v[j] /= w1;527}528}529}530531532533534535/**************************************************************************\536@---------------------------------------------------------------------------537@ int is_vertex_of_wallno(v, w)538@ vertex_TYP *v;539@ int w;540@541@ Checks if the inter w is an entry of v->wall.542@ If w is an entry of w->wall, the result is 1, otherwise 0.543@ CAUTION: the entries of v->wall have to be ordered, t.m.544@ v->wall[i] < v->wall[i+1].545@546@---------------------------------------------------------------------------547@548\**************************************************************************/549int is_vertex_of_wallno(v, w)550vertex_TYP *v;551int w;552{553int o,u,t;554o=w;555u=0;556if(o>= v->wall_no)557o=v->wall_no-1;558while(o>u)559{560t=(o+u)/2;561if(v->wall[t] < w)562u=t+1;563else564o=t;565}566if(w == v->wall[u])567return(TRUE);568return(FALSE);569}570571/**************************************************************************\572@---------------------------------------------------------------------------573@ word_TYP *copy_word(w)574@ word_TYP *w;575@ make returns a copy of w.576@ in w->word[0] the length of w->word is encoded.577@---------------------------------------------------------------------------578\**************************************************************************/579word_TYP *copy_word(w)580word_TYP *w;581{582word_TYP *erg;583int i;584585erg = init_word(w->dim);586erg->word = (int*)malloc((w->word[0]+1)* sizeof(int));587for(i=0; i<= w->word[0]; i++)588erg->word[i] = w->word[i];589if(w->trans != NULL)590erg->trans = copy_mat(w->trans);591592return(erg);593}594595596/**************************************************************************\597@---------------------------------------------------------------------------598@ wall_TYP *copy_wall(w)599@ wall_TYP *w;600@ make returns a copy of w.601@---------------------------------------------------------------------------602@603\**************************************************************************/604wall_TYP *copy_wall(w)605wall_TYP *w;606{607wall_TYP *erg;608int i;609int j;610611erg = init_wall(w->dim);612for(i=0;i<w->dim;i++)613erg->gl[i] = w->gl[i];614if(w->mat != NULL)615erg->mat = copy_mat(w->mat);616else617erg->mat = NULL;618if(w->word != NULL) /*anne, 16/07/97 */619erg->word = copy_word(w->word);620else621erg->word = NULL;622if(w->next != NULL){ /* 3 lines anne 8/10/97 */623erg->next_no = w->next_no;624erg->next = (int **)malloc(w->next_no *sizeof(int*));625for(j=0; j<w->next_no; j++){626erg->next[j] = (int*)malloc(w->dim * sizeof(int));627for(i=0;i<w->dim;i++)628erg->next[j][i] = w->next[j][i];629}630}631else{632erg->next = NULL;633erg->next_no = 0;634}635if(w->extra != NULL){ /* 12 lines, anne 14/10/97 */636erg->ext_no = w->ext_no;637erg->extra = (int **)malloc(w->ext_no *sizeof(int*));638for(j=0; j<w->ext_no; j++){639erg->extra[j] = (int*)malloc(w->dim * sizeof(int));640for(i=0;i<w->dim;i++)641erg->extra[j][i] = w->extra[j][i];642}643}644else{645erg->extra = NULL;646erg->ext_no = 0;647}648erg->neu = w->neu;649erg->nproduct = w->nproduct;650if(w->nproduct != 0)651{652if( (erg->product = (int *)malloc(w->nproduct *sizeof(int))) == 0)653{654printf("malloc failed in copy_wall\n");655exit(2);656}657}658for(i=0;i<w->nproduct;i++)659erg->product[i] = w->product[i];660return(erg);661}662663664/**************************************************************************\665@---------------------------------------------------------------------------666@ void free_polyeder(P)667@ polyeder_TYP *P;668@669@ frees all the pointers allocated in P, and P itself670@---------------------------------------------------------------------------671@672\**************************************************************************/673void free_polyeder(P)674polyeder_TYP *P;675{676int i;677for(i=0;i<P->vert_no;i++)678{679if(P->vert[i] != NULL)680free_vertex(&P->vert[i]);681}682free(P->vert);683for(i=0;i<P->wall_no; i++)684{685if(P->wall[i] != 0)686free_wall(&P->wall[i]);687}688if(P->corner != NULL)689free(P->corner);690if(P->wall != NULL)691free(P->wall);692free(P);693}694695696