【问题标题】:How to find integer points (coordinates) inside a polytope/polyhedra?如何在多面体/多面体中找到整数点(坐标)?
【发布时间】:2018-06-26 19:42:39
【问题描述】:

我正在使用 Python,但我不介意更改语言。我从研究中得到的只是计算区域内的(晶格)点数的工具,给出了包围它的平面的方程。其他工具用于优化多面体内的给定函数(线性规划)。

单独找到格点怎么样?例如,一种函数

latticePoints( 'x < 5 & x > 0' ) = [ 1, 2, 3, 4]

另外,我正在寻找可以在多变量场景中工作的东西(x、y、z、...的约束)。

我目前正在尝试使用ppl 解决此问题。

【问题讨论】:

标签: python ppl polyhedra diophantine


【解决方案1】:

在 Mathematica here 中有一个很好的答案:

点 = {x, y} /。 List@ToRules@ Reduce[x >= 4 y && x



【讨论】:

    【解决方案2】:

    使用 Python 包 polytoped 维多面体内的积分点可以按如下方式计算(此脚本基于我编写的测试:(polytope_test.py lines 415--455):

    """How to compute all points with integer coordinates inside a polytope."""
    import numpy as np
    import polytope.polytope as alg
    
    
    def example():
        """Demonstrate the integral points computation."""
        # convex polytope
        vertices = np.array([[0.5, 1.5], [0.5, 1.5]])
        hull = alg.box2poly(vertices)
            # `hull` is an instance of the class `polytope.polytope.Polytope`,
            # which is for representing convex polytopes
        integral_points = alg.enumerate_integral_points(hull)
        print(hull)
        print('contains the integral points:')
        print(integral_points)
        #
        # nonconvex polytope
        vertices = np.array([[0.0, 0.0], [1.0, 1.0], [2.0, 1.0]])
        hull_1 = alg.qhull(vertices)  # convex hull of vertices in `vertices`
        hull_2 = alg.box2poly([[1.0, 2.0], [1.0, 2.0]])
        nonconvex = hull_1.union(hull_2)
            # `nonconvex` is an instance of the class `polytope.polytope.Region`,
            # which is for representing any polytope, including nonconvex ones,
            # and in this case can also be constructed with
            # `polytope.polytope.Region([hull_1, hull_2])`
        integral_points = alg.enumerate_integral_points(nonconvex)
        print('The polytope that is the union of the following polytopes:')
        print(nonconvex)
        print('contains the integral points:')
        print(integral_points)
        #
        # 3-dimensional polytope
        vertices = np.array([
            [0.0, 0.0, 0.0],
            [1.0, 0.0, 0.0],
            [0.0, 1.0, 0.0],
            [0.0, 0.0, 1.0]])
        hull = alg.qhull(vertices)
        integral_points = alg.enumerate_integral_points(hull)
        print(hull)
        print('contains the integral points:')
        print(integral_points)
    
    
    if __name__ == '__main__':
        example()
    

    目前,上述Python代码适用于polytope的开发版本,可以使用包安装程序pip进行安装:

    pip install git+git://github.com/tulip-control/polytope.git
    

    或通过克隆 GitHub 存储库,并从克隆的存储库安装:

    git clone git@github.com:tulip-control/polytope
    cd polytope
    pip install .
    

    上面的 Python 脚本输出:

    Single polytope
      [[ 1.  0.] |    [[ 1.5]
       [ 0.  1.] x <=  [ 1.5]
       [-1. -0.] |     [-0.5]
       [-0. -1.]]|     [-0.5]]
    
    contains the integral points:
    [[1.]
     [1.]]
    The polytope that is the union of the following polytopes:
         Polytope number 1:
         Single polytope
              [[-0.70711  0.70711] |    [[0.]
               [ 0.       1.     ] x <=  [1.]
               [ 0.44721 -0.89443]]|     [0.]]
    
         Polytope number 2:
         Single polytope
              [[ 1.  0.] |    [[ 2.]
              [ 0.  1.] x <=  [ 2.]
              [-1. -0.] |     [-1.]
              [-0. -1.]]|     [-1.]]
    
    
    
    contains the integral points:
    [[0. 1. 2. 1. 2.]
     [0. 1. 1. 2. 2.]]
    Single polytope
      [[ 0.      -1.      -0.     ] |    [[0.     ]
       [-1.      -0.      -0.     ] x <=  [0.     ]
       [ 0.       0.      -1.     ] |     [0.     ]
       [ 0.57735  0.57735  0.57735]]|     [0.57735]]
    
    contains the integral points:
    [[0. 0. 1. 0.]
     [0. 0. 0. 1.]
     [0. 1. 0. 0.]]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-04
      • 1970-01-01
      • 2010-12-22
      • 1970-01-01
      • 2017-12-04
      • 2015-07-30
      • 1970-01-01
      相关资源
      最近更新 更多