如何在多面体/多面体中找到整数点(坐标)?

时间:2018-01-17 20:21:00

标签: python ppl polyhedra diophantine

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

如何单独找到格点?例如,种类的功能

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

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

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

2 个答案:

答案 0 :(得分:1)

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

  

points = {x,y} /。 List @ ToRules @ Reduce [x&gt; = 4 y&amp;&amp; x <= 4 y + 3   &安培;&安培; 0&lt; x&lt; 63&amp;&amp; 0&lt; y&lt; 15,{x,y},整数]

<小时/> LatticePlot

答案 1 :(得分:1)

使用 Python 包 polytope,可以按如下方式计算 d 维多胞体内的积分点(此脚本基于我编写的测试:(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.]]