blob: f4391fe25727b5f7e9cf9cd3e29d80288e419030 [file] [log] [blame]
Austin Schuh405fa6c2015-09-06 18:13:55 -07001/* 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 4, 2005
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
30dd_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
45dd_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
60int main(int argc, char *argv[])
61{
62 dd_MatrixPtr M=NULL;
63 dd_rowrange i,m;
64 dd_ErrorType err=dd_NoError;
65 dd_rowindex newpos;
66 dd_rowset impl_linset,redset;
67 time_t starttime, endtime;
68 dd_DataFileType inputfile;
69 FILE *reading=NULL;
70
71 dd_set_global_constants(); /* First, this must be called. */
72
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 m=M->rowsize;
90 fprintf(stdout, "Canonicalize the matrix.\n");
91
92 time(&starttime);
93 dd_MatrixCanonicalize(&M, &impl_linset, &redset, &newpos, &err);
94 time(&endtime);
95
96 if (err!=dd_NoError) goto _L99;
97
98 fprintf(stdout, "Implicit linearity rows are:"); set_fwrite(stdout, impl_linset);
99
100 fprintf(stdout, "\nRedundant rows are:"); set_fwrite(stdout, redset);
101 fprintf(stdout, "\n");
102
103 fprintf(stdout, "Nonredundant representation:\n");
104 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");
105
106 for (i=1; i<=m; i++){
107 fprintf(stdout, " %ld:%ld",i, newpos[i]);
108 }
109 fprintf(stdout, "\n");
110 dd_WriteMatrix(stdout, M);
111
112 dd_WriteTimes(stdout,starttime,endtime);
113
114 set_free(redset);
115 set_free(impl_linset);
116 dd_FreeMatrix(M);
117 free(newpos);
118
119_L99:;
120 if (err!=dd_NoError) dd_WriteErrorMessages(stderr,err);
121 return 0;
122}
123
124
125/* end of redcheck.c */