示例#1
0
def main():
    options, args = parse_options()

    check_python_version(options.force_old_python)

    timer = timers.Timer()
    with timers.timing("Parsing", True):
        task = pddl.open()

    with timers.timing("Normalizing task"):
        normalize.normalize(task)

    if options.generate_relaxed_task:
        # Remove delete effects.
        for action in task.actions:
            for index, effect in reversed(list(enumerate(action.effects))):
                if effect.literal.negated:
                    del action.effects[index]

    sas_task = pddl_to_sas(task)
    dump_statistics(sas_task)

    with timers.timing("Writing output"):
        with open("output.sas", "w") as output_file:
            sas_task.output(output_file)
    print("Done! %s" % timer)
示例#2
0
def main() :
	task = pddl.open()
	relaxed_solvable, atoms, actions, axioms = instantiate.explore(task)
	#for action in actions :
	#	action.dump()
	not_trivial_axioms = []
	trivial_axioms = {}
	for axiom in axioms :
		if len(axiom.condition) > 1 :
			not_trivial_axioms.append( axiom )
			continue
		if not isinstance( axiom.effect, pddl.conditions.Literal ) :
			not_trivial_axioms.append( axiom )
			continue
		if isinstance( axiom.effect, pddl.conditions.NegatedAtom ) :
			not_trivial_axioms.append( axiom )
			continue
		try :
			trivial_axioms[ axiom.effect ].append( axiom.condition[0] )
		except KeyError :
			trivial_axioms[ axiom.effect ] = [ axiom.condition[0] ]
	print >> sys.stdout, "Non-trivial axioms:", len(not_trivial_axioms)
	print >> sys.stdout, "Trivial axioms:", len(trivial_axioms.keys())	
	if not relaxed_solvable :
		print >> sys.stdout, "Problem is unsolvable!"
		sys.exit(1)
	task_to_prop_strips_domain( task, atoms, actions, not_trivial_axioms  )
	task_to_prop_strips_problem( task, atoms, trivial_axioms )
示例#3
0
def main():
    print('HOLAAAAAAAAAAAAAAAAAAAAAAA')
    args = parse_args()

    timer = timers.Timer()
    with timers.timing("Parsing", True):
        task = pddl.open(task_filename=args.task, domain_filename=args.domain)

    with timers.timing("Normalizing task"):
        normalize.normalize(task)

    task.INVARIANT_TIME_LIMIT = int(args.inv_limit)

    if args.generate_relaxed_task:
        # Remove delete effects.
        for action in task.actions:
            for index, effect in reversed(list(enumerate(action.effects))):
                if effect.literal.negated:
                    del action.effects[index]

    sas_task = pddl_to_sas(task)

    assert len(sas_task.operators) == len(set([o.name for o in sas_task.operators])), \
           "Error: Operator names (with parameters) must be unique"

    dump_statistics(sas_task)

    with timers.timing("Writing output"):
        with open(args.sas_name, "w") as output_file:
            sas_task.output(output_file)
    print("Done! %s" % timer)
示例#4
0
def main():
    args = parse_args()

    timer = timers.Timer()
    with timers.timing("Parsing", True):
        task = pddl.open(task_filename=args.task,
                         domain_filename=args.domain,
                         addl_filename=args.addl)

    with timers.timing("Normalizing task"):
        normalize.normalize(task)

    if args.generate_relaxed_task:
        # Remove delete effects.
        for action in task.actions:
            for index, effect in reversed(list(enumerate(action.effects))):
                if effect.literal.negated:
                    del action.effects[index]

    output_file = args.output_file
    use_proto = args.use_proto
    print('Use Proto:', use_proto)

    sas_task = pddl_to_sas(task, args.agent_id, args.agent_url)
    dump_statistics(sas_task)

    with timers.timing("Writing output"):
        with open(output_file, "w") as output_file:
            if use_proto:
                sas_task.output_proto(output_file)
            else:
                sas_task.output(output_file)
    print("Done! %s" % timer)
示例#5
0
def main():
    args = parse_args()

    timer = timers.Timer()
    with timers.timing("Parsing", True):
        task = pddl.open(task_filename=args.task,
                         domain_filename=args.domain,
                         addl_filename=args.addl)

    with timers.timing("Normalizing task"):
        normalize.normalize(task)

    if args.generate_relaxed_task:
        # Remove delete effects.
        for action in task.actions:
            for index, effect in reversed(list(enumerate(action.effects))):
                if effect.literal.negated:
                    del action.effects[index]

    output_file = args.output_file
    use_proto = args.use_proto
    print('Use Proto:', use_proto)

    sas_task = pddl_to_sas(task, args.agent_id, args.agent_url)
    dump_statistics(sas_task)

    with timers.timing("Writing output"):
        with open(output_file, "w") as output_file:
            if use_proto:
                sas_task.output_proto(output_file)
            else:
                sas_task.output(output_file)
    print("Done! %s" % timer)
示例#6
0
def main():
    args = parse_args()

    timer = timers.Timer()
    with timers.timing("Parsing", True):
        task = pddl.open(task_filename=args.task, domain_filename=args.domain)

    with timers.timing("Normalizing task"):
        normalize.normalize(task)

    if args.generate_relaxed_task:
        # Remove delete effects.
        for action in task.actions:
            for index, effect in reversed(list(enumerate(action.effects))):
                if effect.literal.negated:
                    del action.effects[index]

    sas_task = pddl_to_sas(task)
    dump_statistics(sas_task)

    if not sas_task is None:
        with timers.timing("Writing output"):
            with open("output.sas", "w") as output_file:
                sas_task.output(output_file)
        print("Done! %s" % timer)
示例#7
0
def main():
    print("--------------FOND Translator------------")
    args = parse_args()

    timer = timers.Timer()
    with timers.timing("Parsing", True):
        task = pddl.open(task_filename=args.task, domain_filename=args.domain)
        
        # for test:
        print();
        print("Problem Filename = " + args.task);
        print("Domain Filename = " + args.domain);
        print();
        
    with timers.timing("Normalizing task"):
        normalize.normalize(task)

    if args.generate_relaxed_task:
        # Remove delete effects.
        for action in task.actions:
            for index, effect in reversed(list(enumerate(action.effects))):
                if effect.literal.negated:
                    del action.effects[index]

    sas_task = pddl_to_sas(task)
    dump_statistics(sas_task)

    with timers.timing("Writing output"):
        with open("..\\webapps\\LunaPlanner\\translator_output\\output.sas", "w") as output_file:
            sas_task.output(output_file)
            
    print()
    print("SAS file saved at: " + output_file.name)
    
    print("Done! %s" % timer)
示例#8
0
def main():
    options, args = parse_options()

    check_python_version(options.force_old_python)

    timer = timers.Timer()
    with timers.timing("Parsing", True):
        task = pddl.open()

    with timers.timing("Normalizing task"):
        normalize.normalize(task)

    if options.generate_relaxed_task:
        # Remove delete effects.
        for action in task.actions:
            for index, effect in reversed(list(enumerate(action.effects))):
                if effect.literal.negated:
                    del action.effects[index]

    sas_task = pddl_to_sas(task)
    dump_statistics(sas_task)

    with timers.timing("Writing output"):
        with open("output.sas", "w") as output_file:
            sas_task.output(output_file)
    print("Done! %s" % timer)
示例#9
0
def main():
    print("-------------POND Translator-----------")
    args = parse_args()

    timer = timers.Timer()
    with timers.timing("Parsing", True):
        task = pddl.open(task_filename=args.task, domain_filename=args.domain)
      
        print();
        print("Problem Filename = " + args.task);
        print("Domain Filename = " + args.domain);
        print();
        
    with timers.timing("Normalizing task"):
        normalize.normalize(task)

    if args.generate_relaxed_task:
        # Remove delete effects.
        for action in task.actions:
            for index, effect in reversed(list(enumerate(action.effects))):
                if effect.literal.negated:
                    del action.effects[index]

    sas_task = pddl_to_sas(task)
    dump_statistics(sas_task)

    if not sas_task is None:
        with timers.timing("Writing output"):
            with open("..\\webapps\\LunaPlanner\\translator_output\\output.sas", "w") as output_file:
                sas_task.output(output_file)
                
        print()
        print("SAS file saved at: " + output_file.name)
                
        print("Done! %s" % timer)
示例#10
0
def main():
    args = parse_args()

    timer = timers.Timer()
    with timers.timing("Parsing", True):
        task = pddl.open(task_filename=args.task, domain_filename=args.domain)

    with timers.timing("Normalizing task"):
        normalize.normalize(task)
    
    task.INVARIANT_TIME_LIMIT = int(args.inv_limit)

    if args.generate_relaxed_task:
        # Remove delete effects.
        for action in task.actions:
            for index, effect in reversed(list(enumerate(action.effects))):
                if effect.literal.negated:
                    del action.effects[index]

    sas_task = pddl_to_sas(task)
    ########### dump_statistics(sas_task).

    with timers.timing("Writing output"):
        with open(args.sas_name, "w") as output_file:
            sas_task.output(output_file)
示例#11
0
def translator(req):
    task = pddl.open(req.problem,req.domain)


    sas_task = pddl_to_sas(task)


    output=sas_task.output()
    del task
    del sas_task
    return translateResponse(str(output))
示例#12
0
    def extract(self, domain_path, instance_path):
        features = self.default_features()

        successful = False

        try:
            task = pddl.open(task_filename=instance_path, domain_filename=domain_path)

            pddl_features = self.extract_features_from_pddl_task(task)
            features.update(pddl_features)

            # make sure at least one non-sentinel value, otherwise obviously not successful
            for key,value in features.iteritems():
                if value != self.sentinel_value:
                    successful = True
        except Exception as e:
            print "Exception running simple_pddl extraction: %s" % (str(e))

        return successful,features
    def extract(self, domain_path, instance_path):
        features = self.default_features()

        successful = False

        try:
            task = pddl.open(task_filename=instance_path,
                             domain_filename=domain_path)

            pddl_features = self.extract_features_from_pddl_task(task)
            features.update(pddl_features)

            # make sure at least one non-sentinel value, otherwise obviously not successful
            for key, value in features.iteritems():
                if value != self.sentinel_value:
                    successful = True
        except Exception as e:
            print "Exception running simple_pddl extraction: %s" % (str(e))

        return successful, features
示例#14
0
def main():
    options, args = parse_options()

    check_python_version(options.force_old_python)

    timer = timers.Timer()
    with timers.timing("Parsing"):
        task = pddl.open()

    # EXPERIMENTAL!
    # import psyco
    # psyco.full()

    sas_task = pddl_to_sas(task)
    dump_statistics(sas_task)

    with timers.timing("Writing output"):
        with open("output.sas", "w") as output_file:
            sas_task.output(output_file)
    print("Done! %s" % timer)
示例#15
0
def main():
    options, args = parse_options()

    check_python_version(options.force_old_python)

    timer = timers.Timer()
    with timers.timing("Parsing"):
        task = pddl.open()

    # EXPERIMENTAL!
    # import psyco
    # psyco.full()

    sas_task = pddl_to_sas(task)
    dump_statistics(sas_task)

    with timers.timing("Writing output"):
        with open("output.sas", "w") as output_file:
            sas_task.output(output_file)
    print("Done! %s" % timer)
示例#16
0
def default(domain_file, problem_file, output_task):
    parsing_timer = timers.Timer()
    print("Domain: %s Problem: %s" % (domain_file, problem_file))

    task = pddl.open(problem_file, domain_file)

    relaxed_reachable, atoms, actions, axioms, reachable_action_params = explore(
        task)
    print("goal relaxed reachable: %s" % relaxed_reachable)
    if not relaxed_reachable:
        print("No weak plan exists")
        sys.exit(2)

    print("%d atoms" % len(atoms))

    with timers.timing("Computing fact groups", block=True):
        groups, mutex_groups, translation_key = fact_groups.compute_groups(
            task,
            atoms,
            reachable_action_params,
            partial_encoding=USE_PARTIAL_ENCODING)

    index = 0
    atom_table = {}

    for atom in atoms:
        atom.index = index
        atom_table[atom.text()] = index
        output_task.add_atom(atom.text())
        index += 1

    print("Invariants %d" % len(mutex_groups))
    for group in mutex_groups:
        if len(group) >= 2:
            print("{%s}" % ", ".join(map(str, group)))
            output_task.add_invariant(encode(group, atom_table))
            #print( encode( group, atom_table ) )

    print("Deterministic %d actions" % len(actions))
    nd_actions = {}
    for action in actions:
        nd_action = PropositionalDetAction(action.name, action.cost)
        nd_action.set_precondition(action.precondition, atom_table)
        nd_action.add_effect(action.add_effects, action.del_effects,
                             atom_table)
        nd_actions[nd_action.name] = nd_action

    index = 0
    for action in nd_actions.values():
        output_task.add_action(action.name)
        output_task.add_precondition(index, action.precondition)
        text_prec = []
        for p, v in action.precondition:
            text_prec.append("%s=%s" % (output_task.get_atom_name(p), not v))
        for eff in action.effects:
            output_task.add_effect(index, eff)
            text_eff = []
            for p, v in eff:
                text_eff.append("%s=%s" %
                                (output_task.get_atom_name(p), not v))
        index += 1
    output_task.set_domain_name(task.domain_name)
    output_task.set_problem_name(task.task_name)
    output_task.set_init(encode(task.init, atom_table))
    output_task.set_goal(encode(task.goal, atom_table))
    output_task.parsing_time = parsing_timer.report()
示例#17
0
def default( domain_file, problem_file, output_task ) :
	parsing_timer = timers.Timer()
	print("Domain: %s Problem: %s"%(domain_file, problem_file) )

	task = pddl.open( problem_file, domain_file)
	normalize.normalize(task)

	relaxed_reachable, atoms, actions, axioms, reachable_action_params = explore(task)
	print("goal relaxed reachable: %s" % relaxed_reachable)
	if not relaxed_reachable :
		print("No plan exists")
		sys.exit(2)
	
	print("%d atoms" % len(atoms))

	with timers.timing("Computing fact groups", block=True):
		groups, mutex_groups, translation_key = fact_groups.compute_groups(
			task, atoms, reachable_action_params,
			partial_encoding=USE_PARTIAL_ENCODING)
	
	index = 0
	atom_table = {}

	atom_names = [ atom.text() for atom in atoms ]
	atom_names.sort()
	
	for atom in atom_names :
		atom_table[ atom ] = index
		output_task.add_atom( atom )
		index += 1


	print("Deterministic %d actions" % len(actions))
	nd_actions = {}
	for action in actions :
		#print( "action: %s cost: %d"%(action.name,action.cost) )
		nd_action = PropositionalDetAction( action.name, action.cost )
		nd_action.set_precondition( action.precondition, atom_table )
		nd_action.add_effect( action.add_effects, action.del_effects, atom_table )
		if len(nd_action.negated_conditions) > 0 :
			output_task.notify_negated_conditions( nd_action.negated_conditions )
		nd_actions[ nd_action.name ] = nd_action

	output_task.create_negated_fluents()

	for name, _ in nd_actions.iteritems() :
		output_task.add_action( name )

	index = 0
	for action in nd_actions.values() :
		output_task.add_precondition( index, action.precondition )
		for eff in action.effects :
			output_task.add_effect( index, eff )
		#if len(action.cond_effs) != 0 :
		#	print action.name, len(action.cond_effs), "has conditional effects"
		for cond, eff in action.cond_effs.iteritems() :
			output_task.add_cond_effect( index, list(cond), eff )
		output_task.set_cost( index, action.cost ) 
		index += 1

	# MRJ: Mutex groups processing needs to go after negations are compiled away
	print("Invariants %d"%len(mutex_groups))
	for group in mutex_groups :
		if len(group) >= 2 :
			#print("{%s}" % ", ".join(map(str, group)))
			output_task.add_mutex_group( encode( group, atom_table ) )
			#print( encode( group, atom_table ) )


	output_task.set_domain_name( task.domain_name )
	output_task.set_problem_name( task.task_name )
	output_task.set_init( encode( task.init, atom_table ) )
	output_task.set_goal( encode( task.goal, atom_table ) )
	output_task.parsing_time = parsing_timer.report()
示例#18
0
def default( domain_file, problem_file, output_task ) :
	parsing_timer = timers.Timer()
	print("Domain: %s Problem: %s"%(domain_file, problem_file) )

	task = pddl.open( problem_file, domain_file)

	relaxed_reachable, atoms, actions, axioms, reachable_action_params = explore(task)
	print("goal relaxed reachable: %s" % relaxed_reachable)
	if not relaxed_reachable :
		print("No weak plan exists")
		sys.exit(2)
	
	print("%d atoms" % len(atoms))

	with timers.timing("Computing fact groups", block=True):
		groups, mutex_groups, translation_key = fact_groups.compute_groups(
			task, atoms, reachable_action_params,
			partial_encoding=USE_PARTIAL_ENCODING)
	
	index = 0
	atom_table = {}

	
	for atom in atoms :
		atom.index = index
		atom_table[ atom.text() ] = index
		output_task.add_atom( atom.text() )
		index += 1

	print("Invariants %d"%len(mutex_groups))
	for group in mutex_groups :
		if len(group) >= 2 :
			print("{%s}" % ", ".join(map(str, group)))
			output_task.add_invariant( encode( group, atom_table ) )
			#print( encode( group, atom_table ) )

	print("Deterministic %d actions" % len(actions))
	nd_actions = {}
	for action in actions :
		nd_action = PropositionalDetAction( action.name, action.cost )
		nd_action.set_precondition( action.precondition, atom_table )
		nd_action.add_effect( action.add_effects, action.del_effects, atom_table )
		nd_actions[ nd_action.name ] = nd_action

	index = 0
	for action in nd_actions.values() :
		output_task.add_action( action.name )
		output_task.add_precondition( index, action.precondition )
		text_prec = []
		for p, v in action.precondition :
			text_prec.append( "%s=%s"%(output_task.get_atom_name( p ),  not v) )
		for eff in action.effects :
			output_task.add_effect( index, eff )
			text_eff = []
			for p, v in eff :
				text_eff.append( "%s=%s"%(output_task.get_atom_name( p ), not v) )
		index += 1
	output_task.set_domain_name( task.domain_name )
	output_task.set_problem_name( task.task_name )
	output_task.set_init( encode( task.init, atom_table ) )
	output_task.set_goal( encode( task.goal, atom_table ) )
	output_task.parsing_time = parsing_timer.report()
def default(domain_file, problem_file, output_task):
    parsing_timer = timers.Timer()
    print("Domain: %s Problem: %s" % (domain_file, problem_file))

    task = pddl.open(problem_file, domain_file)
    normalize.normalize(task)

    relaxed_reachable, atoms, actions, axioms, reachable_action_params = explore(
        task)
    print("goal relaxed reachable: %s" % relaxed_reachable)
    if not relaxed_reachable:
        print("No plan exists")
        sys.exit(2)

    print("%d atoms" % len(atoms))

    with timers.timing("Computing fact groups", block=True):
        groups, mutex_groups, translation_key = fact_groups.compute_groups(
            task,
            atoms,
            reachable_action_params,
            partial_encoding=USE_PARTIAL_ENCODING)

    index = 0
    atom_table = {}

    atom_names = [atom.text() for atom in atoms]
    atom_names.sort()

    for atom in atom_names:
        atom_table[atom] = index
        output_task.add_atom(atom)
        index += 1

    print("Deterministic %d actions" % len(actions))
    nd_actions = {}
    for action in actions:
        #print( "action: %s cost: %d"%(action.name,action.cost) )
        nd_action = PropositionalDetAction(action.name, action.cost)
        nd_action.set_precondition(action.precondition, atom_table)
        nd_action.add_effect(action.add_effects, action.del_effects,
                             atom_table)
        if len(nd_action.negated_conditions) > 0:
            output_task.notify_negated_conditions(nd_action.negated_conditions)
        nd_actions[nd_action.name] = nd_action

    output_task.create_negated_fluents()

    for name, _ in nd_actions.iteritems():
        output_task.add_action(name)

    index = 0
    for action in nd_actions.values():
        output_task.add_precondition(index, action.precondition)
        for eff in action.effects:
            output_task.add_effect(index, eff)
        #if len(action.cond_effs) != 0 :
        #	print action.name, len(action.cond_effs), "has conditional effects"
        for cond, eff in action.cond_effs.iteritems():
            output_task.add_cond_effect(index, list(cond), eff)
        output_task.set_cost(index, action.cost)
        index += 1

    # MRJ: Mutex groups processing needs to go after negations are compiled away
    print("Invariants %d" % len(mutex_groups))
    for group in mutex_groups:
        if len(group) >= 2:
            #print("{%s}" % ", ".join(map(str, group)))
            output_task.add_mutex_group(encode(group, atom_table))
            #print( encode( group, atom_table ) )

    output_task.set_domain_name(task.domain_name)
    output_task.set_problem_name(task.task_name)
    output_task.set_init(encode(task.init, atom_table))
    output_task.set_goal(encode(task.goal, atom_table))
    output_task.parsing_time = parsing_timer.report()
def fodet(domain_file, problem_file, output_task):
    parsing_timer = timers.Timer()
    print("Domain: %s Problem: %s" % (domain_file, problem_file))

    task = pddl.open(problem_file, domain_file)
    normalize.normalize(task)

    relaxed_reachable, atoms, actions, axioms, reachable_action_params = explore(
        task)
    print("goal relaxed reachable: %s" % relaxed_reachable)
    if not relaxed_reachable:
        print("No plan exists")
        sys.exit(2)

    print("%d atoms" % len(atoms))

    with timers.timing("Computing fact groups", block=True):
        groups, mutex_groups, translation_key = fact_groups.compute_groups(
            task,
            atoms,
            reachable_action_params,
            partial_encoding=USE_PARTIAL_ENCODING)

    index = 0
    atom_table = {}

    atom_names = [atom.text() for atom in atoms]
    atom_names.sort()

    for atom in atom_names:
        atom_table[atom] = index
        output_task.add_atom(atom)
        index += 1

    print("Axioms %d" % len(axioms))
    for axiom in axioms:
        axiom.dump()
        output_task.add_axiom(encode(axiom.condition, atom_table),
                              encode([axiom.effect], atom_table))

    print("Deterministic %d actions" % len(actions))
    nd_actions = {}
    for action in actions:
        #print( "action: %s cost: %d"%(action.name,action.cost) )
        nd_action = PropositionalDetAction(action.name, action.cost)
        nd_action.set_precondition(action.precondition, atom_table)
        nd_action.add_effect(action.add_effects, action.del_effects,
                             atom_table)
        nd_actions[nd_action.name] = nd_action

    for name, _ in nd_actions.iteritems():
        output_task.add_action(name)

    index = 0
    for action in nd_actions.values():
        output_task.add_precondition(index, action.precondition)
        for eff in action.effects:
            output_task.add_effect(index, eff)
        #if len(action.cond_effs) != 0 :
        #	print action.name, len(action.cond_effs), "has conditional effects"
        for cond, eff in action.cond_effs.iteritems():
            output_task.add_cond_effect(index, list(cond), eff)
        output_task.set_cost(index, action.cost)
        index += 1
    output_task.set_domain_name(task.domain_name)
    output_task.set_problem_name(task.task_name)
    output_task.set_init(encode(task.init, atom_table))
    output_task.set_goal(encode(task.goal, atom_table))
    output_task.parsing_time = parsing_timer.report()
示例#21
0
def numeric(domain_file, problem_file, output_task):
    import liblapkt
    print("Domain: %s Problem: %s" % (domain_file, problem_file))

    task = pddl.open(problem_file, domain_file)

    normalize.normalize(task)
    relaxed_reachable, atoms, actions, axioms, reachable_action_params = explore(
        task)

    atom_table = dict()

    # atoms
    for atom in atoms:
        if atom.text() not in atom_table:
            atom_table[atom.text()] = TableItem(len(atom_table), atom)
            output_task.add_atom(atom.text())
    init_atoms = [
        x for x in task.init
        if (not hasattr(x, 'predicate')) or x.predicate != '='
    ]

    function_table = dict()

    # functions
    # all ground functions should have some value assigned in init
    # unlike logical fluents, which are false if are not specified
    for func in (x for x in task.init
                 if isinstance(x, pddl.f_expression.Assign)):
        if isinstance(func.fluent, pddl.f_expression.PrimitiveNumericExpression
                      ) and func.fluent.symbol == 'total-cost':
            continue
        atom = pddl.Atom(func.fluent.symbol, func.fluent.args)
        function_table[atom.text()] = TableItem(len(function_table), atom,
                                                func.expression.value)
        output_task.add_function(atom.text())

    negated_set = set()
    action_data = []

    # actions
    for instance in actions:
        precs, cmp, new_atoms = convert_precondition(instance.precondition,
                                                     atom_table)
        for new_atom in new_atoms:
            output_task.add_atom(new_atom)
        negated_condistions = [
            x[0] for x in precs if (x[1] and x[0] not in negated_set)
        ]
        for n in negated_condistions:
            if n not in negated_set:
                negated_set.add(n)
                print("negated: " + str(n))
                output_task.notify_negated_conditions([n])
        effs = convert_effect(instance.add_effects, instance.del_effects,
                              atom_table)
        num_effs = convert_num_effect(instance.numeric_effects, function_table)

        action_data.append(
            NumDetAction(instance.name, instance.cost, precs, effs, num_effs,
                         cmp))
    output_task.create_negated_fluents()
    # numerical conditions
    cmp_map = {
        '>': liblapkt.CompareType.more,
        '>=': liblapkt.CompareType.more_equal
    }
    for (index, action) in enumerate(action_data):
        # todo: add comparision objects
        output_task.add_action(action.name)
        output_task.define_action(index, action.preconditions, action.effects,
                                  action.numeric_effects)
        output_task.set_cost(index, action.cost)
        # add comparision objects to output task
        for (idx, cmp) in action.comparison.items():
            expr = convert_expression(cmp.parts[0], function_table)
            output_task.add_comparison(idx, cmp_map[cmp.comparator], expr)

        # adding init and goal
        num_list = []
        for item in function_table.values():
            num_list.append((item.index, item.value))

        fluent_list = []
        for item in init_atoms:
            if isinstance(item, (pddl.Atom, pddl.NegatedAtom)):
                try:
                    fluent_list.append(
                        (atom_table[item.text()].index, item.negated))
                except KeyError as e:
                    # ignore since some
                    pass
        assert len(num_list) == len(function_table)

    output_task.set_init_num(fluent_list, num_list)
    goal = [(x[0].index, x[1]) for x in encode(task.goal, atom_table)]
    output_task.set_goal(goal)
    # process metric
    if task.metric_expression:
        metric_expression = convert_expression(task.metric_expression,
                                               function_table)
        output_task.set_metric_expression(metric_expression)
        output_task.set_add_cost(False)
示例#22
0
        return result

    def popped_elements(self):
        return queue.queue[:self.queue_pos]


def compute_model(prog):
    rules = convert_rules(prog)
    unifier = Unifier(rules)
    # unifier.dump()
    queue = Queue([fact.atom for fact in prog.facts])
    print "Starting instantiation [%d rules]..." % len(rules)
    while queue:
        next_atom = queue.pop()
        matches = unifier.unify(next_atom)
        for rule, cond_index in matches:
            rule.update_index(next_atom, cond_index)
            rule.fire(next_atom, cond_index, queue.push)
    return queue.queue


if __name__ == "__main__":
    import pddl_to_prolog
    print "Parsing..."
    task = pddl.open()
    print "Writing rules..."
    prog = pddl_to_prolog.translate(task)
    print "Computing model..."
    for atom in compute_model(prog):
        print atom
示例#23
0
def fodet( domain_file, problem_file, output_task ) :
	parsing_timer = timers.Timer()
	print("Domain: %s Problem: %s"%(domain_file, problem_file) )

	task = pddl.open( problem_file, domain_file)
	normalize.normalize(task)

	relaxed_reachable, atoms, actions, axioms, reachable_action_params = explore(task)
	print("goal relaxed reachable: %s" % relaxed_reachable)
	if not relaxed_reachable :
		print("No plan exists")
		sys.exit(2)
	
	print("%d atoms" % len(atoms))

	with timers.timing("Computing fact groups", block=True):
		groups, mutex_groups, translation_key = fact_groups.compute_groups(
			task, atoms, reachable_action_params,
			partial_encoding=USE_PARTIAL_ENCODING)
	
	index = 0
	atom_table = {}

	atom_names = [ atom.text() for atom in atoms ]
	atom_names.sort()
	
	for atom in atom_names :
		atom_table[ atom ] = index
		output_task.add_atom( atom )
		index += 1

	print("Axioms %d"%len(axioms))
	for axiom in axioms:
		axiom.dump()
		output_task.add_axiom( encode( axiom.condition, atom_table), encode( [ axiom.effect ], atom_table ))

	print("Deterministic %d actions" % len(actions))
	nd_actions = {}
	for action in actions :
		#print( "action: %s cost: %d"%(action.name,action.cost) )
		nd_action = PropositionalDetAction( action.name, action.cost )
		nd_action.set_precondition( action.precondition, atom_table )
		nd_action.add_effect( action.add_effects, action.del_effects, atom_table )
		nd_actions[ nd_action.name ] = nd_action


	for name, _ in nd_actions.iteritems() :
		output_task.add_action( name )

	index = 0
	for action in nd_actions.values() :
		output_task.add_precondition( index, action.precondition )
		for eff in action.effects :
			output_task.add_effect( index, eff )
		#if len(action.cond_effs) != 0 :
		#	print action.name, len(action.cond_effs), "has conditional effects"
		for cond, eff in action.cond_effs.iteritems() :
			output_task.add_cond_effect( index, list(cond), eff )
		output_task.set_cost( index, action.cost ) 
		index += 1
	output_task.set_domain_name( task.domain_name )
	output_task.set_problem_name( task.task_name )
	output_task.set_init( encode( task.init, atom_table ) )
	output_task.set_goal( encode( task.goal, atom_table ) )
	output_task.parsing_time = parsing_timer.report()
        if not isinstance(atom,pddl.FunctionAssignment):
            for invariant in predicate_to_invariants.get(atom.predicate, ()):
                group_key = (invariant, tuple(invariant.get_parameters(atom)))
                if group_key not in nonempty_groups:
                    nonempty_groups.add(group_key)
                else:
                    overcrowded_groups.add(group_key)
    useful_groups = nonempty_groups - overcrowded_groups
    for (invariant, parameters) in useful_groups:
        yield [part.instantiate(parameters) for part in invariant.parts]

def get_groups(task, safe=True, reachable_action_params=None):
    with timers.timing("Finding invariants"):
        invariants = list(find_invariants(task, safe, reachable_action_params))
    invariants = sorted(invariants)
    with timers.timing("Checking invariant weight"):
        result = list(useful_groups(invariants, task.init))
    return result

if __name__ == "__main__":
    import pddl
    print "Parsing..."
    task = pddl.open()
    print "Finding invariants..."
    for invariant in find_invariants(task):
        print invariant
    print "Finding fact groups..."
    groups = get_groups(task)
    for group in groups:
        print "[%s]" % ", ".join(map(str, group))
    (task_filename, domain_filename, output_dir) = ('', '', '')
    if len(sys.argv) == 2:
        task_filename = sys.argv[1]
    elif len(sys.argv) == 3:
        (task_filename, domain_filename) = sys.argv[1:]
    elif len(sys.argv) == 4:
        (task_filename, domain_filename, output_dir) = sys.argv[1:]
    else:
        print(
            "Needs 1-3 arguments: task_filename [, domain_filename [, output_dir]]"
        )
        sys.exit(1)

    print("Parsing...")
    task = pddl.open(task_filename, domain_filename)
    if task.domain_name in ["protocol", "rover"]:
        # This is, of course, a HACK HACK HACK!
        # The real issue is that ALLOW_CONFLICTING_EFFECTS = True
        # is actually the correct semantics, but then we don't get to filter
        # out operators that are impossible to apply due to mutexes between
        # different SAS+ variables. For example,
        # ALLOW_CONFLICTING_EFFECTS = True does not filter on(a,a) in
        # blocksworld/4-0.
        ALLOW_CONFLICTING_EFFECTS = True

    # EXPERIMENTAL!
    # import psyco
    # psyco.full()

    sas_task = pddl_to_sas(task)