Solver

Configure and run the constraint solver

This section covers solver configuration and execution.

In This Section

  • Configuration - Configure solver behavior with SolverConfig and TerminationConfig
  • Factory - Create and run solvers with SolverFactory and Solver
  • Scores - Understand SimpleScore, HardSoftScore, HardMediumSoftScore, and BendableScore

Overview

Running a solver involves:

  1. Configure - Set termination conditions, environment mode, and threading
  2. Build Request - Combine domain, constraints, WASM, and problem data
  3. Execute - Send to solver service and receive solution
  4. Interpret - Parse score and solution
use solverforge_core::{SolveRequest, SolveResponse, TerminationConfig};

// Build request with termination
let request = SolveRequest::new(
    domain, constraints, wasm_base64,
    "alloc", "dealloc", list_accessor, problem_json
)
.with_termination(TerminationConfig::new()
    .with_spent_limit("PT5M")
    .with_best_score_feasible(true)
);

// Send to solver
let response: SolveResponse = client
    .post(&format!("{}/solve", service.url()))
    .json(&request)
    .send()?
    .json()?;

// Check result
println!("Score: {}", response.score);
if response.score.starts_with("0hard") {
    println!("Solution is feasible!");
}

Termination Conditions

The solver continues until a termination condition is met:

ConditionDescription
spent_limitMaximum solving time (e.g., "PT5M")
best_score_feasibleStop when feasible
best_score_limitStop at target score
move_count_limitMaximum moves
step_count_limitMaximum steps

Multiple conditions can be combined - the solver stops when any is satisfied.


Solver Configuration

Configure solver behavior with SolverConfig and TerminationConfig

Solver Factory

Create and run solvers with SolverFactory and Solver

Score Types

Understand SimpleScore, HardSoftScore, HardMediumSoftScore, and BendableScore