blob: 6bb1a1921013227467ef4569ee55801867380e99 [file] [log] [blame]
Austin Schuh405fa6c2015-09-06 18:13:55 -07001/* 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
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,M1=NULL,M2=NULL;
63 dd_rowrange i;
64 dd_colrange d;
65 dd_ErrorType err=dd_NoError;
66 dd_rowset redrows,linrows,posset;
67 dd_rowindex newpos=NULL, newpos1=NULL, newpos2=NULL;
68 mytype val;
69 dd_DataFileType inputfile;
70 FILE *reading=NULL;
71 int foi;
72 dd_Arow certificate;
73
74 dd_set_global_constants(); /* First, this must be called. */
75
76 dd_init(val);
77 if (argc>1) strcpy(inputfile,argv[1]);
78 if (argc<=1 || !SetInputFile(&reading,argv[1])){
79 dd_WriteProgramDescription(stdout);
80 fprintf(stdout,"\ncddlib test program to remove duplicates.\n");
81 dd_SetInputFile(&reading,inputfile, &err);
82 }
83 if (err==dd_NoError) {
84 M=dd_PolyFile2Matrix(reading, &err);
85 }
86 else {
87 fprintf(stderr,"Input file not found\n");
88 goto _L99;
89 }
90
91 if (err!=dd_NoError) goto _L99;
92
93 d=M->colsize;
94
95 /*
96 printf("\nInput Matrix.\n");
97 dd_WriteMatrix(stdout, M);
98 */
99
100 M1=dd_MatrixSortedUniqueCopy(M,&newpos1);
101 printf("\nSort and remove duplicates with dd_MatrixSortedUniqueCopy.\n");
102 printf(" Row index changes -- original:new\n");
103 for (i=1;i<=M->rowsize; i++){
104 printf(" %ld:%ld",i,newpos1[i]);
105 }
106 printf("\n");
107 /* dd_WriteMatrix(stdout, M1); */
108
109 dd_InitializeArow(M1->colsize+2, &certificate);
110 fprintf(stdout, "\nCheck whether the system contains an implicit linearity.\n");
111 foi=dd_FreeOfImplicitLinearity(M1, certificate, &posset, &err);
112 switch (foi) {
113 case 1:
114 fprintf(stdout, " It is free of implicit linearity.\n");
115 break;
116
117 case 0:
118 fprintf(stdout, " It is not free of implicit linearity.\n");
119 break;
120
121 case -1:
122 fprintf(stdout, " The input system is trivial (i.e. the empty H-polytope or the V-rep of the whole space.\n");
123 break;
124 }
125
126
127 fprintf(stdout, "\nOne can then remove nontrivial redundant rows with dd_RedundantRows.\n Redundant rows:\n");
128 redrows=dd_RedundantRowsWithPresorting(M1, &err);
129 /* redrows=dd_RedundantRows(M1, &err); */
130 set_fwrite(stdout, redrows);
131 printf("\n");
132
133 M2=dd_MatrixSubmatrix2(M1, redrows, &newpos);
134 dd_FreeMatrix(M1);
135 set_free(redrows);
136 free(newpos);
137
138 fprintf(stdout, " Implicit linearity (after removal of redundant rows): ");
139 linrows=dd_ImplicitLinearityRows(M2, &err);
140
141 if (M->representation==dd_Generator)
142 fprintf(stdout," %ld ", set_card(linrows));
143 else
144 fprintf(stdout," %ld ", set_card(linrows));
145 set_fwrite(stdout,linrows);
146 set_uni(M2->linset, M2->linset, linrows);
147 /* add the implicit linrows to the given linearity rows */
148
149 printf("\nNonredundant representation (except for the linearity part):\n");
150 dd_WriteMatrix(stdout, M2);
151 dd_WriteLPStats(stdout);
152 set_free(linrows);
153
154 dd_FreeMatrix(M);
155 dd_FreeMatrix(M2);
156 dd_clear(val);
157 free(newpos1); free(newpos2);
158
159_L99:;
160 /* if (err!=dd_NoError) dd_WriteErrorMessages(stderr,err); */
161 return 0;
162}
163
164
165/* end of uniqtest.c */