Python 如何找到多面体/多面体内部的整数点(坐标)?
我正在使用Python,但我不介意更改语言。我从我的研究中得到的只是一种工具,根据包围它的平面方程,计算区域内(晶格)点的数量。其他工具用于优化多面体(线性规划)中的给定函数 单独寻找晶格点怎么样?例如,这类函数Python 如何找到多面体/多面体内部的整数点(坐标)?,python,ppl,polyhedra,diophantine,Python,Ppl,Polyhedra,Diophantine,我正在使用Python,但我不介意更改语言。我从我的研究中得到的只是一种工具,根据包围它的平面方程,计算区域内(晶格)点的数量。其他工具用于优化多面体(线性规划)中的给定函数 单独寻找晶格点怎么样?例如,这类函数 latticePoints( 'x < 5 & x > 0' ) = [ 1, 2, 3, 4] latticePoints('x0')=[1,2,3,4] 另外,我正在寻找在多变量场景中工作的东西(x、y、z等的约束) 我目前正在尝试使用解决这个问题。Math
latticePoints( 'x < 5 & x > 0' ) = [ 1, 2, 3, 4]
latticePoints('x<5&x>0')=[1,2,3,4]
另外,我正在寻找在多变量场景中工作的东西(x、y、z等的约束)
我目前正在尝试使用解决这个问题。Mathematica中有一个很好的答案: 点={x,y}/。List@ToRules@Reduce[x>=4y&&x使用Python包,可以按如下方式计算
d
维多面体中的积分点(此脚本基于我编写的测试:():
“”“如何计算多边形内具有整数坐标的所有点。”“”
将numpy作为np导入
导入polytope.polytope作为alg
def示例():
“”“演示积分计算。”“”
#凸多面体
顶点=np.数组([[0.5,1.5],[0.5,1.5])
外壳=alg.box2poly(顶点)
#`hull`是类`polytope.polytope.polytope`的实例,
#用于表示凸多面体
积分点=alg。枚举积分点(外壳)
印刷品(船体)
打印('包含整数:')
打印(积分)
#
#非凸多面体
顶点=np.数组([[0.0,0.0],[1.0,1.0],[2.0,1.0])
hull_1=alg.qhull(顶点)#顶点中顶点的凸包`
hull_2=alg.box2poly([[1.0,2.0],[1.0,2.0])
非凸=赫尔_1.并集(赫尔_2)
#'nonconvex'是'polytope.polytope.Region'类的实例,
#表示任何多面体,包括非凸多面体,
#在这种情况下,也可以用
#`polytope.polytope.Region([hull_1,hull_2])`
积分点=alg.枚举积分点(非凸)
print('是以下多面体的并集的多面体:')
打印(非凸)
打印('包含整数:')
打印(积分)
#
#三维多面体
顶点=np.数组([
[0.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 0.0, 1.0]])
外壳=alg.qhull(顶点)
积分点=alg。枚举积分点(外壳)
印刷品(船体)
打印('包含整数:')
打印(积分)
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
示例()
目前,上述Python代码与开发版本的polytope
配合使用,可以使用以下软件包安装程序安装:
pip安装git+git://github.com/tulip-control/polytope.git
或者通过克隆GitHub存储库并从克隆的存储库安装:
git克隆git@github.com:郁金香控制/polytope
cd多面体
pip安装。
上面的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.]]
单个多面体
[[ 1. 0.] | [[ 1.5]
[0. 1 ] x我认为C++ Boost <代码>多边形< /Co>库有这样的功能。