Open jrray opened 2 years ago
I agree about the naming and general clarification of responsibilities, and maybe I'll take another opportunity to talk about my current affection for the builder pattern... 😉
I can't help but see the current Solver -> SolverRuntime
as more of a SolverBuilder -> Solver
relationship. There's some inconsistency right now with which logic/methods are actually attached to which types, but this type of naming would, I think, clarify what belongs where and what each type actually does (setup/initial state vs actually walking through things). This also feels (to me) like it matches more the natural progression where different solver implementations in the future would have different *Builder
types. Each one creates a unique type that impls Solver
with at least a minimal interface for running it to completion, plus whatever we can standardize in the stepping/progression/reporting stuff (or we just let the builder take a type-specific with_formatter
and hide it behind the trait, maybe).
I don't want to do this now with all the PRs we have already, but I want to write down my thoughts.
Solver::run
does not run a solve. It returns aSolverRuntime
.SolverRuntime
does not run a solve, but it holds the state of a solve. Some of the state of the solve is also inSolver
.DecisionFormatter
runs a solve.This is inverted from what would be IMO more natural.
Have
Solver
take (require) aDecisionFormatter
.Make
Solver::run()
returnResult<Solution>
and execute the solve. (Maybe this should be namedSolver::runtime()
?)Something about the name
SolverRuntime
doesn't work for me. In my mind it would become the thing thatimpl Solve for ...
if/whenSolve
becomes a trait and we have multiple solver implementations. A name likeSolverImpl
orStepStateSolver
which is descriptive of the type of solver it is.There is also
Solver::solve() -> Result<Solution>
but nothing should be using this because it doesn't have the behaviors insideDecisionFormatter
that everyone expects. If we do the inversion thensolve()
could use the assigned formatter andrun()
could go away.I know the devil is in the details and making these changes might be harder than it seems...
DecisionFormatter
is closely coupled to the current solver implementation and not generic.