enumerate-balanced-ideals/test.c

121 lines
2.8 KiB
C

#include <stdio.h>
#include "thickenings.h"
#include "queue.h"
#define SWAP(t, a, b) do {t tmp = a; a = b; b = tmp;} while(0)
char *stringify_Sp2n_permutation(int *word, int wordlength, int rank, int len, char *str)
{
for(int i = 0; i < rank*2; i++)
str[i] = '1' + i;
str[2*rank] = 0;
for(int i = 0; i < wordlength; i++) {
if(word[i] == 0)
SWAP(char, str[rank-1], str[2*rank-1]);
else {
SWAP(char, str[rank-word[i]], str[rank-word[i]-1]);
SWAP(char, str[2*rank-word[i]], str[2*rank-word[i]-1]);
}
}
str[len] = 0;
return str;
}
int main(int argc, const char *argv[])
{
semisimple_type_t type;
node_t *graph;
int *leftbuf, *rightbuf;
edgelist_t *edgelists;
int *words;
int rank, order;
int *reduced, *group;
int current;
queue_t queue;
char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
char buffer[1024];
int left = ~(1 << (atoi(argv[1]) - atoi(argv[3])));
int right = ~(1 << (atoi(argv[1]) - atoi(argv[2])));
type.n = 1;
type.factors = (simple_type_t*)malloc(type.n*sizeof(simple_type_t));
type.factors[0].series = 'B';
type.factors[0].rank = atoi(argv[1]);
rank = coxeter_rank(type);
order = coxeter_order(type);
graph = (node_t*)malloc(order*sizeof(node_t));
leftbuf = (int*)malloc(rank*order*sizeof(int));
rightbuf = (int*)malloc(rank*order*sizeof(int));
for(int i = 0; i < order; i++) {
graph[i].left = &leftbuf[i*rank];
graph[i].right = &rightbuf[i*rank];
}
prepare_graph(type, graph, &edgelists, &words);
reduced = (int*)malloc(order*sizeof(int));
group = (int*)malloc(order*sizeof(int));
for(int i = 0; i < order; i++) {
group[i] = -1;
reduced[i] = i;
}
// step 1: group
for(int i = 0; i < order; i++) {
if(group[i] != -1)
continue;
queue_init(&queue);
queue_put(&queue, i);
while((current = queue_get(&queue)) != -1) {
if(group[current] != -1)
continue;
group[current] = i;
for(int j = 0; j < rank; j++) {
if(left & (1 << j))
queue_put(&queue, graph[current].left[j]);
if(right & (1 << j))
queue_put(&queue, graph[current].right[j]);
}
}
}
// step 2: find minimum
for(int i = 0; i < order; i++)
if(graph[i].wordlength < graph[reduced[group[i]]].wordlength)
reduced[group[i]] = i;
// step 3: assign minimum to all
for(int i = 0; i < order; i++)
reduced[i] = reduced[group[i]];
for(int i = 0; i < order; i++)
if(reduced[i] == i) {
if(i == 0)
printf("1 ");
else
printf("%s ", alphabetize(graph[i].word, graph[i].wordlength, alphabet, buffer));
// printf("%s ", stringify_Sp2n_permutation(graph[i].word, graph[i].wordlength, rank, atoi(argv[2]), buffer));
}
printf("\n");
free(type.factors);
free(graph);
free(edgelists);
free(words);
free(reduced);
free(group);
free(leftbuf);
free(rightbuf);
return 0;
}