enumerate-balanced-ideals/old/process.c

190 lines
6.0 KiB
C
Raw Permalink Normal View History

2016-07-26 08:09:34 +00:00
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include "thickenings.h"
2016-11-20 22:19:08 +00:00
#include "weyl.h"
2016-07-26 08:09:34 +00:00
#include "queue.h"
int main(int argc, const char *argv[])
{
FILE *infile;
semisimple_type_t type;
2016-11-11 16:07:45 +00:00
unsigned long left_invariance, right_invariance; // these are the invariances we have already modded out
unsigned long left_invariant, right_invariant; // these are the invariances of the thickening under consideration
int rank, cosets;
2016-07-26 08:09:34 +00:00
node_t *graph;
2016-11-11 16:07:45 +00:00
signed char *thickening;
int *seen, *generators;
2016-07-26 08:09:34 +00:00
queue_t queue;
2016-11-11 16:07:45 +00:00
int ngenerators;
2016-07-26 08:09:34 +00:00
int current;
char string_buffer1[1000];
const char *alphabet = "abcdefghijklmnopqrstuvwxyz";
if(argc < 2)
infile = stdin;
2016-11-11 16:07:45 +00:00
else
infile = fopen(argv[1], "rb");
2016-07-26 08:09:34 +00:00
2016-11-11 16:07:45 +00:00
// we completely trust the input data
ERROR(fread(&type.n, sizeof(int), 1, infile) == 0, "The input file seems to be empty!\n");
2016-07-26 08:09:34 +00:00
type.factors = malloc(type.n * sizeof(simple_type_t));
fread(type.factors, sizeof(simple_type_t), type.n, infile);
2016-11-11 16:07:45 +00:00
fread(&left_invariance, sizeof(simple_type_t), type.n, infile);
fread(&right_invariance, sizeof(simple_type_t), type.n, infile);
2016-07-26 08:09:34 +00:00
2016-11-20 22:19:08 +00:00
rank = weyl_rank(type);
2016-11-11 16:07:45 +00:00
graph = graph_alloc(type);
cosets = prepare_simplified_graph(type, left_invariance, right_invariance, graph);
2016-07-26 08:09:34 +00:00
2016-11-11 16:07:45 +00:00
thickening = (signed char*)malloc(cosets*sizeof(signed char));
generators = (int*)malloc(cosets*sizeof(int));
seen = (int*)malloc(cosets*sizeof(int));
2016-07-26 08:09:34 +00:00
2016-11-11 16:07:45 +00:00
while(fread(thickening, sizeof(signed char), cosets, infile) == cosets) {
2016-07-26 08:09:34 +00:00
2016-11-11 16:07:45 +00:00
// determine invariances of this thickening
left_invariant = right_invariant = -1; // set all bits to 1
for(int j = 0; j < cosets; j++) {
2016-07-26 08:09:34 +00:00
for(int k = 0; k < rank; k++) {
2016-11-11 16:07:45 +00:00
if(thickening[j] > 0 && thickening[graph[j].left[k]] < 0 ||
thickening[j] < 0 && thickening[graph[j].left[k]] > 0)
left_invariant &= ~(1 << k);
2016-11-11 16:07:45 +00:00
if(thickening[j] > 0 && thickening[graph[j].right[k]] < 0 ||
thickening[j] < 0 && thickening[graph[j].right[k]] > 0)
right_invariant &= ~(1 << k);
2016-11-11 16:07:45 +00:00
}
}
// print this stuff
printf("left: ");
for(int j = 0; j < rank; j++)
printf("%c", left_invariant & (1 << j) ? alphabet[j] : ' ');
printf(" right: ");
for(int j = 0; j < rank; j++)
printf("%c", right_invariant & (1 << j) ? alphabet[j] : ' ');
printf(" generators: ");
// find a minimal set of weyl group elements such that the union of the ideals generated by their cosets wrt the invariances determined above gives the thickening
// in the first step, mark everything which is equivalent to a "head" by a generator id
ngenerators = 0;
memset(generators, 0, cosets*sizeof(int));
for(int j = 0; j < cosets; j++) {
if(thickening[j] == HEAD_MARKER && generators[j] == 0) { // ignore the generator, if it is equivalent to one already seen
ngenerators++;
queue_init(&queue);
queue_put(&queue, j);
while((current = queue_get(&queue)) != -1) {
if(generators[current] == 0) { // visit everyone only once
generators[current] = ngenerators;
for(int k = 0; k < rank; k++) {
if(left_invariant & (1 << k))
queue_put(&queue, graph[current].left[k]);
if(right_invariant & (1 << k))
queue_put(&queue, graph[current].right[k]);
}
}
}
2016-07-26 08:09:34 +00:00
}
}
2016-11-11 16:07:45 +00:00
// in the second step, go through the list in ascending word length order and print the first appearance of each generator id
memset(seen, 0, cosets*sizeof(int));
for(int i = 0; i < cosets; i++) {
if(generators[i] != 0 && seen[generators[i]-1] == 0) {
seen[generators[i]-1] = 1;
printf("%s ", alphabetize(graph[i].word, graph[i].wordlength, alphabet, string_buffer1));
}
}
printf("\n");
}
if(infile != stdin)
fclose(infile);
graph_free(type, graph);
free(type.factors);
free(thickening);
}
/*******************************************************************************************
seen = (int*)malloc(order*sizeof(int));
generators = (int*)malloc(order*sizeof(int));
level = (signed char*)malloc(order*sizeof(int));
graph = graph_alloc(type);
prepare_graph(type, graph);
// finally do stuff
int counter = 0;
while(fread(level, sizeof(signed char), order, infile) == order) {
if((~left_invariant & left_invariant_wanted) == 0 && (~right_invariant & right_invariant_wanted) == 0) {
ngens = 0;
memset(generators, 0, order*sizeof(int));
for(int j = 0; j < order; j++) {
if(level[j] == HEAD_MARKER && generators[j] == 0) { // ignore the generator, if it is equivalent to one already seen
ngens++;
queue_init(&queue);
queue_put(&queue, j);
while((current = queue_get(&queue)) != -1) {
if(generators[current] == 0) { // visit everyone only once
generators[current] = ngens;
for(int k = 0; k < rank; k++) {
if(left_invariant & (1 << k))
2016-07-26 08:09:34 +00:00
queue_put(&queue, graph[current].left[k]);
if(right_invariant & (1 << k))
queue_put(&queue, graph[current].right[k]);
}
2016-07-26 08:09:34 +00:00
}
}
}
}
printf("left: ");
for(int j = 0; j < rank; j++)
printf("%c", left_invariant & (1 << j) ? alphabet[j] : ' ');
printf(" right: ");
for(int j = 0; j < rank; j++)
printf("%c", right_invariant & (1 << j) ? alphabet[j] : ' ');
printf(" generators: ");
memset(seen, 0, order*sizeof(int));
for(int i = 0; i < order; i++) {
if(generators[i] != 0 && seen[generators[i]-1] == 0) {
seen[generators[i]-1] = 1;
// if(type.n == 1 && type.factors[0].series == 'A')
// printf("%s ", stringify_SLn1_permutation(graph[i].word, graph[i].wordlength, rank, string_buffer1));
// else if(type.n == 1 && (type.factors[0].series == 'B' || type.factors[0].series == 'C'))
// printf("%s ", stringify_Onn1_permutation(graph[i].word, graph[i].wordlength, rank, string_buffer1));
// else
2016-07-26 08:09:34 +00:00
if(i == 0)
printf("1 ");
else
printf("%s ", alphabetize(graph[i].word, graph[i].wordlength, alphabet, string_buffer1));
}
2016-07-26 08:09:34 +00:00
}
printf("\n");
}
2016-07-26 08:09:34 +00:00
}
if(infile != stdin)
fclose(infile);
// cleanup
2016-11-11 16:07:45 +00:00
graph_free(type, graph);
2016-07-26 08:09:34 +00:00
free(seen);
free(generators);
free(type.factors);
return 0;
}
2016-11-11 16:07:45 +00:00
*/