def generate_atoms_inst_set(s):
    res = []

    for inst in s[0]:
        values = [int(i.nb) for i in inst]

        # depth
        if len(values) > depth() + 1:
            raise SemanticError('depth of ' + str(inst) +
                                ' greater than the depth of the problem (' +
                                str(depth()) + ')')

        # incorrect agents
        if any(i > nb_agts() for i in values):
            raise SemanticError('incorrect agents in ' + str(inst) +
                                ' (max ' + str(nb_agts()) + ')')

        atom = Atom(values[-1], values[:-1])

        # introspective
        if atom.is_instrospective():
            raise SemanticError('introspective atoms are forbidden (found ' +
                                str(atom) + ' in ' + str(s) + ')')

        res.append(atom)

    return res
Example #2
0
def generate_atoms_inst_set(s):
    res = []

    for inst in s[0]:
        values = [int(i.nb) for i in inst]

        # depth
        if len(values) > depth() + 1:
            raise SemanticError('depth of ' + str(inst) +
                                ' greater than the depth of the problem (' +
                                str(depth()) + ')')

        # incorrect agents
        if any(i > nb_agts() for i in values):
            raise SemanticError('incorrect agents in ' + str(inst) + ' (max ' +
                                str(nb_agts()) + ')')

        atom = Atom(values[-1], values[:-1])

        # introspective
        if atom.is_instrospective():
            raise SemanticError('introspective atoms are forbidden (found ' +
                                str(atom) + ' in ' + str(s) + ')')

        res.append(atom)

    return res
def print_problem_file(base, file):
    output = ""
    output += ';; Gossip problem - PDDL problem file\n'
    output += ';; depth ' + str(depth()) + ', ' + str(
        nb_agts()) + ' agents\n\n'

    output += '(define (problem gossip)\n'
    output += '\t(:domain gossip)\n\n'

    output += '\t(:objects ' + ' '.join(
        str(i) for i in agts()) + ' ' + ' '.join('s' + str(i)
                                                 for i in agts()) + ')\n\n'

    output += '\t(:init\n'
    output += '\t\t' + ' '.join(
        str(atom) for atom in base.get_atoms_of_depth(0)) + '\n'
    output += '\t\t' + ' '.join(
        str(atom)
        for atom in base.get_atoms_of_depth(1) if atom.is_initial()) + '\n'
    output += '\t)\n\n'

    output += '\t(:goal (and\n'
    output += str_goal(base) + '\t))\n'

    output += ')\n'

    for i in agts():
        output = output.replace(f"(s{i})", f"(ps{i})")

    agt_str = "abcdefgh"
    for i in agts():
        output = output.replace(f" {i} ", f" {agt_str[i-1]} ")
        output = output.replace(f" {i})", f" {agt_str[i-1]})")

    file.write(output)
def print_domain_file(base, file):
    file.write(';; Gossip problem - PDDL domain file\n')
    file.write(';; depth ' + str(depth()) + ', ' + str(nb_agts()) +
               ' agents\n\n')

    file.write('(define (domain gossip)\n')
    file.write('\t(:requirements\n')
    file.write('\t\t:strips :disjunctive-preconditions :equality\n')
    file.write('\t)\n\n')

    file.write('\t(:predicates\n')
    file.write('\t\t' +
               ' '.join(str(atom)
                        for atom in base.get_atoms_of_depth(0)) + '\n')
    file.write('\t\t' + ' '.join(
        visibility_predicate(d) for d in range(1,
                                               depth() + 1)) + '\n')
    file.write('\t)\n')

    file.write('\n\t(:action call\n')
    file.write('\t\t:parameters (?i ?j)\n')
    file.write('\t\t:effect (and\n')
    file.write(add_ag(str_cond_effects_call(base)) + '\t\t)\n')
    file.write('\t)\n')

    file.write(')\n')
def print_problem_file(base, file):
    file.write(';; Gossip problem - PDDL problem file\n')
    file.write(';; depth ' + str(depth()) + ', ' + str(nb_agts()) + ' agents\n\n')

    file.write('(define (problem gossip)\n')
    file.write('\t(:domain gossip)\n\n')

    file.write('\t(:objects ' + ' '.join(str(i) for i in agts()) + ')\n\n')

    file.write('\t(:init\n')
    file.write('\t\t' + ' '.join(str(atom) for atom in base.get_atoms_of_depth(0)) + '\n')
    file.write('\t\t' + ' '.join(str(atom) for atom in base.get_atoms_of_depth(1)
                            if atom.is_initial()) + '\n')
    file.write('\t)\n\n')

    file.write('\t(:goal (and\n')
    file.write(str_goal(base) + '\t))\n')

    file.write(')\n')
Example #6
0
def print_domain_file(base, file):

    output = ""
    output += ';; Gossip problem - PDDL domain file\n'
    output += ';; depth ' + str(depth()) + ', ' + str(nb_agts()) + ' agents\n\n'

    output += '(define (domain gossip)\n'
    output += '\t(:requirements\n'
    output += '\t\t:strips :disjunctive-preconditions :equality\n'
    output += '\t)\n\n'

    output += '\t(:predicates\n'
    output += '\t\t' + ' '.join(str(atom)
                                 for atom in base.get_atoms_of_depth(0)) + '\n'
    output += '\t\t' + ' '.join(visibility_predicate(d)
                                 for d in range(1, depth()+1)) + '\n'
    output += '\t)\n'

    output += '\n\t(:action call\n'
    output += '\t\t:parameters (?i ?j)\n'
    output += '\t\t:effect (and\n'
    output += str_cond_effects_call(base) + '\t\t)\n'
    output += '\t)\n'

    # create dummy action for FS planner
    output += '\n\t(:action dummy\n'
    output += '\t\t:parameters (?i ?j)\n'
    output += '\t\t:effect (and\n'
    output += '\t\t' + ' '.join(str(atom)
                                 for atom in base.get_atoms_of_depth(0)) + '\t\t)\n'
    output += '\t)\n'
    output += ')\n'

    for i in agts():
        output = output.replace(f"(s{i})",f"(ps{i})")
    agt_str="abcdefgh"
    for i in agts():
        output = output.replace(f" {i} ",f" {agt_str[i-1]} ")
        output = output.replace(f" {i})",f" {agt_str[i-1]})")


    file.write(output)
def print_problem_file(base, file):
    file.write(';; Gossip problem - PDDL problem file\n')
    file.write(';; depth ' + str(depth()) + ', ' + str(nb_agts()) + ' agents\n\n')

    file.write('(define (problem gossip)\n')
    file.write('\t(:domain gossip)\n\n')

    s_as_constant_gives_me_errors='\t\t' + ' '.join(str(atom) for atom in base.get_atoms_of_depth(0)) + '\n'
    s_as_constant_gives_me_errors=s_as_constant_gives_me_errors.replace('(','').replace(')','')
    file.write('\t(:objects ' + ' '.join("ag"+str(i) for i in agts()) +'\n'+s_as_constant_gives_me_errors+ ')\n\n')

    file.write('\t(:init\n')
    file.write('\t\t' + ' '.join(str(atom) for atom in base.get_atoms_of_depth(0)) + '\n')
    init_S='\t\t' + ' '.join(str(atom) for atom in base.get_atoms_of_depth(1) if atom.is_initial()) + '\n'
    init_S=numToAgnum(init_S)
    file.write(init_S)
    file.write('\t)\n\n')

    file.write('\t(:goal (and\n')
    goal_S=str_goal(base) + '\t))\n'
    goal_S=numToAgnum(goal_S)
    file.write(goal_S)

    file.write(')\n')
def print_domain_file(base, file):
    file.write(';; Gossip problem - PDDL domain file\n')
    file.write(';; depth ' + str(depth()) + ', ' +
               str(nb_agts()) + ' agents\n\n')

    file.write('(define (domain gossip)\n')
    file.write('\t(:requirements\n')
    file.write('\t\t:strips :disjunctive-preconditions :equality\n')
    file.write('\t)\n\n')

    file.write('\t(:predicates\n')
    file.write('\t\t' + ' '.join(str(atom)
                                 for atom in base.get_atoms_of_depth(0)) + '\n')
    file.write('\t\t' + ' '.join(visibility_predicate(d)
                                 for d in range(1, depth()+1)) + '\n')
    file.write('\t)\n')

    file.write('\n\t(:action call\n')
    file.write('\t\t:parameters (?i ?j)\n')
    file.write('\t\t:effect (and\n')
    file.write(str_cond_effects_call(base) + '\t\t)\n')
    file.write('\t)\n')

    file.write(')\n')
try:
    if len(sys.argv) == 2:
        raise ParameterError('wrong number of parameters.')

    if len(sys.argv) > 2:
        d = int(sys.argv[1])
        na = int(sys.argv[2])

    if d <= 0 or na <= 1:
        raise ParameterError('wrong value for <depth> or <number of agents>')

    set_parameters(d, na)

    print('Generating atoms for depth ' + str(depth()) + ' and ' +
          str(nb_agts()) + ' agents...')
    base = Goal()

    # negative goals
    if len(sys.argv) > 3:
        ast = parseSet(sys.argv[3])
        print('Generating negative goals ' + str(ast) + '...')
        update_negative_goals(base, ast)

except ParameterError as e:
    print('Error: ' + str(e))
    print('Usage: python gp_generator.py ' +
          '<depth> <number of agents> ["<description of negative goals>"] ' +
          'with <depth> >= 1 and <number of agents> >= 2')
    sys.exit(1)
try:
    if len(sys.argv) == 2:
        raise ParameterError('wrong number of parameters.')

    if len(sys.argv) > 2:
        d = int(sys.argv[1])
        na = int(sys.argv[2])

    if d <= 0 or na <= 1:
        raise ParameterError('wrong value for <depth> or <number of agents>')

    set_parameters(d, na)

    print('Generating atoms for depth ' + str(depth()) + ' and ' +
          str(nb_agts()) + ' agents...')
    base = Goal()

    # negative goals
    if len(sys.argv) > 3:
        ast = parseSet(sys.argv[3])
        print('Generating negative goals ' + str(ast) + '...')
        update_negative_goals(base, ast)

except ParameterError as e:
    print('Error: ' + str(e))
    print('Usage: python gp_generator.py ' +
          '<depth> <number of agents> ["<description of negative goals>"] ' +
          'with <depth> >= 1 and <number of agents> >= 2')
    sys.exit(1)