Example #1
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 #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 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 #4
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 #5
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 #6
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()