Example #1
0
def main():
    parser = argparse.ArgumentParser()
    #parser.add_argument('-p', '--problem', default='problem1', help='The name of the problem to solve')
    parser.add_argument('-a', '--algorithm', default=None, help='Specifies the algorithm')
    parser.add_argument('-o', '--optimal', action='store_true', help='Runs in an anytime mode')
    parser.add_argument('-t', '--max_time', default=2, type=int, help='The max time')
    args = parser.parse_args()
    print('Arguments:', args)

    problem_fn = problem3 # problem1 | problem2 | problem3
    stream_pddl, stream_map, init, terms = problem_fn()
    #print('Init:', pddlstream_problem.init)
    #print('Goal:', pddlstream_problem.goal)

    info = {
        # Intentionally, misleading the stream
        'positive': StreamInfo(overhead=2),
        'negative': StreamInfo(overhead=1),
        'test-small': StreamInfo(p_success=1e-1),
        # Alternatively, can make the second stream called work
    }
    success_cost = 0 if args.optimal else INF
    if args.algorithm == 'focused':
        solution = solve_pddlstream_satisfaction(stream_pddl, stream_map, init, terms, incremental=False,
                                                 stream_info=info, max_time=args.max_time, success_cost=success_cost)
    elif args.algorithm == 'incremental':
        solution = solve_pddlstream_satisfaction(stream_pddl, stream_map, init, terms, incremental=True,
                                                 max_time=args.max_time, success_cost=success_cost)
    else:
        solution = constraint_satisfaction(stream_pddl, stream_map, init, terms, stream_info=info,
                                           max_time=args.max_time, success_cost=success_cost)
    dump_assignment(solution)
Example #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)
Example #3
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))
Example #4
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)