Exemplo n.º 1
0
 def get_MWOE(self):
     msg = Message()
     msg = msg.get_MWOE()
     for edge in self.mst_edges:
         if edge == self.parent_edge
             continue
         edge.send_message(self.process_id, msg)
     recieved_mwoe_msgs = []
     while len(recieved_mwoe_edges) != len(self.mst_edges) - 1:
         for edge in self.mst_edges:
             status, msg = edge.receive_message(self.process_id)
             if not status:
                 continue
             recieved_mwoe_msgs.append(msg)
         time.sleep(0.5)
     min_edge_id = None
     min_weight = 1000000
     min_process_id = None
     for msg in recieved_mwoe_msgs:
         if msg.msg < min_weight:
             min_weight = msg.msg
             min_edge_id = msg.edge_id
             min_process_id = msg.process_id
     for edge in self.non_mst_edges:
         if edge.get_weight() < min_weight:
             min_weight = edge.get_weight()
             min_edge_id = edge_id
             min_process_id = self.process_id
     ret_msg = Message()
     ret_msg = ret_msg.send_MWOE(min_weight, min_edge_id, self.process_id)
     return ret_msg
Exemplo n.º 2
0
 def get_min_edge(self):
     """This function returns the minimum edge of all the incident edges."""
     min_edge = None
     min_weight = 1000000
     for edge in self.non_mst_edges:
         if edge.get_weight() <= min_weight:
             min_weight = edge.get_weight()
             min_edge = edge
     return edge
Exemplo n.º 3
0
 def find_MWOE(self):
     """This function finds the MWOE of all the edges."""
     if self.level == 0 or (len(self.mst_edges) -1) == 0 and \
             self.parent_edge is None) or len(self.mst_edges) == 0:
         edge = self.get_min_edge()
         ret_msg = Message()
         ret_msg = ret_msg.send_MWOE(edge.get_weight(), edge.id, self.process_id)
         return ret_msg