-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bleed 1D suite, improve makefile
- Loading branch information
Showing
7 changed files
with
452 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Compilation results | ||
bin/ | ||
.deps/ | ||
|
||
# Tables to test with | ||
/table_* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <cmath> | ||
#include <getopt.h> | ||
#include <cstring> | ||
|
||
#include "bleed_utils.h" | ||
#include "gfon.h" | ||
#include "cmdline_options.h" | ||
|
||
using gem = gem_R; | ||
|
||
void worker(const cmdline_options& options) | ||
{ | ||
FILE* table=table_init(options.tables[0], 1); // init bleed | ||
|
||
int len = options.target.len; | ||
gem** pool = (gem**)malloc(len*sizeof(gem*)); // if not malloc-ed 690k is the limit | ||
int* pool_length = (int*)malloc(len*sizeof(int)); | ||
pool[0] = (gem*)malloc(sizeof(gem)); | ||
gem_init(pool[0],1,1); | ||
pool_length[0]=1; | ||
|
||
int prevmax=pool_from_table(pool, pool_length, len, table); // pool filling | ||
if (prevmax+1==len) { | ||
fclose(table); // close | ||
for (int i=0;i<len;++i) free(pool[i]); // free | ||
free(pool); // free | ||
free(pool_length); // free | ||
printf("Table is longer than %d, no need to do anything\n\n",prevmax+1); | ||
exit(1); | ||
} | ||
table=freopen(options.tables[0].c_str(), "a", table); // append -> updating possible | ||
|
||
for (int i=prevmax+1; i<len; ++i) { // more building | ||
int comb_tot = fill_pool_1D(pool, pool_length, i); | ||
|
||
if (!options.output.quiet) { | ||
printf("Value:\t%d\n",i+1); | ||
if (options.output.debug) { | ||
printf("Raw:\t%d\n",comb_tot); | ||
printf("Pool:\t%d\n\n",pool_length[i]); | ||
} | ||
} | ||
table_write_iteration(pool, pool_length, i, table); // write on file | ||
} | ||
|
||
fclose(table); // close | ||
for (int i=0;i<len;++i) free(pool[i]); // free | ||
free(pool); // free | ||
free(pool_length); // free | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
cmdline_options options = cmdline_options(); | ||
options.set_num_tables(1); | ||
|
||
if(!options.parse_args(argc, argv)) | ||
return 1; | ||
if (options.tables[0].empty()) { | ||
options.tables[0] = "table_bleed"; | ||
} | ||
|
||
worker(options); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <cmath> | ||
#include <getopt.h> | ||
|
||
#include "bleed_utils.h" | ||
#include "print_utils.h" | ||
#include "cmdline_options.h" | ||
|
||
using gem = gem_R; | ||
|
||
void worker(const cmdline_options& options) | ||
{ | ||
printf("\n"); | ||
int len = options.target.len; | ||
gem* gems = (gem*)malloc(len*sizeof(gem)); // if not malloc-ed 230k is the limit | ||
gem* pool[len]; | ||
int pool_length[len]; | ||
pool[0] = (gem*)malloc(sizeof(gem)); | ||
gem_init(gems,1,1); | ||
gem_init(pool[0],1,1); | ||
pool_length[0]=1; | ||
if (!options.output.quiet) gem_print(gems); | ||
|
||
for (int i=1; i<len; ++i) { | ||
int comb_tot = fill_pool_1D(pool, pool_length, i); | ||
|
||
compression_1D(gems + i, pool[i], pool_length[i]); | ||
if (!options.output.quiet) { | ||
printf("Value:\t%d\n",i+1); | ||
if (options.output.info) | ||
printf("Growth:\t%f\n", log(gem_power(gems[i]))/log(i+1)); | ||
if (options.output.debug) { | ||
printf("Raw:\t%d\n",comb_tot); | ||
printf("Pool:\t%d\n",pool_length[i]); | ||
} | ||
gem_print(gems+i); | ||
} | ||
} | ||
|
||
if (options.output.quiet) { // outputs last if we never seen any | ||
printf("Value:\t%d\n",len); | ||
printf("Growth:\t%f\n", log(gem_power(gems[len-1]))/log(len)); | ||
if (options.output.debug) | ||
printf("Pool:\t%d\n",pool_length[len-1]); | ||
gem_print(gems+len-1); | ||
} | ||
|
||
gem* gemf=gems+len-1; // gem that will be displayed | ||
|
||
if (options.target.upto) { | ||
double best_growth=-INFINITY; | ||
int best_index=0; | ||
for (int i=0; i<len; ++i) { | ||
if (log(gem_power(gems[i]))/log(i+1) > best_growth) { | ||
best_index=i; | ||
best_growth=log(gem_power(gems[i]))/log(i+1); | ||
} | ||
} | ||
printf("Best gem up to %d:\n\n", len); | ||
printf("Value:\t%d\n",best_index+1); | ||
printf("Growth:\t%f\n", best_growth); | ||
gem_print(gems+best_index); | ||
gemf = gems+best_index; | ||
} | ||
|
||
gem* gem_array = NULL; | ||
if (options.target.chain) { | ||
if (len < 2) printf("I could not add chain!\n\n"); | ||
else { | ||
int value=gem_getvalue(gemf); | ||
gemf = gem_putchain(pool[value-1], pool_length[value-1], &gem_array); | ||
printf("Gem with chain added:\n\n"); | ||
printf("Value:\t%d\n", value); // made to work well with -u | ||
printf("Growth:\t%f\n", log(gem_power(*gemf))/log(value)); | ||
gem_print(gemf); | ||
} | ||
} | ||
|
||
if (options.print.parens) { | ||
printf("Compressed combining scheme:\n"); | ||
print_parens_compressed(gemf); | ||
printf("\n\n"); | ||
} | ||
if (options.print.tree) { | ||
printf("Gem tree:\n"); | ||
print_tree(gemf, ""); | ||
printf("\n"); | ||
} | ||
if (options.print.table) print_table(gems, len); | ||
|
||
if (options.print.equations) { // it ruins gems, must be last | ||
printf("Equations:\n"); | ||
print_equations(gemf); | ||
printf("\n"); | ||
} | ||
|
||
for (int i=0;i<len;++i) free(pool[i]); // free | ||
free(gems); | ||
if (options.target.chain && len > 1) { | ||
free(gem_array); | ||
} | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
cmdline_options options = cmdline_options(); | ||
options.has_printing(); | ||
options.has_extra_search(); | ||
|
||
if(!options.parse_args(argc, argv)) | ||
return 1; | ||
|
||
worker(options); | ||
return 0; | ||
} | ||
|
Oops, something went wrong.