pub fn init_cw(&mut self) {
        let depot = self.reg.depot().expect("There must be at least one depot.");
        let len = self.reg.len();
        let mut routes = Vec::with_capacity(len - 1);

        let mut bh = BinaryHeap::with_capacity(len * len);
        let cache = self.reg.cache();

        for node1 in self.reg.node_iter() {
            if node1.kind() != NodeKind::Depot {
                let mut r = Route::new(depot, self.vehicle_capacity, self.reg.cache());
                r.push_back(&node1);
                routes.push(r);
            }

            let d_depot1 = cache.distance(node1, depot);
            for node2 in self.reg.node_iter() {
                if node2.kind() != NodeKind::Depot && node1 != node2 {
                    let d_depot2 = cache.distance(node2, depot);
                    let d_12 = cache.distance(node1, node2);
                    let saving = d_depot1 + d_depot2 - d_12;
                    bh.push(SavingPair::new(node1, node2, saving));
                }
            }
        }

        while let Some(pair) = bh.pop() {
            let (node1, node2, _) = pair.into_value();

            if node1.kind() != NodeKind::Depot && node2.kind() != NodeKind::Depot {
                unsafe {
                    let mut route1 = node1.inner.as_ref().unwrap().as_ref().route;
                    let mut route2 = node2.inner.as_ref().unwrap().as_ref().route;

                    if Route::check_capacity_(&route1, &route2) {
                        match (node1.pos(), node2.pos()) {
                            (NodePos::First, NodePos::First) => {
                                Route::rev_(&route2, true);
                                Route::append_front_(&mut route1, &mut route2);
                            }
                            (NodePos::First, NodePos::Last) => {
                                Route::append_front_(&mut route1, &mut route2)
                            }
                            (NodePos::Last, NodePos::First) => {
                                Route::append_back_(&mut route1, &mut route2)
                            }
                            (NodePos::Last, NodePos::Last) => {
                                Route::rev_(&route2, true);
                                Route::append_back_(&mut route1, &mut route2);
                            }
                            _ => {}
                        }
                    }
                }
            }
        }

        routes.retain(|r| !r.is_empty());
        routes.shrink_to_fit();
        self.routes = routes;
    }
/// Initialises the tour by using the Clarke-Wright savings algorithm.
Initialises the tour by using the Clarke-Wright savings algorithm.
Initialises the tour by using the Clarke - Wright savings algorithm .
pub fn init_cw(&mut self) {
        let depot = self.reg.depot().expect("There must be at least one depot.");
        let len = self.reg.len();
        let mut routes = Vec::with_capacity(len - 1);
        let mut bh = BinaryHeap::with_capacity(len * len);
        let cache = self.reg.cache();
        for node1 in self.reg.node_iter() {
            if node1.kind() != NodeKind::Depot {
                let mut r = Route::new(depot, self.vehicle_capacity, self.reg.cache());
                r.push_back(&node1);
                routes.push(r);
            }
            let d_depot1 = cache.distance(node1, depot);
            for node2 in self.reg.node_iter() {
                if node2.kind() != NodeKind::Depot && node1 != node2 {
                    let d_depot2 = cache.distance(node2, depot);
                    let d_12 = cache.distance(node1, node2);
                    let saving = d_depot1 + d_depot2 - d_12;
                    bh.push(SavingPair::new(node1, node2, saving));
                }
            }
        }
        while let Some(pair) = bh.pop() {
            let (node1, node2, _) = pair.into_value();
            if node1.kind() != NodeKind::Depot && node2.kind() != NodeKind::Depot {
                unsafe {
                    let mut route1 = node1.inner.as_ref().unwrap().as_ref().route;
                    let mut route2 = node2.inner.as_ref().unwrap().as_ref().route;
                    if Route::check_capacity_(&route1, &route2) {
                        match (node1.pos(), node2.pos()) {
                            (NodePos::First, NodePos::First) => {
                                Route::rev_(&route2, true);
                                Route::append_front_(&mut route1, &mut route2);
                            }
                            (NodePos::First, NodePos::Last) => {
                                Route::append_front_(&mut route1, &mut route2)
                            }
                            (NodePos::Last, NodePos::First) => {
                                Route::append_back_(&mut route1, &mut route2)
                            }
                            (NodePos::Last, NodePos::Last) => {
                                Route::rev_(&route2, true);
                                Route::append_back_(&mut route1, &mut route2);
                            }
                            _ => {}
                        }
                    }
                }
            }
        }
        routes.retain(|r| !r.is_empty());
        routes.shrink_to_fit();
        self.routes = routes;
    }
pub fn init_cw ( & mut self ) { let depot = self . reg . depot ( ) . expect ( " " ) ; let len = self . reg . len ( ) ; let mut routes = Vec :: with_capacity ( len - 1 ) ; let mut bh = BinaryHeap :: with_capacity ( len * len ) ; let cache = self . reg . cache ( ) ; for node1 in self . reg . node_iter ( ) { if node1 . kind ( ) != NodeKind :: Depot { let mut r = Route :: new ( depot , self . vehicle_capacity , self . reg . cache ( ) ) ; r . push_back ( & node1 ) ; routes . push ( r ) ; } let d_depot1 = cache . distance ( node1 , depot ) ; for node2 in self . reg . node_iter ( ) { if node2 . kind ( ) != NodeKind :: Depot && node1 != node2 { let d_depot2 = cache . distance ( node2 , depot ) ; let d_12 = cache . distance ( node1 , node2 ) ; let saving = d_depot1 + d_depot2 - d_12 ; bh . push ( SavingPair :: new ( node1 , node2 , saving ) ) ; } } } while let Some ( pair ) = bh . pop ( ) { let ( node1 , node2 , _ ) = pair . into_value ( ) ; if node1 . kind ( ) != NodeKind :: Depot && node2 . kind ( ) != NodeKind :: Depot { unsafe { let mut route1 = node1 . inner . as_ref ( ) . unwrap ( ) . as_ref ( ) . route ; let mut route2 = node2 . inner . as_ref ( ) . unwrap ( ) . as_ref ( ) . route ; if Route :: check_capacity_ ( & route1 , & route2 ) { match ( node1 . pos ( ) , node2 . pos ( ) ) { ( NodePos :: First , NodePos :: First ) => { Route :: rev_ ( & route2 , true ) ; Route :: append_front_ ( & mut route1 , & mut route2 ) ; } ( NodePos :: First , NodePos :: Last ) => { Route :: append_front_ ( & mut route1 , & mut route2 ) } ( NodePos :: Last , NodePos :: First ) => { Route :: append_back_ ( & mut route1 , & mut route2 ) } ( NodePos :: Last , NodePos :: Last ) => { Route :: rev_ ( & route2 , true ) ; Route :: append_back_ ( & mut route1 , & mut route2 ) ; } _ => { } } } } } } routes . retain ( | r | ! r . is_empty ( ) ) ; routes . shrink_to_fit ( ) ; self . routes = routes ; }
Initialises the tour by using the Clarke-Wright savings algorithm.
Initialises the tour by using the Clarke - Wright savings algorithm .
&mut self