示例#1
0
def write_tp_rows():
    """Write out just the first row of the transition matrix for several
    TSP operators. The first row is enough since later rows are just a
    rotation of the first.

    """
    
    basename = sys.argv[1]
    ops = ("two_opt", "twoh_opt", "three_opt", "three_opt_broad", "swap", "swap_adj")
    lengths = (6, 7, 8, 9, 10)
    for op in ops:
        for length in lengths:
            filename = os.path.join(basename,
                                    "tsp_length_%d_%s" % (length, op),
                                    "TP_row0.dat")
            print op, length
            x = tsp.get_tm_first_row(length, move=op)
            np.savetxt(filename, x)
示例#2
0
def write_tp_row0(space):
    """Write out just the first row of the transition matrix for several
    operators of the given space. The first row is enough since later
    rows are just a rotation of the first.

    """
    
    basename = sys.argv[1]
    if space == "permutation":
        ops = ("two_opt", "twoh_opt", "three_opt", "three_opt_broad", "swap_two", "swap_adj")
        sizes = (9, 10, 11)
    elif space == "bitstring":
        ops = ("per_gene", "per_ind")
        pmuts = (0.0001, 0.0003, 0.0010, 0.0033, 0.01, 0.0333, 0.1, 0.3333)
        sizes = (10, 12, 14)
    for op in ops:
        for size in sizes:
            print op, size
            if space == "permutation":
                filename = os.path.join(basename,
                                        "space_%s/size_%d_op_%s" % (space, size, op),
                                        "TP_row0.dat")
                x = tsp.get_tm_first_row(size, move=op)
                np.savetxt(filename, x)
            elif space == "bitstring":
                if op == "per_ind":
                    filename = os.path.join(basename,
                                            "space_%s/size_%d_op_%s" % (space, size, op),
                                            "TP_row0.dat")
                    x = bitstring.generate_bitstring_tm_row0(size, pmut=None)
                    np.savetxt(filename, x)
                elif op == "per_gene":
                    for pmut in pmuts:
                        op_ = "%s_%.4f" % (op, pmut)
                        filename = os.path.join(basename,
                                                "space_%s/size_%d_op_%s" % (space, size, op_),
                                                "TP_row0.dat")
                        x = bitstring.generate_bitstring_tm_row0(size, pmut=pmut)
                        np.savetxt(filename, x)
                else:
                    raise ValueError("Unexpected operation + op")