forked from cddlib/cddlib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
testcdd1.c
106 lines (89 loc) · 2.82 KB
/
testcdd1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* testcdd1.c: Main test program to call the cdd library cddlib
written by Komei Fukuda, [email protected]
Version 0.93, July 9, 2003
Standard ftp site: ftp.ifor.math.ethz.ch, Directory: pub/fukuda/cdd
*/
/* This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "setoper.h"
#include "cdd.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <string.h>
dd_boolean SetInputFile(FILE **f, char *fname)
{
dd_boolean success=dd_FALSE;
if ( ( *f = fopen(fname, "r") )!= NULL) {
printf("input file %s is open\n", fname);
success=dd_TRUE;
}
else{
printf("The input file %s not found\n",fname);
}
return success;
}
int main(int argc, char *argv[])
{
dd_PolyhedraPtr poly;
dd_MatrixPtr M;
dd_ErrorType err;
dd_DataFileType inputfile;
FILE *reading=NULL;
dd_MatrixPtr A, G;
dd_SetFamilyPtr GI,GA;
dd_set_global_constants(); /* First, this must be called. */
dd_SetInputFile(&reading,inputfile, &err);
if (err==dd_NoError) {
M=dd_PolyFile2Matrix(reading, &err);
}
else {
printf("Input file not found\n");
goto _L99;
}
if (err==dd_NoError) {
poly=dd_DDMatrix2Poly(M, &err); /* compute the second representation */
if (err!=dd_NoError) {
dd_WriteErrorMessages(stdout,err); goto _L99;
}
A=dd_CopyInequalities(poly);
G=dd_CopyGenerators(poly);
GI=dd_CopyIncidence(poly);
GA=dd_CopyAdjacency(poly);
if (poly->representation==dd_Inequality) {
printf("\nInput is an H-representation\n");
} else {
printf("\nInput is a V-representation\n");
}
dd_WriteMatrix(stdout,A); printf("\n");
dd_WriteMatrix(stdout,G);
printf("\nHere is the incidence list:\n");
dd_WriteSetFamily(stdout,GI);
printf("\nHere is the adjacency list:\n");
dd_WriteSetFamily(stdout,GA);
dd_FreePolyhedra(poly);
/* This is to remove all the space allocated for poly. */
dd_FreeMatrix(M);
dd_FreeMatrix(A);
dd_FreeMatrix(G);
dd_FreeSetFamily(GI);
dd_FreeSetFamily(GA);
} else {
dd_WriteErrorMessages(stdout,err);
}
_L99:
dd_free_global_constants(); /* At the end, this must be called. */
return 0;
}
/* end of testcdd1.c */