forked from mirror/toddcox-faster
Group related classes
Flattens the header structure and group related classes together.
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
#include "tc/core.hpp"
|
||||
#include "tc/groups.hpp"
|
||||
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
#include <tc/solver.hpp>
|
||||
#include <tc/groups.hpp>
|
||||
|
||||
template<class G>
|
||||
void test(const G &group) {
|
||||
auto s = std::clock();
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#include "tc/core.hpp"
|
||||
#include "tc/groups.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include <tc/solver.hpp>
|
||||
#include <tc/groups.hpp>
|
||||
|
||||
int main() {
|
||||
auto cube = tc::group::B<3>();
|
||||
auto vars = tc::solve(cube);
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "tc/core/group.hpp"
|
||||
#include "tc/core/solver.hpp"
|
||||
96
include/tc/cosets.hpp
Normal file
96
include/tc/cosets.hpp
Normal file
@@ -0,0 +1,96 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace tc {
|
||||
template<unsigned int Rank>
|
||||
class Path;
|
||||
|
||||
template<unsigned int Rank>
|
||||
class Cosets {
|
||||
private:
|
||||
std::vector<int> data;
|
||||
|
||||
public:
|
||||
Cosets(const Cosets<Rank> &) = default;
|
||||
|
||||
Cosets() = default;
|
||||
|
||||
void add_row() {
|
||||
data.resize(data.size() + Rank, -1);
|
||||
}
|
||||
|
||||
void put(int coset, int gen, int target) {
|
||||
data[coset * Rank + gen] = target;
|
||||
data[target * Rank + gen] = coset;
|
||||
}
|
||||
|
||||
[[nodiscard]] int get(int coset, int gen) const {
|
||||
return data[coset * Rank + gen];
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t order() const {
|
||||
return data.size() / Rank;
|
||||
}
|
||||
|
||||
Path<Rank> path() const;
|
||||
};
|
||||
|
||||
template<unsigned int Rank>
|
||||
class Path {
|
||||
private:
|
||||
friend class Cosets<Rank>;
|
||||
|
||||
std::vector<unsigned int> source;
|
||||
std::vector<unsigned int> gen;
|
||||
size_t _order;
|
||||
|
||||
explicit Path(size_t order) : _order(order), source(order), gen(order) {}
|
||||
|
||||
public:
|
||||
size_t order() const {
|
||||
return _order;
|
||||
}
|
||||
|
||||
template<class T, class F>
|
||||
std::vector <T> walk(const T &start, const F &op) {
|
||||
std::vector <T> res;
|
||||
res.reserve(order());
|
||||
res.push_back(start);
|
||||
|
||||
for (size_t i = 1; i < order(); ++i) {
|
||||
auto val = op(res[source[i]], gen[i]);
|
||||
res.push_back(val);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
template<class T, class E, class F>
|
||||
std::vector <T> walk(const T &start, const E &gens, const F &op) {
|
||||
return walk(start, [&](const T &s, const int g) {
|
||||
return op(s, gens[g]);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
template<unsigned int Rank>
|
||||
Path<Rank> Cosets<Rank>::path() const {
|
||||
Path<Rank> res(order());
|
||||
std::vector<bool> set(order());
|
||||
|
||||
for (int coset = 0; coset < order(); ++coset) {
|
||||
for (int gen = 0; gen < Rank; ++gen) {
|
||||
int target = get(coset, gen);
|
||||
|
||||
if (!set[target]) {
|
||||
res.source[target] = coset;
|
||||
res.gen[target] = gen;
|
||||
set[target] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
|
||||
#include <Eigen/Eigen>
|
||||
#include <iostream>
|
||||
|
||||
namespace {
|
||||
template<class T>
|
||||
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "core.hpp"
|
||||
#include "group.hpp"
|
||||
|
||||
namespace tc::group {
|
||||
/**
|
||||
* Universal Coxeter Group
|
||||
*/
|
||||
template<unsigned int Rank>
|
||||
Group <Rank> U() {
|
||||
Group<Rank> U() {
|
||||
std::stringstream ss;
|
||||
ss << "U(" << Rank << ")";
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace tc::group {
|
||||
* Simplex
|
||||
*/
|
||||
template<unsigned int Rank>
|
||||
Group <Rank> A() {
|
||||
Group<Rank> A() {
|
||||
std::stringstream ss;
|
||||
ss << "A(" << Rank << ")";
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace tc::group {
|
||||
return res;
|
||||
}
|
||||
|
||||
std::array<unsigned int, Rank - 1> mults;
|
||||
tc::Symbol<Rank - 1> mults;
|
||||
mults.fill(3);
|
||||
|
||||
return schlafli<Rank>(mults, ss.str());
|
||||
@@ -41,7 +41,7 @@ namespace tc::group {
|
||||
* Cube, Orthoplex
|
||||
*/
|
||||
template<unsigned int Rank>
|
||||
Group <Rank> B() {
|
||||
Group<Rank> B() {
|
||||
std::stringstream ss;
|
||||
ss << "B(" << Rank << ")";
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace tc::group {
|
||||
* Demicube, Orthoplex
|
||||
*/
|
||||
template<unsigned int Rank>
|
||||
Group <Rank> D() {
|
||||
Group<Rank> D() {
|
||||
std::stringstream ss;
|
||||
ss << "D(" << Rank << ")";
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace tc::group {
|
||||
* E groups
|
||||
*/
|
||||
template<unsigned int Rank>
|
||||
Group <Rank> E() {
|
||||
Group<Rank> E() {
|
||||
std::stringstream ss;
|
||||
ss << "E(" << Rank << ")";
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace tc::group {
|
||||
* Icosahedron
|
||||
*/
|
||||
template<unsigned int Rank>
|
||||
Group <Rank> H() {
|
||||
Group<Rank> H() {
|
||||
std::stringstream ss;
|
||||
ss << "H(" << Rank << ")";
|
||||
|
||||
|
||||
@@ -1,100 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
|
||||
namespace tc {
|
||||
template<unsigned int Rank>
|
||||
class Path;
|
||||
|
||||
template<unsigned int Rank>
|
||||
class Cosets {
|
||||
private:
|
||||
std::vector<int> data;
|
||||
|
||||
public:
|
||||
Cosets(const Cosets<Rank> &) = default;
|
||||
|
||||
Cosets() = default;
|
||||
|
||||
void add_row() {
|
||||
data.resize(data.size() + Rank, -1);
|
||||
}
|
||||
|
||||
void put(int coset, int gen, int target) {
|
||||
data[coset * Rank + gen] = target;
|
||||
data[target * Rank + gen] = coset;
|
||||
}
|
||||
|
||||
[[nodiscard]] int get(int coset, int gen) const {
|
||||
return data[coset * Rank + gen];
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t order() const {
|
||||
return data.size() / Rank;
|
||||
}
|
||||
|
||||
Path<Rank> path() const;
|
||||
};
|
||||
|
||||
template<unsigned int Rank>
|
||||
class Path {
|
||||
private:
|
||||
friend class Cosets<Rank>;
|
||||
|
||||
std::vector<unsigned int> source;
|
||||
std::vector<unsigned int> gen;
|
||||
size_t _order;
|
||||
|
||||
explicit Path(size_t order) : _order(order), source(order), gen(order) {}
|
||||
|
||||
public:
|
||||
size_t order() const {
|
||||
return _order;
|
||||
}
|
||||
|
||||
template<class T, class F>
|
||||
std::vector<T> walk(const T &start, const F &op) {
|
||||
std::vector<T> res;
|
||||
res.reserve(order());
|
||||
res.push_back(start);
|
||||
|
||||
for (size_t i = 1; i < order(); ++i) {
|
||||
auto val = op(res[source[i]], gen[i]);
|
||||
res.push_back(val);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
template<class T, class E, class F>
|
||||
std::vector<T> walk(const T &start, const E &gens, const F &op) {
|
||||
return walk(start, [&](const T &s, const int g) {
|
||||
return op(s, gens[g]);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
template<unsigned int Rank>
|
||||
Path<Rank> Cosets<Rank>::path() const {
|
||||
Path<Rank> res(order());
|
||||
std::vector<bool> set(order());
|
||||
|
||||
for (int coset = 0; coset < order(); ++coset) {
|
||||
for (int gen = 0; gen < Rank; ++gen) {
|
||||
int target = get(coset, gen);
|
||||
|
||||
if (!set[target]) {
|
||||
res.source[target] = coset;
|
||||
res.gen[target] = gen;
|
||||
set[target] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
#include "group.hpp"
|
||||
#include "cosets.hpp"
|
||||
|
||||
namespace {
|
||||
struct Row {
|
||||
@@ -107,7 +20,7 @@ namespace {
|
||||
public:
|
||||
int i, j, mult;
|
||||
|
||||
std::vector<Row> rows;
|
||||
std::vector <Row> rows;
|
||||
|
||||
public:
|
||||
explicit Table(int i, int j, int mult) :
|
||||
@@ -156,8 +69,9 @@ namespace {
|
||||
int *null_lst_ptr = new int;
|
||||
BlockAllocator<int> alloc;
|
||||
|
||||
std::array<std::shared_ptr<Table>, Rels> tables;
|
||||
std::array<std::vector<std::shared_ptr<Table>>, Rank> deps;
|
||||
std::array <std::shared_ptr<Table>, Rels> tables;
|
||||
std::array <std::vector<std::shared_ptr < Table>>, Rank>
|
||||
deps;
|
||||
|
||||
public:
|
||||
explicit Tables(const tc::Group<Rank> &group) {
|
||||
Reference in New Issue
Block a user