def test_discrete(self) -> None: """ DISCRETE """ self.cfg["angle_cost_function"] = "discrete" self.cfg["max_angle"] = np.pi / 4 self.cfg["angle_weight"] = .3 graph = AngleGraph(self.instance, self.corridor) _ = graph.single_sp(**self.cfg) gt_angle_cost_arr = graph.angle_cost_array.copy() gt_dists = graph.dists.copy() graph.dists = np.zeros( (len(graph.stack_array), len(graph.shifts)) ) + np.inf graph.dists[0, :] = 0 graph.preds = np.zeros(graph.dists.shape) - 1 graph.angle_cost_function = "some_non_existant" graph.build_source_sp_tree(**self.cfg) self.assertTrue(np.all(gt_angle_cost_arr == graph.angle_cost_array)) self.assertTrue(np.all(np.isclose(gt_dists, graph.dists)))
def test_linear(self) -> None: """ LINEAR """ self.cfg["angle_cost_function"] = "linear" self.cfg["max_angle"] = np.pi self.cfg["angle_weight"] = .3 graph = AngleGraph(self.instance, self.corridor) _ = graph.single_sp(**self.cfg) gt_angle_cost_arr = graph.angle_cost_array.copy() gt_dists = graph.dists.copy() graph.dists = np.zeros( (len(graph.stack_array), len(graph.shifts)) ) + np.inf graph.dists[0, :] = 0 graph.preds = np.zeros(graph.dists.shape) - 1 graph.angle_cost_function = "some_non_existant" graph.build_source_sp_tree(**self.cfg) self.assertTrue( np.all(np.isclose(gt_angle_cost_arr, graph.angle_cost_array)) ) # Errors can occur randomly, but seem to be only precision errors # errors only appear if angle_weight > 0, try 1 to reproduce self.assertTrue(np.all(np.isclose(gt_dists, graph.dists, atol=1e-04)))