def test_can_add_resources(): task = BaseTask("task") w1 = BaseWorker("w1", solo_working=True) w2 = BaseWorker("w2") w1.workamount_skill_mean_map = {"task": 1.0} w2.workamount_skill_mean_map = {"task": 1.0} f1 = BaseFacility("f1") f2 = BaseFacility("f2", solo_working=True) f1.workamount_skill_mean_map = {"task": 1.0} f2.workamount_skill_mean_map = {"task": 1.0} w1.facility_skill_map = {f1.name: 1.0} assert task.can_add_resources(worker=w1) is False task.state = BaseTaskState.FINISHED assert task.can_add_resources(worker=w1) is False task.state = BaseTaskState.READY assert task.can_add_resources(worker=w1) is True assert task.can_add_resources(worker=w2, facility=f2) is False assert task.can_add_resources(worker=w1, facility=f1) is True w1.solo_working = False task.allocated_worker_list = [w1] task.allocated_facility_list = [f1] assert task.can_add_resources(worker=w2, facility=f2) is False w1.solo_working = True assert task.can_add_resources(worker=w2, facility=f2) is False w1.solo_working = False f1.solo_working = True assert task.can_add_resources(worker=w2, facility=f2) is False w1.solo_working = False f1.solo_working = False w2.solo_working = False f2.solo_working = False assert task.can_add_resources(worker=w1, facility=f1) is True assert task.can_add_resources(worker=w2, facility=f2) is False f1.workamount_skill_mean_map = {} assert task.can_add_resources(worker=w1, facility=f1) is False w1.workamount_skill_mean_map = {} assert task.can_add_resources(worker=w1) is False assert task.can_add_resources() is False
def dummy_project2(scope="function"): # BaseComponents in BaseProduct c3 = BaseComponent("c3") c1 = BaseComponent("c1") c2 = BaseComponent("c2") c3.extend_child_component_list([c1, c2]) # BaseTasks in BaseWorkflow task1_1 = BaseTask("task1_1", need_facility=True) task1_2 = BaseTask("task1_2") task2_1 = BaseTask("task2_1") task3 = BaseTask("task3", due_time=30) task3.extend_input_task_list([task1_2, task2_1]) task1_2.append_input_task(task1_1) task0 = BaseTask("auto", auto_task=True, due_time=20) c1.extend_targeted_task_list([task1_1, task1_2]) c2.append_targeted_task(task2_1) c3.append_targeted_task(task3) # Facilities in factory f1 = BaseFacility("f1") f1.workamount_skill_mean_map = { task1_1.name: 1.0, } # factory.facility_list.append(f1) # Factory in BaseOrganization factory = BaseFactory("factory", facility_list=[f1]) factory.extend_targeted_task_list([task1_1, task1_2, task2_1, task3]) # BaseTeams in BaseOrganization team = BaseTeam("team") team.extend_targeted_task_list([task1_1, task1_2, task2_1, task3]) # BaseResources in each BaseTeam w1 = BaseWorker("w1", team_id=team.ID, cost_per_time=10.0) w1.workamount_skill_mean_map = { task1_1.name: 1.0, task1_2.name: 1.0, task2_1.name: 0.0, task3.name: 1.0, } w1.facility_skill_map = {f1.name: 1.0} team.worker_list.append(w1) w2 = BaseWorker("w2", team_id=team.ID, cost_per_time=6.0) w2.solo_working = True w2.workamount_skill_mean_map = { task1_1.name: 1.0, task1_2.name: 0.0, task2_1.name: 1.0, task3.name: 1.0, } w2.facility_skill_map = {f1.name: 1.0} team.worker_list.append(w2) # BaseProject including BaseProduct, BaseWorkflow and Organization project = BaseProject( init_datetime=datetime.datetime(2020, 4, 1, 8, 0, 0), unit_timedelta=datetime.timedelta(days=1), product=BaseProduct([c3, c1, c2]), workflow=BaseWorkflow([task1_1, task1_2, task2_1, task3, task0]), organization=BaseOrganization(team_list=[team], factory_list=[factory]), time=10, cost_list=[10], ) project.initialize() # project.product = BaseProduct([c3, c1, c2]) # project.workflow = BaseWorkflow([task1_1, task1_2, task2_1, task3]) # project.organization = BaseOrganization(team_list=[team], factory_list=[factory]) return project