Esempio n. 1
0
    def isAchievable(self, goal, current, interp):
        # Check if Goal is achievable for current context
        if not self.isApplicable(goal, current):
            return None
        # Active taks or goals that are dendencies for self.goal achievement
        dependencies = goal.getApplicableDependencies(current)

        if goal.decomposition == Decomposition.OR:
            mapTasks = []

            # if decomposition is OR return first achievable plan from dependencies list
            for dep in dependencies:
                if (dep.myType() is Refinement().GOAL):
                    if type(dep).__name__ == 'Pragmatic':
                        dep.isAchievable(current, interp)
                    else:
                        plan = self.isAchievable(dep, current, interp)
                elif (dep.myType() is Refinement().TASK):
                    if self.isAchievableTask(dep, current, interp):
                        qc = self.getQCsFromTask(dep, current, interp)
                        mapTasks.append({'task': dep, 'qc': qc})

            if len(mapTasks) > 0:
                mapTasks = sorted(mapTasks, key=lambda x: x['qc'])
                plan = Plan(mapTasks[0]['task'])

                return plan

            return None
        else:
            # else decomposition is AND return achievables plans list from dependencies list
            complete = Plan()
            for dep in dependencies:
                if (dep.myType() is Refinement().GOAL):
                    if type(dep).__name__ == 'Pragmatic':
                        plan = dep.isAchievable(current, interp)
                    else:
                        plan = self.isAchievable(dep, current, interp)
                elif (dep.myType() is Refinement().TASK):
                    plan = self.isAchievableTask(dep, current, interp)

                if plan:
                    complete.add(plan)
                else:
                    return None
            if len(complete.getTasks()) > 0:
                return complete
            else:
                return None
Esempio n. 2
0
def test_refinement():
    refinement = Refinement()
    task = Task("T1")
    delegation = Delegation("D1")
    goal = Goal(Decomposition.AND, "G1")

    assert task.myType() is refinement.TASK
    assert delegation.myType() is refinement.DELEGATION
    assert goal.myType() is refinement.GOAL
Esempio n. 3
0
 def __init__(self, decomposition, identifier):
     Refinement.__init__(self, identifier)
     self.decomposition = decomposition
Esempio n. 4
0
 def myType(self):
     return Refinement().GOAL
Esempio n. 5
0
 def __init__(self, identifier):
     Refinement.__init__(self, identifier)
     self.providedQualityLevels = {}
     self.identifier = identifier
Esempio n. 6
0
 def myType(self):
     return Refinement().DELEGATION
Esempio n. 7
0
 def __init__(self, identifier):
     Refinement.__init__(self, identifier)