Пример #1
0
def main(argv):
    "Process command line arguments and kick things off"
    progname = argv[0].split('/')[-1]

    # Parse command line options
    try:
        (opts, args) = getopt.getopt(argv[1:], "hk")
    except getopt.GetoptError as err:
        print >> sys.stderr, str(err)
        usage(progname)
    for opt, _ in opts:
        if opt == '-h':
            usage(progname)

    diag_files = args
    if len(diag_files) == 0:
        diag_files.append(None)  # Read from stdin

    # Do the work
    diags = set()
    diag_gen = load_diagrams_from_files(diag_files)
    for diagram in diag_gen:
        comp_diag = get_compressed_diagram(diagram)
        if str(comp_diag) not in diags:
            print diagram
            for rots in range(0, len(comp_diag) * 2):
                rot_diag = get_rotated_diagram(comp_diag, rots)
                diags.add(str(rot_diag))
Пример #2
0
def main(argv):
    "Process command line arguments and kick things off"
    progname = argv[0].split('/')[-1]
    max_cpus = 0  # Default - use actual cpu_count
    status_diagrams = 100000
    diag_strs = []
    block_size = 1
    block_item = 1

    # Parse command line options
    try:
        (opts, args) = getopt.getopt(argv[1:], "hc:p:d:b:i:")
    except getopt.GetoptError as err:
        print >> sys.stderr, str(err)
        usage(progname)
    for opt, arg in opts:
        if opt == '-c':
            max_cpus = int(arg)
        elif opt == '-d':
            diag_strs.append(arg)
        elif opt == '-p':
            status_diagrams = int(arg)
        elif opt == '-b':
            block_size = int(arg)
        elif opt == '-i':
            block_item = int(arg)
        elif opt == '-h':
            usage(progname)

    # Convert diagram strings to diagrams
    diagrams = []
    if len(diag_strs) > 0:
        for diag_str in diag_strs:
            # TODO: regex validate diag str to prevent code injection attack
            try:
                diagrams.append(eval(diag_str))
            except Exception:
                usage(progname,
                      "Error: Invalid diagram in '-d' option:" + diag_str)

    diag_files = args
    if len(diag_files) == 0 and not diagrams:
        diag_files.append(None)  # Read from stdin

    # Do the work
    diag_gen = chain(
        diagrams,
        load_diagrams_from_files(diag_files, status_diagrams, block_size,
                                 block_item))
    for result in find_graph_planars(diag_gen, max_cpus):
        if result[0]:
            print result[1]
Пример #3
0
def main(argv):
    "Process command line arguments and kick things off"
    progname = argv[0].split('/')[-1]
    n_chords = 0  # Cmdline option '-n'
    scale = 1 # Default Cmdline option '-s'
    min_chord_length = 1 # Cmdline option '-l'
    print_status = 100000 # Cmdline option '-p'
    max_cpus = 1 # Default to single processing. Cmdline option '-c'
    block_size = 1 # Number of items in a block.
    block_item = 1 # Which item in block to process - trivial multinode support
    base_fname = "" # Output filename. Leading chord is '-#_#' appended to name

    # Parse command line options
    try:
        (opts, args) = getopt.getopt(argv[1:], "hn:s:l:p:c:b:i:f:")
    except getopt.GetoptError as err:
        print >>sys.stderr, str(err)
        usage(progname)
    for opt, arg in opts:
        if opt == '-b':
            block_size = int(arg)
        elif opt == '-h':
            usage()
        elif opt == '-i':
            block_item = int(arg)
        elif opt == '-p':
            print_status = int(arg)

    # Determine input sources, if any
    diag_files = args
    if len(diag_files) == 0:
        diag_files.append(None) # Read from stdin

    count = 0
    found = 0
    for diag in load_diagrams_from_files(diag_files,print_status, block_size, block_item):
        count += 1
        if diagram_filter(diag):
            found += 1
            print diag
        if print_status and count % print_status == 0:
            print >>sys.stderr, "{} Count: {:,}  Found: {:,}".format(timestamp(), count, found)
    print >>sys.stderr, "{} Complete! Count: {:,}  Found: {:,}".format(timestamp(), count, found)
def main(argv):
    "Process command line arguments and kick things off"
    progname = argv[0].split('/')[-1]
    print_all = False  # Print detail on each move type
    print_status = 10000
    block_size = 1
    block_item = 1
    diag_strs = []

    # Parse command line options
    try:
        (opts, args) = getopt.getopt(argv[1:], "ab:d:hi:p:")
    except getopt.GetoptError as err:
        usage(progname)
    for opt, arg in opts:
        if opt == '-a':
            print_all = True
        elif opt == '-b':
            block_size = int(arg)
        elif opt == '-d':
            diag_strs.append(arg)
        elif opt == '-h':
            usage(progname)
        elif opt == '-i':
            block_item = int(arg)
        elif opt == '-p':
            print_status = int(arg)

    # Convert diagram strings to diagrams
    diagrams = []
    if len(diag_strs) > 0:
        for diag_str in diag_strs:
            # TODO: regex validate diag str to prevent code injection attack
            try:
                diagrams.append(eval(diag_str))
            except Exception:
                usage(progname,
                      "Error: Invalid diagram in '-d' option:" + diag_str)

    # Determine input sources, if any
    diag_files = args
    if len(diag_files) == 0 and not diagrams:
        diag_files.append(None)  # Read from stdin
    diag_gen = chain(
        diagrams,
        load_diagrams_from_files(diag_files, print_status, block_size,
                                 block_item))

    # Do the work
    for diagram in diag_gen:
        ext_possible_nodes = range(1, len(diagram) * 4, 2)  # Odds 1..2*n_nodes
        ext_possible_chords = get_possible_chords(node_list=ext_possible_nodes)

        sparse_diagram = get_scaled_diagram(diagram, 2)
        invariant_chords = get_invariant_chords_for_diagram(
            sparse_diagram,
            ext_possible_chords,
            diagram_filter=diagram_filter,
            doScale=False)

        if print_all or invariant_chords:
            print
            print "Orig diagram  :", diagram
            print "Sparse diagram:", sparse_diagram
            print "Invariant chords:", invariant_chords
def main(argv):
    "Process command line arguments and kick things off"
    progname = argv[0].split('/')[-1]
    max_cpus = 0 # Default - use actual cpu_count
    status_diagrams = 100000
    diag_strs = []
    block_size = 1
    block_item = 1

    # Parse command line options
    try:
        (opts, args) = getopt.getopt(argv[1:], "hc:p:d:b:i:")
    except getopt.GetoptError as err:
        print >>sys.stderr, str(err)
        usage(progname)
    for opt, arg in opts:
        if opt == '-c':
            max_cpus = int(arg)
        elif opt == '-d':
            diag_strs.append(arg)
        elif opt == '-p':
            status_diagrams = int(arg)
        elif opt == '-b':
            block_size = int(arg)
        elif opt == '-i':
            block_item = int(arg)
        elif opt == '-h':
            usage(progname)

    # Convert diagram strings to diagrams
    diagrams = []
    if len(diag_strs) > 0:
        for diag_str in diag_strs:
            # TODO: regex validate diag str to prevent code injection attack
            try:
                diagrams.append(eval(diag_str))
            except Exception:
                usage(progname,"Error: Invalid diagram in '-d' option:" + diag_str)

    # Determine input sources, if any
    diag_files = args
    if len(diag_files) == 0 and not diagrams:
        diag_files.append(None) # Read from stdin

    # Do the work
    diag_gen = chain(diagrams,
                     load_diagrams_from_files(diag_files, status_diagrams,
                                              block_size, block_item))
    count = 0
    found = 0
    print >>sys.stderr, "{} Starting find_2move_inclusions".format(timestamp())
    for result in find_planarable_2moves(diag_gen, max_cpus):
        count += 1
        if result[1]:
            found += 1
            print "diag:", result[0]
            print "diagx3", result[1]
            print "chords", result[2]
        if count % 10000 == 0:
            print >>sys.stderr, "{} Total: {:,} Found:{:,}".format(timestamp(), count, found)
    print >>sys.stderr, "{} Complete Total: {:,} Found:{:,}".format(timestamp(), count, found)