ConcurrentSolverRunner

class ConcurrentSolverRunner(problemDefinition: ProblemDefinition, tasks: List<SolverMemberTask>, evaluatorFactory: MemberEvaluatorFactoryIfc, numWorkers: Int? = null)(source)

The engine for concurrent solver execution: runs the member solvers of a concurrent run (parallel random restarts, a solver portfolio) on a bounded dispatcher, each with its own factory-provisioned evaluation resources, and hands their results back in deterministic member order.

Execution model:

  • launchAll starts every member as a coroutine on a dispatcher bounded by the worker count; excess members queue and run as workers free up. Non-blocking.

  • awaitMember blocks until the given member completes and returns its result. Owners that report per-member progress await members in submission order, which makes tracker output and best-solution evolution deterministic regardless of which member happens to finish first.

  • requestStop forwards a graceful stop to every in-flight member solver (each checks its stop flag between its own iterations) and prevents queued members from starting. Safe to call from any thread; idempotent.

Determinism contract: every member's inputs (starting point, stream block, solver streams) are fixed at launch time and independent of scheduling, and results are consumed in member order — so for a fixed seed setup the run's results do not depend on the worker count or thread timing.

Failure discipline mirrors the parallel evaluation provider: a member that throws yields a failed SolverMemberResult carrying the problem's bad solution; sibling members are unaffected. Cooperative cancellation exceptions propagate.

Thread-safety expectations on shared problem objects: members share the (read-only) problem definition. Its configuration must not be mutated while a run is in flight, and any custom penalty functions attached to the problem's constraints must be stateless (pure functions of their arguments, like the library-provided ones) — members evaluate penalized objective values concurrently, so a penalty function that keeps internal mutable state would race.

Parameters

problemDefinition

the problem all members solve; supplies the bad solution for failed or never-started members

tasks

the members to run, in order; labels must be unique

evaluatorFactory

provisions each member's private evaluation resources

numWorkers

the maximum number of members running at the same time; null uses the smaller of the member count and the available processors

Constructors

Link copied to clipboard
constructor(problemDefinition: ProblemDefinition, tasks: List<SolverMemberTask>, evaluatorFactory: MemberEvaluatorFactoryIfc, numWorkers: Int? = null)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

True once launchAll() has been called.

Link copied to clipboard

True once a stop has been requested via requestStop().

Link copied to clipboard

The number of members in the run.

Link copied to clipboard

The number of members that may run at the same time.

Functions

Link copied to clipboard

Blocks until every member completes and returns all results in member order.

Link copied to clipboard

Blocks until the member with the given index completes and returns its result. The await establishes the happens-before ordering that makes the member's solver state safe to read from the calling thread.

Link copied to clipboard
fun launchAll()

Launches every member as a coroutine on the bounded dispatcher and returns immediately. May only be called once.

Link copied to clipboard
fun requestStop(msg: String? = null)

Requests a graceful stop of the whole run: members that have not started will not start, and every in-flight member solver is signaled via its stopIterations mechanism, so it exits after its current iteration. Idempotent; safe from any thread.

Link copied to clipboard
fun shutdown()

Cancels the runner's coroutine scope. Call after all members have been awaited (or after a stop) to release the scope; awaiting after shutdown is an error.