Exemplo n.º 1
0
void ddf_InitialDataSetup(ddf_ConePtr cone)
{
  long j, r;
  ddf_rowset ZSet;
  static ddf_Arow Vector1,Vector2;
  static ddf_colrange last_d=0;

  if (last_d < cone->d){
    if (last_d>0) {
    for (j=0; j<last_d; j++){
      ddf_clear(Vector1[j]);
      ddf_clear(Vector2[j]);
    }
    free(Vector1); free(Vector2);
    }
    Vector1=(myfloat*)calloc(cone->d,sizeof(myfloat));
    Vector2=(myfloat*)calloc(cone->d,sizeof(myfloat));
    for (j=0; j<cone->d; j++){
      ddf_init(Vector1[j]);
      ddf_init(Vector2[j]);
    }
    last_d=cone->d;
  }

  cone->RecomputeRowOrder=ddf_FALSE;
  cone->ArtificialRay = NULL;
  cone->FirstRay = NULL;
  cone->LastRay = NULL;
  set_initialize(&ZSet,cone->m);
  ddf_AddArtificialRay(cone);
  set_copy(cone->AddedHalfspaces, cone->InitialHalfspaces);
  set_copy(cone->WeaklyAddedHalfspaces, cone->InitialHalfspaces);
  ddf_UpdateRowOrderVector(cone, cone->InitialHalfspaces);
  for (r = 1; r <= cone->d; r++) {
    for (j = 0; j < cone->d; j++){
      ddf_set(Vector1[j], cone->B[j][r-1]);
      ddf_neg(Vector2[j], cone->B[j][r-1]);
    }
    ddf_Normalize(cone->d, Vector1);
    ddf_Normalize(cone->d, Vector2);
    ddf_ZeroIndexSet(cone->m, cone->d, cone->A, Vector1, ZSet);
    if (set_subset(cone->EqualitySet, ZSet)){
      if (ddf_debug) {
        fprintf(stderr,"add an initial ray with zero set:");
        set_fwrite(stderr,ZSet);
      }
      ddf_AddRay(cone, Vector1);
      if (cone->InitialRayIndex[r]==0) {
        ddf_AddRay(cone, Vector2);
        if (ddf_debug) {
          fprintf(stderr,"and add its negative also.\n");
        }
      }
    }
  }
  ddf_CreateInitialEdges(cone);
  cone->Iteration = cone->d + 1;
  if (cone->Iteration > cone->m) cone->CompStatus=ddf_AllFound; /* 0.94b  */
  set_free(ZSet);
Exemplo n.º 2
0
ddf_MatrixPtr ddf_FourierElimination(ddf_MatrixPtr M,ddf_ErrorType *error)
/* Eliminate the last variable (column) from the given H-matrix using 
   the standard Fourier Elimination.
 */
{
  ddf_MatrixPtr Mnew=NULL;
  ddf_rowrange i,inew,ip,in,iz,m,mpos=0,mneg=0,mzero=0,mnew;
  ddf_colrange j,d,dnew;
  ddf_rowindex posrowindex, negrowindex,zerorowindex;
  myfloat temp1,temp2;
  ddf_boolean localdebug=ddf_FALSE;

  *error=ddf_NoError;
  m= M->rowsize;
  d= M->colsize;
  if (d<=1){
    *error=ddf_ColIndexOutOfRange;
    if (localdebug) {
      printf("The number of column is too small: %ld for Fourier's Elimination.\n",d);
    }
    goto _L99;
  }

  if (M->representation==ddf_Generator){
    *error=ddf_NotAvailForV;
    if (localdebug) {
      printf("Fourier's Elimination cannot be applied to a V-polyhedron.\n");
    }
    goto _L99;
  }

  if (set_card(M->linset)>0){
    *error=ddf_CannotHandleLinearity;
    if (localdebug) {
      printf("The Fourier Elimination function does not handle equality in this version.\n");
    }
    goto _L99;
  }

  /* Create temporary spaces to be removed at the end of this function */
  posrowindex=(long*)calloc(m+1,sizeof(long));
  negrowindex=(long*)calloc(m+1,sizeof(long));
  zerorowindex=(long*)calloc(m+1,sizeof(long));
  ddf_init(temp1);
  ddf_init(temp2);

  for (i = 1; i <= m; i++) {
    if (ddf_Positive(M->matrix[i-1][d-1])){
      mpos++;
      posrowindex[mpos]=i;
    } else if (ddf_Negative(M->matrix[i-1][d-1])) {
      mneg++;
      negrowindex[mneg]=i;
    } else {
      mzero++;
      zerorowindex[mzero]=i;
    }
  }  /*of i*/

  if (localdebug) {
    ddf_WriteMatrix(stdout, M);
    printf("No of  (+  -  0) rows = (%ld, %ld, %ld)\n", mpos,mneg, mzero);
  }

  /* The present code generates so many redundant inequalities and thus
     is quite useless, except for very small examples
  */
  mnew=mzero+mpos*mneg;  /* the total number of rows after elimination */
  dnew=d-1;

  Mnew=ddf_CreateMatrix(mnew, dnew);
  ddf_CopyArow(Mnew->rowvec, M->rowvec, dnew);
/*  set_copy(Mnew->linset,M->linset);  */
  Mnew->numbtype=M->numbtype;
  Mnew->representation=M->representation;
  Mnew->objective=M->objective;


  /* Copy the inequalities independent of x_d to the top of the new matrix. */
  for (iz = 1; iz <= mzero; iz++){
    for (j = 1; j <= dnew; j++) {
      ddf_set(Mnew->matrix[iz-1][j-1], M->matrix[zerorowindex[iz]-1][j-1]);
    }
  } 

  /* Create the new inequalities by combining x_d positive and negative ones. */
  inew=mzero;  /* the index of the last x_d zero inequality */
  for (ip = 1; ip <= mpos; ip++){
    for (in = 1; in <= mneg; in++){
      inew++;
      ddf_neg(temp1, M->matrix[negrowindex[in]-1][d-1]);
      for (j = 1; j <= dnew; j++) {
        ddf_LinearComb(temp2,M->matrix[posrowindex[ip]-1][j-1],temp1,\
          M->matrix[negrowindex[in]-1][j-1],\
          M->matrix[posrowindex[ip]-1][d-1]);
        ddf_set(Mnew->matrix[inew-1][j-1],temp2);
      }
      ddf_Normalize(dnew,Mnew->matrix[inew-1]);
    }
  } 


  free(posrowindex);
  free(negrowindex);
  free(zerorowindex);
  ddf_clear(temp1);
  ddf_clear(temp2);

 _L99:
  return Mnew;
}