Ejemplo n.º 1
0
def test_append_input_task():
    """test_append_input_task."""
    task1 = BaseTask("task1")
    task2 = BaseTask("task2")
    task2.append_input_task(task1)
    assert task2.input_task_list == [[task1, BaseTaskDependency.FS]]
    assert task1.output_task_list == [[task2, BaseTaskDependency.FS]]
Ejemplo n.º 2
0
def test_create_data_for_gantt_plotly():
    c = BaseComponent("c")
    task1 = BaseTask("task1")
    task2 = BaseTask("task2")
    c.extend_targeted_task_list([task1, task2])

    # Set test case (start time = 0, finish time = 5)
    task1.start_time_list = [0, 2]
    task1.ready_time_list = [0, 2]
    task1.finish_time_list = [3, 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 = 1day
    timedelta = datetime.timedelta(days=1)
    df = c.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"
Ejemplo n.º 3
0
def test_init():
    """test_init."""
    task1 = BaseTask("task1")
    task2 = BaseTask("task2")
    task2.append_input_task(task1)
    w = BaseWorkflow([task1, task2])
    assert w.task_list == [task1, task2]
    assert w.critical_path_length == 0.0
Ejemplo n.º 4
0
def test_extend_targeted_task_list():
    team = BaseTeam("team")
    task1 = BaseTask("task1")
    task2 = BaseTask("task2")
    team.extend_targeted_task_list([task1, task2])
    assert team.targeted_task_list == [task1, task2]
    assert task1.allocated_team_list == [team]
    assert task2.allocated_team_list == [team]
Ejemplo n.º 5
0
def test_extend_targeted_task_list():
    factory = BaseFactory("factory")
    task1 = BaseTask("task1")
    task2 = BaseTask("task2")
    factory.extend_targeted_task_list([task1, task2])
    assert factory.targeted_task_list == [task1, task2]
    assert task1.allocated_factory_list == [factory]
    assert task2.allocated_factory_list == [factory]
Ejemplo n.º 6
0
def test_append_targeted_task():
    team = BaseTeam("team")
    task1 = BaseTask("task1")
    task2 = BaseTask("task2")
    team.append_targeted_task(task1)
    team.append_targeted_task(task2)
    assert team.targeted_task_list == [task1, task2]
    assert task1.allocated_team_list == [team]
    assert task2.allocated_team_list == [team]
Ejemplo n.º 7
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.º 8
0
def test_extend_targeted_task_list():
    c = BaseComponent("c")
    assert c.parent_component_list == []
    task1 = BaseTask("task1")
    task2 = BaseTask("task2")
    c.extend_targeted_task_list([task1, task2])
    assert c.targeted_task_list == [task1, task2]
    assert task1.target_component == c
    assert task2.target_component == c
Ejemplo n.º 9
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.º 10
0
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
Ejemplo n.º 11
0
def test_create_data_for_gantt_plotly():
    """test_create_data_for_gantt_plotly."""
    task1 = BaseTask("task1")
    task1.state_record_list = [
        BaseTaskState.READY,
        BaseTaskState.READY,
        BaseTaskState.WORKING,
        BaseTaskState.FINISHED,
        BaseTaskState.FINISHED,
    ]
    init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0)
    timedelta = datetime.timedelta(days=1)
    task1.create_data_for_gantt_plotly(init_datetime, timedelta, view_ready=True)
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_gantt_plotly(tmpdir):
    """test_create_gantt_plotly."""
    task1 = BaseTask("task1")
    task1.state_record_list = [
        BaseTaskState.READY,
        BaseTaskState.READY,
        BaseTaskState.WORKING,
        BaseTaskState.FINISHED,
        BaseTaskState.FINISHED,
    ]
    task2 = BaseTask("task2")
    task2.state_record_list = [
        BaseTaskState.READY,
        BaseTaskState.READY,
        BaseTaskState.WORKING,
        BaseTaskState.FINISHED,
        BaseTaskState.FINISHED,
    ]
    task2.append_input_task(task1)
    w = BaseWorkflow([task1, task2])
    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)
        w.create_gantt_plotly(init_datetime,
                              timedelta,
                              save_fig_path=save_fig_path)
Ejemplo n.º 14
0
def test_get_node_and_edge_trace_for_plotly_network():
    """test_get_node_and_edge_trace_for_plotly_network."""
    task1 = BaseTask("task1")
    task1.state_record_list = [
        BaseTaskState.READY,
        BaseTaskState.READY,
        BaseTaskState.WORKING,
        BaseTaskState.FINISHED,
        BaseTaskState.FINISHED,
    ]
    task2 = BaseTask("task2")
    task2.state_record_list = [
        BaseTaskState.READY,
        BaseTaskState.READY,
        BaseTaskState.WORKING,
        BaseTaskState.FINISHED,
        BaseTaskState.FINISHED,
    ]
    task2.append_input_task(task1)
    w = BaseWorkflow([task1, task2])
    (
        task_node_trace,
        auto_task_node_trace,
        edge_trace,
    ) = w.get_node_and_edge_trace_for_plotly_network()
    # TODO
    # assert...
    (
        task_node_trace,
        auto_task_node_trace,
        edge_trace,
    ) = w.get_node_and_edge_trace_for_plotly_network()
Ejemplo n.º 15
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.º 16
0
def SF_workflow(scope="function"):
    """
    Simple workflow including StartToFinish dependency
    """
    task1 = BaseTask("task1")
    task2 = BaseTask("task2")
    task3 = BaseTask("task3")
    task2.append_input_task(task1, task_dependency_mode=BaseTaskDependency.SF)
    task3.append_input_task(task1, task_dependency_mode=BaseTaskDependency.FS)
    task3.append_input_task(task2, task_dependency_mode=BaseTaskDependency.SS)
    return BaseWorkflow([task1, task2, task3])
Ejemplo n.º 17
0
def test_init():
    task = BaseTask("task")
    assert task.name == "task"
    assert len(task.ID) > 0
    assert task.default_work_amount == 10.0
    assert task.input_task_list == []
    assert task.output_task_list == []
    assert task.due_time == -1
    assert task.allocated_team_list == []
    assert task.target_component is None
    assert task.default_progress == 0.0
    # assert task.additional_work_amount == 0.0
    assert task.est == 0.0
    assert task.eft == 0.0
    assert task.lst == -1.0
    assert task.lft == -1.0
    assert task.remaining_work_amount == task.default_work_amount * (
        1.0 - task.default_progress)
    # assert task.actual_work_amount == task.default_work_amount * (
    #     1.0 - task.default_progress
    # )
    assert task.state == BaseTaskState.NONE
    assert task.ready_time_list == []
    assert task.start_time_list == []
    assert task.finish_time_list == []
    # assert task.additional_task_flag is False
    assert task.allocated_worker_list == []

    tb = BaseTask(
        "task_b1",
        remaining_work_amount=0.0,
        state=BaseTaskState.FINISHED,
        ready_time_list=[1],
        start_time_list=[2],
        finish_time_list=[5],
        allocated_worker_list=[BaseWorker("a")],
        allocated_worker_id_record=[["idid"]],
        allocated_facility_list=[BaseFacility("b")],
        allocated_facility_id_record=[["ibib"]],
    )
    assert tb.remaining_work_amount == 0.0
    assert tb.state == BaseTaskState.FINISHED
    assert tb.ready_time_list == [1]
    assert tb.start_time_list == [2]
    assert tb.finish_time_list == [5]
    assert tb.allocated_worker_list[0].name == "a"
    assert tb.allocated_worker_id_record == [["idid"]]
    assert tb.allocated_facility_list[0].name == "b"
    assert tb.allocated_facility_id_record == [["ibib"]]
Ejemplo n.º 18
0
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
Ejemplo n.º 19
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.º 20
0
def 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,
        placed_factory=BaseFactory("t"),
        placed_factory_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_factory.name == "t"
    assert c.placed_factory_id_record == ["fff"]
Ejemplo n.º 21
0
def test_init(dummy_facility):
    """test_init."""
    # team = Team("team")
    assert dummy_facility.name == "wsss"
    assert dummy_facility.workplace_id == "---"
    assert dummy_facility.cost_per_time == 0.0
    assert not dummy_facility.solo_working
    assert dummy_facility.workamount_skill_mean_map == {}
    assert dummy_facility.workamount_skill_sd_map == {}
    # assert dummy_facility.quality_skill_mean_map == {}
    assert dummy_facility.state == BaseFacilityState.FREE
    assert dummy_facility.cost_list == []
    assert dummy_facility.assigned_task_list == []
    w = BaseFacility(
        "w1",
        solo_working=True,
        state=BaseFacilityState.WORKING,
        cost_list=[10, 10],
        state_record_list=["a"],
        assigned_task_list=[BaseTask("task")],
        assigned_task_id_record=[[], ["ss"]],
    )
    assert w.name == "w1"
    assert w.workplace_id is None
    assert w.cost_per_time == 0.0
    assert w.solo_working
    assert w.workamount_skill_mean_map == {}
    assert w.workamount_skill_sd_map == {}
    # assert w.quality_skill_mean_map == {}
    assert w.state == BaseFacilityState.WORKING
    assert w.cost_list == [10, 10]
    assert w.assigned_task_list[0].name == "task"
    assert w.assigned_task_id_record == [[], ["ss"]]
Ejemplo n.º 22
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.º 23
0
def test_init():
    factory = BaseFactory("factory")
    assert factory.name == "factory"
    assert len(factory.ID) > 0
    assert factory.facility_list == []
    assert factory.targeted_task_list == []
    assert factory.parent_factory is None
    assert factory.max_space_size == 1.0
    assert factory.cost_list == []
    factory.cost_list.append(1)
    assert factory.cost_list == [1.0]

    w1 = BaseFacility("w1")
    t1 = BaseTask("task1")
    factory1 = BaseFactory(
        "factory1",
        parent_factory=factory,
        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 factory1.facility_list == [w1]
    assert factory1.targeted_task_list == [t1]
    assert factory1.parent_factory == factory
    assert factory1.max_space_size == 2.0
    assert factory1.cost_list == [10]
    assert factory1.placed_component_list[0].name == "c"
    assert factory1.placed_component_id_record == ["xxxx"]
Ejemplo n.º 24
0
def test_init():
    """test_init."""
    team = BaseTeam("team")
    assert team.name == "team"
    assert len(team.ID) > 0
    assert team.worker_list == []
    assert team.targeted_task_list == []
    assert team.parent_team is None
    assert team.cost_list == []
    team.cost_list.append(1)
    assert team.cost_list == [1.0]

    w1 = BaseWorker("w1")
    t1 = BaseTask("task1")
    team1 = BaseTeam(
        "team1",
        parent_team=team,
        targeted_task_list=[t1],
        worker_list=[w1],
        cost_list=[10],
    )
    assert team1.worker_list == [w1]
    assert team1.targeted_task_list == [t1]
    assert team1.parent_team == team
    assert team1.cost_list == [10]
Ejemplo n.º 25
0
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
Ejemplo n.º 26
0
def test_get_time_list_for_gannt_chart():
    w = BaseTask("w1", "----")
    w.state_record_list = [
        BaseTaskState.NONE,
        BaseTaskState.READY,
        BaseTaskState.WORKING,
    ]
    ready_time_list, working_time_list = w.get_time_list_for_gannt_chart()
    assert ready_time_list == [(1, 1)]
    assert working_time_list == [(2, 1)]

    w.state_record_list = [
        BaseTaskState.NONE,
        BaseTaskState.READY,
        BaseTaskState.READY,
    ]
    ready_time_list, working_time_list = w.get_time_list_for_gannt_chart()
    assert ready_time_list == [(1, 2)]
    assert working_time_list == []

    w.state_record_list = [
        BaseTaskState.NONE,
        BaseTaskState.WORKING,
        BaseTaskState.FINISHED,
    ]
    ready_time_list, working_time_list = w.get_time_list_for_gannt_chart()
    assert ready_time_list == []
    assert working_time_list == [(1, 1)]

    # for backward
    w.state_record_list = [
        BaseTaskState.FINISHED,
        BaseTaskState.WORKING,
        BaseTaskState.READY,
        BaseTaskState.READY,
        BaseTaskState.FINISHED,
        BaseTaskState.WORKING,
        BaseTaskState.WORKING,
        BaseTaskState.READY,
    ]
    ready_time_list, working_time_list = w.get_time_list_for_gannt_chart()
    assert ready_time_list == [(2, 2), (7, 1)]
    assert working_time_list == [(1, 1), (5, 2)]
Ejemplo n.º 27
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.º 28
0
def test_initialize():
    """test_initialize."""
    team = BaseTeam("team")
    w = BaseWorker("w1", team_id=team.ID)
    w.state = BaseWorkerState.WORKING
    w.cost_list = [9.0, 7.2]
    w.assigned_task_list = [BaseTask("task")]
    w.initialize()
    assert w.state == BaseWorkerState.FREE
    assert w.cost_list == []
    assert w.assigned_task_list == []
Ejemplo n.º 29
0
def test_remove_insert_absence_time_list():
    """test_remove__nsert_absence_time_list."""
    w = BaseTask("w1", "----")
    w.allocated_worker_id_record = ["aa", "bb", "cc", "dd", "ee", "ff"]
    w.allocated_facility_id_record = ["aa", "bb", "cc", "dd", "ee", "ff"]
    w.state_record_list = [0, 1, 2, 3, 4, 5]

    absence_time_list = [3, 4]
    w.remove_absence_time_list(absence_time_list)
    assert w.allocated_worker_id_record == ["aa", "bb", "cc", "ff"]
    assert w.allocated_facility_id_record == ["aa", "bb", "cc", "ff"]
    assert w.state_record_list == [0, 1, 2, 5]

    w.insert_absence_time_list(absence_time_list)
    assert w.allocated_worker_id_record == ["aa", "bb", "cc", "cc", "cc", "ff"]
    assert w.allocated_facility_id_record == ["aa", "bb", "cc", "cc", "cc", "ff"]
    assert w.state_record_list == [0, 1, 2, 1, 1, 5]
Ejemplo n.º 30
0
def test_initialize():
    team = BaseTeam("team")
    w = BaseWorker("w1", team_id=team.ID)
    w.state = BaseResourceState.WORKING
    w.cost_list = [9.0, 7.2]
    w.start_time_list = [0]
    w.finish_time_list = [1]
    w.assigned_task_list = [BaseTask("task")]
    w.initialize()
    assert w.state == BaseResourceState.FREE
    assert w.cost_list == []
    assert w.start_time_list == []
    assert w.finish_time_list == []
    assert w.assigned_task_list == []