Skip to content

Commit 6ef1ca6

Browse files
committed
Chore
1 parent 2a7b6c3 commit 6ef1ca6

2 files changed

Lines changed: 30 additions & 28 deletions

File tree

crates/solver_vrp/src/lib.rs

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
//!
33
//! A vehicle routing solver library.
44
//!
5-
//! This library provides functionalities to solve various vehicle routing problems (VRP), including
5+
//! ! WARNING: Some APIs like the Plan API are still unimplemented and subject to change.
6+
//!
7+
//! This library provides functionalities to solve various vehicle routing problems (VRP), including:
68
//!
79
//! - Pickup and Delivery Problem (PDP)
810
//!
@@ -14,58 +16,58 @@
1416
//! use solver_vrp::random::Random;
1517
//!
1618
//! // Implement a custom objective to add optimized features like linehaul costs to the model.
19+
//! struct ZeroObjective {
20+
//! zero: f64,
21+
//! }
22+
//!
1723
//! impl Objective for ZeroObjective {
1824
//! fn name(&self) -> String {
19-
//! String::from("Zero Objective")
25+
//! String::from("My Zero Objective")
2026
//! }
2127
//!
22-
//! // Returns the computed value of the objective for the given plan.
23-
//! fn compute(&self, _model: &Model, _solution: &Solution, _plan: &Plan) -> f64 {
24-
//! 0.0
25-
//! }
28+
//! // Computes the value of the objective for the given plan.
29+
//! fn compute(&self, _model: &Model, _solution: &Solution, _plan: &Plan) -> f64 {
30+
//! self.zero
31+
//! }
2632
//! }
2733
//!
2834
//! // Implement a custom constraint to enforce unique business rules in the model.
29-
//! struct MaxVehicleWeight((f64, f64));
35+
//! struct MyVehicleCapacities(vec![f64; 2]);
3036
//!
31-
//! impl Constraint for MaxVehicleWeight {
37+
//! impl Constraint for MyVehicleCapacities {
3238
//! fn name(&self) -> String {
33-
//! String::from("Max Vehicle Weight")
39+
//! String::from("My Vehicle Capacities")
3440
//! }
3541
//!
3642
//! // Returns true if the plan is feasible.
3743
//! fn is_feasible(&self, plan: &Plan) -> bool {
38-
//! plan.route()
39-
//! .changes()
40-
//! .last()
41-
//! .map_or(true, |change| {
42-
//! change.capacity.utilization(1) <= self.0.1
43-
//! });
44+
//! let i = 1;
45+
//! self.0.get(i)
46+
//! .zip(plan.route().changes().last())
47+
//! .and_then(|(max, change)| change.required_capacity().get(i).map(|d| d <= max))
48+
//! .unwrap_or(true)
4449
//! }
4550
//! }
4651
//!
4752
//! // Add new operators to refine the solver's search and heuristic capabilities.
48-
//! #![derive(Default)]
49-
//! struct RejectEverything {
50-
//! parameters: OperatorParameters,
51-
//! };
53+
//! struct SimpleOperator {};
5254
//!
53-
//! impl Operator for CustomOperator {
55+
//! impl Operator for SimpleOperator {
5456
//! fn name(&self) -> String {
55-
//! String::from("Custom Operator")
57+
//! String::from("Simple Operator")
5658
//! }
5759
//!
58-
//! // Returns the new solution after executing the operator.
60+
//! // Returns the new plan after executing the operator.
5961
//! fn execute(&self, _model: &Model, _solution: &Solution, _random: &mut Random) -> Plan {
60-
//! Plan::default()
62+
//! return Plan::new();
6163
//! }
6264
//! }
6365
//!
6466
//! fn run() {
6567
//! // Build the model with custom components.
6668
//! let model = ModelBuilder::new()
67-
//! .objective(CustomObjective::default())
68-
//! .constraint(CustomConstraint((26.0, 40_000.0)))
69+
//! .objective(ZeroObjective { zero: 0.0 })
70+
//! .constraint(MyVehicleCapacities(vec![26.0, 40_000.0]))
6971
//! .build();
7072
//!
7173
//! // Define options for the solver.
@@ -77,8 +79,8 @@
7779
//! let solver = SolverBuilder::new()
7880
//! .options(options)
7981
//! .model(model)
80-
//! .plan(initial_solution)
81-
//! .operator(CustomOperator {})
82+
//! .solution(initial_solution)
83+
//! .operator(SimpleOperator {})
8284
//! .build();
8385
//!
8486
//! let best_solution = solver.solve();

crates/solver_vrp/src/solver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl SolverBuilder {
9191
}
9292

9393
#[must_use]
94-
pub fn plan(mut self, solution: Solution) -> Self {
94+
pub fn solution(mut self, solution: Solution) -> Self {
9595
self.solver.solution = Some(solution);
9696
self
9797
}

0 commit comments

Comments
 (0)