def __init__(self, container: Container, limited_population_size: int, mutaion_probability:float, times: int): self.box_list = None self.population = None self.limited_population_size = limited_population_size self.mutaion_probability = mutaion_probability self.stage_best_fitness=[] self.stage_best_scheme=[] self.containers = [] self.time = times Packer.__init__(self, container)
def remap(self): self.chars.sort() self.glyphs = [] for group in self.groups: group.add_chars(self.chars) self.glyphs.extend(group.glyphs) # packer = newPacker(sort_algo=SORT_NONE, rotation=False, bin_algo=PackingBin.Global) packer = Packer(self.tex_w, self.tex_h) for glyph in self.glyphs: if glyph.empty: continue packer.add_rect(glyph.rect.width, glyph.rect.height, rid='%s_%s' % (glyph.group, glyph.char)) packer.add_rect(4, 4, "empty") # packer.add_bin(self.tex_w, self.tex_h) packer.pack() rect_list = packer.rectst for r in rect_list: for glyph in self.glyphs: if r[5] == "empty" and glyph.empty: glyph.x = r[1] glyph.y = r[2] continue if '%s_%s' % (glyph.group, glyph.char) == r[5]: glyph.x = r[1] glyph.y = r[2]
def valid_packer(): """ Return a Packer instance initiated with a valid test package. The package used for testing is as follows: 50 : (1,10,€60) (2,20,€100) (3,30,€100) """ return Packer('50 : (1,10,€60) (2,20,€100) (3,30,€100)')
# !/usr/bin/python # coding:utf-8 import os,hashlib,json from shutil import copytree, ignore_patterns,rmtree from pack import Packer,DealResource CURDIR = os.path.split(os.path.realpath(__file__))[0] NAME = "fileinfo.txt" serveroot = os.path.join(CURDIR,"../trunk/serve/code/hotUpdateServer/root/game") game_root = os.path.join(CURDIR,"../trunk/client/mahjong") # make root if os.path.exists(serveroot): rmtree(serveroot) os.mkdir(serveroot) # copy for dirname in ("res","src"): copytree(os.path.join(game_root,dirname), os.path.join(serveroot,dirname), ignore=ignore_patterns('*.pyc', 'tmp*')) instance = Packer(game_root,None,"android",None) instance.updateVersion() instance.encryptCode(os.path.join(serveroot,"src"),os.path.join(serveroot,"res")) deal = DealResource(serveroot) deal.run()
if cmd_argv[1] == '--file': reader = FileReader(cmd_argv[2]) elif cmd_argv[1] == '--git': args = cmd_argv[2:] wd = args.pop(0) hash1 = args.pop(0) try: hash2 = args.pop(0) except IndexError: hash2 = None reader = GitReader(wd, hash1, hash2) else: raise UnsupportedReaderError(cmd_argv[1]) return reader if __name__ == "__main__": valid = True try: reader = get_reader(argv) except UnsupportedReaderError: valid = False except IndexError: # if argv[1] is not found valid = False if not valid: show_usage() exit(1) config = reader.get_config() p = Packer(config) output = p.output() print "Project files packed to %s" % (output["target_path"])
reader = FileReader(cmd_argv[2]) elif cmd_argv[1] == '--git': args = cmd_argv[2:] wd = args.pop(0) hash1 = args.pop(0) try: hash2 = args.pop(0) except IndexError: hash2 = None reader = GitReader(wd, hash1, hash2) else: raise UnsupportedReaderError(cmd_argv[1]) return reader if __name__ == "__main__": valid = True try: reader = get_reader(argv) except UnsupportedReaderError: valid = False except IndexError: # if argv[1] is not found valid = False if not valid: show_usage() exit(1) config = reader.get_config() p = Packer(config) output = p.output() print "Project files packed to %s" % (output["target_path"])
def empty_packer(): """Return a Packer instance initiated with default (empty) values.""" return Packer()
def test_solve_method(input_data, expected_solution): """Test functionality of the solve method, comparing to known solution.""" packer = Packer(input_data) packer.solve() assert packer.__str__() == expected_solution
def test_max_weight_constraint(input_data, error_message): """Test all of the challenge's constraints, expect APIException.""" with pytest.raises(APIException, match=error_message, message='Expecting APIException'): Packer(input_data)