def locationIsIdentifiedGoal(): locationIsIdentifiedGoal = Pragmatic( Decomposition.OR, "locationIsIdentifiedGoal") qc4 = QualityConstraint(None, MpersMetrics.DISTANCE_ERROR, 1000, Comparison.LESS_OR_EQUAL_TO) qc6 = QualityConstraint(c5, MpersMetrics.DISTANCE_ERROR, 20, Comparison.LESS_OR_EQUAL_TO) qc5 = QualityConstraint(c10, MpersMetrics.DISTANCE_ERROR, 200, Comparison.LESS_OR_EQUAL_TO) qc1 = QualityConstraint(None, MpersMetrics.SECONDS, 120, Comparison.LESS_OR_EQUAL_TO) qc3 = QualityConstraint(c9, MpersMetrics.SECONDS, 240, Comparison.LESS_OR_EQUAL_TO) qc2 = QualityConstraint(c10, MpersMetrics.SECONDS, 20, Comparison.LESS_OR_EQUAL_TO) locationIsIdentifiedGoal.interp.addQualityConstraint(qc1) locationIsIdentifiedGoal.interp.addQualityConstraint(qc2) locationIsIdentifiedGoal.interp.addQualityConstraint(qc3) locationIsIdentifiedGoal.interp.addQualityConstraint(qc4) locationIsIdentifiedGoal.interp.addQualityConstraint(qc5) locationIsIdentifiedGoal.interp.addQualityConstraint(qc6) locationIsIdentifiedGoal.addDependency(considerLastKnownLocationTask) locationIsIdentifiedGoal.addDependency(identifyLocationByVoiceCallTask) locationIsIdentifiedGoal.addDependency(accessLocationFromGPSTask) locationIsIdentifiedGoal.addDependency(accessLocationFromTriangulationTask) return locationIsIdentifiedGoal
def test_ApplicableDeps(): goal = Pragmatic(Decomposition.AND) task = Task() 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.setIdentifier("Root") goal.addDependency(task) goal.addApplicableContext(context) goal.interp.addQualityConstraint(qc) interp = Interpretation() interp.addQualityConstraint(qc) current = [] current.append(wrongContext) assert goal.isAchievable(current, interp) is None current.append(context) assert len(goal.isAchievable(current, interp).getTasks()) == 1
def isNotifiedAboutEmergencyGoal(): isNotifiedAboutEmergencyGoal = Pragmatic( Decomposition.OR, "isNotifiedAboutEmergencyGoal") isNotifiedAboutEmergencyGoal.addDependency(notifyByMobileVibrationTask) isNotifiedAboutEmergencyGoal.addDependency(notifyBySoundAlertTask) isNotifiedAboutEmergencyGoal.addDependency(notifyByLightAlertTask) isNotifiedAboutEmergencyGoal.addDependency(centralCallTask) notifyByMobileVibrationTask.addApplicableContext(c1) notifyBySoundAlertTask.addApplicableContext(c6) notifyByLightAlertTask.addApplicableContext(c7) centralCallTask.addApplicableContext(c8) baseline = QualityConstraint(None, MpersMetrics.NOISE, 10, Comparison.LESS_OR_EQUAL_TO) qc1 = QualityConstraint(c9, MpersMetrics.NOISE, 3, Comparison.LESS_OR_EQUAL_TO) isNotifiedAboutEmergencyGoal.interp.addQualityConstraint(baseline) isNotifiedAboutEmergencyGoal.interp.addQualityConstraint(qc1) return isNotifiedAboutEmergencyGoal
def test_shouldThereBeMoreThanOneApplicableQCreturnTheStricterOne(): goal = Pragmatic(Decomposition.AND) task = Task() 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.setIdentifier("Root") 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)
def test_getApplicableQC(): goal = Pragmatic(Decomposition.AND) task = Task() 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.setIdentifier("Root") goal.addApplicableContext(context) goal.interp.addQualityConstraint(qc) goal.interp.addQualityConstraint(stricter) interp = Interpretation() interp.addQualityConstraint(qc) fullContext.append(context) assert stricter not in goal.interp.getQualityConstraints(fullContext) plan = goal.isAchievable(fullContext, interp) assert len(plan.getTasks()) == 1 fullContext.append(anotherContext) assert qc in goal.interp.getQualityConstraints(fullContext) assert stricter in goal.interp.getQualityConstraints(fullContext) assert goal.isAchievable(fullContext, interp) is None fullContext.remove(context) assert qc not in goal.interp.getQualityConstraints(fullContext) assert stricter in goal.interp.getQualityConstraints(fullContext)
def test_shouldGetBaselineQC(): goal = Pragmatic(Decomposition.AND) 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.setIdentifier("Root") goal.addApplicableContext(context) goal.interp.addQualityConstraint(qc) goal.interp.addQualityConstraint(baselineQC) assert baselineQC in goal.interp.getQualityConstraints([None])
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(False) 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)
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")
def test_shouldIncludeNonApplicableContexts(): goal = Pragmatic(False) task = Task() 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.setIdentifier("Root") goal.addNonapplicableContext(wrongContext) goal.interp.addQualityConstraint(qc) interp = Interpretation() interp.addQualityConstraint(qc) current.append(wrongContext) assert goal.isAchievable(current, interp) is None current.append(context) assert goal.isAchievable(current, interp) is None current.remove(wrongContext) assert goal.isAchievable(current, interp) assert goal.isAchievable(current, interp).getTasks() assert 1 == len(goal.isAchievable(current, interp).getTasks())
def rootGoal(): # Goals respondToEmergencyGoal = Pragmatic(Decomposition.AND, "respondToEmergency") emergencyIsDetectedGoal = Pragmatic(Decomposition.OR, "emergencyIsDetected") centralReceivesInfoGoal = Pragmatic(Decomposition.AND, "centralReceivesInfo") locationIsIdentifiedGoal = Pragmatic(Decomposition.OR, "locationIsIdentified") infoIsPreparedGoal = Pragmatic(Decomposition.OR, "infoIsPrepared") isNotifiedAboutEmergencyGoal = Pragmatic(Decomposition.OR, "isNotifiedAboutEmergency") callForHelpIsAcceptedGoal = Goal(Decomposition.AND, "callForHelpIsAccepted") falseAlarmIsCheckedGoal = Goal(Decomposition.OR, "falseAlarmIsChecked") pIsContactedGoal = Goal(Decomposition.AND, "pIsContacted") receivesEmergencyButtonCallGoal = Goal(Decomposition.OR, "receivesEmergencyButtonCall") situationsAreIdentifiedGoal = Goal(Decomposition.AND, "situationsAreIdentified") vitalSignsAreMonitoredGoal = Goal(Decomposition.AND, "vitalSignsAreMonitored") infoIsSentToEmergencyGoal = Goal(Decomposition.OR, "infoIsSentToEmergency") setupAutomatedInfoGoal = Goal(Decomposition.AND, "setupAutomatedInfo") situationDataIsRecoveredGoal = Goal(Decomposition.AND, "situationDataIsRecovered") contactResponsibleGoal = Goal(Decomposition.AND, "contactResponsible") medicalCareReachesGoal = Goal(Decomposition.AND, "medicalCareReaches") ambulanceIsDispatchedToLocationGoal = Goal( Decomposition.AND, "ambulanceIsDispatchedToLocation") # Refinements respondToEmergencyGoal.addDependency(emergencyIsDetectedGoal) respondToEmergencyGoal.addDependency(isNotifiedAboutEmergencyGoal) respondToEmergencyGoal.addDependency(centralReceivesInfoGoal) respondToEmergencyGoal.addDependency(medicalCareReachesGoal) emergencyIsDetectedGoal.addDependency(callForHelpIsAcceptedGoal) emergencyIsDetectedGoal.addDependency(situationsAreIdentifiedGoal) callForHelpIsAcceptedGoal.addDependency(receivesEmergencyButtonCallGoal) callForHelpIsAcceptedGoal.addDependency(falseAlarmIsCheckedGoal) receivesEmergencyButtonCallGoal.addDependency(notifyCentralBySMSTask) receivesEmergencyButtonCallGoal.addDependency(notifyCentralByInternetTask) falseAlarmIsCheckedGoal.addDependency(acceptEmergencyTask) falseAlarmIsCheckedGoal.addDependency(pIsContactedGoal) pIsContactedGoal.addDependency(confirmEmergencyByCallTask) situationsAreIdentifiedGoal.addDependency(processDataFromSensorsTask) situationsAreIdentifiedGoal.addDependency(vitalSignsAreMonitoredGoal) situationsAreIdentifiedGoal.addDependency(identifySituationTask) vitalSignsAreMonitoredGoal.addDependency(collectDataFromSensorsTask) vitalSignsAreMonitoredGoal.addDependency(persistDataToDatabaseTask) isNotifiedAboutEmergencyGoal.addDependency(notifyByMobileVibrationTask) isNotifiedAboutEmergencyGoal.addDependency(notifyBySoundAlertTask) isNotifiedAboutEmergencyGoal.addDependency(notifyByLightAlertTask) isNotifiedAboutEmergencyGoal.addDependency(centralCallTask) centralReceivesInfoGoal.addDependency(infoIsSentToEmergencyGoal) centralReceivesInfoGoal.addDependency(infoIsPreparedGoal) infoIsSentToEmergencyGoal.addDependency(sendInfoBySMSTask) infoIsSentToEmergencyGoal.addDependency(sendInfoByInternetTask) infoIsPreparedGoal.addDependency(setupAutomatedInfoGoal) infoIsPreparedGoal.addDependency(contactResponsibleGoal) setupAutomatedInfoGoal.addDependency(locationIsIdentifiedGoal) setupAutomatedInfoGoal.addDependency(situationDataIsRecoveredGoal) locationIsIdentifiedGoal.addDependency(considerLastKnownLocationTask) locationIsIdentifiedGoal.addDependency(identifyLocationByVoiceCallTask) locationIsIdentifiedGoal.addDependency(accessLocationFromGPSTask) locationIsIdentifiedGoal.addDependency(accessLocationFromTriangulationTask) situationDataIsRecoveredGoal.addDependency(accessDataFromDatabaseTask) contactResponsibleGoal.addDependency(getInfoFromResponsibleTask) medicalCareReachesGoal.addDependency(ambulanceIsDispatchedToLocationGoal) ambulanceIsDispatchedToLocationGoal.addDependency( ambulanceDispatchDelegationTask) # Applicable Contexts notifyCentralBySMSTask.addApplicableContext(c2) notifyCentralByInternetTask.addApplicableContext(c3) notifyCentralByInternetTask.addApplicableContext(c4) acceptEmergencyTask.addNonapplicableContext(c2) confirmEmergencyByCallTask.addApplicableContext(c2) notifyByMobileVibrationTask.addApplicableContext(c1) notifyBySoundAlertTask.addApplicableContext(c6) notifyByLightAlertTask.addApplicableContext(c7) centralCallTask.addApplicableContext(c8) sendInfoBySMSTask.addApplicableContext(c2) sendInfoByInternetTask.addApplicableContext(c3) sendInfoByInternetTask.addApplicableContext(c4) identifyLocationByVoiceCallTask.addApplicableContext(c2) accessLocationFromTriangulationTask.addApplicableContext(c2) accessLocationFromGPSTask.addApplicableContext(c5) # Goal Interpretations qc1 = QualityConstraint(None, MpersMetrics.SECONDS, 180, Comparison.LESS_THAN) qc2 = QualityConstraint(c10, MpersMetrics.SECONDS, 90, Comparison.LESS_THAN) qc3 = QualityConstraint(c9, MpersMetrics.SECONDS, 240, Comparison.LESS_THAN) respondToEmergencyGoal.interp.addQualityConstraint(qc1) respondToEmergencyGoal.interp.addQualityConstraint(qc2) respondToEmergencyGoal.interp.addQualityConstraint(qc3) qc1 = QualityConstraint(None, MpersMetrics.FALSE_NEGATIVE_PERCENTAGE, 30, Comparison.LESS_THAN) qc2 = QualityConstraint(c3, MpersMetrics.FALSE_NEGATIVE_PERCENTAGE, 10, Comparison.LESS_THAN) qc3 = QualityConstraint(c9, MpersMetrics.FALSE_NEGATIVE_PERCENTAGE, 5, Comparison.LESS_THAN) emergencyIsDetectedGoal.interp.addQualityConstraint(qc1) emergencyIsDetectedGoal.interp.addQualityConstraint(qc2) emergencyIsDetectedGoal.interp.addQualityConstraint(qc3) qc1 = QualityConstraint(None, MpersMetrics.SECONDS, 60, Comparison.LESS_THAN) centralReceivesInfoGoal.interp.addQualityConstraint(qc1) qc4 = QualityConstraint(None, MpersMetrics.DISTANCE_ERROR, 1000, Comparison.LESS_THAN) qc6 = QualityConstraint(c5, MpersMetrics.DISTANCE_ERROR, 20, Comparison.LESS_THAN) qc5 = QualityConstraint(c10, MpersMetrics.DISTANCE_ERROR, 200, Comparison.LESS_THAN) qc1 = QualityConstraint(None, MpersMetrics.SECONDS, 120, Comparison.LESS_THAN) qc3 = QualityConstraint(c9, MpersMetrics.SECONDS, 240, Comparison.LESS_THAN) qc2 = QualityConstraint(c10, MpersMetrics.SECONDS, 20, Comparison.LESS_THAN) locationIsIdentifiedGoal.interp.addQualityConstraint(qc1) locationIsIdentifiedGoal.interp.addQualityConstraint(qc2) locationIsIdentifiedGoal.interp.addQualityConstraint(qc3) locationIsIdentifiedGoal.interp.addQualityConstraint(qc4) locationIsIdentifiedGoal.interp.addQualityConstraint(qc5) locationIsIdentifiedGoal.interp.addQualityConstraint(qc6) qc1 = QualityConstraint(None, MpersMetrics.SECONDS, 900, Comparison.LESS_THAN) qc2 = QualityConstraint(c10, MpersMetrics.SECONDS, 600, Comparison.LESS_THAN) infoIsPreparedGoal.interp.addQualityConstraint(qc1) infoIsPreparedGoal.interp.addQualityConstraint(qc2) qc1 = QualityConstraint(None, MpersMetrics.NOISE, 10, Comparison.LESS_THAN) qc2 = QualityConstraint(c1, MpersMetrics.NOISE, 3, Comparison.LESS_THAN) isNotifiedAboutEmergencyGoal.interp.addQualityConstraint(qc1) isNotifiedAboutEmergencyGoal.interp.addQualityConstraint(qc2) # Provided Task QoS notifyCentralBySMSTask.setProvidedQuality( None, MpersMetrics.FALSE_NEGATIVE_PERCENTAGE, 10) notifyCentralByInternetTask.setProvidedQuality( None, MpersMetrics.FALSE_NEGATIVE_PERCENTAGE, 5) acceptEmergencyTask.setProvidedQuality( None, MpersMetrics.FALSE_NEGATIVE_PERCENTAGE, 30) confirmEmergencyByCallTask.setProvidedQuality( None, MpersMetrics.FALSE_NEGATIVE_PERCENTAGE, 5) processDataFromSensorsTask.setProvidedQuality( None, MpersMetrics.FALSE_NEGATIVE_PERCENTAGE, 15) collectDataFromSensorsTask.setProvidedQuality(None, MpersMetrics.SECONDS, 120) collectDataFromSensorsTask.setProvidedQuality(c3, MpersMetrics.SECONDS, 60) persistDataToDatabaseTask.setProvidedQuality(None, MpersMetrics.SECONDS, 5) identifySituationTask.setProvidedQuality( None, MpersMetrics.FALSE_NEGATIVE_PERCENTAGE, 20) notifyByMobileVibrationTask.setProvidedQuality(None, MpersMetrics.NOISE, 2) notifyBySoundAlertTask.setProvidedQuality(None, MpersMetrics.NOISE, 9) notifyByLightAlertTask.setProvidedQuality(None, MpersMetrics.NOISE, 0) centralCallTask.setProvidedQuality(None, MpersMetrics.NOISE, 7) sendInfoBySMSTask.setProvidedQuality(None, MpersMetrics.SECONDS, 65) sendInfoBySMSTask.setProvidedQuality(c8, MpersMetrics.SECONDS, 45) sendInfoByInternetTask.setProvidedQuality(None, MpersMetrics.SECONDS, 40) considerLastKnownLocationTask.setProvidedQuality( None, MpersMetrics.DISTANCE_ERROR, 900) considerLastKnownLocationTask.setProvidedQuality(None, MpersMetrics.SECONDS, 15) identifyLocationByVoiceCallTask.setProvidedQuality( None, MpersMetrics.DISTANCE_ERROR, 100) identifyLocationByVoiceCallTask.setProvidedQuality( c11, MpersMetrics.DISTANCE_ERROR, 300) identifyLocationByVoiceCallTask.setProvidedQuality(None, MpersMetrics.SECONDS, 45) accessLocationFromTriangulationTask.setProvidedQuality( None, MpersMetrics.DISTANCE_ERROR, 40) accessLocationFromTriangulationTask.setProvidedQuality( c11, MpersMetrics.DISTANCE_ERROR, 400) accessLocationFromTriangulationTask.setProvidedQuality( None, MpersMetrics.SECONDS, 30) accessLocationFromGPSTask.setProvidedQuality(None, MpersMetrics.DISTANCE_ERROR, 20) accessLocationFromGPSTask.setProvidedQuality(c11, MpersMetrics.DISTANCE_ERROR, 30) accessLocationFromGPSTask.setProvidedQuality(None, MpersMetrics.SECONDS, 50) accessDataFromDatabaseTask.setProvidedQuality(None, MpersMetrics.SECONDS, 20) getInfoFromResponsibleTask.setProvidedQuality(None, MpersMetrics.SECONDS, 25) getInfoFromResponsibleTask.setProvidedQuality(c11, MpersMetrics.SECONDS, 50) ambulanceDispatchDelegationTask.setProvidedQuality(None, MpersMetrics.SECONDS, 30) rootGoal = Goal(Decomposition.AND, "rootGoal") rootGoal = respondToEmergencyGoal return rootGoal