Frist: Flop/Turn pruefen die Uhr jede Iteration, Rand 150 ms; lesen/solver_abnahme.py (D4-Abnahme Heuristik vs Solver)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -133,7 +133,7 @@ pub fn solve_flop(spot: &Spot, hero: &[(Vec<Card>, f64)], villain_list: &[(Vec<C
|
||||
while done < cfg.iterations {
|
||||
solver.iterate();
|
||||
done += 1;
|
||||
if done % 5 == 0 && started.elapsed().as_secs_f64() * 1e3 > cfg.budget_ms {
|
||||
if started.elapsed().as_secs_f64() * 1e3 > cfg.budget_ms {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+50
-50
@@ -1,50 +1,50 @@
|
||||
//! The decision deadline of the postflop solvers ("Solver ueberall"): `decide_with` marks the start of
|
||||
//! each decision on its thread, and a solver gets what is left of its street's total before it starts.
|
||||
//! Totals per decision (live table): river and flop 2 s, turn 1.25 s, each minus `MARGIN_MS` for the
|
||||
//! work after the solve. Without a mark (tests, tools calling a solver directly) the full total is left.
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::time::Instant;
|
||||
|
||||
thread_local! {
|
||||
static START: Cell<Option<Instant>> = const { Cell::new(None) };
|
||||
}
|
||||
|
||||
/// Total wall time of one decision per street, in ms.
|
||||
pub const RIVER_MS: f64 = 2000.0;
|
||||
pub const TURN_MS: f64 = 1250.0;
|
||||
pub const FLOP_MS: f64 = 2000.0;
|
||||
/// Kept free after the solve (strategy readout, sampling, the answer).
|
||||
pub const MARGIN_MS: f64 = 100.0;
|
||||
|
||||
/// Mark the start of a decision on this thread.
|
||||
pub fn begin() {
|
||||
START.with(|s| s.set(Some(Instant::now())));
|
||||
}
|
||||
|
||||
/// Milliseconds since the mark (0 without one).
|
||||
pub fn elapsed_ms() -> f64 {
|
||||
START.with(|s| s.get().map_or(0.0, |t| t.elapsed().as_secs_f64() * 1e3))
|
||||
}
|
||||
|
||||
/// What a solver may still spend of `total_ms` (may be ≤ 0: then it must not start).
|
||||
pub fn left_ms(total_ms: f64) -> f64 {
|
||||
total_ms - MARGIN_MS - elapsed_ms()
|
||||
}
|
||||
|
||||
/// Measurement switch `SOLVER_ZEIT=fest`: solvers ignore wall time and always run their full iteration
|
||||
/// count, so ladder and LBR results do not depend on machine load (read once).
|
||||
pub fn fixed() -> bool {
|
||||
static FIXED: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*FIXED.get_or_init(|| std::env::var("SOLVER_ZEIT").as_deref() == Ok("fest"))
|
||||
}
|
||||
|
||||
/// The budget a solve gets: `cap_ms` (its own limit), cut to what is left of the street's total;
|
||||
/// infinite under `SOLVER_ZEIT=fest`.
|
||||
pub fn budget_ms(cap_ms: f64, total_ms: f64) -> f64 {
|
||||
if fixed() {
|
||||
f64::INFINITY
|
||||
} else {
|
||||
cap_ms.min(left_ms(total_ms))
|
||||
}
|
||||
}
|
||||
//! The decision deadline of the postflop solvers ("Solver ueberall"): `decide_with` marks the start of
|
||||
//! each decision on its thread, and a solver gets what is left of its street's total before it starts.
|
||||
//! Totals per decision (live table): river and flop 2 s, turn 1.25 s, each minus `MARGIN_MS` for the
|
||||
//! work after the solve. Without a mark (tests, tools calling a solver directly) the full total is left.
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::time::Instant;
|
||||
|
||||
thread_local! {
|
||||
static START: Cell<Option<Instant>> = const { Cell::new(None) };
|
||||
}
|
||||
|
||||
/// Total wall time of one decision per street, in ms.
|
||||
pub const RIVER_MS: f64 = 2000.0;
|
||||
pub const TURN_MS: f64 = 1250.0;
|
||||
pub const FLOP_MS: f64 = 2000.0;
|
||||
/// Kept free after the solve (strategy readout, sampling, the answer).
|
||||
pub const MARGIN_MS: f64 = 150.0;
|
||||
|
||||
/// Mark the start of a decision on this thread.
|
||||
pub fn begin() {
|
||||
START.with(|s| s.set(Some(Instant::now())));
|
||||
}
|
||||
|
||||
/// Milliseconds since the mark (0 without one).
|
||||
pub fn elapsed_ms() -> f64 {
|
||||
START.with(|s| s.get().map_or(0.0, |t| t.elapsed().as_secs_f64() * 1e3))
|
||||
}
|
||||
|
||||
/// What a solver may still spend of `total_ms` (may be ≤ 0: then it must not start).
|
||||
pub fn left_ms(total_ms: f64) -> f64 {
|
||||
total_ms - MARGIN_MS - elapsed_ms()
|
||||
}
|
||||
|
||||
/// Measurement switch `SOLVER_ZEIT=fest`: solvers ignore wall time and always run their full iteration
|
||||
/// count, so ladder and LBR results do not depend on machine load (read once).
|
||||
pub fn fixed() -> bool {
|
||||
static FIXED: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*FIXED.get_or_init(|| std::env::var("SOLVER_ZEIT").as_deref() == Ok("fest"))
|
||||
}
|
||||
|
||||
/// The budget a solve gets: `cap_ms` (its own limit), cut to what is left of the street's total;
|
||||
/// infinite under `SOLVER_ZEIT=fest`.
|
||||
pub fn budget_ms(cap_ms: f64, total_ms: f64) -> f64 {
|
||||
if fixed() {
|
||||
f64::INFINITY
|
||||
} else {
|
||||
cap_ms.min(left_ms(total_ms))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ fn solve_core(spot: &Spot, hero: &[(Vec<Card>, f64)], villain_list: &[(Vec<Card>
|
||||
while done < cfg.iterations {
|
||||
solver.iterate();
|
||||
done += 1;
|
||||
if done % 5 == 0 && started.elapsed().as_secs_f64() * 1e3 > cfg.budget_ms {
|
||||
if started.elapsed().as_secs_f64() * 1e3 > cfg.budget_ms {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user