def __init__(self, simulation_parameters): """ Constructor. simulation_parameters - The parameters to be used to run this simulation """ self.type_of_nodes = simulation_parameters.config_p['type_of_nodes'] self._max_cycles = simulation_parameters.config_p['max_cycles'] self.number_messages_out = 0 self.number_messages_in = 0 self.number_asynchronous_events = 0 self.number_simulation_events = 0 self.all_nodes = {} self.time = 0 self.protocol_manager = \ simulation_parameters.config_p['protocol_manager'](protocol_arguments=simulation_parameters.protocol_p) self.event_broker = EventBroker() self.message_broker = MessageBroker() node_parameters = simulation_parameters.node_p type_of_nodes = simulation_parameters.config_p['type_of_nodes'] events_to_launch = simulation_parameters.config_p['events'] # If the simulator is generating the plane if not 'scenario_file' in simulation_parameters.plane_p: generated_nodes = Node.generate_nodes(number_to_generate=simulation_parameters.plane_p['number_of_nodes'], \ type_of_nodes=type_of_nodes, node_parameters=node_parameters, \ protocol_manager=self.protocol_manager) for node in generated_nodes: self.all_nodes[node.id] = node self.plane = Plane.generate_plane(all_nodes=self.all_nodes, plane_parameters=simulation_parameters.plane_p) # If the simulator is loading the plane from a file else: (self.all_nodes, self.plane) = Plane.load_plane(plane_parameters=simulation_parameters.plane_p, \ node_parameters=simulation_parameters.node_p, \ type_of_nodes=self.type_of_nodes, \ protocol_manager=self.protocol_manager) #Now putt the events to launch in the event broker for event in events_to_launch: self.event_broker.add_asynchronous_event(event)
def test_bfg_draw_heat_map(self): all_nodes = {} # make all the nodes for i in xrange(50): node_a = BfgNode(node_id=str(i), protocol_manager=self.protocol_manager) all_nodes[str(i)] = node_a # make the plane import plane_builders from simulator import PlaneParameters plane_p = PlaneParameters(x_size = 10, y_size = 10, min_degree=1, max_degree=8, plane_builder_method=plane_builders.degree_plane_builder) plane = Plane.generate_plane(all_nodes=all_nodes, plane_parameters=plane_p) #make the protocol manager bfg_protocol = BfgProtocolManager({'origin_ids':["1", "2"], 'destiny_ids':["3"]}) #Make heat spread #TODO #Draw the map bfg_protocol.draw_heat_map("Final Heat", all_nodes, plane, '3')