def test_parabolic_penalty(self):
        """Test a multipoint optimization, with polysimplification."""
        nmap = np.zeros([200, 200])
        starting_point = (7, 7)
        intermediate = (20, int(nmap.shape[1] * 0.8))
        ending_point = (nmap.shape[0] - 10, nmap.shape[1] - 10)
        """Optimization"""

        max_slope = 0.1
        semi_size = 5
        neighbors = a_star.precalc_neighbourhood(semi_size)
        max_dist_index = 100 * np.sum(np.square(nmap.shape))
        penalty_factor_xy = 40
        penalty_factor_z = 0

        heuristic = heuristics.DistanceSlopeMetric(nmap, max_slope,
                                                   max_dist_index)
        tentative_heuristic = heuristics.Distance(max_dist_index)
        penalty = penalties.ParabolicPenalty(neighbors, penalty_factor_xy,
                                             penalty_factor_z)

        astar = a_star.AStarOptimizer(nmap, 5, heuristic, tentative_heuristic,
                                      penalty)

        waypoints = astar.astar([starting_point, intermediate, ending_point])

        self.assertGreater(len(waypoints), 0)
示例#2
0
    def reset_config(self, min_slope, max_slope, semi_size, penalty_factor_xy,
                     penalty_factor_z, exclusion_array):
        """Create default heuristics, tentative_heuristic and penalty objects.
        """
        max_dist_index = 100 * np.sum(
            np.square(np.array(self.array) * self.array_resolution_m_per_pix))

        neighbors = precalc_neighbourhood(semi_size)

        if min_slope is None and max_slope is None:
            self.heuristic = heuristics.DistanceSquaredFakeSlope(
                max_dist_index)
            self.tentative_heuristic = heuristics.DistanceSquared(
                max_dist_index)
        else:

            if min_slope is None or min_slope <= 0:

                self.heuristic = heuristics.DistanceSlopeMetric(
                    self.array, max_slope, max_dist_index)
            else:
                self.heuristic = heuristics.DistanceMinMaxSlopeMetric(
                    self.array, max_slope, max_dist_index, min_slope)

            use_precalc = False
            if use_precalc:
                assert (min_slope <= 0)
                self.tentative_heuristic = \
                heuristics.PrecalculatedOptimalDistanceSlopeConstrained(
                    max_dist_index,
                    self.array,
                    max_slope  * self.array_resolution_m_per_pix,
                    1.0,
                    target_scale=None)
            else:
                self.tentative_heuristic = heuristics.Distance(max_dist_index)

        if exclusion_array is not None:
            """Use specialized class that supports exclusion, slower."""

            self.penalty = penalties.ParabolicPenaltyStatic(
                exclusion_array[::-1] * (3 * max_dist_index), neighbors,
                penalty_factor_xy, penalty_factor_z)
        elif penalty_factor_xy != 0 or penalty_factor_z != 0:
            """Approx. 20% faster than ParabolicPenaltyStatic."""
            self.penalty = penalties.ParabolicPenalty(neighbors,
                                                      penalty_factor_xy,
                                                      penalty_factor_z)
        else:
            self.penalty = penalties.NoPenalty(neighbors)
    def _test_full_stack_distance_transform_precalc_penalty(self):
        """Test a multipoint optimization, with polysimplification."""
        nmap = np.zeros([100, 100])
        starting_point = (7, 7)
        intermediate = (20, int(nmap.shape[1] * 0.8))
        ending_point = (nmap.shape[0] - 10, nmap.shape[1] - 10)
        """Optimization"""

        max_slope = 0.1
        semi_size = 5
        neighbors = a_star.precalc_neighbourhood(semi_size)
        max_dist_index = 100 * np.sum(np.square(nmap.shape))
        penalty_factor_xy = 40
        penalty_factor_z = 0
        scale_m_per_pix = 5

        heuristic = heuristics.DistanceSlopeMetric(nmap, max_slope,
                                                   max_dist_index)
        tentative_heuristic = \
            heuristics.PrecalculatedOptimalDistanceSlopeConstrained(
                max_dist_index,
                nmap,
                max_slope,
                scale_m_per_pix,
                target_scale=1)
        penalty = penalties.ParabolicPenalty(neighbors, penalty_factor_xy,
                                             penalty_factor_z)

        astar = a_star.AStarOptimizer(nmap, scale_m_per_pix, heuristic,
                                      tentative_heuristic, penalty)

        waypoints = astar.astar([starting_point, intermediate, ending_point])

        path_simplifier = polysimplify.VWSimplifier(waypoints)
        path_simplified = path_simplifier.from_threshold(0.01)
        self.assertGreater(len(path_simplified), 0)
示例#4
0
    neighbors = precalc_neighbourhood(semi_size)
    max_dist_index = 100 * np.sum(np.square(nmap.shape) * scale_m_per_pix**2)

    if max_slope is None:
        heuristic = heuristics.DistanceSquaredFakeSlope(max_dist_index)
        tentative_heuristic = heuristics.DistanceSquared(max_dist_index)
        penalty = NoPenalty(neighbors)

    else:
        penalty_factor_xy = 40
        penalty_factor_z = 0

        heuristic = heuristics.DistanceSlopeMetric(nmap, max_slope,
                                                   max_dist_index)

        penalty = penalties.ParabolicPenalty(neighbors, penalty_factor_xy,
                                             penalty_factor_z)
        use_precalc = True
        if use_precalc:
            tentative_heuristic = \
            heuristics.PrecalculatedOptimalDistanceSlopeConstrained(
                max_dist_index,
                nmap,
                max_slope,
                scale_m_per_pix,
                target_scale=None)
        else:
            tentative_heuristic = heuristics.Distance(max_dist_index)

    astar = AStarOptimizer(nmap, 1, heuristic, tentative_heuristic, penalty)

    starting_point = (1, 0)