Example #1
0
def integer_mixed_cells(mixture, points, verbose=True):
    r"""
    Given a tuple of lifted support sets in *points*, computes all mixed cells
    in the regular subdivision defined by the integer lifting values
    given as the last coordinate of every point in the lifted supports.
    If *verbose*, then output is written to screen.
    Returns the mixed volume as the sum of the volumes of the cells.
    """
    from ast import literal_eval
    from phcpy.phcpy2c3 import py2c_intcelcon_set_type_of_mixture as setmix
    from phcpy.phcpy2c3 import py2c_intcelcon_type_of_mixture as getmix
    from phcpy.phcpy2c3 import py2c_intcelcon_initialize_supports as initsup
    from phcpy.phcpy2c3 import py2c_intcelcon_append_lifted_point as applpt
    from phcpy.phcpy2c3 import py2c_intcelcon_get_lifted_point as getlpt
    from phcpy.phcpy2c3 import py2c_intcelcon_length_of_supports as lensup
    from phcpy.phcpy2c3 import py2c_intcelcon_make_subdivision as makesub
    from phcpy.phcpy2c3 import py2c_intcelcon_number_of_cells as nbrcells
    from phcpy.phcpy2c3 import py2c_intcelcon_get_inner_normal as getnormal
    from phcpy.phcpy2c3 import py2c_intcelcon_mixed_volume as mixvol
    from phcpy.phcpy2c3 import py2c_intcelcon_write_mixed_cell_configuration
    setmix(len(mixture), str(mixture))
    if verbose:
        print('the type of mixture stored :', getmix())
    initsup(len(mixture))
    for k in range(len(points)):
        if verbose:
            print('points', k, points[k])
        for point in points[k]:
            if verbose:
                print('append lifted point :', point)
            applpt(len(point), k + 1, str(point))
    lenpts = literal_eval(lensup())
    if verbose:
        dim = len(points[0][0])
        print('lengths of supports :', lenpts)
        for i in range(len(lenpts)):
            print('lifted points in support', i, ':')
            for j in range(lenpts[k]):
                print(getlpt(dim, i + 1, j + 1))
    makesub()
    if verbose:
        py2c_intcelcon_write_mixed_cell_configuration()
    number = nbrcells()
    totmv = 0
    if verbose:
        dim = len(points[0][0])
        print('number of cells :', number)
        for k in range(number):
            print('cell', k + 1, 'has normal :', getnormal(dim, k + 1), end='')
            mv = mixvol(k + 1)
            print(' mixed volume :', mv)
            totmv = totmv + mv
    else:
        totmv = 0
        for k in range(number):
            totmv = totmv + mixvol(k + 1)
    return totmv
Example #2
0
def integer_mixed_cells(mixture, points, verbose=True):
    r"""
    Given a tuple of lifted support sets in *points*, computes all mixed cells
    in the regular subdivision defined by the integer lifting values
    given as the last coordinate of every point in the lifted supports.
    If *verbose*, then output is written to screen.
    Returns the mixed volume as the sum of the volumes of the cells.
    """
    from ast import literal_eval
    from phcpy.phcpy2c3 import py2c_intcelcon_set_type_of_mixture as setmix
    from phcpy.phcpy2c3 import py2c_intcelcon_type_of_mixture as getmix
    from phcpy.phcpy2c3 import py2c_intcelcon_initialize_supports as initsup
    from phcpy.phcpy2c3 import py2c_intcelcon_append_lifted_point as applpt
    from phcpy.phcpy2c3 import py2c_intcelcon_get_lifted_point as getlpt
    from phcpy.phcpy2c3 import py2c_intcelcon_length_of_supports as lensup
    from phcpy.phcpy2c3 import py2c_intcelcon_make_subdivision as makesub
    from phcpy.phcpy2c3 import py2c_intcelcon_number_of_cells as nbrcells
    from phcpy.phcpy2c3 import py2c_intcelcon_get_inner_normal as getnormal
    from phcpy.phcpy2c3 import py2c_intcelcon_mixed_volume as mixvol
    from phcpy.phcpy2c3 import py2c_intcelcon_write_mixed_cell_configuration
    setmix(len(mixture), str(mixture))
    if verbose:
        print('the type of mixture stored :', getmix())
    initsup(len(mixture))
    for k in range(len(points)):
        if verbose:
            print('points', k, points[k])
        for point in points[k]:
            if verbose:
                print('append lifted point :', point)
            applpt(len(point), k+1, str(point))
    lenpts = literal_eval(lensup())
    if verbose:
        dim = len(points[0][0])
        print('lengths of supports :', lenpts)
        for i in range(len(lenpts)):
            print('lifted points in support', i, ':')
            for j in range(lenpts[k]):
                print(getlpt(dim,i+1,j+1))
    makesub()
    if verbose:
        py2c_intcelcon_write_mixed_cell_configuration()
    number = nbrcells()
    totmv = 0
    if verbose:
        dim = len(points[0][0])
        print('number of cells :', number)
        for k in range(number):
            print('cell', k+1, 'has normal :', getnormal(dim, k+1), end='')
            mv = mixvol(k+1)
            print(' mixed volume :', mv)
            totmv = totmv + mv
    else:
        totmv = 0
        for k in range(number):
            totmv = totmv + mixvol(k+1)
    return totmv;
Example #3
0
def mixed_volume(mixture, points, checkin=True):
    r"""
    Returns the mixed volume of the tuple in *points*.
    Both *mixture* and *points* have the same length.
    The list *mixture* counts the number of times each support
    in *points* should be counted.
    For example, to compute the volume of a three dimensional polytope,
    the *mixture* is [3].  In general, the *mixture* determines the powers
    of the unknowns in the Minkowski polynomial of which the computed
    mixed volume is its coefficient.
    If checkin, then the mixture will be tested to match the length
    of each point in points.
    """
    from phcpy.phcpy2c3 import py2c_celcon_initialize_supports as init
    from phcpy.phcpy2c3 import py2c_celcon_set_type_of_mixture as setmix
    from phcpy.phcpy2c3 import py2c_celcon_append_lifted_point as applft
    from phcpy.phcpy2c3 import py2c_celcon_mixed_volume_of_supports as mixvol
    if checkin:
        if not check_mixture(mixture, points):
            print('incorrect type of mixture')
            return -1
    nbr = len(mixture)
    init(nbr)
    setmix(nbr, str(mixture))
    for k in range(nbr):
        for point in points[k]:
            lpt = list(point)
            lpt.append(0)
            applft(len(lpt), k + 1, str(lpt))
    return mixvol()
Example #4
0
def integer_mixed_cell(dim, nbr, idx, verbose=True):
    r"""
    Given are three integers and one boolean, respectively:

    *dim*: the number of coordinates in the inner normal,

    *nbr*: the number of distinct supports,

    *idx*: the index to the cell (starts at one, instead of at zero), and

    *verbose*: the verbose flag.

    Returns the extracted data for the mixed cell with index *idx*.
    If verbose, the data is written to screen.
    """
    from ast import literal_eval
    from phcpy.phcpy2c3 import py2c_intcelcon_get_inner_normal as getnormal
    from phcpy.phcpy2c3 import py2c_intcelcon_mixed_volume as mixvol
    from phcpy.phcpy2c3 import py2c_intcelcon_number_of_points_in_cell as npts
    from phcpy.phcpy2c3 import py2c_intcelcon_get_point_in_cell as getpoint
    normal = literal_eval(getnormal(dim, idx))
    mv = mixvol(idx)
    lenpts = literal_eval(npts(idx, nbr))
    if verbose:
        print('inner normal :', normal)
        print('mixed volume :', mv)
        print('number of points :', lenpts)
    supp = [[] for _ in range(nbr)]
    for i in range(nbr):  # scan the i-th support
        if verbose:
            print('points in support', i + 1, ':')
        for j in range(lenpts[i]):  # get j-th point in i-th support
            point = getpoint(dim, idx, i + 1, j + 1)
            if verbose:
                print(eval(point))
            supp[i].append(eval(point))
    return (normal, mv, tuple(supp))
Example #5
0
def integer_mixed_cell(dim, nbr, idx, verbose=True):
    r"""
    Given are three integers and one boolean, respectively:

    *dim*: the number of coordinates in the inner normal,

    *nbr*: the number of distinct supports,

    *idx*: the index to the cell (starts at one, instead of at zero), and

    *verbose*: the verbose flag.

    Returns the extracted data for the mixed cell with index *idx*.
    If verbose, the data is written to screen.
    """
    from ast import literal_eval
    from phcpy.phcpy2c3 import py2c_intcelcon_get_inner_normal as getnormal
    from phcpy.phcpy2c3 import py2c_intcelcon_mixed_volume as mixvol
    from phcpy.phcpy2c3 import py2c_intcelcon_number_of_points_in_cell as npts
    from phcpy.phcpy2c3 import py2c_intcelcon_get_point_in_cell as getpoint
    normal = literal_eval(getnormal(dim, idx))
    mv = mixvol(idx)
    lenpts = literal_eval(npts(idx, nbr))
    if verbose:
        print('inner normal :', normal)
        print('mixed volume :', mv)
        print('number of points :', lenpts)
    supp = [ [] for _ in range(nbr)]
    for i in range(nbr):  # scan the i-th support
        if verbose:
            print('points in support', i+1, ':')
        for j in range(lenpts[i]): # get j-th point in i-th support
            point = getpoint(dim, idx, i+1, j+1)
            if verbose:
                print(eval(point))
            supp[i].append(eval(point))
    return (normal, mv, tuple(supp))
Example #6
0
def mixed_volume(mixture, points, checkin=True):
    r"""
    Returns the mixed volume of the list of lists in *points*.
    Both *mixture* and *points* have the same length.
    The list *mixture* counts the number of times each support
    in *points* should be counted.
    For example, to compute the volume of a three dimensional polytope,
    the *mixture* is [3].  In general, the *mixture* determines the powers
    of the unknowns in the Minkowski polynomial of which the computed
    mixed volume is its coefficient.
    If checkin, then the mixture will be tested to match the length
    of each point in points.
    Examples:
    >>> q1 = [(1, 1), (1, 0), (0, 1), (0, 0)]
    >>> q2 = [(2, 2), (1, 0), (0, 1)]
    >>> mv([1, 1], [q1, q2])
    4
    >>> mv([2], [q1])
    2
    """
    from phcpy.phcpy2c3 import py2c_celcon_initialize_supports as init
    from phcpy.phcpy2c3 import py2c_celcon_set_type_of_mixture as setmix
    from phcpy.phcpy2c3 import py2c_celcon_append_lifted_point as applft
    from phcpy.phcpy2c3 import py2c_celcon_mixed_volume_of_supports as mixvol
    if checkin:
        if not check_mixture(mixture, points):
            print('incorrect type of mixture')
            return -1
    nbr = len(mixture)
    init(nbr)
    setmix(nbr, str(mixture))
    for k in range(nbr):
        for point in points[k]:
            lpt = list(point)
            lpt.append(0)
            applft(len(lpt), k+1, str(lpt))
    return mixvol()
Example #7
0
def mixed_volume(mixture, points):
    """
    Returns the mixed volume of the tuple in points.
    Both mixture and points have the same length.
    The list mixture counts the number of times each support
    in points should be counted.
    For example, to compute the volume of a three dimensional polytope,
    the mixture is [3].  In general, the mixture determines the powers
    of the unknowns in the Minkowski polynomial of which the computed
    mixed volume is its coefficient.
    """
    from phcpy.phcpy2c3 import py2c_celcon_initialize_supports as init
    from phcpy.phcpy2c3 import py2c_celcon_set_type_of_mixture as setmix
    from phcpy.phcpy2c3 import py2c_celcon_append_lifted_point as applft
    from phcpy.phcpy2c3 import py2c_celcon_mixed_volume_of_supports as mixvol
    nbr = len(mixture)
    init(nbr)
    setmix(nbr, str(mixture))
    for k in range(nbr):
        for point in points[k]:
            lpt = list(point)
            lpt.append(0)
            applft(len(lpt), k + 1, str(lpt))
    return mixvol()
Example #8
0
def mixed_volume(mixture, points):
    """
    Returns the mixed volume of the tuple in points.
    Both mixture and points have the same length.
    The list mixture counts the number of times each support
    in points should be counted.
    For example, to compute the volume of a three dimensional polytope,
    the mixture is [3].  In general, the mixture determines the powers
    of the unknowns in the Minkowski polynomial of which the computed
    mixed volume is its coefficient.
    """
    from phcpy.phcpy2c3 import py2c_celcon_initialize_supports as init
    from phcpy.phcpy2c3 import py2c_celcon_set_type_of_mixture as setmix
    from phcpy.phcpy2c3 import py2c_celcon_append_lifted_point as applft
    from phcpy.phcpy2c3 import py2c_celcon_mixed_volume_of_supports as mixvol
    nbr = len(mixture)
    init(nbr)
    setmix(nbr, str(mixture))
    for k in range(nbr):
        for point in points[k]:
            lpt = list(point)
            lpt.append(0)
            applft(len(lpt), k+1, str(lpt))
    return mixvol()