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