Esempio n. 1
0
def main(focused=False, deterministic=False, unit_costs=True):
    np.set_printoptions(precision=2)
    if deterministic:
        seed = 0
        np.random.seed(seed)
    print('Seed:', get_random_seed())

    problem_fn = get_tight_problem  # get_tight_problem | get_blocked_problem
    tamp_problem = problem_fn()
    print(tamp_problem)

    stream_info = {
        #'test-region': StreamInfo(eager=True, p_success=0), # bound_fn is None
        #'plan-motion': StreamInfo(p_success=1),  # bound_fn is None
        #'trajcollision': StreamInfo(p_success=1),  # bound_fn is None
        #'cfree': StreamInfo(eager=True),
    }

    pddlstream_problem = pddlstream_from_tamp(tamp_problem)
    pr = cProfile.Profile()
    pr.enable()
    if focused:
        solution = solve_focused(pddlstream_problem,
                                 stream_info=stream_info,
                                 max_time=10,
                                 max_cost=INF,
                                 debug=False,
                                 effort_weight=None,
                                 unit_costs=unit_costs,
                                 postprocess=False,
                                 visualize=False)
    else:
        solution = solve_incremental(pddlstream_problem,
                                     layers=1,
                                     unit_costs=unit_costs,
                                     verbose=False)
    print_solution(solution)
    plan, cost, evaluations = solution
    pr.disable()
    pstats.Stats(pr).sort_stats('tottime').print_stats(10)
    if plan is None:
        return

    colors = dict(zip(sorted(tamp_problem.initial.block_poses.keys()), COLORS))
    viewer = ContinuousTMPViewer(tamp_problem.regions, title='Continuous TAMP')
    state = tamp_problem.initial
    print()
    print(state)
    draw_state(viewer, state, colors)
    for i, (action, args) in enumerate(plan):
        user_input('Continue?')
        print(i, action, args)
        s2 = args[-1]
        state = TAMPState(
            s2[R], s2[H],
            {b: s2[b]
             for b in state.block_poses if s2[b] is not None})
        print(state)
        draw_state(viewer, state, colors)
    user_input('Finish?')
Esempio n. 2
0
def main(success_cost=0):
    parser = argparse.ArgumentParser()
    parser.add_argument('-d', '--deterministic', action='store_true', help='Uses a deterministic sampler')
    parser.add_argument('-a', '--algorithm', default='', help='Specifies the algorithm')
    parser.add_argument('-o', '--optimizer', action='store_true', help='Uses the optimizers')
    parser.add_argument('-t', '--max_time', default=30, type=int, help='The max time')
    parser.add_argument('-u', '--unit', action='store_true', help='Uses unit costs')
    args = parser.parse_args()
    print('Arguments:', args)

    np.set_printoptions(precision=2)
    if args.deterministic:
        set_deterministic()
    print('Random seed:', get_random_seed())
    tamp_problem = get_tight_problem(n_blocks=2, n_goals=2)
    print(tamp_problem)

    pddlstream_problem = pddlstream_from_tamp(tamp_problem, use_stream=not args.optimizer,
                                              use_optimizer=args.optimizer)
    stream_pddl, stream_map = pddlstream_problem[2:4]
    stream_info = {
        't-region': StreamInfo(eager=True, p_success=0), # bound_fn is None
        #'t-cfree': StreamInfo(eager=False, negate=True),
        #'distance': FunctionInfo(opt_fn=lambda q1, q2: MOVE_COST), # Doesn't make a difference
    }

    terms = CONSTRAINTS + OBJECTIVES
    pr = cProfile.Profile()
    pr.enable()
    if args.algorithm == 'focused':
        solution = solve_pddlstream_satisfaction(stream_pddl, stream_map, INIT, terms,
                                                 incremental=False, stream_info=stream_info,
                                                 #search_sample_ratio=1,
                                                 #max_skeletons=1,
                                                 success_cost=success_cost, max_time=args.max_time)
    elif args.algorithm == 'incremental':
        solution = solve_pddlstream_satisfaction(stream_pddl, stream_map, INIT, terms, incremental=True,
                                                 success_cost=success_cost, max_time=args.max_time,
                                                 verbose=False, debug=False)
    else:
        solution = constraint_satisfaction(stream_pddl, stream_map, INIT, terms, stream_info=stream_info,
                                           costs=not args.unit, success_cost=success_cost,
                                           max_time=args.max_time, search_sample_ratio=1,
                                           debug=False)
        #raise ValueError(args.algorithm)

    dump_assignment(solution)
    pr.disable()
    pstats.Stats(pr).sort_stats('tottime').print_stats(10)
    bindings, cost, evaluations = solution
    if bindings is None:
        return
    plan = []
    for name, args in SKELETON:
        new_args = [bindings[a] if is_parameter(a) else a for a in args]
        plan.append((name, new_args))
    display_plan(tamp_problem, plan)
Esempio n. 3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-p', '--problem', default='mirror', help='The name of the problem to solve')
    parser.add_argument('-a', '--algorithm', default='incremental', help='Specifies the algorithm')
    parser.add_argument('-c', '--cfree', action='store_true', help='Disables collisions')
    parser.add_argument('-d', '--deterministic', action='store_true', help='Uses a deterministic sampler')
    parser.add_argument('-g', '--gurobi', action='store_true', help='Uses gurobi')
    parser.add_argument('-n', '--number', default=1, type=int, help='The number of blocks')
    parser.add_argument('-o', '--optimal', action='store_true', help='Runs in an anytime mode')
    parser.add_argument('-s', '--skeleton', action='store_true', help='Enforces skeleton plan constraints')
    parser.add_argument('-t', '--max_time', default=30, type=int, help='The max time')
    parser.add_argument('-u', '--unit', action='store_true', help='Uses unit costs')
    parser.add_argument('-v', '--visualize', action='store_true', help='Visualizes graphs')
    args = parser.parse_args()
    print('Arguments:', args)

    np.set_printoptions(precision=2)
    if args.deterministic:
        random.seed(seed=0)
        np.random.seed(seed=0)
    print('Random seed:', get_random_seed())

    problem_from_name = {fn.__name__: fn for fn in PROBLEMS}
    if args.problem not in problem_from_name:
        raise ValueError(args.problem)
    print('Problem:', args.problem)
    problem_fn = problem_from_name[args.problem]
    tamp_problem = problem_fn(args.number)
    print(tamp_problem)

    pddlstream_problem = pddlstream_from_tamp(tamp_problem, collisions=not args.cfree,
                                              use_stream=not args.gurobi, use_optimizer=args.gurobi)
    print('Constants:', str_from_object(pddlstream_problem.constant_map))
    print('Initial:', sorted_str_from_list(pddlstream_problem.init))
    print('Goal:', str_from_object(pddlstream_problem.goal))

    success_cost = 0 if args.optimal else INF
    planner = 'max-astar'
    #planner = 'ff-wastar1'
    with Profiler(field='cumtime', num=20):
        if args.algorithm == 'incremental':
            solution = solve_incremental(pddlstream_problem,
                                         complexity_step=1, planner=planner,
                                         unit_costs=args.unit, success_cost=success_cost,
                                         max_time=args.max_time, verbose=False)
        else:
            raise ValueError(args.algorithm)

    print_solution(solution)
    plan, cost, evaluations = solution
    if plan is not None:
        display_plan(tamp_problem, plan)
Esempio n. 4
0
def initialize(parser):
    parser.add_argument('-c',
                        '--cfree',
                        action='store_true',
                        help='Disables collisions')
    parser.add_argument('-d',
                        '--deterministic',
                        action='store_true',
                        help='Uses a deterministic sampler')
    parser.add_argument('-t',
                        '--max_time',
                        default=30,
                        type=int,
                        help='The max time')
    parser.add_argument('-n',
                        '--number',
                        default=2,
                        type=int,
                        help='The number of blocks')
    parser.add_argument('-p',
                        '--problem',
                        default='tight',
                        help='The name of the problem to solve')
    parser.add_argument('-u',
                        '--unit',
                        action='store_true',
                        help='Uses unit costs')
    parser.add_argument('-v',
                        '--visualize',
                        action='store_true',
                        help='Visualizes graphs')

    args = parser.parse_args()
    print('Arguments:', args)
    np.set_printoptions(precision=2)
    if args.deterministic:
        set_deterministic()
    print('Random seed:', get_random_seed())

    problem_from_name = {fn.__name__: fn for fn in PROBLEMS}
    if args.problem not in problem_from_name:
        raise ValueError(args.problem)
    print('Problem:', args.problem)
    problem_fn = problem_from_name[args.problem]
    tamp_problem = problem_fn(args.number)
    print(tamp_problem)
    return tamp_problem, args
Esempio n. 5
0
def main(deterministic=False, unit_costs=True):
    np.set_printoptions(precision=2)
    if deterministic:
        seed = 0
        np.random.seed(seed)
    print('Seed:', get_random_seed())

    problem_fn = tight  # get_tight_problem | get_blocked_problem
    tamp_problem = problem_fn(n_blocks=1, n_goals=1, n_robots=1)
    print(tamp_problem)

    pddlstream_problem = pddlstream_from_tamp(tamp_problem)
    with Profiler():
        solution = solve_incremental(pddlstream_problem, complexity_step=1, max_time=30,
                                     unit_costs=unit_costs, verbose=False)
    print_solution(solution)
    plan, cost, evaluations = solution
    step_plan(tamp_problem, plan)
Esempio n. 6
0
def main(deterministic=False, unit_costs=True):
    np.set_printoptions(precision=2)
    if deterministic:
        seed = 0
        np.random.seed(seed)
    print('Seed:', get_random_seed())

    problem_fn = tight  # get_tight_problem | get_blocked_problem
    tamp_problem = problem_fn(n_blocks=2, n_goals=2, n_robots=1)
    print(tamp_problem)

    pddlstream_problem = pddlstream_from_tamp(tamp_problem)
    with Profiler():
        solution = solve_incremental(pddlstream_problem, complexity_step=1, max_time=30, planner='dijkstra',
                                     unit_costs=unit_costs, verbose=False)
        print_solution(solution)
        plan, cost, evaluations = solution
    if plan is None:
        return

    # TODO: might still be a planning bug
    viewer = ContinuousTMPViewer(SUCTION_HEIGHT, tamp_problem.regions, title='Continuous TAMP')
    conf = conf_from_state(tamp_problem.initial)
    print()
    print(conf)
    draw_conf(viewer, tamp_problem, conf)
    user_input('Start?')
    for i, (action, args) in enumerate(plan):
        print(i, action, args)
        if action == 'switch':
            continue
        traj = args[-1]
        for conf in traj[1:]:
            print(conf)
            draw_conf(viewer, tamp_problem, conf)
            user_input('Continue?')
    user_input('Finish?')
Esempio n. 7
0
def main(focused=True,
         deterministic=True,
         unit_costs=False,
         use_synthesizers=False):
    np.set_printoptions(precision=2)
    if deterministic:
        seed = 0
        np.random.seed(seed)
    print('Seed:', get_random_seed())
    if use_synthesizers and not has_gurobi():
        use_synthesizers = False
        print(
            'Warning! use_synthesizers=True requires gurobipy. Setting use_synthesizers=False.'
        )
    print('Focused: {} | Costs: {} | Synthesizers: {}'.format(
        focused, not unit_costs, use_synthesizers))

    problem_fn = get_blocked_problem  # get_tight_problem | get_blocked_problem
    tamp_problem = problem_fn()
    print(tamp_problem)

    action_info = {
        #'move': ActionInfo(terminal=True),
        #'pick': ActionInfo(terminal=True),
        #'place': ActionInfo(terminal=True),
    }
    stream_info = {
        't-region': StreamInfo(eager=True, p_success=0),  # bound_fn is None
        't-cfree': StreamInfo(eager=False, negate=True),
        #'distance': FunctionInfo(opt_fn=lambda *args: 1),
        #'gurobi': OptimizerInfo(p_success=0),
        #'rrt': OptimizerInfo(p_success=0),
    }
    hierarchy = [
        #ABSTRIPSLayer(pos_pre=['atconf']), #, horizon=1),
    ]

    synthesizers = [
        #StreamSynthesizer('cfree-motion', {'s-motion': 1, 'trajcollision': 0},
        #                  gen_fn=from_fn(cfree_motion_fn)),
        StreamSynthesizer('optimize', {
            's-region': 1,
            's-ik': 1,
            'posecollision': 0,
            't-cfree': 0,
            'distance': 0
        },
                          gen_fn=from_fn(get_optimize_fn(
                              tamp_problem.regions))),
    ] if use_synthesizers else []

    pddlstream_problem = pddlstream_from_tamp(tamp_problem)
    print('Initial:', str_from_object(pddlstream_problem.init))
    print('Goal:', str_from_object(pddlstream_problem.goal))
    pr = cProfile.Profile()
    pr.enable()
    if focused:
        solution = solve_focused(
            pddlstream_problem,
            action_info=action_info,
            stream_info=stream_info,
            planner='ff-wastar1',
            max_planner_time=10,
            synthesizers=synthesizers,
            verbose=True,
            max_time=300,
            max_cost=INF,
            debug=False,
            hierarchy=hierarchy,
            effort_weight=1,
            search_sampling_ratio=0,  # TODO: run without to see difference
            unit_costs=unit_costs,
            postprocess=False,
            visualize=False)
    else:
        solution = solve_incremental(pddlstream_problem,
                                     layers=1,
                                     hierarchy=hierarchy,
                                     unit_costs=unit_costs,
                                     verbose=False)
    print_solution(solution)
    plan, cost, evaluations = solution
    pr.disable()
    pstats.Stats(pr).sort_stats('tottime').print_stats(10)
    if plan is not None:
        display_plan(tamp_problem, plan)
Esempio n. 8
0
def main(success_cost=INF, use_costs=True):  # 0 | INF
    parser = argparse.ArgumentParser()
    parser.add_argument('-d',
                        '--deterministic',
                        action='store_true',
                        help='Uses a deterministic sampler')
    parser.add_argument('-a',
                        '--algorithm',
                        default='',
                        help='Specifies the algorithm')
    parser.add_argument('-g',
                        '--gurobi',
                        action='store_true',
                        help='Uses gurobi')
    parser.add_argument('-t',
                        '--max_time',
                        default=30,
                        type=int,
                        help='The max time')
    parser.add_argument('-u',
                        '--unit',
                        action='store_true',
                        help='Uses unit costs')
    args = parser.parse_args()
    print('Arguments:', args)

    np.set_printoptions(precision=2)
    if args.deterministic:
        set_deterministic()
    print('Random seed:', get_random_seed())
    tamp_problem = tight(n_robots=1, n_blocks=2, n_goals=2)
    print(tamp_problem)

    pddlstream_problem = pddlstream_from_tamp(tamp_problem,
                                              use_stream=not args.gurobi,
                                              use_optimizer=args.gurobi)
    _, _, stream_pddl, stream_map, _, _ = pddlstream_problem
    stream_info = {
        't-region': StreamInfo(eager=True, p_success=0),  # bound_fn is None
        #'t-cfree': StreamInfo(eager=False, negate=True),
        #'distance': FunctionInfo(opt_fn=lambda q1, q2: MOVE_COST), # Doesn't make a difference
    }

    terms = CONSTRAINTS
    print('Constraints:', CONSTRAINTS)
    if use_costs:
        print('Objectives:', OBJECTIVES)
        terms += OBJECTIVES
    satisfaction_problem = SatisfactionProblem(stream_pddl, stream_map, INIT,
                                               terms)

    with Profiler():
        if args.algorithm == 'focused':
            solution = solve_pddlstream_satisfaction(
                satisfaction_problem,
                incremental=False,
                stream_info=stream_info,
                #search_sample_ratio=1,
                #max_skeletons=1,
                success_cost=success_cost,
                max_time=args.max_time)
        elif args.algorithm == 'incremental':
            assert not args.gurobi
            solution = solve_pddlstream_satisfaction(satisfaction_problem,
                                                     incremental=True,
                                                     success_cost=success_cost,
                                                     max_time=args.max_time,
                                                     verbose=False,
                                                     debug=False)
        else:
            solution = constraint_satisfaction(satisfaction_problem,
                                               stream_info=stream_info,
                                               costs=not args.unit,
                                               success_cost=success_cost,
                                               max_time=args.max_time,
                                               search_sample_ratio=1,
                                               debug=False)
            #raise ValueError(args.algorithm)

    dump_assignment(solution)
    bindings, cost, evaluations = solution
    if bindings is None:
        return
    plan = []
    for name, args in SKELETON:
        new_args = [bindings[a] if is_parameter(a) else a for a in args]
        plan.append((name, new_args))
    display_plan(tamp_problem, retime_plan(plan))
Esempio n. 9
0
def main(success_cost=0, max_time=30):
    parser = argparse.ArgumentParser()
    parser.add_argument('-d',
                        '--deterministic',
                        action='store_true',
                        help='Uses a deterministic sampler')
    parser.add_argument('-a',
                        '--algorithm',
                        default='focused',
                        help='Specifies the algorithm')
    parser.add_argument('-o',
                        '--optimizer',
                        action='store_true',
                        help='Uses the optimizers')
    args = parser.parse_args()
    print('Arguments:', args)

    np.set_printoptions(precision=2)
    if args.deterministic:
        seed = 0
        np.random.seed(seed)
    print('Random seed:', get_random_seed())
    tamp_problem = get_tight_problem(n_blocks=2, n_goals=2)
    print(tamp_problem)

    pddlstream_problem = pddlstream_from_tamp(tamp_problem,
                                              use_stream=not args.optimizer,
                                              use_optimizer=args.optimizer)
    stream_pddl, stream_map = pddlstream_problem[2:4]
    stream_info = {
        't-region': StreamInfo(eager=True, p_success=0),  # bound_fn is None
        #'t-cfree': StreamInfo(eager=False, negate=True),
    }

    terms = CONSTRAINTS + OBJECTIVES
    pr = cProfile.Profile()
    pr.enable()
    if args.algorithm == 'focused':
        solution = solve_pddlstream_satisfaction(
            stream_pddl,
            stream_map,
            INIT,
            terms,
            incremental=False,
            stream_info=stream_info,
            #search_sample_ratio=1,
            #max_iterations=1,
            success_cost=success_cost,
            max_time=max_time)
    elif args.algorithm == 'incremental':
        solution = solve_pddlstream_satisfaction(stream_pddl,
                                                 stream_map,
                                                 INIT,
                                                 terms,
                                                 incremental=True,
                                                 success_cost=success_cost,
                                                 max_time=max_time,
                                                 verbose=False)
    else:
        raise ValueError(args.algorithm)

    dump_assignment(solution)
    pr.disable()
    pstats.Stats(pr).sort_stats('tottime').print_stats(10)
Esempio n. 10
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-p',
                        '--problem',
                        default='blocked',
                        help='The name of the problem to solve')
    parser.add_argument('-a',
                        '--algorithm',
                        default='focused',
                        help='Specifies the algorithm')
    parser.add_argument('-c',
                        '--cfree',
                        action='store_true',
                        help='Disables collisions')
    parser.add_argument('-d',
                        '--deterministic',
                        action='store_true',
                        help='Uses a deterministic sampler')
    parser.add_argument('-g',
                        '--gurobi',
                        action='store_true',
                        help='Uses gurobi')
    parser.add_argument('-n',
                        '--number',
                        default=2,
                        type=int,
                        help='The number of blocks')
    parser.add_argument('-o',
                        '--optimal',
                        action='store_true',
                        help='Runs in an anytime mode')
    parser.add_argument('-s',
                        '--skeleton',
                        action='store_true',
                        help='Enforces skeleton plan constraints')
    parser.add_argument('-t',
                        '--max_time',
                        default=30,
                        type=int,
                        help='The max time')
    parser.add_argument('-u',
                        '--unit',
                        action='store_true',
                        help='Uses unit costs')
    parser.add_argument('-v',
                        '--visualize',
                        action='store_true',
                        help='Visualizes graphs')
    args = parser.parse_args()
    print('Arguments:', args)

    np.set_printoptions(precision=2)
    if args.deterministic:
        random.seed(seed=0)
        np.random.seed(seed=0)
    print('Random seed:', get_random_seed())

    problem_from_name = {fn.__name__: fn for fn in PROBLEMS}
    if args.problem not in problem_from_name:
        raise ValueError(args.problem)
    print('Problem:', args.problem)
    problem_fn = problem_from_name[args.problem]
    tamp_problem = problem_fn(args.number)
    print(tamp_problem)

    action_info = {
        #'move': ActionInfo(terminal=True),
        #'pick': ActionInfo(terminal=True),
        #'place': ActionInfo(terminal=True),
    }
    stream_info = {
        't-region': StreamInfo(eager=False, p_success=0),  # bound_fn is None
        't-cfree': StreamInfo(eager=False, negate=True),
        'distance': FunctionInfo(opt_fn=lambda q1, q2: MOVE_COST),
        'gurobi-cfree': StreamInfo(eager=False, negate=True),
        #'gurobi': OptimizerInfo(p_success=0),
        #'rrt': OptimizerInfo(p_success=0),
    }
    hierarchy = [
        #ABSTRIPSLayer(pos_pre=['atconf']), #, horizon=1),
    ]

    skeletons = [TIGHT_SKELETON] if args.skeleton else None
    max_cost = INF  # 8*MOVE_COST
    constraints = PlanConstraints(
        skeletons=skeletons,
        #skeletons=[],
        #skeletons=[skeleton, []],
        exact=True,
        max_cost=max_cost)

    pddlstream_problem = pddlstream_from_tamp(tamp_problem,
                                              collisions=not args.cfree,
                                              use_stream=not args.gurobi,
                                              use_optimizer=args.gurobi)
    print('Initial:', sorted_str_from_list(pddlstream_problem.init))
    print('Goal:', str_from_object(pddlstream_problem.goal))
    pr = cProfile.Profile()
    pr.enable()
    success_cost = 0 if args.optimal else INF
    planner = 'max-astar'
    #planner = 'ff-wastar1'
    if args.algorithm == 'focused':
        solution = solve_focused(
            pddlstream_problem,
            constraints=constraints,
            action_info=action_info,
            stream_info=stream_info,
            planner=planner,
            max_planner_time=10,
            hierarchy=hierarchy,
            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,
            search_sample_ratio=1,
            #max_skeletons=None, bind=True,
            visualize=args.visualize)
    elif args.algorithm == 'incremental':
        solution = solve_incremental(pddlstream_problem,
                                     constraints=constraints,
                                     complexity_step=2,
                                     planner=planner,
                                     hierarchy=hierarchy,
                                     unit_costs=args.unit,
                                     success_cost=success_cost,
                                     max_time=args.max_time,
                                     verbose=False)
    else:
        raise ValueError(args.algorithm)

    print_solution(solution)
    plan, cost, evaluations = solution
    pr.disable()
    pstats.Stats(pr).sort_stats('cumtime').print_stats(20)
    if plan is not None:
        display_plan(tamp_problem, retime_plan(plan))
Esempio n. 11
0
def main(focused=True, deterministic=False, unit_costs=False):
    np.set_printoptions(precision=2)
    if deterministic:
        seed = 0
        np.random.seed(seed)
    print('Seed:', get_random_seed())

    problem_fn = get_blocked_problem  # get_tight_problem | get_blocked_problem
    tamp_problem = problem_fn()
    print(tamp_problem)

    action_info = {
        #'move': ActionInfo(terminal=True),
        #'pick': ActionInfo(terminal=True),
        #'place': ActionInfo(terminal=True),
    }
    stream_info = {
        #'test-region': StreamInfo(eager=True, p_success=0), # bound_fn is None
        #'plan-motion': StreamInfo(p_success=1),  # bound_fn is None
        #'trajcollision': StreamInfo(p_success=1),  # bound_fn is None
        #'cfree': StreamInfo(eager=True),
    }

    dynamic = [
        StreamSynthesizer('cfree-motion', {
            'plan-motion': 1,
            'trajcollision': 0
        },
                          gen_fn=from_fn(cfree_motion_fn)),
        #StreamSynthesizer('optimize', {'sample-pose': 1, 'inverse-kinematics': 1,
        #                           'posecollision': 0, 'distance': 0},
        #                  gen_fn=from_fn(get_optimize_fn(tamp_problem.regions))),
    ]

    pddlstream_problem = pddlstream_from_tamp(tamp_problem)
    pr = cProfile.Profile()
    pr.enable()
    if focused:
        solution = solve_focused(pddlstream_problem,
                                 action_info=action_info,
                                 stream_info=stream_info,
                                 synthesizers=dynamic,
                                 max_time=10,
                                 max_cost=INF,
                                 debug=False,
                                 effort_weight=None,
                                 unit_costs=unit_costs,
                                 postprocess=False,
                                 visualize=False)
    else:
        solution = solve_incremental(pddlstream_problem,
                                     layers=1,
                                     unit_costs=unit_costs)
    print_solution(solution)
    plan, cost, evaluations = solution
    pr.disable()
    pstats.Stats(pr).sort_stats('tottime').print_stats(10)
    if plan is None:
        return

    colors = dict(zip(sorted(tamp_problem.initial.block_poses.keys()), COLORS))
    viewer = ContinuousTMPViewer(tamp_problem.regions, title='Continuous TAMP')
    state = tamp_problem.initial
    print()
    print(state)
    draw_state(viewer, state, colors)
    for i, action in enumerate(plan):
        user_input('Continue?')
        print(i, *action)
        state = apply_action(state, action)
        print(state)
        draw_state(viewer, state, colors)
    user_input('Finish?')
Esempio n. 12
0
def main(use_synthesizers=False):
    parser = argparse.ArgumentParser()
    parser.add_argument('-p', '--problem', default='blocked', help='The name of the problem to solve')
    parser.add_argument('-a', '--algorithm', default='focused', help='Specifies the algorithm')
    parser.add_argument('-c', '--cfree', action='store_true', help='Disables collisions')
    parser.add_argument('-d', '--deterministic', action='store_true', help='Uses a deterministic sampler')
    parser.add_argument('-u', '--unit', action='store_true', help='Uses unit costs')
    parser.add_argument('-o', '--optimal', action='store_true', help='Runs in an anytime mode')
    parser.add_argument('-t', '--max_time', default=20, type=int, help='The max time')
    args = parser.parse_args()
    print('Arguments:', args)
    print('Synthesizers: {}'.format(use_synthesizers))

    np.set_printoptions(precision=2)
    if args.deterministic:
        seed = 0
        np.random.seed(seed)
    print('Random seed:', get_random_seed())
    if use_synthesizers and not has_gurobi():
        use_synthesizers = False
        print('Warning! use_synthesizers=True requires gurobipy. Setting use_synthesizers=False.')

    if args.problem not in PROBLEMS:
        raise ValueError(args.problem)
    print('Problem:', args.problem)
    problem_fn = PROBLEMS[args.problem]
    tamp_problem = problem_fn()
    print(tamp_problem)

    action_info = {
        #'move': ActionInfo(terminal=True),
        #'pick': ActionInfo(terminal=True),
        #'place': ActionInfo(terminal=True),
    }
    stream_info = {
        't-region': StreamInfo(eager=True, p_success=0), # bound_fn is None
        't-cfree': StreamInfo(eager=False, negate=True),
        'distance': FunctionInfo(opt_fn=lambda q1, q2: MOVE_COST),
        #'gurobi': OptimizerInfo(p_success=0),
        #'rrt': OptimizerInfo(p_success=0),
    }
    hierarchy = [
        #ABSTRIPSLayer(pos_pre=['atconf']), #, horizon=1),
    ]

    synthesizers = [
        #StreamSynthesizer('cfree-motion', {'s-motion': 1, 'trajcollision': 0},
        #                  gen_fn=from_fn(cfree_motion_fn)),
        StreamSynthesizer('optimize', {'s-region': 1, 's-ik': 1,
                                       'posecollision': 0, 't-cfree': 0, 'distance': 0},
                          gen_fn=from_fn(get_optimize_fn(tamp_problem.regions))),
    ] if use_synthesizers else []


    skeleton = [
        ('move', ['?q0', WILD, '?q1']),
        ('pick', ['b0', '?p0', '?q1']),
        ('move', ['?q1', WILD, '?q2']),
        ('place', ['b0', '?p1', '?q2']),
    ]
    constraints = PlanConstraints(#skeletons=None,
                                  #skeletons=[],
                                  #skeletons=[skeleton],
                                  #skeletons=[skeleton, []],
                                  #exact=False,
                                  max_cost=INF)

    pddlstream_problem = pddlstream_from_tamp(tamp_problem, collisions=not args.cfree)
    print('Initial:', str_from_object(pddlstream_problem.init))
    print('Goal:', str_from_object(pddlstream_problem.goal))
    pr = cProfile.Profile()
    pr.enable()
    success_cost = 0 if args.optimal else INF
    if args.algorithm == 'focused':
        solution = solve_focused(pddlstream_problem, constraints=constraints,
                                 action_info=action_info, stream_info=stream_info, synthesizers=synthesizers,
                                 planner='ff-wastar1', max_planner_time=10, hierarchy=hierarchy, 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,
                                 search_sample_ratio=0,
                                 #max_skeletons=None,
                                 visualize=False)
    elif args.algorithm == 'incremental':
        solution = solve_incremental(pddlstream_problem, constraints=constraints,
                                     complexity_step=2, hierarchy=hierarchy,
                                     unit_costs=args.unit, success_cost=success_cost,
                                     max_time=args.max_time, verbose=False)
    else:
        raise ValueError(args.algorithm)

    print_solution(solution)
    plan, cost, evaluations = solution
    pr.disable()
    pstats.Stats(pr).sort_stats('tottime').print_stats(10)
    if plan is not None:
        display_plan(tamp_problem, plan)