Ejemplo n.º 1
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
Ejemplo 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())
Ejemplo n.º 3
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
Ejemplo n.º 4
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
def test_interpretation():
    interp = Interpretation()
    context = Context("C1")
    commonMetrics = CommonMetrics()
    qc = QualityConstraint(context, commonMetrics.SECONDS, 15,
                           Comparison.LESS_THAN)

    interp.addQualityConstraint(qc)
    map = interp.getContextDependentInterpretation()

    assert 1 == len(map)
    assert 1 == len(map[context])

    assert 1 == len(map)
Ejemplo n.º 6
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
def test_getQC():
    interp = Interpretation()
    context = Context("C1")
    commonMetrics = CommonMetrics()

    qc1 = QualityConstraint(context, commonMetrics.SECONDS, 15,
                            Comparison.LESS_THAN)
    qc2 = QualityConstraint(context, commonMetrics.METERS, 100,
                            Comparison.LESS_THAN)

    interp.addQualityConstraint(qc1)
    interp.addQualityConstraint(qc2)

    listContext = [context]

    assert qc1 in interp.getQualityConstraints(listContext)
    assert qc2 in interp.getQualityConstraints(listContext)
Ejemplo n.º 8
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()
Ejemplo n.º 9
0
    def __init__(self, decomposition, identifier):
        Goal.__init__(self, decomposition, identifier)

        self.interp = Interpretation()
        self.maxValue = 0
        self.task = []
        self.value = []
        self.weight = []
        self.group = []
        self.solution = []
Ejemplo n.º 10
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
Ejemplo n.º 11
0
    def mergeKnapsack(self, newKnapsack, interp):
        self.task.extend(newKnapsack.task)
        self.value.extend(newKnapsack.value)
        self.weight.extend(newKnapsack.weight)
        self.group.extend(newKnapsack.group)

        newInterp = Interpretation()
        newInterp.merge(self.interp)
        newInterp.merge(interp)
    def mergeInterp(self, goal, interp):
        newInterp = Interpretation()
        newInterp.merge(goal.interp)
        newInterp.merge(interp)

        return newInterp
Ejemplo n.º 13
0
    def __init__(self, decomposition, identifier):
        Goal.__init__(self, decomposition, identifier)

        self.interp = Interpretation()
Ejemplo n.º 14
0
    def isAchievable(self, current, interp):
        newInterp = Interpretation()
        newInterp.merge(self.interp)
        newInterp.merge(interp)

        return PragmaticPlanning().isAchievable(self, current, newInterp)