Пример #1
0
def pytest6(verbose=1):
    """ Check generation of OA(32, t, 2^a) """
    N = 32
    k = 8
    t = 3
    l = [2] * 8
    rr = []
    gtrr = [3, 5, 10, 17, 33]
    s = oalib.intVector(l)
    adata = oalib.arraydata_t(s, N, t, k)

    if verbose:
        print('pytest6: run different algorithms on the same case')
    algs = [oalib.MODE_ORIGINAL, oalib.MODE_J4]
    for ii, alg in enumerate(algs):
        algname = oalib.algnames(alg)
        if verbose >= 2:
            print('pytest6: running %s, alg %s' % (adata.fullidstr(), algname))
        rr = []
        tmp = oahelper.runExtend(N,
                                 k,
                                 t,
                                 l,
                                 verbose=verbose,
                                 nums=rr,
                                 algorithm=alg)
        if not rr == gtrr:
            print('pytest6: case %s' % adata.fullidstr())
            print(
                '   algorithm %s: error: incorrect number of arrays! %s -> %s'
                % (algname, rr, gtrr))
Пример #2
0
def selectArraysInFile(infile,
                       outfile,
                       idx,
                       afmode=oalib.ATEXT,
                       verbose=1,
                       cache=1):
    """ Select arrays in a file by indices

    Args:
        infile (str): file with designs
        outfile (str): output  file with designs
        inx (list of indices)
    Returns:
        None

    """
    if not checkFiles(outfile, cache=cache):
        gidxint = oalib.intVector([int(x) for x in idx])
        sols = oalib.arraylist_t()
        oalib.selectArrays(infile, gidxint, sols, 0)
        af = oalib.arrayfile_t(infile, 1)
        _ = oalib.writearrayfile(outfile, sols, afmode, af.nrows, af.ncols)
        if verbose >= 2:
            print('selectArrays: write array file %s in mode %d' %
                  (outfile, afmode))
    else:
        if verbose >= 2:
            print('output file %s already exists' % outfile)
Пример #3
0
def pytest2level(verbose=1):
    """ Check generation of OA(16,2, 4^2 2^a) """
    N = 32
    k = 10
    t = 3
    l = [2]
    rr = []
    t0 = time.time()
    oahelper.runExtend(N,
                       k,
                       t,
                       l,
                       verbose=1,
                       nums=rr,
                       algorithm=oalib.MODE_ORIGINAL)
    dt = time.time() - t0
    t0 = time.time()
    oahelper.runExtend(N,
                       k,
                       t,
                       l,
                       verbose=1,
                       nums=rr,
                       algorithm=oalib.MODE_LMC_2LEVEL)
    dt2level = time.time() - t0

    ll = l * k
    s = oalib.intVector(ll)

    adata = oalib.arraydata_t(s, N, t, k)

    if verbose:
        print('case %s: 2-level method %.2f [s] -> %.2f [s]' %
              (adata.idstr(), dt, dt2level))
Пример #4
0
def selectArrays(infile, outfile, idx, afmode=oalib.ATEXT, verbose=1, cache=1):
    """ Select arrays in a file by indices

    Input:
        - infile (string)
        - outfile (string)
        - inx (list of indices)
    Output:
        - None

    """
    if not checkFiles(outfile, cache=cache):
        gidxint = oalib.intVector([int(x) for x in idx])
        # print('  xx select: %s' % str(gidxint))
        # print('  xx select: %s' % str([v for v in gidxint]))
        sols = oalib.arraylist_t()
        oalib.selectArrays(infile, gidxint, sols, 0)
        af = oalib.arrayfile_t(infile, 1)
        af.nrows
        r = oalib.writearrayfile(outfile, sols, afmode, af.nrows, af.ncols)
        if verbose >= 2:
            print('selectArrays: write array file %s in mode %d' %
                  (outfile, afmode))
    else:
        if verbose >= 2:
            print('output file %s already exists' % outfile)
Пример #5
0
def runExtend(N,
              k,
              t=3,
              l=2,
              verbose=1,
              initsols=None,
              nums=[],
              algorithm=None):
    """ Run extension algorithm and return arrays

    Args:
      N (int): number of rows
      k (int): number of columns to extend to
      t (int): strength of the arrays
      l (int): factors of the designs
      initsols (None or list): list of arrays to extend, None to start with root

    Returns:
        list: list of generated designs

    Example:
       >>> import oapackage
       >>> designs = oapackage.oahelper.runExtend(16, 5, 3, verbose=0)
    """
    if verbose:
        print('runExtend: N=%d, k=%d, t=%d' % (N, k, t))
    if isinstance(l, list):
        ll = l
    else:
        ll = [l]
    ll = ll + [ll[-1]] * (k - len(ll))
    s = oalib.intVector(ll)
    adata = oalib.arraydata_t(s, N, t, k)
    al = oalib.array_link(adata.N, adata.strength, 1)
    al.create_root(adata)
    if initsols is None:
        sols0 = oalib.arraylist_t()
        sols0.append(al)
        tstart = t
    else:
        sols0 = initsols
        tstart = sols0[0].n_columns

    oaoptions = oalib.OAextend()
    if algorithm is None:
        oaoptions.setAlgorithmAuto(adata)
    else:
        oaoptions.setAlgorithm(algorithm, adata)
    solsx = sols0
    for ii in range(tstart, k):
        solsx = oalib.arraylist_t()
        oalib.extend_arraylist(sols0, adata, oaoptions, ii, solsx)
        if verbose >= 2:
            print(' ii %d: %d' % (ii, solsx.size()))
        sols0 = solsx
        nums.append(solsx.size())
        sys.stdout.flush()
    return solsx
Пример #6
0
def runExtend(N,
              k,
              t=3,
              l=2,
              verbose=1,
              initsols=None,
              nums=[],
              algorithm=None):
    """ Run extension algorithm and return arrays

    Arguments
    ---------
    N : integer
        number of rows
    k: integer
        number of columns
    t: integer
        strength of the arrays

    >>> r = runExtend(16, 5, 3, verbose=0)    
    """
    if verbose:
        print('runExtend: N=%d, k=%d, t=%d' % (N, k, t))
    if isinstance(l, list):  # types.ListType):
        ll = l
    else:
        ll = [l]
    ll = ll + [ll[-1]] * (k - len(ll))
    s = oalib.intVector(ll)
    adata = oalib.arraydata_t(s, N, t, k)
    al = oalib.array_link(adata.N, adata.strength, 1)
    al.create_root(adata)
    if initsols is None:
        sols0 = oalib.arraylist_t()
        sols0.append(al)
        tstart = t
    else:
        sols0 = initsols
        tstart = sols0[0].n_columns

    oaoptions = oalib.OAextend()
    if algorithm is None:
        oaoptions.setAlgorithmAuto(adata)
    else:
        oaoptions.setAlgorithm(algorithm, adata)
    solsx = sols0
    for ii in range(tstart, k):
        solsx = oalib.arraylist_t()
        oalib.extend_arraylist(sols0, adata, oaoptions, ii, solsx)
        if verbose >= 2:
            print(' ii %d: %d' % (ii, solsx.size()))
        sols0 = solsx
        nums.append(solsx.size())
        sys.stdout.flush()
    return solsx
Пример #7
0
def runExtend(N, k, t=3, l=2, verbose=1, initsols=None, nums=[], algorithm=None):
    """ Run extension algorithm and return arrays

    Args:
      N (int): number of rows
      k (int): number of columns to extend to
      t (int): strength of the arrays
      l (int): factors of the designs
      initsols (None or list): list of arrays to extend, None to start with root

    Returns:
        list: list of generated designs

    Example:
       >>> import oapackage
       >>> designs = oapackage.oahelper.runExtend(16, 5, 3, verbose=0)
    """
    if verbose:
        print('runExtend: N=%d, k=%d, t=%d' % (N, k, t))
    if isinstance(l, list):
        ll = l
    else:
        ll = [l]
    ll = ll + [ll[-1]] * (k - len(ll))
    s = oalib.intVector(ll)
    adata = oalib.arraydata_t(s, N, t, k)
    al = oalib.array_link(adata.N, adata.strength, 1)
    al.create_root(adata)
    if initsols is None:
        sols0 = oalib.arraylist_t()
        sols0.append(al)
        tstart = t
    else:
        sols0 = initsols
        tstart = sols0[0].n_columns

    oaoptions = oalib.OAextend()
    if algorithm is None:
        oaoptions.setAlgorithmAuto(adata)
    else:
        oaoptions.setAlgorithm(algorithm, adata)
    solsx = sols0
    for ii in range(tstart, k):
        solsx = oalib.arraylist_t()
        oalib.extend_arraylist(sols0, adata, oaoptions, ii, solsx)
        if verbose >= 2:
            print(' ii %d: %d' % (ii, solsx.size()))
        sols0 = solsx
        nums.append(solsx.size())
        sys.stdout.flush()
    return solsx
Пример #8
0
def selectArraysInFile(infile, outfile, idx, afmode=oalib.ATEXT, verbose=1, cache=1):
    """ Select arrays in a file by indices

    Args:
        infile (str): file with designs
        outfile (str): output  file with designs
        inx (list of indices)
    Returns:
        None

    """
    if not checkFiles(outfile, cache=cache):
        gidxint = oalib.intVector([int(x) for x in idx])
        sols = oalib.arraylist_t()
        oalib.selectArrays(infile, gidxint, sols, 0)
        af = oalib.arrayfile_t(infile, 1)
        _ = oalib.writearrayfile(outfile, sols, afmode, af.nrows, af.ncols)
        if verbose >= 2:
            print('selectArrays: write array file %s in mode %d' %
                  (outfile, afmode))
    else:
        if verbose >= 2:
            print('output file %s already exists' % outfile)