ortools中的RoutingModel

时间:2019-05-12 07:43:32

标签: python

我该如何解决?

def __init__(self, locations, speed):
    self.locations = locations
    self.speed = speed
    self._durations = {}
    num_locations = len(self.locations)

    # precompute distance between location to have distance callback in O(1)
    for from_node in xrange(num_locations):
        self._durations[from_node] = {}
        for to_node in xrange(num_locations):
            if from_node == to_node:
                self._durations[from_node][to_node] = 0
            else:
                loc1 = self.locations[from_node]
                loc2 = self.locations[to_node]
                dist = self.distance(loc1[0], loc1[1], loc2[0], loc2[1])
                dur = self._durations[from_node][to_node] = (3600 * dist) / self.speed
                # print "{} {} {}".format(from_node, to_node, dur)

def Duration(self, from_node, to_node):
    return self._durations[from_node][to_node]

def distance(self, lat1, long1, lat2, long2):
    # Note: The formula used in this function is not exact, as it assumes
    # the Earth is a perfect sphere.

    # Mean radius of Earth in miles
    radius_earth = 3959

    # Convert latitude and longitude to
    # spherical coordinates in radians.
    degrees_to_radians = math.pi / 180.0
    phi1 = lat1 * degrees_to_radians
    phi2 = lat2 * degrees_to_radians
    lambda1 = long1 * degrees_to_radians
    lambda2 = long2 * degrees_to_radians
    dphi = phi2 - phi1
    dlambda = lambda2 - lambda1

    a = self.haversine(dphi) + math.cos(phi1) * math.cos(phi2) * self.haversine(dlambda)
    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
    d = radius_earth * c
    return d

def haversine(self, angle):
    h = math.sin(angle / 2) ** 2
    return h

返回_pywrapcp.RoutingModel_SetArcCostEvaluatorOfAllVehicles(自身,evaluator_index) TypeError:方法“ RoutingModel_SetArcCostEvaluatorOfAllVehicles”中,类型为“ int”的参数2

0 个答案:

没有答案