blob: 8f1355fe1b477df0115c10ad95cee5119204381b [file] [log] [blame]
Austin Schuh405fa6c2015-09-06 18:13:55 -07001/* testcdd1.c: Main test program to call the cdd library cddlib
2 written by Komei Fukuda, fukuda@ifor.math.ethz.ch
3 Version 0.93, July 9, 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, char *fname)
31{
32 dd_boolean success=dd_FALSE;
33
34 if ( ( *f = fopen(fname, "r") )!= NULL) {
35 printf("input file %s is open\n", fname);
36 success=dd_TRUE;
37 }
38 else{
39 printf("The input file %s not found\n",fname);
40 }
41 return success;
42}
43
44int main(int argc, char *argv[])
45{
46 dd_PolyhedraPtr poly;
47 dd_MatrixPtr M;
48 dd_ErrorType err;
49 dd_DataFileType inputfile;
50 FILE *reading=NULL;
51 dd_MatrixPtr A, G;
52 dd_SetFamilyPtr GI,GA;
53
54 dd_set_global_constants(); /* First, this must be called. */
55
56 dd_SetInputFile(&reading,inputfile, &err);
57 if (err==dd_NoError) {
58 M=dd_PolyFile2Matrix(reading, &err);
59 }
60 else {
61 printf("Input file not found\n");
62 goto _L99;
63 }
64
65 if (err==dd_NoError) {
66 poly=dd_DDMatrix2Poly(M, &err); /* compute the second representation */
67 if (err!=dd_NoError) {
68 dd_WriteErrorMessages(stdout,err); goto _L99;
69 }
70 A=dd_CopyInequalities(poly);
71 G=dd_CopyGenerators(poly);
72 GI=dd_CopyIncidence(poly);
73 GA=dd_CopyAdjacency(poly);
74
75 if (poly->representation==dd_Inequality) {
76 printf("\nInput is an H-representation\n");
77 } else {
78 printf("\nInput is a V-representation\n");
79 }
80 dd_WriteMatrix(stdout,A); printf("\n");
81 dd_WriteMatrix(stdout,G);
82
83 printf("\nHere is the incidence list:\n");
84 dd_WriteSetFamily(stdout,GI);
85
86 printf("\nHere is the adjacency list:\n");
87 dd_WriteSetFamily(stdout,GA);
88
89 dd_FreePolyhedra(poly);
90 /* This is to remove all the space allocated for poly. */
91 dd_FreeMatrix(M);
92 dd_FreeMatrix(A);
93 dd_FreeMatrix(G);
94 dd_FreeSetFamily(GI);
95 dd_FreeSetFamily(GA);
96 } else {
97 dd_WriteErrorMessages(stdout,err);
98 }
99_L99:
100 dd_free_global_constants(); /* At the end, this must be called. */
101 return 0;
102}
103
104
105/* end of testcdd1.c */