blob: c9b033e7857ba77d2dfd46501cbd53eda1b0fccf [file] [log] [blame]
Austin Schuh405fa6c2015-09-06 18:13:55 -07001/* redexter.c: Test program to call the cdd library cddlib
2 written by Komei Fukuda, fukuda@ifor.math.ethz.ch
3 Version 0.94, November 21, 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 M1=NULL,M2=NULL,M2row=NULL,M1plus=NULL;
63 dd_colrange d1;
64 dd_rowrange i,m1,m2,m1plus;
65 dd_ErrorType err=dd_NoError,err1=dd_NoError,err2=dd_NoError;
66 dd_rowset delset,rowset2;
67 dd_Arow cvec; /* certificate */
68
69 time_t starttime, endtime;
70 dd_DataFileType inputfile1,inputfile2;
71 FILE *reading1=NULL,*reading2=NULL;
72
73 dd_set_global_constants(); /* First, this must be called. */
74
75 dd_WriteProgramDescription(stdout);
76 fprintf(stdout,"\ncddlib test program to check redundancy of additional data.\n");
77 if (argc>2){
78 strcpy(inputfile1,argv[1]);
79 strcpy(inputfile2,argv[2]);
80 }
81 /*
82 if (argc<=2){
83 fprintf(stdout,"\nUsage:\n redexter file1 file2\n");
84 goto _L99;
85 }
86 */
87 if (!SetInputFile(&reading1,argv[1])){
88 fprintf(stdout,"\nSpecify file1.\n");
89 dd_SetInputFile(&reading1,inputfile1, &err1);
90 }
91 if (!SetInputFile(&reading2,argv[2])){
92 fprintf(stdout,"\nSpecify the secondary file.\n");
93 dd_SetInputFile(&reading2,inputfile2, &err2);
94 }
95 if ((err1==dd_NoError) && (err2==dd_NoError)) {
96 M1=dd_PolyFile2Matrix(reading1, &err1);
97 M2=dd_PolyFile2Matrix(reading2, &err2);
98 }
99 else {
100 fprintf(stderr,"Input file(s) not found\n");
101 goto _L99;
102 }
103
104 if ((err1!=dd_NoError) || (err2!=dd_NoError)) goto _L99;
105
106 m1=M1->rowsize;
107 m2=M2->rowsize;
108 set_initialize(&delset,m2);
109 m1plus=m1+1;
110 if (M1->representation==dd_Generator){
111 d1=(M1->colsize)+1;
112 } else {
113 d1=M1->colsize;
114 }
115 dd_InitializeArow(d1,&cvec);
116
117 fprintf(stdout, "\nThe first matrix\n");
118 dd_WriteMatrix(stdout, M1);
119 fprintf(stdout, "\nThe second matrix\n");
120 dd_WriteMatrix(stdout, M2);
121
122 printf("\nChecking whether each row of the second matrix is redundant w.r.t. the first.\n");
123
124 time(&starttime);
125
126 for (i=1; i<=m2; i++){
127 set_initialize(&rowset2,m2);
128 set_addelem(rowset2, i);
129 set_compl(delset, rowset2);
130 M2row=dd_MatrixSubmatrix(M2, delset);
131 M1plus=dd_MatrixAppend(M1,M2row);
132
133 if (dd_Redundant(M1plus, m1plus, cvec, &err)) {
134 printf("%ld-th row: redundant\n", i);
135 } else {
136 printf("%ld-th row: non-redundant\n A certificate:", i);
137 dd_WriteArow(stdout, cvec, d1);
138 }
139
140 dd_FreeMatrix(M1plus);
141 dd_FreeMatrix(M2row);
142 set_free(rowset2);
143 }
144
145 time(&endtime);
146
147 dd_WriteTimes(stdout,starttime,endtime);
148
149 set_free(delset);
150 dd_FreeMatrix(M1);
151 dd_FreeMatrix(M2);
152
153_L99:;
154 if (err1!=dd_NoError) dd_WriteErrorMessages(stderr,err1);
155 if (err2!=dd_NoError) dd_WriteErrorMessages(stderr,err2);
156 return 0;
157}
158
159
160/* end of redexter.c */