def test_depth_0(self, msgsteiner): ''' Run Forest with depth = 0; msgsteiner fails and test_util.run_forest raises an error INPUT: msgsteiner - fixture object with the value of --msgpath parsed by conftest.py ''' params = copy.deepcopy(conf_params) params['D'] = 0 with pytest.raises(Exception) as excinfo: test_util.run_forest(msgsteiner, params, forest_opts) assert 'Forest did not generate the optimal forest file' in excinfo.value.message
def test_w_missing(self, msgsteiner): ''' Run Forest with w missing from the configuration file and check that Forest does not produce an output subnetwork INPUT: msgsteiner - fixture object with the value of --msgpath parsed by conftest.py ''' params = copy.deepcopy(conf_params) with pytest.raises(Exception) as excinfo: test_util.run_forest(msgsteiner, params, forest_opts) # Forest will not raise an Exception, it simply exits if w is missing # Have to check for missing output files to determine whether it exited assert 'Forest did not generate the optimal forest file' in excinfo.value.message
def test_w_1(self, msgsteiner): ''' Run Forest with w=1 and check optimal subnetwork INPUT: msgsteiner - fixture object with the value of --msgpath parsed by conftest.py ''' params = copy.deepcopy(conf_params) params['w'] = 1 graph, objective = test_util.run_forest(msgsteiner, params, forest_opts) # Check that the DiGraph has the expected properties # Undirected edges are loaded as a pair of directed edges assert graph.order() == 3, "Unexpected number of nodes" assert graph.size() == 3, "Unexpected number of edges" # Check that the DiGraph has the expected edges assert graph.has_edge('A','C') assert graph.has_edge('C','A') assert graph.has_edge('C','D') # Check that the optimal forest has the correct objective function # value, using isclose to allow for minor floating point variation # Objective function: 2.0 # Excluded prizes: 0 # Edge costs: 1.0 # Number of trees * w: 1 * 1.0 = 1.0 assert isclose(2.0, objective, rtol=0, atol=1e-5), 'Incorrect objective function value'
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_026(self, msgsteiner): ''' Run Forest with beta = 0.26 See test_beta_024; this value of beta makes it worth while to obtain prizes for C and D; we expect the following network: A B \ \ C D note an undirected edge ab in a digraph is represented by the network containing both edges ab and ba ''' params = copy.deepcopy(conf_params) params['b'] = 0.26 graph, objective = test_util.run_forest(msgsteiner, params, forest_opts) assert graph.order() == 4 assert graph.size() == 4 assert graph.has_edge('A', 'C') assert graph.has_edge('C', 'A') assert graph.has_edge('B', 'D') assert graph.has_edge('D', 'B') # Check that the optimal forest has the correct objective function # value, using isclose to allow for minor floating point variation # Objective function: 0.5 # Excluded prizes: 0 # Edge costs: 0.5 # Number of trees * w: 0 * 2 = 0 assert isclose(0.5, objective, rtol=0, atol=1e-5), 'Incorrect objective function value'
def test_depth_3_w_1(self, msgsteiner): ''' When the solver is constrained by depth, it still picks up net positive nodes. This results in a different network than if the solver is not constrained by depth. Note behavior of the following tests for comparison (which we do not repeat in this class): TestW#test_w_1, which has w = 1 and D = 5 we are not constrained by depth and we pick A - C -> D TestDepth#test_depth_10, which has w = 0 and D = 10 there is no forest penalty, so the optimal network is the same as this one ''' params = copy.deepcopy(conf_params) params['D'] = 3 params['w'] = 1 graph, objective = test_util.run_forest(msgsteiner, params, forest_opts) # Check that the DiGraph has the expected properties # Undirected edges are loaded as a pair of directed edges assert graph.order() == 4, "Unexpected number of nodes" assert graph.size() == 4, "Unexpected number of edges" # Check that the DiGraph has the expected edges assert graph.has_edge('A','C') assert graph.has_edge('C','A') assert graph.has_edge('B','D') assert graph.has_edge('D','B')
def test_depth_3_w_1(self, msgsteiner): ''' When the solver is constrained by depth, it still picks up net positive nodes. This results in a different network than if the solver is not constrained by depth. Note behavior of the following tests for comparison (which we do not repeat in this class): TestW#test_w_1, which has w = 1 and D = 5 we are not constrained by depth and we pick A - C -> D TestDepth#test_depth_10, which has w = 0 and D = 10 there is no forest penalty, so the optimal network is the same as this one ''' params = copy.deepcopy(conf_params) params['D'] = 3 params['w'] = 1 graph, objective = test_util.run_forest(msgsteiner, params, forest_opts) # Check that the DiGraph has the expected properties # Undirected edges are loaded as a pair of directed edges assert graph.order() == 4, "Unexpected number of nodes" assert graph.size() == 4, "Unexpected number of edges" # Check that the DiGraph has the expected edges assert graph.has_edge('A', 'C') assert graph.has_edge('C', 'A') assert graph.has_edge('B', 'D') assert graph.has_edge('D', 'B')
def test_depth_2(self, msgsteiner): ''' Run Forest with depth = 2; while this depth is valid, it results in no edges because the depth parameter is used as a strict inequality and there is a dummy node ''' params = copy.deepcopy(conf_params) params['D'] = 2 graph, objective = test_util.run_forest(msgsteiner, params, forest_opts) assert graph.order() == 0, "Unexpected number of nodes" assert graph.size() == 0, "Unexpected number of edges"
def test_beta_024(self, msgsteiner): ''' Run Forest with beta = 0.24 This value of beta is just below the 0.25 value of beta which sets the prize benefit of C and D equal to the cost of obtaining those prizes through edges AC and BD: we expect an empty network again ''' params = copy.deepcopy(conf_params) params['b'] = 0.24 graph = test_util.run_forest(msgsteiner, params, forest_opts) assert graph.order() == 0, "Unexpected number of nodes" assert graph.size() == 0, "Unexpected number of edges"
def test_beta_0(self, msgsteiner): ''' Run Forest with beta = 0 and check optimal subnetwork In p'(v) = beta * p(v) - mu * deg(v), beta = 0 implies that an empty graph is the optimal network INPUT: msgsteiner - fixture object with the value of --msgpath parsed by conftest.py ''' params = copy.deepcopy(conf_params) params['b'] = 0 graph = test_util.run_forest(msgsteiner, params, forest_opts) assert graph.order() == 0, "Unexpected number of nodes" assert graph.size() == 0, "Unexpected number of edges"
def test_depth_10(self, msgsteiner): ''' Run forest with depth = 10; the results are the same as in test_depth_3 ''' params = copy.deepcopy(conf_params) params['D'] = 3 graph, objective = test_util.run_forest(msgsteiner, params, forest_opts) # Check that the DiGraph has the expected properties # Undirected edges are loaded as a pair of directed edges assert graph.order() == 4, "Unexpected number of nodes" assert graph.size() == 4, "Unexpected number of edges" # Check that the DiGraph has the expected edges assert graph.has_edge('A', 'C') assert graph.has_edge('C', 'A') assert graph.has_edge('B', 'D') assert graph.has_edge('D', 'B')
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
def test_beta_024(self, msgsteiner): ''' Run Forest with beta = 0.24 This value of beta is just below the 0.25 value of beta which sets the prize benefit of C and D equal to the cost of obtaining those prizes through edges AC and BD: we expect an empty network again ''' params = copy.deepcopy(conf_params) params['b'] = 0.24 graph, objective = test_util.run_forest(msgsteiner, params, forest_opts) assert graph.order() == 0, "Unexpected number of nodes" assert graph.size() == 0, "Unexpected number of edges" # Check that the optimal forest has the correct objective function # value, using isclose to allow for minor floating point variation # Objective function: 0.48 # Excluded prizes: 0.48 # Edge costs: 0 # Number of trees * w: 0 assert isclose(0.48, objective, rtol=0, atol=1e-5), 'Incorrect objective function value'
def test_beta_0(self, msgsteiner): ''' Run Forest with beta = 0 and check optimal subnetwork In p'(v) = beta * p(v) - mu * deg(v), beta = 0 implies that an empty graph is the optimal network INPUT: msgsteiner - fixture object with the value of --msgpath parsed by conftest.py ''' params = copy.deepcopy(conf_params) params['b'] = 0 graph, objective = test_util.run_forest(msgsteiner, params, forest_opts) assert graph.order() == 0, "Unexpected number of nodes" assert graph.size() == 0, "Unexpected number of edges" # Check that the optimal forest has the correct objective function # value, using isclose to allow for minor floating point variation # Objective function: 0 # Excluded prizes: 0 # Edge costs: 0 # Number of trees * w: 0 assert isclose(0, objective, rtol=0, atol=1e-5), 'Incorrect objective function value'
def test_beta_026(self, msgsteiner): ''' Run Forest with beta = 0.26 See test_beta_024; this value of beta makes it worth while to obtain prizes for C and D; we expect the following network: A B \ \ C D note an undirected edge ab in a digraph is represented by the network containing both edges ab and ba ''' params = copy.deepcopy(conf_params) params['b'] = 0.26 graph = test_util.run_forest(msgsteiner, params, forest_opts) assert graph.order() == 4 assert graph.size() == 4 assert graph.has_edge('A', 'C') assert graph.has_edge('C', 'A') assert graph.has_edge('B', 'D') assert graph.has_edge('D', 'B')