def cone_span_to_face(S, eliminate_redundancies=False): """ Returns the face matrix S^F of the span matrix S, that is, a matrix such that {x = S z, z >= 0} if and only if {S^F x <= 0}. """ V = hstack([zeros((S.shape[1], 1)), S.T]) # V-representation: first column is 0 for rays V_cdd = Matrix(V, number_type=NUMBER_TYPE) V_cdd.rep_type = RepType.GENERATOR P = Polyhedron(V_cdd) H_matrix = P.get_inequalities(); if(eliminate_redundancies): H_matrix.canonicalize(); H = array(H_matrix); if(H.shape[1]>1): b = H[:, 0] A = H[:, 1:] else: b, A = H[:, 0], zeros((H.shape[0],S.shape[0])); for i in xrange(H.shape[0]): if b[i] != 0: raise NotConeSpan(S) return -A
def face_of_span(S): """ Returns the face matrix S^F of the span matrix S, that is, a matrix such that {x = S z, z >= 0} if and only if {S^F x <= 0}. """ V = hstack([zeros((S.shape[1], 1)), S.T]) # V-representation: first column is 0 for rays V_cdd = Matrix(V, number_type="float") V_cdd.rep_type = RepType.GENERATOR P = Polyhedron(V_cdd) ineq = P.get_inequalities() H = array(ineq) if H.shape == (0,): # H = [] return H # b, A = H[:, 0], -H[:, 1:] # H matrix is [b, -A] A = [] for i in xrange(H.shape[0]): if H[i, 0] != 0: # b should be zero raise NotConeSpan(S) elif i not in ineq.lin_set: A.append(-H[i, 1:]) return array(A)
def cone_span_to_face(S, eliminate_redundancies=False): """ Returns the face matrix S^F of the span matrix S, that is, a matrix such that {x = S z, z >= 0} if and only if {S^F x <= 0}. """ V = hstack([ones((S.shape[1], 1)), S.T]) # V-representation: first column is 0 for rays V_cdd = Matrix(V, number_type=NUMBER_TYPE) V_cdd.rep_type = RepType.GENERATOR P = Polyhedron(V_cdd) H_matrix = P.get_inequalities() if (eliminate_redundancies): H_matrix.canonicalize() H = array(H_matrix) if (H.shape[1] > 1): b = H[:, 0] A = H[:, 1:] else: b, A = H[:, 0], zeros((H.shape[0], S.shape[0])) #~ for i in xrange(H.shape[0]): #~ if b[i] != 0: #~ raise NotConeSpan(S) return -A, b
def poly_span_to_face(S): """ Returns the face matrix S^F of the span matrix S, that is, a matrix such that {x = S z, z >= 0, sum(z)=1} if and only if {S^F x <= s}. """ V = hstack([ones((S.shape[1], 1)), S.T]) # V-representation: first column is 0 for rays, 1 for vertices V_cdd = Matrix(V, number_type=NUMBER_TYPE) V_cdd.rep_type = RepType.GENERATOR P = Polyhedron(V_cdd) H = array(P.get_inequalities()) # H-representation: A x + b >= 0 b, A = H[:, 0], H[:, 1:] return (-A, b)
def poly_span_to_face(S): """ Returns the face matrix S^F of the span matrix S, that is, a matrix such that {x = S z, z >= 0, sum(z)=1} if and only if {S^F x <= s}. """ V = hstack([ones((S.shape[1], 1)), S.T]) # V-representation: first column is 0 for rays, 1 for vertices V_cdd = Matrix(V, number_type=NUMBER_TYPE) V_cdd.rep_type = RepType.GENERATOR P = Polyhedron(V_cdd) H = array(P.get_inequalities()) # H-representation: A x + b >= 0 b, A = H[:, 0], H[:, 1:] return (-A,b)
def cone_span_to_face(S, eliminate_redundancies=False): """ Returns the face matrix S^F of the span matrix S, that is, a matrix such that {x = S z, z >= 0} if and only if {S^F x <= 0}. """ S = np.asarray(S).squeeze() V = hstack([zeros((S.shape[1], 1)), S.T]) # V-representation: first column is 0 for rays V_cdd = Matrix(V, number_type=NUMBER_TYPE) V_cdd.rep_type = RepType.GENERATOR P = Polyhedron(V_cdd) H_matrix = P.get_inequalities() if (eliminate_redundancies): try: H_matrix.canonicalize() except: print "RuntimeError: failed to canonicalize matrix" H = array(H_matrix) if (len(H.shape) < 2): # warnings.warn("[cone_span_to_face] H is a vector rather than a matrix. S:\n"+str(S)+"\nH:\n"+str(H)); # S += 1e-6*np.random.rand(S.shape[0], S.shape[1]); # V = hstack([zeros((S.shape[1], 1)), S.T]) # V_cdd = Matrix(V, number_type=NUMBER_TYPE) # V_cdd.rep_type = RepType.GENERATOR # P = Polyhedron(V_cdd) # H_matrix = P.get_inequalities(); # H = array(H_matrix); # if(len(H.shape)<2): raise ValueError( "[cone_span_to_face] Cddlib failed to convert cone span to face: H is a vector rather than a matrix. H: " + str(H)) if (H.shape[1] > 1): b = H[:, 0] A = H[:, 1:] else: b, A = H[:, 0], zeros((H.shape[0], S.shape[0])) for i in xrange(H.shape[0]): if b[i] != 0: raise NotConeSpan(S) return -A
def arbitrary_span_to_face(S, rv): """ Returns the face matrix S^F of the span matrix S, that is, a matrix such that {x = S z, z >= 0} if and only if {S^F x <= f}. The vector rv specifies whether the corresponding column in S is a vertex (1) or a ray (0). """ V = hstack([rv.reshape((S.shape[1], 1)), S.T]) # V-representation: first column is 0 for rays V_cdd = Matrix(V, number_type=NUMBER_TYPE) V_cdd.rep_type = RepType.GENERATOR P = Polyhedron(V_cdd) H = array(P.get_inequalities()) b, A = H[:, 0], H[:, 1:] return (-A, b)
def arbitrary_span_to_face(S, rv): """ Returns the face matrix S^F of the span matrix S, that is, a matrix such that {x = S z, z >= 0} if and only if {S^F x <= f}. The vector rv specifies whether the corresponding column in S is a vertex (1) or a ray (0). """ V = hstack([rv.reshape((S.shape[1], 1)), S.T]) # V-representation: first column is 0 for rays V_cdd = Matrix(V, number_type=NUMBER_TYPE) V_cdd.rep_type = RepType.GENERATOR P = Polyhedron(V_cdd) H = array(P.get_inequalities()) b, A = H[:, 0], H[:, 1:] return (-A,b)
def face_of_span(S): """ Returns the face matrix S^F of the span matrix S, that is, a matrix such that {x = S z, z >= 0} if and only if {S^F x <= 0}. """ V = hstack([zeros((S.shape[1], 1)), S.T]) # V-representation: first column is 0 for rays V_cdd = Matrix(V, number_type=NUMBER_TYPE) V_cdd.rep_type = RepType.GENERATOR P = Polyhedron(V_cdd) H = array(P.get_inequalities()) b, A = H[:, 0], H[:, 1:] for i in xrange(H.shape[0]): if b[i] != 0: raise NotConeSpan(S) return -A