Austin Schuh | 405fa6c | 2015-09-06 18:13:55 -0700 | [diff] [blame] | 1 | /* testcdd2.c: Main test program to call the cdd library cddlib |
| 2 | written by Komei Fukuda, fukuda@ifor.math.ethz.ch |
| 3 | Version 0.90c, June 12, 2000 |
| 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 | |
| 30 | int main(int argc, char *argv[]) |
| 31 | { |
| 32 | dd_PolyhedraPtr poly; |
| 33 | dd_MatrixPtr A, B, G; |
| 34 | dd_rowrange m; |
| 35 | dd_colrange d; |
| 36 | dd_ErrorType err; |
| 37 | |
| 38 | dd_set_global_constants(); /* First, this must be called to use cddlib. */ |
| 39 | |
| 40 | m=4; d=3; |
| 41 | A=dd_CreateMatrix(m,d); |
| 42 | dd_set_si(A->matrix[0][0],7); dd_set_si(A->matrix[0][1],-3); dd_set_si(A->matrix[0][2], 0); |
| 43 | dd_set_si(A->matrix[1][0],7); dd_set_si(A->matrix[1][1], 0); dd_set_si(A->matrix[1][2],-3); |
| 44 | dd_set_si(A->matrix[2][0],1); dd_set_si(A->matrix[2][1], 1); dd_set_si(A->matrix[2][2], 0); |
| 45 | dd_set_si(A->matrix[3][0],1); dd_set_si(A->matrix[3][1], 0); dd_set_si(A->matrix[3][2], 1); |
| 46 | /* 7 - 3 x1 >= 0 |
| 47 | 7 - 3x2 >= 0 |
| 48 | 1 + x1 >= 0 |
| 49 | 1 + x2 >= 0 |
| 50 | */ |
| 51 | A->representation=dd_Inequality; |
| 52 | poly=dd_DDMatrix2Poly(A, &err); /* compute the second (generator) representation */ |
| 53 | if (err!=dd_NoError) goto _L99; |
| 54 | printf("\nInput is H-representation:\n"); |
| 55 | G=dd_CopyGenerators(poly); |
| 56 | dd_WriteMatrix(stdout,A); printf("\n"); |
| 57 | dd_WriteMatrix(stdout,G); |
| 58 | dd_FreeMatrix(A); |
| 59 | dd_FreeMatrix(G); |
| 60 | |
| 61 | /* Add inequalities: |
| 62 | 7 + x1 -3x2 = 0 |
| 63 | 7 - 3x1 + x2 >= 0 |
| 64 | */ |
| 65 | m=2; |
| 66 | B=dd_CreateMatrix(m,d); |
| 67 | dd_set_si(B->matrix[0][0],7); dd_set_si(B->matrix[0][1], 1); dd_set_si(B->matrix[0][2],-3); |
| 68 | dd_set_si(B->matrix[1][0],7); dd_set_si(B->matrix[1][1],-3); dd_set_si(B->matrix[1][2], 1); |
| 69 | set_addelem(B->linset,1); /* setting the first to be equality */ |
| 70 | |
| 71 | dd_DDInputAppend(&poly,B, &err); /* append the two inequalities and compute the generators */ |
| 72 | if (err!=dd_NoError) goto _L99; |
| 73 | A=dd_CopyInequalities(poly); /* get the inequalities (=input). */ |
| 74 | G=dd_CopyGenerators(poly); /* get the generators (=output). */ |
| 75 | printf("\nNew H-representation with added inequalities:\n"); |
| 76 | dd_WriteMatrix(stdout,A); printf("\n"); |
| 77 | dd_WriteMatrix(stdout,G); |
| 78 | |
| 79 | dd_FreeMatrix(A); |
| 80 | dd_FreeMatrix(B); |
| 81 | dd_FreeMatrix(G); |
| 82 | dd_FreePolyhedra(poly); |
| 83 | |
| 84 | _L99: |
| 85 | if (err!=dd_NoError) dd_WriteErrorMessages(stdout,err); |
| 86 | |
| 87 | dd_free_global_constants(); /* At the end, this must be called. */ |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | |
| 92 | /* end of testcdd2.c */ |