コード例 #1
0
    def test_gripper01_extracted_opgraph(self):
        file_dir = os.path.dirname(__file__) #<-- absolute dir the script is in
        original_sas = SAS3Extended.from_file(os.path.join(file_dir, 'test_cases/gripper01.sas'))
        encoded_sas = SAS3Extended.from_file(os.path.join(file_dir, 'test_cases/gripper01_extracted.sas'))

        candidates = extract_tau_operators_opgraph(original_sas)
        if len(candidates) > 0:
            original_sas = encode(original_sas,candidates)
        self.assertEqual(str(original_sas),str(encoded_sas))
コード例 #2
0
    def test_miconic_extracted_top_down(self):
        file_dir = os.path.dirname(__file__) #<-- absolute dir the script is in
        original_sas = SAS3Extended.from_file(os.path.join(file_dir, 'test_cases/miconic.sas'))
        expected_sas = SAS3Extended.from_file(os.path.join(file_dir, 'test_cases/miconic_extracted.sas'))

        candidates = extract_tau_operators_top(original_sas)
        if len(candidates) > 0:
            encoded_sas = encode(original_sas,candidates)
        self.assertEqual(str(encoded_sas),str(expected_sas))
コード例 #3
0
    def test_sokoban01_extracted_top_down(self):
        file_dir = os.path.dirname(__file__) #<-- absolute dir the script is in
        original_sas = SAS3Extended.from_file(os.path.join(file_dir, 'test_cases/sokoban01_essential.sas'))
        expected_sas = SAS3Extended.from_file(os.path.join(file_dir, 'test_cases/sokoban01_extracted.sas'))

        candidates = extract_tau_operators_top(original_sas)
        if len(candidates) > 0:
            encoded_sas = encode(original_sas,candidates)
        normalize(encoded_sas)
        self.assertMultiLineEqual(str(encoded_sas),str(expected_sas))
コード例 #4
0
    def test_sokoban01_unormalized(self):
        file_dir = os.path.dirname(
            __file__)  #<-- absolute dir the script is in
        tested_sas = SAS3Extended.from_file(
            os.path.join(file_dir, 'test_cases/sokoban01_unnormalized.sas'))
        expected_sas = SAS3Extended.from_file(
            os.path.join(file_dir, 'test_cases/sokoban01_extracted.sas'))

        normalize(tested_sas)
        self.assertEqual(str(tested_sas), str(expected_sas))
コード例 #5
0
 def test_sas3_extended(self):
     file_dir = os.path.dirname(__file__) #<-- absolute dir the script is in
     rel_path = 'test_cases/miconic.sas'
     abs_file_path = os.path.join(file_dir, rel_path)
     sas = SAS3Extended.from_file(abs_file_path)
     with open(abs_file_path,'r') as f:
         self.assertEqual(str(sas),f.read())
コード例 #6
0
ファイル: encode.py プロジェクト: dosydon/tau_axiom_extractor
def encode(sas, tau_operators):
    eff_var = {var for op in tau_operators for var,
               to in op.achievement.items() if sas.is_essential(var)}
    inner_goal = {(var, value)
                  for var, value in sas.goal.items() if var in eff_var}
    outer_goal = {var: value for var,
                  value in sas.goal.items() if var not in eff_var}

    primary_var = copy.deepcopy(sas.primary_var)
    secondary_var = copy.deepcopy(sas.secondary_var)
    prop2under = defaultdict(dict)
    primary2secondary = {}
    initial_assignment = sas.initial_assignment.copy()
    goal = outer_goal
    removed_goal = sas.goal.copy()
    axiom_layer = sas.axiom_layer.copy()
    metric = sas.metric
    mutex_group = sas.mutex_group.copy()
    axioms = set()
    operators = []
    removed_operators = set(tau_operators)
    remained_operators = set()
    removed_axioms = sas.axioms.copy()

    pre_existing_secondary_vars = sas.secondary_var.keys()
    max_layer = max([layer for layer in sas.axiom_layer.values()]) + 1
    observable_operators = [
        op for op in sas.operators if op not in tau_operators]

    introduce_base_axioms(primary_var, secondary_var, primary2secondary,
                          initial_assignment, axiom_layer, axioms, eff_var, inner_goal, max_layer, goal)
    copy_secondary_vars(primary_var, secondary_var, initial_assignment, prop2under,
                        axiom_layer, axioms, goal, eff_var, pre_existing_secondary_vars, max_layer)

    introduce_reachability_axioms(primary_var, axiom_layer, primary2secondary,
                                  eff_var, tau_operators, axioms, pre_existing_secondary_vars, prop2under)

    introduce_encoded_observable_operators(observable_operators, primary2secondary,
                                           prop2under, pre_existing_secondary_vars, eff_var, operators, remained_operators)

    copy_axioms(primary_var, removed_operators, prop2under, axioms,
                removed_axioms, eff_var, pre_existing_secondary_vars)

    return SAS3Extended(primary_var=primary_var, secondary_var=secondary_var, initial_assignment=initial_assignment, axiom_layer=axiom_layer, removed_goal=removed_goal, goal=goal, metric=metric, mutex_group=mutex_group, axioms=axioms, operators=operators, removed_operators=removed_operators, remained_operators=remained_operators, removed_axioms=removed_axioms)
コード例 #7
0
        plan, propeties = fd.solve(subsas, sas)
        if not plan:
            raise Exception
        for k, v in propeties.items():
            statistics[k].append(v)
        complete_plan += plan
        for item in plan:
            state.apply(item)
    return complete_plan, statistics


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("sas_file")
    parser.add_argument("sas_plan")
    args = parser.parse_args()

    sas = SAS3Extended.from_file(args.sas_file)

    complete_plan, statistics = decode(sas, plan_from_file(sas, args.sas_plan))
    print("Decoded!")
    with open(args.sas_plan, "w") as f:
        for op in complete_plan:
            print("(" + op.name + ")")
            print("(" + op.name + ")", file=f)
        print(";cost={}".format(len(complete_plan)), file=f)
    print("Decode Peak Memory: {} KB".format(
        max(statistics["peak_memory"] + [0])))
    print("Decode Search Time: {} s".format(
        sum(statistics["search_time"] + [0])))