def high_reliability_model(node_range, length_of_area, breadth_of_area): """Model that preserves reliability""" node_list = [] distances = [] node_id = 1 hex_along_l = calculate_p(length_of_area, node_range) hex_along_b = calculate_o(breadth_of_area, node_range) lattice = hexagonal_lattice_graph(hex_along_b, hex_along_l) x, y = generate_hex_mesh(lattice, node_range) centre_x, centre_y = generate_centers(x, y, node_range) for i in range(len(centre_x)): distances.append( distance(length_of_area / 2, breadth_of_area / 2, centre_x[i], centre_y[i])) k = distances.index(min(distances)) for i in range(len(x)): node_list.append(Node(node_id, x[i], y[i], node_range)) node_id += 1 for i in range(len(centre_x)): node_list.append(Node(node_id, centre_x[i], centre_y[i], node_range)) node_id += 1 node_list.append(BaseStation(0, centre_x[k], centre_y[k], node_range)) return node_list
def define(self): """Define a network. Returns a node_list.""" if self.model is None: self.number_of_nodes = len(self.node_id) for i in range(self.number_of_nodes): self.node_list.append( Node(self.node_id[i], self.x[i], self.y[i], self.node_properties[1])) # Appending the nodes to the list elif self.model == "low latency model": self.node_list = low_latency_model( self.node_properties[1], self.length_of_area, self.breadth_of_area, ) for node in self.node_list: node.type = self.node_properties[0] elif self.model == "high lifetime model": # l, b are length and breadth. self.node_list = high_lifetime_model(self.node_properties[1], self.length_of_area, self.breadth_of_area) elif self.model == "high reliability model": # l, b are length and breadth. self.node_list = high_reliability_model(self.node_properties[1], self.length_of_area, self.breadth_of_area) return self.node_list
def high_lifetime_model(node_range, length_of_area, breadth_of_area): """Model that optimises lifetime.""" node_list = [] distances = [] node_id = 1 hex_along_l = calculate_p(length_of_area, node_range) hex_along_b = calculate_o(breadth_of_area, node_range) lattice = hexagonal_lattice_graph(hex_along_b, hex_along_l) x, y = generate_hex_mesh(lattice, node_range) centre_x, centre_y = generate_centers(x, y, node_range) for i in range(len(centre_x)): distances.append( distance(length_of_area / 2, breadth_of_area / 2, centre_x[i], centre_y[i])) k = distances.index(min(distances)) inner_x, inner_y = draw_ring(centre_x[k], centre_y[k], node_range) for i in range(len(x)): node_list.append(Node(node_id, x[i], y[i], node_range)) node_id += 1 for i in range(len(inner_x)): node_list.append(Node(node_id, inner_x[i], inner_y[i], node_range)) node_id += 1 node_list.append(BaseStation(0, centre_x[k], centre_y[k], node_range)) actual_node_list = [] for node in node_list: ct = 1 k = node_list.index(node) for j in node_list[k + 1::]: # if node_list[i].x == node_list[j].x == node_list[i].y == node_list[j].y: if node.x == j.x and node.y == j.y: ct += 1 if ct == 1: actual_node_list.append(node) # print(len(actual_node_list), 'HEEHEHE') # print(len(node_list), 'LOLO') return actual_node_list
def low_latency_model(node_range, length_of_area, breadth_of_area): """Model for relatively low latency. Placing nodes such that the number of jumps are the least at a moderate cost. """ node_list = [] node_id = 1 initial_value = node_range / np.sqrt(2) # - 5 num_nodes_along_length = int(length_of_area / initial_value) num_nodes_along_breadth = int(breadth_of_area / initial_value) for i in range(num_nodes_along_length + 1): # + 1 for j in range(num_nodes_along_breadth + 1): # + 1 node_list.append( Node(node_id, i * initial_value, j * initial_value, node_range)) node_id += 1 # Making a sink distances = [] for node in (node_list): distances.append( distance(length_of_area / 2, breadth_of_area / 2, node.x, node.y)) k = distances.index(min(distances)) sink = BaseStation(0, node_list[k].x, node_list[k].y, node_range) node_list.append(sink) actual_node_list = [] for node in node_list: ct = 1 k = node_list.index(node) for j in node_list[k + 1::]: # if node_list[i].x == node_list[j].x == node_list[i].y == node_list[j].y: if node.x == j.x and node.y == j.y: ct += 1 if ct == 1: actual_node_list.append(node) node_id = 1 for node in actual_node_list[:-1:]: node.id = node_id node_id += 1 return actual_node_list
def low_latency_model(node_range, length_of_area, breadth_of_area): """Model for relatively low latency. Placing nodes such that the number of jumps are the least at a moderate cost. """ node_list = [] node_id = 1 initial_value = node_range / np.sqrt(2) num_nodes_along_length = int(length_of_area / initial_value) num_nodes_along_breadth = int(breadth_of_area / initial_value) for i in range(num_nodes_along_length + 1): # + 1 for j in range(num_nodes_along_breadth + 1): # + 1 node_list.append( Node(node_id, i * initial_value, j * initial_value, node_range)) node_id += 1 # Making a sink sink = BaseStation(0, node_list[28].x, node_list[28].y, node_range) node_list.append(sink) return node_list
def high_reliability_model(node_range, length_of_area, breadth_of_area): """Model that preserves reliability""" node_list = [] distances = [] node_id = 1 hex_along_l = calculate_p(length_of_area, node_range) hex_along_b = calculate_o(breadth_of_area, node_range) lattice = hexagonal_lattice_graph(hex_along_b, hex_along_l) x, y = generate_hex_mesh(lattice, node_range) centre_x, centre_y = generate_centers(x, y, node_range) for i in range(len(centre_x)): distances.append( distance(length_of_area / 2, breadth_of_area / 2, centre_x[i], centre_y[i])) try: k = distances.index(min(distances)) for i in range(len(x)): node_list.append(Node(node_id, x[i], y[i], node_range)) node_id += 1 for i in range(len(centre_x)): node_list.append( Node(node_id, centre_x[i], centre_y[i], node_range)) node_id += 1 node_list.append(BaseStation(0, centre_x[k], centre_y[k], node_range)) except Exception as e: print( "Not enough area for a Wireless Sensor Network with available motes" ) sys.exit() actual_node_list = [] for node in node_list: ct = 1 k = node_list.index(node) for j in node_list[k + 1::]: # if node_list[i].x == node_list[j].x == node_list[i].y == node_list[j].y: if node.x == j.x and node.y == j.y: ct += 1 if ct == 1: actual_node_list.append(node) node_id = 1 for node in actual_node_list[:-1:]: node.id = node_id node_id += 1 # print(len(actual_node_list), 'HEEHEHE') # print(len(node_list), 'LOLO') popping_out = [] for node in actual_node_list[:-1:]: if node.x > breadth_of_area or node.x < 0 or node.y < 0 or node.y > length_of_area: popping_out.append(node) for node in popping_out: actual_node_list.remove(node) return actual_node_list