31 #include "../util/MyList.hpp" 36 class DepthFirstSearcher {
38 static int const AR = Spec::ARITY;
43 MyList<char> statePool;
44 std::vector<std::pair<int,int> > valueList;
47 DepthFirstSearcher(Spec
const& spec) :
48 spec(spec), datasize(spec.datasize()) {
58 std::vector<std::pair<int,int> > findOneInstance() {
60 void* p = statePool.alloc_front(datasize);
61 int n = spec.get_root(p);
70 ok = findOneInstanceStep(p, n);
72 for (
int i = n; i >= 1; --i) {
73 spec.destructLevel(i);
78 statePool.pop_front();
79 if (!ok)
throw std::runtime_error(
"No instance");
84 bool findOneInstanceStep(
void* p,
int i) {
85 int b0 = std::rand() % AR;
86 void* pp = statePool.alloc_front(datasize);
89 for (
int bb = 0; bb < AR; ++bb) {
90 int b = (b0 + bb) % AR;
93 int ii = spec.get_child(pp, i, b);
99 ok = findOneInstanceStep(pp, ii);
104 valueList.push_back(std::make_pair(i, b));
109 statePool.pop_front();