コード例 #1
0
ファイル: cddlib_f.c プロジェクト: adsnaider/Robotics-Project
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);
コード例 #2
0
ファイル: cddlib_f.c プロジェクト: adsnaider/Robotics-Project
void ddf_DDMain(ddf_ConePtr cone)
{
  ddf_rowrange hh, itemp, otemp;
  ddf_boolean locallog=ddf_log; /* if ddf_log=ddf_FALSE, no log will be written.  */

  if (cone->d<=0){
    cone->Iteration=cone->m;
    cone->FeasibleRayCount=0;
    cone->CompStatus=ddf_AllFound;
    goto _L99;
  }
  if (locallog) {
     fprintf(stderr,"(Initially added rows ) = ");
     set_fwrite(stderr,cone->InitialHalfspaces);
  }
  while (cone->Iteration <= cone->m) {
    ddf_SelectNextHalfspace(cone, cone->WeaklyAddedHalfspaces, &hh);
    if (set_member(hh,cone->NonequalitySet)){  /* Skip the row hh */
      if (ddf_debug) {
        fprintf(stderr,"*The row # %3ld should be inactive and thus skipped.\n", hh);
      }
      set_addelem(cone->WeaklyAddedHalfspaces, hh);
    } else {
      if (cone->PreOrderedRun)
        ddf_AddNewHalfspace2(cone, hh);
      else{
        ddf_AddNewHalfspace1(cone, hh);
      }
      set_addelem(cone->AddedHalfspaces, hh);
      set_addelem(cone->WeaklyAddedHalfspaces, hh);
    }
    if (!cone->PreOrderedRun){
      for (itemp=1; cone->OrderVector[itemp]!=hh; itemp++);
        otemp=cone->OrderVector[cone->Iteration];
      cone->OrderVector[cone->Iteration]=hh;
        /* store the dynamic ordering in ordervec */
      cone->OrderVector[itemp]=otemp;
        /* store the dynamic ordering in ordervec */
    }
    if (locallog){
      fprintf(stderr,"(Iter, Row, #Total, #Curr, #Feas)= %5ld %5ld %9ld %6ld %6ld\n",
        cone->Iteration, hh, cone->TotalRayCount, cone->RayCount,
        cone->FeasibleRayCount);
    }
    if (cone->CompStatus==ddf_AllFound||cone->CompStatus==ddf_RegionEmpty) {
      set_addelem(cone->AddedHalfspaces, hh);
      goto _L99;
    }
    (cone->Iteration)++;
  }
  _L99:;
  if (cone->d<=0 || cone->newcol[1]==0){ /* fixing the number of output */
     cone->parent->n=cone->LinearityDim + cone->FeasibleRayCount -1;
     cone->parent->ldim=cone->LinearityDim - 1;
  } else {
    cone->parent->n=cone->LinearityDim + cone->FeasibleRayCount;
    cone->parent->ldim=cone->LinearityDim;
  }
コード例 #3
0
ファイル: redcheck.c プロジェクト: mcmtroffaes/cddlib
int main(int argc, char *argv[])
{
  dd_MatrixPtr M=NULL;
  dd_rowrange i,m;
  dd_ErrorType err=dd_NoError;
  dd_rowindex newpos;
  dd_rowset impl_linset,redset;
  time_t starttime, endtime;
  dd_DataFileType inputfile;
  FILE *reading=NULL;

  dd_set_global_constants();  /* First, this must be called. */

  if (argc>1) strcpy(inputfile,argv[1]);
  if (argc<=1 || !SetInputFile(&reading,argv[1])){
    dd_WriteProgramDescription(stdout);
    fprintf(stdout,"\ncddlib test program to check redundancy of an H/V-representation.\n");
    dd_SetInputFile(&reading,inputfile, &err);
  }
  if (err==dd_NoError) {
    M=dd_PolyFile2Matrix(reading, &err);
  }
  else {
    fprintf(stderr,"Input file not found\n");
    goto _L99;
  }

  if (err!=dd_NoError) goto _L99;

  m=M->rowsize;
  fprintf(stdout, "Canonicalize the matrix.\n");
    
  time(&starttime);
  dd_MatrixCanonicalize(&M, &impl_linset, &redset, &newpos, &err);
  time(&endtime);
  
  if (err!=dd_NoError) goto _L99;

  fprintf(stdout, "Implicit linearity rows are:"); set_fwrite(stdout, impl_linset);

  fprintf(stdout, "\nRedundant rows are:"); set_fwrite(stdout, redset);
  fprintf(stdout, "\n");
  
  fprintf(stdout, "Nonredundant representation:\n");
  fprintf(stdout, "The new row positions are as follows (orig:new).\nEach redundant row has the new number 0.\nEach deleted duplicated row has a number nagative of the row that\nrepresents its equivalence class.\n");
  
  for (i=1; i<=m; i++){
   fprintf(stdout, " %ld:%ld",i, newpos[i]); 
  }
  fprintf(stdout, "\n");
  dd_WriteMatrix(stdout, M);
  
  dd_WriteTimes(stdout,starttime,endtime);

  set_free(redset);
  set_free(impl_linset);
  dd_FreeMatrix(M);
  free(newpos);

_L99:;
  if (err!=dd_NoError) dd_WriteErrorMessages(stderr,err);
  return 0;
}
コード例 #4
0
ファイル: fourier.c プロジェクト: adsnaider/Robotics-Project
int main(int argc, char *argv[])
{
  dd_MatrixPtr M=NULL,M1=NULL,M2=NULL;
  dd_colrange j,s,d;
  dd_ErrorType err=dd_NoError;
  dd_rowset redset,impl_linset;
  dd_rowindex newpos;
  mytype val;
  dd_DataFileType inputfile;
  FILE *reading=NULL;

  dd_set_global_constants();  /* First, this must be called. */

  dd_init(val);
  if (argc>1) strcpy(inputfile,argv[1]);
  if (argc<=1 || !SetInputFile(&reading,argv[1])){
    dd_WriteProgramDescription(stdout);
    fprintf(stdout,"\ncddlib test program to apply Fourier's Elimination to an H-polyhedron.\n");
    dd_SetInputFile(&reading,inputfile, &err);
  }
  if (err==dd_NoError) {
    M=dd_PolyFile2Matrix(reading, &err);
  }
  else {
    fprintf(stderr,"Input file not found\n");
    goto _L99;
  }

  if (err!=dd_NoError) goto _L99;

  d=M->colsize;
  M2=dd_CopyMatrix(M);

  printf("How many variables to elminate? (max %ld): ",d-1);
  scanf("%ld",&s);
  
  if (s>0 && s < d){
    for (j=1; j<=s; j++){
      M1=dd_FourierElimination(M2, &err);
      printf("\nRemove the variable %ld.  The resulting redundant system.\n",d-j);
      dd_WriteMatrix(stdout, M1);

      dd_MatrixCanonicalize(&M1, &impl_linset, &redset, &newpos, &err);
      if (err!=dd_NoError) goto _L99;

      fprintf(stdout, "\nRedundant rows: ");
      set_fwrite(stdout, redset);

      dd_FreeMatrix(M2);
      M2=M1;
      set_free(redset);
      set_free(impl_linset);
      free(newpos);
    }

    printf("\nNonredundant representation:\n");
    dd_WriteMatrix(stdout, M1);
  } else {
    printf("Value out of range\n");
  }

  dd_FreeMatrix(M);
  dd_FreeMatrix(M1);
  dd_clear(val);

_L99:;
  /* if (err!=dd_NoError) dd_WriteErrorMessages(stderr,err); */
  dd_free_global_constants();  /* At the end, this should be called. */
  return 0;
}