Пример #1
0
def test_shouldComplainAboutDifferentMetrics():
    lessStrictQC = QualityConstraint(Context("C1"), CommonMetrics.SECONDS, 15,
                                     Comparison.LESS_THAN)
    moreStrictQC = QualityConstraint(Context("C2"), CommonMetrics.METERS, 10,
                                     Comparison.LESS_THAN)

    lessStrictQC.stricterQC(moreStrictQC)
Пример #2
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)
Пример #3
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])
Пример #4
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())
Пример #5
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
Пример #6
0
def test_aGoalOrDecomposedWithTwoTasksMayNotBeAchievable():
    goal = Goal(Decomposition.OR, "Root")

    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, 17)

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

    goal.addApplicableContext(current)

    interp = Interpretation()
    interp.addQualityConstraint(qc)

    plan = PragmaticPlanning().isAchievable(goal, fullContext, interp)
    assert goal.decomposition is Decomposition.OR
    assert plan is None
Пример #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)
Пример #8
0
def test_aNonApplicableRootGoalIsNotAchievable():
    goal = Goal(Decomposition.AND, "G1")
    current = Context("C1")
    fullContext = []

    qc = QualityConstraint(current, CommonMetrics.SECONDS,
                           15, Comparison.LESS_OR_EQUAL_TO)
    goal.addApplicableContext(Context("C2"))

    interp = Interpretation()
    interp.addQualityConstraint(qc)

    assert PragmaticPlanning().isAchievable(goal, fullContext, interp) is None
Пример #9
0
def test_shouldSelectStricterConstraint():
    lessStrictQC = QualityConstraint(Context("C1"), CommonMetrics.SECONDS, 15,
                                     Comparison.LESS_THAN)
    moreStrictQC = QualityConstraint(Context("C2"), CommonMetrics.SECONDS, 10,
                                     Comparison.LESS_THAN)

    assert moreStrictQC is lessStrictQC.stricterQC(moreStrictQC)
    assert moreStrictQC is moreStrictQC.stricterQC(lessStrictQC)
Пример #10
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)
Пример #11
0
def aTaskMayNotBeAchievable():
    task = Task("T1")

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

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

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

    interp = Interpretation()
    interp.addQualityConstraint(qc)

    assert PragmaticPlanning().isAchievable(task, fullContext, interp) is None
Пример #12
0
def test_aTaskShouldBeAchievable():
    task = Task("T1")

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

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

    task.addApplicableContext(currentContext)
    task.setProvidedQuality(currentContext, CommonMetrics.SECONDS, 12)

    interp = Interpretation()
    interp.addQualityConstraint(qc)

    assert task in PragmaticPlanning().isAchievableTask(task, 
        fullContext, interp).getTasks()
Пример #13
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
Пример #14
0
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]

    plan = Planning().isAchievable(goal, fullContext, goal.interp)

    assert plan is not None

    assert True is assertPlan(plan, [task2])

Пример #15
0
    def __init__(self):

        self.tasks = MpersTasks()
        self.goals = MpersGoals()

        # Refinements

        self.goals.respondToEmergencyGoal.addDependency(
            self.goals.emergencyIsDetectedGoal)
        self.goals.respondToEmergencyGoal.addDependency(
            self.goals.isNotifiedAboutEmergencyGoal)
        self.goals.respondToEmergencyGoal.addDependency(
            self.goals.centralReceivesInfoGoal)
        self.goals.respondToEmergencyGoal.addDependency(
            self.goals.medicalCareReachesGoal)

        self.goals.emergencyIsDetectedGoal.addDependency(
            self.goals.callForHelpIsAcceptedGoal)
        self.goals.emergencyIsDetectedGoal.addDependency(
            self.goals.situationsAreIdentifiedGoal)

        self.goals.callForHelpIsAcceptedGoal.addDependency(
            self.goals.receivesEmergencyButtonCallGoal)
        self.goals.callForHelpIsAcceptedGoal.addDependency(
            self.goals.falseAlarmIsCheckedGoal)

        self.goals.receivesEmergencyButtonCallGoal.addDependency(
            self.tasks.notifyCentralBySMSTask)
        self.goals.receivesEmergencyButtonCallGoal.addDependency(
            self.tasks.notifyCentralByInternetTask)

        self.goals.falseAlarmIsCheckedGoal.addDependency(
            self.tasks.acceptEmergencyTask)
        self.goals.falseAlarmIsCheckedGoal.addDependency(
            self.goals.pIsContacted)

        self.goals.pIsContacted.addDependency(
            self.tasks.confirmEmergencyByCallTask)

        self.goals.situationsAreIdentifiedGoal.addDependency(
            self.tasks.processDataFromSensorsTask)
        self.goals.situationsAreIdentifiedGoal.addDependency(
            self.goals.vitalSignsAreMonitoredGoal)
        self.goals.situationsAreIdentifiedGoal.addDependency(
            self.tasks.identifySituationTask)

        self.goals.vitalSignsAreMonitoredGoal.addDependency(
            self.tasks.collectDataFromSensorsTask)
        self.goals.vitalSignsAreMonitoredGoal.addDependency(
            self.tasks.persistDataToDatabaseTask)

        self.goals.isNotifiedAboutEmergencyGoal.addDependency(
            self.tasks.notifyByLightAlertTask)
        self.goals.isNotifiedAboutEmergencyGoal.addDependency(
            self.tasks.notifyByMobileVibrationTask)
        self.goals.isNotifiedAboutEmergencyGoal.addDependency(
            self.tasks.notifyBySoundAlertTask)
        self.goals.isNotifiedAboutEmergencyGoal.addDependency(
            self.tasks.centralCallTask)

        self.goals.centralReceivesInfoGoal.addDependency(
            self.goals.infoIsSentToEmergencyGoal)
        self.goals.centralReceivesInfoGoal.addDependency(
            self.goals.infoIsPreparedGoal)

        self.goals.infoIsSentToEmergencyGoal.addDependency(
            self.tasks.sendInfoByInternetTask)
        self.goals.infoIsSentToEmergencyGoal.addDependency(
            self.tasks.sendInfoBySMSTask)

        self.goals.infoIsPreparedGoal.addDependency(
            self.goals.setupAutomatedInfoGoal)
        self.goals.infoIsPreparedGoal.addDependency(
            self.goals.contactResponsibleGoal)

        self.goals.setupAutomatedInfoGoal.addDependency(
            self.goals.locationIsIdentifiedGoal)
        self.goals.setupAutomatedInfoGoal.addDependency(
            self.goals.situationDataIsRecoveredGoal)

        self.goals.locationIsIdentifiedGoal.addDependency(
            self.tasks.accessLocationFromTriangulationTask)
        self.goals.locationIsIdentifiedGoal.addDependency(
            self.tasks.considerLastKnownLocationTask)
        self.goals.locationIsIdentifiedGoal.addDependency(
            self.tasks.identifyLocationByVoiceCallTask)
        self.goals.locationIsIdentifiedGoal.addDependency(
            self.tasks.accessLocationFromGPSTask)

        self.goals.situationDataIsRecoveredGoal.addDependency(
            self.tasks.accessDataFromDatabaseTask)

        self.goals.contactResponsibleGoal.addDependency(
            self.tasks.getInfoFromResponsibleTask)

        self.goals.medicalCareReachesGoal.addDependency(
            self.goals.ambulanceIsDispatchedToLocationGoal)

        self.goals.ambulanceIsDispatchedToLocationGoal.addDependency(
            self.tasks.ambulanceDispatchDelegationTask)

        # Applicable Contexts

        self.tasks.notifyCentralBySMSTask.addApplicableContext(
            self.contexts.c2)

        self.tasks.notifyCentralByInternetTask.addApplicableContext(
            self.contexts.c3)
        self.tasks.notifyCentralByInternetTask.addApplicableContext(
            self.contexts.c4)

        self.tasks.acceptEmergencyTask.addNonapplicableContext(
            self.contexts.c2)

        self.tasks.confirmEmergencyByCallTask.addApplicableContext(
            self.contexts.c2)

        self.tasks.notifyByMobileVibrationTask.addApplicableContext(
            self.contexts.c1)

        self.tasks.notifyBySoundAlertTask.addApplicableContext(
            self.contexts.c6)

        self.tasks.notifyByLightAlertTask.addApplicableContext(
            self.contexts.c7)

        self.tasks.centralCallTask.addApplicableContext(self.contexts.c8)

        self.tasks.sendInfoBySMSTask.addApplicableContext(self.contexts.c2)

        self.tasks.sendInfoByInternetTask.addApplicableContext(
            self.contexts.c3)
        self.tasks.sendInfoByInternetTask.addApplicableContext(
            self.contexts.c4)

        self.tasks.identifyLocationByVoiceCallTask.addApplicableContext(
            self.contexts.c2)

        self.tasks.accessLocationFromTriangulationTask.addApplicableContext(
            self.contexts.c2)

        self.tasks.accessLocationFromGPSTask.addApplicableContext(
            self.contexts.c5)

        # Goal Interpretation

        qc1 = QualityConstraint(None, MpersMetrics.SECONDS, 180,
                                Comparison.LESS_OR_EQUAL_TO)
        qc2 = QualityConstraint(self.contexts.c10, MpersMetrics.SECONDS, 90,
                                Comparison.LESS_OR_EQUAL_TO)
        qc3 = QualityConstraint(self.contexts.c9, MpersMetrics.SECONDS, 240,
                                Comparison.LESS_OR_EQUAL_TO)
        self.goals.respondToEmergencyGoal.interp.addQualityConstraint(qc1)
        self.goals.respondToEmergencyGoal.interp.addQualityConstraint(qc2)
        self.goals.respondToEmergencyGoal.interp.addQualityConstraint(qc3)

        qc1 = QualityConstraint(None, MpersMetrics.FALSE_NEGATIVE_PERCENTAGE,
                                30, Comparison.LESS_OR_EQUAL_TO)
        qc2 = QualityConstraint(self.contexts.c3,
                                MpersMetrics.FALSE_NEGATIVE_PERCENTAGE, 10,
                                Comparison.LESS_OR_EQUAL_TO)
        qc3 = QualityConstraint(self.contexts.c9,
                                MpersMetrics.FALSE_NEGATIVE_PERCENTAGE, 5,
                                Comparison.LESS_OR_EQUAL_TO)
        self.goals.emergencyIsDetectedGoal.interp.addQualityConstraint(qc1)
        self.goals.emergencyIsDetectedGoal.interp.addQualityConstraint(qc2)
        self.goals.emergencyIsDetectedGoal.interp.addQualityConstraint(qc3)

        qc1 = QualityConstraint(None, MpersMetrics.SECONDS, 60,
                                Comparison.LESS_OR_EQUAL_TO)
        self.goals.centralReceivesInfoGoal.interp.addQualityConstraint(qc1)

        qc4 = QualityConstraint(None, MpersMetrics.DISTANCE_ERROR, 1000,
                                Comparison.LESS_OR_EQUAL_TO)
        qc6 = QualityConstraint(self.contexts.c5, MpersMetrics.DISTANCE_ERROR,
                                20, Comparison.LESS_OR_EQUAL_TO)
        qc5 = QualityConstraint(self.contexts.c10, MpersMetrics.DISTANCE_ERROR,
                                200, Comparison.LESS_OR_EQUAL_TO)
        qc1 = QualityConstraint(None, MpersMetrics.SECONDS, 120,
                                Comparison.LESS_OR_EQUAL_TO)
        qc3 = QualityConstraint(self.contexts.c9, MpersMetrics.SECONDS, 240,
                                Comparison.LESS_OR_EQUAL_TO)
        qc2 = QualityConstraint(self.contexts.c10, MpersMetrics.SECONDS, 20,
                                Comparison.LESS_OR_EQUAL_TO)
        self.goals.locationIsIdentifiedGoal.interp.addQualityConstraint(qc1)
        self.goals.locationIsIdentifiedGoal.interp.addQualityConstraint(qc2)
        self.goals.locationIsIdentifiedGoal.interp.addQualityConstraint(qc3)
        self.goals.locationIsIdentifiedGoal.interp.addQualityConstraint(qc4)
        self.goals.locationIsIdentifiedGoal.interp.addQualityConstraint(qc5)
        self.goals.locationIsIdentifiedGoal.interp.addQualityConstraint(qc6)

        qc1 = QualityConstraint(None, MpersMetrics.SECONDS, 45,
                                Comparison.LESS_OR_EQUAL_TO)
        qc2 = QualityConstraint(self.contexts.c10, MpersMetrics.SECONDS, 30,
                                Comparison.LESS_OR_EQUAL_TO)
        self.goals.infoIsPreparedGoal.interp.addQualityConstraint(qc1)
        self.goals.infoIsPreparedGoal.interp.addQualityConstraint(qc2)

        qc1 = QualityConstraint(None, MpersMetrics.NOISE, 10,
                                Comparison.LESS_OR_EQUAL_TO)
        qc2 = QualityConstraint(self.contexts.c1, MpersMetrics.NOISE, 3,
                                Comparison.LESS_OR_EQUAL_TO)
        self.goals.isNotifiedAboutEmergencyGoal.interp.addQualityConstraint(
            qc1)
        self.goals.isNotifiedAboutEmergencyGoal.interp.addQualityConstraint(
            qc2)

        # Provided Task QoS
        self.tasks.notifyCentralBySMSTask.setProvidedQuality(
            None, MpersMetrics.FALSE_NEGATIVE_PERCENTAGE, 10)

        self.tasks.notifyCentralByInternetTask.setProvidedQuality(
            None, MpersMetrics.FALSE_NEGATIVE_PERCENTAGE, 5)

        self.tasks.acceptEmergencyTask.setProvidedQuality(
            None, MpersMetrics.FALSE_NEGATIVE_PERCENTAGE, 30)

        self.tasks.confirmEmergencyByCallTask.setProvidedQuality(
            None, MpersMetrics.FALSE_NEGATIVE_PERCENTAGE, 5)

        self.tasks.processDataFromSensorsTask.setProvidedQuality(
            None, MpersMetrics.FALSE_NEGATIVE_PERCENTAGE, 15)

        self.tasks.collectDataFromSensorsTask.setProvidedQuality(
            None, MpersMetrics.SECONDS, 120)
        self.tasks.collectDataFromSensorsTask.setProvidedQuality(
            self.contexts.c3, MpersMetrics.SECONDS, 60)

        self.tasks.persistDataToDatabaseTask.setProvidedQuality(
            None, MpersMetrics.SECONDS, 5)

        self.tasks.identifySituationTask.setProvidedQuality(
            None, MpersMetrics.FALSE_NEGATIVE_PERCENTAGE, 20)

        self.tasks.notifyByMobileVibrationTask.setProvidedQuality(
            None, MpersMetrics.NOISE, 2)
        self.tasks.notifyBySoundAlertTask.setProvidedQuality(
            None, MpersMetrics.NOISE, 9)
        self.tasks.notifyByLightAlertTask.setProvidedQuality(
            None, MpersMetrics.NOISE, 0)
        self.tasks.centralCallTask.setProvidedQuality(None, MpersMetrics.NOISE,
                                                      7)

        self.tasks.sendInfoBySMSTask.setProvidedQuality(
            None, MpersMetrics.SECONDS, 65)
        self.tasks.sendInfoBySMSTask.setProvidedQuality(
            self.contexts.c8, MpersMetrics.SECONDS, 45)

        self.tasks.sendInfoByInternetTask.setProvidedQuality(
            None, MpersMetrics.SECONDS, 40)

        self.tasks.considerLastKnownLocationTask.setProvidedQuality(
            None, MpersMetrics.DISTANCE_ERROR, 900)
        self.tasks.considerLastKnownLocationTask.setProvidedQuality(
            None, MpersMetrics.SECONDS, 15)

        self.tasks.identifyLocationByVoiceCallTask.setProvidedQuality(
            None, MpersMetrics.DISTANCE_ERROR, 100)
        self.tasks.identifyLocationByVoiceCallTask.setProvidedQuality(
            self.contexts.c11, MpersMetrics.DISTANCE_ERROR, 300)
        self.tasks.identifyLocationByVoiceCallTask.setProvidedQuality(
            None, MpersMetrics.SECONDS, 45)

        self.tasks.accessLocationFromTriangulationTask.setProvidedQuality(
            None, MpersMetrics.DISTANCE_ERROR, 40)
        self.tasks.accessLocationFromTriangulationTask.setProvidedQuality(
            self.contexts.c11, MpersMetrics.DISTANCE_ERROR, 400)
        self.tasks.accessLocationFromTriangulationTask.setProvidedQuality(
            None, MpersMetrics.SECONDS, 30)

        self.tasks.accessLocationFromGPSTask.setProvidedQuality(
            None, MpersMetrics.DISTANCE_ERROR, 20)
        self.tasks.accessLocationFromGPSTask.setProvidedQuality(
            self.contexts.c11, MpersMetrics.DISTANCE_ERROR, 30)
        self.tasks.accessLocationFromGPSTask.setProvidedQuality(
            None, MpersMetrics.SECONDS, 50)

        self.tasks.accessDataFromDatabaseTask.setProvidedQuality(
            None, MpersMetrics.SECONDS, 20)

        self.tasks.getInfoFromResponsibleTask.setProvidedQuality(
            None, MpersMetrics.SECONDS, 25)
        self.tasks.getInfoFromResponsibleTask.setProvidedQuality(
            self.contexts.c11, MpersMetrics.SECONDS, 50)

        self.tasks.ambulanceDispatchDelegationTask.setProvidedQuality(
            None, MpersMetrics.SECONDS, 30)

        self.rootGoal = Goal(Decomposition.AND, "rootGoal")
        self.rootGoal = self.goals.respondToEmergencyGoal
Пример #16
0
task2.addApplicableContext(c2)

task1.setProvidedQuality(None, MpersMetrics.SECONDS, 30)
task1.setProvidedQuality(None, MpersMetrics.ERROR, 30)
task2.setProvidedQuality(None, MpersMetrics.SECONDS, 70)
task2.setProvidedQuality(None, MpersMetrics.ERROR, 10)
task3.setProvidedQuality(None, MpersMetrics.SECONDS, 10)
task3.setProvidedQuality(None, MpersMetrics.ERROR, 70)

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

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

qc1 = QualityConstraint(None, MpersMetrics.SECONDS, 100, Comparison.LESS_THAN)
qc1 = QualityConstraint(None, MpersMetrics.ERROR, 90, Comparison.LESS_THAN)
qc2 = QualityConstraint(c2, MpersMetrics.SECONDS, 40, Comparison.LESS_THAN)
qc3 = QualityConstraint(c4, MpersMetrics.ERROR, 40, Comparison.LESS_THAN)

goal.interp.addQualityConstraint(qc1)
goal.interp.addQualityConstraint(qc2)
goal.interp.addQualityConstraint(qc3)


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

    plan = Planning().isAchievable(goal, fullContext, goal.interp)

    assert plan is not None
Пример #17
0
def shouldCorrectlyCompareMetrics():
    qc = QualityConstraint(Context("C1"), CommonMetrics.SECONDS, 15,
                           Comparison.LESS_THAN)
    assert True is qc.abidesByQC(14, CommonMetrics.SECONDS)

    qc = QualityConstraint(Context("C1"), CommonMetrics.SECONDS, 15,
                           Comparison.LESS_OR_EQUAL_TO)
    assert True is qc.abidesByQC(14, CommonMetrics.SECONDS)

    qc = QualityConstraint(Context("C1"), CommonMetrics.SECONDS, 15,
                           Comparison.LESS_OR_EQUAL_TO)
    assert True is qc.abidesByQC(15, CommonMetrics.SECONDS)

    qc = QualityConstraint(Context("C1"), CommonMetrics.SECONDS, 15,
                           Comparison.EQUAL_TO)
    assert True is qc.abidesByQC(15, CommonMetrics.SECONDS)

    qc = QualityConstraint(Context("C1"), CommonMetrics.SECONDS, 15,
                           Comparison.GREATER_OR_EQUAL_TO)
    assert True is qc.abidesByQC(15, CommonMetrics.SECONDS)

    qc = QualityConstraint(Context("C1"), CommonMetrics.SECONDS, 15,
                           Comparison.GREATER_OR_EQUAL_TO)
    assert True is qc.abidesByQC(16, CommonMetrics.SECONDS)

    qc = QualityConstraint(Context("C1"), CommonMetrics.SECONDS, 15,
                           Comparison.GREATER_THAN)
    assert True is qc.abidesByQC(16, CommonMetrics.SECONDS)

    qc = QualityConstraint(Context("C1"), CommonMetrics.SECONDS, 15,
                           Comparison.LESS_THAN)
    assert False is qc.abidesByQC(16, CommonMetrics.SECONDS)

    qc = QualityConstraint(Context("C1"), CommonMetrics.SECONDS, 15,
                           Comparison.LESS_OR_EQUAL_TO)
    assert False is qc.abidesByQC(16, CommonMetrics.SECONDS)

    qc = QualityConstraint(Context("C1"), CommonMetrics.SECONDS, 15,
                           Comparison.EQUAL_TO)
    assert False is qc.abidesByQC(16, CommonMetrics.SECONDS)

    qc = QualityConstraint(Context("C1"), CommonMetrics.SECONDS, 15,
                           Comparison.GREATER_OR_EQUAL_TO)
    assert False is qc.abidesByQC(14, CommonMetrics.SECONDS)

    qc = QualityConstraint(Context("C1"), CommonMetrics.SECONDS, 15,
                           Comparison.GREATER_THAN)
    assert False is qc.abidesByQC(14, CommonMetrics.SECONDS)
Пример #18
0
def shouldAbideByQcIfMetricIsNotAffected():
    qc = QualityConstraint(Context("C1"), CommonMetrics.SECONDS, 15,
                           Comparison.LESS_THAN)
    assert True is qc.abidesByQC(15, CommonMetrics.METERS)
Пример #19
0
def test_shouldBeBetterThan():
    qc = QualityConstraint(Context("C1"), CommonMetrics.SECONDS, 15,
                           Comparison.LESS_THAN)
    assert True is qc.abidesByQC(13, CommonMetrics.SECONDS)
    assert False is qc.abidesByQC(16, CommonMetrics.SECONDS)
Пример #20
0
def test_shouldGetCorrectContexts():
    qc = QualityConstraint(Context("C1"), CommonMetrics.SECONDS, 15,
                           Comparison.LESS_THAN)
    Context("C1") is qc.getApplicableContext()
Пример #21
0
def test_shouldGetCorrectMetric():
    qc = QualityConstraint(Context("C1"), CommonMetrics.SECONDS, 15,
                           Comparison.LESS_THAN)
    assert CommonMetrics.SECONDS is qc.metric
Пример #22
0
def test_shouldGetCorrectThreshold():
    qc = QualityConstraint(Context("C1"), CommonMetrics.SECONDS, 15,
                           Comparison.LESS_THAN)
    print(qc.value)
    assert 15 == qc.value