0a1,8 > // rwang1880.cpp -- job #1880 (route 73): randomised-restart fork of Jinyuan Wang's public A144311 branch-and-bound > // (oeis.org/A144311/a144311.cpp.txt; base copy wang_base.cpp = return #1166's wang.cpp). Changes, all marked JOB1880: > // (1) the residue loop of each prime visits the residues 1..p-1 in a seeded random permutation instead of increasing order; > // (2) a node budget per restart aborts the DFS, and main() restarts it from the global best record with a new permutation > // until the wall-clock cap; (3) records print with elapsed time; nothing else (dfs body, pruning bound, plist, pskip, > // CRT convention) is touched. usage: rwang1880 n seconds seed nodecap [start_m] > #include > #include 11a20,24 > // JOB1880 globals > static unsigned long long RS = 88172645463325252ULL; static unsigned long long rnd(){ RS ^= RS << 13; RS ^= RS >> 7; RS ^= RS << 17; return RS; } > static long long NODES = 0, NODECAP = 0, TOTALNODES = 0; static int RESTARTS = 0, ABORT = 0; static clock_t T0; static double SECONDS = 0; > static int BESTM = 0; static int BESTREM[MAXN]; > static double elapsed(){ return (double)(clock() - T0) / CLOCKS_PER_SEC; } 17c30,33 < for (int i = 1; i < p; ++i) --- > // JOB1880: node budget and random residue order > if (ABORT) return; ++NODES; ++TOTALNODES; if (NODES > NODECAP || elapsed() > SECONDS) { ABORT = 1; return; } > int perm[128]; for (int q = 1; q < p; ++q) perm[q-1] = q; for (int q = p - 2; q > 0; --q) { int z = rnd() % (q + 1); int tmp = perm[q]; perm[q] = perm[z]; perm[z] = tmp; } > for (int ii = 0; ii < p - 1 && !ABORT; ++ii) { int i = perm[ii]; 69a86 > } 93c110,111 < cout << "New record: " << 6 * maxm + 5 << endl; --- > cout << "New record: " << 6 * maxm + 5 << " t " << elapsed() << " restart " << RESTARTS << endl; > if (maxm > BESTM) { BESTM = maxm; for (int i = 0; i < k; ++i) BESTREM[i] = remainders[i]; } 117c135 < cout << "A144311(" << n << ") = " << 6 * maxm + 5 << "\n\n"; --- > cerr << "A144311(" << n << ") pass ended, best " << 6 * BESTM + 5 << (ABORT ? " (budget)" : " (exhausted)") << endl; 121,122c139,151 < int n = argc > 1 ? atoi(argv[1]) : 10; < A144311(n); --- > // JOB1880 driver: n seconds seed nodecap [start_m] > int n = atoi(argv[1]); SECONDS = atof(argv[2]); unsigned long long seed = strtoull(argv[3], 0, 10); NODECAP = atoll(argv[4]); > int start_m = argc > 5 ? atoi(argv[5]) : 1; > RS ^= seed * 0x9E3779B97F4A7C15ULL; for (int i = 0; i < 20; ++i) rnd(); > T0 = clock(); BESTM = start_m - 1; > while (elapsed() < SECONDS) { > ++RESTARTS; NODES = 0; ABORT = 0; > A144311(n, BESTM + 1 > 1 ? BESTM + 1 : 1); > cerr << "restart " << RESTARTS << " nodes " << NODES << " best " << 6 * BESTM + 5 << " t " << elapsed() << endl; > } > cout << "BEST length " << 6 * BESTM + 5 << " remainders"; > for (int i = 0; i < n - 2; ++i) cout << " " << BESTREM[i] << "/" << plist[i]; > cout << " restarts " << RESTARTS << " nodes " << TOTALNODES << " t " << elapsed() << endl;