def compute_groups(task, atoms, reachable_action_params): groups = invariant_finder.get_groups(task, reachable_action_params) with timers.timing("Instantiating groups"): groups = instantiate_groups(groups, task, atoms) # Sort here already to get deterministic mutex groups. groups = sort_groups(groups) # TODO: I think that collect_all_mutex_groups should do the same thing # as choose_groups with partial_encoding=False, so these two should # be unified. with timers.timing("Collecting mutex groups"): mutex_groups = collect_all_mutex_groups(groups, atoms) with timers.timing("Choosing groups", block=True): groups = choose_groups(groups, atoms) groups = sort_groups(groups) with timers.timing("Building translation key"): translation_key = build_translation_key(groups) if DEBUG: for group in groups: if len(group) >= 2: print("{%s}" % ", ".join(map(str, group))) return groups, mutex_groups, translation_key
def compute_groups(task, atoms, reachable_action_params, return_mutex_groups=True, partial_encoding=True, safe=True): ## NOTE: exactly one of the following options should be true # TODO: there should be a configure section for this kind of stuff # don't use the information from the object fluents at all no_objectfluents = False # use only information from objectfluents (all other variables will be # proposotional only_objectfluents = False # use both the information from the objectfluents and the information from # the invariant syntheses and choose the groups by size choose_groups_by_size = False # use first the information from the objectfluents. If there are # propositional variables left use the information from the invariant # syntheses to group them use_objectfluents_first = True objectfluent_groups = [] groups = [] mutex_groups = [] if not no_objectfluents: objectfluent_groups = create_groups_from_object_fluents(atoms) if not only_objectfluents: print "Finding invariants..." groups = invariant_finder.get_groups(task, safe, reachable_action_params) groups = sorted(groups, cmp=lambda x,y: cmp(str([str(a) for a in x]), str([str(a) for a in y]))) print "Instantiating groups..." groups = instantiate_groups(groups, task, atoms) if return_mutex_groups: mutex_groups = collect_all_mutex_groups(groups, atoms) + \ objectfluent_groups print "Choosing groups..." if use_objectfluents_first: groups = choose_groups_with_object_fluents_first(groups, objectfluent_groups, atoms, partial_encoding=partial_encoding) else: if only_objectfluents: groups = objectfluent_groups elif choose_groups_by_size: groups = objectfluent_groups + groups # slightly prefer objectfluent groups groups = choose_groups(groups, atoms, partial_encoding=partial_encoding) print "Building translation key..." translation_key = build_translation_key(groups) return groups, mutex_groups, translation_key
def compute_groups(task, atoms, partial_encoding=True): groups = invariant_finder.get_groups(task) with timers.timing("Instantiating groups"): groups = instantiate_groups(groups, task, atoms) # TODO: I think that collect_all_mutex_groups should do the same thing # as choose_groups with partial_encoding=False, so these two should # be unified. with timers.timing("Collecting mutex groups"): mutex_groups = collect_all_mutex_groups(groups, atoms) with timers.timing("Choosing groups", block=True): groups = choose_groups(groups, atoms, partial_encoding=partial_encoding) with timers.timing("Building translation key"): translation_key = build_translation_key(groups) return groups, mutex_groups, translation_key
def compute_groups(task, atoms, return_mutex_groups=True, partial_encoding=True): print "Finding invariants..." groups = invariant_finder.get_groups(task) print "Instantiating groups..." groups = instantiate_groups(groups, task, atoms) if return_mutex_groups: mutex_groups = collect_all_mutex_groups(groups, atoms) else: mutex_groups = [] print "Choosing groups..." groups = choose_groups(groups, atoms, partial_encoding=partial_encoding) print "Building translation key..." translation_key = build_translation_key(groups) return groups, mutex_groups, translation_key
def compute_groups(task, atoms, reachable_action_params, partial_encoding=True): groups = invariant_finder.get_groups(task, reachable_action_params) with timers.timing("Instantiating groups"): groups = instantiate_groups(groups, task, atoms) # TODO: I think that collect_all_mutex_groups should do the same thing # as choose_groups with partial_encoding=False, so these two should # be unified. with timers.timing("Collecting mutex groups"): mutex_groups = collect_all_mutex_groups(groups, atoms) with timers.timing("Choosing groups", block=True): groups = choose_groups(groups, atoms, partial_encoding=partial_encoding) with timers.timing("Building translation key"): translation_key = build_translation_key(groups) return groups, mutex_groups, translation_key
def compute_groups(task, atoms, actions, reachable_action_params, partial_encoding=True, comm = None): invariants, groups = invariant_finder.get_groups(task, reachable_action_params) with timers.timing("Instantiating groups"): groups = instantiate_groups(groups, task, atoms) if comm is not None: # Try to instantiate another mutex groups that are based on initial # states of other agents #groups = ma_instantiate_groups(comm, groups, invariants, task, atoms) # Separate private atoms to a separate groups groups = split_groups_by_private_atoms(groups) print('Groups split to private/public') sys.stdout.flush() # Split mutex groups so that all agents have the same mutex groups # -- this should ensure that no agent have invalid mutexes. groups = ma_split_groups(comm, groups, atoms, task.init, actions) else: print('NOT COMM!') sys.stdout.flush() print('Groups computed.') sys.stdout.flush() # Sort here already to get deterministic mutex groups. groups = sort_groups(groups) # TODO: I think that collect_all_mutex_groups should do the same thing # as choose_groups with partial_encoding=False, so these two should # be unified. with timers.timing("Collecting mutex groups"): mutex_groups = collect_all_mutex_groups(groups, atoms) with timers.timing("Choosing groups", block=True): groups = choose_groups(groups, atoms, partial_encoding=partial_encoding) groups = sort_groups(groups) with timers.timing("Building translation key"): translation_key = build_translation_key(groups) if DEBUG: for group in groups: if len(group) >= 2: print("{%s}" % ", ".join(map(str, group))) return groups, mutex_groups, translation_key
def compute_groups(task, atoms, reachable_action_params,actions,axioms): print(options.invariant) if options.invariant == 'mip': groups = mip_invariant_finder.get_groups(task,reachable_action_params,atoms,actions) else: groups = invariant_finder.get_groups(task, reachable_action_params) with timers.timing("Instantiating groups"): groups = instantiate_groups(groups, task, atoms) # groups = [group for group in groups if is_group_useful(group,atoms)] # Sort here already to get deterministic mutex groups. groups = sort_groups(groups) # TODO: I think that collect_all_mutex_groups should do the same thing # as choose_groups with partial_encoding=False, so these two should # be unified. with timers.timing("Collecting mutex groups"): mutex_groups = collect_all_mutex_groups(groups, atoms) inessentials = defaultdict(list) if options.group_choice == 'exact': with timers.timing("Choosing groups", block=True): essentials = mip.choose_groups_exact(groups, atoms) elif options.group_choice == 'essential': with timers.timing("Computing exactly groups", block=True): exactly1 = exactly_groups.compute_groups(task,actions,mutex_groups) with timers.timing("Choosing groups", block=True): essentials,inessentials = mip.choose_groups_essential_exact(mutex_groups,exactly1,atoms) else: with timers.timing("Choosing groups", block=True): essentials = choose_groups(groups, atoms) groups = essentials + [[item] for item in inessentials.keys()] if options.group_choice == 'essential' and options.axiom: task.init = [item for item in task.init if not isinstance(item,pddl.Assign) and not item in inessentials ] actions = [action.filt(inessentials) for action in actions] for k,v in inessentials.items(): if len(v) <= 1: axiom = pddl.PropositionalAxiom(k,[],k) axioms.append(axiom) continue neg = pddl.Atom("neg-" + k.predicate,k.args) groups.append([neg]) atoms.add(neg) for atom in v: neg_axiom = pddl.PropositionalAxiom(neg,[atom],neg) axiom = pddl.PropositionalAxiom(k,[neg.negate()],k) axioms.append(neg_axiom) axioms.append(axiom) groups = sort_groups(groups) # for item in groups: # print(item) with timers.timing("Building translation key"): translation_key = build_translation_key(groups) if DEBUG: for group in groups: if len(group) >= 2: print("{%s}" % ", ".join(map(str, group))) return groups, mutex_groups, translation_key,(inessentials)
def compute_groups(task, atoms, reachable_action_params, return_mutex_groups=True, partial_encoding=True, safe=True): ## NOTE: exactly one of the following options should be true # TODO: there should be a configure section for this kind of stuff # don't use the information from the object fluents at all no_objectfluents = False # use only information from objectfluents (all other variables will be # proposotional only_objectfluents = False # use both the information from the objectfluents and the information from # the invariant syntheses and choose the groups by size choose_groups_by_size = False # use first the information from the objectfluents. If there are # propositional variables left use the information from the invariant # syntheses to group them use_objectfluents_first = True objectfluent_groups = [] groups = [] mutex_groups = [] if not no_objectfluents: objectfluent_groups = create_groups_from_object_fluents(atoms) if not only_objectfluents: print "Finding invariants..." groups = invariant_finder.get_groups(task, safe, reachable_action_params) groups = sorted( groups, cmp=lambda x, y: cmp(str([str(a) for a in x]), str([str(a) for a in y]))) print "Instantiating groups..." groups = instantiate_groups(groups, task, atoms) if return_mutex_groups: mutex_groups = collect_all_mutex_groups(groups, atoms) + \ objectfluent_groups print "Choosing groups..." if use_objectfluents_first: groups = choose_groups_with_object_fluents_first( groups, objectfluent_groups, atoms, partial_encoding=partial_encoding) else: if only_objectfluents: groups = objectfluent_groups elif choose_groups_by_size: groups = objectfluent_groups + groups # slightly prefer objectfluent groups groups = choose_groups(groups, atoms, partial_encoding=partial_encoding) print "Building translation key..." translation_key = build_translation_key(groups) return groups, mutex_groups, translation_key
def compute_groups(task, atoms, reachable_action_params, actions): import mutex import time t = time.time() groups = set() for mtype in options.mutex.split('+'): if mtype == 'fd': g = invariant_finder.get_groups(task, reachable_action_params) with timers.timing("Instantiating groups"): g = instantiate_groups(g, task, atoms) g = set([frozenset(x) for x in g]) elif mtype == 'h2': g, _ = mutex.h2(task, atoms, actions) elif mtype == 'fa': g, _ = mutex.fa(task, atoms, actions) elif mtype == 'rfa': g, _ = mutex.rfa(task, atoms, actions) elif mtype == 'rfa-ilp': g, _ = mutex.fa(task, atoms, actions, rfa = True) elif mtype == 'rfa-ilp-c': g, _ = mutex.rfa_complete(task, atoms, actions) elif mtype == 'extend': g, _ = mutex.extend_mutexes(groups, task, atoms, actions) elif mtype == 'full': g, _ = mutex.full(task, atoms, actions, True) elif mtype.startswith('full'): size = int(mtype[4:]) g, _ = mutex.full(task, atoms, actions, True, size) else: raise Exception('Uknown mutex algorithm: ' + mtype) g = set([x for x in g if len(x) > 1]) groups |= g if options.mutex_max: groups = mutex.max_mutexes(groups) t = time.time() - t print('MUTEX TIME:', t) for m in groups: print('MUTEX:', ';'.join(sorted([str(x) for x in m]))) for m in mutex.pair_mutexes(groups): print('MUTEX2:', ';'.join(sorted([str(x) for x in m]))) # for m in mutex.max_mutexes(groups): # print('MUTEX-MAX:', ';'.join(sorted([str(x) for x in m]))) if options.mutex_check >= 0: check, _ = mutex.full(task, atoms, actions, True, options.mutex_check) if check is not None: mutex.check_mutexes(check, groups) # Sort here already to get deterministic mutex groups. groups = sort_groups(groups) # TODO: I think that collect_all_mutex_groups should do the same thing # as choose_groups with partial_encoding=False, so these two should # be unified. with timers.timing("Collecting mutex groups"): mutex_groups = collect_all_mutex_groups(groups, atoms) with timers.timing("Choosing groups", block=True): groups = choose_groups(groups, atoms) groups = sort_groups(groups) with timers.timing("Building translation key"): translation_key = build_translation_key(groups) if DEBUG: for group in groups: if len(group) >= 2: print("{%s}" % ", ".join(map(str, group))) return groups, mutex_groups, translation_key
def compute_groups(task, atoms, reachable_action_params, actions): import mutex import time t = time.time() groups = set() for mtype in options.mutex.split('+'): if mtype == 'fd': g = invariant_finder.get_groups(task, reachable_action_params) with timers.timing("Instantiating groups"): g = instantiate_groups(g, task, atoms) g = set([frozenset(x) for x in g]) elif mtype == 'h2': g, _ = mutex.h2(task, atoms, actions) elif mtype == 'fa': g, _ = mutex.fa(task, atoms, actions) elif mtype == 'rfa': g, _ = mutex.rfa(task, atoms, actions) elif mtype == 'rfa-ilp': g, _ = mutex.fa(task, atoms, actions, rfa=True) elif mtype == 'rfa-ilp-c': g, _ = mutex.rfa_complete(task, atoms, actions) elif mtype == 'extend': g, _ = mutex.extend_mutexes(groups, task, atoms, actions) elif mtype == 'full': g, _ = mutex.full(task, atoms, actions, True) elif mtype.startswith('full'): size = int(mtype[4:]) g, _ = mutex.full(task, atoms, actions, True, size) else: raise Exception('Uknown mutex algorithm: ' + mtype) g = set([x for x in g if len(x) > 1]) groups |= g if options.mutex_max: groups = mutex.max_mutexes(groups) t = time.time() - t print('MUTEX TIME:', t) for m in groups: print('MUTEX:', ';'.join(sorted([str(x) for x in m]))) for m in mutex.pair_mutexes(groups): print('MUTEX2:', ';'.join(sorted([str(x) for x in m]))) # for m in mutex.max_mutexes(groups): # print('MUTEX-MAX:', ';'.join(sorted([str(x) for x in m]))) if options.mutex_check >= 0: check, _ = mutex.full(task, atoms, actions, True, options.mutex_check) if check is not None: mutex.check_mutexes(check, groups) # Sort here already to get deterministic mutex groups. groups = sort_groups(groups) # TODO: I think that collect_all_mutex_groups should do the same thing # as choose_groups with partial_encoding=False, so these two should # be unified. with timers.timing("Collecting mutex groups"): mutex_groups = collect_all_mutex_groups(groups, atoms) with timers.timing("Choosing groups", block=True): groups = choose_groups(groups, atoms) groups = sort_groups(groups) with timers.timing("Building translation key"): translation_key = build_translation_key(groups) if DEBUG: for group in groups: if len(group) >= 2: print("{%s}" % ", ".join(map(str, group))) return groups, mutex_groups, translation_key