From d45cd9d3cf7aa35ef4e5076aec1e545e63fc9167 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 21 Oct 2026 15:35:07 +0200 Subject: [PATCH] spec: STRATA_SPEC_COST_TABLE seeds the row costs (a per-card table), the CLI prints the learned table at the end --- include/strata/spec/draft_policy.hpp | 6 ++++++ src/program/generate.cpp | 11 +++++++++++ src/spec/draft_policy.cpp | 20 ++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/include/strata/spec/draft_policy.hpp b/include/strata/spec/draft_policy.hpp index ed83abf0..2408de59 100644 --- a/include/strata/spec/draft_policy.hpp +++ b/include/strata/spec/draft_policy.hpp @@ -16,6 +16,7 @@ #pragma once #include +#include namespace strata::spec { @@ -45,6 +46,11 @@ public: double chain_rate(int match) const; double lookup_rate(int match) const; // current q for a match length double cost_ms(int t) const; // measured or scaled round time of a window of t tokens + /// A per-card row-cost table (round ms of the windows of 1..n rows, the draft included) counted as `weight` earlier rounds each: + /// the start of a process that already knows the card (STRATA_SPEC_COST_TABLE; tuning time), replaced by what it then measures. + void seed_costs(const double* ms, int n, double weight); + /// The measured round cost of every window size seen: "T1:39.8(n=120) T2:..." for the log / the next process's table. + std::string cost_table_text() const; /// COST-AWARE MTP WINDOW (STRATA_SPEC_COST=1): the MTP chain is drafted one step at a time; after draft j (probability p_j) /// E_j = 1 + q_0 + .. + q_j, q_i = prod_{k<=i} a(p_k) a() = the acceptance measured for MTP drafts of that probability diff --git a/src/program/generate.cpp b/src/program/generate.cpp index 653b9aad..3f2cda8f 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -16247,6 +16247,16 @@ int main(int argc, char** argv) { strata::spec::DraftPolicy policy(o.spec); // MTP or lookup window (see draft_policy.hpp) strata::spec::DraftPolicy::ChainState chain_st; int chain_rows = 1; // STRATA_SPEC_COST: the window the cost-aware rule kept in the MTP chain just drafted + if (const char* tab = std::getenv("STRATA_SPEC_COST_TABLE"); spec_cost && tab != nullptr && tab[0] != '\0') { + double ms[strata::spec::DraftPolicy::kMaxT] = {}; + int n = 0; + for (const char* q = tab; *q != '\0' && n < strata::spec::DraftPolicy::kMaxT;) { + ms[n++] = std::atof(q); + while (*q != '\0' && *q != ',') ++q; + if (*q == ',') ++q; + } + policy.seed_costs(ms, n, 6.0); + } if (spec_cost && use_mtp) mtp.set_chain_rule([&](int idx, float pj) { const bool k = policy.keep_draft(chain_st, idx, pj, S_mtp); @@ -16489,6 +16499,7 @@ int main(int argc, char** argv) { if (o.lookup_chain > 0) std::printf("%-24s %lld windows, chained drafts accepted %lld of %lld\n", "lookup chain", (long long) chain_windows, (long long) chain_ok, (long long) chain_drafts); + if (spec_cost) std::printf("%-24s %s\n", "spec cost table", policy.cost_table_text().c_str()); if (!t_cycle.empty()) { std::printf("%-24s", "window cost (ms/round)"); for (size_t i = 1; i < t_cycle_ms.size(); ++i) diff --git a/src/spec/draft_policy.cpp b/src/spec/draft_policy.cpp index 124e3fca..16d997b1 100644 --- a/src/spec/draft_policy.cpp +++ b/src/spec/draft_policy.cpp @@ -2,6 +2,7 @@ #include "strata/spec/draft_policy.hpp" #include +#include namespace strata::spec { namespace { @@ -51,6 +52,25 @@ double DraftPolicy::cost_ms(int t) const { return den > 0 ? num / den : kShape[t]; } +void DraftPolicy::seed_costs(const double* ms, int n, double weight) { + for (int t = 1; t <= std::min(n, kMaxT); ++t) + if (ms[t - 1] > 0.0 && cost_n_[t] == 0) { + cost_[t] = ms[t - 1]; + cost_n_[t] = weight; + } +} + +std::string DraftPolicy::cost_table_text() const { + std::string out; + char b[64]; + for (int t = 1; t <= kMaxT; ++t) + if (cost_n_[t] > 0) { + std::snprintf(b, sizeof b, "%sT%d:%.2f(n=%.0f)", out.empty() ? "" : " ", t, cost_[t], cost_n_[t]); + out += b; + } + return out; +} + bool DraftPolicy::stale(int t) const { return cost_n_[t] > 0 && rounds_ - last_[t] > kStaleRounds; } double DraftPolicy::mtp_tokens(int t) const {