Example #1
0
def test_aGoalOrDecomposedWithTwoTasksMayBeAchievableAtOnlyOneBranch():
    goal = Goal(Decomposition.OR, "Root")
    assert goal.decomposition

    task1 = Task("T1")
    task2 = Task("T2")

    current = Context("C1")
    fullContext = []
    fullContext.append(current)

    qc = QualityConstraint(current, CommonMetrics.SECONDS, 15,
                           Comparison.LESS_OR_EQUAL_TO)

    task1.addApplicableContext(current)
    task1.setProvidedQuality(current, CommonMetrics.SECONDS, 16)

    task2.addApplicableContext(current)
    task2.setProvidedQuality(current, CommonMetrics.SECONDS, 11)

    goal.addDependency(task1)
    goal.addDependency(task2)

    goal.addApplicableContext(current)

    interp = Interpretation()
    interp.addQualityConstraint(qc)

    plan = PragmaticPlanning().isAchievable(goal, fullContext, interp)
    assert task2 in plan.getTasks()
    assert task1 not in plan.getTasks()
Example #2
0
def test_c10(mpers):
    fullcontext = [
        mpers.contexts.c1, mpers.contexts.c2, mpers.contexts.c3,
        mpers.contexts.c5, mpers.contexts.c6, mpers.contexts.c8,
        mpers.contexts.c10, mpers.contexts.c12
    ]

    tasks = PragmaticPlanning().isAchievablePlan(mpers.rootGoal, fullcontext,
                                                 None)
    plan = ["notifyByLightAlert", "acceptEmergency"]
    assert tasks is not None
    for task in tasks.getTasks():
        assert task.identifier not in plan
Example #3
0
def test_c3(mpers):
    fullcontext = [
        mpers.contexts.c1, mpers.contexts.c2, mpers.contexts.c3,
        mpers.contexts.c4, mpers.contexts.c5, mpers.contexts.c6,
        mpers.contexts.c7, mpers.contexts.c8
    ]

    tasks = PragmaticPlanning().isAchievablePlan(mpers.rootGoal, fullcontext,
                                                 None)

    assert tasks is not None

    for task in tasks.getTasks():
        assert task.identifier != "acceptEmergency"
Example #4
0
def test_c6(mpers):
    fullcontext = [
        mpers.contexts.c1, mpers.contexts.c4, mpers.contexts.c5,
        mpers.contexts.c6, mpers.contexts.c7, mpers.contexts.c8,
        mpers.contexts.c10, mpers.contexts.c12
    ]

    tasks = PragmaticPlanning().isAchievablePlan(mpers.rootGoal, fullcontext,
                                                 None)

    plan = ["notifyCentralBySMS", "confirmEmergencyByCall", "sendInfoBySMS"]

    assert tasks is not None

    for task in tasks.getTasks():
        assert task.identifier not in plan
Example #5
0
def test_c4(mpers):
    fullcontext = [
        mpers.contexts.c1, mpers.contexts.c4, mpers.contexts.c6,
        mpers.contexts.c7, mpers.contexts.c8, mpers.contexts.c10,
        mpers.contexts.c12
    ]

    tasks = PragmaticPlanning().isAchievablePlan(mpers.rootGoal, fullcontext,
                                                 None)
    plan = [
        "notifyCentralBySMS", "confirmEmergencyByCall", "notifyBySoundAlert",
        "sendInfoBySMS", "identifyLocationByVoiceCall",
        "accessLocationFromTriangulation"
    ]
    assert tasks is not None

    for task in tasks.getTasks():
        assert task.identifier not in plan
def test_shouldBeAchievable():
    root = Goal(Decomposition.AND, "root")

    context = Context("c1")
    current = []
    current.append(context)

    task1 = Task("t1")
    task2 = Task("t2")

    task1.addApplicableContext(context)

    root.addDependency(task1)
    root.addDependency(task2)

    plan = PragmaticPlanning().isAchievable(root, current, None)
    assert plan

    assert task2 in plan.getTasks()
Example #7
0
def test_getApplicableQC():
    goal = Pragmatic(Decomposition.AND, "Root")

    task = Task("T1")
    context = Context("C1")
    anotherContext = Context("C2")

    fullContext = []

    qc = QualityConstraint(context, CommonMetrics.SECONDS, 15,
                           Comparison.LESS_OR_EQUAL_TO)
    stricter = QualityConstraint(anotherContext, CommonMetrics.SECONDS, 10,
                                 Comparison.LESS_OR_EQUAL_TO)

    task.setProvidedQuality(context, CommonMetrics.SECONDS, 13)

    goal.addDependency(task)
    goal.addApplicableContext(context)
    goal.interp.addQualityConstraint(qc)
    goal.interp.addQualityConstraint(stricter)

    fullContext.append(context)

    assert stricter not in goal.interp.getQualityConstraints(fullContext)

    plan = PragmaticPlanning().isAchievable(goal, fullContext, goal.interp)
    assert len(plan.getTasks()) == 1

    fullContext.append(anotherContext)
    assert qc in goal.interp.getQualityConstraints(fullContext)

    assert stricter in goal.interp.getQualityConstraints(fullContext)

    assert PragmaticPlanning().isAchievable(goal, fullContext,
                                            goal.interp) is None

    fullContext.remove(context)

    assert qc not in goal.interp.getQualityConstraints(fullContext)

    assert stricter in goal.interp.getQualityConstraints(fullContext)
Example #8
0
def test_aGoalWithATaskMayBeAchievable():
    goal = Goal(Decomposition.AND, "Root")

    task = Task("T1")

    current = Context("C1")
    fullContext = []
    fullContext.append(current)

    qc = QualityConstraint(current, CommonMetrics.SECONDS, 15,
                           Comparison.LESS_OR_EQUAL_TO)
    interp = Interpretation()
    interp.addQualityConstraint(qc)

    task.addApplicableContext(current)
    task.setProvidedQuality(current, CommonMetrics.SECONDS, 13)

    goal.addDependency(task)
    goal.addApplicableContext(current)

    plan = PragmaticPlanning().isAchievable(goal, fullContext, interp)
    assert len(plan.getTasks()) == 1