示例#1
0
文件: run.py 项目: syc7446/pddlstream
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-a',
                        '--algorithm',
                        default='focused',
                        help='Specifies the algorithm')
    parser.add_argument('-g',
                        '--gurobi',
                        action='store_true',
                        help='Uses gurobi')
    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')

    # TODO: test if placed in the same region
    defer_fn = defer_shared  # never_defer | defer_unique | defer_shared
    tamp_problem, args = initialize(parser)
    stream_info = {
        's-region':
        StreamInfo(defer_fn=defer_fn),
        's-grasp':
        StreamInfo(defer_fn=defer_fn),
        's-ik':
        StreamInfo(defer_fn=get_defer_all_unbound(
            inputs='?g')),  # defer_fn | defer_unbound
        's-motion':
        StreamInfo(defer_fn=get_defer_any_unbound()),
        't-cfree':
        StreamInfo(defer_fn=get_defer_any_unbound(), eager=False,
                   negate=True),  # defer_fn |  defer_unbound
        't-region':
        StreamInfo(eager=False, p_success=0),  # bound_fn is None
        'dist':
        FunctionInfo(defer_fn=get_defer_any_unbound(),
                     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
    assert implies(args.skeleton, args.problem == 'tight')
    max_cost = INF  # 8*MOVE_COST
    constraints = PlanConstraints(
        skeletons=skeletons,
        #skeletons=[],
        #skeletons=[skeleton, []],
        exact=True,
        max_cost=max_cost)
    #replan_actions = set()
    replan_actions = {'move', 'pick', 'place'}

    pddlstream_problem = pddlstream_from_tamp(tamp_problem,
                                              collisions=not args.cfree,
                                              use_stream=not args.gurobi,
                                              use_optimizer=args.gurobi)
    dump_pddlstream(pddlstream_problem)
    pr = cProfile.Profile()
    pr.enable()
    success_cost = 0 if args.optimal else INF
    planner = 'max-astar'
    #planner = 'ff-wastar1'
    if args.algorithm == 'focused':
        solver = solve_focused  # solve_focused | solve_serialized
        solution = solver(
            pddlstream_problem,
            constraints=constraints,
            stream_info=stream_info,
            replan_actions=replan_actions,
            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=True,
            effort_weight=1,
            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))
示例#2
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

    with Profiler():
        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':
            assert not args.gurobi
            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)
    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))
示例#3
0
def main():
    # TODO: side grasps (horizontal gripper, one finger, forklift)
    parser = create_parser()
    parser.add_argument('-g',
                        '--gurobi',
                        action='store_true',
                        help='Uses gurobi')
    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')
    tamp_problem, args = initialize(parser)

    # TODO: test if placed in the same region
    defer_fn = defer_shared  # never_defer | defer_unique | defer_shared
    stream_info = {
        's-region':
        StreamInfo(defer_fn=defer_fn),
        's-grasp':
        StreamInfo(defer_fn=defer_fn),
        's-ik':
        StreamInfo(defer_fn=get_defer_all_unbound(
            inputs='?g')),  # defer_fn | defer_unbound
        's-motion':
        StreamInfo(defer_fn=get_defer_any_unbound()),
        't-cfree':
        StreamInfo(defer_fn=get_defer_any_unbound(),
                   eager=False,
                   verbose=False),  # defer_fn |  defer_unbound
        't-region':
        StreamInfo(eager=True, p_success=0),  # bound_fn is None
        'dist':
        FunctionInfo(eager=False,
                     defer_fn=get_defer_any_unbound(),
                     opt_fn=lambda q1, q2: MOVE_COST),
        'gurobi-cfree':
        StreamInfo(
            eager=False, negate=True
        ),  # TODO: AttributeError: 'tuple' object has no attribute 'instance'
        #'gurobi': OptimizerInfo(p_success=0),
        #'rrt': OptimizerInfo(p_success=0),
    }
    #stream_info = {}

    hierarchy = [
        #ABSTRIPSLayer(pos_pre=['atconf']), #, horizon=1),
    ]

    skeletons = [TIGHT_SKELETON] if args.skeleton else None
    assert implies(args.skeleton, args.problem == 'tight')
    max_cost = INF  # 8*MOVE_COST
    constraints = PlanConstraints(
        skeletons=skeletons,
        #skeletons=[],
        #skeletons=[skeleton, []],
        exact=True,
        max_cost=max_cost)
    replan_actions = set()
    #replan_actions = {'move', 'pick', 'place'}

    pddlstream_problem = pddlstream_from_tamp(tamp_problem,
                                              collisions=not args.cfree,
                                              use_stream=not args.gurobi,
                                              use_optimizer=args.gurobi)
    dump_pddlstream(pddlstream_problem)

    success_cost = 0 if args.optimal else INF
    #planner = 'dijkstra'
    planner = 'max-astar'
    #planner = 'ff-wastar1'
    #effort_weight = 1.
    effort_weight = 1. / get_cost_scale()
    #effort_weight = None

    with Profiler(field='cumtime', num=20):
        solution = solve(pddlstream_problem,
                         algorithm=args.algorithm,
                         constraints=constraints,
                         stream_info=stream_info,
                         replan_actions=replan_actions,
                         planner=planner,
                         max_planner_time=10,
                         hierarchy=hierarchy,
                         max_time=args.max_time,
                         max_iterations=INF,
                         debug=False,
                         verbose=True,
                         unit_costs=args.unit,
                         success_cost=success_cost,
                         unit_efforts=True,
                         effort_weight=effort_weight,
                         search_sample_ratio=1,
                         visualize=args.visualize)  # TODO: solve_serialized

    print_solution(solution)
    plan, cost, evaluations = solution
    if plan is not None:
        display_plan(tamp_problem, retime_plan(plan))
示例#4
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))