custom_constraint/common/
routing.rs

1//! This code is used by multiple examples.
2
3use vrp_core::prelude::*;
4
5/// Gets a routing matrix for 5 unique locations.
6pub fn define_routing_data() -> GenericResult<impl TransportCost> {
7    // define distance/duration matrix (use the same data for both)
8    // as we have five locations, we need to define 5x5 matrix, flatten to 1 dimension:
9    #[rustfmt::skip]
10    let routing_data = vec![
11    //  0     1     2     3     4
12        0.,  500., 520., 530., 540.,  // 0
13        500.,  0.,  30.,  40.,  50.,  // 1
14        520., 30.,   0.,  20.,  25.,  // 2
15        530., 40.,  20.,   0.,  15.,  // 3
16        540., 50.,  25.,  15.,   0.   // 4
17    ];
18    let (durations, distances) = (routing_data.clone(), routing_data);
19
20    // `SimpleTransportCost` provides a simple way to use single routing matrix for any vehicle in the problem
21    SimpleTransportCost::new(durations, distances)
22}