def mergedEdgeCostWeightedByLength(edge1, cost1, edge2, cost2):
    """Combiner function for `StaticEdgeCosts`.  Defines the cost for
    a merged edge as the average of the costs from the merged edges,
    weighted by their lengths."""

    l1 = edge1.length()
    l2 = edge2.length()
    return (cost1*l1 + cost2*l2)/(l1+l2)