def generate_all_schemes(cfg): """ Convert the abstract schema given by the algorithm into subsets """ log.info("Generating all possible schemes for the partitions...") subset_count = len(cfg.user_subsets) # Now generate the pattern for this many partitions all_schemes = submodels.get_submodels(subset_count) scheme_name = 1 scheme_list = [] for scheme in all_schemes: subs = {} # We use the numbers returned to group the different subsets for sub_index, grouping in enumerate(scheme): insub = subs.setdefault(grouping, []) insub.append(sub_index) # We now have what we need to create a subset. Each entry will have a # set of values which are the index for the partition created_subsets = [] for sub_indexes in subs.values(): sub = subset_ops.merge_subsets( [cfg.user_subsets[i] for i in sub_indexes]) created_subsets.append(sub) scheme_list.append(Scheme(cfg, str(scheme_name), created_subsets)) log.debug("Created scheme %d of %d" % (scheme_name, len(all_schemes))) scheme_name += 1 return scheme_list
def create_scheme(cfg, scheme_name, scheme_description): """ Generate a single scheme given a list of numbers that represent the indexes of the partitions e.g. [0,1,2,3,4,5,6,7] """ subset_count = len(cfg.user_subsets) # Check that the correct number of items are in the list if len(scheme_description) != subset_count: log.error("There's a problem with the description of scheme %s" % scheme_name) raise SchemeError # Now generate the pattern subs = {} # We use the numbers returned to group the different subsets for sub_index, grouping in enumerate(scheme_description): insub = subs.setdefault(grouping, []) insub.append(sub_index) # We now have what we need to create a subset. Each entry will have a # set of values which are the index for the partition created_subsets = [] for sub_indexes in subs.values(): subs_to_merge = [cfg.user_subsets[i] for i in sub_indexes] sub = subset_ops.merge_subsets(subs_to_merge) created_subsets.append(sub) return Scheme(cfg, str(scheme_name), created_subsets, description=scheme_description)
def model_to_scheme(model, scheme_name, cfg): """Turn a model definition e.g. [0, 1, 2, 3, 4] into a scheme""" subs = {} # We use the numbers returned to group the different subsets for sub_index, grouping in enumerate(model): insub = subs.setdefault(grouping, []) insub.append(sub_index) # We now have what we need to create a subset. Each entry will have a # set of values which are the index for the partition created_subsets = [] for sub_indexes in subs.values(): subs_to_merge = [cfg.user_subsets[i] for i in sub_indexes] sub = subset_ops.merge_subsets(subs_to_merge) created_subsets.append(sub) return Scheme(cfg, str(scheme_name), created_subsets)