/** Removes equalities involving only parameters, but starting from a
 * Polyhedron and its context.
 * @param P the polyhedron
 * @param C P's context
 * @param renderSpace: 0 for the parameter space, =1 for the combined space.
 * @maxRays Polylib's usual <i>workspace</i>.
 */
Polyhedron * Polyhedron_Remove_parm_eqs(Polyhedron ** P, Polyhedron ** C, 
					int renderSpace, 
					unsigned int ** elimParms, 
					int maxRays) {
  Matrix * Eqs;
  Polyhedron * Peqs;
  Matrix * M = Polyhedron2Constraints((*P));
  Matrix * Ct = Polyhedron2Constraints((*C));

  /* if the Minkowski representation is not computed yet, do not compute it in
     Constraints2Polyhedron */
  if (F_ISSET((*P), POL_VALID | POL_INEQUALITIES) && 
      (F_ISSET((*C), POL_VALID | POL_INEQUALITIES))) {
    FL_INIT(maxRays, POL_NO_DUAL);
  }
    
  Eqs = Constraints_Remove_parm_eqs(&M, &Ct, renderSpace, elimParms);
  Peqs = Constraints2Polyhedron(Eqs, maxRays);
  Matrix_Free(Eqs);

  /* particular case: no equality involving only parms is found */
  if (Eqs->NbRows==0) {
    Matrix_Free(M);
    Matrix_Free(Ct);
    return Peqs;
  }
  Polyhedron_Free(*P);
  Polyhedron_Free(*C);
  (*P) = Constraints2Polyhedron(M, maxRays);
  (*C) = Constraints2Polyhedron(Ct, maxRays);
  Matrix_Free(M);
  Matrix_Free(Ct);
  return Peqs;
} /* Polyhedron_Remove_parm_eqs */
static isl_stat add_vertex(__isl_take isl_vertex *vertex, void *user)
{
	Param_Vertices ***next_V = (Param_Vertices ***) user;
	Param_Vertices *V;
	Polyhedron *D;
	isl_basic_set *dom;
	isl_multi_aff *expr;
	isl_ctx *ctx;

	ctx = isl_vertex_get_ctx(vertex);

	dom = isl_vertex_get_domain(vertex);
	D = isl_basic_set_to_polylib(dom);
	isl_basic_set_free(dom);

	expr = isl_vertex_get_expr(vertex);

	V = isl_alloc_type(ctx, Param_Vertices);
	V->Vertex = isl_multi_aff_to_polylib(expr);
	V->Domain = Polyhedron2Constraints(D);
	V->Facets = NULL;
	V->next = NULL;

	Polyhedron_Free(D);
	isl_multi_aff_free(expr);

	**next_V = V;
	*next_V = &V->next;

	isl_vertex_free(vertex);

	return isl_stat_ok;
}
Exemple #3
0
PlutoConstraints *polylib_to_pluto_constraints(Polyhedron *pol)
{
    PlutoConstraints *cst;

    // printf("Poly\n");
    // Polyhedron_Print(stdout, "%4d", pol);
    Matrix *polymat = Polyhedron2Constraints(pol);
     //printf("constraints\n");
     //Matrix_Print(stdout, "%4d", polymat);

    cst = polylib_matrix_to_pluto_constraints(polymat);
    Matrix_Free(polymat);

    if (pol->next != NULL) {
        cst->next = polylib_to_pluto_constraints(pol->next);
    }

    return cst;
}
Param_Polyhedron *ISL_P2PP(Polyhedron *P, Polyhedron *C,
			  struct barvinok_options *options)
{
	int i, j;
	isl_ctx *ctx = isl_ctx_alloc();
	isl_space *dim;
	isl_basic_set *bset, *context;
	isl_vertices *vertices;
	unsigned nparam = C->Dimension;
	unsigned nvar = P->Dimension - nparam;
	Param_Polyhedron *PP = isl_calloc_type(ctx, Param_Polyhedron);
	Param_Vertices **next_V;
	struct bv_add_chamber_data data;

	dim = isl_space_set_alloc(ctx, nparam, nvar);
	bset = isl_basic_set_new_from_polylib(P, dim);
	dim = isl_space_set_alloc(ctx, nparam, 0);
	context = isl_basic_set_new_from_polylib(C, dim);

	bset = isl_basic_set_intersect(bset, context);

	vertices = isl_basic_set_compute_vertices(bset);
	isl_basic_set_free(bset);

	PP->Rays = NULL;
	PP->nbV = isl_vertices_get_n_vertices(vertices);
	PP->Constraints = Polyhedron2Constraints(P);

	next_V = &PP->V;
	isl_vertices_foreach_vertex(vertices, &add_vertex, &next_V);

	data.next_D = &PP->D;
	data.vertex_len = (PP->nbV + INT_BITS - 1)/INT_BITS;
	isl_vertices_foreach_cell(vertices, &add_chamber, &data);

	isl_vertices_free(vertices);

	isl_ctx_free(ctx);

	return PP;
}
Exemple #5
0
int main() { 
  
  Matrix *a, *b, *t;
  Polyhedron *A, *B, *C, *D;
  
  printf("Polyhedral Library Test\n\n");
  
  /* read in a matrix containing your equations */
  /* for example, run this program and type in these five  lines:
     4 4
     1 0 1 -1
     1 -1 0 6
     1 0 -1 7
     1 1 0 -2
     This is a matrix for the following inequalities
     1 = inequality,  0x +  1y -1 >=0  -->	y >= 1
     1 = inequality, -1x +  0y +6 >=0  -->	x <= 6
     1 = inequality,  0x + -1y +7 >=0  -->	y <= 7
     1 = inequality,  1x +  0y -2 >=0  -->	x >= 2
     If the first number is a 0 instead of a 1, then that constraint
     is an 'equality' instead of an 'inequality'.
  */
  a = Matrix_Read();
  
  /* read in a second matrix containing a second set of constraints:
     for example :
     4 4
     1 1 0 -1
     1 -1 0 3
     1 0 -1 5
     1 0 1 -2
  */
  b = Matrix_Read();

  /* Convert the constraints to a Polyhedron.
     This operation 1. Computes the dual ray/vertice form of the
     system, and 2. Eliminates redundant constraints and reduces
     them to a minimal form.
  */
  A = Constraints2Polyhedron(a, 200);
  B = Constraints2Polyhedron(b, 200);

  /* the 200 is the size of the working space (in terms of number
     of rays) that is allocated temporarily
     -- you can enlarge or reduce it as needed */
  
  /* There is likewise a rays to polyhedron procedure */
  
  /* Since you are done with the matrices a and b, be a good citizen
     and clean up your garbage */
  Matrix_Free(a);
  Matrix_Free(b);
  
  /* If you want the the reduced set of equations back, you can
     either learn to read the polyhedron structure (not hard,
     look in "types.h"...
     or you can get the matrix back in the same format it started
     in... */
  a = Polyhedron2Constraints(A);
  b = Polyhedron2Constraints(B);

  /* Take a look at them if you want */
  printf("\na =");
  Matrix_Print(stdout,P_VALUE_FMT,a);
  printf("\nb =");
  Matrix_Print(stdout,P_VALUE_FMT,b);

  Matrix_Free(a);
  Matrix_Free(b);
  
  /* To intersect the two systems, use the polyhedron formats... */
  C = DomainIntersection(A, B, 200);
  
  /* Again, the 200 is the size of the working space */
  
  /* This time, lets look a the polyhedron itself... */
  printf("\nC = A and B =");
  Polyhedron_Print(stdout,P_VALUE_FMT,C);
  
  /* 
   * The operations DomainUnion, DomainDifference, and DomainConvex
   * are also available 
   */
  
  /* 
   * Read in a third matrix containing a transformation matrix,
   * this one swaps the indices (x,y --> y,x):
   * 3 3
   * 0 1 0
   * 1 0 0
   * 0 0 1
   */
  
  
  t = Matrix_Read();
  
  /* Take the preimage (transform the equations) of the domain C to
     get D.  Are you catching on to this 200 thing yet ??? */
  
  D = Polyhedron_Preimage(C, t, 200);
  
  /* cleanup please */
  Matrix_Free(t);
  
  printf("\nD = transformed C =");
  Polyhedron_Print(stdout,P_VALUE_FMT,D);
  Domain_Free(D);
  
  /* in a similar way, Polyhedron_Image(dom, mat, 200), takes the image
     of dom under matrix mat  (transforms the vertices/rays) */
  
  /* The function PolyhedronIncludes(Pol1, Pol2) returns 1 if Pol1
     includes (covers) Pol2, and a 0 otherwise */
  
  if (PolyhedronIncludes(A,C))
    printf("\nWe expected A to cover C since C = A intersect B\n");
  if (!PolyhedronIncludes(C,B))
    printf("and C does not cover B...\n");
  
  /* Final note:  some functions are defined for Domains, others
   * for Polyhedrons.  A domain is simply a list of polyhedrons.
   * Every polyhedron structure has a "next" pointer used to 
   * make a list of polyhedrons...  For instance, the union of
   * two disjoint polyhedra is a domain consisting of two polyhedra.
   * If you want the convex domain... you have to call 
   * DomainConvex(Pol1, 200) explicity.   
   * Note that includes does not work on domains, only on simple
   * polyhedrons...
   * Thats the end of the demo...  write me if you have questions.
   * And remember to clean up... 
   */
  
  Domain_Free(A);
  Domain_Free(B);
  Domain_Free(C);
  
  return 0;
}