diff --git a/.idea/cosets.iml b/.idea/cosets.iml deleted file mode 100644 index f08604b..0000000 --- a/.idea/cosets.iml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 9bb8048..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 44442b6..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/cosets/src/tc.cpp b/cosets/src/tc.cpp index 63d0262..63f83e1 100644 --- a/cosets/src/tc.cpp +++ b/cosets/src/tc.cpp @@ -1,11 +1,13 @@ #include #include +template struct Row; template struct Table; +template struct Row { std::vector::const_iterator l; std::vector::const_iterator r; @@ -15,10 +17,37 @@ struct Row { Row(const std::vector &vec, int from, int to) { this->l = vec.begin(); - this->r = vec.end(); + this->r = vec.end() - 1; this->from = from; this->to = to; } + + bool learn(Table &table) { + if (r - l == 0) { + return false; + } + + while (r - l > 0) { + int next = table.get(from, *l); + if (next < 0) break; + l++; + from = next; + } + + while (r - l > 0) { + int next = table.rget(*r, to); + if (next < 0) break; + r--; + to = next; + } + + if (r - l == 0) { + table.set(from, *l, to); + return true; + } + + return false; + } }; template @@ -26,15 +55,52 @@ struct Table { std::vector> fwd; std::vector> rev; + Table() { + add_row(); + } + void add_row() { - fwd.push_back(std::vector(N)); + fwd.push_back(std::vector(N, -1)); + rev.push_back(std::vector(N, -1)); + } + + int add_coset() { + for (int from = 0; from < size(); ++from) { + for (int gen = 0; gen < N; ++gen) { + if (get(from, gen) < 0) { + int to = size(); + add_row(); + set(from, gen, to); + return to; + } + } + } + return 0; + } + + [[nodiscard]] unsigned size() const { + return fwd.size(); + } + + void set(int from, int gen, int to) { + fwd[from][gen] = to; + rev[to][gen] = from; + } + + [[nodiscard]] int get(int from, int gen) const { + return fwd[from][gen]; + } + + [[nodiscard]] int rget(int gen, int to) const { + return rev[to][gen]; } }; -std::ostream &operator<<(std::ostream &out, const Row &row) { +template +std::ostream &operator<<(std::ostream &out, const Row &row) { out << "[ " << row.from << " | "; auto it = row.l; - while (it != row.r) { + while (row.r - it > 0) { out << *it << " "; it++; } @@ -45,7 +111,7 @@ std::ostream &operator<<(std::ostream &out, const Row &row) { template std::ostream &operator<<(std::ostream &out, const Table &table) { out << "["; - for (int j = 0; j < table.fwd.size(); ++j) { + for (unsigned j = 0; j < table.size(); ++j) { auto arr = table.fwd[j]; out << "["; for (int i = 0; i < N; ++i) { @@ -65,19 +131,33 @@ std::ostream &operator<<(std::ostream &out, const Table &table) { } int main(int argc, char *argv[]) { - int gens = 2; std::vector> ids{ {0, 0}, {1, 1}, {0, 1, 0, 1, 0, 1} }; + Row<3> row(ids[2], 0, 0); Table<3> table; + table.add_row(); table.add_row(); table.add_row(); - table.add_row(); - std::cout << table; + + table.set(0, 0, 1); + table.set(1, 1, 2); + + std::cout << table << std::endl; + std::cout << row << std::endl; + + row.learn(table); + std::cout << row << std::endl; + +// std::cout << table << std::endl; +// table.add_coset(); +// std::cout << table << std::endl; +// +// row.learn(table); return 0; -} \ No newline at end of file +}