Esempio n. 1
0
File: bmodel.py Progetto: kemas/ns3
def addnewnode(vertices, m_add):
    # add one node and connect it to m_add new links

    verlen = vertices.getlength()
    if m_add > verlen:
        m_add = verlen

    indexp = amodel.addnode(vertices)

    for i in range(m_add):
        indexq = choosenode(vertices)
        while indexp == indexq:
            indexq = choosenode(vertices)
        # connect these two if they are not connected
        if not vertices.is_connected(indexp, indexq):
            amodel.linknodes(vertices, indexp, indexq)
Esempio n. 2
0
File: bmodel.py Progetto: kemas/ns3
def addnewlinks(vertices, l_add):
    # add l_add new links between existing vertices
    # choose randomly l_add number of vertices
    # for each chosen vertex, connect to other vertex based on the probability function

    # choose l_add number of random vertices
    verlen = vertices.getlength()
    if l_add > verlen:
        l_add = verlen

    lsindex = random.sample(range(verlen), l_add)

    for indexp in lsindex:
        # choose another vertex to be connected to
        indexq = choosenode(vertices)
        while indexp == indexq:
            indexq = choosenode(vertices)
        # connect these two if they are not connected
        if not vertices.is_connected(indexp, indexq):
            amodel.linknodes(vertices, indexp, indexq)