Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ environment_mode = "reproducible"
random_seed = 42

[termination]
seconds_spent_limit = 5
step_count_limit = 50

[[phases]]
type = "construction_heuristic"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ use std::sync::Arc;

use solverforge::cvrp::ProblemData;
use solverforge::prelude::*;
use solverforge::SolverConfig;
use solverforge::stream::ConstraintFactory;

use super::Route;

#[planning_solution(
constraints = "constraints",
solver_toml = "../../fixtures/list_cvrp_k_opt_time_window_solver.toml"
)]
#[planning_solution(constraints = "constraints", config = "solver_config")]
pub struct Plan {
#[planning_list_element_collection(owner = "routes")]
pub customer_values: Vec<usize>,
Expand All @@ -21,6 +19,17 @@ pub struct Plan {
pub score: Option<HardSoftScore>,

pub shared: Arc<ProblemData>,

/// The solver TOML a retained solve of this plan runs with.
pub solver_toml: &'static str,
}

/// The k-opt construction fixture: list k-opt only, no local search.
pub const K_OPT_SOLVER_TOML: &str =
include_str!("../../fixtures/list_cvrp_k_opt_time_window_solver.toml");

fn solver_config(solution: &Plan, _base: SolverConfig) -> SolverConfig {
SolverConfig::from_toml_str(solution.solver_toml).expect("the fixture config parses")
}

impl solverforge::cvrp::VrpSolution for Plan {
Expand Down Expand Up @@ -99,5 +108,6 @@ pub fn build_plan() -> Plan {
}],
score: None,
shared,
solver_toml: K_OPT_SOLVER_TOML,
}
}
12 changes: 9 additions & 3 deletions crates/solverforge/tests/list_cvrp_union_lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ lower every compiled node exactly once. */
fn compiled_cvrp_union_selector_lowers_every_node_once() {
static MANAGER: SolverManager<Plan> = SolverManager::new();

let (job_id, mut receiver) = MANAGER.solve(build_plan()).expect("solve should start");
let mut plan = build_plan();
plan.solver_toml = include_str!("fixtures/list_cvrp_union_lowering_solver.toml");
let (job_id, mut receiver) = MANAGER.solve(plan).expect("solve should start");

let completed = loop {
let (metadata, completed) = loop {
match receiver
.blocking_recv()
.expect("event stream should reach a terminal event")
{
SolverEvent::Completed { solution, .. } => break solution,
SolverEvent::Completed { metadata, solution } => break (metadata, solution),
SolverEvent::Failed { error, .. } => panic!("solve unexpectedly failed: {error}"),
SolverEvent::Cancelled { metadata } => {
panic!(
Expand All @@ -47,4 +49,8 @@ fn compiled_cvrp_union_selector_lowers_every_node_once() {
.map(|route| route.visits.len())
.sum();
assert!(assigned > 0, "construction should assign customers");
assert!(
metadata.telemetry.moves_evaluated > 0,
"local search should evaluate moves from the union"
);
}
Loading