def test_find_demands(self): for project_name in ALL_FILES_DICT.keys(): if not project_name.startswith( 'classic') and not project_name.startswith('realistic'): continue # get content nrp = NextReleaseProblem(project_name) if project_name.startswith('classic'): nrp.flatten() # construct demands requests = nrp.content()[3] demands = NextReleaseProblem.find_demands(requests) # demands => requests for key, values in demands.items(): for value in values: assert (value, key) in requests # requests => demands for key, value in requests: assert value in demands assert key in demands[value]
def test_single_stakeholder(self): for project_name in ALL_FILES_DICT.keys(): if not project_name.startswith('realistic'): continue # get content nrp = NextReleaseProblem(project_name) # modelling moip = nrp.model('single', {'b': 0.5}) cost, profit, _, requests = nrp.content() # check for counts assert moip.objectiveCount == 1 assert moip.featureCount == len(cost) + len(profit) constant_id = moip.featureCount # check for equations assert moip.sparseEquationsMapList == [dict()] # check for objective assert len(moip.objectiveSparseMapList) == 1 neo_profit = { k: -v for k, v in moip.objectiveSparseMapList[0].items() } assert neo_profit == profit # check for inequations assert len(moip.sparseInequationsMapList) == len( moip.sparseInequationSensesList) assert moip.sparseInequationSensesList == ['L'] * len( moip.sparseInequationSensesList) # construct new requests from inequations neo_requests = [] neo_demands = dict() cost_inequation = None # get demands demands = NextReleaseProblem.find_demands(requests) for inequation in moip.sparseInequationsMapList: if inequation[constant_id] != 0: assert not cost_inequation cost_inequation = inequation else: # either request or xj - Sum yi <= 0 # get a positive key to have a look key = self.positive_one(inequation) assert key != None if key in cost: # xj - Sum yi <= 0 demands_list = self.negative_ones(inequation) assert demands_list neo_demands[key] = demands_list elif key in profit: # request # length == 3 assert len(inequation) == 3 # constant == 0 assert inequation[constant_id] == 0 # request neo_requests.append(self.unzip_inequation(inequation)) else: assert False assert neo_demands == demands assert set(neo_requests) == set(requests) # check for cost_inequation assert not cost_inequation[constant_id] - sum( cost.values()) * 0.5 > 10e-6 assert not cost_inequation[constant_id] - sum( cost.values()) * 0.5 < -10e-6 del cost_inequation[constant_id] assert cost_inequation == cost