Add spanning tree path to cosets.

This commit is contained in:
2020-01-03 22:37:11 -05:00
parent f1c57b241f
commit 3c3cd69be7
4 changed files with 35 additions and 1 deletions

View File

@@ -1,2 +1,5 @@
add_executable(bench bench.cpp) add_executable(bench bench.cpp)
target_link_libraries(bench PRIVATE tc) target_link_libraries(bench PRIVATE tc)
add_executable(path path.cpp)
target_link_libraries(path PRIVATE tc)

17
example/path.cpp Normal file
View File

@@ -0,0 +1,17 @@
#include "solver.h"
#include "groups.h"
#include <ctime>
#include <iostream>
int main() {
auto cube = tc::group::B(3);
auto vars = tc::solve(cube, {});
for (int target = 1; target < vars.len; target++) {
auto &action = vars.path[target];
std::cout << action.coset << " " << action.gen << " " << target << std::endl;
}
return 0;
}

View File

@@ -4,9 +4,15 @@
#include <vector> #include <vector>
namespace tc { namespace tc {
struct Action {
int coset = -1;
int gen = -1;
};
struct Cosets { struct Cosets {
int ngens; int ngens;
std::vector<int> data; std::vector<int> data;
std::vector<Action> path;
int len; int len;
explicit Cosets(int ngens); explicit Cosets(int ngens);
@@ -21,5 +27,4 @@ namespace tc {
[[nodiscard]] int get(int idx) const; [[nodiscard]] int get(int idx) const;
}; };
} }

View File

@@ -7,11 +7,16 @@ namespace tc {
void Cosets::add_row() { void Cosets::add_row() {
len++; len++;
data.resize(data.size() + ngens, -1); data.resize(data.size() + ngens, -1);
path.resize(path.size() + 1);
} }
void Cosets::put(int coset, int gen, int target) { void Cosets::put(int coset, int gen, int target) {
data[coset * ngens + gen] = target; data[coset * ngens + gen] = target;
data[target * ngens + gen] = coset; data[target * ngens + gen] = coset;
if (path[target].coset == -1) {
path[target] = {coset, gen};
}
} }
void Cosets::put(int idx, int target) { void Cosets::put(int idx, int target) {
@@ -19,6 +24,10 @@ namespace tc {
int gen = idx % ngens; int gen = idx % ngens;
data[idx] = target; data[idx] = target;
data[target * ngens + gen] = coset; data[target * ngens + gen] = coset;
if (path[target].coset == -1) {
path[target] = {coset, gen};
}
} }
int Cosets::get(int coset, int gen) const { int Cosets::get(int coset, int gen) const {