diff options
-rw-r--r-- | cacount.cpp | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/cacount.cpp b/cacount.cpp index ca6c1ab..210d9b8 100644 --- a/cacount.cpp +++ b/cacount.cpp @@ -51,7 +51,7 @@ void init(Trans &t) { Trans* findCycle(Trans &t) { // forward to t=maxState; now every state is in a cycle iterTrans(logState, [&](int s) { - t[s] = t[t[s]]; }); + t[s] = t[t[s]]; }, true); // compute loop id (lowest occuring state no): go through the loop again and // record the lowest occuring state number Trans &c(*new Trans()); @@ -59,7 +59,7 @@ Trans* findCycle(Trans &t) { c[s] = t[s]; }); iterTrans(logState, [&](int s) { c[s] = min(c[s], c[t[s]]); - t[s] = t[t[s]]; }); + t[s] = t[t[s]]; }, true); return &c; } @@ -69,8 +69,10 @@ void cycleStat(Trans &c) { Stat() : basin(0), len(0), minState(maxState) {} }; map<State, Stat> cyc; + // how big is the basin of attraction? iterState([&](int s) { cyc[c[s]].basin++; }); + // how long is the cycle, what is the actual minimal state for (auto i : cyc) { Stat &s = cyc[i.first]; @@ -82,13 +84,27 @@ void cycleStat(Trans &c) { cur=update(cur); } while (cur != start); } - // print it + + // find duplicates cycles (only bitshifted) + auto canonize = [](State s) { + State cs = s; + for (State i=0; i<logState; i++) + cs = min(cs, (((s<<i) | (s>>(logState-i))) & (maxState - 1))); + return cs; + }; + map<State, set<State>> ccyc; for (auto i : cyc) { - Stat &s = i.second; - cout << s.minState << "\t" - << bitset<logState>(s.minState) << "\t" + ccyc[canonize(i.second.minState)].insert(i.first); + } + + // print it + for (auto i : ccyc) { + Stat &s = cyc[*(i.second.begin())]; + cout << bitset<logState>(i.first) << "\t" + << i.second.size() << "\t" << s.len << "\t" - << s.basin << endl; + << s.basin << "\t" + << i.first << endl; } } |