python中的多面体和多面体操作
pypoman的Python项目详细描述
这个库对convex polyhedra这样的 作为polytope projection,double description(之间的转换 半空间和顶点表示),计算Chebyshev center, 等
有关详细信息,请参见完整的API documentation。
示例
顶点计数
我们可以计算半空间中描述的多面体的顶点列表 由A * x <= b:
表示importnumpyimportpypomanA=numpy.array([[-1,0,0,0,0,0,0,0,0,0,0,0],[0,-1,0,0,0,0,0,0,0,0,0,0],[0,0,-1,0,0,0,0,0,0,0,0,0],[0,0,0,-1,0,0,0,0,0,0,0,0],[0,0,0,0,-1,0,0,0,0,0,0,0],[0,0,0,0,0,-1,0,0,0,0,0,0],[0,0,0,0,0,0,-1,0,0,0,0,0],[0,0,0,0,0,0,0,-1,0,0,0,0],[0,0,0,0,0,0,0,0,-1,0,0,0],[0,0,0,0,0,0,0,0,0,-1,0,0],[0,0,0,0,0,0,0,0,0,0,-1,0],[0,0,0,0,0,0,0,0,0,0,0,-1],[1,1,1,0,0,0,0,0,0,0,0,0],[0,0,0,1,1,1,0,0,0,0,0,0],[0,0,0,0,0,0,1,1,1,0,0,0],[0,0,0,0,0,0,0,0,0,1,1,1],[1,0,0,1,0,0,1,0,0,1,0,0],[0,1,0,0,1,0,0,1,0,0,1,0],[0,0,1,0,0,1,0,0,1,0,0,1]])b=numpy.array([0,0,0,0,0,0,0,0,0,0,0,0,2,1,2,2,1,2,3])vertices=pypoman.compute_polytope_vertices(A,b)
多面体投影
让我们在x = [x_1 ... x_n]上投射一个n维多面体到它的 前两个坐标proj(x) = [x_1 x_2]:
importpypomanfromnumpyimportarray,eye,ones,vstack,zerosn=10# dimension of the original polytopep=2# dimension of the projected polytope# Original polytope:# - inequality constraints: \forall i, |x_i| <= 1# - equality constraint: sum_i x_i = 0A=vstack([+eye(n),-eye(n)])b=ones(2*n)C=ones(n).reshape((1,n))d=array([0])ineq=(A,b)# A * x <= beq=(C,d)# C * x == d# Projection is proj(x) = [x_0 x_1]E=zeros((p,n))E[0,0]=1.E[1,1]=1.f=zeros(p)proj=(E,f)# proj(x) = E * x + fvertices=pypoman.project_polytope(proj,ineq,eq,method='bretl')if__name__=="__main__":# plot projected polytopeimportpylabpylab.ion()pylab.figure()pypoman.plot_polygon(vertices)