def getBestMTaxisByRange(analyzer, initDate, finalDate, M):
    dateslist = om.keys(analyzer['DateIndex'], initDate, finalDate)
    if lt.isEmpty(dateslist):
        return 0
    iterator = it.newIterator(dateslist)
    pointdic = {}
    while it.hasNext(iterator):
        date = it.next(iterator)
        dictaxis = me.getValue(om.get(analyzer["DateIndex"], date))
        for tid in dictaxis:
            if tid not in pointdic:
                pointdic[tid] = {
                    "miles": 0,
                    "total": 0,
                    "services": 0,
                    "points": 0
                }
            pointdic[tid]["miles"] += dictaxis[tid]["miles"]
            pointdic[tid]["total"] += dictaxis[tid]["total"]
            pointdic[tid]["services"] += dictaxis[tid]["services"]
            if pointdic[tid]["total"] != 0:
                pointdic[tid]["points"] = pointdic[tid]["miles"] * pointdic[
                    tid]["services"] / pointdic[tid]["total"]
    qeue = pq.newMinPQ(cmpfunction=compareDegreeMax)
    for taxi in pointdic:
        points = pointdic[taxi]["points"]
        pq.insert(qeue, {"id": taxi, "points": points})
    return qeue
def getMaxPointsinDateRange(tree, mindate, maxdate, num):
    taxiPoints = m.newMap(numelements=75000, comparefunction=compareTaxiId)
    taxiPointsPQ = pq.newMinPQ(comparePoints)
    dateRange = om.values(tree, mindate, maxdate)
    dateIterator = it.newIterator(dateRange)
    while it.hasNext(dateIterator):
        elem = it.next(dateIterator)
        taxiMap = elem['TaxiMap']
        taxiIterator = it.newIterator(m.keySet(taxiMap))
        while it.hasNext(taxiIterator):
            eleme = it.next(taxiIterator)
            if m.contains(taxiPoints, eleme):
                entry = me.getValue(m.get(taxiMap, eleme))
                add_points = entry['points']
                other_entry = me.getValue(m.get(taxiPoints, eleme))
                other_entry['points'] += add_points
            else:
                entry = me.getValue(m.get(taxiMap, eleme))
                add_points = entry['points']
                other_entry = {'taxi_id': eleme, 'points': add_points}
                m.put(taxiPoints, eleme, other_entry)
    keyPoints = m.keySet(taxiPoints)
    keyIterator = it.newIterator(keyPoints)
    while it.hasNext(keyIterator):
        el = it.next(keyIterator)
        points = me.getValue(m.get(taxiPoints, el))['points']
        pq.insert(taxiPointsPQ, (el, points))
    cont = 0
    taxiList = lt.newList()
    while cont < num:
        tax = pq.delMin(taxiPointsPQ)
        lt.addLast(taxiList, tax)
        cont += 1
    return taxiList
示例#3
0
def topN(theServices,N):
    valores=[]
    res={}
    i=0
    n=0
    keys= m.keySet(theServices)
    values=m.valueSet(theServices)
    itv=it.newIterator(values)
    itk=it.newIterator(keys)
    orden=mpq.newMinPQ(comparemaxpq)
    while it.hasNext(itv):
        value=it.next(itv)
        key= it.next(itk)
        if key!= "Independent Owner":
            mpq.insert(orden,value[1])

    while i<N:
        valor=mpq.min(orden)
        valores.append(valor)
        res[valor]=[]
        mpq.delMin(orden)
        i+=1

    itval=it.newIterator(values)
    itke=it.newIterator(keys)
    while it.hasNext(itval):
        val=it.next(itval)
        ke= it.next(itke)
        if ke!= "Independent Owner":
            for i in valores:
                if i==val[1]:
                    if ke not in res[i] and n<N:
                        res[i].append(ke)
                        n+=1
    return res
示例#4
0
def addAnchoQueue(catalog, point, ancho):
    if mp.contains(catalog["anchos_landing"], point):
        cola = me.getValue(mp.get(catalog["anchos_landing"], point))
        pq.insert(cola, ancho)
    else:
        cola = pq.newMinPQ(cmpfunction_minPQ)
        pq.insert(cola, ancho)
        mp.put(catalog["anchos_landing"], point, cola)
示例#5
0
def test_delete(minpq):
    minpq = pq.insert(minpq, 23)
    minpq = pq.insert(minpq, 7)
    minpq = pq.insert(minpq, 30)
    minpq = pq.insert(minpq, 5)
    minpq = pq.insert(minpq, 15)
    minpq = pq.insert(minpq, 1)
    key = pq.min(minpq)
    assert key == 1
    key = pq.delMin(minpq)
    assert key == 1
    key = pq.min(minpq)
    assert key == 5
    key = pq.delMin(minpq)
    assert key == 5
    key = pq.min(minpq)
    assert key == 7
    minpq = pq.insert(minpq, 4)
    minpq = pq.insert(minpq, 3)
    minpq = pq.insert(minpq, 2)
    key = pq.min(minpq)
    assert key == 2
    key = pq.delMin(minpq)
    assert key == 2
    key = pq.delMin(minpq)
    assert key == 3
    key = pq.delMin(minpq)
    assert key == 4
示例#6
0
def addTaxisServices (analyzer):
    iterator=it.newIterator(analyzer["companies"]["taxis"])
    while it.hasNext(iterator):
        company=it.next(iterator)
        mp.insert(analyzer["companies"]["total_taxis"],(lt.size(company["taxis_id"])*-1),company["company"])
        mp.insert(analyzer["companies"]["total_services"],(company["services"])*-1,company["company"])
        analyzer["NumTaxis"]+=lt.size(company["taxis_id"])
    for i in range(0,mp.size(analyzer["companies"]["total_taxis"])):
        analyzer["companies"]["diccio"]["top_taxis"].append(mp.delMin(analyzer["companies"]["total_taxis"]))
    for j in range (0,mp.size(analyzer["companies"]["total_services"])):
        analyzer["companies"]["diccio"]["top_services"].append(mp.delMin(analyzer["companies"]["total_services"]))
def getBestNTaxisByDate(analyzer, Date, N):
    """
    Para una fecha determinada, retorna el mejores N taxis.
    """
    qeue = pq.newMinPQ(cmpfunction=compareDegreeMax)
    Date = om.get(analyzer['DateIndex'], Date)
    try:
        if Date['key'] is not None:
            entry = me.getValue(Date)
            for taxi in entry:
                points = entry[taxi]["points"]
                pq.insert(qeue, {"id": taxi, "points": points})
            return qeue
    except:
        return 0
示例#8
0
def prueba2(hola):
    mx = min.newMinPQ(compareQuantity)
    for h in hola:
        x = min.insert(mx, h)
    mayor = min.min(mx)
    print(mx)
    return mayor
示例#9
0
def P_Q(analyzer): 
    
    TopS =  pq.newMinPQ(cmpfunction= comparefunction)
    TopT = pq.newMinPQ(cmpfunction= comparefunction)
    lstcompany = m.keySet(analyzer["Company"])
    iterator = it.newIterator(lstcompany)

    while it.hasNext(iterator):
        i = it.next(iterator)
        consulta = m.get(analyzer["Company"], i)['value']
        
        numtaxis = len(consulta["Taxis"])
        numservices = (consulta["Services"])

        taxisE = {"key": numtaxis, "company": i}
        servicesE = {"key": numservices, "company": i}
        
        pq.insert(TopT, taxisE)
        pq.insert(TopS, servicesE)

    return {"T_taxis": TopT, "T_services": TopS}
def PQmaker(analyzer):

    TopServices = pq.newMinPQ(cmpfunction=comparefunction)
    TopTaxis = pq.newMinPQ(cmpfunction=comparefunction)
    lstcompany = m.keySet(analyzer["Company"])
    iterator = it.newIterator(lstcompany)

    while it.hasNext(iterator):
        element = it.next(iterator)
        consulta = m.get(analyzer["Company"], element)['value']

        numtaxis = len(consulta["Taxis"])
        numservices = (consulta["Services"])

        taxisentry = {"key": numtaxis, "company": element}
        servicesentry = {"key": numservices, "company": element}

        pq.insert(TopTaxis, taxisentry)
        pq.insert(TopServices, servicesentry)

    return {"T_taxis": TopTaxis, "T_services": TopServices}
def stationsUsage(analyzer):
    indegreePQ = pq.newMinPQ(cmpfunction=compareDegreeMax)
    outdegreePQ = pq.newMinPQ(cmpfunction=compareDegreeMax)
    lessUsedPQ = pq.newMinPQ(cmpfunction=compareDegreeMin)
    vortexLst = gr.vertices(analyzer["graph"])
    ite = it.newIterator(vortexLst)

    while it.hasNext(ite):
        station = it.next(ite)
        StationName = getName(analyzer["stationinfo"], station)
        #Se obtienen los valores de las estaciones que entran, que salen y su suma

        indegree = gr.indegree(analyzer["graph"], station)
        outdegree = gr.outdegree2(analyzer["graph"], station)
        usage = outdegree + indegree
        #Se crean entradas para organizar en el PQ

        indegreeEntry = {"key": indegree, "station": StationName}
        outdegreeEntry = {"key": outdegree, "station": StationName}
        usageEntry = {"key": usage, "station": StationName}

        #Se inserta cada entrada en los PQ correspondientes
        pq.insert(indegreePQ, indegreeEntry)
        pq.insert(lessUsedPQ, usageEntry)
        pq.insert(outdegreePQ, outdegreeEntry)

    return {"In": indegreePQ, "Out": outdegreePQ, "Usage": lessUsedPQ}
def getMaxPointsinDate(tree, date, num):
    dateEntry = om.get(tree, date)
    if dateEntry is not None:
        minPQ = pq.newMinPQ(comparePoints)
        dateValue = me.getValue(dateEntry)
        taxiMap = dateValue['TaxiMap']
        taxiList = m.keySet(taxiMap)
        taxiIterator = it.newIterator(taxiList)
        while it.hasNext(taxiIterator):
            elem = it.next(taxiIterator)
            taxiValue = me.getValue(m.get(taxiMap, elem))
            taxipoints = taxiValue['points']
            pq.insert(minPQ, (elem, taxipoints))
        cont = 0
        taxis = lt.newList()
        while cont < num:
            taxi = pq.delMin(minPQ)
            lt.addLast(taxis, taxi)
            cont +=1
        return taxis
    else:
        return None
示例#13
0
def test_insert(minpq):
    minpq = pq.insert(minpq, 23)
    minpq = pq.insert(minpq, 7)
    minpq = pq.insert(minpq, 30)
    minpq = pq.insert(minpq, 5)
    minpq = pq.insert(minpq, 15)
    minpq = pq.insert(minpq, 1)
    key = pq.min(minpq)
    assert key == 1
def criticalStations(analyzer):
    vertexs = gr.vertices(analyzer["connections"])
    indegree = mq.newMinPQ(compareinverted)
    outdegree = mq.newMinPQ(compareinverted)
    degree = mq.newMinPQ(comparenormal)
    iterator = it.newIterator(vertexs)
    res1 = lt.newList()
    res2 = lt.newList()
    res3 = lt.newList()
    while it.hasNext(iterator):
        element = it.next(iterator)
        ins = (element,int(gr.indegree(analyzer["connections"],element)))
        out = (element,int(gr.outdegree(analyzer["connections"],element)))
        deg = (element,int(gr.indegree(analyzer["connections"],element))+int(gr.outdegree(analyzer["connections"],element)))
        mq.insert(indegree,ins)
        mq.insert(outdegree,out)
        mq.insert(degree,deg)

    for a in range(1,4):
        lt.addLast(res1,mq.delMin(indegree))
        lt.addLast(res2,mq.delMin(outdegree))
        lt.addLast(res3,mq.delMin(degree)) 
        
    return (res1,res2,res3)
示例#15
0
def Añadirservicios(lista):
    for cp in lista["Info"]:
        dato = (lista["Info"][cp]["servs"], cp)
        mpq.insert(lista["Servicios"], dato)
    return lista["Servicios"]
示例#16
0
def AñadirCompañias(lista):
    for cp in lista["Info"]:
        dato = (lista["Info"][cp]["taxis_num"], cp)
        mpq.insert(lista["Compañias"], dato)
    return lista["Compañias"]
示例#17
0
import config

from DISClib.ADT import minpq as pq
"""
Encontrar los 5 elementos mas pequeños de un lista
"""


def greater(key1, key2):
    if key1 == key2:
        return 0
    elif key1 < key2:
        return -1
    else:
        return 1


minpq = pq.newMinPQ(greater)

pq.insert(minpq, 5)
pq.insert(minpq, 23)
pq.insert(minpq, 31)
pq.insert(minpq, 15)

print(pq.delMin(minpq))
print(pq.delMin(minpq))
print(pq.delMin(minpq))
示例#18
0
"""


def greater(key1, key2):
    if key1['t'] == key2['t']:
        return 0
    elif key1['t'] < key2['t']:
        return -1
    else:
        return 1


cola_de_espera = queue.newQueue()

minpq = pq.newMinPQ(greater)
pq.insert(minpq, {'t': 0, 'evento': 'llegada'})
pq.insert(minpq, {'t': 5, 'evento': 'fin'})

iters = 0
while not pq.isEmpty(minpq) and iters < 100:
    p = pq.delMin(minpq)

    if p['evento'] == 'llegada':
        queue.enqueue(cola_de_espera, 1)
        pq.insert(minpq, {'t': p['t'] + 1, 'evento': 'llegada'})
        print('llegada')

    if p['evento'] == 'fin':
        break
    iters = iters + 1