Exemplo n.º 1
0
def compute_flow_throughputs(ports):
    # Function for walking path to assign a flow

    # Build the port priority queue
    portpq = priority_dict()
    for port in ports:
        portpq[port] = port.flow_rate()

    # Iterate the priority queue
    while len(portpq) > 0:
        updated_ports = set()
        port = portpq.pop_smallest()

        # Get the rate and quit continue if it is 0.0
        rate = port.flow_rate()
        if rate is 0:
            continue
        
        # Assign the flow rate to all of the flows on this port.
        # Also update the affected ports by this assignment
        for flow in port.flows.copy():
            flow.rate = rate
            for fp in flow.ports:
                fp.used += rate
                assert(fp.used <= 1.01)
                fp.flows.remove(flow)
                updated_ports.add(fp)
        assert(len(port.flows) is 0)
        #print port.used
        assert(port.used >= 0.99 and port.used <= 1.01)

        for up in updated_ports:
            portpq[up] = up.flow_rate()
def search(beginning, goal):
  global path, goal_stop
  goal_stop = goal
  node_list = priority_dict()
  node_list[beginning[0]] = beginning[1]
  while len(node_list) > 0:
    print"Solmulista: " + ", ".join([str((k, v)) for k,v in node_list.items()])
    node = node_list.smallest()
    time = node_list[node]
    path.append((node.name, time))
    print "Solmu: " + node.name + ", " + str(time)
    node_list.pop_smallest()
    if node.name == goal_stop.name:
      return("Ratkaisu: ", node)
    node_list = _add_a_star(neighbors(node, time), node_list)
  print "Path: " + str(path)
  return ("Ei ratkaisua", node)
Exemplo n.º 3
0
        embeddings_dictionary[noun] = numpy_embeddings
        #print 'yes'
    #else:
    #    print 'not:',noun
    #   sys.exit()

#sys.exit()
k = int(sys.argv[3])

#print 'size embeddings dictionary',len(embeddings_dictionary)
#raw_input()
#first create the heap dictionary 

all_pair_distances = {}
for word in embeddings_dictionary:
    distances = {}
    for i in embeddings_dictionary:
        #print 'word i',i
        if i == word:
            continue
        distances[i] = numpy.square(embeddings_dictionary[word]-embeddings_dictionary[i]).sum()
        #print distances[i]
    #print 'distances',len(distances)
    distances_heap = priority_dict(distances)

    for i in range(k):
        p_argmin,p_min = distances_heap.pop_smallest()
        #print word,',',p_argmin,',',p_min
        print "_%s_,_%s_,%s"%(word,p_argmin,repr(p_min))