def isFeasable(self, ride, carLocation, currentTime): dist_to = Location.distance(carLocation, ride.start_location) dist_ride = Location.distance(ride.start_location, ride.finish_location) if (dist_to + dist_ride + currentTime <= ride.finish_time): return True else: return False
def log(self): if LOG_ENABLED: print('---------- LOG from Node {} ----------'.format(self.id)) print('\t Location {},{}'.format(self.location.x, self.location.y)) print('\t Distance from gateway {}'.format( Location.distance(self.location, self.base_station.location))) print('\t LoRa Param {}'.format(self.lora_param)) print('\t ADR {}'.format(self.adr)) print('\t Payload size {}'.format(self.payload_size)) print('\t Energy spend transmitting {0:.2f}'.format( self.energy_tracking[NodeState(NodeState.TX).name])) print('\t Energy spend receiving {0:.2f}'.format( self.energy_tracking[NodeState(NodeState.RX).name])) print('\t Energy spend sleeping {0:.2f}'.format( self.energy_tracking[NodeState(NodeState.SLEEP).name])) print('\t Energy spend processing {0:.2f}'.format( self.energy_tracking[NodeState(NodeState.PROCESS).name])) for lora_param, t in self.change_lora_param.items(): print('\t {}:{}'.format(lora_param, t)) print('Bytes sent by node {}'.format(self.bytes_sent)) print('Total Packets sent by node {}'.format(self.packets_sent)) print( 'Total Packets sent by node (according to tx state changes) {}' .format(self.num_tx_state_changes)) print('Unique Packets sent by node {}'.format( self.num_unique_packets_sent)) print('Retransmissions {}'.format(self.num_retransmission)) print('Packets collided {}'.format(self.num_collided)) print('-------------------------------------')
def packet_in_air(self, packet: UplinkMessage): self.num_of_packets_send += 1 # id = packet.node.id # if id not in self.color_per_node: # self.color_per_node[id] = '#' + random.choice(AirInterface.color_values) + random.choice( # AirInterface.color_values) + random.choice(AirInterface.color_values) + random.choice( # AirInterface.color_values) + random.choice(AirInterface.color_values) + random.choice( # AirInterface.color_values) from_node = packet.node node_id = from_node.id rss = self.prop_model.tp_to_rss( from_node.location.indoor, packet.lora_param.tp, Location.distance(self.gateway.location, packet.node.location)) if node_id not in self.prop_measurements: self.prop_measurements[node_id] = { 'rss': [], 'snr': [], 'time': [] } packet.rss = rss snr = self.snr_model.rss_to_snr(rss) packet.snr = snr #print('Gateway location: ({}, {})'.format(self.gateway.location.x, self.gateway.location.y)) #print('Node {} location: ({}, {} ->{})'.format(packet.node.id, packet.node.location.x, packet.node.location.y, Location.distance(self.gateway.location, packet.node.location))) #print('RSS: {} SNR: {}'.format(rss, snr)) self.prop_measurements[node_id]['time'].append(self.env.now) self.prop_measurements[node_id]['rss'].append(rss) self.prop_measurements[node_id]['snr'].append(snr) self.packages_in_air.append(packet) gc.disable()
class Car: def __init__(self, id): self.rides = list() self.id = id self.timeAvailable = 0 self.currentLocation = Location(0, 0) def addNewRide(self, ride): self.rides.append(ride) self.timeAvailable += self.currentLocation.distance( ride.start_location) if (self.timeAvailable < ride.start_time): self.timeAvailable = ride.start_time self.timeAvailable += ride.start_location.distance( ride.finish_location) self.currentLocation = ride.finish_location def output(self): output = "" for ride in self.rides: output += str(ride.id) output += " " if output != "": output = output[:-1] return str(len(self.rides)) + " " + output def __str__(self): return str(self.id)
def packet_in_air(self, packet: UplinkMessage): self.num_of_packets_send += 1 # id = packet.node.id # if id not in self.color_per_node: # self.color_per_node[id] = '#' + random.choice(AirInterface.color_values) + random.choice( # AirInterface.color_values) + random.choice(AirInterface.color_values) + random.choice( # AirInterface.color_values) + random.choice(AirInterface.color_values) + random.choice( # AirInterface.color_values) from_node = packet.node node_id = from_node.id rss = self.prop_model.tp_to_rss( from_node.location.indoor, packet.lora_param.tp, Location.distance(self.gateway.location, packet.node.location)) if node_id not in self.prop_measurements: self.prop_measurements[node_id] = { 'rss': [], 'snr': [], 'time': [] } packet.rss = rss snr = self.snr_model.rss_to_snr(rss) packet.snr = snr self.prop_measurements[node_id]['time'].append(self.env.now) self.prop_measurements[node_id]['rss'].append(rss) self.prop_measurements[node_id]['snr'].append(snr) self.packages_in_air.append(packet) gc.collect()
def packet_in_air(self, packet: UplinkMessage): self.num_of_packets_send += 1 # id = packet.node.id # if id not in self.color_per_node: # self.color_per_node[id] = '#' + random.choice(AirInterface.color_values) + random.choice( # AirInterface.color_values) + random.choice(AirInterface.color_values) + random.choice( # AirInterface.color_values) + random.choice(AirInterface.color_values) + random.choice( # AirInterface.color_values) from_node = packet.node node_id = from_node.id # Calculate RSSI and SNR from node to each gateway for gw in self.gateways: d = Location.distance(gw.location, from_node.location) rss = self.prop_model.tp_to_rss(from_node.location.indoor, packet.lora_param.tp, d) if node_id not in self.prop_measurements: self.prop_measurements[node_id] = {} if gw.id not in self.prop_measurements[node_id]: self.prop_measurements[node_id][gw.id] = { 'rss': [], 'snr': [], 'time': [] } packet.rss[gw.id] = rss snr = self.snr_model.rss_to_snr(rss) packet.snr[gw.id] = snr packet.collided[ gw. id] = False # collisions are checked later, once the packet is already in the air self.prop_measurements[node_id][gw.id]['time'].append(self.env.now) self.prop_measurements[node_id][gw.id]['rss'].append(rss) self.prop_measurements[node_id][gw.id]['snr'].append(snr) self.packages_in_air.append(packet) gc.collect()