Ejemplo n.º 1
0
def test_create_data_for_cost_history_plotly():
    """test_create_data_for_cost_history_plotly."""
    workplace = BaseWorkplace("workplace")
    w1 = BaseFacility("w1", cost_per_time=10.0)
    w1.cost_list = [0, 0, 10, 10, 0, 10]
    w2 = BaseFacility("w2", cost_per_time=5.0)
    w2.cost_list = [5, 5, 0, 0, 5, 5]
    workplace.facility_list = [w1, w2]
    workplace.cost_list = list(map(sum, zip(w1.cost_list, w2.cost_list)))

    init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0)
    timedelta = datetime.timedelta(days=1)
    data = workplace.create_data_for_cost_history_plotly(init_datetime, timedelta)

    x = [
        (init_datetime + time * timedelta).strftime("%Y-%m-%d %H:%M:%S")
        for time in range(len(workplace.cost_list))
    ]
    # w1
    assert data[0].name == w1.name
    assert data[0].x == tuple(x)
    assert data[0].y == tuple(w1.cost_list)

    # w2
    assert data[1].name == w2.name
    assert data[1].x == tuple(x)
    assert data[1].y == tuple(w2.cost_list)
Ejemplo n.º 2
0
def test_add_facility():
    """test_add_facility."""
    workplace = BaseWorkplace("workplace")
    facility = BaseFacility("facility")
    workplace.add_facility(facility)
    assert len(workplace.facility_list) == 1
    assert facility.workplace_id == workplace.ID
Ejemplo n.º 3
0
def test_init():
    """test_init."""
    workplace = BaseWorkplace("workplace")
    assert workplace.name == "workplace"
    assert len(workplace.ID) > 0
    assert workplace.facility_list == []
    assert workplace.targeted_task_list == []
    assert workplace.parent_workplace is None
    assert workplace.max_space_size == 1.0
    assert workplace.input_workplace_list == []
    assert workplace.output_workplace_list == []
    assert workplace.cost_list == []
    workplace.cost_list.append(1)
    assert workplace.cost_list == [1.0]

    w1 = BaseFacility("w1")
    t1 = BaseTask("task1")
    workplace1 = BaseWorkplace(
        "workplace1",
        parent_workplace=workplace,
        targeted_task_list=[t1],
        facility_list=[w1],
        max_space_size=2.0,
        cost_list=[10],
        placed_component_list=[BaseComponent("c")],
        placed_component_id_record=["xxxx"],
    )
    assert workplace1.facility_list == [w1]
    assert workplace1.targeted_task_list == [t1]
    assert workplace1.parent_workplace == workplace
    assert workplace1.max_space_size == 2.0
    assert workplace1.cost_list == [10]
    assert workplace1.placed_component_list[0].name == "c"
    assert workplace1.placed_component_id_record == ["xxxx"]
Ejemplo n.º 4
0
def test_get_facility_list():
    """test_get_facility_list."""
    # TODO if we have enough time for setting test case...
    workplace = BaseWorkplace("workplace")
    w1 = BaseFacility("w1", cost_per_time=10.0)
    w2 = BaseFacility("w2", cost_per_time=5.0)
    workplace.facility_list = [w2, w1]
    assert (
        len(
            workplace.get_facility_list(
                name="test",
                ID="test",
                workplace_id="test",
                cost_per_time=99876,
                solo_working=True,
                workamount_skill_mean_map={},
                workamount_skill_sd_map=[],
                state=BaseFacilityState.WORKING,
                cost_list=[],
                assigned_task_list=[],
                assigned_task_id_record=[],
            )
        )
        == 0
    )
Ejemplo n.º 5
0
def test_create_data_for_gantt_plotly():
    """test_create_data_for_gantt_plotly."""
    workplace = BaseWorkplace("workplace")
    w1 = BaseFacility("w1", cost_per_time=10.0)
    w1.state_record_list = [
        BaseFacilityState.WORKING,
        BaseFacilityState.WORKING,
        BaseFacilityState.FREE,
        BaseFacilityState.WORKING,
        BaseFacilityState.FREE,
        BaseFacilityState.FREE,
    ]
    w2 = BaseFacility("w2", cost_per_time=5.0)
    w2.state_record_list = [
        BaseFacilityState.WORKING,
        BaseFacilityState.WORKING,
        BaseFacilityState.FREE,
        BaseFacilityState.WORKING,
        BaseFacilityState.FREE,
        BaseFacilityState.FREE,
    ]
    workplace.facility_list = [w1, w2]

    init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0)
    timedelta = datetime.timedelta(days=1)
    workplace.create_data_for_gantt_plotly(init_datetime, timedelta)
Ejemplo n.º 6
0
def test_extend_targeted_task_list():
    """test_extend_targeted_task_list."""
    workplace = BaseWorkplace("workplace")
    task1 = BaseTask("task1")
    task2 = BaseTask("task2")
    workplace.extend_targeted_task_list([task1, task2])
    assert workplace.targeted_task_list == [task1, task2]
    assert task1.allocated_workplace_list == [workplace]
    assert task2.allocated_workplace_list == [workplace]
Ejemplo n.º 7
0
def test_append_targeted_task():
    """test_append_targeted_task."""
    workplace = BaseWorkplace("workplace")
    task1 = BaseTask("task1")
    task2 = BaseTask("task2")
    workplace.append_targeted_task(task1)
    workplace.append_targeted_task(task2)
    assert workplace.targeted_task_list == [task1, task2]
    assert task1.allocated_workplace_list == [workplace]
    assert task2.allocated_workplace_list == [workplace]
Ejemplo n.º 8
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.º 9
0
def dummy_organization(scope="function"):
    """dummy_organization."""
    c1 = BaseTeam("c1")
    w11 = BaseWorker("w11", cost_per_time=10.0)
    w12 = BaseWorker("w12", cost_per_time=5.0)
    w11.state_record_list = [
        BaseWorkerState.WORKING,
        BaseWorkerState.WORKING,
        BaseWorkerState.FREE,
        BaseWorkerState.WORKING,
        BaseWorkerState.FREE,
        BaseWorkerState.FREE,
    ]
    w12.state_record_list = [
        BaseWorkerState.WORKING,
        BaseWorkerState.WORKING,
        BaseWorkerState.FREE,
        BaseWorkerState.WORKING,
        BaseWorkerState.FREE,
        BaseWorkerState.FREE,
    ]
    c1.worker_list = [w11, w12]

    c2 = BaseTeam("c2")
    w2 = BaseWorker("w2", cost_per_time=5.0)
    w2.state_record_list = [
        BaseWorkerState.WORKING,
        BaseWorkerState.WORKING,
        BaseWorkerState.FREE,
        BaseWorkerState.WORKING,
        BaseWorkerState.FREE,
        BaseWorkerState.FREE,
    ]
    c2.worker_list = [w2]
    c2.parent_team = c1

    f = BaseFacility("f", cost_per_time=20.0)
    f.state_record_list = [
        BaseFacilityState.WORKING,
        BaseFacilityState.WORKING,
        BaseFacilityState.FREE,
        BaseFacilityState.WORKING,
        BaseFacilityState.FREE,
        BaseFacilityState.FREE,
    ]
    workplace = BaseWorkplace("workplace", facility_list=[f])

    dummy_workplace = BaseWorkplace("dummy")
    workplace.parent_workplace = dummy_workplace

    organization = BaseOrganization(
        team_list=[c1, c2], workplace_list=[workplace, dummy_workplace])
    return organization
Ejemplo n.º 10
0
def test_can_put():
    """test_can_put."""
    c1 = BaseComponent("c1", space_size=2.0)
    c2 = BaseComponent("c2", space_size=2.0)
    workplace = BaseWorkplace("f", max_space_size=1.0)
    assert workplace.can_put(c1) is False
    assert workplace.can_put(c2) is False
    workplace.max_space_size = 3.0
    assert workplace.can_put(c1) is True
    assert workplace.can_put(c2) is True
    workplace.set_placed_component(c1)
    assert workplace.can_put(c2) is False
    workplace.max_space_size = 4.0
    assert workplace.can_put(c2) is True
Ejemplo n.º 11
0
def test_init():
    """test_init."""
    c1 = BaseComponent("c1")
    assert c1.name == "c1"
    assert len(c1.ID) > 0

    c2 = BaseComponent("c2")
    task = BaseTask("task")
    c = BaseComponent(
        "c",
        ID="xx88xx",
        child_component_list=[c1],
        parent_component_list=[c2],
        targeted_task_list=[task],
        space_size=2.0,
        state=BaseComponentState.FINISHED,
        state_record_list=["aa"],
        placed_workplace=BaseWorkplace("t"),
        placed_workplace_id_record=["fff"],
    )
    assert c.name == "c"
    assert c.ID == "xx88xx"
    assert c.child_component_list == [c1]
    assert c.parent_component_list == [c2]
    assert c.targeted_task_list == [task]
    assert c.space_size == 2.0
    assert c.placed_workplace.name == "t"
    assert c.placed_workplace_id_record == ["fff"]
Ejemplo n.º 12
0
def test_create_gantt_plotly(tmpdir):
    """test_create_gantt_plotly."""
    workplace = BaseWorkplace("workplace")
    w1 = BaseFacility("w1", cost_per_time=10.0)
    w1.state_record_list = [
        BaseFacilityState.WORKING,
        BaseFacilityState.WORKING,
        BaseFacilityState.FREE,
        BaseFacilityState.WORKING,
        BaseFacilityState.FREE,
        BaseFacilityState.FREE,
    ]
    w2 = BaseFacility("w2", cost_per_time=5.0)
    w2.state_record_list = [
        BaseFacilityState.WORKING,
        BaseFacilityState.WORKING,
        BaseFacilityState.FREE,
        BaseFacilityState.WORKING,
        BaseFacilityState.FREE,
        BaseFacilityState.FREE,
    ]
    workplace.facility_list = [w1, w2]

    init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0)
    timedelta = datetime.timedelta(days=1)
    workplace.create_gantt_plotly(
        init_datetime, timedelta, save_fig_path=os.path.join(str(tmpdir), "test.png")
    )

    for ext in ["png", "html", "json"]:
        save_fig_path = os.path.join(str(tmpdir), "test." + ext)
        workplace.create_gantt_plotly(
            init_datetime, timedelta, save_fig_path=save_fig_path
        )
Ejemplo n.º 13
0
def test_remove_insert_absence_time_list():
    """test_remove_insert_absence_time_list."""
    f1 = BaseFacility("w1", "----")
    f1.cost_list = [1.0, 0.0, 1.0, 0.0, 0.0, 1.0]
    f1.assigned_task_id_record = ["aa", "bb", "cc", "dd", "ee", "ff"]
    f1.state_record_list = [2, 1, 2, 1, 1, 2]

    f2 = BaseFacility("w1", "----")
    f2.cost_list = [1.0, 0.0, 1.0, 0.0, 0.0, 1.0]
    f2.assigned_task_id_record = ["aa", "bb", "cc", "dd", "ee", "ff"]
    f2.state_record_list = [2, 1, 2, 1, 1, 2]

    workplace = BaseWorkplace("aa", facility_list=[f1, f2])
    workplace.cost_list = [2.0, 0.0, 2.0, 0.0, 0.0, 2.0]

    absence_time_list = [1, 3, 4]
    workplace.remove_absence_time_list(absence_time_list)
    assert workplace.cost_list == [2.0, 2.0, 2.0]
    assert f1.cost_list == [1.0, 1.0, 1.0]
    assert f1.assigned_task_id_record == ["aa", "cc", "ff"]
    assert f1.state_record_list == [2, 2, 2]
    assert f2.cost_list == [1.0, 1.0, 1.0]
    assert f2.assigned_task_id_record == ["aa", "cc", "ff"]
    assert f2.state_record_list == [2, 2, 2]

    workplace.insert_absence_time_list(absence_time_list)
    assert workplace.cost_list == [2.0, 0.0, 2.0, 0.0, 0.0, 2.0]
    assert f1.cost_list == [1.0, 0.0, 1.0, 0.0, 0.0, 1.0]
    assert f1.assigned_task_id_record == ["aa", "aa", "cc", "cc", "cc", "ff"]
    assert f1.state_record_list == [2, 0, 2, 0, 0, 2]
    assert f2.cost_list == [1.0, 0.0, 1.0, 0.0, 0.0, 1.0]
    assert f2.assigned_task_id_record == ["aa", "aa", "cc", "cc", "cc", "ff"]
    assert f2.state_record_list == [2, 0, 2, 0, 0, 2]
Ejemplo n.º 14
0
def test_initialize():
    """test_initialize."""
    team = BaseWorkplace("team")
    w = BaseFacility("w1", workplace_id=team.ID)
    w.state = BaseFacilityState.WORKING
    w.cost_list = [9.0, 7.2]
    w.assigned_task_list = [BaseTask("task")]
    w.initialize()
    assert w.state == BaseFacilityState.FREE
    assert w.cost_list == []
    assert w.assigned_task_list == []
Ejemplo n.º 15
0
def test_get_available_space_size():
    """test_get_available_space_size."""
    max_space_size = 5.0
    workplace = BaseWorkplace("f", max_space_size=max_space_size)
    assert workplace.get_available_space_size() == max_space_size
    c1_space_size = 3.0
    workplace.set_placed_component(BaseComponent("c1", space_size=c1_space_size))
    assert workplace.get_available_space_size() == max_space_size - c1_space_size
Ejemplo n.º 16
0
def test_plot_simple_gantt():
    """test_plot_simple_gantt."""
    workplace = BaseWorkplace("workplace")
    w1 = BaseFacility("w1", cost_per_time=10.0)
    w1.state_record_list = [
        BaseFacilityState.WORKING,
        BaseFacilityState.WORKING,
        BaseFacilityState.FREE,
        BaseFacilityState.WORKING,
        BaseFacilityState.FREE,
        BaseFacilityState.FREE,
    ]
    w2 = BaseFacility("w2", cost_per_time=5.0)
    w2.state_record_list = [
        BaseFacilityState.WORKING,
        BaseFacilityState.WORKING,
        BaseFacilityState.FREE,
        BaseFacilityState.WORKING,
        BaseFacilityState.FREE,
        BaseFacilityState.FREE,
    ]
    workplace.facility_list = [w1, w2]
    workplace.plot_simple_gantt()
Ejemplo n.º 17
0
def test_extend_input_workplace_list():
    """test_extend_input_workplace_list."""
    workplace11 = BaseWorkplace("workplace11")
    workplace12 = BaseWorkplace("workplace12")
    workplace2 = BaseWorkplace("workplace2")
    workplace2.extend_input_workplace_list([workplace11, workplace12])
    assert workplace2.input_workplace_list == [workplace11, workplace12]
    assert workplace11.output_workplace_list == [workplace2]
    assert workplace12.output_workplace_list == [workplace2]
Ejemplo n.º 18
0
def test_append_input_workplace():
    """test_append_input_workplace."""
    workplace = BaseWorkplace("workplace")
    workplace1 = BaseWorkplace("workplace1")
    workplace2 = BaseWorkplace("workplace2")
    workplace.append_input_workplace(workplace1)
    workplace.append_input_workplace(workplace2)
    assert workplace.input_workplace_list == [workplace1, workplace2]
    assert workplace1.output_workplace_list == [workplace]
    assert workplace2.output_workplace_list == [workplace]
Ejemplo n.º 19
0
def test_remove_placed_component():
    """test_remove_placed_component."""
    c = BaseComponent("c")
    c1 = BaseComponent("c1")
    c2 = BaseComponent("c2")
    c.append_child_component(c1)
    c1.append_child_component(c2)
    workplace = BaseWorkplace("workplace")
    workplace.set_placed_component(c)
    assert workplace.placed_component_list == [c, c1, c2]
    workplace.remove_placed_component(c)
    assert workplace.placed_component_list == []
Ejemplo n.º 20
0
def test_add_labor_cost():
    """test_add_labor_cost."""
    workplace = BaseWorkplace("workplace")
    w1 = BaseFacility("w1", cost_per_time=10.0)
    w2 = BaseFacility("w2", cost_per_time=5.0)
    workplace.facility_list = [w2, w1]
    w1.state = BaseFacilityState.WORKING
    w2.state = BaseFacilityState.FREE
    workplace.add_labor_cost()
    assert w1.cost_list == [10.0]
    assert w2.cost_list == [0.0]
    assert workplace.cost_list == [10.0]
    workplace.add_labor_cost(only_working=False)
    assert workplace.cost_list == [10.0, 15.0]
    assert w1.cost_list == [10.0, 10.0]
    assert w2.cost_list == [0.0, 5.0]
Ejemplo n.º 21
0
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]
    )
Ejemplo n.º 22
0
def test_set_placed_workplace():
    """test_set_placed_workplace."""
    c = BaseComponent("c")
    c1 = BaseComponent("c1")
    c2 = BaseComponent("c2")
    c.append_child_component(c1)
    c1.append_child_component(c2)
    workplace = BaseWorkplace("workplace")

    c.set_placed_workplace(workplace, set_to_all_children=False)
    assert c.placed_workplace == workplace
    assert c1.placed_workplace is None
    assert c2.placed_workplace is None

    c.set_placed_workplace(workplace, set_to_all_children=True)
    assert c.placed_workplace == workplace
    assert c1.placed_workplace == workplace
    assert c2.placed_workplace == workplace
Ejemplo n.º 23
0
def test_create_cost_history_plotly(tmpdir):
    """test_create_cost_history_plotly."""
    workplace = BaseWorkplace("workplace")
    w1 = BaseFacility("w1", cost_per_time=10.0)
    w1.cost_list = [0, 0, 10, 10, 0, 10]
    w2 = BaseFacility("w2", cost_per_time=5.0)
    w2.cost_list = [5, 5, 0, 0, 5, 5]
    workplace.facility_list = [w1, w2]
    workplace.cost_list = list(map(sum, zip(w1.cost_list, w2.cost_list)))

    init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0)
    timedelta = datetime.timedelta(days=1)
    workplace.create_cost_history_plotly(init_datetime, timedelta)

    for ext in ["png", "html", "json"]:
        save_fig_path = os.path.join(str(tmpdir), "test." + ext)
        workplace.create_cost_history_plotly(
            init_datetime, timedelta, title="bbbbbbb", save_fig_path=save_fig_path
        )
        if os.path.exists(save_fig_path):
            os.remove(save_fig_path)
Ejemplo n.º 24
0
def test_initialize():
    """test_initialize."""
    workplace = BaseWorkplace("workplace")
    workplace.cost_list = [9.0, 7.2]
    w = BaseFacility("w1")
    workplace.facility_list = [w]
    w.state = BaseFacilityState.WORKING
    w.cost_list = [9.0, 7.2]
    w.assigned_task_list = [BaseTask("task")]
    workplace.initialize()
    assert workplace.cost_list == []
    assert w.state == BaseFacilityState.FREE
    assert w.cost_list == []
    assert w.assigned_task_list == []
Ejemplo n.º 25
0
def test_remove_insert_absence_time_list():
    """test_remove_insert_absence_time_list."""
    f1 = BaseFacility("w1", "----")
    f1.cost_list = [1.0, 0.0, 1.0, 0.0, 0.0, 1.0]
    f1.assigned_task_id_record = ["aa", "bb", "cc", "dd", "ee", "ff"]
    f1.state_record_list = [2, 1, 2, 1, 1, 2]

    f2 = BaseFacility("w1", "----")
    f2.cost_list = [1.0, 0.0, 1.0, 0.0, 0.0, 1.0]
    f2.assigned_task_id_record = ["aa", "bb", "cc", "dd", "ee", "ff"]
    f2.state_record_list = [2, 1, 2, 1, 1, 2]

    workplace = BaseWorkplace("aa", facility_list=[f1, f2])
    workplace.cost_list = [2.0, 0.0, 2.0, 0.0, 0.0, 2.0]

    w1 = BaseWorker("w1", "----")
    w1.cost_list = [1.0, 0.0, 1.0, 0.0, 0.0, 1.0]
    w1.assigned_task_id_record = ["aa", "bb", "cc", "dd", "ee", "ff"]
    w1.state_record_list = [2, 1, 2, 1, 1, 2]

    w2 = BaseWorker("w1", "----")
    w2.cost_list = [1.0, 0.0, 1.0, 0.0, 0.0, 1.0]
    w2.assigned_task_id_record = ["aa", "bb", "cc", "dd", "ee", "ff"]
    w2.state_record_list = [2, 1, 2, 1, 1, 2]

    team = BaseTeam("aa", worker_list=[w1, w2])
    team.cost_list = [2.0, 0.0, 2.0, 0.0, 0.0, 2.0]

    organization = BaseOrganization(team_list=[team],
                                    workplace_list=[workplace])
    organization.cost_list = [4.0, 0.0, 4.0, 0.0, 0.0, 4.0]

    absence_time_list = [1, 3, 4]
    organization.remove_absence_time_list(absence_time_list)
    assert organization.cost_list == [4.0, 4.0, 4.0]
    assert workplace.cost_list == [2.0, 2.0, 2.0]
    assert f1.cost_list == [1.0, 1.0, 1.0]
    assert f1.assigned_task_id_record == ["aa", "cc", "ff"]
    assert f1.state_record_list == [2, 2, 2]
    assert f2.cost_list == [1.0, 1.0, 1.0]
    assert f2.assigned_task_id_record == ["aa", "cc", "ff"]
    assert f2.state_record_list == [2, 2, 2]
    assert team.cost_list == [2.0, 2.0, 2.0]
    assert w1.cost_list == [1.0, 1.0, 1.0]
    assert w1.assigned_task_id_record == ["aa", "cc", "ff"]
    assert w1.state_record_list == [2, 2, 2]
    assert w2.cost_list == [1.0, 1.0, 1.0]
    assert w2.assigned_task_id_record == ["aa", "cc", "ff"]
    assert w2.state_record_list == [2, 2, 2]

    organization.insert_absence_time_list(absence_time_list)
    assert organization.cost_list == [4.0, 0.0, 4.0, 0.0, 0.0, 4.0]
    assert team.cost_list == [2.0, 0.0, 2.0, 0.0, 0.0, 2.0]
    assert w1.cost_list == [1.0, 0.0, 1.0, 0.0, 0.0, 1.0]
    assert w1.assigned_task_id_record == ["aa", "aa", "cc", "cc", "cc", "ff"]
    assert w1.state_record_list == [2, 0, 2, 0, 0, 2]
    assert w2.cost_list == [1.0, 0.0, 1.0, 0.0, 0.0, 1.0]
    assert w2.assigned_task_id_record == ["aa", "aa", "cc", "cc", "cc", "ff"]
    assert w2.state_record_list == [2, 0, 2, 0, 0, 2]
    assert workplace.cost_list == [2.0, 0.0, 2.0, 0.0, 0.0, 2.0]
    assert f1.cost_list == [1.0, 0.0, 1.0, 0.0, 0.0, 1.0]
    assert f1.assigned_task_id_record == ["aa", "aa", "cc", "cc", "cc", "ff"]
    assert f1.state_record_list == [2, 0, 2, 0, 0, 2]
    assert f2.cost_list == [1.0, 0.0, 1.0, 0.0, 0.0, 1.0]
    assert f2.assigned_task_id_record == ["aa", "aa", "cc", "cc", "cc", "ff"]
    assert f2.state_record_list == [2, 0, 2, 0, 0, 2]
Ejemplo n.º 26
0
def test_set_parent_workplace():
    """test_set_parent_workplace."""
    workplace = BaseWorkplace("workplace")
    workplace.set_parent_workplace(BaseWorkplace("xxx"))
    assert workplace.parent_workplace.name == "xxx"
Ejemplo n.º 27
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.º 28
0
def test_str():
    """test_str."""
    print(BaseWorkplace("aaaaaaaa"))
Ejemplo n.º 29
0
def dummy_project(scope="function"):
    """dummy_project."""
    # 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 workplace
    f1 = BaseFacility("f1")
    f1.workamount_skill_mean_map = {
        task1_1.name: 1.0,
    }
    # workplace.facility_list.append(f1)

    # Workplace in BaseOrganization
    workplace = BaseWorkplace("workplace", facility_list=[f1])
    workplace.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],
                                        workplace_list=[workplace])
    return project
Ejemplo n.º 30
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