Austin Schuh | 405fa6c | 2015-09-06 18:13:55 -0700 | [diff] [blame^] | 1 | /* redcheck.c: Test program to call the cdd library cddlib |
| 2 | written by Komei Fukuda, fukuda@ifor.math.ethz.ch |
| 3 | Version 0.94, April 12, 2012 |
| 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,M2=NULL; |
| 63 | dd_ErrorType err=dd_NoError; |
| 64 | dd_rowset redrows,linrows; |
| 65 | mytype val; |
| 66 | dd_DataFileType inputfile; |
| 67 | FILE *reading=NULL; |
| 68 | time_t starttime,endtime; |
| 69 | |
| 70 | dd_set_global_constants(); /* First, this must be called. */ |
| 71 | |
| 72 | dd_init(val); |
| 73 | if (argc>1) strcpy(inputfile,argv[1]); |
| 74 | if (argc<=1 || !SetInputFile(&reading,argv[1])){ |
| 75 | dd_WriteProgramDescription(stdout); |
| 76 | fprintf(stdout,"\ncddlib test program to check redundancy of an H/V-representation.\n"); |
| 77 | dd_SetInputFile(&reading,inputfile, &err); |
| 78 | } |
| 79 | if (err==dd_NoError) { |
| 80 | M=dd_PolyFile2Matrix(reading, &err); |
| 81 | } |
| 82 | else { |
| 83 | fprintf(stderr,"Input file not found\n"); |
| 84 | goto _L99; |
| 85 | } |
| 86 | |
| 87 | if (err!=dd_NoError) goto _L99; |
| 88 | |
| 89 | time(&starttime); |
| 90 | fprintf(stdout, "redundant rows: "); |
| 91 | redrows=dd_RedundantRows(M, &err); |
| 92 | set_fwrite(stdout, redrows); |
| 93 | |
| 94 | M2=dd_MatrixSubmatrix(M, redrows); |
| 95 | |
| 96 | fprintf(stdout, "Implicit linearity (after removal of redundant rows): "); |
| 97 | linrows=dd_ImplicitLinearityRows(M2, &err); |
| 98 | |
| 99 | if (M->representation==dd_Generator) |
| 100 | fprintf(stdout," %ld ", set_card(linrows)); |
| 101 | else |
| 102 | fprintf(stdout," %ld ", set_card(linrows)); |
| 103 | set_fwrite(stdout,linrows); |
| 104 | set_uni(M2->linset, M2->linset, linrows); |
| 105 | /* add the implicit linrows to the given linearity rows */ |
| 106 | |
| 107 | time(&endtime); |
| 108 | printf("\nNonredundant representation (except for the linearity part):\n"); |
| 109 | dd_WriteMatrix(stdout, M2); |
| 110 | dd_WriteTimes(stdout,starttime,endtime); |
| 111 | |
| 112 | dd_FreeMatrix(M); |
| 113 | dd_FreeMatrix(M2); |
| 114 | |
| 115 | _L99:; |
| 116 | if (err!=dd_NoError) dd_WriteErrorMessages(stderr,err); |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | |
| 121 | /* end of redcheck.c */ |