Skip to content

Commit

Permalink
Add bleed 1D suite, improve makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
12345ieee committed Feb 15, 2020
1 parent 5694ac5 commit 43e2312
Show file tree
Hide file tree
Showing 7 changed files with 452 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Compilation results
bin/
.deps/

# Tables to test with
/table_*
Expand Down
25 changes: 19 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,32 @@ QUERY_CRIT=critgem/critquery critgem/critquery-amps
QUERY_KILLGEM=killgem/kgquery-alone killgem/kgquery-amps killgem/kgquery-setup killgem/kgquery-omnia
QUERY_MGNGEM=managem/mgquery-ngems
QUERY_KGNGEM=killgem/kgquery-ngems
QUERY_DIST=$(QUERY_LEECH) $(QUERY_MANAGEM) $(QUERY_KILLGEM)
QUERY_ALL=$(QUERY_DIST) $(QUERY_CRIT) $(QUERY_MGNGEM) $(QUERY_KGNGEM)
QUERY_BLEED=bleedgem/bleedquery
QUERY_DIST=$(QUERY_LEECH) $(QUERY_MANAGEM) $(QUERY_CRIT) $(QUERY_KILLGEM) $(QUERY_BLEED)
QUERY_ALL=$(QUERY_DIST) $(QUERY_MGNGEM) $(QUERY_KGNGEM)

# Build
BUILD_LEECH=leechgem/leechbuild
BUILD_MANAGEM=managem/mgbuild-appr managem/mgbuild-exact managem/mgbuild-c6
BUILD_CRIT=critgem/critbuild
BUILD_KILLGEM=killgem/kgbuild-appr killgem/kgbuild-exact killgem/kgbuild-c6
BUILD_ALL=$(BUILD_LEECH) $(BUILD_MANAGEM) $(BUILD_CRIT) $(BUILD_KILLGEM)
BUILD_BLEED=bleedgem/bleedbuild
BUILD_ALL=$(BUILD_LEECH) $(BUILD_MANAGEM) $(BUILD_CRIT) $(BUILD_KILLGEM) $(BUILD_BLEED)

# Combine
COMBINE_LEECH=leechgem/leechcombine
COMBINE_MANAGEM=managem/mgcombine-appr
COMBINE_CRIT=critgem/critcombine
COMBINE_KILLGEM=killgem/kgcombine-appr killgem/kgcombine-exact
COMBINE_ALL=$(COMBINE_LEECH) $(COMBINE_MANAGEM) $(COMBINE_CRIT) $(COMBINE_KILLGEM)
COMBINE_BLEED=bleedgem/bleedcombine
COMBINE_ALL=$(COMBINE_LEECH) $(COMBINE_MANAGEM) $(COMBINE_CRIT) $(COMBINE_KILLGEM) $(COMBINE_BLEED)

# Type aggregates
LEECH_ALL=$(QUERY_LEECH) $(BUILD_LEECH) $(COMBINE_LEECH)
MANAGEM_ALL=$(QUERY_MANAGEM) $(QUERY_MGNGEM) $(BUILD_MANAGEM) $(COMBINE_MANAGEM)
CRIT_ALL=$(QUERY_CRIT) $(BUILD_CRIT) $(COMBINE_CRIT)
KILLGEM_ALL=$(QUERY_KILLGEM) $(QUERY_KGNGEM) $(BUILD_KILLGEM) $(COMBINE_KILLGEM)
BLEED_ALL=$(QUERY_BLEED) $(BUILD_BLEED) $(COMBINE_BLEED)

# Parser
PARSER=parser
Expand All @@ -55,6 +59,7 @@ BINDIR:=bin
WINDIR:=$(BINDIR)/win
TABLES_DIR:=gem_tables
INCLUDE_DIR:=include
DEPS_DIR:=.deps

# Version
VERSION:=$(shell git describe --tags | rev | cut -d '-' -f2- | rev)
Expand Down Expand Up @@ -86,6 +91,7 @@ set-leech: $(LEECH_ALL)
set-managem: $(MANAGEM_ALL)
set-crit: $(CRIT_ALL)
set-killgem: $(KILLGEM_ALL)
set-bleed: $(BLEED_ALL)

.PHONY: set-query set-build set-combine set-leech set-managem set-crit set-killgem

Expand Down Expand Up @@ -122,9 +128,15 @@ $(BINDIR):

.PHONY: move move-white

# Include deps folder
-include $(wildcard $(DEPS_DIR)/*.d)

# Compilation targets
$(DEV_ALL): %: %.cpp $(INCLUDE_DIR)/*.h
$(CXX) $(CXXFLAGS) $< $(LIBFLAGS) -o $@
$(DEV_ALL): %: %.cpp | $(DEPS_DIR)
$(CXX) $(CXXFLAGS) -MMD -MF $(DEPS_DIR)/$(<F).d -MT $@ $< $(LIBFLAGS) -o $@

$(DEPS_DIR):
mkdir -p $(DEPS_DIR)

# Tables
tables: $(TABLES_DIR)/table_* | $(TABLES_DIR) $(BINDIR)
Expand All @@ -138,6 +150,7 @@ $(TABLES_DIR):
# Clean
clean:
@rm -vf $(DEV_ALL)
@rm $(DEPS_DIR)/*

clean-white:
@if [ -d "white" ]; then \
Expand Down
68 changes: 68 additions & 0 deletions bleedgem/bleedbuild.cpp
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;
}

117 changes: 117 additions & 0 deletions bleedgem/bleedcombine.cpp
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;
}

Loading

0 comments on commit 43e2312

Please sign in to comment.