def create_route(features: Features, start_point: ImmutablePoint, end_point: ImmutablePoint): processed_features = process_route_features(features) waypoints, _, waypoint_connections, costs_matrix = processed_features waypoint_indexes = list(range(len(waypoints))) create_route_function = route_creator(waypoint_indexes, costs_matrix) start_waypoint_index = waypoints.index(start_point) end_waypoint_index = waypoints.index(end_point) route = create_route_function(start_waypoint_index, end_waypoint_index) return create_route_line_string(waypoints, waypoint_connections, route)
def make_route_creator( waypoints: Waypoints, waypoint_distances: Matrix, waypoint_connections: WaypointConnections, costs_matrix: Matrix, ): waypoint_indexes = list(range(len(waypoints))) logger.info("creating route using %s waypoints", len(waypoints)) create_route_function = route_creator(waypoint_indexes, costs_matrix) def create_route(start_index: int, end_index: int): route = create_route_function(start_index, end_index) return create_route_line_string(waypoints, waypoint_connections, route) return create_route
def create_longest_route( waypoints: Waypoints, waypoint_distances: Matrix, waypoint_connections: WaypointConnections, costs_matrix: Matrix, ) -> MultiLineString: waypoint_indexes = list(range(len(waypoints))) logger.info("creating route using %s waypoints", len(waypoints)) create_route_function = route_creator(waypoint_indexes, costs_matrix) (start_index, end_index) = find_furthest_waypoints(waypoint_distances) (start_waypoint, end_waypoint) = waypoints[start_index], waypoints[end_index] logger.info("finding route between %s and %s", start_waypoint, end_waypoint) route = create_route_function(start_index, end_index) logger.info("found route through %s waypoints", len(route)) return create_route_line_string(waypoints, waypoint_connections, route)
def test_disconnected_waypoints_full_route(self): "Waypoints which are close but there is no connection should return route" create_route = route_creator(*disconnected_route_data()) self.assertListEqual(create_route(0, 4), [0, 1, 2, 3, 4])
def test_disconnected_waypoints_jump_gap(self): "Waypoints which are close but there is no connection should return connection" create_route = route_creator(*disconnected_route_data()) self.assertListEqual(create_route(2, 3), [2, 3])
def test_basic_connected_route(self): "Waypoints directly connected should be returned as three element list" create_route = route_creator(*basic_route_data()) self.assertListEqual(create_route(0, 2), [0, 1, 2])
def test_basic_base_case(self): "Route between same start and end should only contain single waypoint" create_route = route_creator(*basic_route_data()) self.assertListEqual(create_route(2, 2), [2])