Esempio n. 1
0
def test_shouldGetBaselineQC():
    goal = Pragmatic(Decomposition.AND, "Root")

    context = Context("C1")

    qc = QualityConstraint(context, CommonMetrics.SECONDS,
                           15, Comparison.LESS_OR_EQUAL_TO)
    baselineQC = QualityConstraint(
        None, CommonMetrics.SECONDS, 10, Comparison.LESS_OR_EQUAL_TO)

    goal.addApplicableContext(context)
    goal.interp.addQualityConstraint(qc)
    goal.interp.addQualityConstraint(baselineQC)

    assert baselineQC in goal.interp.getQualityConstraints([None])
Esempio n. 2
0
def test_shouldIncludeNonApplicableContexts():
    goal = Pragmatic(False, "Root")

    task = Task("T1")
    context = Context("C1")
    wrongContext = Context("C2")
    current = []

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

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

    goal.addDependency(task)
    goal.addNonapplicableContext(wrongContext)
    goal.interp.addQualityConstraint(qc)

    interp = Interpretation()
    interp.addQualityConstraint(qc)

    current.append(wrongContext)
    assert PragmaticPlanning().isAchievable(goal, current, interp) is None

    current.append(context)
    assert PragmaticPlanning().isAchievable(goal, current, interp) is None

    current.remove(wrongContext)
    assert PragmaticPlanning().isAchievable(goal, current, interp)
    assert PragmaticPlanning().isAchievable(goal, current, interp).getTasks()
    assert 1 == len(goal.isAchievable(current, interp).getTasks())
Esempio n. 3
0
def test_ApplicableDeps():
    goal = Pragmatic(Decomposition.AND, "Root")

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

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

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

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

    interp = Interpretation()
    interp.addQualityConstraint(qc)
    current = []
    current.append(wrongContext)
    assert PragmaticPlanning().isAchievable(goal, current, interp) is None

    current.append(context)
    assert len(goal.isAchievable(current, interp).getTasks()) == 1
Esempio n. 4
0
def test_shouldThereBeMoreThanOneApplicableQCreturnTheStricterOne():
    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)

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

    assert stricter == qc.stricterQC(stricter)

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

    fullContext.append(anotherContext)
    assert stricter in \
        goal.interp.getQualityConstraints(fullContext)
Esempio n. 5
0
def test_shouldGetDifferentQualityConstraintsForDifferentContexts():
    aContext = Context("c1")
    anotherContext = Context("c2")

    aQC = QualityConstraint(aContext, CommonMetrics.METERS, 30,
                            Comparison.LESS_OR_EQUAL_TO)
    anotherQC = QualityConstraint(anotherContext, CommonMetrics.METERS, 60,
                                  Comparison.LESS_OR_EQUAL_TO)

    goal = Pragmatic(Decomposition.AND, "G1")

    goal.interp.addQualityConstraint(aQC)
    goal.interp.addQualityConstraint(anotherQC)

    fullContext = []
    fullContext.append(aContext)

    assert aQC in goal.interp.getQualityConstraints(fullContext)

    anotherFullContext = []
    anotherFullContext.append(anotherContext)

    assert anotherQC in goal.interp.getQualityConstraints(anotherFullContext)
Esempio n. 6
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)
Esempio n. 7
0
 def __init__(self):
     # Goals
     self.respondToEmergencyGoal = Pragmatic(Decomposition.AND,
                                             "respondToEmergencyGoal")
     self.emergencyIsDetectedGoal = Pragmatic(Decomposition.OR,
                                              "emergencyIsDetectedGoal")
     self.centralReceivesInfoGoal = Pragmatic(Decomposition.AND,
                                              "centralReceivesInfoGoal")
     self.locationIsIdentifiedGoal = Pragmatic(Decomposition.OR,
                                               "locationIsIdentifiedGoal")
     self.infoIsPreparedGoal = Pragmatic(Decomposition.OR,
                                         "infoIsPreparedGoal")
     self.isNotifiedAboutEmergencyGoal = Pragmatic(
         Decomposition.OR, "isNotifiedAboutEmergencyGoal")
     self.callForHelpIsAcceptedGoal = Goal(Decomposition.AND,
                                           "callForHelpIsAcceptedGoal")
     self.falseAlarmIsCheckedGoal = Goal(Decomposition.OR,
                                         "falseAlarmIsCheckedGoal")
     self.pIsContacted = Goal(Decomposition.AND, "pIsContacted")
     self.receivesEmergencyButtonCallGoal = Goal(
         Decomposition.OR, "receivesEmergencyButtonCallGoal")
     self.situationsAreIdentifiedGoal = Goal(Decomposition.AND,
                                             "situationsAreIdentifiedGoal")
     self.vitalSignsAreMonitoredGoal = Goal(Decomposition.AND,
                                            "vitalSignsAreMonitoredGoal")
     self.infoIsSentToEmergencyGoal = Goal(Decomposition.OR,
                                           "infoIsSentToEmergencyGoal")
     self.setupAutomatedInfoGoal = Goal(Decomposition.AND,
                                        "setupAutomatedInfoGoal")
     self.situationDataIsRecoveredGoal = Goal(
         Decomposition.AND, "situationDataIsRecoveredGoal")
     self.contactResponsibleGoal = Goal(Decomposition.AND,
                                        "contactResponsibleGoal")
     self.medicalCareReachesGoal = Goal(Decomposition.AND,
                                        "medicalCareReachesGoal")
     self.ambulanceIsDispatchedToLocationGoal = Goal(
         Decomposition.AND, "ambulanceIsDispatchedToLocationGoal")
Esempio n. 8
0
c3 = Context("c3")
c4 = Context("c4")

task1 = Task("task1")
task2 = Task("task2")
task3 = Task("task3")
task4 = Task("task4")

task2.addApplicableContext(c2)

task1.setProvidedQuality(None, MpersMetrics.SECONDS, 80)
task2.setProvidedQuality(None, MpersMetrics.SECONDS, 60)
task3.setProvidedQuality(None, MpersMetrics.SECONDS, 100)
task4.setProvidedQuality(None, MpersMetrics.SECONDS, 200)

goal = Pragmatic(Decomposition.OR, "g1")

goal.addDependency(task1)
goal.addDependency(task2)
goal.addDependency(task3)
goal.addDependency(task4)

qc1 = QualityConstraint(None, MpersMetrics.SECONDS, 180, Comparison.LESS_THAN)
qc2 = QualityConstraint(c2, MpersMetrics.SECONDS, 90, Comparison.LESS_THAN)
goal.interp.addQualityConstraint(qc1)
goal.interp.addQualityConstraint(qc2)


def test_C1():
    fullContext = [c1, c2, c3, c4]