#pragma once #include "common.h" #include "expr.h" #include namespace nnet { class PermutationGenerator { vector> from, to; vector> mapping; public: PermutationGenerator(vector> _from, vector> _to); bool next(); PtrMap get() const; }; template class SubsetGenerator { vector elements; int n, bitmap; public: SubsetGenerator(vector elements, bool nonEmpty = 1) : elements(elements), n(elements.size()), bitmap((nonEmpty > 0)) { assert(n < 10); }; bool next() { return ((++bitmap) < (1 << n) - 1); } vector get() const { vector ret; for (int i = 0; i < n; ++i) if (bitmap & (1 << i)) ret.emplace_back(elements[i]); return ret; } }; } // namespace nnet