Skip to content

Commit

Permalink
working on #94
Browse files Browse the repository at this point in the history
  • Loading branch information
ihh committed Oct 30, 2018
1 parent 532bf22 commit 54fca8e
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,15 @@ Machine Machine::advanceSort (bool decode) const {
silentIncoming[trans.dest].insert (s);
}
}
auto compareStates = [&] (StateIndex a, StateIndex b) {
const int aIncoming = (int) silentIncoming[a].size(), aDiff = aIncoming - (int) silentOutgoing[a].size();
const int bIncoming = (int) silentIncoming[b].size(), bDiff = bIncoming - (int) silentOutgoing[b].size();
return (aIncoming == bIncoming
? (aDiff == bDiff
? (a < b)
: (aDiff < bDiff))
: (aIncoming < bIncoming));
};
vguard<StateIndex> order;
vguard<bool> inOrder (nStates(), false);
auto addToOrder = [&] (StateIndex s) {
Expand All @@ -1133,20 +1142,12 @@ Machine Machine::advanceSort (bool decode) const {
deque<StateIndex> queue;
for (StateIndex s = 1; s + 1 < nStates(); ++s)
queue.push_back (s);
sort (queue.begin() + 1, queue.end(), compareStates);
ProgressLog(plogSort,6);
plogSort.initProgress ("Advance-sorting %lu states", nStates() - 1);
while (queue.size()) {
plogSort.logProgress ((nStates() - queue.size()) / (double) nStates(), "sorted %lu states", nStates() - queue.size());
partial_sort (queue.begin(), queue.begin() + 1, queue.end(),
[&] (StateIndex a, StateIndex b) {
const int aIncoming = (int) silentIncoming[a].size(), aDiff = aIncoming - (int) silentOutgoing[a].size();
const int bIncoming = (int) silentIncoming[b].size(), bDiff = bIncoming - (int) silentOutgoing[b].size();
return (aIncoming == bIncoming
? (aDiff == bDiff
? (a < b)
: (aDiff < bDiff))
: (aIncoming < bIncoming));
});
partial_sort (queue.begin(), queue.begin() + 1, queue.end(), compareStates);
addToOrder (queue.front());
queue.erase (queue.begin());
}
Expand Down

0 comments on commit 54fca8e

Please sign in to comment.