Modified facts to use heap

This commit is contained in:
JCRaymond
2019-12-24 23:23:12 -05:00
parent ed69ba6dc0
commit 55520fd50a
2 changed files with 16 additions and 19 deletions

View File

@@ -1,6 +1,6 @@
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <functional>
#include <iostream>
@@ -62,12 +62,6 @@ struct RelTable {
}
};
struct {
bool operator()(std::pair<int,int> p1, std::pair<int,int> p2) {
return p1.first == p2.first ? p1.second > p2.second : p1.first > p2.first;
}
} intpair_greater;
struct Group {
int ngens;
std::vector<std::vector<int>> _mults;
@@ -178,16 +172,21 @@ struct Group {
rel.add_row();
}
std::vector<std::pair<int,int>> facts;
facts.push_back(std::make_pair(coset, gen));
std::priority_queue<int, std::vector<int>, std::greater<int>> facts;
facts.push(coset*ngens + gen);
while (!facts.empty()) {
auto top = facts.back();
coset = top.first;
gen = top.second;
facts.pop_back();
int fact_idx = facts.top();
facts.pop();
if (cosets.get(fact_idx) != -1)
continue;
cosets.put(fact_idx, target);
coset = fact_idx / ngens;
gen = fact_idx % ngens;
cosets.put(coset, gen, target);
for (RelTable &rel : rel_tables) {
if ( (gen == rel.gens[0] or gen == rel.gens[1]) and (rel.fam[target] == -1) ) {
@@ -200,19 +199,17 @@ struct Group {
if (rel.gen[target] == rel.mult) {
int lst = rel.lst[rel.fam[target]];
int gen_ = rel.gens[(int)(rel.gens[0] == gen)];
facts.push_back(std::make_pair(lst, gen_));
facts.push(lst*ngens + gen_);
}
else if (rel.gen[target] == -rel.mult) {
int gen_ = rel.gens[rel.gens[0] == gen];
facts.push_back(std::make_pair(target, gen_));
facts.push(target*ngens + gen_);
}
else if (rel.gen[target] == rel.mult - 1) {
rel.lst[rel.fam[target]] = target;
}
}
}
std::sort(facts.begin(), facts.end(), intpair_greater);
}
for (RelTable &rel : rel_tables) {

View File

@@ -3,7 +3,7 @@
#include <iostream>
int main() {
Group g = B(9);
Group g = E(7);
auto s = std::chrono::system_clock::now();
auto cosets = g.solve();