Пример #1
0
def test_can_add_resources():
    task = BaseTask("task")
    w1 = BaseWorker("w1", solo_working=True)
    w2 = BaseWorker("w2")
    w1.workamount_skill_mean_map = {"task": 1.0}
    w2.workamount_skill_mean_map = {"task": 1.0}
    f1 = BaseFacility("f1")
    f2 = BaseFacility("f2", solo_working=True)
    f1.workamount_skill_mean_map = {"task": 1.0}
    f2.workamount_skill_mean_map = {"task": 1.0}
    w1.facility_skill_map = {f1.name: 1.0}

    assert task.can_add_resources(worker=w1) is False
    task.state = BaseTaskState.FINISHED
    assert task.can_add_resources(worker=w1) is False
    task.state = BaseTaskState.READY
    assert task.can_add_resources(worker=w1) is True

    assert task.can_add_resources(worker=w2, facility=f2) is False
    assert task.can_add_resources(worker=w1, facility=f1) is True

    w1.solo_working = False
    task.allocated_worker_list = [w1]
    task.allocated_facility_list = [f1]
    assert task.can_add_resources(worker=w2, facility=f2) is False

    w1.solo_working = True
    assert task.can_add_resources(worker=w2, facility=f2) is False

    w1.solo_working = False
    f1.solo_working = True
    assert task.can_add_resources(worker=w2, facility=f2) is False

    w1.solo_working = False
    f1.solo_working = False
    w2.solo_working = False
    f2.solo_working = False
    assert task.can_add_resources(worker=w1, facility=f1) is True
    assert task.can_add_resources(worker=w2, facility=f2) is False

    f1.workamount_skill_mean_map = {}
    assert task.can_add_resources(worker=w1, facility=f1) is False

    w1.workamount_skill_mean_map = {}
    assert task.can_add_resources(worker=w1) is False

    assert task.can_add_resources() is False
Пример #2
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