Example #1
0
def generate_outcome_fluents(fluent):
    ret = []
    if is_grounded(fluent):
        return [fluent]

    for kb_fluent in KB.get_fluents(fluent):
        unify_subs = unify_args(fluent.args, kb_fluent.args)
        kb_fluent.args = reify_args(kb_fluent.args, unify_subs)
        fluent_args = reify_args(fluent.args, unify_subs)

        if kb_fluent.args == fluent_args:
            ret.append(kb_fluent)

    return ret
Example #2
0
def unify_fluent(cond, cycle_time, counter=0):

    fluent = cond
    temporal_var = cond.time

    # debug_display(fluent, KB.exists_fluent(fluent))

    substitutions = {}
    grounded = is_grounded(fluent)

    # Handle the grounded case
    if grounded:

        # Check if fluent is in KB
        if not KB.exists_fluent(fluent):
            return None

        # Unify with temporal vars, return the substitution
        substitutions.update(unify(
            var(temporal_var.name.split(VAR_SEPARATOR)[0] +
                VAR_SEPARATOR + str(counter)),
            cycle_time))

        yield substitutions

    kb_fluents = KB.get_fluents(fluent)

    for kb_fluent in kb_fluents:
        unify_res = unify_args(fluent.args, kb_fluent.args)

        if unify_res == {}:
            continue

        # debug_display('FLUENT_UNIFY_RES', unify_res)

        unify_res.update(unify(
            var(temporal_var.name.split(VAR_SEPARATOR)[0] +
                VAR_SEPARATOR + str(counter)),
            cycle_time
        ))

        yield unify_res

    return substitutions
Example #3
0
def expand_fluent(constraint, cur_state, states, all_proposed):
    cons_fluent, outcome = constraint.goal, constraint.outcome
    cur_subs = cur_state.subs
    fluents = copy.deepcopy(KB.get_fluents(cons_fluent))

    grounded = True

    for arg in cons_fluent.args:
        try:
            if not cur_subs.get(var(arg.name)):
                grounded = False
        except AttributeError:
            continue

    # debug_display('CONS_FLUENT', cons_fluent, outcome, cur_subs)
    # debug_display('CUR_SUBS', cur_subs)
    # debug_display('FROM KB', fluents)
    # debug_display('ALL_PROP', all_proposed)

    for causality_outcome in all_proposed.fluents:
        if causality_outcome.outcome == A_INITIATE:
            if causality_outcome.fluent in fluents:
                continue

            # TODO: Hotfix, force grounded
            if is_grounded(causality_outcome.fluent):
                # debug_display('CFLUENT', causality_outcome.fluent)
                fluents.append(causality_outcome.fluent)

        # TODO: Why does this work?
        # elif causality_outcome.outcome == A_TERMINATE:
        #     if outcome:
        #         pass
        #     if causality_outcome.fluent not in fluents:
        #         continue
        #     fluents.remove(causality_outcome.fluent)

    # debug_display('FROM KB AFTER ADD', fluents)
    # debug_display()

    # No fluents found
    if not fluents:
        # Expect something
        if outcome:
            return

        new_state = cur_state  # REMOVED_DEEPCOPY
        states.append(new_state)
        return

    matched = False
    for fluent in fluents:
        if grounded:
            res = reify_args(cons_fluent.args, cur_subs)
            if res == fluent.args:
                matched = True
                if outcome:
                    new_state = copy.deepcopy(cur_state)
                    states.append(new_state)
                    continue

            continue

        new_state = copy.deepcopy(cur_state)
        cons_fluent_res = reify_args(cons_fluent.args, cur_subs)
        res = unify_args(cons_fluent_res, fluent.args)

        if res == {}:
            continue

        new_state.update_subs(res)
        states.append(new_state)

    if not outcome and not matched:
        new_state = cur_state  # REMOVED_DEEPCOPY
        states.append(new_state)