working implementation

This commit is contained in:
2019-11-20 12:29:01 -05:00
parent e9abbe0e30
commit fcb57c3b4e
2 changed files with 62 additions and 17 deletions

View File

@@ -2,5 +2,9 @@ cmake_minimum_required(VERSION 3.14)
project(hpc)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
find_package(OpenMP)
add_executable(hpc main.cpp)
target_link_libraries(hpc PUBLIC OpenMP::OpenMP_CXX)

View File

@@ -1,21 +1,25 @@
#include <iostream>
#include <vector>
#include <iomanip>
#include <chrono>
using Gens=std::vector<int>;
using Table=std::vector<Gens>;
void pp(const Gens &g) {
void pp(const Gens &g, int w) {
for (const auto &e : g) {
std::cout << e << " ";
std::cout << std::setw(w) << e << " ";
}
std::cout << std::endl;
}
void pp(const Table &t) {
std::cout << "| table:" << std::endl;
for (const auto &g : t) {
std::cout << "| ";
pp(g);
int w = 3;
for (size_t i = 0; i < t.size(); ++i) {
std::cout << std::setw(w) << i << " | ";
pp(t[i], w);
}
}
@@ -41,8 +45,31 @@ void add_row(const int ngens, const std::vector<Gens> &rels,
}
}
int add_coset(const int ngens, const std::vector<Gens> &rels,
Table &cosets, std::vector<Table> &reltables,
Table &starts, Table &ends,
int coset_scan_hint) {
int C = cosets.size();
for (int c = coset_scan_hint; c < C; ++c) {
std::vector<int> &row = cosets[c];
for (int g = 0; g < ngens; ++g) {
if (row[g] == -1) {
row[g] = C;
add_row(ngens, rels, cosets, reltables, starts, ends);
cosets[C][g] = c;
return c;
}
}
}
return -1;
}
/**
* @return true if anything was learned
* learn until it can't
*/
void learn(Table &coset, const std::vector<Gens> &rels,
std::vector<Table> &reltables, Table &starts, Table &ends) {
@@ -63,27 +90,28 @@ void learn(Table &coset, const std::vector<Gens> &rels,
if (s == e - 1) continue;
while (row[s] == -1) {
int &lookup = coset[row[s]][rel[s]];
while (row[s + 1] == -1) {
const int &lookup = coset[row[s]][rel[s]];
if (lookup < 0) break;
row[s] = lookup;
s++;
row[s] = lookup;
}
while (row[e] == -1) {
int &lookup = coset[row[e]][rel[e - 1]];
while (row[e - 1] == -1) {
const int &lookup = coset[row[e]][rel[e - 1]];
if (lookup < 0) break;
row[e] = lookup;
e--;
row[e] = lookup;
}
if (s == e - 1) {
complete = false;
coset[row[s]][rel[s]] = rel[row[e]];
coset[row[e]][rel[s]] = rel[row[s]];
const int &gen = rel[s];
coset[row[s]][gen] = row[e];
coset[row[e]][gen] = row[s];
}
starts[r][c] = s;
@@ -109,17 +137,30 @@ Table solve_tc(int ngens, const Gens &subgens, const std::vector<Gens> &rels) {
cosets[0][gen] = 0;
}
int coset_scan_hint = 0;
while (coset_scan_hint >= 0) {
learn(cosets, rels, reltables, starts, ends);
coset_scan_hint = add_coset(ngens, rels, cosets, reltables, starts, ends, coset_scan_hint);
}
return cosets;
}
int main() {
auto cosets = solve_tc(3, {0, 1}, {
{0, 1, 0, 1, 0, 1, 0, 1},
auto s = std::chrono::system_clock::now();
auto cosets = solve_tc(4, {}, {
{0, 1, 0, 1, 0, 1, 0, 1, 0, 1},
{1, 2, 1, 2, 1, 2},
{2, 3, 2, 3, 2, 3},
{0, 2, 0, 2},
{0, 3, 0, 3},
{1, 3, 1, 3},
});
auto e = std::chrono::system_clock::now();
std::chrono::duration<float> diff = e - s;
std::cout << diff.count() << "s" << std::endl;
pp(cosets);
// pp(cosets);
return 0;
}