Example #1
0
def mme_search(search, heuristic, explained_plan, m_r: Task, m_h: Task):
    eps_mme = []
    fringe = PrioQueue(search, heuristic, explained_plan)
    c_list = []
    h_list = []
    fringe.push((m_r, []), 0)
    m_hat = m_h
    while len(fringe) != 0:
        x, c = fringe.pop(m_hat)
        m_hat, eps = x
        m_hat_optimal = search_plan(m_hat, search, heuristic)
        if m_hat_optimal is None or not is_plan_applicable(
                explained_plan,
                m_hat) or len(explained_plan) > len(m_hat_optimal):
            h_list.append(m_hat.get_gamma() ^ m_r.get_gamma())
        else:
            c_list.append(m_hat.get_gamma())
            for f in m_hat.get_gamma() - m_h.get_gamma():
                lamb = Operator("del-{}".format(f), m_hat.get_gamma(), {}, {f})
                new_gamma = lamb.apply(m_hat.get_gamma())
                if new_gamma not in c_list:
                    sym_diff = m_hat.get_gamma() ^ m_r.get_gamma()
                    prop3_violated = False
                    for s in subsets(sym_diff):
                        if s in h_list:
                            prop3_violated = True
                            break
                    if not prop3_violated:
                        fringe.push((Task.from_gamma(new_gamma), eps + [lamb]),
                                    c + 1)
                        if len(eps) > len(eps_mme):
                            eps_mme = eps

            for f in m_h.get_gamma() - m_hat.get_gamma():
                lamb = Operator("add-{}".format(f), m_hat.get_gamma(), {f}, {})
                new_gamma = lamb.apply(m_hat.get_gamma())
                if new_gamma not in c_list:
                    sym_diff = m_hat.get_gamma() ^ m_r.get_gamma()
                    prop3_violated = False
                    for s in subsets(sym_diff):
                        if s in h_list:
                            prop3_violated = True
                            break
                    if not prop3_violated:
                        fringe.push((Task.from_gamma(new_gamma), eps + [lamb]),
                                    c + 1)
                        if len(eps) > len(eps_mme):
                            eps_mme = eps

    print(m_hat.get_gamma() ^ m_r.get_gamma())
    return explained_plan, eps_mme
Example #2
0
def mce_search(search, heuristic, explained_plan, m_r: Task, m_h: Task):
    c_list = []  # Closed list
    p_r = explained_plan
    fringe = PrioQueue(search, heuristic, explained_plan)
    fringe.push((m_h, []), 0)
    m_hat = m_h
    i = 0
    print(m_r)
    while True:
        print(i)
        i += 1
        print("Popping")
        x, c = fringe.pop(m_hat)
        m_hat, eps = x
        print("Checking plan optimality")
        p_h = search_plan(m_hat, search, heuristic)
        if is_plan_optimal(p_r, m_hat, p_h):
            return p_r, eps
        else:
            c_list.append(m_hat.get_gamma())
            for f in m_hat.get_gamma() - m_r.get_gamma():
                print("Fact to be removed:", f)
                lamb = Operator("del-{}".format(f), m_hat.get_gamma(), {}, {f})
                new_gamma = lamb.apply(m_hat.get_gamma())
                if new_gamma not in c_list:
                    fringe.push((Task.from_gamma(new_gamma), eps + [lamb]),
                                c + 1)
                else:
                    print("In c_list !")

            print("Robot gamma:", m_r.get_gamma(), "\nExplored gamma: ",
                  m_hat.get_gamma(), "\nG(Mr) \\ G(Mh):",
                  m_r.get_gamma() - m_hat.get_gamma())
            for f in m_r.get_gamma() - m_hat.get_gamma():
                print("fact to be added: ", f)
                lamb = Operator("add-{}".format(f), m_hat.get_gamma(), {f}, {})
                new_gamma = lamb.apply(m_hat.get_gamma())
                if new_gamma not in c_list:
                    fringe.push((Task.from_gamma(new_gamma), eps + [lamb]),
                                c + 1)
                    #print(Task.from_gamma(new_gamma))
                else:
                    print("In c_list !")