def test_only_one_request_is_embedded_due_to_capacity_limitations(): sub = vtd.create_test_substrate("single_edge_substrate") req1 = vtd.create_test_request("single_edge_request", sub, allowed_nodes=dict(i1=["u1"], i2=["u2"])) req2 = vtd.create_test_request( "single_edge_request", sub, ) req1.name = "req1" req2.name = "req2" scenario = datamodel.Scenario( name="test_scen", requests=[req1, req2], substrate=sub, objective=datamodel.Objective.MAX_PROFIT, ) v = vine.OfflineViNEAlgorithm( scenario, edge_embedding_model=vine.ViNEEdgeEmbeddingModel.UNSPLITTABLE, lp_objective=vine.ViNELPObjective.ViNE_COSTS_DEF, rounding_procedure=vine.ViNERoundingProcedure.DETERMINISTIC) result = v.compute_integral_solution() solution = result.get_solution() m1 = solution.request_mapping[req1] assert m1.mapping_nodes == dict( i1="u1", i2="u2", ) assert m1.mapping_edges == {("i1", "i2"): [("u1", "u2")]} assert solution.request_mapping[req2] is None
def test_requests_are_processed_in_profit_order(): sub = vtd.create_test_substrate("single_edge_substrate") req1 = vtd.create_test_request("single_edge_request", sub, allowed_nodes=dict(i1=["u1"], i2=["u2"])) req2 = vtd.create_test_request("single_edge_request", sub, allowed_nodes=dict(i1=["u1"], i2=["u2"])) req2.profit = req1.profit + 1 scenario = datamodel.Scenario( name="test_scen", requests=[req1, req2], substrate=sub, objective=datamodel.Objective.MAX_PROFIT, ) v = vine.OfflineViNEAlgorithm( scenario, edge_embedding_model=vine.ViNEEdgeEmbeddingModel.UNSPLITTABLE, lp_objective=vine.ViNELPObjective.ViNE_COSTS_DEF, rounding_procedure=vine.ViNERoundingProcedure.DETERMINISTIC) result = v.compute_integral_solution() solution = result.get_solution() m = solution.request_mapping[req2] # Although req2 is second in the request list, it must be processed first due to its higher profit. assert m.mapping_nodes == dict( i1="u1", i2="u2", ) assert m.mapping_edges == {("i1", "i2"): [("u1", "u2")]} assert solution.request_mapping[req1] is None
def test_cleanup_references(): sub = vtd.create_test_substrate("single_edge_substrate") req1 = vtd.create_test_request("single_edge_request", sub) req2 = vtd.create_test_request("single_edge_request", sub) scenario = datamodel.Scenario( name="test_scen", requests=[req1, req2], substrate=sub, objective=datamodel.Objective.MAX_PROFIT, ) v = vine.OfflineViNEAlgorithm( scenario, edge_embedding_model=vine.ViNEEdgeEmbeddingModel.UNSPLITTABLE, lp_objective=vine.ViNELPObjective.ViNE_COSTS_DEF, rounding_procedure=vine.ViNERoundingProcedure.DETERMINISTIC) result = v.compute_integral_solution() scenario_copy = copy.deepcopy(scenario) assert result.get_solution().scenario is not scenario_copy for req in result.get_solution().request_mapping: assert req not in scenario_copy.requests for req in result.runtime_per_request: assert req not in scenario_copy.requests for req in result.mapping_status_per_request: assert req not in scenario_copy.requests result.cleanup_references(scenario_copy) solution = result.get_solution() assert solution.scenario is scenario_copy for req in solution.request_mapping: assert req in scenario_copy.requests for req in result.runtime_per_request: assert req in scenario_copy.requests for req in result.mapping_status_per_request: assert req in scenario_copy.requests