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())
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
def test_shouldGetApplicableDependencies(): root = Goal(Decomposition.AND, "root") context = Context("c1") current = [] current.append(context) task = Task("t1") goal = Goal(Decomposition.AND, "g1") delegation = Delegation("D1") task.addApplicableContext(context) root.addDependency(task) root.addDependency(goal) root.addDependency(delegation) deps = [] deps.append(task) assert 1 == len(deps) assert task in deps
def test_shouldGetDependencies(): root = Goal(Decomposition.AND, "root") task = Task("T1") goal = Goal(Decomposition.AND, "G1") delegation = Delegation("D1") root.addDependency(task) root.addDependency(goal) root.addDependency(delegation) deps = [] deps.append(delegation) deps.append(goal) deps.append(task) for d in deps: assert d in root.dependencies
def test_shouldProvideSpecificContextMetric(): task = Task("T2") currentContext = Context("C1") baseline = None fullContext = [] fullContext.append(currentContext) fullContext.append(baseline) task.setProvidedQuality(currentContext, MpersMetrics.METERS, 50) task.setProvidedQuality(baseline, MpersMetrics.METERS, 30) assert 50 == PragmaticPlanning().myProvidedQuality(task, MpersMetrics.METERS, fullContext)
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
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()
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
from goald.quality.common.model.interpretation import Interpretation from tests.utils.assert_util import assertPlan from tests.test_data.mpers_metric import MpersMetrics from tests.test_data.mpers_model import MpersModel from goald.quality.planning.pragmatic.pragmatic import Pragmatic from goald.quality.planning.optimized_planning import Planning import pytest # Contexts c1 = Context("c1") c2 = Context("c2") 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)
def __init__(self): # Tasks self.notifyCentralBySMSTask = Task("notifyCentralBySMSTask") self.notifyCentralByInternetTask = Task("notifyCentralByInternetTask") self.acceptEmergencyTask = Task("acceptEmergencyTask") self.confirmEmergencyByCallTask = Task("confirmEmergencyByCallTask") self.processDataFromSensorsTask = Task("processDataFromSensorsTask") self.identifySituationTask = Task("identifySituationTask") self.collectDataFromSensorsTask = Task("collectDataFromSensorsTask") self.persistDataToDatabaseTask = Task("persistDataToDatabaseTask") self.notifyByMobileVibrationTask = Task("notifyByMobileVibrationTask") self.notifyBySoundAlertTask = Task("notifyBySoundAlertTask") self.notifyByLightAlertTask = Task("notifyByLightAlertTask") self.centralCallTask = Task("centralCallsPTask") self.sendInfoBySMSTask = Task("sendInfoBySMSTask") self.sendInfoByInternetTask = Task("sendInfoByInternetTask") self.considerLastKnownLocationTask = Task( "considerLastKnownLocationTask") self.identifyLocationByVoiceCallTask = Task( "identifyLocationByVoiceCallTask") self.accessLocationFromTriangulationTask = Task( "accessLocationFromTriangulationTask") self.accessLocationFromGPSTask = Task("accessLocationFromGPSTask") self.accessDataFromDatabaseTask = Task("accessDataFromDatabaseTask") self.getInfoFromResponsibleTask = Task("getInfoFromResponsibleTask") self.ambulanceDispatchDelegationTask = Task( "ambulanceDispatchDelegationTask")
from goald.quality.common.model.interpretation import Interpretation from tests.utils.assert_util import assertPlan from tests.test_data.mpers_metric import MpersMetrics from tests.test_data.mpers_model import MpersModel from goald.quality.planning.pragmatic.pragmatic import Pragmatic from goald.quality.planning.optimized_planning import Planning import pytest # Contexts c1 = Context("c1") c2 = Context("c2") c3 = Context("c3") c4 = Context("c4") task1 = Task("task1") task2 = Task("task2") task3 = Task("task3") 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)
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