Ejemplo n.º 1
0
def test_create_data_for_gantt_plotly():
    """test_create_data_for_gantt_plotly."""
    c1 = BaseComponent("c1")
    c2 = BaseComponent("c2")
    product = BaseProduct([c1, c2])

    # Set test case
    c1.state_record_list = [
        BaseTaskState.READY,
        BaseTaskState.WORKING,
        BaseTaskState.FINISHED,
        BaseTaskState.WORKING,
        BaseTaskState.WORKING,
        BaseTaskState.FINISHED,
    ]
    c2.state_record_list = [
        BaseTaskState.WORKING,
        BaseTaskState.WORKING,
        BaseTaskState.FINISHED,
        BaseTaskState.WORKING,
        BaseTaskState.FINISHED,
        BaseTaskState.FINISHED,
    ]

    init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0)
    timedelta = datetime.timedelta(days=1)
    product.create_data_for_gantt_plotly(init_datetime, timedelta)
Ejemplo n.º 2
0
def test_create_gantt_plotly(tmpdir):
    """test_create_gantt_plotly."""
    c1 = BaseComponent("c1")
    c2 = BaseComponent("c2")
    product = BaseProduct([c1, c2])

    # Set test case
    c1.state_record_list = [
        BaseTaskState.READY,
        BaseTaskState.WORKING,
        BaseTaskState.FINISHED,
        BaseTaskState.WORKING,
        BaseTaskState.WORKING,
        BaseTaskState.FINISHED,
    ]
    c2.state_record_list = [
        BaseTaskState.WORKING,
        BaseTaskState.WORKING,
        BaseTaskState.FINISHED,
        BaseTaskState.WORKING,
        BaseTaskState.FINISHED,
        BaseTaskState.FINISHED,
    ]

    init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0)
    timedelta = datetime.timedelta(days=1)
    for ext in ["png", "html", "json"]:
        save_fig_path = os.path.join(str(tmpdir), "test." + ext)
        product.create_gantt_plotly(init_datetime,
                                    timedelta,
                                    save_fig_path=save_fig_path)
Ejemplo n.º 3
0
def test_plot_simple_gantt(tmpdir):
    """test_plot_simple_gantt."""
    c1 = BaseComponent("c1")
    c2 = BaseComponent("c2")
    product = BaseProduct([c1, c2])

    # Set test case
    c1.state_record_list = [
        BaseTaskState.READY,
        BaseTaskState.WORKING,
        BaseTaskState.FINISHED,
        BaseTaskState.WORKING,
        BaseTaskState.WORKING,
        BaseTaskState.FINISHED,
    ]
    c2.state_record_list = [
        BaseTaskState.WORKING,
        BaseTaskState.WORKING,
        BaseTaskState.FINISHED,
        BaseTaskState.WORKING,
        BaseTaskState.FINISHED,
        BaseTaskState.FINISHED,
    ]

    for ext in ["png"]:
        save_fig_path = os.path.join(str(tmpdir), "test." + ext)
        product.plot_simple_gantt(save_fig_path=save_fig_path)
Ejemplo n.º 4
0
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"
Ejemplo n.º 5
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")
Ejemplo n.º 6
0
def test_get_networkx_graph():
    c1 = BaseComponent("c1")
    c2 = BaseComponent("c2")
    c3 = BaseComponent("c3")
    c2.parent_component_list = [c1]
    c2.child_component_list = [c3]
    product = BaseProduct([c3, c2, c1])
    product.get_networkx_graph()
Ejemplo n.º 7
0
def test_get_node_and_edge_trace_for_plotly_network():
    c1 = BaseComponent("c1")
    c2 = BaseComponent("c2")
    c3 = BaseComponent("c3")
    c2.parent_component_list = [c1]
    c2.child_component_list = [c3]
    product = BaseProduct([c3, c2, c1])
    node_trace, edge_trace = product.get_node_and_edge_trace_for_plotly_network(
    )
Ejemplo n.º 8
0
def test_draw_plotly_network():
    c1 = BaseComponent("c1")
    c2 = BaseComponent("c2")
    c3 = BaseComponent("c3")
    c2.parent_component_list = [c1]
    c2.child_component_list = [c3]
    product = BaseProduct([c3, c2, c1])
    product.draw_plotly_network(save_fig_path="test.png")
    if os.path.exists("test.png"):
        os.remove("test.png")
Ejemplo n.º 9
0
def test_draw_plotly_network(tmpdir):
    """test_draw_plotly_network."""
    c1 = BaseComponent("c1")
    c2 = BaseComponent("c2")
    c3 = BaseComponent("c3")
    c2.parent_component_list = [c1]
    c2.child_component_list = [c3]
    product = BaseProduct([c3, c2, c1])
    for ext in ["png", "html", "json"]:
        save_fig_path = os.path.join(str(tmpdir), "test." + ext)
        product.draw_plotly_network(save_fig_path=save_fig_path)
Ejemplo n.º 10
0
def test_get_component_list():
    """test_get_component_list."""
    # TODO if we have enough time for setting test case...
    c1 = BaseComponent("c1")
    product = BaseProduct([c1])
    assert (len(
        product.get_component_list(
            name="test",
            ID="test",
            parent_component_list=[],
            child_component_list=[],
            targeted_task_list=[],
            space_size=99876,
            placed_workplace="test",
            placed_workplace_id_record=[],
        ))) == 0
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
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
Ejemplo n.º 13
0
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")
Ejemplo n.º 14
0
def dummy_simple_project(scope="function"):
    c = BaseComponent("c", space_size=1.0)
    task1 = BaseTask("task1", default_work_amount=2.0)
    task2 = BaseTask("task2", default_work_amount=2.0)
    auto_task2 = BaseTask("auto_task2",
                          auto_task=True,
                          default_work_amount=2.0)
    task2.append_input_task(auto_task2)
    task3 = BaseTask("task3", default_work_amount=2.0)
    auto_task3 = BaseTask("auto_task3",
                          auto_task=True,
                          default_work_amount=4.0)
    task3.append_input_task(auto_task3)
    workflow = BaseWorkflow([task1, task2, task3, auto_task2, auto_task3])
    c.extend_targeted_task_list([task1, task2, task3])
    product = BaseProduct([c])

    # BaseTeams in BaseOrganization
    team = BaseTeam("team")
    team.extend_targeted_task_list([task1, task2, task3])

    # BaseWorkers in each BaseTeam
    w1 = BaseWorker("w1", team_id=team.ID)
    w1.workamount_skill_mean_map = {
        task1.name: 1.0,
    }
    team.add_worker(w1)
    w2 = BaseWorker("w1", team_id=team.ID)
    w2.workamount_skill_mean_map = {
        task2.name: 1.0,
    }
    team.add_worker(w2)
    w3 = BaseWorker("w3", team_id=team.ID)
    w3.workamount_skill_mean_map = {
        task3.name: 1.0,
    }
    team.add_worker(w3)

    project = BaseProject(
        init_datetime=datetime.datetime(2020, 4, 1, 8, 0, 0),
        unit_timedelta=datetime.timedelta(days=1),
        product=product,
        workflow=workflow,
        organization=BaseOrganization(team_list=[team]),
    )
    return project
Ejemplo n.º 15
0
def dummy_product_for_extracting(scope="function"):
    """dummy_product_for_extracting."""
    component1 = BaseComponent("component1")
    component1.state_record_list = [
        BaseComponentState.WORKING,
        BaseComponentState.FINISHED,
        BaseComponentState.FINISHED,
        BaseComponentState.FINISHED,
        BaseComponentState.FINISHED,
    ]
    component2 = BaseComponent("component2")
    component2.state_record_list = [
        BaseComponentState.WORKING,
        BaseComponentState.WORKING,
        BaseComponentState.FINISHED,
        BaseComponentState.FINISHED,
        BaseComponentState.FINISHED,
    ]
    component3 = BaseComponent("component3")
    component3.state_record_list = [
        BaseComponentState.READY,
        BaseComponentState.WORKING,
        BaseComponentState.WORKING,
        BaseComponentState.FINISHED,
        BaseComponentState.FINISHED,
    ]
    component4 = BaseComponent("component4")
    component4.state_record_list = [
        BaseComponentState.NONE,
        BaseComponentState.READY,
        BaseComponentState.WORKING,
        BaseComponentState.WORKING,
        BaseComponentState.FINISHED,
    ]
    component5 = BaseComponent("component5")
    component5.state_record_list = [
        BaseComponentState.NONE,
        BaseComponentState.NONE,
        BaseComponentState.READY,
        BaseComponentState.READY,
        BaseComponentState.WORKING,
    ]
    return BaseProduct(
        [component1, component2, component3, component4, component5])
Ejemplo n.º 16
0
def test_remove_insert_absence_time_list():
    """test_remove_insert_absence_time_list."""
    c1 = BaseComponent("c1", "----")
    c1.placed_workplace_id_record = ["aa", "bb", "cc", "dd", "ee", "ff"]
    c1.state_record_list = [0, 1, 2, 3, 4, 5]

    c2 = BaseComponent("c2", "----")
    c2.placed_workplace_id_record = ["ff", "ee", "dd", "cc", "bb", "aa"]
    c2.state_record_list = [5, 4, 3, 2, 1, 0]
    c2.append_child_component(c1)

    product = BaseProduct([c1, c2])

    absence_time_list = [0, 1]
    product.remove_absence_time_list(absence_time_list)
    assert c1.placed_workplace_id_record == ["cc", "dd", "ee", "ff"]
    assert c1.state_record_list == [2, 3, 4, 5]
    assert c2.placed_workplace_id_record == ["dd", "cc", "bb", "aa"]
    assert c2.state_record_list == [3, 2, 1, 0]

    product.insert_absence_time_list(absence_time_list)
    assert c1.placed_workplace_id_record == [
        None, None, "cc", "dd", "ee", "ff"
    ]
    assert c1.state_record_list == [
        BaseComponentState.NONE,
        BaseComponentState.READY,
        2,
        3,
        4,
        5,
    ]
    assert c2.placed_workplace_id_record == [
        None, None, "dd", "cc", "bb", "aa"
    ]
    assert c2.state_record_list == [
        BaseComponentState.NONE,
        BaseComponentState.NONE,
        3,
        2,
        1,
        0,
    ]
Ejemplo n.º 17
0
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
Ejemplo n.º 18
0
def test_str():
    print(BaseProduct([]))
Ejemplo n.º 19
0
def test_str():
    """test_str."""
    print(BaseProduct([]))
Ejemplo n.º 20
0
def test_initialize():
    c1 = BaseComponent("c1")
    product = BaseProduct([c1])
    product.initialize()
Ejemplo n.º 21
0
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
Ejemplo n.º 22
0
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
Ejemplo n.º 23
0
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
Ejemplo n.º 24
0
def test_init():
    c1 = BaseComponent("c1")
    product = BaseProduct([c1])
    assert product.component_list == [c1]