コード例 #1
0
ファイル: server.py プロジェクト: gangamaha/lynxapp
def returnsingle():
    source = request.GET.get('source')
    sink = request.GET.get('sink')
    rank = request.GET.get('rank')
	
    # Load the graph
    G = DiGraph("net5")    
    # Get the painting object and set its properties.
    paint = G.painter()
    paint.set_source_sink(source, sink)    
    # Generate the graph using the painter we configured.
    G.export(False, paint)
    i=int(rank)
    iRank = i
    # Get shortest paths from the graph.
    items = algorithms.ksp_yen(G, source, sink, i)
    for path in items:
        sCost = path['cost']
        sPath = ", ".join(path['path'])               
        response.content_type='application/json'
        response.headers['Access-Control-Allow-Origin']='*'
        bus_Stop, bus_No, stop_Name, route_Id =  result.busChanger(source,sink,iRank)
        if i==1:
            return { "BusStop": bus_Stop, "BusNo": bus_No, "StopName": stop_Name, "RouteNo ": route_Id}
        else:
            i=i-1
            continue
コード例 #2
0
ファイル: __init__.py プロジェクト: Astasie/YenKSP
def main():
    # Load the graph
    G = DiGraph("net5")
    
    # Get the painting object and set its properties.
    paint = G.painter()
    paint.set_source_sink("C", "H")
    paint.set_rank_same(['C', 'D', 'F'])
    paint.set_rank_same(['E', 'G', 'H'])
    
    # Generate the graph using the painter we configured.
    G.export(False, paint)
    
    # Get 30 shortest paths from the graph.
    items = algorithms.ksp_yen(G, "C", "H", 30)
    for path in items:
        print "Cost:%s\t%s" % (path['cost'], "->".join(path['path']))
          
    return 0
コード例 #3
0
def main():
    # Load the graph
    G = DiGraph("net5")

    # Get the painting object and set its properties.
    paint = G.painter()
    paint.set_source_sink("C", "H")
    paint.set_rank_same(['C', 'D', 'F'])
    paint.set_rank_same(['E', 'G', 'H'])

    # Generate the graph using the painter we configured.
    G.export(False, paint)

    # Get 30 shortest paths from the graph.
    items = algorithms.ksp_yen(G, "C", "H", 30)
    for path in items:
        print "Cost:%s\t%s" % (path['cost'], "->".join(path['path']))

    return 0
コード例 #4
0
ファイル: test.py プロジェクト: gangamaha/lynxapp
from graph import DiGraph
import algorithms

source = "s175"
sink = "s555"
rank = "13"

# Load the graph
G = DiGraph("net5")    
# Get the painting object and set its properties.
paint = G.painter()
paint.set_source_sink(source, sink)    
# Generate the graph using the painter we configured.
G.export(False, paint)
i=int(rank)
iRank = i
# Get shortest paths from the graph.
items = algorithms.ksp_yen(G, source, sink, i)
print(items)
#for path in items:
#   sCost = path['cost']
#    sPath = ", ".join(path['path'])               
#    response.content_type='application/json'
#    if i==1:
#        return { "Cost": sCost, "Path": sPath, "BusChange": result.busChanger(source,sink,iRank) }
#    else:
#        i=i-1
#        continue
コード例 #5
0
def main():
    # Load the graph
    G = DiGraph("net5")

    # Get the painting object and set its properties.
    paint = G.painter()
    #paint.set_source_sink('ada', 'bob')
    paint.set_source_sink('s5', 's7')

    # load the graph dictionary
    das_ergebnis = joblib.load(
        "/Users/aditimiglani/Downloads/das_ergebnis.pkl")

    list_of_edges = das_ergebnis['edges']
    list_of_nodes = das_ergebnis['nodes']
    for edge in list_of_edges:
        source = str(edge['source'])
        target = str(edge['target'])
        load = float(edge['load'])
        G.add_edge(source, target, load)
        G.add_edge(target, source, load)

    #G.add_edge('ada', 'sue', 3)
    #G.add_edge('ada', 'john', 2)
    #G.add_edge('sue', 'bob', 1)
    #G.add_edge('a', 'b', 1)
    #G.add_edge('sue', 'john', 1)
    #G.add_edge('john', 'bob', 1)

    # Generate the graph using the painter we configured.
    G.export(False, paint)

    # Get 5 shortest paths from the graph.
    items = algorithms.ksp_yen(G, 's5', 's7', 5)
    all_paths = []
    #items = algorithms.ksp_yen(G, 'ada', 'bob', 5)
    for path in items:
        print "Cost:%s\t%s" % (path['cost'], "->".join(path['path']))
        all_paths.append(path['path'])

    print all_paths
    sub_das_ergebnis = {}
    sub_das_ergebnis['nodes'] = []
    sub_das_ergebnis['edges'] = []
    for sub_dict in list_of_nodes:
        for path in all_paths:
            for i in range(len(path)):
                if path[i] == sub_dict['id']:
                    if sub_dict not in sub_das_ergebnis['nodes']:
                        if i == 0 or i == len(path) - 1:
                            sub_dict['root'] = True
                            sub_das_ergebnis['nodes'].append(sub_dict)
                        else:
                            sub_dict['root'] = False
                            sub_das_ergebnis['nodes'].append(sub_dict)
    for sub_dict in list_of_edges:
        for path in all_paths:
            for i in range(len(path)):
                if i < len(path) - 1:
                    if (path[i] == sub_dict['source']
                            or path[i] == sub_dict['target']) and (
                                path[i + 1] == sub_dict['source']
                                or path[i + 1] == sub_dict['target']):
                        if sub_dict not in sub_das_ergebnis['edges']:
                            sub_das_ergebnis['edges'].append(sub_dict)

    joblib.dump(sub_das_ergebnis, 'sub_das_ergebnis.pkl')
    print sub_das_ergebnis
    print 'loading'
    loaded = joblib.load('sub_das_ergebnis.pkl')
    print loaded

    return 0