def con(location_file, file_path,limit=10):
    result = readLocationFile(location_file)
    #print result
    result = connected(result, connection_limit=limit)
    #print result
    generate_network_file(result, file_path, minus_one=False)
    network = Network()
    network.read(file_path)
    network.dot_gen(file_path + ".dot")
def generate(trees, result_dir, connection_rate):
    files = glob.glob(trees + os.sep + "tree_*.txt")
    for f in files:
        print f + "%5.1f" % connection_rate
        file_name = os.path.basename(f)
        mesh_name = file_name.replace("tree","mesh")
        mesh_file_name = mesh_name # '_'.join(split_names)
        mesh_file_path = os.path.join(result_dir, mesh_file_name)
        t = Network(f)
        h = TreeGen.tree_to_mesh(t.network, connection_rate)
        #print h
        a = Network(h)
        a.write(mesh_file_path)
        a.dot_gen(mesh_file_path + ".dot")
def reduce_average_network_link(network, new_network_path, goal):
    network = Network(network).get_network()
    new_network = copy.copy(network)

    for key, neighbors in network.items():
        if len(neighbors) > goal:
            new_neighbors = sorted(neighbors, key=lambda e: random.random())
            new_neighbors = new_neighbors[0:goal]
            diff = set(neighbors) - set(new_neighbors)
            for d in diff:
                if len(new_network[d]) == 1: # if this is the only link, don't do anything
                    new_neighbors.append(d)
                else:
                    print "remove key(%d) from n(%s)" % (key, new_network[d])
                    new_network[d].remove(key)
                    print "removed key(%d) from n(%s)" % (key, new_network[d])
            new_network[key] = new_neighbors

    print new_network
    #new_network = Network.make_symmetric_network(self, new_network)
    n2 = Network(new_network)
    n2.write(new_network_path)
    n2.dot_gen(new_network_path + ".dot")
def generate_dot(network_file_path):
    network = Network(network_file_path)
    dot_file_path = network_file_path + ".dot"
    network.dot_gen(dot_file_path)
 def test_dot_gen(self):
     network = Network()
     network.read(network_file_path)
     network.dot_gen(dot_file_path)