def iterative_encode(self, glyph_set, fdselect=None, fdlen=1):

        # generate substrings for marketplace
        sf = SubstringFinder(glyph_set, verbose=self.verbose)

        if self.test_mode:
            substrings = sf.get_substrings(min_freq=0, check_positive=False, sort_by_length=False)
        else:
            substrings = sf.get_substrings(min_freq=2, check_positive=True, sort_by_length=False)

        # TODO remove unnecessary substrings?

        data = sf.data
        rev_keymap = sf.rev_keymap
        cost_map = sf.cost_map
        glyph_set_keys = sf.glyph_set_keys
        del sf

        if not self.SINGLE_PROCESS:
            pool = multiprocessing.Pool(processes=self.PROCESSES)
        else:
            class DummyPool: pass
            pool = DummyPool()
            pool.map = lambda f, *l, **kwargs: map(f, *l)

        substr_dict = {}

        start_time = time.time()

        if self.verbose:
            print("glyphstrings+substrings=%d" % (len(data) + len(substrings)))

        # set up dictionary with initial values
        for idx, substr in enumerate(substrings):
            substr._adjusted_cost = substr.cost()
            substr._price = substr._adjusted_cost
            substr._usages = substr.freq # this is the frequency that the substring appears, 
                                        # not necessarily used
            substr._list_idx = idx
            substr_dict[substr.value()] = (idx, substr._price) # NOTE: avoid excess data copying on fork
                                                               # probably can just pass substr
                                                               # if threading instead

        for run_count in range(self.NROUNDS):
            # calibrate prices
            for idx, substr in enumerate(substrings):
                marg_cost = float(substr._adjusted_cost) / (substr._usages + self.K)
                substr._price = marg_cost * self.ALPHA + substr._price * (1 - self.ALPHA)
                substr_dict[substr.value()] = (idx, substr._price)

            # minimize substring costs
            csize = int(math.ceil(self.POOL_CHUNKRATIO*len(substrings)))
            substr_encodings = pool.map(functools.partial(optimize_charstring, 
                                                          cost_map=cost_map,
                                                          substr_dict=substr_dict,
                                                          verbose=self.verbose),
                                        enumerate([s.value() for s in substrings]),
                                        chunksize=csize)

            for substr, result in zip(substrings, substr_encodings):
                substr._encoding = [(enc_item[0], substrings[enc_item[1]]) for enc_item in result["encoding"]]
                substr._adjusted_cost = result["market_cost"]
            del substr_encodings

            # minimize charstring costs in current market through DP
            csize = int(math.ceil(self.POOL_CHUNKRATIO*len(data)))
            encodings = pool.map(functools.partial(optimize_charstring,
                                                   cost_map=cost_map,
                                                   substr_dict=substr_dict,
                                                   verbose=self.verbose),
                                 data,
                                 chunksize=csize)
            encodings = [[(enc_item[0], substrings[enc_item[1]]) for enc_item in i["encoding"]] for i in encodings]

            # update substring frequencies based on cost minimization
            for substr in substrings:
                substr._usages = 0

            for calling_substr in substrings:
                for start, substr in calling_substr._encoding:
                    if substr:
                        substr._usages += 1
            for glyph_idx, enc in enumerate(encodings):
                for start, substr in enc:
                    if substr:
                        substr._usages += 1

            if self.verbose or self.print_status:
                print("Round %d Done!" % (run_count + 1))
                print("avg: %f" % (float(sum(substr._usages for substr in substrings)) / len(substrings)))
                print("max: %d" % max(substr._usages for substr in substrings))
                print("used: %d" % sum(substr._usages > 0 for substr in substrings))

            if run_count <= self.NROUNDS - 2 and not self.test_mode:
                cutdown_time = time.time()
                if run_count < self.NROUNDS - 2:
                    bad_substrings = [s for s in substrings if s.subr_saving(use_usages=True) <= 0]
                    substrings = [s for s in substrings if s.subr_saving(use_usages=True) > 0]
                else:
                    bad_substrings = [s for s in substrings if s.subr_saving(use_usages=True, true_cost=False) <= 0]
                    substrings = [s for s in substrings if s.subr_saving(use_usages=True, true_cost=False) > 0]

                for substr in bad_substrings:
                    # heuristic to encourage use of called substrings:
                    for idx, called_substr in substr._encoding:
                        called_substr._usages += substr._usages - 1
                    del substr_dict[substr.value()]
                for idx, s in enumerate(substrings):
                    s._list_idx = idx
                if self.verbose:
                    print("%d substrings with non-positive savings removed" % len(bad_substrings))
                    print("(%d had positive usage)" % len([s for s in bad_substrings if s._usages > 0]))
                    print("Took %gs to cutdown" % (time.time() - cutdown_time))

            if self.verbose:
                print("")

        if self.verbose or self.print_status:
            print("Finished iterative market (%gs)" % (time.time() - start_time))
            print("%d candidate subrs found" % len(substrings))

        gsubrs, lsubrs = Compreffor.process_subrs(
                                            glyph_set_keys,
                                            encodings,
                                            fdlen,
                                            fdselect,
                                            substrings,
                                            rev_keymap,
                                            self.NSUBRS_LIMIT,
                                            self.SUBR_NEST_LIMIT,
                                            self.verbose)

        return {"glyph_encodings": dict(zip(glyph_set_keys, encodings)),
                "lsubrs": lsubrs,
                "gsubrs": gsubrs}
Returns the name of a package at a path.
dataset/ETHPy150Open googlei18n/compreffor/compreffor/pyCompressor.py/Compreffor.iterative_encode--crossover with--dataset/ETHPy150Open lektor/lektor/lektor/packages.py/get_package_info