def run(): parser = argparse.ArgumentParser( description="Run VSVBP heuristics on given instances") parser.add_argument( '-f', type=argparse.FileType('r'), help="The path to a file containing the bin packing problem to optimize" ) parser.add_argument('-d', help="A directory containing (only) files modeling\ bin packing problems to optimize. Optimize all files in the directory." ) parser.add_argument('-r', action='store_true', help="Recursive. If a directory is provided,\ optimize all files in all final subdirectories.") parser.add_argument('-u', action='store_true', help="If activated, use dot product heuristics") parser.add_argument('-s', type=int, help="Set seed to specified value") args = parser.parse_args() if not (args.f or args.d): parser.error('No action requested, add -f or -d') if args.f and args.d: parser.error('Too many actions requested, add only -f or -d') if args.r and not args.d: sys.stderr.write("Warning recursive argument was specified but") sys.stderr.write(" no directory was provided. Argument ignored.\n") if args.d and not os.path.isdir(args.d): parser.error('Invalid directory') optimize.dp = args.u optimize.seed = args.s if args.f: items, tbin = parse(args.f) opt = len(solver.optimize(items, tbin, args.u, args.s).bins) template = "{0:50}{1:10}" st = args.f.name.split('/').pop() print template.format(st, str(opt)) elif not args.r: optim_dir(args.d) else: optim_rec(args.d)
def optimize(filename, level=0): fl = open(filename) items, tbin = parse(fl) if not items: fl.close() return opt = len(solver.optimize(items, tbin, optimize.dp, optimize.seed).bins) template = "{0:50}{1:10}" if level == 0: st = filename.split('/').pop() print template.format(st, str(opt)) else: st = " " * level + "| " + filename.split('/').pop() print template.format(st, str(opt)) fl.close() sys.stdout.flush()
def optimize(filename, level=0): fl = open(filename) items, tbin = parse(fl) if not items: fl.close() return opt = len(solver.optimize(items, tbin, optimize.dp, optimize.seed).bins) template = "{0:50}{1:10}" if level == 0: st = filename.split('/').pop() print template.format(st, str(opt)) else: st = " "*level+"| "+filename.split('/').pop() print template.format(st, str(opt)) fl.close() sys.stdout.flush()
def run(): parser = argparse.ArgumentParser(description="Run VSVBP heuristics on given instances") parser.add_argument('-f', type=argparse.FileType('r'), help="The path to a file containing the bin packing problem to optimize") parser.add_argument('-d', help="A directory containing (only) files modeling\ bin packing problems to optimize. Optimize all files in the directory.") parser.add_argument('-r', action='store_true', help="Recursive. If a directory is provided,\ optimize all files in all final subdirectories.") parser.add_argument('-u', action='store_true', help="If activated, use dot product heuristics") parser.add_argument('-s', type=int, help="Set seed to specified value") args = parser.parse_args() if not (args.f or args.d): parser.error('No action requested, add -f or -d') if args.f and args.d: parser.error('Too many actions requested, add only -f or -d') if args.r and not args.d: sys.stderr.write("Warning recursive argument was specified but") sys.stderr.write(" no directory was provided. Argument ignored.\n") if args.d and not os.path.isdir(args.d): parser.error('Invalid directory') optimize.dp = args.u optimize.seed = args.s if args.f: items, tbin = parse(args.f) opt = len(solver.optimize(items, tbin, args.u, args.s).bins) template = "{0:50}{1:10}" st = args.f.name.split('/').pop() print template.format(st, str(opt)) elif not args.r: optim_dir(args.d) else: optim_rec(args.d)