コード例 #1
0
def EarthMoversDistance( lengraph, supplygraph, length='length', weight1='weight1', weight2='weight2' ) :
    # lengraph is a *non*-multi DiGraph
    digraph, s, t = FLOW.obtainCapacityNetwork( lengraph, supplygraph, length, weight1, weight2 )
    #
    flowgraph = FLOW.obtainFlowNetwork( digraph, s, t, capacity='capacity' )
    costgraph = FLOW.obtainWeightedCosts( flowgraph, lengraph, weight=length )
    
    # compute optimal flow
    FLOW.max_flow_min_cost( flowgraph, costgraph )
    
    return FLOW.totalcost( costgraph ).value
コード例 #2
0
def EarthMoversDistance( measurenx, length='length', weight1='weight1', weight2='weight2', DELTA=None ) :
    flowgraph, costgraph = obtainWassersteinProblem( measurenx, length, weight1, weight2 )
    flownets.max_flow_min_cost( flowgraph, costgraph )
    return flownets.totalcost( costgraph ).value
コード例 #3
0
        roadnet.add_edge( 0, 1, 'road1', length=2., weight1=0.+OFFSET, weight2=.5+OFFSET)
        roadnet.add_edge( 1, 2, 'road2', length=1., weight1=.4)
        roadnet.add_edge( 2, 3, 'road3', length=3., weight2=.1)
        roadnet.add_edge( 3, 0, 'road4', length=5., weight1=.4)
        
    elif False :
        OFFSET = 10.
        roadnet.add_node( 0, weight1=.7 )
        roadnet.add_edge( 0,1, 'road1', length=1., weight1=0.+OFFSET, weight2=.5+OFFSET )
        roadnet.add_edge( 0,2, 'road2', length=10., weight2=.6 )
        
    else :
        roadnet.add_edge( 0, 1, 'N', length=1., weight2=3. )
        roadnet.add_edge( 1, 2, 'E', length=1., weight1=1000., oneway=False )
        roadnet.add_edge( 2, 3, 'S', length=1., weight1=1. )
        roadnet.add_edge( 3, 0, 'W', length=1., weight2=1. )
        #roadnet.add_node( 0, weight1=.7 )
        #roadnet.add_edge( 0, 1 )
        
        
    #g.add_edge( 1, 3, 'road3 ' )
    #print 'max flow is %f' % maxflow
    #print 'min cost max flow is %f' % res
    fgraph, cgraph = obtainWassersteinProblem( roadnet)
    
    flownets.max_flow_min_cost( fgraph, cgraph )