def test_check_state(): """test_check_state.""" task1 = BaseTask("task1") task2 = BaseTask("task2") task3 = BaseTask("task3") task4 = BaseTask("task4") task5 = BaseTask("task5") task3.extend_input_task_list([task1, task2]) task5.extend_input_task_list([task3, task4]) w = BaseWorkflow([task1, task2, task3, task4, task5]) w1 = BaseWorker("w1", assigned_task_list=[task1]) # __check_ready test task1.state = BaseTaskState.FINISHED task2.state = BaseTaskState.FINISHED task3.state = BaseTaskState.NONE task4.state = BaseTaskState.NONE task5.state = BaseTaskState.NONE w.check_state(2, BaseTaskState.READY) assert task1.state == BaseTaskState.FINISHED assert task2.state == BaseTaskState.FINISHED assert task3.state == BaseTaskState.READY assert task4.state == BaseTaskState.READY assert task5.state == BaseTaskState.NONE # __check_working test task1.state = BaseTaskState.READY task2.state = BaseTaskState.READY task2.allocated_worker_list = [w1] task3.state = BaseTaskState.NONE task4.state = BaseTaskState.NONE task5.state = BaseTaskState.NONE w.check_state(2, BaseTaskState.WORKING) assert task1.state == BaseTaskState.READY assert task2.state == BaseTaskState.WORKING assert task3.state == BaseTaskState.NONE assert task4.state == BaseTaskState.NONE assert task5.state == BaseTaskState.NONE task1.state = BaseTaskState.WORKING task1.need_facility = True w2 = BaseWorker("w2", assigned_task_list=[task1]) f2 = BaseFacility("f2", assigned_task_list=[task1]) task1.allocated_worker_list = [w2] task1.allocated_facility_list = [f2] w.check_state(2, BaseTaskState.WORKING) # __check_finished test task1.state = BaseTaskState.WORKING task1.allocated_worker_list = [w1] task1.remaining_work_amount = 0.0 task2.state = BaseTaskState.FINISHED task3.state = BaseTaskState.NONE task4.state = BaseTaskState.NONE task5.state = BaseTaskState.NONE w.check_state(2, BaseTaskState.FINISHED) assert task1.state == BaseTaskState.FINISHED assert task2.state == BaseTaskState.FINISHED assert task3.state == BaseTaskState.NONE assert task4.state == BaseTaskState.NONE assert task5.state == BaseTaskState.NONE
def dummy_facility(): """dummy_facility.""" w = BaseFacility("wsss", workplace_id="---") return w
def dummy_place_check(): c3 = BaseComponent("c3", space_size=1.0) c1 = BaseComponent("c1", space_size=1.0) c2 = BaseComponent("c2", space_size=1.0) task1 = BaseTask("t1", need_facility=True) task2 = BaseTask("t2", need_facility=True) task3 = BaseTask("t3", need_facility=True) c1.append_targeted_task(task1) c2.append_targeted_task(task2) c3.append_targeted_task(task3) # Facilities in factory f1 = BaseFacility("f1") f1.solo_working = True f1.workamount_skill_mean_map = { task1.name: 1.0, task2.name: 1.0, task3.name: 1.0, } f2 = BaseFacility("f2") f2.solo_working = True f2.workamount_skill_mean_map = { task1.name: 1.0, task2.name: 1.0, task3.name: 1.0, } # Factory in BaseOrganization factory = BaseFactory("factory", facility_list=[f1, f2]) factory.extend_targeted_task_list([task1, task2, task3]) # BaseTeams in BaseOrganization team = BaseTeam("team") team.extend_targeted_task_list([task1, task2, task3]) # BaseResources in each BaseTeam w1 = BaseWorker("w1", team_id=team.ID, cost_per_time=10.0) w1.workamount_skill_mean_map = { task1.name: 1.0, task2.name: 1.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.workamount_skill_mean_map = { task1.name: 1.0, task2.name: 1.0, task3.name: 1.0, } w2.facility_skill_map = {f2.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([c1, c2, c3]), workflow=BaseWorkflow([task1, task2, task3]), organization=BaseOrganization(team_list=[team], factory_list=[factory]), ) return project
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
def test_get_work_amount_skill_progress(): w = BaseFacility("w1", "----") # w.set_workamount_skill_mean_map( # {"task1": 1.0, "task2": 0.0}, update_other_skill_info=True # ) w.workamount_skill_mean_map = {"task1": 1.0, "task2": 0.0} assert w.get_work_amount_skill_progress("task3") == 0.0 assert w.get_work_amount_skill_progress("task2") == 0.0 with pytest.raises(ZeroDivisionError): assert w.get_work_amount_skill_progress("task1") == 1.0 task1 = BaseTask("task1") task1.state = BaseTaskState.NONE w.assigned_task_list = [task1] with pytest.raises(ZeroDivisionError): assert w.get_work_amount_skill_progress("task1") == 1.0 task1.state = BaseTaskState.READY with pytest.raises(ZeroDivisionError): assert w.get_work_amount_skill_progress("task1") == 1.0 task1.state = BaseTaskState.WORKING_ADDITIONALLY assert w.get_work_amount_skill_progress("task1") == 1.0 task1.state = BaseTaskState.FINISHED with pytest.raises(ZeroDivisionError): assert w.get_work_amount_skill_progress("task1") == 1.0 task1.state = BaseTaskState.WORKING assert w.get_work_amount_skill_progress("task1") == 1.0 w.workamount_skill_sd_map["task1"] = 0.1 w.get_work_amount_skill_progress("task1", seed=1234) # seed test task2 = BaseTask("task2") task2.state = BaseTaskState.NONE w.assigned_task_list.append(task2) w.workamount_skill_sd_map["task1"] = 0.0 assert w.get_work_amount_skill_progress("task1") == 1.0 task2.state = BaseTaskState.WORKING assert w.get_work_amount_skill_progress("task1") == 0.5
def test_str(): print(BaseFacility("w1"))
def dummy_project(scope="function"): # Components in Product c3 = Component("c3") c1 = Component("c1") c2 = Component("c2") c3.extend_child_component_list([c1, c2]) # Tasks in Workflow task1_1 = Task("task1_1", need_facility=True) task1_2 = Task("task1_2") task2_1 = Task("task2_1") task3 = Task("task3") task3.extend_input_task_list([task1_2, task2_1]) task1_2.append_input_task(task1_1) 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]) # Teams in Organization team = Team("team") team.extend_targeted_task_list([task1_1, task1_2, task2_1, task3]) # Workers in each Team w1 = Worker("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 = Worker("w2", team_id=team.ID, cost_per_time=6.0) 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) # Project including Product, Workflow and Organization project = Project( init_datetime=datetime.datetime(2020, 4, 1, 8, 0, 0), unit_timedelta=datetime.timedelta(days=1), ) project.product = Product([c3, c1, c2]) project.workflow = Workflow([task1_1, task1_2, task2_1, task3]) project.organization = Organization(team_list=[team], factory_list=[factory]) return project
def dummy_facility(): w = BaseFacility("wsss", factory_id="---") return w
def test_add_facility(): factory = BaseFactory("factory") facility = BaseFacility("facility") factory.add_facility(facility) assert len(factory.facility_list) == 1 assert facility.factory_id == factory.ID
def dummy_team_for_extracting(scope="function"): """dummy_team_for_extracting.""" facility1 = BaseFacility("facility1") facility1.state_record_list = [ BaseFacilityState.FREE, BaseFacilityState.FREE, BaseFacilityState.FREE, BaseFacilityState.FREE, BaseFacilityState.FREE, ] facility2 = BaseFacility("facility2") facility2.state_record_list = [ BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.WORKING, ] facility3 = BaseFacility("facility3") facility3.state_record_list = [ BaseFacilityState.FREE, BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.FREE, ] facility4 = BaseFacility("facility4") facility4.state_record_list = [ BaseFacilityState.FREE, BaseFacilityState.FREE, BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.FREE, ] facility5 = BaseFacility("facility5") facility5.state_record_list = [ BaseFacilityState.FREE, BaseFacilityState.FREE, BaseFacilityState.FREE, BaseFacilityState.FREE, BaseFacilityState.WORKING, ] return BaseWorkplace( "test", facility_list=[facility1, facility2, facility3, facility4, facility5] )
def test_can_add_resources(): """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 task2 = BaseTask( "task", fixing_allocating_worker_id_list=[w1.ID], fixing_allocating_facility_id_list=[f1.ID], ) task2.state = BaseTaskState.WORKING w1.workamount_skill_mean_map = {"task": 1.0} w2.workamount_skill_mean_map = {"task": 1.0} f1.workamount_skill_mean_map = {"task": 1.0} f2.workamount_skill_mean_map = {"task": 1.0} assert task2.can_add_resources(worker=w1) is True assert task2.can_add_resources(worker=w2) is False assert task2.can_add_resources(worker=w1, facility=f1) is True assert task2.can_add_resources(worker=w1, facility=f2) is False
def dummy_conveyor_project_with_child_component(): """dummy_conveyor_project_with_child_component.""" c1_1 = BaseComponent("c1_1") c1_2 = BaseComponent("c1_2") c2_1 = BaseComponent("c2_1") c2_2 = BaseComponent("c2_2") c3_1 = BaseComponent("c3_1") c3_2 = BaseComponent("c3_2") c1_2.append_child_component(c1_1) c2_2.append_child_component(c2_1) c3_2.append_child_component(c3_1) taskA1 = BaseTask("A1", need_facility=True, default_work_amount=6) taskA2 = BaseTask("A2", need_facility=True, default_work_amount=2) taskA3 = BaseTask("A3", need_facility=True, default_work_amount=2) taskB1 = BaseTask("B1", need_facility=True, default_work_amount=2) taskB2 = BaseTask("B2", need_facility=True, default_work_amount=7) taskB3 = BaseTask("B3", need_facility=True, default_work_amount=2) c1_1.append_targeted_task(taskA1) c1_2.append_targeted_task(taskB1) c2_1.append_targeted_task(taskA2) c2_2.append_targeted_task(taskB2) c3_1.append_targeted_task(taskA3) c3_2.append_targeted_task(taskB3) taskB1.append_input_task(taskA1) taskB2.append_input_task(taskA2) taskB3.append_input_task(taskA3) f1 = BaseFacility("f1") f1.workamount_skill_mean_map = { taskA1.name: 1.0, taskA2.name: 1.0, taskA3.name: 1.0, } f2 = BaseFacility("f2") f2.workamount_skill_mean_map = { taskA1.name: 1.0, taskA2.name: 1.0, taskA3.name: 1.0, } f3 = BaseFacility("f3") f3.workamount_skill_mean_map = { taskB1.name: 1.0, taskB2.name: 1.0, taskB3.name: 1.0, } f4 = BaseFacility("f4") f4.workamount_skill_mean_map = { taskB1.name: 1.0, taskB2.name: 1.0, taskB3.name: 1.0, } # Workplace in BaseOrganization wp1 = BaseWorkplace("workplace1", facility_list=[f1], max_space_size=1.0) wp1.extend_targeted_task_list([taskA1, taskA2, taskA3]) wp2 = BaseWorkplace("workplace2", facility_list=[f2], max_space_size=2.0) wp2.extend_targeted_task_list([taskA1, taskA2, taskA3]) wp3 = BaseWorkplace("workplace3", facility_list=[f3], max_space_size=4.0) wp3.extend_targeted_task_list([taskB1, taskB2, taskB3]) wp4 = BaseWorkplace("workplace4", facility_list=[f4], max_space_size=4.0) wp4.extend_targeted_task_list([taskB1, taskB2, taskB3]) wp3.append_input_workplace(wp1) wp4.append_input_workplace(wp2) # BaseTeams in BaseOrganization team = BaseTeam("team") team_list = [team] team.extend_targeted_task_list( [taskA1, taskA2, taskA3, taskB1, taskB2, taskB3]) # BaseWorkers in each BaseTeam w1 = BaseWorker("w1", team_id=team.ID) w1.workamount_skill_mean_map = { taskA1.name: 1.0, taskA2.name: 1.0, taskA3.name: 1.0, } w1.facility_skill_map = {f1.name: 1.0} team.add_worker(w1) w2 = BaseWorker("w2", team_id=team.ID) w2.workamount_skill_mean_map = { taskA1.name: 1.0, taskA2.name: 1.0, taskA3.name: 1.0, } w2.facility_skill_map = {f2.name: 1.0} team.add_worker(w2) w3 = BaseWorker("w3", team_id=team.ID) w3.workamount_skill_mean_map = { taskB1.name: 1.0, taskB2.name: 1.0, taskB3.name: 1.0, } w3.facility_skill_map = {f3.name: 1.0} team.add_worker(w3) w4 = BaseWorker("w4", team_id=team.ID) w4.workamount_skill_mean_map = { taskB1.name: 1.0, taskB2.name: 1.0, taskB3.name: 1.0, } w4.facility_skill_map = {f4.name: 1.0} team.add_worker(w4) workplace_list = [wp1, wp2, wp3, wp4] # BaseProject including BaseProduct, BaseWorkflow and Organization project = BaseProject( init_datetime=datetime.datetime(2021, 8, 20, 8, 0, 0), unit_timedelta=datetime.timedelta(days=1), product=BaseProduct([c1_1, c1_2, c2_1, c2_2, c3_1, c3_2]), workflow=BaseWorkflow([taskA1, taskA2, taskA3, taskB1, taskB2, taskB3]), organization=BaseOrganization(team_list, workplace_list), ) return project
def project_for_checking_space_judge(cope="function"): """project_for_checking_space_judge.""" project = BaseProject( init_datetime=datetime.datetime(2021, 4, 2, 8, 0, 0), unit_timedelta=datetime.timedelta(minutes=1), ) # Components in Product a = BaseComponent("a") b = BaseComponent("b") # Register Product including Components in Project project.product = BaseProduct([a, b]) # Tasks in Workflow # define work_amount and whether or not to need facility for each task task_a = BaseTask( "task_a", need_facility=True, worker_priority_rule=ResourcePriorityRuleMode.HSV, default_work_amount=2, ) task_b = BaseTask( "task_b", need_facility=True, worker_priority_rule=ResourcePriorityRuleMode.HSV, default_work_amount=2, ) # Register Workflow including Tasks in Project project.workflow = BaseWorkflow([task_a, task_b]) # workplace in workplace model # define max_space_size which decide how many components can be placed workplace1 = BaseWorkplace("workplace1", max_space_size=3.0) workplace2 = BaseWorkplace("workplace2", max_space_size=3.0) # facility in workplace model # define workplace_id (each facility is placed which workplace) and cost_per_time machine1 = BaseFacility("machine1", workplace_id=workplace1.ID, cost_per_time=10, solo_working=True) machine2 = BaseFacility("machine2", workplace_id=workplace2.ID, cost_per_time=10, solo_working=True) # define each facility task skill value machine1.workamount_skill_mean_map = {task_a.name: 1.0, task_b.name: 1.0} machine2.workamount_skill_mean_map = {task_a.name: 1.0, task_b.name: 1.0} # define facilities belonging to wach workplace workplace1.add_facility(machine1) workplace2.add_facility(machine2) # Team in team mode team = BaseTeam("factory_A") # worker in team model # define cost_per_time and add each worker to the relevant team w1 = BaseWorker("w1", cost_per_time=10.0) team.add_worker(w1) w2 = BaseWorker("w2", cost_per_time=10.0) team.add_worker(w2) # define each worker task skill value # (Set the skill value of an average worker as 1.0) w1.workamount_skill_mean_map = {task_a.name: 1.0, task_b.name: 1.0} w2.workamount_skill_mean_map = {task_a.name: 1.0, task_b.name: 1.0} # define each worker facility skill value w1.facility_skill_map = {machine1.name: 1.0} w2.facility_skill_map = {machine2.name: 1.0} # Register Organization including Team in Project team_list = [team] workplace_list = [workplace1, workplace2] project.organization = BaseOrganization(team_list, workplace_list) # Component <-> Task a.append_targeted_task(task_a) b.append_targeted_task(task_b) # Team <-> Task team.extend_targeted_task_list([task_a, task_b]) # Workplace <-> Task workplace1.extend_targeted_task_list([task_a, task_b]) workplace2.extend_targeted_task_list([task_a, task_b]) return project