def do( solver_t, ws, steps, w_min, w_max, search_t, diag ): db = [] print solver_t, ws, steps, w_min, w_max, search_t, diag var_d = [ "0x" + "0"*(ws/4) for _ in xrange(16) ] fmt = "{:0"+ str(ws/2) + "X}" w_best = w_max v_best = None nr = 0 for i in xrange(2*ws-1,-1,-1): for j in xrange(i): print nr, i, j, "best:", w_best, v_best v = fmt.format( (1 << i) + (1 << j) ) var_d[1] = "0x" + v[:ws/4] var_d[2] = "0x" + v[ws/4:] r = basic.do( solver_t, ws, steps, w_min, w_best, search_t, diag, "input", var_d ) if r != [] and int(r[0][0]) < w_best: w_best = int(r[0][0]) v_best = (var_d[1],var_d[2]) nr += 1
def do(solver_t, ws, steps, w_min, w_max, search_t, diag): db = [] print solver_t, ws, steps, w_min, w_max, search_t, diag var_d = ["0x" + "0" * (ws / 4) for _ in xrange(16)] fmt = "{:0" + str(ws / 2) + "X}" w_best = w_max v_best = None nr = 0 for i in xrange(2 * ws - 1, -1, -1): for j in xrange(i): print nr, i, j, "best:", w_best, v_best v = fmt.format((1 << i) + (1 << j)) var_d[1] = "0x" + v[:ws / 4] var_d[2] = "0x" + v[ws / 4:] r = basic.do(solver_t, ws, steps, w_min, w_best, search_t, diag, "input", var_d) if r != [] and int(r[0][0]) < w_best: w_best = int(r[0][0]) v_best = (var_d[1], var_d[2]) nr += 1
def main(): p = argparse.ArgumentParser( description='{} ({})'.format(__description__, __version__)) p.add_argument('-d', help="set type of search database", required=True, choices=['basic', 'enum', 'bit']) p.add_argument('-e', help="set type of search problem (see config.json)", required=True) p.add_argument('-p', help="print the CVC code and return", action='store_true') args = p.parse_args() path = './tmp/' f = path + '{}-{}-{}.csv'.format(args.d, args.e, utils.timestamp()) if args.d == 'basic': import src.search.basic as search cmds = cmd.basic elif args.d == 'enum': import src.search.enum as search cmds = cmd.enum elif args.d == 'bit': import src.search.bit as search cmds = cmd.bit """ check if stp and solver are in PATH or node/bin """ stp = utils.which('stp') solver = utils.which(cmds[args.e][0]) if stp == None: print "stp not found in PATH or in node/bin" return 1 if solver == None: print "solver {} not found in PATH or in node/bin".format( cmds[args.e][0]) return 1 if not args.p: """ start search """ solutions = search.do(*cmds[args.e]) if solutions != None: utils.to_csv(solutions, f) print "Solution(s) written to {}".format(f) else: """ print CVC code """ print search.cvc(*cmds[args.e])
def main(): p = argparse.ArgumentParser(description='{} ({})'.format(__description__,__version__)) p.add_argument('-d',help="set type of search database",required=True,choices=['basic','enum','bit']) p.add_argument('-e',help="set type of search problem (see config.json)",required=True) p.add_argument('-p',help="print the CVC code and return",action='store_true') args = p.parse_args() path = './tmp/' f = path + '{}-{}-{}.csv'.format(args.d,args.e,utils.timestamp()) if args.d == 'basic': import src.search.basic as search cmds = cmd.basic elif args.d == 'enum': import src.search.enum as search cmds = cmd.enum elif args.d == 'bit': import src.search.bit as search cmds = cmd.bit """ check if stp and solver are in PATH or node/bin """ stp = utils.which('stp') solver = utils.which(cmds[args.e][0]) if stp == None: print "stp not found in PATH or in node/bin" return 1 if solver == None: print "solver {} not found in PATH or in node/bin".format(cmds[args.e][0]) return 1 if not args.p: """ start search """ solutions = search.do(*cmds[args.e]) if solutions != None: utils.to_csv( solutions, f ) print "Solution(s) written to {}".format(f) else: """ print CVC code """ print search.cvc(*cmds[args.e])