コード例 #1
0
def run_test_plan(world_spec, plan, expression_spec, result, sets={}):
    global run, passed
    run += 1
    try:
        world = make_world(world_spec, sets)
        i = 1
        for p in plan:
            run += 1
            (pre, eff, subst) = p

            preexp = make_expression(pre)
            effexp = make_expression(eff)

            for s in subst:
                (var, val) = s
                preexp = substitute(preexp, var, val)
                effexp = substitute(effexp, var, val)
            if not models(world, preexp):
                print("precondition failed at step", i)
                return False
            world = apply(world, effexp)
            passed += 1
            i += 1
        exp = make_expression(expression_spec)
        res = models(world, exp)
        if res == result:
            passed += 1
            return True
    except Exception:
        traceback.print_exc()
    return False
コード例 #2
0
ファイル: planner.py プロジェクト: muteki86/PF-3335-a54818
 def get_neighbors(self):
     # for each grounded action
     for ac in groundedActions:
         # if the action is modeled in the state
         if expressions.models(self.state,
                               expressions.make_expression(
                                   ac.precondition)):
             ## apply the effect to the world
             newstate = expressions.apply(
                 self.state, expressions.make_expression(ac.effect))
             ## add state to the neighbours list as an edge
             nt = PlanNode(ac.name, newstate, self.objs)
             ne = graph.Edge(nt, 1, ac.name)
             self.neighbours.append(ne)
     return self.neighbours
コード例 #3
0
def run_test_substitute(world_spec, expression_spec, subst, result, sets={}):
    global run, passed
    run += 1
    try:

        world = make_world(world_spec, sets)
        action = make_expression(action_spec)
        world1 = apply(world, action)
        exp = make_expression(expression_spec)
        res = models(world1, exp)
        if res == result:
            passed += 1
            return True
    except Exception:
        traceback.print_exc()
    return False
コード例 #4
0
def run_test_planp(world_spec, plan, expression_spec, result, sets={}):
    global run, passed
    run += 1
    try:
        world = make_world(world_spec, sets)
        i = 1
        for p in plan:
            run += 1
            (pre, eff, subst) = p

            preexp = make_expression(sub(pre, subst))
            effexp = make_expression(sub(eff, subst))
            printNAryTree(effexp.getRoot())

            if not models(world, preexp):
                print("precondition failed at step", i, preexp)
                return False
            world = apply(world, effexp)
            passed += 1
            i += 1
        exp = make_expression(expression_spec)
        res = models(world, exp)
        if res == result:
            passed += 1
            return True
        else:
            print('Not pass planp')
            print('world')
            print(world_spec)
            print('plan')
            print(plan)
            print('exp')
            print(expression_spec)
            print('result')
            print(result)
            print('set')
            print(sets)
    except Exception:
        print('error 5')
        traceback.print_exc()
    return False
コード例 #5
0
ファイル: planner.py プロジェクト: muteki86/PF-3335-a54818
def computeRPG(actions, start, isgoal):

    fluents = []
    actionsApplied = []
    executedActionEffects = {}

    #initialize
    fluents.append(copy.deepcopy(start))
    actionsApplied.append([])
    t = 0

    while not isgoal(fluents[t]):  # while goal is not in the layer
        t += 1
        actionsApplied.append([])
        for rac in groundedActions:  # find the actions that can be applied
            if expressions.models(
                    fluents[t - 1].state,
                    expressions.make_expression(rac.precondition)):
                actionsApplied[t].append(rac)

        fluents.append(copy.deepcopy(
            fluents[t - 1]))  # copy the fluents of last layer

        for act in actionsApplied[t]:  #apply the actions to this  layer
            actionEffects = expressions.apply(
                fluents[t].state,
                expressions.make_expression(act.effect, True))
            aef = []
            for atm in actionEffects.formulas:
                if atm not in fluents[t].state.formulas:
                    aef.append(atm)
                    fluents[t].state.formulas.append(atm)
                if len(aef) > 0:
                    executedActionEffects[str(t) + act.name] = aef

        if t > 0 and fluents[t].state == fluents[
                t -
                1].state:  # if the new state is no different than the last one, fail
            return None, None, None

    return fluents, actionsApplied, executedActionEffects
コード例 #6
0
def run_test_apply(world_spec, action_spec, expression_spec, result, sets={}):
    global run, passed
    run += 1
    try:
        world = make_world(world_spec, sets)
        action = make_expression(action_spec)
        world1 = apply(world, action)
        exp = make_expression(expression_spec)
        res = models(world1, exp)
        if res == result:
            passed += 1
            return True
        else:
            print('Not pass apply')
            print(world_spec)
            print(action_spec)
            print(expression_spec)
            print(sets)
            print(result)
    except Exception:
        print('error 2')
        traceback.print_exc()

    return False