예제 #1
0
## another triangle
V = numpy.array([[0, 0], [0, 1], [1, 0]], float)

## Tetrahegron
V = numpy.array([[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0]], float)

## our routine
hull = scipy.spatial.ConvexHull(V)

b = numpy.zeros((len(hull.simplices[:, 0]), len(hull.points[0, :])))

for i in range(0, len(hull.simplices[:, 0])):
    b[i] = numpy.mean(hull.points[hull.simplices[i, :], :], axis=0)

hull.points[hull.simplices[0, :], :]
polyOperation.verticesToConstraint(hull.points[hull.simplices[0, :], :])
polyOperation.PolygonObj(optimTestFun.rosen, None, None,
                         hull.points[hull.simplices[0, :], :])

polyObj = polyOperation.PolygonObj(optimTestFun.rosen, None, None, V)

## TODO: Currently facing with a rank deficiency problem where the face of a polygon is
## actually a hyperplane

lb = numpy.array([-2., -2.], float)
ub = numpy.array([2., 2.], float)
A, b = polyOperation.addBoxToInequalityLBUB(lb, ub)

V, dualHull, G, h, x0 = polyOperation.constraintToVertices(A,
                                                           b,
                                                           full_output=True)
예제 #2
0
plt.show()

## testing inequality <=> verticies operations

V, hull, A, b, x0 = polyOperation.constraintToVertices(G[0:5, :], h[0:5], full_output=True)

points = hull.points
plt.plot(points[:, 0], points[:, 1], "o")
plt.plot(x[0], x[1], "ro")
for simplex in hull.simplices:
    plt.plot(points[simplex, 0], points[simplex, 1], "k-")

plt.show()


ATest, bTest = polyOperation.verticesToConstraint(V)

polyOperation.constraintToVertices(ATest, bTest)

polyOperation.findAnalyticCenter(ATest, bTest)
polyOperation.findAnalyticCenter(G[0:5, :], h[0:5])

hull.simplices
hull.points

##  splitting

newV = V[hull.simplices[0, :], :]
newV = numpy.append(newV, numpy.reshape(numpy.array(x0), (1, 2)), axis=0)

ATest, bTest = polyOperation.verticesToConstraint(newV)
예제 #3
0
## testing inequality <=> verticies operations

V, hull, A, b, x0 = polyOperation.constraintToVertices(G[0:5, :],
                                                       h[0:5],
                                                       full_output=True)

points = hull.points
plt.plot(points[:, 0], points[:, 1], 'o')
plt.plot(x[0], x[1], 'ro')
for simplex in hull.simplices:
    plt.plot(points[simplex, 0], points[simplex, 1], 'k-')

plt.show()

ATest, bTest = polyOperation.verticesToConstraint(V)

polyOperation.constraintToVertices(ATest, bTest)

polyOperation.findAnalyticCenter(ATest, bTest)
polyOperation.findAnalyticCenter(G[0:5, :], h[0:5])

hull.simplices
hull.points

##  splitting

newV = V[hull.simplices[0, :], :]
newV = numpy.append(newV, numpy.reshape(numpy.array(x0), (1, 2)), axis=0)

ATest, bTest = polyOperation.verticesToConstraint(newV)
예제 #4
0
V = numpy.array([[0,0],[0,1],[1,0]],float)

## Tetrahegron
V = numpy.array([[0,0,0],[0,0,1],[0,1,0],[1,0,0]],float)

## our routine
hull = scipy.spatial.ConvexHull(V)

b = numpy.zeros((len(hull.simplices[:,0]),len(hull.points[0,:])))

for i in range(0,len(hull.simplices[:,0])):
    b[i] = numpy.mean(hull.points[hull.simplices[i,:],:],axis=0)


hull.points[hull.simplices[0,:],:]
polyOperation.verticesToConstraint(hull.points[hull.simplices[0,:],:])
polyOperation.PolygonObj(optimTestFun.rosen,None,None,hull.points[hull.simplices[0,:],:])

polyObj = polyOperation.PolygonObj(optimTestFun.rosen,None,None,V)

## TODO: Currently facing with a rank deficiency problem where the face of a polygon is 
## actually a hyperplane


lb = numpy.array([-2.,-2.],float)
ub = numpy.array([2.,2.],float)
A,b = polyOperation.addBoxToInequalityLBUB(lb,ub)

V, dualHull, G, h, x0 = polyOperation.constraintToVertices(A,b,full_output=True)

V = numpy.array([[0,0],[0,1],[1,0]],float)