Пример #1
0
def getAgentOrder(a, nagents, orderedEdges):
    '''
    returns visits
    visits[i] = j means agent j should make edge i
    
    ALSO creates time attributes in a:
        
    Time that must be spent just walking
        a.walktime
    Time it takes to communicate completion of a sequence of links
        a.commtime
    Time spent navigating linking menu
        a.linktime
    '''
    geo = np.array([a.node[i]['geo'] for i in xrange(a.order())])
    d = geometry.sphereDist(geo, geo)
    # print d
    order = [e[0] for e in orderedEdges]

    # Reduce sequences of links made from same portal to single entry
    condensed, mult = condenseOrder(order)

    link2agent, times = orderedTSP.getVisits(d, condensed, nagents)
    # print

    # Expand links made from same portal to original count
    link2agent = expandOrder(link2agent, mult)

    # If agents communicate sequential completions all at once, we avoid waiting for multiple messages
    # To find out how many communications will be sent, we count the number of same-agent link sequences
    condensed, mult = condenseOrder(link2agent)
    numCOMMs = len(condensed)

    # Time that must be spent just walking
    a.walktime = times[-1] / WALKSPEED
    # Waiting for link completion messages to be sent
    a.commtime = numCOMMs * COMMTIME
    # Time spent navigating linking menu
    a.linktime = a.size() * LINKTIME

    movements = [None] * nagents

    for i in xrange(len(link2agent)):
        try:
            movements[link2agent[i]].append(i)
        except:
            movements[link2agent[i]] = [i]

    return movements
Пример #2
0
def getAgentOrder(a,nagents,orderedEdges):
    '''
    returns visits
    visits[i] = j means agent j should make edge i
    
    ALSO creates time attributes in a:
        
    Time that must be spent just walking
        a.walktime
    Time it takes to communicate completion of a sequence of links
        a.commtime
    Time spent navigating linking menu
        a.linktime
    '''
    geo = np.array([ a.node[i]['geo'] for i in xrange(a.order())])
    d = geometry.sphereDist(geo,geo)
    # print d
    order = [e[0] for e in orderedEdges]

    # Reduce sequences of links made from same portal to single entry
    condensed , mult = condenseOrder(order)

    link2agent , times = orderedTSP.getVisits(d,condensed,nagents)
    # print

    # Expand links made from same portal to original count
    link2agent = expandOrder(link2agent,mult)

    # If agents communicate sequential completions all at once, we avoid waiting for multiple messages
    # To find out how many communications will be sent, we count the number of same-agent link sequences
    condensed , mult = condenseOrder(link2agent)
    numCOMMs = len(condensed)

    # Time that must be spent just walking
    a.walktime = times[-1]/WALKSPEED
    # Waiting for link completion messages to be sent
    a.commtime = numCOMMs*COMMTIME
    # Time spent navigating linking menu
    a.linktime = a.size()*LINKTIME

    movements = [None]*nagents

    for i in xrange(len(link2agent)):
        try:    
            movements[link2agent[i]].append(i)
        except:
            movements[link2agent[i]] = [i]

    return movements
Пример #3
0
def getAgentOrder(a,nagents,orderedEdges):
    '''
    returns visits
    visits[i] = j means agent j should make edge i
    '''
    geo = np.array([ a.node[i]['geo'] for i in xrange(a.order())])
    d = geometry.sphereDist(geo,geo)
#    print d
    order = [e[0] for e in orderedEdges]
    link2agent , times = orderedTSP.getVisits(d,order,nagents)

    print 'Plan can be completed in time it takes one agent to walk',times[-1],'meters'

    movements = [None]*nagents

    # I realize that switching between these formats all the time is stupid
    # Consistency hasn't been my highest priority
    for i in xrange(len(link2agent)):
        try:    
            movements[link2agent[i]].append(i)
        except:
            movements[link2agent[i]] = [i]

    return movements