def test_beta_2(self, msgsteiner): ''' See test_beta_1; beta = 2 is enough to overcome the hub penalty so that the hub at A is chosen: p'(A) = 2*5 - 2*4 = 2 ''' params = copy.deepcopy(conf_params) params['b'] = 2 graph, objective = test_util.run_forest(msgsteiner, params, forest_opts) try: assert graph.order() == 5, "Unexpected number of nodes" assert graph.size() == 4, "Unexpected number of edges" assert graph.has_edge('A', 'B') assert graph.has_edge('A', 'C') assert graph.has_edge('A', 'D') assert graph.has_edge('A', 'E') # Check that the optimal forest has the correct objective function # value, using isclose to allow for minor floating point variation # Objective function: 1.4 # Excluded prizes: 0 # Edge costs: 0.4 # Number of trees * w: 1 * 1.0 = 1.0 assert isclose(1.4, objective, rtol=0, atol=1e-5), 'Incorrect objective function value' except AssertionError as e: test_util.print_graph(graph) raise e
def test_beta_1(self, msgsteiner): ''' In p'(v) = beta * p(v) - mu * deg(v), beta = 1 is too small to overcome the hub penalty with mu = 2: p'(A) = 1*5 - 2*4 = -3 We expect forest to use the more costly edges BC and CD in its network instead ''' params = copy.deepcopy(conf_params) params['b'] = 1 graph, objective = test_util.run_forest(msgsteiner, params, forest_opts) try: assert graph.order() == 4, "Unexpected number of nodes" assert graph.size() == 2, "Unexpected number of edges" assert graph.has_edge('B', 'C') assert graph.has_edge('D', 'E') # Check that the optimal forest has the correct objective function # value, using isclose to allow for minor floating point variation # Objective function: 0.8 # Excluded prizes: -3.0 # Edge costs: 1.8 # Number of trees * w: 2 * 1.0 = 2.0 assert isclose(0.8, objective, rtol=0, atol=1e-5), 'Incorrect objective function value' except AssertionError as e: test_util.print_graph(graph) raise e
def test_beta_2(self, msgsteiner): ''' See test_beta_1; beta = 2 is enough to overcome the hub penalty so that the hub at A is chosen: p'(A) = 2*5 - 2*4 = 2 ''' params = copy.deepcopy(conf_params) params['b'] = 2 graph = test_util.run_forest(msgsteiner, params, forest_opts) try: assert graph.order() == 5, "Unexpected number of nodes" assert graph.size() == 4, "Unexpected number of edges" assert graph.has_edge('A', 'B') assert graph.has_edge('A', 'C') assert graph.has_edge('A', 'D') assert graph.has_edge('A', 'E') except AssertionError as e: test_util.print_graph(graph) raise e
def test_beta_1(self, msgsteiner): ''' In p'(v) = beta * p(v) - mu * deg(v), beta = 1 is too small to overcome the hub penalty with mu = 2: p'(A) = 1*5 - 2*4 = -3 We expect forest to use the more costly edges BC and CD in its network instead ''' params = copy.deepcopy(conf_params) params['b'] = 1 graph = test_util.run_forest(msgsteiner, params, forest_opts) try: assert graph.order() == 4, "Unexpected number of nodes" assert graph.size() == 2, "Unexpected number of edges" assert graph.has_edge('B', 'C') assert graph.has_edge('D', 'E') except AssertionError as e: test_util.print_graph(graph) raise e