Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tikz #221

Merged
merged 82 commits into from
Jan 12, 2024
Merged

Tikz #221

Show file tree
Hide file tree
Changes from 80 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
999a77e
This should be a cleaner push, i hope
Dec 4, 2023
f2c57c5
placeholder
Dec 4, 2023
7f482f0
git
Dec 4, 2023
1bf42f6
added config.mf again
Dec 4, 2023
51b1d40
changed enum_graphs to trees
Dec 4, 2023
2e2ab96
Generates now output file. Also distinguishes between enum and trees …
Dec 8, 2023
48e5cbf
added Header and Footer to tikz code. Still missing } for trees.
Dec 8, 2023
cd1211f
Removed separate print_value_pp function. Since we piping the outpu i…
Dec 11, 2023
ecdee14
found the missing {, now just need to localize start and end point fo…
Dec 13, 2023
56d34a0
remove Daniels functions in cpp.cc for now
sjanssen2 Dec 14, 2023
c43f5f2
adding auto algebra generation for tikZ enum
sjanssen2 Dec 14, 2023
0fbf99d
revert some of Daniels work
sjanssen2 Dec 14, 2023
1261977
revert more
sjanssen2 Dec 14, 2023
b4083b1
revert
sjanssen2 Dec 14, 2023
0b5f848
rename "trees" into "tikz"
sjanssen2 Dec 14, 2023
23734ae
first tikz test case
sjanssen2 Dec 14, 2023
fd56462
be more specific in error message
sjanssen2 Dec 14, 2023
9d2f273
expose color definitions via header files (to be also used via tikz)
sjanssen2 Dec 15, 2023
ade6a07
use external color definitions
sjanssen2 Dec 15, 2023
fd5f00d
first tikz test for RNA
sjanssen2 Dec 15, 2023
294622c
fixed tikz for single track grammars + for RNA instances, use a new a…
sjanssen2 Dec 15, 2023
bce4203
codestyle
sjanssen2 Dec 15, 2023
6876340
use branch tikz of truth
sjanssen2 Dec 15, 2023
d6fc881
same line number for semantic error
sjanssen2 Dec 15, 2023
71c9273
add test with constant terminals
sjanssen2 Dec 15, 2023
e3a5888
also add enum to instance
sjanssen2 Dec 15, 2023
b15c525
Merge branch 'master' into tikz
sjanssen2 Dec 17, 2023
d35e3f7
Merge branch 'master' into tikz
sjanssen2 Dec 18, 2023
d6697e1
Merge branch 'master' of github.com:jlab/gapc into tikz
sjanssen2 Dec 18, 2023
1b9fada
Update c-cpp.yml
sjanssen2 Dec 18, 2023
599254e
Merge branch 'master' of github.com:jlab/gapc into tikz
sjanssen2 Dec 18, 2023
16c4d72
Merge branch 'master' into tikz
sjanssen2 Dec 18, 2023
b565a6c
Merge branch 'tikz' of github.com:jlab/gapc into tikz
sjanssen2 Dec 18, 2023
15979e5
using tikz3 as truth branch
sjanssen2 Dec 18, 2023
0a2916d
Merge branch 'master' into tikz
sjanssen2 Dec 18, 2023
5286051
differentiate between RNA and RAW input for tikz auto generation
sjanssen2 Dec 18, 2023
7ca0389
Merge branch 'tikz' of github.com:jlab/gapc into tikz
sjanssen2 Dec 18, 2023
700d810
codestyle
sjanssen2 Dec 18, 2023
84dcfe1
if type is substring and input is raw, use append_deep instead of "no…
sjanssen2 Dec 19, 2023
9a25d03
adding more test instances
sjanssen2 Dec 19, 2023
44cfd4d
adding test for tikz & backtracing
sjanssen2 Dec 19, 2023
7b655a7
let each algebra know if it was automatically generated or not (= NON…
sjanssen2 Dec 20, 2023
6111229
adding a mechanism to obtain accessors like ".second.first" for singu…
sjanssen2 Dec 20, 2023
dbbd999
print latex tikZ output IFF auto tikz algebra was used in instance
sjanssen2 Dec 20, 2023
684666e
avoid printing "Answer:" to stdout IFF auto tikz was requested, to av…
sjanssen2 Dec 20, 2023
ce0fda9
escape _ for TikZ
sjanssen2 Dec 20, 2023
29e58bc
left align algebra results
sjanssen2 Dec 20, 2023
f9e6462
Merge branch 'master' of github.com:jlab/gapc into tikz
sjanssen2 Dec 20, 2023
b14f738
codestyle
sjanssen2 Dec 20, 2023
5b0dbb3
additionally calling print_document_footer after answers have been re…
sjanssen2 Dec 21, 2023
47cee19
store fwd part of algebra product split for two phase backtracing; ad…
sjanssen2 Dec 21, 2023
71385f9
refactor and adding code for tikZ output generation for --backtrace
sjanssen2 Dec 21, 2023
a4ba73e
renamed contains_tiks to uses_tikz
sjanssen2 Dec 21, 2023
c65caac
add uses_tikz
sjanssen2 Dec 21, 2023
fe7034f
elaborate test instance
sjanssen2 Dec 21, 2023
bc2ec59
adding tikz instance with backtracing
sjanssen2 Dec 21, 2023
523cae7
adding instance for backtracing with tikz
sjanssen2 Dec 21, 2023
07eb70f
adding tests for backtracing&tikz and empty answer lists
sjanssen2 Dec 21, 2023
4e461c7
Merge branch 'master' into tikz
sjanssen2 Dec 21, 2023
c6bb204
improve codestyle for generated out.hh
sjanssen2 Dec 21, 2023
45dcfc8
don't access uninitialized objects to avoid segfaults
sjanssen2 Dec 21, 2023
a5135c0
generate output tikz code for subopt
sjanssen2 Dec 21, 2023
346b250
adding subopt tikz test
sjanssen2 Dec 21, 2023
2bf1bd8
tikz code generation for --backtrace (not --kbracktrace)
sjanssen2 Dec 21, 2023
797efbb
adding --backtrace test
sjanssen2 Dec 21, 2023
320f633
move latex document header into specific function to avoid repetitive…
sjanssen2 Dec 21, 2023
5732431
adding window mode test
sjanssen2 Dec 21, 2023
14d39f1
adding a function that escapes special latex characters for CHAR term…
sjanssen2 Dec 21, 2023
2060f3d
adding new test
sjanssen2 Dec 21, 2023
bb981d8
include what I use
sjanssen2 Dec 21, 2023
d0cf373
also escape subsequences
sjanssen2 Dec 21, 2023
8612c6f
example with string latex escape
sjanssen2 Dec 21, 2023
9434533
tikZ now also reports NT parameters for algebra functions
sjanssen2 Dec 21, 2023
2a32ea2
test NT parameter reporting in tikZ
sjanssen2 Dec 21, 2023
bf6d3ce
let unittest know about Subsequence
sjanssen2 Dec 21, 2023
0731a21
special treatment for overlay products as used in e.g. sample
sjanssen2 Dec 22, 2023
6291b21
move latex escaping into rope.hh
sjanssen2 Dec 22, 2023
ec18edc
escaping algebra names
sjanssen2 Dec 22, 2023
b99600a
extending tikZ header such that individual image PDFs can be created
sjanssen2 Jan 2, 2024
6551c6a
adding changelog text
sjanssen2 Jan 8, 2024
fadc34e
adding/updating comments to append_deep_rna and append_deep_rna_loc
sjanssen2 Jan 12, 2024
85ed757
Update c-cpp.yml
sjanssen2 Jan 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
run: sudo apt-get install flex bison make libboost-all-dev libgsl-dev python3 python3-pip

- name: Checkout truth
run: git clone --branch master https://github.com/jlab/gapc-test-suite.git $GITHUB_WORKSPACE/../gapc-test-suite
run: git clone --branch tikz3 https://github.com/jlab/gapc-test-suite.git $GITHUB_WORKSPACE/../gapc-test-suite

- uses: actions/checkout@v3
- name: configure
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:
- name: add base Haskell lib containers (prelude, Data.Map, Data.Map.Strict)
run: cabal install --lib base
- name: Checkout truth
run: git clone --branch master https://github.com/jlab/gapc-test-suite.git $GITHUB_WORKSPACE/../gapc-test-suite
run: git clone --branch tikz3 https://github.com/jlab/gapc-test-suite.git $GITHUB_WORKSPACE/../gapc-test-suite

- uses: actions/checkout@v3
- name: configure
Expand Down
77 changes: 77 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,80 @@
bellmansgapc (2024.08.01-0ubuntu0ppa1~noble1) xenial; urgency=medium

* features:
+ new auto generation of "tikz" algebras" to generate tikZ code to draw
candidate trees. Just add "algebra foo auto tikz" to your gap code, as
you already did for "count" or "enum".
Note: for lager search spaces, you will probably hit the limit of
recursive LaTeX environments when compiling the generated tikZ code.

-- janssenlab <[email protected]> Mon, 8 January 2024 11:36:00 +0200

bellmansgapc (2024.08.01-0ubuntu0ppa1~mantic1) xenial; urgency=medium

* features:
+ new auto generation of "tikz" algebras" to generate tikZ code to draw
candidate trees. Just add "algebra foo auto tikz" to your gap code, as
you already did for "count" or "enum".
Note: for lager search spaces, you will probably hit the limit of
recursive LaTeX environments when compiling the generated tikZ code.

-- janssenlab <[email protected]> Mon, 8 January 2024 11:36:00 +0200

bellmansgapc (2024.08.01-0ubuntu0ppa1~lunar1) xenial; urgency=medium

* features:
+ new auto generation of "tikz" algebras" to generate tikZ code to draw
candidate trees. Just add "algebra foo auto tikz" to your gap code, as
you already did for "count" or "enum".
Note: for lager search spaces, you will probably hit the limit of
recursive LaTeX environments when compiling the generated tikZ code.

-- janssenlab <[email protected]> Mon, 8 January 2024 11:36:00 +0200

bellmansgapc (2024.08.01-0ubuntu0ppa1~jammy1) xenial; urgency=medium

* features:
+ new auto generation of "tikz" algebras" to generate tikZ code to draw
candidate trees. Just add "algebra foo auto tikz" to your gap code, as
you already did for "count" or "enum".
Note: for lager search spaces, you will probably hit the limit of
recursive LaTeX environments when compiling the generated tikZ code.

-- janssenlab <[email protected]> Mon, 8 January 2024 11:36:00 +0200

bellmansgapc (2024.08.01-0ubuntu0ppa1~focal1) xenial; urgency=medium

* features:
+ new auto generation of "tikz" algebras" to generate tikZ code to draw
candidate trees. Just add "algebra foo auto tikz" to your gap code, as
you already did for "count" or "enum".
Note: for lager search spaces, you will probably hit the limit of
recursive LaTeX environments when compiling the generated tikZ code.

-- janssenlab <[email protected]> Mon, 8 January 2024 11:36:00 +0200

bellmansgapc (2024.08.01-0ubuntu0ppa1~bionic1) xenial; urgency=medium

* features:
+ new auto generation of "tikz" algebras" to generate tikZ code to draw
candidate trees. Just add "algebra foo auto tikz" to your gap code, as
you already did for "count" or "enum".
Note: for lager search spaces, you will probably hit the limit of
recursive LaTeX environments when compiling the generated tikZ code.

-- janssenlab <[email protected]> Mon, 8 January 2024 11:36:00 +0200

bellmansgapc (2024.08.01-0ubuntu0ppa1~xenial1) xenial; urgency=medium

* features:
+ new auto generation of "tikz" algebras" to generate tikZ code to draw
candidate trees. Just add "algebra foo auto tikz" to your gap code, as
you already did for "count" or "enum".
Note: for lager search spaces, you will probably hit the limit of
recursive LaTeX environments when compiling the generated tikZ code.

-- janssenlab <[email protected]> Mon, 8 January 2024 11:36:00 +0200

bellmansgapc (2023.07.05-0ubuntu0ppa1~xenial1) xenial; urgency=medium

* features:
Expand Down
6 changes: 6 additions & 0 deletions rtlib/generic_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ int main(int argc, char **argv) {
std::cout << std::setprecision(FLOAT_ACC) << std::fixed;
#endif

// print statements prior to result list, e.g. for TikZ document generation
obj.print_document_header(std::cout);
#ifdef WINDOW_MODE
unsigned n = obj.t_0_seq.size();
for (unsigned int i = 0; ; i+=opts.window_increment) {
Expand All @@ -94,7 +96,9 @@ int main(int argc, char **argv) {
gapc::add_event("end_computation");

#ifndef OUTSIDE
#ifndef TIKZ
std::cout << "Answer: \n";
#endif
obj.print_result(std::cout, res);
#else
obj.report_insideoutside(std::cout);
Expand All @@ -112,6 +116,8 @@ int main(int argc, char **argv) {
gapc::add_event("end");
#endif

// print statements after result list, e.g. for TikZ document generation
obj.print_document_footer(std::cout);
#ifdef STATS
obj.print_stats(std::cerr);
#endif
Expand Down
14 changes: 14 additions & 0 deletions rtlib/rna.hh
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,20 @@ inline void append_deep_rna(
str.append(static_cast<char>(base_to_char(*i)));
}

// same as append_deep_rna, but LOC will leave a <X> instead of an empty string
sjanssen2 marked this conversation as resolved.
Show resolved Hide resolved
template<typename X, typename alphabet, typename pos_type>
inline void append_deep_rna_loc(
rope::Ref<X> &str, const Basic_Subsequence<alphabet, pos_type> &sub) {
for (typename Basic_Subsequence<alphabet, pos_type>::const_iterator
i = sub.begin(); i != sub.end(); ++i)
str.append(static_cast<char>(base_to_char(*i)));
if ((sub.size() == 0) && (sub.i == sub.j)) {
str.append('<');
str.append(static_cast<int>(sub.i));
str.append('>');
}
}

// ======== energy wrapper function ========

/*
Expand Down
45 changes: 45 additions & 0 deletions rtlib/rope.hh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
#include <fstream>
#include <sstream>

#include <string>
#include <boost/cstdint.hpp>
#include <boost/algorithm/string/replace.hpp>

#include "../rtlib/cstr.h"
#include "bitops.hh"
Expand Down Expand Up @@ -754,6 +756,49 @@ inline void append(rope::Ref<X> &str, const T &x) {
str.append(x);
}

/* accepts a string and escapes all containing characters to be compatible
* to LaTeX math mode. Used for tikZ generations.
*/
inline std::string latex(const std::string in) {
std::string out = std::string(in);

/* https://www.cespedes.org/blog/85/how-to-escape-latex-special-characters
* note that we are in math mode, which might use different rules than
* LaTeX's "normal" text mode. */
boost::replace_all(out, "\\", "\\backslash");
boost::replace_all(out, "#", "\\#");
boost::replace_all(out, "$", "\\$");
boost::replace_all(out, "%", "\\%");
boost::replace_all(out, "&", "\\&");
boost::replace_all(out, "_", "\\_");
boost::replace_all(out, "{", "\\{");
boost::replace_all(out, "}", "\\}");
boost::replace_all(out, "^", "\\hat{\\ }");
sjanssen2 marked this conversation as resolved.
Show resolved Hide resolved
boost::replace_all(out, "~", "\\tilde{\\ }");

return out;
}
template<typename X>
inline void append_latex(rope::Ref<X> &str, char &c) {
std::string in(1, c);
std::string out = latex(in);
str.append(out.c_str(), out.size());
}
template<typename X>
inline void append_latex(rope::Ref<X> &str, const Subsequence &s) {
for (typename Subsequence::const_iterator i = s.begin(); i != s.end(); ++i) {
char ichar = (*i);
append_latex(str, ichar);
}
}
template<typename X>
inline void append_latex(rope::Ref<X> &str, const char *s, int slen) {
for (int i = 0; i < slen; ++i) {
char ichar = (s[i]);
append_latex(str, ichar);
}
}

template<class T, typename X>
inline void append(rope::Ref<X> &str, char c, T i) {
assert(i >= 0);
Expand Down
17 changes: 15 additions & 2 deletions src/algebra.hh
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ class Filter;


class Algebra : public Signature_Base {
public:
// if algebra is auto generated, it is one of three types: enum, count, tikz
// otherwise, it is a user defined one, i.e. not auto generated: NONE
enum AutoRole { NONE, ENUM, COUNT, TIKZ };

private:
std::string *default_choice_fn_mode;
void init_choice_fns();
AutoRole role = AutoRole::NONE;

public:
hashtable<std::string, Fn_Def*> fns;
Expand All @@ -77,9 +83,9 @@ class Algebra : public Signature_Base {
signature(NULL), signature_name(NULL) {
}

explicit Algebra(std::string *n)
explicit Algebra(std::string *n, AutoRole role)
: Signature_Base(n), default_choice_fn_mode(0),
signature(NULL), signature_name(NULL) {
role(role), signature(NULL), signature_name(NULL) {
}


Expand Down Expand Up @@ -139,6 +145,13 @@ class Algebra : public Signature_Base {
void add_choice_specialisations(Product::Two &product);

Algebra *copy() const;

/* return role of automatically generated algebra. None if algebra is user
* defined.
*/
AutoRole get_auto_role() {
return this->role;
}
};

inline std::ostream &operator<<(std::ostream &s, const Algebra &a) {
Expand Down
2 changes: 2 additions & 0 deletions src/ast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ AST::AST()
signature(NULL),
first_instance(NULL), instance_(0),
backtrack_product(0),
fwd_product(0),
backtrack_filter(0),
original_product(0),
char_type(0),
Expand Down Expand Up @@ -739,6 +740,7 @@ Instance *AST::split_instance_for_backtrack(std::string &n) {
original_product = two;

backtrack_product = two->right();
fwd_product = two->left();
backtrack_filter = two->filter();
Instance *score = new Instance(i->name(), two->left(), grammar());
return score;
Expand Down
16 changes: 15 additions & 1 deletion src/ast.hh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include "product.hh"

#include "checkpoint.hh"
#include "instance.hh"


class Signature;
Expand Down Expand Up @@ -257,6 +258,10 @@ class AST {
private:
// FIXME
Product::Base *backtrack_product;

// when instance is split for backtracing, fwd_product is the part computed
// in the forward pass
Product::Base *fwd_product;
Filter *backtrack_filter;
Product::Two *original_product;

Expand Down Expand Up @@ -299,9 +304,12 @@ class AST {

std::list<std::pair<Filter*, Expr::Fn_Call*> > sf_filter_code;

Product::Base * get_backtrack_product() {
Product::Base * get_backtrack_product() const {
return backtrack_product;
}
Product::Base * get_fwd_product() const {
return fwd_product;
}

Printer::Checkpoint *checkpoint;

Expand All @@ -317,6 +325,12 @@ class AST {
std::vector<std::string> *get_outside_nt_list() const {
return this->outside_nt_list;
}

bool uses_tikz() const {
return instance_->product->uses_tikz() ||
(backtrack_product && backtrack_product->uses_tikz()) ||
(fwd_product && fwd_product->uses_tikz());
}
};

#endif // SRC_AST_HH_
2 changes: 1 addition & 1 deletion src/backtrack_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ void Backtrack_Base::gen_nt_decls(const std::list<Symbol::NT*> &nts) {

void Backtrack_Base::gen_algebra(Signature &signature, Type::Base *alph) {
Algebra *a = signature.generate_backtrace
(new std::string("bt_algebra"), value_type, pos_type, alph);
(new std::string("bt_algebra"), value_type, pos_type, alph, Algebra::NONE);
algebra = a;
}
Loading
Loading