blob: bff5dd5bdb41b2f43d5622162b45ecef869cf6d5 [file] [log] [blame]
Austin Schuh405fa6c2015-09-06 18:13:55 -07001/* fourier.c: Test program to call the cdd library cddlib
2 written by Komei Fukuda, fukuda@ifor.math.ethz.ch
3 Version 0.94, August 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,M1=NULL,M2=NULL;
63 dd_colrange j,s,d;
64 dd_ErrorType err=dd_NoError;
65 dd_rowset redset,impl_linset;
66 dd_rowindex newpos;
67 mytype val;
68 dd_DataFileType inputfile;
69 FILE *reading=NULL;
70
71 dd_set_global_constants(); /* First, this must be called. */
72
73 dd_init(val);
74 if (argc>1) strcpy(inputfile,argv[1]);
75 if (argc<=1 || !SetInputFile(&reading,argv[1])){
76 dd_WriteProgramDescription(stdout);
77 fprintf(stdout,"\ncddlib test program to apply Fourier's Elimination to an H-polyhedron.\n");
78 dd_SetInputFile(&reading,inputfile, &err);
79 }
80 if (err==dd_NoError) {
81 M=dd_PolyFile2Matrix(reading, &err);
82 }
83 else {
84 fprintf(stderr,"Input file not found\n");
85 goto _L99;
86 }
87
88 if (err!=dd_NoError) goto _L99;
89
90 d=M->colsize;
91 M2=dd_CopyMatrix(M);
92
93 printf("How many variables to elminate? (max %ld): ",d-1);
94 scanf("%ld",&s);
95
96 if (s>0 && s < d){
97 for (j=1; j<=s; j++){
98 M1=dd_FourierElimination(M2, &err);
99 printf("\nRemove the variable %ld. The resulting redundant system.\n",d-j);
100 dd_WriteMatrix(stdout, M1);
101
102 dd_MatrixCanonicalize(&M1, &impl_linset, &redset, &newpos, &err);
103 if (err!=dd_NoError) goto _L99;
104
105 fprintf(stdout, "\nRedundant rows: ");
106 set_fwrite(stdout, redset);
107
108 dd_FreeMatrix(M2);
109 M2=M1;
110 set_free(redset);
111 set_free(impl_linset);
112 free(newpos);
113 }
114
115 printf("\nNonredundant representation:\n");
116 dd_WriteMatrix(stdout, M1);
117 } else {
118 printf("Value out of range\n");
119 }
120
121 dd_FreeMatrix(M);
122 dd_FreeMatrix(M1);
123 dd_clear(val);
124
125_L99:;
126 /* if (err!=dd_NoError) dd_WriteErrorMessages(stderr,err); */
127 dd_free_global_constants(); /* At the end, this should be called. */
128 return 0;
129}
130
131
132/* end of fourier.c */