6 from test_algebraic_connectivity
import build_multi_robot_graph
11 from collections
import namedtuple
16 robot_id, nb_candidates_to_choose):
17 """Build a graph and perform selection based on algebraic connectivity
20 nb_poses, nb_candidate_edges, max_nb_robots)
23 params[
'robot_id'] = robot_id
24 params[
'max_nb_robots'] = max_nb_robots
25 params[
'frontend.similarity_threshold'] = 0.0
26 params[
'frontend.sensor_type'] =
'stereo'
27 params[
"frontend.enable_sparsification"] =
True
28 params[
"evaluation.enable_sparsification_comparison"] =
False
30 lcsm.candidate_selector.set_graph(fixed_edges_list, candidate_edges_list)
33 is_robot_considered = {}
34 for i
in range(max_nb_robots):
35 is_robot_considered[i] =
True
36 return lcsm.select_candidates(nb_candidates_to_choose,
38 greedy_initialization=
False)
41 def verif_broker(unittest_framework, nb_poses, nb_candidate_edges, max_nb_robots,
42 robot_id, nb_candidates_to_choose, use_vertex_cover):
43 """Test broker based on params
47 max_nb_robots, robot_id,
48 nb_candidates_to_choose)
49 unittest_framework.assertEqual(
50 len(selection), min(nb_candidate_edges, nb_candidates_to_choose))
51 neighbors_in_range_list = range(max_nb_robots)
54 broker =
Broker(selection, neighbors_in_range_list)
55 components = broker.brokerage(use_vertex_cover)
58 initial_vertices = set()
61 v0 = (e.robot0_id, e.robot0_keyframe_id)
62 if v0
in initial_vertices:
64 initial_vertices.add(v0)
65 v1 = (e.robot1_id, e.robot1_keyframe_id)
66 if v1
in initial_vertices:
68 initial_vertices.add(v1)
70 unittest_framework.assertEqual(
71 len(initial_vertices) + len(duplicates),
72 min(nb_candidate_edges, nb_candidates_to_choose) * 2)
82 unittest_framework.assertLessEqual(
83 len(vertices), min(nb_candidate_edges, nb_candidates_to_choose))
84 if use_vertex_cover
and max_nb_robots == 2:
85 unittest_framework.assertLessEqual(
86 len(vertices), math.ceil(float(len(initial_vertices)) / 2))
88 unittest_framework.assertGreaterEqual(len(vertices), 1)
91 for i
in range(len(vertices)):
92 for j
in range(len(vertices)):
94 unittest_framework.assertNotEqual(vertices[i], vertices[j])
98 v0 = (e.robot0_id, e.robot0_keyframe_id)
99 v1 = (e.robot1_id, e.robot1_keyframe_id)
100 v0_in = v0
in vertices
101 v1_in = v1
in vertices
102 unittest_framework.assertTrue(v0_in
or v1_in)
106 """Unit tests for communication broker
110 """Simple dialog strategy
115 nb_candidate_edges = 50
117 nb_candidates_to_choose = 30
118 use_vertex_cover =
False
120 verif_broker(self, nb_poses, nb_candidate_edges, max_nb_robots, robot_id,
121 nb_candidates_to_choose, use_vertex_cover)
123 verif_broker(self, nb_poses, nb_candidate_edges, max_nb_robots, robot_id,
124 nb_candidate_edges, use_vertex_cover)
126 verif_broker(self, nb_poses * 10, nb_candidate_edges * 10, max_nb_robots,
127 robot_id, nb_candidates_to_choose * 10, use_vertex_cover)
129 verif_broker(self, nb_poses * 10, nb_candidate_edges * 10, max_nb_robots,
130 robot_id, nb_candidate_edges * 10, use_vertex_cover)
132 verif_broker(self, nb_poses, nb_candidate_edges, max_nb_robots, robot_id,
133 2 * nb_candidate_edges, use_vertex_cover)
136 """Vertex cover strategy
141 nb_candidate_edges = 50
143 nb_candidates_to_choose = 30
144 use_vertex_cover =
True
146 verif_broker(self, nb_poses, nb_candidate_edges, max_nb_robots, robot_id,
147 nb_candidates_to_choose, use_vertex_cover)
149 verif_broker(self, nb_poses, nb_candidate_edges, max_nb_robots, robot_id,
150 nb_candidate_edges, use_vertex_cover)
152 verif_broker(self, nb_poses * 10, nb_candidate_edges * 10, max_nb_robots,
153 robot_id, nb_candidates_to_choose * 10, use_vertex_cover)
155 verif_broker(self, nb_poses * 10, nb_candidate_edges * 10, max_nb_robots,
156 robot_id, nb_candidate_edges * 10, use_vertex_cover)
158 verif_broker(self, nb_poses, nb_candidate_edges, max_nb_robots, robot_id,
159 2 * nb_candidate_edges, use_vertex_cover)
162 """Simple dialog strategy
167 nb_candidate_edges = 200
169 nb_candidates_to_choose = 100
170 use_vertex_cover =
False
172 verif_broker(self, nb_poses, nb_candidate_edges, max_nb_robots, robot_id,
173 nb_candidates_to_choose, use_vertex_cover)
175 verif_broker(self, nb_poses, nb_candidate_edges, max_nb_robots, robot_id,
176 nb_candidate_edges, use_vertex_cover)
178 verif_broker(self, nb_poses * 10, nb_candidate_edges * 10, max_nb_robots,
179 robot_id, nb_candidates_to_choose * 10, use_vertex_cover)
181 verif_broker(self, nb_poses * 10, nb_candidate_edges * 10, max_nb_robots,
182 robot_id, nb_candidate_edges * 10, use_vertex_cover)
184 verif_broker(self, nb_poses, nb_candidate_edges, max_nb_robots, robot_id,
185 2 * nb_candidate_edges, use_vertex_cover)
188 """Vertex cover strategy
193 nb_candidate_edges = 200
195 nb_candidates_to_choose = 100
196 use_vertex_cover =
True
198 verif_broker(self, nb_poses, nb_candidate_edges, max_nb_robots, robot_id,
199 nb_candidates_to_choose, use_vertex_cover)
201 verif_broker(self, nb_poses, nb_candidate_edges, max_nb_robots, robot_id,
202 nb_candidate_edges, use_vertex_cover)
204 verif_broker(self, nb_poses * 10, nb_candidate_edges * 10, max_nb_robots,
205 robot_id, nb_candidates_to_choose * 10, use_vertex_cover)
207 verif_broker(self, nb_poses * 10, nb_candidate_edges * 10, max_nb_robots,
208 robot_id, nb_candidate_edges * 10, use_vertex_cover)
210 verif_broker(self, nb_poses, nb_candidate_edges, max_nb_robots, robot_id,
211 2 * nb_candidate_edges, use_vertex_cover)
215 fixed_edges_list = []
216 candidate_edges_list = []
218 candidate_edges_list.append(
EdgeInterRobot(0, 1, 1, 1, fixed_weight))
219 candidate_edges_list.append(
EdgeInterRobot(0, 1, 1, 2, fixed_weight))
220 candidate_edges_list.append(
EdgeInterRobot(0, 1, 1, 3, fixed_weight))
221 candidate_edges_list.append(
EdgeInterRobot(0, 1, 1, 4, fixed_weight))
222 candidate_edges_list.append(
EdgeInterRobot(0, 2, 1, 5, fixed_weight))
226 nb_candidate_edges = 5
228 nb_candidates_to_choose = 5
229 use_vertex_cover =
True
232 params[
'robot_id'] = robot_id
233 params[
'max_nb_robots'] = max_nb_robots
234 params[
'frontend.similarity_threshold'] = 0.0
235 params[
'frontend.sensor_type'] =
'stereo'
236 params[
"frontend.enable_sparsification"] =
True
237 params[
"evaluation.enable_sparsification_comparison"] =
False
239 lcsm.candidate_selector.set_graph(fixed_edges_list, candidate_edges_list)
242 is_robot_considered = {}
243 for i
in range(max_nb_robots):
244 is_robot_considered[i] =
True
245 selection = lcsm.select_candidates(nb_candidates_to_choose,
247 greedy_initialization=
False)
250 len(selection), min(nb_candidate_edges, nb_candidates_to_choose))
251 neighbors_in_range_list = range(max_nb_robots)
254 broker =
Broker(selection, neighbors_in_range_list)
255 components = broker.brokerage(use_vertex_cover)
257 nb_components = len(components)
258 nb_vertices_transmitted = 0
260 for component
in components:
262 nb_vertices_transmitted += 1
264 self.assertEqual(nb_components, 2)
265 self.assertEqual(nb_vertices_transmitted, 2)
270 if __name__ ==
"__main__":
def test_vertex_cover_5robots(self)
def test_simple_dialog_2robots(self)
def test_manual_vertex_cover(self)
def test_simple_dialog_5robots(self)
def test_vertex_cover_2robots(self)
def build_multi_robot_graph(nb_poses, nb_candidate_edges, max_nb_robots)
def build_graph_and_extract_selection(nb_poses, nb_candidate_edges, max_nb_robots, robot_id, nb_candidates_to_choose)
def verif_broker(unittest_framework, nb_poses, nb_candidate_edges, max_nb_robots, robot_id, nb_candidates_to_choose, use_vertex_cover)