コード例 #1
0
ファイル: Zpolyhedron.c プロジェクト: intersense/pluto-gw
/*
 * Return the Z-polyhedron intersection of the Z-polyhedra 'A' and 'B'. 
 * Note: If Z1 = L1 (intersect) P1 and Z2 = L2 (intersect) P2, then 
 *     Z1 (intersect) Z2 = (L1 (intersect) L2) (intersect) (P1 (intersect) P2) 
 */
static ZPolyhedron *ZPolyhedronIntersection(ZPolyhedron *A, ZPolyhedron *B) {
  
  ZPolyhedron *Result = NULL;
  Lattice *LInter;
  Polyhedron *PInter, *ImageA, *ImageB, *PreImage;
  
#ifdef DOMDEBUG
  FILE *fp;
  fp = fopen("_debug","a");
  fprintf(fp,"\nEntered ZPOLYHEDRONINTERSECTION\n");
  fclose(fp);
#endif  
  
  LInter = LatticeIntersection(A->Lat,B->Lat);
  if(isEmptyLattice(LInter) == True) {
    ZPolyhedron_Free (Result);
    Matrix_Free(LInter);
    return (EmptyZPolyhedron(A->Lat->NbRows-1));
  }  
  ImageA = DomainImage(A->P,A->Lat,MAXNOOFRAYS);
  ImageB = DomainImage(B->P,B->Lat,MAXNOOFRAYS);
  PInter = DomainIntersection(ImageA,ImageB,MAXNOOFRAYS); 
  if (emptyQ(PInter))
    Result = EmptyZPolyhedron(LInter->NbRows-1);
  else { 
    PreImage = DomainPreimage(PInter,(Matrix *)LInter,MAXNOOFRAYS);
    Result = ZPolyhedron_Alloc(LInter, PreImage);    
    Domain_Free (PreImage);
  }  
  Matrix_Free(LInter);
  Domain_Free(PInter); 
  Domain_Free(ImageA);
  Domain_Free(ImageB);  
  return Result ;
} /* ZPolyhedronIntersection */ 
コード例 #2
0
int main(int argc, char **argv)
{
    Matrix *M;
    Polyhedron *C;
    struct barvinok_options *options = barvinok_options_new_with_defaults();

    argc = barvinok_options_parse(options, argc, argv, ISL_ARG_ALL);

    M = Matrix_Read();
    C = Constraints2Polyhedron(M, options->MaxRays);
    Matrix_Free(M);

    M = Cone_Integer_Hull(C, NULL, 0, options);

    Polyhedron_Free(C);

    Matrix_Print(stdout, P_VALUE_FMT, M);
    Matrix_Free(M);

    if (options->print_stats)
	barvinok_stats_print(options->stats, stdout);

    barvinok_options_free(options);
    return 0;
}
コード例 #3
0
ファイル: findv.c プロジェクト: intersense/pluto-gw
int main() {

  Matrix *a, *b;
  Polyhedron *A, *B;
  Param_Polyhedron *PA;
  const char **param_name;
  
  a = Matrix_Read();
  A = Constraints2Polyhedron(a,200);
  Matrix_Free(a);
  
  b = Matrix_Read();
  B = Constraints2Polyhedron(b,200);
  Matrix_Free(b);
  
  /* Read the name of the parameters */
  param_name = Read_ParamNames(stdin,B->Dimension);  
  PA = Polyhedron2Param_Vertices(A,B,500);  
  Param_Vertices_Print(stdout,PA->V,param_name);
  Domain_Free(A);
  Domain_Free(B);
  Param_Polyhedron_Free( PA );
  free(param_name);
  return 0;
} /* main */
コード例 #4
0
ファイル: hilbert.c プロジェクト: erickmartins/ftszentropy
static Matrix *Polyhedron2standard_form(Polyhedron *P, Matrix **T)
{
    int i, j;
    int rows;
    unsigned dim = P->Dimension;
    Matrix *M2;
    Matrix *H, *U;
    Matrix M;

    assert(P->NbEq == 0);
    Polyhedron_Remove_Positivity_Constraint(P);
    for (i = 0; i < P->NbConstraints; ++i)
	assert(value_zero_p(P->Constraint[i][1+dim]));

    Polyhedron_Matrix_View(P, &M, P->NbConstraints);
    H = standard_constraints(&M, 0, &rows, &U);
    *T = homogenize(U);
    Matrix_Free(U);

    M2 = Matrix_Alloc(rows, 2+dim+rows);

    for (i = dim; i < H->NbRows; ++i) {
	Vector_Copy(H->p[i], M2->p[i-dim]+1, dim);
	value_set_si(M2->p[i-dim][1+i], -1);
    }
    for (i = 0, j = H->NbRows-dim; i < dim; ++i) {
	if (First_Non_Zero(H->p[i], i) == -1)
	    continue;
	Vector_Oppose(H->p[i], M2->p[j]+1, dim);
	value_set_si(M2->p[j][1+j+dim], 1);
	++j;
    }
    Matrix_Free(H);
    return M2;
}
コード例 #5
0
/** 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 */
コード例 #6
0
/** extracts the equalities holding on the parameters only, try to introduce
    them back and compare the two polyhedra.
    Reads a polyhedron and a context.
 */
int test_Polyhedron_Remove_parm_eqs(Matrix * A, Matrix * B) {
  int isOk = 1;
  Matrix * M, *C;
  Polyhedron *Pm, *Pc, *Pcp, *Peqs, *Pint, *Pint1;
  unsigned int * elimParms;
  printf("----- test_Polyhedron_Remove_parm_eqs() -----\n");

  M = Matrix_Copy(A);
  C = Matrix_Copy(B);

   /* compute the combined polyhedron */
  Pm = Constraints2Polyhedron(M, maxRays);
  Pc = Constraints2Polyhedron(C, maxRays);
  Pcp = align_context(Pc, Pm->Dimension, maxRays);
  Polyhedron_Free(Pc);
  Pint1 = DomainIntersection(Pm, Pcp, maxRays);
  Polyhedron_Free(Pm);
  Polyhedron_Free(Pcp);
  Matrix_Free(M);
  Matrix_Free(C);

  M = Matrix_Copy(A);
  C = Matrix_Copy(B);
  /* extract the parm-equalities, expressed in the combined space */
  Pm = Constraints2Polyhedron(M, maxRays);
  Pc = Constraints2Polyhedron(C, maxRays);
  Matrix_Free(M);
  Matrix_Free(C);
  Peqs = Polyhedron_Remove_parm_eqs(&Pm, &Pc, 1, &elimParms, 200);
  
  /* compute the supposedly-same polyhedron, using the extracted equalities */
  Pcp = align_context(Pc, Pm->Dimension, maxRays);
  Polyhedron_Free(Pc);
  Pc = DomainIntersection(Pm, Pcp, maxRays);
  Polyhedron_Free(Pm);
  Polyhedron_Free(Pcp);
 
  Pint = DomainIntersection(Pc, Peqs, maxRays);
  Polyhedron_Free(Pc);
  Polyhedron_Free(Peqs);

  /* test their equality */
  if (!PolyhedronIncludes(Pint, Pint1)) {
    isOk = 0;
  }
  else {
    if (!PolyhedronIncludes(Pint1, Pint)) {
      isOk = 0;
    }
  }
  Polyhedron_Free(Pint1);
  Polyhedron_Free(Pint);
  return isOk;
} /* test_Polyhedron_remove_parm_eqs() */
コード例 #7
0
/** 
 * Computes the intersection of two linear lattices, whose base vectors are
 * respectively represented in A and B.
 * If I and/or Lb is set to NULL, then the matrix is allocated. 
 * Else, the matrix is assumed to be allocated already. 
 * I and Lb are rk x rk, where rk is the rank of A (or B).
 * @param A the full-row rank matrix whose column-vectors are the basis for the
 * first linear lattice.
 * @param B the matrix whose column-vectors are the basis for the second linear
 * lattice.
 * @param Lb the matrix such that B.Lb = I, where I is the intersection.
 * @return their intersection.
 */
static void linearInter(Matrix * A, Matrix * B, Matrix ** I, Matrix **Lb) {
  Matrix * AB=NULL;
  int rk = A->NbRows;
  int a = A->NbColumns;
  int b = B->NbColumns;
  int i,j, z=0;

  Matrix * H, *U, *Q;
  /* ensure that the spanning vectors are in the same space */
  assert(B->NbRows==rk);
  /* 1- build the matrix 
   * (A 0 1)
   * (0 B 1)
   */
  AB = Matrix_Alloc(2*rk, a+b+rk);
  Matrix_copySubMatrix(A, 0, 0, rk, a, AB, 0, 0);
  Matrix_copySubMatrix(B, 0, 0, rk, b, AB, rk, a);
  for (i=0; i< rk; i++) {
      value_set_si(AB->p[i][a+b+i], 1);
      value_set_si(AB->p[i+rk][a+b+i], 1);
  }
  if (dbgCompParm) {
    show_matrix(AB);
  }

  /* 2- Compute its left Hermite normal form. AB.U = [H 0] */
  left_hermite(AB, &H, &Q, &U);
  Matrix_Free(AB);
  Matrix_Free(Q);
  /* count the number of non-zero colums in H */ 
  for (z=H->NbColumns-1; value_zero_p(H->p[H->NbRows-1][z]); z--);
  z++;
  if (dbgCompParm) {
    show_matrix(H);
    printf("z=%d\n", z);
  }
  Matrix_Free(H);
  /* if you split U in 9 submatrices, you have: 
   * A.U_13 = -U_33
   * B.U_23 = -U_33,
   * where the nb of cols of U_{*3} equals the nb of zero-cols of H
   * U_33 is a (the smallest) combination of col-vectors of A and B at the same
   * time: their intersection.
  */
  Matrix_subMatrix(U, a+b, z, U->NbColumns, U->NbColumns, I);
  Matrix_subMatrix(U, a, z, a+b, U->NbColumns, Lb);
  if (dbgCompParm) {
    show_matrix(U);
  }
  Matrix_Free(U);
} /* linearInter */
コード例 #8
0
/** 
 * Computes the validity lattice of a set of equalities. I.e., the lattice
 * induced on the last <tt>b</tt> variables by the equalities involving the
 * first <tt>a</tt> integer existential variables.  The submatrix of Eqs that
 * concerns only the existential variables (so the first a columns) is assumed
 * to be full-row rank.
 * @param Eqs the equalities
 * @param a the number of existential integer variables, placed as first
 * variables
 * @param vl the (returned) validity lattice, in homogeneous form. It is
 * allocated if initially set to null, or reused if already allocated.
 */
void Equalities_validityLattice(Matrix * Eqs, int a, Matrix** vl) {
  unsigned int b = Eqs->NbColumns-2-a;
  unsigned int r = Eqs->NbRows;
  Matrix * A=NULL, * B=NULL, *I = NULL, *Lb=NULL, *sol=NULL;
  Matrix *H, *U, *Q;
  unsigned int i;

  if (dbgCompParm) {
    printf("Computing validity lattice induced by the %d first variables of:"
	   ,a);
    show_matrix(Eqs);
  }
  if (b==0) {
    ensureMatrix((*vl), 1, 1);
    value_set_si((*vl)->p[0][0], 1);
    return;
  }

  /* 1- check that there is an integer solution to the equalities */
  /* OPT: could change integerSolution's profile to allocate or not*/
  Equalities_integerSolution(Eqs, &sol);
  /* if there is no integer solution, there is no validity lattice */
  if (sol==NULL) {
    if ((*vl)!=NULL) Matrix_Free(*vl);
    return;
  }
  Matrix_subMatrix(Eqs, 0, 1, r, 1+a, &A);
  Matrix_subMatrix(Eqs, 0, 1+a, r, 1+a+b, &B);
  linearInter(A, B, &I, &Lb);
  Matrix_Free(A);
  Matrix_Free(B);
  Matrix_Free(I);
  if (dbgCompParm) {
    show_matrix(Lb);
  }
  
  /* 2- The linear part of the validity lattice is the left HNF of Lb */
  left_hermite(Lb, &H, &Q, &U);
  Matrix_Free(Lb);
  Matrix_Free(Q);
  Matrix_Free(U);

  /* 3- build the validity lattice */
  ensureMatrix((*vl), b+1, b+1);
  Matrix_copySubMatrix(H, 0, 0, b, b, (*vl), 0,0);
  Matrix_Free(H);
  for (i=0; i< b; i++) {
    value_assign((*vl)->p[i][b], sol->p[0][a+i]);
  }
  Matrix_Free(sol);
  Vector_Set((*vl)->p[b],0, b);
  value_set_si((*vl)->p[b][b], 1);
  
} /* validityLattice */
コード例 #9
0
static Polyhedron *partition2polyhedron(Matrix *A,
					struct barvinok_options *options)
{
	int i;
	unsigned nvar, nparam;
	Matrix *M;
	Polyhedron *P;

	nvar = A->NbColumns;
	nparam = A->NbRows;

	M = Matrix_Alloc(nvar + nparam, 1 + nvar + nparam + 1);
	assert(M);

	for (i = 0; i < nparam; ++i) {
		Vector_Copy(A->p[i], M->p[i] + 1, nvar);
		value_set_si(M->p[i][1 + nvar + i], -1);
	}
	for (i = 0; i < nvar; ++i) {
		value_set_si(M->p[nparam + i][0], 1);
		value_set_si(M->p[nparam + i][1 + i], 1);
	}

	P = Constraints2Polyhedron(M, options->MaxRays);
	Matrix_Free(M);

	return P;
}
コード例 #10
0
int main() {
  
	int np, i;

	Matrix *a;
	Polyhedron *A, *tmp, *DD;

	scanf( "%d", &np );

	A = NULL;
	for( i=0 ; i<np ; i++ )
	{
		a = Matrix_Read();
		tmp = Constraints2Polyhedron(a,WS);
		Matrix_Free(a);
		tmp ->next = A;
		A = tmp;
	}


	DD = Disjoint_Domain( A, 1, WS );

	AffContraintes(DD);

	return 0;
}
コード例 #11
0
ファイル: constraints_polylib.c プロジェクト: tajkhan/pluto
/*
 * Image: if cst is a list of constraints, just its first element's image
 * is taken.
 */
PlutoConstraints *pluto_constraints_image(const PlutoConstraints *cst, const PlutoMatrix *func)
{
    // IF_DEBUG(printf("pluto const image: domain\n"););
    // IF_DEBUG(pluto_constraints_print(stdout, cst););
    // IF_DEBUG(printf("pluto const image: func\n"););
    // IF_DEBUG(pluto_matrix_print(stdout, func););
    assert(func->ncols == cst->ncols);

    PlutoConstraints *imagecst;

    Polyhedron *pol = pluto_constraints_to_polylib(cst);
    Matrix *polymat = pluto_matrix_to_polylib(func);

    // Polyhedron_Print(stdout, "%4d", pol);
    Polyhedron *image = Polyhedron_Image(pol, polymat, 2*cst->nrows);

    // Polyhedron_Print(stdout, "%4d ",  image);
    imagecst = polylib_to_pluto_constraints(image);

    Matrix_Free(polymat);
    Domain_Free(pol);
    Polyhedron_Free(image);

    // IF_DEBUG(printf("pluto const image is\n"););
    // IF_DEBUG(pluto_constraints_print(stdout, imagecst););

    return imagecst;
}
コード例 #12
0
ファイル: Material.c プロジェクト: Waqar144/NGen
///
//Frees a material
//Does not free the associated texture!!
//
//Parameters:
//	mat: A pointer to the material to free
void Material_Free(Material* mat)
{
	Matrix_Free(mat->colorMatrix);
	Vector_Free(mat->tile);

	free(mat);
}
コード例 #13
0
ファイル: Zpolyhedron.c プロジェクト: intersense/pluto-gw
/*
 * Given a Z-polyhedron 'A' in which the Lattice is not integral, return the
 * Z-polyhedron which contains all the integral points in the input lattice.
 */
ZPolyhedron *IntegraliseLattice(ZPolyhedron *A) {
 
  ZPolyhedron *Result;
  Lattice *M = NULL, *Id;
  Polyhedron *Im = NULL, *Preim = NULL;

#ifdef DOMDEBUG
  FILE *fp;
  fp = fopen("_debug","a");
  fprintf(fp,"\nEntered INTEGRALISELATTICE\n");
  fclose(fp);
#endif
  
  Im = DomainImage(A->P,A->Lat,MAXNOOFRAYS);
  Id = Identity(A->Lat->NbRows);
  M = LatticeImage(Id, A->Lat);
  if (isEmptyLattice(M))
    Result = EmptyZPolyhedron(A->Lat->NbRows-1);
  else {
    Preim = DomainPreimage(Im,M,MAXNOOFRAYS);
    Result = ZPolyhedron_Alloc(M,Preim);
  }  
  Matrix_Free(M);
  Domain_Free(Im);
  Domain_Free(Preim);  
  return Result;
} /* IntegraliseLattice */ 
コード例 #14
0
int main(int argc, char ** argv) {
  int isOk = 0;
  Matrix * A, * B;
  if (argc>1) {
    printf("Warning: No arguments taken into account: testing"
	   "remove_parm_eqs().\n");
  }

  A = Matrix_Read();
  B = Matrix_Read();
  TEST( test_Constraints_Remove_parm_eqs(A, B) )
  TEST( test_Polyhedron_Remove_parm_eqs(A, B) )
  TEST( test_Constraints_fullDimensionize(A, B, 4) )
  Matrix_Free(A);
  Matrix_Free(B);
  return (1-isOk);
}
コード例 #15
0
void Read_Network_Weights()
{
    MATRIX_DOUBLE *MDIH;
    MATRIX_DOUBLE *MDHO;
/*  char *wts_input_file;   */

/*
 *   Clear_Screen;
 *   Move_To(10,5);
 *   wts_input_file=
 *   Get_String("Enter input-hidden weights file to read");
 *   MDIH = (MATRIX_DOUBLE *) Matrix_Read(wts_input_file);
 */

    MDIH = (MATRIX_DOUBLE *) Matrix_Read("ih_wts.dat");

    if(MDIH->element_size != sizeof(double)
            || MDIH->rows != HNODES || MDIH->cols != INODES ) {
        printf("\nWeights read from ih_wts.dat are inconsistant\n");
        exit(1);
    }
    IH_Wts = Matrix_Allocate_Double(HNODES, INODES);
    ASSIGN_MAT(MDIH->ptr,IH_Wts,HNODES,INODES,double,double);
    Matrix_Free((MATRIX_DOUBLE *) MDIH);
   
/*
 *   Clear_Screen;
 *   Move_To(10,5);
 *   wts_input_file=
 *   Get_String("Enter hidden-ouput weights file to read");
 *   MDHO = (MATRIX_DOUBLE *) Matrix_Read(wts_input_file);
 */

    MDHO = (MATRIX_DOUBLE *) Matrix_Read("ho_wts.dat");

    if(MDHO->element_size != sizeof(double)
            || MDHO->rows != ONODES || MDHO->cols != HNODES ) {
        printf("\nWeights read from ho_wts.dat are inconsistant\n");
        exit(1);
    }
    HO_Wts = Matrix_Allocate_Double(ONODES, HNODES);
    ASSIGN_MAT(MDHO->ptr,HO_Wts,ONODES,HNODES,double,double);
    Matrix_Free((MATRIX_DOUBLE *) MDHO);
    return;
}
コード例 #16
0
ファイル: Zpolyhedron.c プロジェクト: intersense/pluto-gw
/*
 * Free the memory used by the Z-polyhderon 'Zpol' 
 */
static void ZPolyhedron_Free (ZPolyhedron *Zpol) {
  
  if (Zpol == NULL)
    return;
  Matrix_Free((Matrix *) Zpol->Lat);
  Domain_Free(Zpol->P);
  free(Zpol);
  return;
} /* ZPolyhderon_Free */
コード例 #17
0
void Read_Node_Thresholds()
{
    MATRIX_DOUBLE *MDO;
    MATRIX_DOUBLE *MDH;
/*  char *thr_input_file;   */

/*
 *   Clear_Screen;
 *   Move_To(10,5);
 *   thr_input_file=
 *   Get_String("Enter output nodes threshold file to read");
 *   MDO = (MATRIX_DOUBLE *) Matrix_Read(thr_input_file);
 */

    MDO = (MATRIX_DOUBLE *) Matrix_Read("o_thr.dat");

    if(MDO->element_size != sizeof(double)
            || MDO->rows != 1 || MDO->cols != ONODES ) {
        printf("\nThresholds read from o_thr.dat are inconsistant\n");
        exit(1);
    }
    Onode_Thr = Vector_Allocate_Double(ONODES);
    ASSIGN(MDO->ptr[0],Onode_Thr,ONODES,double,double);
    Matrix_Free((MATRIX_DOUBLE *) MDO);

/*
 *   Clear_Screen;
 *   Move_To(10,5);
 *   thr_input_file=Get_String("Enter hidden-ouput weight file");
 *   MDH = (MATRIX_DOUBLE *) Matrix_Read(thr_input_file);
 */

    MDH = (MATRIX_DOUBLE *) Matrix_Read("h_thr.dat");

    if(MDH->element_size != sizeof(double)
            || MDH->rows != 1 || MDH->cols != HNODES ) {
        printf("\nThresholds read from h_thr.dat are inconsistant\n");
        exit(1);
    }
    Hnode_Thr = Vector_Allocate_Double(HNODES);
    ASSIGN(MDH->ptr[0],Hnode_Thr,HNODES,double,double);
    Matrix_Free((MATRIX_DOUBLE *) MDH);
    return;
}
コード例 #18
0
/** 
 * Given a full-row-rank nxm matrix M made of m row-vectors), computes the
 * basis K (made of n-m column-vectors) of the integer kernel of the rows of M
 * so we have: M.K = 0
*/
Matrix * int_ker(Matrix * M) {
  Matrix *U, *Q, *H, *H2, *K=NULL;
  int i, j, rk;

  if (dbgCompParm)
    show_matrix(M);
  /* eliminate redundant rows : UM = H*/
  right_hermite(M, &H, &Q, &U);
  for (rk=H->NbRows-1; (rk>=0) && Vector_IsZero(H->p[rk], H->NbColumns); rk--);
  rk++;
  if (dbgCompParmMore) {
    printf("rank = %d\n", rk);
  }
    
  /* there is a non-null kernel if and only if the dimension m of 
     the space spanned by the rows 
     is inferior to the number n of variables */
  if (M->NbColumns <= rk) {
    Matrix_Free(H);
    Matrix_Free(Q);
    Matrix_Free(U);
    K = Matrix_Alloc(M->NbColumns, 0);
    return K;
  }
  Matrix_Free(U); 
  Matrix_Free(Q);
  /* fool left_hermite  by giving NbRows =rank of M*/
  H->NbRows=rk;
  /* computes MU = [H 0] */
  left_hermite(H, &H2, &Q, &U); 
   if (dbgCompParmMore) {
    printf("-- Int. Kernel -- \n");
    show_matrix(M);
    printf(" = \n");
    show_matrix(H2);
    show_matrix(U); 
  }
  H->NbRows==M->NbRows;
  Matrix_Free(H);
  /* the Integer Kernel is made of the last n-rk columns of U */
  Matrix_subMatrix(U, 0, rk, U->NbRows, U->NbColumns, &K);

  /* clean up */
  Matrix_Free(H2);
  Matrix_Free(U);
  Matrix_Free(Q);
  return K;
} /* int_ker */
コード例 #19
0
ファイル: constraints_polylib.c プロジェクト: tajkhan/pluto
PlutoMatrix *pluto_matrix_inverse(PlutoMatrix *mat)
{
    assert(mat->nrows == mat->ncols);

    PlutoMatrix *inv;

    int dim = mat->nrows;

    Matrix *pinv = Matrix_Alloc(dim, dim);
    Matrix *pmat = pluto_matrix_to_polylib(mat);

    Matrix_Inverse(pmat, pinv);
    
    inv = polylib_matrix_to_pluto(pinv);

    Matrix_Free(pmat);
    Matrix_Free(pinv);

    return inv;
}
コード例 #20
0
ファイル: example.c プロジェクト: intersense/pluto-gw
int main () {
  
  Matrix *a, *b; 
  Polyhedron *P;
  ZPolyhedron *Z1, *Z2, *Z3, *Z4;
  
  a = Matrix_Read ();
  b = Matrix_Read ();
  P = Constraints2Polyhedron (b, 200);
  Z1 = ZPolyhedron_Alloc (a, P);
  
  Matrix_Free (a);
  Matrix_Free (b);
  Domain_Free (P);
  
  a = Matrix_Read ();
  b = Matrix_Read ();
  P = Constraints2Polyhedron (b, 200);
  Z2 = ZPolyhedron_Alloc (a, P);
  
  Matrix_Free (a); 
  Matrix_Free (b); 
  Domain_Free (P);
  
  Z3 = ZDomainIntersection (Z1, Z2);
  printf ("\nZ3 = Z1 and Z2");
  ZDomainPrint(stdout,P_VALUE_FMT, Z3);

  a = Matrix_Read ();
  Z4 = ZDomainImage (Z1, a);
  printf ("\nZ4 = image (Z1 by a)");
  ZDomainPrint (stdout,P_VALUE_FMT, Z4);

  Matrix_Free (a);
  ZDomain_Free (Z1);
  ZDomain_Free (Z2);
  ZDomain_Free (Z3);
  ZDomain_Free (Z4);
  
  return 0;
} /* main */
コード例 #21
0
/**
 * Given a matrix that defines a full-dimensional affine lattice, returns the 
 * affine sub-lattice spanned in the k first dimensions.
 * Useful for instance when you only look for the parameters' validity lattice.
 * @param lat the original full-dimensional lattice
 * @param subLat the sublattice
 */
void Lattice_extractSubLattice(Matrix * lat, unsigned int k, Matrix ** subLat) {
  Matrix * H, *Q, *U, *linLat = NULL;
  unsigned int i;
  dbgStart(Lattice_extractSubLattice);
  /* if the dimension is already good, just copy the initial lattice */
  if (k==lat->NbRows-1) {
    if (*subLat==NULL) {
      (*subLat) = Matrix_Copy(lat);
    }
    else {
      Matrix_copySubMatrix(lat, 0, 0, lat->NbRows, lat->NbColumns, (*subLat), 0, 0);
    }
    return;
  }
  assert(k<lat->NbRows-1);
  /* 1- Make the linear part of the lattice triangular to eliminate terms from 
     other dimensions */
  Matrix_subMatrix(lat, 0, 0, lat->NbRows, lat->NbColumns-1, &linLat);
  /* OPT: any integer column-vector elimination is ok indeed. */
  /* OPT: could test if the lattice is already in triangular form. */
  left_hermite(linLat, &H, &Q, &U);
  if (dbgCompParmMore) {
    show_matrix(H);
  }
  Matrix_Free(Q);
  Matrix_Free(U);
  Matrix_Free(linLat);
  /* if not allocated yet, allocate it */
  if (*subLat==NULL) {
    (*subLat) = Matrix_Alloc(k+1, k+1);
  }
  Matrix_copySubMatrix(H, 0, 0, k, k, (*subLat), 0, 0);
  Matrix_Free(H);
  Matrix_copySubMatrix(lat, 0, lat->NbColumns-1, k, 1, (*subLat), 0, k);
  for (i=0; i<k; i++) {
    value_set_si((*subLat)->p[k][i], 0);
  }
  value_set_si((*subLat)->p[k][k], 1);
  dbgEnd(Lattice_extractSubLattice);
} /* Lattice_extractSubLattice */
コード例 #22
0
ファイル: Zpolyhedron.c プロジェクト: intersense/pluto-gw
/*
 * Return the image of the Z-polyhedron 'ZPol' under the invertible, affine, 
 * rational transformation function 'Func'. The matrix representing the funct-
 * ion must be non-singular and the number of rows of the function must be 
 * equal to the number of rows in the matrix representing the lattice of 'ZPol'
 * Algorithm: 
 *         1)  Let ZPol = L (intersect) Q
 *         2)  L1 = LatticeImage(L,F)
 *         3)  Q1 = DomainImage(Q,F)
 *         4)  Z1 = L1(Inverse(L1)*Q1)
 *         5)  Return Z1
 */
static ZPolyhedron *ZPolyhedronImage(ZPolyhedron *ZPol,Matrix *Func) {
 
  ZPolyhedron *Result = NULL ;
  Matrix *LatIm ;
  Polyhedron *Pol, *PolImage ; 
  
#ifdef DOMDEBUG
  FILE *fp;
  fp = fopen("_debug", "a");
  fprintf(fp,"\nEntered ZPOLYHEDRONIMAGE\n");
  fclose(fp);
#endif
  
  if ((Func->NbRows != ZPol->Lat->NbRows) || (Func->NbColumns != ZPol->Lat->NbColumns)) {
    fprintf (stderr, "In ZPolImage - The Function, is not compatible with the ZPolyhedron\n");
    return NULL;
  }
  LatIm = LatticeImage(ZPol->Lat,Func);
  if (isEmptyLattice(LatIm)) {
    Matrix_Free(LatIm);
    return NULL;
  }
  Pol = DomainImage(ZPol->P,ZPol->Lat,MAXNOOFRAYS);
  PolImage = DomainImage(Pol,Func,MAXNOOFRAYS);
  Domain_Free(Pol);
  if(emptyQ(PolImage)) {
    Matrix_Free (LatIm);
    Domain_Free (PolImage);
    return NULL;
  } 
  Pol = DomainPreimage(PolImage,LatIm,MAXNOOFRAYS);
  Result = ZPolyhedron_Alloc(LatIm,Pol);
  Domain_Free(Pol);
  Domain_Free(PolImage);
  Matrix_Free(LatIm);
  return Result;  
} /* ZPolyhedronImage */ 
コード例 #23
0
ファイル: lcp_sfun.c プロジェクト: YangShuailing/MATLAB_diva
/* free memory at the end of simulation for work vectors */
static void mdlTerminate(SimStruct *S)
{
    int_T i;
 	for ( i=0; i<5; i++ ) {
		if ( ssGetPWork(S)[i] != NULL ) {
			free( ssGetPWork(S)[i] );
		}
	}
 
	Matrix_Free(ssGetPWork(S)[5]);
	free(ssGetPWork(S)[5]);
    
   	Basis_Free(ssGetPWork(S)[6]);
	free(ssGetPWork(S)[6]);
}
コード例 #24
0
ファイル: lcp_matrix.c プロジェクト: ssketch/motorControl
/* Free basis */
void Basis_Free(PT_Basis pB)
{
	Index_Free(pB->pW);
	Index_Free(pB->pZ);
	Index_Free(pB->pWc);
	Index_Free(pB->pP);

	Matrix_Free(pB->pG);
	Matrix_Free(pB->pX);
	Matrix_Free(pB->pF);
	Matrix_Free(pB->pLX);
	Matrix_Free(pB->pUX);
	Matrix_Free(pB->pUt);
	
	if (pB->pW!=NULL)
		free(pB->pW);
	if (pB->pZ!=NULL)
		free(pB->pZ);
	if (pB->pWc!=NULL)
		free(pB->pWc);
	if (pB->pP!=NULL)
		free(pB->pP);
	if (pB->pG!=NULL)
		free(pB->pG);
	if (pB->pX!=NULL)
		free(pB->pX);
	if (pB->pF!=NULL)
		free(pB->pF);
	if (pB->pLX!=NULL)
		free(pB->pLX);
	if (pB->pUX!=NULL)
		free(pB->pUX);
	if (pB->pUt!=NULL)
		free(pB->pUt);

	if (pB->y!=NULL)
		free(pB->y);
	if (pB->z!=NULL)
		free(pB->z);
	if (pB->w!=NULL)
		free(pB->w);
	if (pB->v!=NULL)
		free(pB->v);
	if (pB->r!=NULL)
		free(pB->r);
	if (pB->p!=NULL)
		free(pB->p);
	if (pB->s!=NULL)
		free(pB->s);
	
}
コード例 #25
0
/** 
 * Given an integer matrix B with m rows and integer m-vectors C and d,
 * computes the basis of the integer solutions to (BN+C) mod d = 0 (1).
 * This is an affine lattice (G): (N 1)^T= G(N' 1)^T, forall N' in Z^b.
 * If there is no solution, returns NULL.
 * @param B B, a (m x b) matrix
 * @param C C, a (m x 1) integer matrix
 * @param d d, a (1 x m) integer matrix
 * @param imb the affine (b+1)x(b+1) basis of solutions, in the homogeneous
 * form. Allocated if initially set to NULL, reused if not.
*/
void Equalities_intModBasis(Matrix * B, Matrix * C, Matrix * d, Matrix ** imb) {
  int b = B->NbColumns;
  /* FIXME: treat the case d=0 as a regular equality B_kN+C_k = 0: */
  /* OPT: could keep only equalities for which d>1 */
  int nbEqs = B->NbRows;
  unsigned int i;

  /* 1- buid the problem DI+BN+C = 0 */
  Matrix * eqs = Matrix_Alloc(nbEqs, nbEqs+b+1);
  for (i=0; i< nbEqs; i++) {
    value_assign(eqs->p[i][i], d->p[0][i]);
  }
  Matrix_copySubMatrix(B, 0, 0, nbEqs, b, eqs, 0, nbEqs);
  Matrix_copySubMatrix(C, 0, 0, nbEqs, 1, eqs, 0, nbEqs+b);

  /* 2- the solution is the validity lattice of the equalities */
  Equalities_validityLattice(eqs, nbEqs, imb);
  Matrix_Free(eqs);
} /* Equalities_intModBasis */
コード例 #26
0
ファイル: constraints_polylib.c プロジェクト: tajkhan/pluto
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;
}
コード例 #27
0
void count_new(Value* cb, int lanes[NLANES][L],int filaments,int noconsts){
	//clock_t t1 = clock();
	Polyhedron *A;
	int i,j;
    Matrix *M;
    //printf("inside count we have the following lanes for %d filaments and %d noconsts:\n",filaments,noconsts);
    //dump_lanes(lanes);
    M=Matrix_Alloc(noconsts,filaments+2);
    //lock_t t2 = clock();
    int** constraints;
    constraints= malloc(noconsts*sizeof(int *));
    //clock_t t3 = clock();
	//printf("%lu\n",(filaments+2)*(noconsts));
	for (i=0;i<noconsts;i++){
		constraints[i]=(int*)malloc(sizeof(int)*(filaments+2));
		for(j=0;j<filaments+2;j++){
			constraints[i][j]=0;
			//printf("%d %d %d\n",i,j,constraints[i][j]);
		}
	}
	//clock_t t4 = clock();
	//printf("from count: fils %d noconsts %d\n",filaments,noconsts);
    gen_constraints(constraints,lanes,filaments,noconsts);
    //clock_t t5 = clock();
	struct barvinok_options *options = barvinok_options_new_with_defaults();
	Matrix_Init(M,constraints);
	//clock_t t6 = clock();
	A=Constraints2Polyhedron(M,options->MaxRays);
	//clock_t t7 = clock();
	barvinok_count_with_options(A, cb, options);
	//clock_t t8 = clock();
	//printf("timings at count: t2=%f, t3=%f, t4=%f, t5=%f, t6=%f, t7=%f, t8=%f\n",(double)(t2-t1)/CLOCKS_PER_SEC,(double)(t3-t1)/CLOCKS_PER_SEC,(double)(t4-t1)/CLOCKS_PER_SEC,(double)(t5-t1)/CLOCKS_PER_SEC,(double)(t6-t1)/CLOCKS_PER_SEC,(double)(t7-t1)/CLOCKS_PER_SEC,(double)(t8-t1)/CLOCKS_PER_SEC);
	Polyhedron_Free(A);
    barvinok_options_free(options);
    Matrix_Free(M);
    for (i=0;i<noconsts;i++){
		free(constraints[i]);
		}
	free(constraints);
   	

	}	
コード例 #28
0
ファイル: Zpolyhedron.c プロジェクト: intersense/pluto-gw
/*
 * Return the empty Z-polyhedron of dimension 'dimension' 
 */
ZPolyhedron *EmptyZPolyhedron(int dimension) {

  ZPolyhedron *Zpol;
  Lattice *E ;
  Polyhedron *P; 
  
#ifdef DOMDEBUG
  FILE *fp;
  fp = fopen ("_debug", "a");
  fprintf (fp, "\nEntered EMPTYZPOLYHEDRON\n");
  fclose (fp);
#endif

  E = EmptyLattice(dimension+1);
  P = Empty_Polyhedron(dimension);
  Zpol = ZPolyhedron_Alloc(E,P);
  Matrix_Free((Matrix *) E);
  Domain_Free(P);
  return Zpol;
} /* EmptyZPolyhedron */
コード例 #29
0
ファイル: constraints_polylib.c プロジェクト: tajkhan/pluto
/* Converts to a polylib polyhedron */
Polyhedron *pluto_constraints_to_polylib(const PlutoConstraints *cst)
{
    Polyhedron *pol;
    PlutoMatrix *mat;
    Matrix *polymat;

    mat = pluto_constraints_to_matrix(cst);

    polymat = pluto_matrix_to_polylib(mat);

    pol = Constraints2Polyhedron(polymat, 50);

    Matrix_Free(polymat);
    pluto_matrix_free(mat);

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

    return pol;
}
コード例 #30
0
int main(int argc, char **argv)
{
	int nchamber;
	unsigned nparam;
	Matrix *A;
	Polyhedron *P, *C;
	Param_Polyhedron *PP;
	Param_Domain *PD;
	struct barvinok_options *options = barvinok_options_new_with_defaults();

	argc = barvinok_options_parse(options, argc, argv, ISL_ARG_ALL);

	A = Matrix_Read();
	assert(A);

	nparam = A->NbRows;
	C = Universe_Polyhedron(nparam);
	P = partition2polyhedron(A, options);
	Matrix_Free(A);

	PP = Polyhedron2Param_Polyhedron(P, C, options);
	Polyhedron_Free(P);
	Polyhedron_Free(C);

	nchamber = 0;
	for (PD = PP->D; PD; PD = PD->next)
		nchamber++;

	printf("%d\n", nchamber);
	for (PD = PP->D; PD; PD = PD->next) {
		printf("\n");
		Polyhedron_PrintConstraints(stdout, P_VALUE_FMT, PD->Domain);
	}
	Param_Polyhedron_Free(PP);

	barvinok_options_free(options);
	return 0;
}