Ejemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-a', '--attachments', action='store_true')
    parser.add_argument('-o', '--optimal', action='store_true', help='Runs in an anytime mode')

    tamp_problem, args = initialize(parser)
    stream_info = {
        't-region': StreamInfo(eager=False, p_success=0),
        'distance': FunctionInfo(opt_fn=lambda q1, q2: MOVE_COST),
    }

    pddlstream_problem = pddlstream_from_tamp(tamp_problem)
    dump_pddlstream(pddlstream_problem)

    success_cost = 0 if args.optimal else INF
    planner = 'max-astar'
    #planner = 'ff-wastar1'
    with Profiler():
        if args.attachments:
            solution = solve_incremental(pddlstream_problem, planner='ff-wastar1', max_time=args.max_time, verbose=True)
        else:
            solution = solve_focused(pddlstream_problem, stream_info=stream_info,
                                     planner=planner, max_planner_time=10, debug=False,
                                     max_time=args.max_time, max_iterations=INF, verbose=True,
                                     unit_costs=args.unit, success_cost=success_cost,
                                     unit_efforts=False, effort_weight=0,
                                     max_skeletons=None, bind=True,
                                     visualize=args.visualize)

        print_solution(solution)
    plan, cost, evaluations = solution
    step_plan(tamp_problem, plan)
Ejemplo n.º 2
0
def main():
    parser = argparse.ArgumentParser()

    tamp_problem, args = initialize(parser)
    pddlstream_problem = pddlstream_from_tamp(tamp_problem)
    dump_pddlstream(pddlstream_problem)

    with Profiler():
        solution = solve_incremental(pddlstream_problem,
                                     planner='ff-wastar1',
                                     max_time=args.max_time,
                                     verbose=False)
        print_solution(solution)
    plan, cost, evaluations = solution
    step_plan(tamp_problem, plan)
Ejemplo n.º 3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-a', '--algorithm', default='focused', help='Specifies the algorithm')
    parser.add_argument('-s', '--skeleton', action='store_true', help='Enforces skeleton plan constraints')

    tamp_problem, args = initialize(parser)

    colors = dict(zip(sorted(tamp_problem.initial.block_poses.keys()), COLORS))
    viewer = ContinuousTMPViewer(SUCTION_HEIGHT, tamp_problem.regions, title='Continuous TAMP')
    draw_state(viewer, tamp_problem.initial, colors)

    [robot] = tamp_problem.initial.robot_confs
    blocks = sorted(tamp_problem.initial.block_poses)
    regions = sorted(set(tamp_problem.regions) - {GROUND_NAME})
    print(robot)
    print(blocks)
    print(regions)
    print(tamp_problem)

    domain_pddl = read(get_file_path(__file__, 'domain.pddl'))
    stream_pddl = read(get_file_path(__file__, 'stream.pddl'))
    constant_map = {}
    stream_map = DEBUG # TODO: reuse same streams

    stream_info = {
        't-region': StreamInfo(eager=False, p_success=0),  # bound_fn is None
    }

    streams_from_problem = {}
    for order in permutations(blocks):
        for region in regions: # Objects could also have separate goals
            print(SEPARATOR)
            print('Block order:', order)
            print('Goal region:', region)
            #tamp_problem = dual(n_blocks=args.number, goal_regions=[region])
            tamp_problem.goal_regions.update({block: region for block in order})

            init, goal = create_problem(tamp_problem)
            problem = PDDLProblem(domain_pddl, constant_map, stream_pddl, stream_map, init, goal)
            dump_pddlstream(problem)

            skeleton = create_skeleton(robot, order, home=tamp_problem.goal_conf is not None)
            print(skeleton)
            skeletons = [skeleton]
            #skeletons = None
            constraints = PlanConstraints(skeletons=skeletons, exact=True)

            solution = solve_focused(problem, constraints=constraints, stream_info=stream_info,
                                     planner='max-astar', max_planner_time=10, debug=False,
                                     max_time=args.max_time, verbose=True,
                                     unit_costs=True, unit_efforts=True, effort_weight=1)
            print_solution(solution)
            plan, cost, evaluations = solution
            assert plan is not None

            # TODO: params not sufficient if no output stream or output not in plan
            streams = set()
            for name, params in plan:
                for param in params:
                    value = get_stream_value(param)
                    if isinstance(value, StreamValue):
                        # TODO: propagate recursively
                        streams.add((value.stream, value.inputs))
            streams_from_problem[order, region] = streams
            #print(streams)
            #user_input()

    print(SEPARATOR)
    dump_statistics()

    print(SEPARATOR)
    best_problems, best_p = None, -INF
    for problems in combinations(streams_from_problem, r=2): # Make r a parameter
        stream_plans = [streams_from_problem[problem] for problem in problems]
        intersection = set.intersection(*stream_plans)
        p = p_disjunction(stream_plans, STATS_PER_STREAM)
        assert 0 <= p <= 1
        print('Problems: {} | Intersection: {} | p={:.3f}'.format(problems, len(intersection), p)) #, intersection)
        if p > best_p:
            best_problems, best_p = problems, p

    print('\nBest: {} (p={:.3f})'.format(best_problems, best_p))