Austin Schuh | 405fa6c | 2015-09-06 18:13:55 -0700 | [diff] [blame] | 1 | /* uniqtest.c: Test program to call the cdd library cddlib |
| 2 | written by Komei Fukuda, fukuda@ifor.math.ethz.ch |
| 3 | Version 0.93c, Nov. 14, 2003 |
| 4 | Standard ftp site: ftp.ifor.math.ethz.ch, Directory: pub/fukuda/cdd |
| 5 | */ |
| 6 | |
| 7 | /* This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
| 22 | #include "setoper.h" |
| 23 | #include "cdd.h" |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <time.h> |
| 27 | #include <math.h> |
| 28 | #include <string.h> |
| 29 | |
| 30 | dd_boolean SetInputFile(FILE **f, dd_DataFileType fname) |
| 31 | { |
| 32 | dd_boolean success=dd_FALSE; |
| 33 | success=dd_FALSE; |
| 34 | |
| 35 | if ( ( *f = fopen(fname, "r") )!= NULL) { |
| 36 | printf("input file %s is open\n", fname); |
| 37 | success=dd_TRUE; |
| 38 | } |
| 39 | else{ |
| 40 | printf("The input file %s not found\n",fname); |
| 41 | } |
| 42 | return success; |
| 43 | } |
| 44 | |
| 45 | dd_boolean SetWriteFile(FILE **f, dd_DataFileType fname) |
| 46 | { |
| 47 | dd_boolean success=dd_FALSE; |
| 48 | |
| 49 | if ( (*f = fopen(fname, "w")) != NULL){ |
| 50 | printf("output file %s is open\n",fname); |
| 51 | success=dd_TRUE; |
| 52 | } |
| 53 | else{ |
| 54 | printf("The output file %s cannot be opened\n",fname); |
| 55 | } |
| 56 | return success; |
| 57 | } |
| 58 | |
| 59 | |
| 60 | int main(int argc, char *argv[]) |
| 61 | { |
| 62 | dd_MatrixPtr M=NULL,M1=NULL,M2=NULL,M3=NULL,M4=NULL; |
| 63 | dd_rowrange i; |
| 64 | dd_colrange d; |
| 65 | dd_ErrorType err=dd_NoError; |
| 66 | dd_rowset redrows,linrows; |
| 67 | dd_rowindex newpos1=NULL, newpos2=NULL,newpos4=NULL; |
| 68 | mytype val; |
| 69 | dd_DataFileType inputfile; |
| 70 | FILE *reading=NULL; |
| 71 | |
| 72 | dd_set_global_constants(); /* First, this must be called. */ |
| 73 | |
| 74 | dd_init(val); |
| 75 | if (argc>1) strcpy(inputfile,argv[1]); |
| 76 | if (argc<=1 || !SetInputFile(&reading,argv[1])){ |
| 77 | dd_WriteProgramDescription(stdout); |
| 78 | fprintf(stdout,"\ncddlib test program to remove duplicates.\n"); |
| 79 | dd_SetInputFile(&reading,inputfile, &err); |
| 80 | } |
| 81 | if (err==dd_NoError) { |
| 82 | M=dd_PolyFile2Matrix(reading, &err); |
| 83 | } |
| 84 | else { |
| 85 | fprintf(stderr,"Input file not found\n"); |
| 86 | goto _L99; |
| 87 | } |
| 88 | |
| 89 | if (err!=dd_NoError) goto _L99; |
| 90 | |
| 91 | d=M->colsize; |
| 92 | |
| 93 | printf("\nInput Matrix.\n"); |
| 94 | dd_WriteMatrix(stdout, M); |
| 95 | M1=dd_MatrixSortedCopy(M,&newpos1); |
| 96 | printf("\nNormalize and sort the matrix with dd_MatrixSortedCopy.\n"); |
| 97 | printf(" Row index changes -- original:new\n"); |
| 98 | for (i=1;i<=M->rowsize; i++){ |
| 99 | printf(" %ld:%ld",i,newpos1[i]); |
| 100 | } |
| 101 | printf("\n"); |
| 102 | |
| 103 | dd_WriteMatrix(stdout, M1); |
| 104 | |
| 105 | M2=dd_MatrixUniqueCopy(M1,&newpos2); |
| 106 | printf("\nRemove row (consecutive) duplicates with dd_MatrixUniqueCopy.\n"); |
| 107 | printf(" Row index changes -- original:new\n"); |
| 108 | for (i=1;i<=M1->rowsize; i++){ |
| 109 | printf(" %ld:%ld",i,newpos2[i]); |
| 110 | } |
| 111 | printf("\n"); |
| 112 | dd_WriteMatrix(stdout, M2); |
| 113 | |
| 114 | |
| 115 | M4=dd_MatrixSortedUniqueCopy(M,&newpos4); |
| 116 | printf("\nTwo operations can be done at once with dd_MatrixSortedUniqueCopy.\n"); |
| 117 | printf(" Row index changes -- original:new\n"); |
| 118 | for (i=1;i<=M->rowsize; i++){ |
| 119 | printf(" %ld:%ld",i,newpos4[i]); |
| 120 | } |
| 121 | printf("\n"); |
| 122 | dd_WriteMatrix(stdout, M4); |
| 123 | |
| 124 | |
| 125 | fprintf(stdout, "\nOne can then remove nontrivial redundant rows with dd_RedundantRows.\n Redundant rows:"); |
| 126 | redrows=dd_RedundantRows(M2, &err); |
| 127 | set_fwrite(stdout, redrows); |
| 128 | |
| 129 | M3=dd_MatrixSubmatrix(M2, redrows); |
| 130 | dd_FreeMatrix(M1); |
| 131 | dd_FreeMatrix(M2); |
| 132 | set_free(redrows); |
| 133 | |
| 134 | fprintf(stdout, " Implicit linearity (after removal of redundant rows): "); |
| 135 | linrows=dd_ImplicitLinearityRows(M3, &err); |
| 136 | |
| 137 | if (M->representation==dd_Generator) |
| 138 | fprintf(stdout," %ld ", set_card(linrows)); |
| 139 | else |
| 140 | fprintf(stdout," %ld ", set_card(linrows)); |
| 141 | set_fwrite(stdout,linrows); |
| 142 | set_uni(M3->linset, M3->linset, linrows); |
| 143 | /* add the implicit linrows to the given linearity rows */ |
| 144 | |
| 145 | printf("\nNonredundant representation (except for the linearity part):\n"); |
| 146 | dd_WriteMatrix(stdout, M3); |
| 147 | set_free(linrows); |
| 148 | |
| 149 | dd_FreeMatrix(M); |
| 150 | dd_FreeMatrix(M3); |
| 151 | dd_FreeMatrix(M4); |
| 152 | dd_clear(val); |
| 153 | free(newpos1); free(newpos2); free(newpos4); |
| 154 | |
| 155 | _L99:; |
| 156 | /* if (err!=dd_NoError) dd_WriteErrorMessages(stderr,err); */ |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | |
| 161 | /* end of uniqtest.c */ |