Exemple #1
0
def get_sports_kb():
    sports_kb = []
    # Predicatul 'Consecutive'
    add_statement(sports_kb, make_atom('Consecutive', make_const('Luni'), make_const('Marti')))
    add_statement(sports_kb, make_atom('Consecutive', make_const('Marti'), make_const('Miercuri')))
    add_statement(sports_kb, make_atom('Consecutive', make_const('Miercuri'), make_const('Joi')))
    add_statement(sports_kb, make_atom('Consecutive', make_const('Joi'), make_const('Vineri')))
    add_statement(sports_kb, make_atom('Consecutive', make_const('Vineri'), make_const('Sambata')))
    add_statement(sports_kb, make_atom('Consecutive', make_const('Sambata'), make_const('Duminica')))
    # Predicatul 'Weekend'
    add_statement(sports_kb, make_atom('Weekend', make_const('Sambata')))
    add_statement(sports_kb, make_atom('Weekend', make_const('Duminica')))
    # Predicatul 'Ploua'
    add_statement(sports_kb, make_atom('Ploua', make_const('Vineri')))
    # TODO 2.1: Dacă a plouat două zile la rând, a treia zi va fi frumos.
    add_statement(sports_kb, make_atom('Frumos',  make_var('day3')), make_atom('Ploua', make_var('day1')),
                 make_atom('Ploua', make_var('day2')), make_atom('Consecutive', make_var('day1'), make_var('day2')),
                 make_atom('Consecutive', make_var('day2'), make_var('day3')))
    # Predicatul 'Frumos'
    add_statement(sports_kb, make_atom('Frumos', make_const('Luni')))
    add_statement(sports_kb, make_atom('Frumos', make_const('Marti')))
    add_statement(sports_kb, make_atom('Frumos', make_const('Miercuri')))
    # TODO 2.2: Dacă a fost frumos trei zile la rând, în cea de-a patra zi va ploua.
    add_statement(sports_kb, make_atom('Ploua', make_var('day4')), make_atom('Frumos', make_var('day1')),
                 make_atom('Frumos', make_var('day2')), make_atom('Frumos', make_var('day3')),
                 make_atom('Consecutive', make_var('day1'), make_var('day2')), make_atom('Consecutive', make_var('day2'), make_var('day3')),
                 make_atom('Consecutive', make_var('day3'), make_var('day4')))
    # Predicatul 'Student'
    add_statement(sports_kb, make_atom('Student', make_const('Nectarie')))
    add_statement(sports_kb, make_atom('Student', make_const('Arsenie')))
    # MergeLaMunte (cine, cand)
    # TODO 2.3: Un student merge întotdeauna la munte dacă este frumos într-o zi de weekend.
    add_statement(sports_kb, make_atom('MergeLaMunte', make_var('Student'), make_var('when')), make_atom('Weekend', make_var('when')),
                 make_atom('Frumos', make_var('when')))
    # Predicatul 'SportDeVara'
    add_statement(sports_kb, make_atom('SportDeVara', make_const('Volei')))
    # Predicatul 'SportDeIarna'
    add_statement(sports_kb, make_atom('SportDeIarna', make_const('Schi')))
    add_statement(sports_kb, make_atom('SportDeIarna', make_const('Sanie')))
    # Predicatul 'PracticaSport'
    add_statement(sports_kb, make_atom('PracticaSport', make_const('Nectarie'), make_const('Schi')))
    add_statement(sports_kb, make_atom('PracticaSport', make_const('Nectarie'), make_const('Sanie')))
    add_statement(sports_kb, make_atom('PracticaSport', make_const('Arsenie'), make_const('Schi')))
    add_statement(sports_kb, make_atom('PracticaSport', make_const('Arsenie'), make_const('Volei')))
    # Predicatul 'Activitate'
    add_statement(sports_kb, make_atom('Activitate', make_var('who'), make_var('what'), make_var('when')),
                  make_atom('MergeLaMunte', make_var('who'), make_var('when')),
                  make_atom('PracticaSport', make_var('who'), make_var('what')))
    make_unique_var_names(sports_kb)
    return sports_kb
    'dimension': [],
    'substance': [],
    'isDirty': [],
    'edge': [],
    'isRoom': [],
    'isWarehouse': [],
    'capacity': []
}
math_predicates = ['isBigger', 'equal', 'sum', 'dif']

state = []
newState = []
reward = 0
Time = -1
# (action_name, [preconditions], [repetitive preconditions], [LA], [LE])
actions = [('Move', [make_var('r1'), make_var('r2')], [
    make_atom('location', make_var('r1')),
    make_atom('edge', make_var('r1'), make_var('r2'), make_var('cost'))
], [], [make_atom('location',
                  make_var('r2'))], [make_atom('location', make_var('r1'))]),
           ('Clean', [make_var('r')], [
               make_atom('location', make_var('r')),
               make_atom('isRoom', make_var('r')),
               make_atom('isDirty', make_var('r'))
           ], [
               make_atom('substance', make_var('r'), make_var('s'),
                         make_var('n')),
               make_atom('carries', make_var('s'), make_var('m')),
               make_atom('isBigger', make_var('m'), make_var('n')),
               make_atom('dif', make_var('m'), make_var('n'), make_var('d'))
           ], [make_atom('carries', make_var('s'), make_var('d'))], [
Exemple #3
0
	'isDirty': [],
	'edge': [],
	'isRoom': [],
	'isWarehouse': [],
	'capacity': []
}
math_predicates = ['isBigger', 'isSmaller', 'equal', 'sum', 'dif']

state = []
newState = []
reward = 0
time = -1
readBefore = False
# (action_name, [preconditions], [repetitive preconditions], [LA], [LE])
actions = [
	('Move', [make_var('r1'), make_var('r2')], 
		[make_atom('location', make_var('r1')), make_atom('edge', make_var('r1'), make_var('r2'), make_var('cost'))], 
		[],
		[make_atom('location', make_var('r2'))], 
		[make_atom('location', make_var('r1'))]),
	('Clean', [make_var('r')], 
		[make_atom('location', make_var('r')), make_atom('isRoom', make_var('r')),
		make_atom('isDirty', make_var('r')), make_atom('dimension', make_var('r'), make_var('dim'))],
		[make_atom('substance', make_var('r'), make_var('s'), make_var('n')),
		make_atom('carries', make_var('s'), make_var('m')), make_atom('isBigger', make_var('m'), make_var('n')),
		make_atom('dif', make_var('m'), make_var('n'), make_var('d'))],
		[make_atom('carries', make_var('s'), make_var('d'))],
		[make_atom('isDirty', make_var('r')), make_atom('carries', make_var('s'), make_var('m'))]),
	('Refill', [make_var('w')], 
		[make_atom('location', make_var('w')), make_atom('isWarehouse', make_var('w')), 
		make_atom('capacity', make_var('n')), make_atom('carries', make_var('sprim'), make_var('mprim')),
Exemple #4
0
    for arg in get_args(formula):
        if is_positive_literal(arg):
            return arg


def is_fact(formula):
    return is_positive_literal(formula)


def is_rule(formula):
    return get_head(formula) == 'or' or get_head(formula) == 'and'


# Test!
# formula: P(x) ^ Q(x) -> R(x)
f = make_or(make_neg(make_atom("P", make_var("x"))),
            make_neg(make_atom("Q", make_var("x"))),
            make_atom("R", make_var("x")))
print(" ; ".join([print_formula(p, True)
                  for p in get_premises(f)]))  # Should be P(?x) ; Q(?x)
print_formula(get_conclusion(f))  # Should be R(?x)
print(is_rule(f))  # must be True
print(is_fact(f))  # must be False
print(is_fact(get_conclusion(f)))  # must be True
print(is_rule(get_conclusion(f)))  # must be False


def equal_terms(t1, t2):
    if is_constant(t1) and is_constant(t2):
        return get_value(t1) == get_value(t2)
    if is_variable(t1) and is_variable(t2):