Repository navigation
feat(solver): read the solve's time limit from SolverScope - #280
Conversation
|
Thanks @slapers, you were right that a custom phase needs this. It can stop on the limit through I pushed a change on top of your commit. The getter is now
It returns |
Clone requires Sized, so the ?Sized bound on the guard's Clone impl was ignored and clippy's needless_maybe_sized lint rejects it under -D warnings, which failed CI's all-targets clippy on main. Every carrier the guard checks is Sized, so both impls drop the bound; the guard still fails to compile when a carrier gains Clone.
make clippy linted only library code without features, so a lint in test code passed locally and failed CI's cargo clippy --workspace --all-targets --all-features. make build and make test also left out --all-features. The three targets now run the same commands as the CI Rust job, so make lint and make test catch what CI catches.
SolverScope::set_time_limit is public but time_limit is crate-private, so a custom phase can set the limit but not read it. The built-in construction takes a share of the limit; a custom phase that needs the same (a time-based annealing temperature, a phase that runs for the first part of the solve) has to carry the limit beside the solver config. Make time_limit public.
A custom phase that plans its own schedule needs to know how much time is left before a time limit ends it. The raw time_limit() field answers that only for a top-level solve. A custom phase running as a partition's child phase sees None, because its scope carries the enclosing solve's deadline and any partition bound instead of a limit, so a schedule built on it silently loses its time bound there. Using the raw limit also invites a phase to shorten the solve's limit and restore it, which cannot put back "no limit" when there was none. SolverScope::remaining_time() returns the solve's time limit minus solver-active time, or the earliest inherited deadline (enclosing solve or partition bound chain), whichever ends first. It returns None when no time limit applies and zero once one is reached. time_limit() goes back to crate-private; built-in construction still reads it for its share of the solve. Tests cover the top-level limit, the inherited deadline in a child scope and the nested partition bound, and the facade test calls the method from outside the crate.
…line The optional assignment pass takes a fifth of the solve's time limit. It read the raw time limit, which a partition's child scope does not carry: the partition inherits the solve's deadline instead. Default phases run inside partitions, so there the optional pass had no time cap and could spend the whole partition deadline before local search started. The share is now a fifth of the scope's span, its solver-active time plus remaining_time(), which equals the time limit for a top-level solve and the inherited deadline for a partition. The crate-private time_limit() accessor has no reader left and is removed.
The custom-phase guide now names SolverScope::remaining_time as the way a phase reads its time, including the deadline it inherits as a partition's child phase, and says a phase that takes a share of the time returns when the share is spent instead of changing the solve's limit.
81c4202 to
6421406
Compare
|
One more thing your change turned up: the built-in construction had the same blind spot. Its optional pass takes a fifth of the solve's time limit, and inside a partition it saw no limit, so it ran uncapped. It now takes its share from |
Change and Purpose
SolverScope::set_time_limitis public, butSolverScope::time_limitispub(crate): a custom phase can set the solve's time limit but not read it.The built-in construction already reads it to take a share of the solve's time (
optional_construction_termination). Custom phases need the same: a simulated annealing whose temperature falls with the time gradient, or a phase that runs only for the first part of the solve and then hands over (it sets a shorter limit withset_time_limitand must restore the original one). Today such a phase has to carry the time limit a second time, beside the solver config, and the two can drift apart.This makes
time_limit()public, next toset_time_limit(). No behavior changes.scope/solver/scope_termination.rs:time_limitispub.scope/tests.rs:time_limit_reads_back_what_was_set(unset isNone; a set limit reads back).solverforge-solver/WIREFRAME.md:time_limit()in theSolverScopekey methods.solverforge-solver/public-api.txt: blessed withscripts/check-public-api.py --bless.Verification
make fmt-check clippy doc-names file-length facade-reachability public-api: all pass.cargo test --workspace: 1644 passed, 0 failed.make depsnot run:cargo-macheteis not installed here. The change adds no dependency.Review Checklist