示例#1
0
def init_geometric(num_drones):
    r = 250
    list_drones = list()
    for i in xrange(num_drones):
        if i == 0:
            list_drones.append(
                global_variables.Drone(i, random.uniform(0, 1000),
                                       random.uniform(0, 1000)))
        else:
            drone = random.randint(0, len(list_drones) - 1)
            if random.randint(0, 10) > 5:  #flip a coin
                x = list_drones[drone].node_x + random.uniform(0, r)  # add
                if x > 1000:
                    x = 1000
            else:
                x = list_drones[drone].node_x - random.uniform(0,
                                                               r)  # substract
                if x < 0:
                    x = 0
            aux = x - list_drones[drone].node_x
            delta_y = math.sqrt((r * r) - (aux * aux))
            if random.randint(0, 10) > 5:
                y = list_drones[drone].node_y + random.uniform(0, delta_y)
                if y > 1000:
                    y = 1000
            else:
                y = list_drones[drone].node_y - random.uniform(0, delta_y)
                if y < 0:
                    y = 0
            list_drones.append(global_variables.Drone(i, x, y))
    return list_drones
示例#2
0
def init_modified(list_drones_genetic, num_drones):
    """ this function is used if different number of drones is used during the initial deployment
    and the adaptation to the real conditions"""

    accomplished = 0
    global total
    while accomplished == 0:
        list_drones = list()
        for j in list_drones_genetic:
            x = j.node_x
            y = j.node_y
            list_drones.append(global_variables.Drone(total, x, y))

        for i in range(len(list_drones_genetic), num_drones):
            x_cor = random.random() * 1000
            y_cor = random.random() * 1000
            list_drones.append(global_variables.Drone(total, x_cor, y_cor))
        if check_drones_conectivity(list_drones) < 0:
            accomplished = 0
        else:
            accomplished = 1
            total = total + 1
            print "we got one, total number %d" % total

    return list_drones
示例#3
0
def copy_drones_positions():
	""" copies drones positions from the file to be used in local optimization"""
	list_drones = []
	x = open("x_drones_positions.txt",'r')
	y = open("y_drones_positions.txt", 'r')
	ident = 0
	for i, j in zip(x, y):
		list_drones.append(global_variables.Drone(ident,float(i),float(j)))
		ident = ident + 1
	return list_drones
示例#4
0
def init(num_drones):
    accomplished = 0
    global total
    while accomplished == 0:
        list_drones = list()
        for i in range(0, num_drones):
            x_cor = random.random() * 1000
            y_cor = random.random() * 1000
            list_drones.append(global_variables.Drone(i, x_cor, y_cor))
        if check_drones_conectivity(list_drones) < 0:
            accomplished = 0
        else:
            accomplished = 1
            total = total + 1
            print "we got one, total number %d" % total
    return list_drones
示例#5
0
def initPredefIndiv(icls, input_file):
	## deterministic, uavs coordinates given as argument
	f = open(input_file, 'r')
	tmp=[line[:-1] for line in f ]
	uavs_list=[[float(j) for j in ele.split(",")] for ele in tmp ]
	f.close()
	list_drones =  list()
	i=0
	for a_uav in uavs_list :
		x_cor = a_uav[0]
		y_cor = a_uav[1]
		##print(i, " reading indiv content ", x_cor, " and ",y_cor)
		list_drones.append(global_variables.Drone(i,x_cor,y_cor))
		i=i+1
	if check_drones_conectivity(list_drones) < 0:
		print("It's terrible, this individual is not connected, and that it not supposed to happen")
	return icls(list_drones)
示例#6
0
def init_grid(num_drones):
    list_x = list()
    list_y = list()
    accomplished = 0
    global total
    for i in range(0, 1100, 150):
        list_x.append(i)
        list_y.append(i)
    while accomplished == 0:
        list_drones = []
        for i in range(0, num_drones):
            ind_x = random.randint(0, len(list_x) - 1)
            ind_y = random.randint(0, len(list_y) - 1)
            x_cor = list_x[ind_x]
            y_cor = list_y[ind_y]
            list_drones.append(global_variables.Drone(total, x_cor, y_cor))
        if check_drones_conectivity(list_drones) < 0:
            accomplished = 0
        else:
            accomplished = 1
            total = total + 1
            print "we got one, total number %d" % total
    return list_drones
示例#7
0
def positions_from_file(fil, num, k, nodes, UAVs, fig):
    """ It plots the solution"""
    #global list_victim
    #global list_partial_victims
    f = open(fil, 'r')
    scenarios.generate_victim_positions_traces()
    scenarios.partial_knowledge_generation(k)
    #print list_victims

    list_drones = list()
    for line in f:
        fields = line.split(",")
        list_drones.append(
            global_variables.Drone(int(fields[0]), float(fields[1]),
                                   float(fields[2])))

    for i in list_drones:
        print(i.id, i.node_x, i.node_y)

    #CO= quality.evaluate_coverage(list_drones)
    #G= quality.create_drones_graph(list_drones)
    #print quality.check_graph_connectivity(G)
    #for i in list_drones:
    #	print i.neighbordrones

    #F= quality.evaluate_weighted(list_drones)
    CO = quality.evaluate_coverage(list_drones)
    print("coverage", CO)
    #FTO= quality.evaluate_tolerance(list_drones)
    #print FTO
    #RO= quality.evaluate_redundancy(list_drones)
    #print "redundancy", RO

    ground_x = list()  # victims' positions
    ground_y = list()

    ground_x_covered = list()  # victims' positions
    ground_y_covered = list()

    UAV_x = list()  # drones' positions
    UAV_y = list()

    UAV_ground_x = list()  # links among drones and victims
    UAV_ground_y = list()

    UAV_UAV_x = list()  # links among drones
    UAV_UAV_y = list()

    for i in global_variables.list_partial_victims:
        ground_x.append(i.node_x)
        ground_y.append(i.node_y)

    for j in list_drones:
        UAV_x.append(j.node_x)
        UAV_y.append(j.node_y)

    #print UAV_x, UAV_y
    #print ground_x, ground_y
    UAV_ground_x, UAV_ground_y, ground_x_covered, ground_y_covered = plot_links(
        list_drones, 1)
    UAV_UAV_x, UAV_UAV_y = plot_links_drones(list_drones)
    #print UAV_ground_x

    # plotting drones connectivity
    #fig = plt.figure(figsize= (10,20), dpi = 300)
    ax1 = fig.add_subplot(4, 2, num)
    #s1= ax1.scatter(ground_x, ground_y, c = 'y', label = "ground_nodes", marker = 'o')
    s1 = ax1.scatter(UAV_x, UAV_y, c='r', label="UAV", marker='x')
    for i in range(0, len(UAV_UAV_x)):
        if i % 2 == 0:
            x1 = UAV_UAV_x[i]
            x11 = UAV_UAV_x[i + 1]
            y1 = UAV_UAV_y[i]
            y11 = UAV_UAV_y[i + 1]
            ax1.plot([x1, x11], [y1, y11],
                     'r--',
                     label="UAV-UAV links",
                     marker='_')
    ax1.set_xlabel("X [m]", fontsize=11)
    ax1.set_ylabel("Y [m]", fontsize=11)
    ax1.axis([-50, 1050, -50, 1050])
    ax1.set_title(UAVs, fontsize=12)
    ax1.grid("on")

    ax2 = fig.add_subplot(4, 2, num + 1)
    s2 = ax2.scatter(ground_x,
                     ground_y,
                     c='c',
                     label="ground_nodes",
                     marker='x')
    s3 = ax2.scatter(ground_x_covered,
                     ground_y_covered,
                     c='m',
                     label="ground_nodes",
                     marker='x')
    ax2.scatter(UAV_x, UAV_y, c='r', label="UAV", marker='x')
    for i in range(0, len(UAV_ground_x)):
        if i % 2 == 0:
            x1 = UAV_ground_x[i]
            x11 = UAV_ground_x[i + 1]
            y1 = UAV_ground_y[i]
            y11 = UAV_ground_y[i + 1]
            ax2.plot([x1, x11], [y1, y11],
                     'g--',
                     label="UAV-ground links",
                     marker='_')
    ax2.set_xlabel("X [m]", fontsize=11)
    ax2.set_ylabel("Y [m]", fontsize=11)
    ax2.axis([-50, 1050, -50, 1050])
    ax2.set_title(nodes, fontsize=12)
    ax2.grid("on")
    #l = ["unknown victims", "known victims", "drones"]
    #c = ['b', 'k', 'r', 'y', 'g', 'r']
    #m = ['o', 'o', 'o', '_', '_', '_']
    UAV_links = mlines.Line2D([], [],
                              color='red',
                              linestyle='--',
                              label='Blue stars')
    GN_links = mlines.Line2D([], [],
                             color='green',
                             linestyle='--',
                             label='Blue stars')
    if num == 1:
        fig.legend(handles=[s1, s2, s3, UAV_links, GN_links],
                   labels=['UAV', 'GN', 'Cov-GN', 'UAV-links', 'GN-links'],
                   loc='upper center')
    #fig.legend(handles=[s1, s2, s3, s4, s5, s6], ('UAV', 'GN','Cov-GN','UAV-links', 'GN-GN.links'), loc= 'upper right')
    fig.savefig("Positions.png")