diff --git a/README.md b/README.md index 8f61cef..0d49a24 100644 --- a/README.md +++ b/README.md @@ -98,19 +98,24 @@ w(block) = 3 (biz + flb + rnz) + 2 × span(cell 地址) + Σ op # flb=1, set_1 桶队列(Dial),按代价递增弹出,第一次弹出目标态就是最短纸带。给一个 `max_cost` 上界就变成 分支限界,超出上界的状态不入队。 -穷尽得到的数据(6 个 cell 紧邻,full_add): +full_add、6 个 cell 紧邻时,搜索推进到某个代价时已经攒下的状态数: -| max_cost | 状态数 | 用时 | -|---|---|---| -| 20 | 1,086 | 0.0 s | -| 40 | 128,528 | 0.1 s | -| 50 | 999,448 | 0.7 s | -| 60 | 7,671,626 | 12.8 s | -| 65 | 20,153,459 | 47.6 s | +| 代价 | 状态数 | +|---|---| +| 20 | 1,086 | +| 40 | 128,528 | +| 50 | 999,448 | +| 58 | 80,000,000 | +| 62 | 140,000,000 | +| 66 | 220,000,000 | +| 70 | 280,000,000 | -每加 5 点代价状态数约 ×2.6,每状态约 32 字节(8 字节 key + 2 距离 + 4 父 + 2 指令 + 哈希表)。 -按这个斜率,`max_cost = 80` 约 3.5 亿状态 / 11 GB,`82` 约 6 亿 / 19 GB —— 后者超出机器 -内存,所以默认跑 80。 +每状态约 27 字节(8 key + 2 距离 + 4 父 + 2 指令 + 哈希表),到代价 70 约 7.5 GB,速度约 +65 万状态/秒。所以这台机器上能跑到的上限大约就是「代价 75 左右 / 4.5 亿状态 / 12 GB」, +再往上就超出内存了 —— 这正是当初估的 13 GB 量级。 + +因为 Dijkstra 按代价递增弹出,**停在哪儿就证明了「比它更短的纸带不存在」**:跑到代价 d 就 +停,等于给出「没有短于 d 字符的程序」这个下界。 注意:模型里的 `w` 不含「上一块的牺牲位跳到这一块」的那几步(`|s_i − s_{i−1}|`),因为那让 代价依赖历史、Dijkstra 就不能用了。发射器会把这部分加上再报真实长度,5 层程序是模型 82 / diff --git a/include/r8forge/r8veritas.hh b/include/r8forge/r8veritas.hh index b7ed0a6..c7ad12b 100644 --- a/include/r8forge/r8veritas.hh +++ b/include/r8forge/r8veritas.hh @@ -544,18 +544,13 @@ private: int d = 0; size_t pops_last = 0; const int limit = opt.max_cost; - while (true) { + while (d <= limit) { auto &bucket = ring[size_t(d) % ring.size()]; if (bucket.empty()) { - // Dijkstra pops in nondecreasing order, so when this bucket is dry the - // next state lives in the next nonempty one -- which can be further - // away than one edge weight. - int next = d + 1; - while (next <= limit && ring[size_t(next) % ring.size()].empty()) - next++; - if (next > limit) - break; // nothing left under the limit - d = next; + // plain Dial: step one unit at a time. Scanning ahead is not safe -- + // the ring reuses slots every ring.size() steps, so a far bucket can + // sit where a near one would be. + d++; continue; } const uint32_t id = bucket.back(); diff --git a/tests/cost_search.cc b/tests/cost_search.cc index 3d2bcfc..95ee572 100644 --- a/tests/cost_search.cc +++ b/tests/cost_search.cc @@ -13,7 +13,16 @@ int main(int argc, char **argv) { V v; v.initialize_nicknames(); v.initialize_tp_paths(); - auto raw = v.generate_truthtable([](V::cell inp) -> V::cell { + const int problem = argc > 4 ? std::atoi(argv[4]) : 0; + auto raw = v.generate_truthtable([problem](V::cell inp) -> V::cell { + if (problem == 1) { // copy: A -> bit0,bit1 + unsigned a = inp & 1; + return V::cell((a << 1) | a); + } + if (problem == 2) { // clb_and: A&B -> bit2 + unsigned a = inp & 1, b = (inp >> 1) & 1; + return V::cell(((a & b) << 2)); + } unsigned a = inp & 1, b = (inp >> 1) & 1, c = (inp >> 2) & 1; unsigned s = a ^ b ^ c; unsigned co = (a & b) | (a & c) | (b & c);