4 from networkx.algorithms 
import bipartite
 
    9     """The broker decides which vertices in the matching  
   10     graph are to be shared between the robots. 
   14         """Initialize the broker 
   17             edges (list(EdgeInterRobot)): _description_ 
   18             robots_involved (list(int)): Robot ids of the  
   19                                 robots involved in the exchange 
   22         robots_involved_with_edges = set()
 
   23         for e 
in self.
edgesedges:
 
   24             if e.robot0_id 
in robots_involved:
 
   25                 robots_involved_with_edges.add(e.robot0_id)
 
   26             if e.robot1_id 
in robots_involved:
 
   27                 robots_involved_with_edges.add(e.robot1_id)
 
   28         robots_involved_with_edges = list(robots_involved_with_edges)
 
   32             if len(robots_involved_with_edges) == 2:
 
   34             elif len(robots_involved_with_edges) > 2:
 
   38                     "Broker: The communication brokerage needs to be between at least 2 robots" 
   43             for e 
in self.
edgesedges:
 
   44                 edge_vertices = [(e.robot0_id, e.robot0_keyframe_id),
 
   45                                  (e.robot1_id, e.robot1_keyframe_id)]
 
   47                 for vertex 
in edge_vertices:
 
   50                             if vertex[0] == robots_involved_with_edges[0]:
 
   53                             elif vertex[0] == robots_involved_with_edges[1]:
 
   57                             if vertex[0] 
in robots_involved_with_edges:
 
   61                         0] 
in robots_involved_with_edges 
and edge_vertices[1][
 
   62                             0] 
in robots_involved_with_edges:
 
   67         """Return the broker selection of vertices to send. 
   68         Either using vertex cover or simple dialog strategy. 
   71             use_vertex_cover (bool): use vertex cover stratehy 
   74             List(set((int,int)): Vertices to be transmitted 
   85         """Computes the minimum vertex cover over the edges 
   86         If the graph is bipartite: we compute the maximum matching and 
   87          recover the minimum vertex cover with Konig's theorem 
   89         Otherwise, we use an approximate greedy algorithm. 
   92             List(set((int,int)): Vertices to be transmitted 
   96         matching_subgraphs = [
 
   98             for c 
in nx.connected_components(self.
matching_graphmatching_graph)
 
  101         for graph 
in matching_subgraphs:
 
  103                 matching = nx.bipartite.maximum_matching(graph)
 
  104                 vertex_covers.append(
 
  105                     nx.bipartite.to_vertex_cover(graph, matching))
 
  107                 vertex_covers.append(
 
  108                     nx.algorithms.approximation.vertex_cover.
 
  109                     min_weighted_vertex_cover(graph))
 
  113         """Simple dialog exchange 
  114         For each edge, transmit one of the two vertices randomly 
  115         unless one of the 2 vertices is already transmitted. 
  118             List(set((int,int)): Vertices to be transmitted 
  120         vertices_dialog = set()
 
  121         for e 
in self.
edgesedges:
 
  122             edge_vertices = [(e.robot0_id, e.robot0_keyframe_id),
 
  123                              (e.robot1_id, e.robot1_keyframe_id)]
 
  124             if edge_vertices[0] 
not in vertices_dialog 
and edge_vertices[
 
  125                     1] 
not in vertices_dialog:
 
  126                 rand_idx = np.random.randint(2)
 
  127                 vertices_dialog.add(edge_vertices[rand_idx])
 
  129         return [vertices_dialog]
 
def __init__(self, edges, robots_involved)
 
def brokerage(self, use_vertex_cover)