schnellerer Algo
This commit is contained in:
100
thickenings.c
100
thickenings.c
@@ -20,6 +20,33 @@ char *alphabetize(int *word, int len, const char *alphabet, char *buffer)
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void print_thickening(int rank, int order, const int *thickening, int is_fat, int is_slim, int conflict, const char *alphabet, FILE *f)
|
||||
{
|
||||
for(int i = 0; i < order; i++) {
|
||||
if(thickening[i] == 1000)
|
||||
fprintf(f, "\e[41mx\e[40m\e[m");
|
||||
else if(thickening[i] < 0 && thickening[i] > -10)
|
||||
fprintf(f, "\e[47m\e[30m%d\e[40m\e[m", -thickening[i]);
|
||||
else if(thickening[i] <= -10)
|
||||
fprintf(f, "\e[47m\e[30m+\e[40m\e[m");
|
||||
else if(thickening[i] > 0 && thickening[i] < 10)
|
||||
fprintf(f, "%d", thickening[i]);
|
||||
else if(thickening[i] >= 10)
|
||||
fprintf(f, "+");
|
||||
else
|
||||
fprintf(f, " ");
|
||||
}
|
||||
|
||||
if(is_fat)
|
||||
fprintf(f, " F");
|
||||
if(is_slim)
|
||||
fprintf(f, " S");
|
||||
if(conflict)
|
||||
fprintf(f, " C");
|
||||
|
||||
fprintf(f, "\n");
|
||||
}
|
||||
|
||||
void print_balanced_thickening(int rank, int order, const int *thickening, const int *left_invariant, const int *right_invariant, const char *alphabet, FILE *f)
|
||||
{
|
||||
for(int i = 0; i < order; i++) {
|
||||
@@ -288,6 +315,7 @@ void enumerate_balanced_thickenings(semisimple_type_t type, node_t *graph, const
|
||||
int is_fat, is_slim;
|
||||
int current_level, head, current;
|
||||
int i;
|
||||
int conflict;
|
||||
edgelist_t *edge;
|
||||
|
||||
queue_t queue;
|
||||
@@ -303,14 +331,31 @@ void enumerate_balanced_thickenings(semisimple_type_t type, node_t *graph, const
|
||||
memset(level, 0, order*sizeof(int));
|
||||
current_level = 1;
|
||||
head = order - 1;
|
||||
level[head] = -1;
|
||||
level[head] = 1000;
|
||||
while(current_level > 0) {
|
||||
// calculate transitive closure
|
||||
conflict = 0;
|
||||
queue_init(&queue);
|
||||
queue_put(&queue, head);
|
||||
for(int i = head + 1; level[i] != 1000 && i < order; i++) {
|
||||
if(level[graph[i].opposite] == 0) {
|
||||
level[graph[i].opposite] = current_level;
|
||||
queue_put(&queue, graph[i].opposite);
|
||||
}
|
||||
}
|
||||
while((current = queue_get(&queue)) != -1) {
|
||||
if(level[current] < 0 || level[graph[current].opposite] > 0) { // conflict, can not be slim
|
||||
conflict = 1;
|
||||
break;
|
||||
}
|
||||
if(level[graph[current].opposite] == 0)
|
||||
level[graph[current].opposite] = - current_level;
|
||||
edge = graph[current].bruhat_lower;
|
||||
while(edge) {
|
||||
if(level[edge->to] < 0) {
|
||||
conflict = 1;
|
||||
break;
|
||||
}
|
||||
if(level[edge->to] == 0) {
|
||||
level[edge->to] = current_level;
|
||||
queue_put(&queue, edge->to);
|
||||
@@ -319,8 +364,8 @@ void enumerate_balanced_thickenings(semisimple_type_t type, node_t *graph, const
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// we have a thickening, do something with it!
|
||||
|
||||
is_fat = is_slim = 1;
|
||||
for(int i = 0; i < order; i++) {
|
||||
if(level[graph[i].opposite] != 0) {
|
||||
@@ -344,7 +389,9 @@ void enumerate_balanced_thickenings(semisimple_type_t type, node_t *graph, const
|
||||
fwrite(level, sizeof(int), order, outfile);
|
||||
balanced_count++;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// print out the thickening
|
||||
if(is_fat && is_slim) {
|
||||
// check for invariances
|
||||
@@ -362,44 +409,65 @@ void enumerate_balanced_thickenings(semisimple_type_t type, node_t *graph, const
|
||||
}
|
||||
print_balanced_thickening(rank, order, level, left_invariant, right_invariant, alphabet, stderr);
|
||||
}
|
||||
*/
|
||||
|
||||
is_fat = 1;
|
||||
for(int i = 0; i < order; i++) {
|
||||
if(level[i] == 0)
|
||||
is_fat = 0;
|
||||
}
|
||||
|
||||
if(is_fat && !conflict) {
|
||||
// ERROR(balanced_count >= MAX_THICKENINGS, "Too many balanced thickenings! Increase MAX_THICKENINGS\n");
|
||||
fwrite(level, sizeof(int), order, outfile);
|
||||
balanced_count++;
|
||||
}
|
||||
|
||||
// print_thickening(rank, order, level, is_fat, !conflict, conflict, alphabet, stderr);
|
||||
|
||||
// now find the next one!
|
||||
|
||||
// try to find empty spot to the left of "head"
|
||||
for(i = head - 1; i >= 0; i--)
|
||||
if(level[i] == 0)
|
||||
break;
|
||||
if(i >= 0) {
|
||||
head = i;
|
||||
level[head] = -1;
|
||||
current_level++;
|
||||
continue;
|
||||
// try to find empty spot to the left of "head", but only if it is slim, as otherwise there is no point in adding even more
|
||||
if(!conflict) {
|
||||
for(i = head - 1; i >= 0; i--)
|
||||
if(level[i] == 0)
|
||||
break;
|
||||
if(i >= 0) {
|
||||
head = i;
|
||||
level[head] = 1000;
|
||||
current_level++;
|
||||
// print_thickening(rank, order, level, 0, 0, 0, alphabet, stderr);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// if none was found, try to move "head" to the left
|
||||
while(current_level > 0) {
|
||||
for(i = head - 1; i >= 0; i--)
|
||||
if(level[i] == 0 || level[i] >= current_level)
|
||||
if(level[i] == 0 || level[i] >= current_level || level[i] <= -current_level)
|
||||
break;
|
||||
if(i >= 0) { // if this was successful, just move head
|
||||
level[head] = 0;
|
||||
head = i;
|
||||
level[head] = -1;
|
||||
level[head] = 1000;
|
||||
break;
|
||||
} else { // if moving the head is not possible, take the next head to the right
|
||||
current_level--;
|
||||
level[head] = 0;
|
||||
do {
|
||||
head++;
|
||||
} while(head < order && level[head] != -1);
|
||||
} while(head < order && level[head] != 1000);
|
||||
}
|
||||
}
|
||||
|
||||
// clean up
|
||||
for(int i = 0; i < head; i++)
|
||||
if(level[i] >= current_level)
|
||||
for(int i = 0; i < order; i++)
|
||||
if(level[i] >= current_level && level[i] != 1000 || level[i] <= -current_level)
|
||||
level[i] = 0;
|
||||
|
||||
|
||||
// print_thickening(rank, order, level, 0, 0, 0, alphabet, stderr);
|
||||
|
||||
}
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
Reference in New Issue
Block a user