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
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::process;
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<(), String> {
let problem = deserialize_problem(problem_reader).unwrap_or_else(|errs| {
eprintln!("cannot read problem: '{}'", FormatError::format_many(&errs, ","));
process::exit(1);
});
let solution = deserialize_solution(solution_reader).unwrap_or_else(|err| {
eprintln!("cannot read solution: '{}'", err);
process::exit(1);
});
let matrices = matrices_readers.map(|matrices| {
matrices
.into_iter()
.map(|file| {
deserialize_matrix(BufReader::new(file)).unwrap_or_else(|errs| {
eprintln!("cannot read matrix: '{}'", FormatError::format_many(&errs, ","));
process::exit(1);
})
})
.collect::<Vec<_>>()
});
let core_problem = Arc::new((problem.clone(), matrices.clone()).read_pragmatic().unwrap_or_else(|err| {
eprintln!("cannot read pragmatic problem: {}", FormatError::format_many(&err, ","));
process::exit(1);
}));
CheckerContext::new(core_problem, problem, matrices, solution).check()
}