示例#1
0
def rmpyl_episode_ids(hello,uav):
    """Example of how episode ID's can be used to retrieve them."""
    prog = RMPyL()

    first_uav_seq = prog.sequence(uav.scan(),uav.fly(),id='uav-1-seq')
    second_uav_seq = prog.sequence(uav.scan(),uav.fly(),id='uav-2-seq')

    first_hello_seq = prog.sequence(hello.scan(),hello.fly(),id='hello-1-seq')
    second_hello_seq = prog.sequence(hello.scan(),hello.fly(),id='hello-2-seq')

    prog *= prog.parallel(prog.sequence(first_uav_seq,second_uav_seq,id='uav-seqs'),
                          prog.sequence(first_hello_seq,second_hello_seq,id='hello-seqs'),id='par-seqs')

    #This could have been accomplished much more easily by using the sequence
    #variables directly, but I wanted to show how episodes can be retrieved by
    #ID.
    tc1 = TemporalConstraint(start=prog.episode_by_id('uav-1-seq').end,
                            end=prog.episode_by_id('hello-2-seq').start,
                            ctype='controllable',lb=2.0,ub=3.0)

    tc2 = TemporalConstraint(start=prog.episode_by_id('hello-1-seq').end,
                            end=prog.episode_by_id('uav-2-seq').start,
                            ctype='controllable',lb=0.5,ub=1.0)

    prog.add_temporal_constraint(tc1)
    prog.add_temporal_constraint(tc2)

    return prog
示例#2
0
def rmpyl_original_verbose(hello,uav):
    """
    Implementation of the original RMPL using a more verbose syntax and adding
    a chance constraint.

    ##### Original RMPL

    class UAV {
        value on;
        value off;

        primitive method fly() [3,10];
        primitive method scan() [1,10];
    }

    class Main {
      UAV helo;
      UAV uav;

      method run () {
        [0, 18] sequence {
            parallel {
                sequence {
                    helo.scan();
                    helo.fly();
                }
                sequence {
                    uav.fly();
                    uav.scan();
                }
            }
            choose {
                with reward: 5 {helo.fly();}
                with reward: 7 {uav.fly();}
            }
        }
      }
    }
    """
    prog = RMPyL()
    prog.plan = prog.sequence(
                prog.parallel(
                    prog.sequence(
                        hello.scan(),
                        hello.fly()),
                    prog.sequence(
                        uav.fly(),
                        uav.scan())),
                prog.decide({'name':'UAV-choice','domain':['Hello','UAV'],'utility':[5,7]},
                            hello.fly(),
                            uav.fly()))
    overall_tc = prog.add_overall_temporal_constraint(ctype='controllable',lb=0.0,ub=18.0)
    cc_time = ChanceConstraint(constraint_scope=[overall_tc],risk=0.1)
    prog.add_chance_constraint(cc_time)
    return prog
示例#3
0
def rmpyl_parallel_choices(hello,uav):
    """Simple RMPyL example with parallel execution of choices."""
    uav2 = UAV(name='uav2')

    prog = RMPyL()
    prog *= prog.parallel(
                prog.observe({'name':'HELLO-OBS','domain':['FLY','SCAN','CRASH'],
                          'ctype':'probabilistic','probability':[0.50,0.49,0.01]},
                           hello.fly(),hello.scan(),hello.crash()),
                prog.observe({'name':'UAV-OBS','domain':['FLY','SCAN','CRASH'],
                          'ctype':'probabilistic','probability':[0.50,0.49,0.01]},
                           uav.fly(),uav.scan(),uav.crash()))*uav2.fly()
    return prog
示例#4
0
def rmpyl_parallel_uav():
    hello = UAV('hello')
    uav = UAV('uav')

    prog = RMPyL()
    prog.plan = prog.parallel(
        prog.sequence(
            prog.decide(
                {
                    'name': 'hello-action',
                    'domain': ['Fly', 'Scan'],
                    'utility': [0, 1]
                }, hello.fly(), hello.scan()),
            prog.decide(
                {
                    'name': 'hello-action',
                    'domain': ['Fly', 'Scan'],
                    'utility': [0, 1]
                }, hello.fly(), hello.scan()),
            prog.decide(
                {
                    'name': 'hello-action',
                    'domain': ['Fly', 'Scan'],
                    'utility': [0, 1]
                }, hello.fly(), hello.scan())),
        prog.sequence(
            prog.decide(
                {
                    'name': 'uav-action',
                    'domain': ['Fly', 'Scan'],
                    'utility': [0, 1]
                }, uav.fly(), uav.scan()),
            prog.decide(
                {
                    'name': 'uav-action',
                    'domain': ['Fly', 'Scan'],
                    'utility': [0, 1]
                }, uav.fly(), uav.scan()),
            prog.decide(
                {
                    'name': 'uav-action',
                    'domain': ['Fly', 'Scan'],
                    'utility': [0, 1]
                }, uav.fly(), uav.scan())))
    return prog
示例#5
0
def rmpyl_parallel_uav():
    hello = UAV('hello')
    uav = UAV('uav')

    prog = RMPyL()
    prog.plan = prog.parallel(
                    prog.sequence(
                        prog.decide({'name':'hello-action','domain':['Fly','Scan'],
                                     'utility':[0,1]},
                                     hello.fly(),
                                     hello.scan()),
                        prog.decide({'name':'hello-action','domain':['Fly','Scan'],
                                     'utility':[0,1]},
                                     hello.fly(),
                                     hello.scan()),
                        prog.decide({'name':'hello-action','domain':['Fly','Scan'],
                                     'utility':[0,1]},
                                     hello.fly(),
                                     hello.scan())
                    ),
                    prog.sequence(
                        prog.decide({'name':'uav-action','domain':['Fly','Scan'],
                                     'utility':[0,1]},
                                     uav.fly(),
                                     uav.scan()),
                        prog.decide({'name':'uav-action','domain':['Fly','Scan'],
                                     'utility':[0,1]},
                                     uav.fly(),
                                     uav.scan()),
                        prog.decide({'name':'uav-action','domain':['Fly','Scan'],
                                     'utility':[0,1]},
                                     uav.fly(),
                                     uav.scan())

                    ))
    return prog
示例#6
0
        for op_name,op_param_dict in time_windows['time_windows'].items():
            for arg_set,window_dict in op_param_dict.items():
                for ev_type,time_bound in window_dict.items():
                    orb_ep_id='%s_event_%s-%s'%(ev_type,op_name,'-'.join(arg_set))
                    activation_episodes.append(Episode(id=orb_ep_id,
                                                    action='(%s)'%(orb_ep_id.replace('-',' ')),
                                                    duration={'ctype':'controllable','lb':0.005,'ub':0.1}))
                    activation_tcs.append(TemporalConstraint(start=global_start,
                                                             end=activation_episodes[-1].start,
                                                             ctype='controllable',
                                                             lb=float(time_bound),
                                                             ub=float(time_bound)))

        global_prog = RMPyL(name='run()')
        global_prog *= global_prog.parallel(prog.plan,*activation_episodes,start=global_start)

        activation_tcs.append(TemporalConstraint(start=global_start,end=prog.first_event,
                                                 ctype='controllable',lb=0.0,ub=0.005))

        for tc in activation_tcs:
            global_prog.add_temporal_constraint(tc)

        # rmpyl_policy.to_ptpn(filename=output_file)
        #ipdb.set_trace()

        global_prog.to_ptpn(filename=output_file+'_test')
        paris = PARIS()

        # risk_bound,sc_schedule = paris.stnu_reformulation(rmpyl_policy,makespan=True,cc=0.001)
示例#7
0
def rmpyl_breakfast():
    """
    Example from (Levine & Williams, ICAPS14).
    """
    #Actions that Alice performs
    get_mug_ep = Episode(action='(get alice mug)',
                         duration={
                             'ctype': 'controllable',
                             'lb': 0.5,
                             'ub': 1.0
                         })
    get_glass_ep = Episode(action='(get alice glass)',
                           duration={
                               'ctype': 'controllable',
                               'lb': 0.5,
                               'ub': 1.0
                           })

    make_cofee_ep = Episode(action='(make-coffee alice)',
                            duration={
                                'ctype': 'controllable',
                                'lb': 3.0,
                                'ub': 5.0
                            })
    pour_cofee_ep = Episode(action='(pour-coffee alice mug)',
                            duration={
                                'ctype': 'controllable',
                                'lb': 0.5,
                                'ub': 1.0
                            })
    pour_juice_glass = Episode(action='(pour-juice alice glass)',
                               duration={
                                   'ctype': 'controllable',
                                   'lb': 0.5,
                                   'ub': 1.0
                               })

    get_bagel_ep = Episode(action='(get alice bagel)',
                           duration={
                               'ctype': 'controllable',
                               'lb': 0.5,
                               'ub': 1.0
                           })
    get_cereal_ep = Episode(action='(get alice cereal)',
                            duration={
                                'ctype': 'controllable',
                                'lb': 0.5,
                                'ub': 1.0
                            })

    toast_bagel_ep = Episode(action='(toast alice bagel)',
                             duration={
                                 'ctype': 'controllable',
                                 'lb': 3.0,
                                 'ub': 5.0
                             })
    add_cheese_bagel_ep = Episode(action='(add-cheese alice bagel)',
                                  duration={
                                      'ctype': 'controllable',
                                      'lb': 1.0,
                                      'ub': 2.0
                                  })
    mix_cereal_ep = Episode(action='(mix-cereal alice milk)',
                            duration={
                                'ctype': 'controllable',
                                'lb': 1.0,
                                'ub': 2.0
                            })

    #Actions that the robot performs
    get_grounds_ep = Episode(action='(get grounds robot)',
                             duration={
                                 'ctype': 'controllable',
                                 'lb': 0.5,
                                 'ub': 1.0
                             })
    get_juice_ep = Episode(action='(get juice robot)',
                           duration={
                               'ctype': 'controllable',
                               'lb': 0.5,
                               'ub': 1.0
                           })
    get_milk_ep = Episode(action='(get milk robot)',
                          duration={
                              'ctype': 'controllable',
                              'lb': 0.5,
                              'ub': 1.0
                          })
    get_cheese_ep = Episode(action='(get cheese robot)',
                            duration={
                                'ctype': 'controllable',
                                'lb': 0.5,
                                'ub': 1.0
                            })

    prog = RMPyL()
    prog *= prog.sequence(
        prog.parallel(
            prog.observe(
                {
                    'name': 'observe-utensil',
                    'domain': ['Mug', 'Glass'],
                    'ctype': 'uncontrollable'
                },
                get_mug_ep,
                get_glass_ep,
                id='observe-utensil-ep'),
            prog.decide(
                {
                    'name': 'choose-beverage-ingredient',
                    'domain': ['Grounds', 'Juice'],
                    'utility': [0, 0]
                },
                get_grounds_ep,
                get_juice_ep,
                id='choose-beverage-ingredient-ep')),
        prog.observe(
            {
                'name': 'observe-alice-drink',
                'domain': ['Coffee', 'Juice'],
                'ctype': 'uncontrollable'
            },
            prog.sequence(make_cofee_ep, pour_cofee_ep),
            pour_juice_glass,
            id='observe-alice-drink-ep'),
        prog.parallel(prog.observe(
            {
                'name': 'observe-food',
                'domain': ['Bagel', 'Cereal'],
                'ctype': 'uncontrollable'
            },
            get_bagel_ep,
            get_cereal_ep,
            id='observe-food-ep'),
                      prog.decide(
                          {
                              'name': 'choose-food-ingredient',
                              'domain': ['Milk', 'Cheese'],
                              'utility': [0, 0]
                          },
                          get_milk_ep,
                          get_cheese_ep,
                          id='choose-food-ingredient-ep'),
                      id='parallel-food-ep'),
        prog.observe(
            {
                'name': 'observe-alice-food',
                'domain': ['Bagel', 'Cereal'],
                'ctype': 'uncontrollable'
            }, prog.sequence(toast_bagel_ep, add_cheese_bagel_ep),
            mix_cereal_ep),
        id='breakfast-sequence')

    extra_tcs = [
        TemporalConstraint(
            start=prog.episode_by_id('breakfast-sequence').start,
            end=prog.episode_by_id('observe-utensil-ep').start,
            ctype='controllable',
            lb=0.0,
            ub=0.0),
        TemporalConstraint(
            start=prog.episode_by_id('breakfast-sequence').start,
            end=prog.episode_by_id('choose-beverage-ingredient-ep').start,
            ctype='controllable',
            lb=0.2,
            ub=0.3),
        TemporalConstraint(start=prog.episode_by_id('parallel-food-ep').start,
                           end=prog.episode_by_id('observe-food-ep').start,
                           ctype='controllable',
                           lb=0.0,
                           ub=0.0),
        TemporalConstraint(
            start=prog.episode_by_id('parallel-food-ep').start,
            end=prog.episode_by_id('choose-food-ingredient-ep').start,
            ctype='controllable',
            lb=0.2,
            ub=0.3)
    ]

    for tc in extra_tcs:
        prog.add_temporal_constraint(tc)

    prog.add_overall_temporal_constraint(ctype='controllable', lb=0.0, ub=7.0)
    prog.simplify_temporal_constraints()

    return prog
示例#8
0
def rmpyl_breakfast():
    """
    Example from (Levine & Williams, ICAPS14).
    """
    #Actions that Alice performs
    get_mug_ep = Episode(action='(get alice mug)',duration={'ctype':'controllable','lb':0.5,'ub':1.0})
    get_glass_ep = Episode(action='(get alice glass)',duration={'ctype':'controllable','lb':0.5,'ub':1.0})

    make_cofee_ep = Episode(action='(make-coffee alice)',duration={'ctype':'controllable','lb':3.0,'ub':5.0})
    pour_cofee_ep = Episode(action='(pour-coffee alice mug)',duration={'ctype':'controllable','lb':0.5,'ub':1.0})
    pour_juice_glass = Episode(action='(pour-juice alice glass)',duration={'ctype':'controllable','lb':0.5,'ub':1.0})

    get_bagel_ep = Episode(action='(get alice bagel)',duration={'ctype':'controllable','lb':0.5,'ub':1.0})
    get_cereal_ep = Episode(action='(get alice cereal)',duration={'ctype':'controllable','lb':0.5,'ub':1.0})

    toast_bagel_ep = Episode(action='(toast alice bagel)',duration={'ctype':'controllable','lb':3.0,'ub':5.0})
    add_cheese_bagel_ep = Episode(action='(add-cheese alice bagel)',duration={'ctype':'controllable','lb':1.0,'ub':2.0})
    mix_cereal_ep = Episode(action='(mix-cereal alice milk)',duration={'ctype':'controllable','lb':1.0,'ub':2.0})

    #Actions that the robot performs
    get_grounds_ep = Episode(action='(get grounds robot)',duration={'ctype':'controllable','lb':0.5,'ub':1.0})
    get_juice_ep = Episode(action='(get juice robot)',duration={'ctype':'controllable','lb':0.5,'ub':1.0})
    get_milk_ep = Episode(action='(get milk robot)',duration={'ctype':'controllable','lb':0.5,'ub':1.0})
    get_cheese_ep = Episode(action='(get cheese robot)',duration={'ctype':'controllable','lb':0.5,'ub':1.0})

    prog = RMPyL()
    prog *= prog.sequence(
                prog.parallel(
                    prog.observe(
                        {'name':'observe-utensil','domain':['Mug','Glass'],'ctype':'uncontrollable'},
                        get_mug_ep,
                        get_glass_ep,
                        id='observe-utensil-ep'),
                    prog.decide(
                        {'name':'choose-beverage-ingredient','domain':['Grounds','Juice'],'utility':[0,0]},
                        get_grounds_ep,
                        get_juice_ep,
                        id='choose-beverage-ingredient-ep')),
                prog.observe(
                    {'name':'observe-alice-drink','domain':['Coffee','Juice'],'ctype':'uncontrollable'},
                    prog.sequence(make_cofee_ep,pour_cofee_ep),
                    pour_juice_glass,
                    id='observe-alice-drink-ep'),
                prog.parallel(
                    prog.observe(
                        {'name':'observe-food','domain':['Bagel','Cereal'],'ctype':'uncontrollable'},
                        get_bagel_ep,
                        get_cereal_ep,
                        id='observe-food-ep'),
                    prog.decide(
                        {'name':'choose-food-ingredient','domain':['Milk','Cheese'],'utility':[0,0]},
                        get_milk_ep,
                        get_cheese_ep,
                        id='choose-food-ingredient-ep'),
                    id='parallel-food-ep'),
                prog.observe(
                    {'name':'observe-alice-food','domain':['Bagel','Cereal'],'ctype':'uncontrollable'},
                    prog.sequence(toast_bagel_ep,add_cheese_bagel_ep),
                    mix_cereal_ep),
                id='breakfast-sequence')

    extra_tcs = [TemporalConstraint(start=prog.episode_by_id('breakfast-sequence').start,
                                  end=prog.episode_by_id('observe-utensil-ep').start,
                                  ctype='controllable',lb=0.0,ub=0.0),
                 TemporalConstraint(start=prog.episode_by_id('breakfast-sequence').start,
                                    end=prog.episode_by_id('choose-beverage-ingredient-ep').start,
                                    ctype='controllable',lb=0.2,ub=0.3),
                 TemporalConstraint(start=prog.episode_by_id('parallel-food-ep').start,
                                    end=prog.episode_by_id('observe-food-ep').start,
                                    ctype='controllable',lb=0.0,ub=0.0),
                 TemporalConstraint(start=prog.episode_by_id('parallel-food-ep').start,
                                    end=prog.episode_by_id('choose-food-ingredient-ep').start,
                                    ctype='controllable',lb=0.2,ub=0.3)]

    for tc in extra_tcs:
        prog.add_temporal_constraint(tc)

    prog.add_overall_temporal_constraint(ctype='controllable',lb=0.0,ub=7.0)
    prog.simplify_temporal_constraints()

    return prog
示例#9
0
def rmpyl_simple_verbose(hello,uav):
    """Simple RMPyL example using verbose syntax."""
    prog = RMPyL()
    prog *= prog.sequence(hello.scan(),uav.scan(),prog.parallel(hello.fly(),uav.fly()))
    return prog
示例#10
0
                                action='(%s)' % (orb_ep_id.replace('-', ' ')),
                                duration={
                                    'ctype': 'controllable',
                                    'lb': 0.005,
                                    'ub': 0.1
                                }))
                    activation_tcs.append(
                        TemporalConstraint(start=global_start,
                                           end=activation_episodes[-1].start,
                                           ctype='controllable',
                                           lb=float(time_bound),
                                           ub=float(time_bound)))

        global_prog = RMPyL(name='run()')
        global_prog *= global_prog.parallel(prog.plan,
                                            *activation_episodes,
                                            start=global_start)

        activation_tcs.append(
            TemporalConstraint(start=global_start,
                               end=prog.first_event,
                               ctype='controllable',
                               lb=0.0,
                               ub=0.005))

        for tc in activation_tcs:
            global_prog.add_temporal_constraint(tc)

        # rmpyl_policy.to_ptpn(filename=output_file)
        #ipdb.set_trace()