示例#1
0
def grafo_unido(Cab=None, Rep=None, we=False, co=True, **kwds):
    G = nx.Graph()
    PO = []
    Gax = nx.Graph()
    if Cab is not None:
        G.add_nodes_from(Cab.keys())
        nx.set_node_attributes(G, Cab, 'pos')
        aux = edge_gen(G.nodes())
        G.add_edges_from(aux)

        for i in Cab.keys():
            if Rep is not None:
                re = Rep[i]
                pre = pos_rep(re)
                Gax.add_nodes_from(pre.keys())
                G.add_nodes_from(pre.keys())
                nx.set_node_attributes(G, pre, 'pos')
            pos = bd.georefxc(Fil=[i])
            for t in pos[i].keys():
                PO.append(t)
            Gax.add_nodes_from(pos[i].keys())
            nx.set_node_attributes(Gax, pos[i], 'pos')
            # se agrega atributos con pocisión
            G.add_nodes_from(pos[i].keys())
            nx.set_node_attributes(G, pos[i], 'pos')
            ed = edge_gen(Gax.nodes())
            Gax.add_edges_from(ed)
            G.add_edges_from(Gax.edges())
    if we == True:
        w = {}

        w = w_eg(G)
        nx.set_edge_attributes(G, w, 'weight')
    return G, PO
示例#2
0
def ejec_rep(Cab, G=None):

    for i in Cab.keys():
        rep = {}
        G1 = nx.Graph()
        map = []
        pos = bd.georefxc(Fil=[i])
        G1, pos1 = grafo_unido({i: Cab[i]})
        print(i)
        #pos ={'7':{'rep199': [-74.497104, 4.610978], 'rep200': [-74.555972, 4.578489]
        #       ,'rep19': [-74.4903, 4.5924],'rep2': (-74.508625, 4.603122)}}
        Arcoo = pos.values()[0]
        map, DiM = ext_map(Arco=Arcoo, met=True)
        MaIr, map1 = ins_rep(pos.values()[0], map, DiM, tam=7)
        Rep, Corep, map1 = Inter_search(MaIr, DiM, map, map1)
        #map1[97,131]=120
        G = nx.Graph()
        map_inter(map1, DiM, No=i, r=False, G=G1, p1=[i], p2=pos1)
        try:
            rep[i] = Corep
        except KeyError:
            rep[i] = {}
            rep[i] = Corep
        print(Corep)
        print('-' * 120)
示例#3
0
def ejecucion():
    pos= bd.georefxc()
    cab={u'SILVANIA':[-74.388056,4.403333] 
        ,u'TIBACUY':[-74.4525, 4.347222]
        ,u'PASCA' :[-74.300833, 4.3075]
        ,u'ARBELAEZ':[-74.415556,4.272222]
        ,u'PANDI': [-74.487778,4.191111] 
        ,u'SAN BERNARDO':[-74.422222,4.178889] 
        ,u'VENECIA': [-74.4775,4.088611] 
        ,u'CABRERA':	[-74.485833,3.978056]
        ,u'GRANADA':	[-74.351389,4.518611]
        ,u'FUSAGASUGA':[-74.364444,4.337222]}
    G2= nx.Graph()
    G= nx.Graph()
    G2.add_nodes_from(cab.keys())
    nx.set_node_attributes(G2,'pos',cab)
    #nx.set_node_attributes(G,'color',col)
    #nx.set_node_attributes(G,'tam',tam)
    #G.add_edges_from(edge_gen(G.nodes()))
    #el=G.edges()
    sG={}
    attr={}
    for i in pos.keys():
        sG[i]= nx.Graph()
    for i in pos.keys():
        G.add_nodes_from(pos[i].keys())
        nx.set_node_attributes(G,'pos',pos[i])
        sG[i].add_nodes_from(pos[i].keys())
        nx.set_node_attributes(sG[i],'pos',pos[i])
        aux=edge_gen(pos[i].keys())
        G.add_edges_from(aux)
        attr[i]=(aux)

    lon,la= bd.la_lon()
    po=nx.get_node_attributes(G,'pos')
    coo=[np.mean(la.values()), np.mean(lon.values())]
    #s=h.vercu(coo,po)
    au, DiM = ext_map(coo,po)
    we=[]
    for i in G.edges():
        r=list(i)
        per,o= h.perfil(au,[po[i[0]],po[i[1]]],DiM)
        aux=np.round(np.max(per[3]))  
        we.append((i,aux))   
    we=dict(we)
    nx.set_edge_attributes(G,'weight',we)
    #h.show_map(au,DiM,G,Pos=po,Pos1=cab,G1=G2)
    COSTO=[0.25,0.55,1,60,20]
    Gs=nx.Graph()
    Gs.add_nodes_from(G.nodes())
    cos={}
    for i in sG.keys():
        A= nx.Graph()
        co=[cab[i][1],cab[i][0]]
        print i, co
        for j in attr[i]:       
            r=list(j)
            sG[i].add_edge(r[0],r[1],weight=G[r[0]][r[1]]['weight'])
        po1=nx.get_node_attributes(sG[i],'pos')
        cC,cT, coverh,T = tc.algo(sG[i],COSTO)
        s=h.vercu(co,po1)
        print s
        au1, DiM1= h.manipular_mapas(co,s)
        A.add_nodes_from(coverh.nodes())
        A.add_edges_from(coverh.edges()) 
        Gs.add_edges_from(coverh.edges())
        h.show_map(au1,DiM1,sG[i],Pos=po1,Pos1=cab,G1=G2,nodels=[i])
        h.show_map(au1,DiM1,A,Pos=po1,Pos1=cab,G1=G2,nodels=[i])
        cos[i]=[cC,cT]
        print cC, cT
        print '-'*80
    print nx.number_of_edges(G),nx.number_of_nodes(G)
    print nx.number_of_edges(Gs),nx.number_of_nodes(Gs)    
    h.show_map(au,DiM,Gs,Pos=po,Pos1=cab,G1=G2)
    print cos
    print '*'*120
示例#4
0
def dibujar_grafo_unido(G=None,
                        cab=None,
                        Rep=None,
                        map=None,
                        DiM=None,
                        nols=None,
                        no_lab=None,
                        title=None,
                        rt=False,
                        s=None,
                        **kwds):
    po = 0
    key = list(cab.keys())
    if cab is None:
        pass
    else:
        if len(cab) == 1:
            pos = bd.georefxc(key[0])
        else:
            pos = bd.georefxc()
    if G is None:

        G = nx.Graph()
        G.add_nodes_from(cab.keys())
        nx.set_node_attributes(G, 'pos', cab)
        attr = {}
        for i in pos.keys():
            G.add_nodes_from(pos[i].keys())
            nx.set_node_attributes(G, 'pos', pos[i])
            aux = edge_gen(pos[i].keys())
            G.add_edges_from(aux)
            attr[i] = (aux)
    po = nx.get_node_attributes(G, 'pos')
    G1nodels = []
    if map is None:
        map = []
        map, DiM = ext_map(Arco=po, met=True, s=s)
    if Rep is not None:
        h.show_map(map,
                   DiM,
                   G,
                   Pos=po,
                   nodels=cab.keys(),
                   G1nodels=nols,
                   Repls=Rep,
                   no_lab=no_lab,
                   p=True,
                   title=title,
                   rt=rt)
    else:
        h.show_map(map,
                   DiM,
                   G,
                   Pos=po,
                   nodels=cab.keys(),
                   G1nodels=nols,
                   no_lab=no_lab,
                   p=True,
                   title=title,
                   rt=rt)
    return map, DiM
示例#5
0
def usar_algo(G,
              Cab,
              rep1=False,
              max=False,
              num_rep=None,
              icu=False,
              no_lab=None,
              label=False,
              **kwds):
    sG = {}
    GT = nx.Graph()
    GC = nx.Graph()
    Gi = nx.Graph()
    lsRe = []
    Po1 = []
    Ps = {}
    Sp = {}
    for i in Cab.keys():
        cab = {i: Cab[i]}
        sG[i] = nx.Graph()
        print(i)
        if rep1 == True:
            rep = dr.dict_rep([i], max=max, num_rep=num_rep, icu=icu)
            print('Repetidor =', rep)
            lsrep = Re.pos_rep(rep)
            lsrep = Re.pos_rep(lsrep)
            for k in lsrep:
                lsRe.append(k)
        else:
            lsrep = None
            rep = None
            lsRe = None

        sG[i], pos1 = Re.grafo_unido(cab, we=True, Rep=rep)

        for k in pos1:
            Po1.append(k)
        """
        pos= bd.georefxc(Fil=[i])
        pos=pos[i]
        pos[i]=cab[i]
        if no_lab is not None:
            no_lab=pos
        """

        u1 = nx.get_node_attributes(sG[i], 'pos')
        ps = bd.georefxc(Fil=[i], label=True)
        sp = dict((n, n) for n in u1.keys())

        print(nx.get_edge_attributes(sG[i], 'weight'))

        map, DiM = Re.dibujar_grafo_unido(G=sG[i],
                                          cab=cab,
                                          nols=pos1,
                                          rt=True,
                                          title=i,
                                          Rep=lsrep,
                                          no_lab=sp)
        COSTO = [0.75, 0.65, 1, 30, 20]
        for k in ps.keys():
            Sp[k] = sp[k]
        for k in ps.keys():
            Ps[k] = ps[k]

        cC, cT, InG, coverh, T = tc.algo(G, COSTO)

        u = nx.get_node_attributes(sG[i], 'pos')
        GT.add_nodes_from(sG[i].nodes())
        nx.set_node_attributes(GT, u, 'pos')
        GT.add_edges_from(sG[i].edges())
        GC.add_nodes_from(coverh.nodes())
        GC.add_edges_from(coverh.edges())
        nx.set_node_attributes(GC, u, 'pos')
        Gi.add_nodes_from(InG.nodes())
        Gi.add_edges_from(InG.edges())
        nx.set_node_attributes(Gi, u, 'pos')
        print('cC=', cC, 'cT=', cT)
        print('*' * 200)

    map, DiM = Re.dibujar_grafo_unido(G=GT, cab=Cab, nols=Po1)
    map, DiM = Re.dibujar_grafo_unido(G=GC, cab=Cab, nols=Po1)
    map, DiM = Re.dibujar_grafo_unido(G=Gi, cab=Cab, nols=Po1)
    return GT