Sets the piece-wise linear cost attribute, converting the
        polynomial cost variable by evaluating at zero and then at n_points
        evenly spaced points between p_min and p_max.

def poly_to_pwl(self, n_points=4):
        """ Sets the piece-wise linear cost attribute, converting the
        polynomial cost variable by evaluating at zero and then at n_points
        evenly spaced points between p_min and p_max.
        """
        assert self.pcost_model == POLYNOMIAL
        p_min = self.p_min
        p_max = self.p_max
        p_cost = []

        if p_min > 0.0:
            # Make the first segment go from the origin to p_min.
            step = (p_max - p_min) / (n_points - 2)

            y0 = self.total_cost(0.0)
            p_cost.append((0.0, y0))

            x = p_min
            n_points -= 1
        else:
            step = (p_max - p_min) / (n_points - 1)
            x = 0.0

        for _ in range(n_points):
            y = self.total_cost(x)
            p_cost.append((x, y))
            x += step

        # Change the cost model and set the new cost.
        self.pcost_model = PW_LINEAR
        self.p_cost = p_cost