Пример #1
0
        risk_bound,sc_schedule = paris.stnu_reformulation(global_prog,makespan=True,cc=0.001)

        if risk_bound != None:
            risk_bound = min(risk_bound,1.0)
            print('\nSuccessfully performed STNU reformulation with scheduling risk %f %%!'%(risk_bound*100.0))


            for tc in global_prog.temporal_constraints:
                if tc.type == 'uncontrollable_bounded':
                    tc.type = 'controllable'

            for i in range(len(pddl_episodes)-1):
                global_prog.add_temporal_constraint(TemporalConstraint(start=pddl_episodes[i].end,end=pddl_episodes[i+1].start,
                                                                       ctype='controllable',lb=1.005,ub=2.1))

            global_prog.simplify_temporal_constraints()


            # activation_episode_end_events = [ep.end for ep in activation_episodes]
            # for tc in global_prog.temporal_constraints:
            #     if tc.start in activation_episode_end_events:
            #         global_prog.remove_temporal_constraint(tc)

            global_prog.to_ptpn(filename=output_file)

            print('\nThis is the schedule:')
            for e,t in sorted([(e,t) for e,t in sc_schedule.items()],key=lambda x: x[1]):
                print('\t%s: %.2f s'%(e,t))

        else:
            print('\nFailed to perform STNU reformulation...')
Пример #2
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
Пример #3
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
Пример #4
0
                '\nSuccessfully performed STNU reformulation with scheduling risk %f %%!'
                % (risk_bound * 100.0))

            for tc in global_prog.temporal_constraints:
                if tc.type == 'uncontrollable_bounded':
                    tc.type = 'controllable'

            for i in range(len(pddl_episodes) - 1):
                global_prog.add_temporal_constraint(
                    TemporalConstraint(start=pddl_episodes[i].end,
                                       end=pddl_episodes[i + 1].start,
                                       ctype='controllable',
                                       lb=1.005,
                                       ub=2.1))

            global_prog.simplify_temporal_constraints()

            # activation_episode_end_events = [ep.end for ep in activation_episodes]
            # for tc in global_prog.temporal_constraints:
            #     if tc.start in activation_episode_end_events:
            #         global_prog.remove_temporal_constraint(tc)

            global_prog.to_ptpn(filename=output_file)

            print('\nThis is the schedule:')
            for e, t in sorted([(e, t) for e, t in sc_schedule.items()],
                               key=lambda x: x[1]):
                print('\t%s: %.2f s' % (e, t))

        else:
            print('\nFailed to perform STNU reformulation...')