コード例 #1
0
ファイル: SmartRouter.py プロジェクト: cantu/SmartRouter
def getRouteMatchScore(car, passenger):

    cursor = RouteInfo.initDatabase()
    
    #车主起点到车主终点行车路径规划距离D0
    distance_0 = RouteInfo.queryDistanceFromDriveTable( car['start_simple_lng'], car['start_simple_lat'],
                                                                    car['end_simple_lng'], car['end_simple_lat'])
    #车主起点到乘客起点行车路径规划距离D1
    distance_1 = RouteInfo.queryDistanceFromDriveTable( car['start_simple_lng'], car['start_simple_lat'],
                                                                    passenger['start_simple_lng'], passenger['start_simple_lat'])
    #乘客起点到乘客终点行车路径规划距离D2
    distance_2 = RouteInfo.queryDistanceFromDriveTable( passenger['start_simple_lng'], passenger['start_simple_lat'],
                                                                    passenger['end_simple_lng'], passenger['end_simple_lat'])
    #乘客终点到司机终点行车路径规划距离D3
    distance_3 = RouteInfo.queryDistanceFromDriveTable( passenger['end_simple_lng'], passenger['end_simple_lat'],
                                                                    car['end_simple_lng'], car['end_simple_lat'])
    
    #计算车主绕行距离: d = (D1+D2+D3) - D0
    car_extra_distance = (distance_1 + distance_2 +distance_3) - distance_0
    #计算车主绕行因子:  r1 = d / D0,     ( 0< r1 < 1 )  越小越好
    car_extra_factor= car_extra_distance / distance_0 
    #计算车主收益因子:  r2 = D2 / D0,(0< r2 )  越大越好
    car_earn_factor= distance_2 /distance_0
    
    car_extra_plus = 1.5
    if( car_earn_factor< 0.1 ):
        match_factor = 0
    elif(car_extra_factor==0 and  car_earn_factor == 0 ):
        match_factor = 0
    else:
        match_factor = car_earn_factor - car_extra_plus*car_extra_factor
        
    #print "getRouteMatchScore, d0=%d, d1=%d, d2=%d, d3=%d"%(distance_0, distance_1, distance_2, distance_3)
    # print "车主绕行距离=%d,  车主绕行因子=%f,  车主收益因子=%f"%( car_extra_distance, car_extra_factor, car_earn_factor)   
    return (match_factor, car_extra_distance, car_extra_factor, car_earn_factor)     
コード例 #2
0
def parseRoutes(data):
    for route in data["routes"]:
        sourceToDestination = RouteInfo.RouteInfo(route["ports"][0],
                                                  route["ports"][1],
                                                  route["distance"])

        destinationToSource = RouteInfo.RouteInfo(route["ports"][1],
                                                  route["ports"][0],
                                                  route["distance"])

        QueryingData.routeList.append(sourceToDestination)
        QueryingData.routeList.append(destinationToSource)

        UserQuerying.addHubCity(route["ports"][0])
        UserQuerying.addHubCity(route["ports"][1])
コード例 #3
0
ファイル: SmartRouter.py プロジェクト: cantu/SmartRouter
def findMatchRoute(test_car_route_id ):
    #test_car_route_id = 2178
    table_name = 'recommend_'+ str(test_car_route_id) +'_tb'
    start_time = datetime.datetime.now()
    #go through all route in database 
    cursor = RouteInfo.initDatabase()
    
    #新建这条路线的匹配表
    RouteInfo.createRecommendFactorTable(cursor, table_name)
    
    #车主信息
    car = dict()
    try:
        get_car_sql =  "SELECT * from recommend_route_tb where route_id=%d "%test_car_route_id 
        print get_car_sql
        count = cursor.execute( get_car_sql)
        print 'database return %d line'%(count)
        result = cursor.fetchone()
    except Exception, e:
        print e
コード例 #4
0
        valid = QueryData.getroute(city_code)

        if valid == False:
            print "No such code."

    elif i == 5:
        EditRoute.editnetwork()

    elif i == 6:
        EditRoute.addnetwork()

    elif i == 7:
        SaveFile.saveFile()

    elif i == 8:
        RouteInfo.routeinfo()

    elif i == 9:
        MapParser.newMapParser()

    elif i == 10:
        RouteInfo.shortestroute()

    elif i == 0:
        print "See ya!"
        break

    else:
        print "Invalid Number!"
コード例 #5
0
ファイル: Interface.py プロジェクト: GoingtoRock/242
    def start(self):
        MapParser.MapParser()
        s = "Type the number for corresponding options:\n" \
            "1. Get all the cities from CSAir\n" \
            "2. Get a specific information about one city\n" \
            "3. Get all kinds of stats\n" \
            "4. Get a specific route\n" \
            "5. Edit the current city's information\n" \
            "6. Add/Remove cities and routes\n" \
            "7. Save the changed list to JSON File\n" \
            "8. Calculuate the total flight\n" \
            "9. Update CSAir with new Champaign hub town\n" \
            "10. Calculate the shortest route between to cities.\n" \
            "0. Exit the program"

        while True:

            print s

            i = raw_input("Enter the number.")
            i = int(i)
            if i == 1:
                cityList = QueryData.citylist()
                print "Here are the lists!"
                for city in cityList:
                    print city

            elif i == 2:
                city_name = raw_input("Enter the city name.")

                valid = QueryData.getcitydata(city_name)

                if valid == False :
                    print "No such city."

            elif i == 3:
                QueryData.getstat()

            elif i == 4:
                city_code = raw_input("Enter the city code.")

                valid = QueryData.getroute(city_code)

                if valid == False :
                    print "No such code."

            elif i == 5:
                EditRoute.editnetwork()

            elif i == 6:
                EditRoute.addnetwork()

            elif i == 7:
                SaveFile.saveFile()

            elif i == 8:
                RouteInfo.routeinfo()

            elif i == 9:
                MapParser.newMapParser()

            elif i == 10:
                self.routeInfo.shortestroute()

            elif i == 0:
                print "See ya!"
                break

            else:
                print "Invalid Number!"
コード例 #6
0
 def __init__(self):
     self.run = True
     self.routeInfo = RouteInfo.RouteInfo()
コード例 #7
0
    def start(self):
        MapParser.MapParser()
        s = "Type the number for corresponding options:\n" \
            "1. Get all the cities from CSAir\n" \
            "2. Get a specific information about one city\n" \
            "3. Get all kinds of stats\n" \
            "4. Get a specific route\n" \
            "5. Edit the current city's information\n" \
            "6. Add/Remove cities and routes\n" \
            "7. Save the changed list to JSON File\n" \
            "8. Calculuate the total flight\n" \
            "9. Update CSAir with new Champaign hub town\n" \
            "10. Calculate the shortest route between to cities.\n" \
            "0. Exit the program"

        while True:

            print s

            i = raw_input("Enter the number.")
            i = int(i)
            if i == 1:
                cityList = QueryData.citylist()
                print "Here are the lists!"
                for city in cityList:
                    print city

            elif i == 2:
                city_name = raw_input("Enter the city name.")

                valid = QueryData.getcitydata(city_name)

                if valid == False:
                    print "No such city."

            elif i == 3:
                QueryData.getstat()

            elif i == 4:
                city_code = raw_input("Enter the city code.")

                valid = QueryData.getroute(city_code)

                if valid == False:
                    print "No such code."

            elif i == 5:
                EditRoute.editnetwork()

            elif i == 6:
                EditRoute.addnetwork()

            elif i == 7:
                SaveFile.saveFile()

            elif i == 8:
                RouteInfo.routeinfo()

            elif i == 9:
                MapParser.newMapParser()

            elif i == 10:
                self.routeInfo.shortestroute()

            elif i == 0:
                print "See ya!"
                break

            else:
                print "Invalid Number!"
コード例 #8
0
ファイル: Interface.py プロジェクト: GoingtoRock/242
        valid = QueryData.getroute(city_code)

        if valid == False :
            print "No such code."

    elif i == 5:
        EditRoute.editnetwork()

    elif i == 6:
        EditRoute.addnetwork()

    elif i == 7:
        SaveFile.saveFile()

    elif i == 8:
        RouteInfo.routeinfo()

    elif i == 9:
        MapParser.newMapParser()

    elif i == 10:
        RouteInfo.shortestroute()

    elif i == 0:
        print "See ya!"
        break

    else:
        print "Invalid Number!"

コード例 #9
0
        valid = QueryData.getroute(city_code)

        if valid == False :
            print "No such code."

    elif i == 5:
        EditRoute.editnetwork()

    elif i == 6:
        EditRoute.addnetwork()

    elif i == 7:
        SaveFile.saveFile()

    elif i == 8:
        RouteInfo.routeinfo()

    elif i == 9:
        MapParser.newMapParser()

    elif i == 10:
        print "Try the other interface."

    elif i == 0:
        print "See ya!"
        break

    else:
        print "Invalid Number!"
コード例 #10
0
ファイル: SmartRouter.py プロジェクト: cantu/SmartRouter
def setupData():
    #1
    RouteInfo.initialRouteDatabase()
    
    #2
    RouteInfo.updateAddressInRouteTable()
    RouteInfo.updateAddressInPointAreaTable()
    RouteInfo.updateAreaIdInRouteTable()
    
    #3
    #新建驾车路径的数据库
    #RouteInfo.createDriveRouteTable()
    #计算所有路线自己的路线
    start_time = datetime.datetime.now()
    RouteInfo.queryPathOneself()
    end_time = datetime.datetime.now()
    elapsed = (end_time -  start_time ).seconds
    print( ' query one point all drive route total used time: ', elapsed)
    
    #实验用司机路线 route_id=2178,  
    #中关村街道恒兴大厦(东门)                start_simple( 116.335, 39.985),     area_id =1
    #通州区梨园地区新华联家园(南区)        end_simple( 116.645, 39.890),     area_id=326
    
    #实验路线的起点到其它所有点的规划
    area_id = 1
    start_time = time.clock( )
    RouteInfo.queryPathOneToOthers( area_id )
    print ''
    print  '*'*80
    elapsed = (time.clock() - start_time )
    print( ' query one point all drive route total used time: ', elapsed)
    
        
    
    #实验路线的终点到其它所有点的驾车路线规划
    area_id = 326
    start_time = datetime.datetime.now()
    RouteInfo.queryPathOneToOthers( area_id )
    print ''
    print  '*'*80
    end_time = datetime.datetime.now()
    elapsed = (end_time -  start_time ).seconds
    print( ' query one point all drive route total used time: ', elapsed)
コード例 #11
0
ファイル: SmartRouter.py プロジェクト: cantu/SmartRouter
    
#***********************************************************************************
#main function    


#实验用司机路线 route_id=2178,  
#中关村街道恒兴大厦(东门)                start_simple( 116.335, 39.985),     area_id =1
#通州区梨园地区新华联家园(南区)        end_simple( 116.645, 39.890),     area_id=326
example_car_route_list=[2178, 20, 814, 928, 3690, 1090, 1591, 2531, 788, 1377, 1490]

#findMatchRoute(1377)


for route_id in example_car_route_list:
    #findMatchRoute(route_id)
    RouteInfo.updateRecommendRouteInRouteTable( route_id)

print 'finish '
#SELECT * FROM youche_info.recommend_2178_tb order by car_extra_factor limit 30;
#SELECT * FROM `recommend_route_tb` WHERE start_address LIKE '%大兴%'
#SELECT * FROM youche_info.recommend_20_tb where car_extra_factor <0.1 order by car_earn_factor desc limit 30;
#SELECT * FROM youche_info.recommend_2178_tb order by match_factor desc limit 100;
#SELECT * FROM youche_info.recommend_route_tb where recommend_route_id IS NULL limit 100;