| 75 | |
| 76 | template<class Tracer> |
| 77 | forceinline Space* |
| 78 | DFS<Tracer>::next(void) { |
| 79 | /* |
| 80 | * The engine maintains the following invariant: |
| 81 | * - If the current space (cur) is not nullptr, the path always points |
| 82 | * to exactly that space. |
| 83 | * - If the current space (cur) is nullptr, the path always points |
| 84 | * to the next space (if there is any). |
| 85 | * |
| 86 | * This invariant is needed so that no-goods can be extracted properly |
| 87 | * when the engine is stopped or has found a solution. |
| 88 | * |
| 89 | */ |
| 90 | start(); |
| 91 | while (true) { |
| 92 | if (stop(opt)) |
| 93 | return nullptr; |
| 94 | while (cur == nullptr) { |
| 95 | if (path.empty()) |
| 96 | return nullptr; |
| 97 | cur = path.recompute(d,opt.a_d,*this,tracer); |
| 98 | if (cur != nullptr) |
| 99 | break; |
| 100 | path.next(); |
| 101 | } |
| 102 | node++; |
| 103 | SearchTracer::EdgeInfo ei; |
| 104 | if (tracer && (path.entries() > 0)) { |
| 105 | typename Path<Tracer>::Edge& top = path.top(); |
| 106 | ei.init(tracer.wid(), top.nid(), top.truealt(), *cur, *top.choice()); |
| 107 | } |
| 108 | unsigned int nid = tracer.nid(); |
| 109 | switch (cur->status(*this)) { |
| 110 | case SS_FAILED: |
| 111 | if (tracer) { |
| 112 | SearchTracer::NodeInfo ni(SearchTracer::NodeType::FAILED, |
| 113 | tracer.wid(), nid, *cur); |
| 114 | tracer.node(ei,ni); |
| 115 | } |
| 116 | fail++; |
| 117 | delete cur; |
| 118 | cur = nullptr; |
| 119 | path.next(); |
| 120 | break; |
| 121 | case SS_SOLVED: |
| 122 | { |
| 123 | if (tracer) { |
| 124 | SearchTracer::NodeInfo ni(SearchTracer::NodeType::SOLVED, |
| 125 | tracer.wid(), nid, *cur); |
| 126 | tracer.node(ei,ni); |
| 127 | } |
| 128 | // Deletes all pending branchers |
| 129 | (void) cur->choice(); |
| 130 | Space* s = cur; |
| 131 | cur = nullptr; |
| 132 | path.next(); |
| 133 | return s; |
| 134 | } |