def test_check_removing_placed_factory(): c1 = BaseComponent("c1") task1 = BaseTask("task1") c1.append_targeted_task(task1) c2 = BaseComponent("c2") task2 = BaseTask("task2") c2.append_targeted_task(task2) product = BaseProduct([c1, c2]) f1 = BaseFactory("f1") f2 = BaseFactory("f2") c1.placed_factory = f1 c2.placed_factory = f2 f1.set_placed_component(c1) f2.set_placed_component(c2) # case1 task1.state = BaseTaskState.WORKING task2.state = BaseTaskState.FINISHED product.check_removing_placed_factory() assert c1.placed_factory.name == "f1" assert c2.placed_factory is None # case2 task1.state = BaseTaskState.FINISHED task2.state = BaseTaskState.FINISHED c1.append_child_component(c2) c2.placed_factory = BaseFactory("f2") product.check_removing_placed_factory() assert c1.placed_factory is None assert c2.placed_factory is None
def test_perform(): """test_perform.""" task = BaseTask("task") task.state = BaseTaskState.WORKING w1 = BaseWorker("w1") w2 = BaseWorker("w2") w1.workamount_skill_mean_map = {"task": 1.0} task.allocated_worker_list = [w1, w2] w1.assigned_task_list = [task] w2.assigned_task_list = [task] c = BaseComponent("a") c.append_targeted_task(task) auto_task = BaseTask("auto", auto_task=True) auto_task.state = BaseTaskState.WORKING w = BaseWorkflow([task, auto_task]) w.perform(10) assert task.remaining_work_amount == task.default_work_amount - 1.0 assert auto_task.remaining_work_amount == auto_task.default_work_amount - 1.0 assert task.target_component == c # autotask testing w.initialize() task.state = BaseTaskState.WORKING auto_task.state = BaseTaskState.WORKING w.perform(10, only_auto_task=True) assert task.remaining_work_amount == task.default_work_amount assert auto_task.remaining_work_amount == auto_task.default_work_amount - 1.0
def test_create_gantt_plotly(): c1 = BaseComponent("c1") task11 = BaseTask("task11") task12 = BaseTask("task12") c1.extend_targeted_task_list([task11, task12]) c2 = BaseComponent("c2") task2 = BaseTask("task2") c2.append_targeted_task(task2) product = BaseProduct([c1, c2]) # Set test case task11.start_time_list = [0, 2] task11.ready_time_list = [0, 2] task11.finish_time_list = [3, 5] task12.start_time_list = [1] task12.ready_time_list = [2] task12.finish_time_list = [5] task2.start_time_list = [1] task2.ready_time_list = [2] task2.finish_time_list = [5] init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0) timedelta = datetime.timedelta(days=1) product.create_gantt_plotly(init_datetime, timedelta, save_fig_path="test.png") if os.path.exists("test.png"): os.remove("test.png")
def test_create_data_for_gantt_plotly(): c1 = BaseComponent("c1") task11 = BaseTask("task11") task12 = BaseTask("task12") c1.extend_targeted_task_list([task11, task12]) c2 = BaseComponent("c2") task2 = BaseTask("task2") c2.append_targeted_task(task2) product = BaseProduct([c1, c2]) # Set test case task11.start_time_list = [0, 2] task11.ready_time_list = [0, 2] task11.finish_time_list = [3, 5] task12.start_time_list = [1] task12.ready_time_list = [2] task12.finish_time_list = [5] task2.start_time_list = [1] task2.ready_time_list = [2] task2.finish_time_list = [5] init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0) timedelta = datetime.timedelta(days=1) df = product.create_data_for_gantt_plotly(init_datetime, timedelta) assert df[0]["Start"] == (init_datetime + 0 * timedelta).strftime("%Y-%m-%d %H:%M:%S") assert df[0]["Finish"] == ( init_datetime + (5 + 1.0) * timedelta).strftime("%Y-%m-%d %H:%M:%S") assert df[0]["Type"] == "Component" assert df[1]["Start"] == (init_datetime + 1 * timedelta).strftime("%Y-%m-%d %H:%M:%S") assert df[1]["Finish"] == ( init_datetime + (5 + 1.0) * timedelta).strftime("%Y-%m-%d %H:%M:%S") assert df[1]["Type"] == "Component"
def test_check_removing_placed_workplace(): """test_check_removing_placed_workplace.""" c1 = BaseComponent("c1") task1 = BaseTask("task1") c1.append_targeted_task(task1) c2 = BaseComponent("c2") task2 = BaseTask("task2") c2.append_targeted_task(task2) product = BaseProduct([c1, c2]) f1 = BaseWorkplace("f1") f2 = BaseWorkplace("f2") c1.placed_workplace = f1 c2.placed_workplace = f2 f1.set_placed_component(c1) f2.set_placed_component(c2) # case1 task1.state = BaseTaskState.WORKING task2.state = BaseTaskState.FINISHED product.check_removing_placed_workplace() assert c1.placed_workplace.name == "f1" assert c2.placed_workplace is None # case2 task1.state = BaseTaskState.FINISHED task2.state = BaseTaskState.FINISHED c1.append_child_component(c2) c1.placed_workplace = f1 c2.placed_workplace = f1 f1.placed_component_list = [c1, c2] product.check_removing_placed_workplace() assert c1.placed_workplace is None assert c2.placed_workplace is None
def test_perform(): auto = BaseTask("a", auto_task=True, state=BaseTaskState.WORKING) auto.perform(0, seed=1234) assert auto.remaining_work_amount == auto.default_work_amount - 1 task = BaseTask("task") task.state = BaseTaskState.READY w1 = BaseWorker("w1") w2 = BaseWorker("w2") w1.workamount_skill_mean_map = {"task": 1.0} task.allocated_worker_list = [w1, w2] w1.assigned_task_list = [task] w2.assigned_task_list = [task] c = BaseComponent("a") c.append_targeted_task(task) task.perform(10) assert task.remaining_work_amount == task.default_work_amount assert task.target_component == c # assert c.error == 0.0 task.state = BaseTaskState.WORKING task.perform(10) assert task.remaining_work_amount == task.default_work_amount - 1.0 assert task.target_component == c # assert c.error == 0.0 # Next test case w1.workamount_skill_sd_map = {"task": 0.2} # w1.quality_skill_mean_map = {"task": 0.9} # w1.quality_skill_sd_map = {"task": 0.02} task.perform(11, seed=1234) assert task.remaining_work_amount == 7.905712967253502
def test_append_targeted_task(): c = BaseComponent("c") assert c.parent_component_list == [] task = BaseTask("task1") assert task.target_component is None c.append_targeted_task(task) assert c.targeted_task_list == [task] assert task.target_component == c
def test_perform(): task = BaseTask("task") task.state = BaseTaskState.WORKING w1 = BaseResource("w1") w2 = BaseResource("w2") w1.workamount_skill_mean_map = {"task": 1.0} task.allocated_worker_list = [w1, w2] w1.assigned_task_list = [task] w2.assigned_task_list = [task] c = BaseComponent("a") c.append_targeted_task(task) w = BaseWorkflow([task]) w.perform(10) assert task.remaining_work_amount == task.default_work_amount - 1.0 assert task.target_component == c
def test_create_simple_gantt(): c1 = BaseComponent("c1") task11 = BaseTask("task11") task12 = BaseTask("task12") c1.extend_targeted_task_list([task11, task12]) c2 = BaseComponent("c2") task2 = BaseTask("task2") c2.append_targeted_task(task2) product = BaseProduct([c1, c2]) # Set test case task11.start_time_list = [1, 5] task11.ready_time_list = [0, 4] task11.finish_time_list = [2, 6] task12.start_time_list = [2] task12.ready_time_list = [1] task12.finish_time_list = [5] task2.start_time_list = [2] task2.ready_time_list = [1] task2.finish_time_list = [5] product.create_simple_gantt(save_fig_path="test.png") if os.path.exists("test.png"): os.remove("test.png")
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 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_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