1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#[cfg(test)]
#[path = "../../../tests/unit/extensions/check/check_test.rs"]
mod check_test;
use vrp_pragmatic::checker::CheckerContext;
use vrp_pragmatic::format::problem::{deserialize_matrix, deserialize_problem, PragmaticProblem};
use vrp_pragmatic::format::solution::deserialize_solution;
use std::io::{BufReader, Read};
use std::sync::Arc;
use vrp_pragmatic::format::FormatError;
pub fn check_pragmatic_solution<F: Read>(
problem_reader: BufReader<F>,
solution_reader: BufReader<F>,
matrices_readers: Option<Vec<BufReader<F>>>,
) -> Result<(), Vec<String>> {
let problem = deserialize_problem(problem_reader)
.map_err(|errs| vec![format!("cannot read problem: '{}'", FormatError::format_many(&errs, ","))])?;
let solution =
deserialize_solution(solution_reader).map_err(|err| vec![format!("cannot read solution: '{}'", err)])?;
let matrices = if let Some(matrices_readers) = matrices_readers {
Some(
matrices_readers
.into_iter()
.map(|file| {
deserialize_matrix(BufReader::new(file))
.map_err(|errs| vec![format!("cannot read matrix: '{}'", FormatError::format_many(&errs, ","))])
})
.collect::<Result<Vec<_>, _>>()?,
)
} else {
None
};
let core_problem = Arc::new(
(problem.clone(), matrices.clone())
.read_pragmatic()
.map_err(|err| vec![format!("cannot read pragmatic problem: {}", FormatError::format_many(&err, ","))])?,
);
CheckerContext::new(core_problem, problem, matrices, solution).and_then(|ctx| ctx.check())
}