コード例 #1
0
ファイル: cddmex.c プロジェクト: zhihan/checkmate
/* hull 
  Compute convex hull of a set of points
*/
void
hull(int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[])
{
    dd_PolyhedraPtr P;
    dd_ErrorType err;
    dd_MatrixPtr H,V;
    dd_SetFamilyPtr GI,GA;
	
    if (nrhs  == 1 && nlhs <= 2 && mxIsStruct(prhs[0])) {
        V = FT_get_V_MatrixPtr(prhs[0]);		
        dd_set_global_constants();  /* First, this must be called. */

        P = dd_DDMatrix2Poly(V, &err); /* compute the second representation */
        if (err == dd_NoError) {
            H = dd_CopyInequalities(P);
            plhs[0] = FT_set_H_MatrixPtr(H);
                
            GI=dd_CopyIncidence(P);
            GA=dd_CopyInputAdjacency(P);
            plhs[1] = ZH_set_Vlist(GI,GA);

            dd_FreeSetFamily(GI);
            dd_FreeSetFamily(GA);
            dd_FreeMatrix(H);
        } else {
            dd_WriteErrorMessages(stdout,err);
            mexErrMsgTxt("CDD returned an error, see above(!) for details");
        }
        dd_FreeMatrix(V);
        dd_FreePolyhedra(P);
        return;
    } else {
        mexErrMsgTxt("hull expects a V input struct and produces an H output struct");
    }
}
コード例 #2
0
void allvertices(int m_input, int d_input, double *a_input)
/* output vertices and incidences */
{
  dd_PolyhedraPtr poly;
  dd_MatrixPtr A=NULL,G=NULL;
  dd_SetFamilyPtr GI=NULL;
  dd_rowrange i,m; 
  dd_colrange j,d;
  dd_ErrorType err;

  m=(dd_rowrange)m_input; d=(dd_colrange)d_input;
  A=dd_CreateMatrix(m,d);
  for (i=0; i<m; i++){
    for (j=0; j<d; j++) dd_set_d(A->matrix[i][j],a_input[i*d+j]);
  }
  A->representation=dd_Inequality;
  poly=dd_DDMatrix2Poly(A, &err);
    /* compute the second (generator) representation */
  if (err==dd_NoError) {
    G=dd_CopyGenerators(poly);
    GI=dd_CopyIncidence(poly);

    MLPutFunction(stdlink,"List",2);
    dd_MLWriteMatrix(G);
    dd_MLWriteSetFamily(GI);
  } else {
    dd_MLWriteError(poly);
  }

  dd_FreeMatrix(A);
  dd_FreeMatrix(G);
  dd_FreeSetFamily(GI);
}
コード例 #3
0
void allfacets(int n_input, int d_input, double *g_input)
/* output facets and incidences */
{
  dd_PolyhedraPtr poly;
  dd_MatrixPtr A=NULL,G=NULL;
  dd_SetFamilyPtr AI=NULL;
  dd_rowrange i,n; 
  dd_colrange j,d;
  dd_ErrorType err;

  n=(dd_rowrange)n_input; d=(dd_colrange)d_input;
  G=dd_CreateMatrix(n,d);
  for (i=0; i<n; i++){
    for (j=0; j<d; j++) dd_set_d(G->matrix[i][j],g_input[i*d+j]);
  }
  G->representation=dd_Generator;
  poly=dd_DDMatrix2Poly(G, &err);
    /* compute the second (inequality) representation */
  if (err==dd_NoError){
    A=dd_CopyInequalities(poly);
    AI=dd_CopyIncidence(poly);

    MLPutFunction(stdlink,"List",2);
    dd_MLWriteMatrix(A);
    dd_MLWriteSetFamily(AI);
  } else {
    dd_MLWriteError(poly);
  }

  dd_FreeMatrix(A);
  dd_FreeMatrix(G);
  dd_FreeSetFamily(AI);
}
コード例 #4
0
ファイル: pplacer_cdd.c プロジェクト: boegel/pplacer
/*
 * Find the extreme vertices between lower_bound and upper_bound of the convex
 * hull of ineqs.
 *
 * ineqs: row-major order matrix of total length nrow*ncols
 * nrows: Number of rows in matrix
 * ncols: Number of columns in matrix
 * lower_bound: lower bound of solution space on x-axis
 * upper_bound: upper bound of solution space on y-axis
 * output size: Set to size of result
 *
 * Returns array representing 3 by (output_size/3) matrix, where each row is:
 *   x_i, y_i, l_i
 * Where x_i, y_i are the coordinates of the vertex, and l_i is the index of
 * the input inequality that constrains the solution space *to the right* of
 * vertex i.
 */
double *extreme_vertices(const double *ineqs, const size_t nrows,
                         const size_t ncols, float lower_bound,
                         float upper_bound, /*OUT*/ size_t * output_size)
{

  /* Preconditions */
  assert(ineqs != NULL);
  assert(ncols == 3);
  assert(output_size != NULL);

  /* Check for approx equal lower and upper bound */
  if (abs(lower_bound - upper_bound) < EPS)
    return NULL;

  assert(lower_bound <= upper_bound);

  /*
   * Initialize library
   * TODO: Do we want to do this on every call?
   */
  dd_set_global_constants();
  dd_ErrorType err;
  dd_MatrixPtr generators;
  dd_MatrixPtr m =
      init_ineq_doubles(ineqs, nrows, ncols, lower_bound, upper_bound);
  dd_SetFamilyPtr incidence;

  /* Outputs */
  dd_PolyhedraPtr poly = dd_DDMatrix2Poly(m, &err);
  if (err != dd_NoError) {
    return NULL;
  }

  /* Get generators */
  generators = dd_CopyGenerators(poly);

  /* Get incidence */
  incidence = dd_CopyIncidence(poly);

  double *result =
      list_extreme_vertices(generators, incidence, nrows, m->rowsize - 1,
          output_size);

  dd_FreeMatrix(m);
  dd_FreeMatrix(generators);
  dd_FreePolyhedra(poly);
  dd_FreeSetFamily(incidence);
  dd_free_global_constants();

  return result;
}