| 58 | |
| 59 | template<class Tracer> |
| 60 | forceinline Space* |
| 61 | BAB<Tracer>::next(void) { |
| 62 | /* |
| 63 | * The engine maintains the following invariant: |
| 64 | * - If the current space (cur) is not nullptr, the path always points |
| 65 | * to exactly that space. |
| 66 | * - If the current space (cur) is nullptr, the path always points |
| 67 | * to the next space (if there is any). |
| 68 | * |
| 69 | * This invariant is needed so that no-goods can be extracted properly |
| 70 | * when the engine is stopped or has found a solution. |
| 71 | * |
| 72 | * An additional invariant maintained by the engine is: |
| 73 | * For all nodes stored at a depth less than mark, there |
| 74 | * is no guarantee of betterness. For those above the mark, |
| 75 | * betterness is guaranteed. |
| 76 | * |
| 77 | */ |
| 78 | start(); |
| 79 | while (true) { |
| 80 | if (stop(opt)) |
| 81 | return nullptr; |
| 82 | // Recompute and add constraint if necessary |
| 83 | while (cur == nullptr) { |
| 84 | if (path.empty()) |
| 85 | return nullptr; |
| 86 | cur = path.recompute(d,opt.a_d,*this,*best,mark,tracer); |
| 87 | if (cur != nullptr) |
| 88 | break; |
| 89 | path.next(); |
| 90 | } |
| 91 | node++; |
| 92 | SearchTracer::EdgeInfo ei; |
| 93 | if (tracer && (path.entries() > 0)) { |
| 94 | typename Path<Tracer>::Edge& top = path.top(); |
| 95 | ei.init(tracer.wid(), top.nid(), top.truealt(), *cur, *top.choice()); |
| 96 | } |
| 97 | unsigned int nid = tracer.nid(); |
| 98 | switch (cur->status(*this)) { |
| 99 | case SS_FAILED: |
| 100 | if (tracer) { |
| 101 | SearchTracer::NodeInfo ni(SearchTracer::NodeType::FAILED, |
| 102 | tracer.wid(), nid, *cur); |
| 103 | tracer.node(ei,ni); |
| 104 | } |
| 105 | fail++; |
| 106 | delete cur; |
| 107 | cur = nullptr; |
| 108 | path.next(); |
| 109 | break; |
| 110 | case SS_SOLVED: |
| 111 | { |
| 112 | if (tracer) { |
| 113 | SearchTracer::NodeInfo ni(SearchTracer::NodeType::SOLVED, |
| 114 | tracer.wid(), nid, *cur); |
| 115 | tracer.node(ei,ni); |
| 116 | } |
| 117 | // Deletes all pending branchers |