Пример #1
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
Пример #2
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
Пример #3
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
Пример #4
0
def extendSingleArray(A, adata, t=3, verbose=1):
    """ Extend a single array """
    oaoptions = oalib.OAextend()
    sols0 = oalib.arraylist_t()
    solsx = oalib.arraylist_t()
    sols0.push_back(A)
    #N = A.n_rows
    k = A.n_columns
    n = oalib.extend_arraylist(sols0, adata, oaoptions, k, solsx)
    sys.stdout.flush()
    return solsx
Пример #5
0
def extendSingleArray(A, adata, t=3, verbose=1):
    """ Extend a single orthogonal array """
    oaoptions = oalib.OAextend()
    oaoptions.setAlgorithmAuto(adata)
    sols0 = oalib.arraylist_t()
    solsx = oalib.arraylist_t()
    sols0.push_back(A)
    k = A.n_columns
    n = oalib.extend_arraylist(sols0, adata, oaoptions, k, solsx)
    assert(n >= len(solsx))
    sys.stdout.flush()
    return solsx
Пример #6
0
def extendSingleArray(A, adata, t=3, verbose=1):
    """ Extend a single orthogonal array """
    oaoptions = oalib.OAextend()
    oaoptions.setAlgorithmAuto(adata)
    sols0 = oalib.arraylist_t()
    solsx = oalib.arraylist_t()
    sols0.push_back(A)
    k = A.n_columns
    n = oalib.extend_arraylist(sols0, adata, oaoptions, k, solsx)
    assert (n >= len(solsx))
    sys.stdout.flush()
    return solsx
Пример #7
0
def miscunittest(verbose=1):
    """ Perform some unit testing, return True if succesfull """
    if verbose:
        print('oapackage: unittest: oalib version %s' % oalib.version())
    al = oalib.array_link()
    ii = 0
    al = oalib.exampleArray(ii, 0)

    arrayclass = oalib.arraydata_t(2, 16, 2, 6)  # fine
    alist = [arrayclass.create_root()]
    r = oalib.extend_arraylist(alist, arrayclass)
    if len(r) != 3:
        raise Exception('extension generation for %s failed' % (arrayclass, ))

    if not isinstance(al.getarray(), np.ndarray):
        print(
            'oapackage: unittest: error: array interface not working properly')
    else:
        if not al[2, 0] == al.getarray()[2, 0]:
            print(
                'oapackage: unittest: error: array interface not working properly'
            )

    arrayclass = oalib.arraylink2arraydata(al)

    if verbose >= 2:
        print('unittest: calculate efficiencies')
    Deff = al.Defficiency()
    aa = oalib.Aefficiencies(al)
    assert (aa[0] == 1.0)
    assert (aa[1] == 1.0)
    assert (aa[2] == 1.0)

    if verbose >= 2:
        print('## oapackage test: example array %d: Deff %.3f' % (ii, Deff))

    # DOP reduction
    if verbose >= 2:
        print('unittest: test delete-one-factor GWLP reduction')
    al = oalib.exampleArray(5, verbose)
    al2 = al.randomperm()

    alr = al.reduceDOP()
    al2r = al2.reduceDOP()
    if not alr == al2r:
        print('error: DOP reduced arrays unequal!: %d' % (alr == al2r))
        print('alr')
        alr.showarraycompact()
        print('al2r')
        al2r.showarraycompact()
        return False

    transformation = oalib.reductionDOP(al)
    check = transformation.apply(al) == al.reduceDOP()
    if not check:
        print('error: DOP reduction transformation is invalid')

    # test graphtools
    if verbose >= 2:
        print('unittest: test graphtools')
    from oapackage.graphtools import oa2graph
    arrayclass = oalib.arraylink2arraydata(al)
    _ = oa2graph(al, arrayclass)

    test_numpy_interface()
    test_nauty()

    return True
adata.show()

print('-- Create root element --')
al = adata.create_root()
al.show()
al.showarray()

# Extend
print('-- Extend arrays --')

print('Extend to 3 columns')
newsols = oalib.extend_array(al, adata, oaoptions)
print(newsols)

print('Extend to 4 columns')
newsols2 = oalib.extend_arraylist(newsols, adata, oaoptions)
print(newsols2)

print('-- Analysing properties of arrays --')
for ii in range(0, 10):
    al = newsols2[ii]
    print('array %d: generalized word length pattern: %s' %
          (ii, str(al.GWLP())))
    print('          D-efficiency: %.3f' % ((al.Defficiency())))

al = oalib.exampleArray()
al.showarray()
print('D-efficiency %f, rank %d' % (al.Defficiency(), al.rank()))

#%% Write al array to disk
al = oalib.exampleArray()