Пример #1
0
def ROADSBIPARTITEMATCH( P, Q, roadnet, **kwargs ) :
    MATCH = []
    
    segment_dict = SEGMENTS( P, Q, roadnet )
    surplus_dict = dict()
    objective_dict = dict()
    measure_dict = dict()
    
    for road, segment in segment_dict.iteritems() :
        match = PREMATCH( segment )
        MATCH.extend( match )
        
        surplus_dict[road] = SURPLUS( segment )
        
        roadlen = get_road_data( road, roadnet ).get( 'length', 1 )
        measure = MEASURE( segment, roadlen )
        measure_dict[road] = measure
        #objective_dict[road] = OBJECTIVE( measure )
        #objective_dict[road] = objective
        
    #from nxflow.capscaling import SOLVER
    if True :
        assist = SOLVER( roadnet, surplus_dict, measure_dict )
    else :
        try :
            assist = SOLVER( roadnet, surplus_dict, objective_dict )
        except Exception as ex :
            ex.segs = segment_dict
            ex.surp = surplus_dict
            ex.obj = objective_dict
            
            raise ex
    
    if False :		# activate for debug
        imbalance = CHECKFLOW( assist, roadnet, surplus_dict )
    else :
        imbalance = []
        
    try :
        assert len( imbalance ) <= 0
    except Exception as ex :
        ex.imbal = imbalance
        raise ex

    if kwargs.get('assist_only', False ) : return assist
    
    
    topograph = TOPOGRAPH( segment_dict, assist, roadnet )
    
    try :
        match = TRAVERSE( topograph )
    except Exception as ex :
        ex.assist = assist
        ex.topograph = topograph
        raise ex
    
    MATCH.extend( match )
    return MATCH
Пример #2
0
def ROADSBIPARTITEMATCH(P, Q, roadnet, **kwargs):
    MATCH = []

    segment_dict = SEGMENTS(P, Q, roadnet)
    surplus_dict = dict()
    objective_dict = dict()
    measure_dict = dict()

    for road, segment in segment_dict.iteritems():
        match = PREMATCH(segment)
        MATCH.extend(match)

        surplus_dict[road] = SURPLUS(segment)

        roadlen = get_road_data(road, roadnet).get('length', 1)
        measure = MEASURE(segment, roadlen)
        measure_dict[road] = measure
        #objective_dict[road] = OBJECTIVE( measure )
        #objective_dict[road] = objective

    #from nxflow.capscaling import SOLVER
    if True:
        assist = SOLVER(roadnet, surplus_dict, measure_dict)
    else:
        try:
            assist = SOLVER(roadnet, surplus_dict, objective_dict)
        except Exception as ex:
            ex.segs = segment_dict
            ex.surp = surplus_dict
            ex.obj = objective_dict

            raise ex

    if False:  # activate for debug
        imbalance = CHECKFLOW(assist, roadnet, surplus_dict)
    else:
        imbalance = []

    try:
        assert len(imbalance) <= 0
    except Exception as ex:
        ex.imbal = imbalance
        raise ex

    if kwargs.get('assist_only', False): return assist

    topograph = TOPOGRAPH(segment_dict, assist, roadnet)

    try:
        match = TRAVERSE(topograph)
    except Exception as ex:
        ex.assist = assist
        ex.topograph = topograph
        raise ex

    MATCH.extend(match)
    return MATCH
Пример #3
0
def position(address, roadmap, pos, length_attr='length'):
    """
    get the Euclidean position of a street address,
    given roadmap and dictionary of vertex positions
    """
    road, coord = address
    coord = float(coord)

    u, v, key = ROAD.obtain_edge(roadmap, road)
    assert key == road
    data = ROAD.get_road_data(road, roadmap)
    width = data.get( length_attr, 1 )

    #ROAD.get_edge_data( )
    x = pos[u]
    vec = pos[v] - x
    return x + vec * coord / width
Пример #4
0
def WRITEOBJECTIVES(P, Q, roadnet):
    MATCH = []  # although, we just toss this...

    segment_dict = SEGMENTS(P, Q, roadnet)
    surplus_dict = dict()
    objective_dict = dict()

    for road, segment in segment_dict.iteritems():
        match = PREMATCH(segment)
        MATCH.extend(match)

        surplus_dict[road] = SURPLUS(segment)

        roadlen = get_road_data(road, roadnet).get('length', 1)
        measure = MEASURE(segment, roadlen)
        objective_dict[road] = OBJECTIVE(measure)
        #objective_dict[road] = objective

    return objective_dict
Пример #5
0
def WRITEOBJECTIVES( P, Q, roadnet ) :
    MATCH = []      # although, we just toss this...
    
    segment_dict = SEGMENTS( P, Q, roadnet )
    surplus_dict = dict()
    objective_dict = dict()
    
    for road, segment in segment_dict.iteritems() :
        match = PREMATCH( segment )
        MATCH.extend( match )
        
        surplus_dict[road] = SURPLUS( segment )
        
        roadlen = get_road_data( road, roadnet ).get( 'length', 1 )
        measure = MEASURE( segment, roadlen )
        objective_dict[road] = OBJECTIVE( measure )
        #objective_dict[road] = objective
        
    return objective_dict
Пример #6
0
    plt.figure()
    plt.title('Pure Path-length Optimal')
    matchvis.SHOWTRAILS( S, T, assist_nocongestion, roadmap, pos )


    if False :    
        segment_dict = roadbm.SEGMENTS( S, T, roadmap )
        measure_dict = {}
        
        for road, segment in segment_dict.iteritems() :
            match = roadbm.PREMATCH( segment )
            MATCH.extend( match )
            
            #surplus_dict[road] = SURPLUS( segment )
            
            roadlen = ROAD.get_road_data( road, roadmap ).get( 'length', 1 )
            measure = roadbm.MEASURE( segment, roadlen )
            measure_dict[road] = measure
            #objective_dict[road] = OBJECTIVE( measure )
            #objective_dict[road] = objective
        """ measure_dict now contains sequence of W_n """
    
    
        C_man = CONGESTION_OBJECTIVE_DATA( measure, rho, False )
        C_fft = CONGESTION_OBJECTIVE_DATA( measure, rho, True )
        
        C = CONGESTION_OBJECTIVE( measure, rho )
        
    
    
    
Пример #7
0
        cost_brute = ROADMATCHCOST(match_brute, PP, QQ, roadnet)
        print match_brute
        print costs_brute
        print cost_brute
        #print 'optimal match has cost: %f' % matchcost

    if False:  # validate CTREES
        zmin = -NUMPOINT / 2
        zmax = NUMPOINT / 2
        ZZZ = range(zmin, zmax)
        #
        for road, C in CTREES.iteritems():
            ax = drawCBounds(ZZ, CTREES[road])
            #plt.plot( ZZ, Cz, linestyle='--' )

            width = get_road_data(road, roadnet).get('length', 1)
            Cmatch = [MATCHCOST(P[road], Q[road], width, z) for z in ZZZ]
            plt.scatter(ZZZ, Cmatch, marker='x')

    if False:
        # validate C's of the different roads
        for road in CTREES:
            ax = drawCBounds(ZZ, CTREES[road])
            ax.set_title('road=%s' % road)
            zr = assist[road].value
            cost = costWrapper(CTREES[road])
            Cr = cost(zr)
            #ax.axvline( assist[road].value )
            ax.scatter([zr], [Cr], marker='o')
            ax.scatter([zr], [cost[road].value], marker='x')
Пример #8
0
        print costs_brute
        print cost_brute
        #print 'optimal match has cost: %f' % matchcost

        
        
    if False :       # validate CTREES
        zmin = -NUMPOINT/2
        zmax = NUMPOINT/2
        ZZZ = range( zmin, zmax )
        #
        for road, C in CTREES.iteritems() :
            ax = drawCBounds( ZZ, CTREES[road] )
            #plt.plot( ZZ, Cz, linestyle='--' )
            
            width = get_road_data( road, roadnet ).get( 'length', 1 )
            Cmatch = [ MATCHCOST( P[road], Q[road], width, z ) for z in ZZZ ]
            plt.scatter( ZZZ, Cmatch, marker='x' )
            
            
    if False :
            # validate C's of the different roads
            for road in CTREES :
                ax = drawCBounds( ZZ, CTREES[road] )
                ax.set_title('road=%s' % road )
                zr = assist[road].value
                cost = costWrapper( CTREES[road] )
                Cr = cost( zr )
                #ax.axvline( assist[road].value )
                ax.scatter( [ zr ], [ Cr ], marker='o' )
                ax.scatter( [ zr ], [ cost[road].value ], marker='x' )