Austin Schuh | 405fa6c | 2015-09-06 18:13:55 -0700 | [diff] [blame] | 1 | /* cddmp.c (cddlib arithmetic operations using gmp) |
| 2 | written by Komei Fukuda, fukuda@math.ethz.ch |
| 3 | Version 0.94h, April 30, 2015 |
| 4 | */ |
| 5 | /* This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; either version 2 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program; if not, write to the Free Software |
| 17 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 | */ |
| 19 | |
| 20 | #include "setoper.h" /* set operation library header (Ver. March 16,1995 or later) */ |
| 21 | #include "cdd.h" |
| 22 | |
| 23 | void dd_set_global_constants() |
| 24 | { |
| 25 | dd_init(dd_zero); |
| 26 | dd_init(dd_minuszero); |
| 27 | dd_init(dd_one); |
| 28 | dd_init(dd_minusone); |
| 29 | dd_init(dd_purezero); |
| 30 | |
| 31 | time(&dd_statStartTime); /* cddlib starting time */ |
| 32 | dd_statBApivots=0; /* basis finding pivots */ |
| 33 | dd_statCCpivots=0; /* criss-cross pivots */ |
| 34 | dd_statDS1pivots=0; /* phase 1 pivots */ |
| 35 | dd_statDS2pivots=0; /* phase 2 pivots */ |
| 36 | dd_statACpivots=0; /* anticycling (cc) pivots */ |
| 37 | |
| 38 | dd_choiceLPSolverDefault=dd_DualSimplex; /* Default LP solver Algorithm */ |
| 39 | dd_choiceRedcheckAlgorithm=dd_DualSimplex; /* Redundancy Checking Algorithm */ |
| 40 | dd_choiceLexicoPivotQ=dd_TRUE; /* whether to use the lexicographic pivot */ |
| 41 | |
| 42 | #if defined GMPRATIONAL |
| 43 | dd_statBSpivots=0; /* basis status checking pivots */ |
| 44 | mpq_set_ui(dd_zero,0U,1U); |
| 45 | mpq_set_ui(dd_purezero,0U,1U); |
| 46 | mpq_set_ui(dd_one,1U,1U); |
| 47 | mpq_set_si(dd_minusone,-1L,1U); |
| 48 | ddf_set_global_constants(); |
| 49 | #elif defined GMPFLOAT |
| 50 | mpf_set_d(dd_zero,dd_almostzero); |
| 51 | mpf_set_ui(dd_purezero,0U); |
| 52 | mpf_set_ui(dd_one,1U); |
| 53 | mpf_set_si(dd_minusone,-1L,1U); |
| 54 | #else |
| 55 | dd_zero[0]= dd_almostzero; /*real zero */ |
| 56 | dd_purezero[0]= 0.0; |
| 57 | dd_one[0]= 1L; |
| 58 | dd_minusone[0]= -1L; |
| 59 | #endif |
| 60 | dd_neg(dd_minuszero,dd_zero); |
| 61 | } |
| 62 | |
| 63 | void dd_free_global_constants() |
| 64 | { |
| 65 | dd_clear(dd_zero); |
| 66 | dd_clear(dd_minuszero); |
| 67 | dd_clear(dd_one); |
| 68 | dd_clear(dd_minusone); |
| 69 | dd_clear(dd_purezero); |
| 70 | |
| 71 | time(&dd_statStartTime); /* cddlib starting time */ |
| 72 | dd_statBApivots=0; /* basis finding pivots */ |
| 73 | dd_statCCpivots=0; /* criss-cross pivots */ |
| 74 | dd_statDS1pivots=0; /* phase 1 pivots */ |
| 75 | dd_statDS2pivots=0; /* phase 2 pivots */ |
| 76 | dd_statACpivots=0; /* anticycling (cc) pivots */ |
| 77 | |
| 78 | dd_choiceLPSolverDefault=dd_DualSimplex; /* Default LP solver Algorithm */ |
| 79 | dd_choiceRedcheckAlgorithm=dd_DualSimplex; /* Redundancy Checking Algorithm */ |
| 80 | dd_choiceLexicoPivotQ=dd_TRUE; /* whether to use the lexicographic pivot */ |
| 81 | |
| 82 | #if defined GMPRATIONAL |
| 83 | dd_statBSpivots=0; /* basis status checking pivots */ |
| 84 | ddf_free_global_constants(); |
| 85 | #endif |
| 86 | } |
| 87 | |
| 88 | |
| 89 | #if defined GMPRATIONAL |
| 90 | void ddd_mpq_set_si(mytype a,signed long b) |
| 91 | { |
| 92 | mpz_t nz, dz; |
| 93 | |
| 94 | mpz_init(nz); mpz_init(dz); |
| 95 | |
| 96 | mpz_set_si(nz, b); |
| 97 | mpz_set_ui(dz, 1U); |
| 98 | mpq_set_num(a, nz); |
| 99 | mpq_set_den(a, dz); |
| 100 | mpz_clear(nz); mpz_clear(dz); |
| 101 | } |
| 102 | #endif |
| 103 | |
| 104 | #if defined dd_CDOUBLE |
| 105 | void ddd_init(mytype a) |
| 106 | { |
| 107 | a[0]=0L; |
| 108 | } |
| 109 | |
| 110 | void ddd_clear(mytype a) |
| 111 | { |
| 112 | /* a[0]=0L; */ |
| 113 | } |
| 114 | |
| 115 | void ddd_set(mytype a,mytype b) |
| 116 | { |
| 117 | a[0]=b[0]; |
| 118 | } |
| 119 | |
| 120 | void ddd_set_d(mytype a,double b) |
| 121 | { |
| 122 | a[0]=b; |
| 123 | } |
| 124 | |
| 125 | void ddd_set_si(mytype a,signed long b) |
| 126 | { |
| 127 | a[0]=(double)b; |
| 128 | } |
| 129 | |
| 130 | void ddd_set_si2(mytype a,signed long b, unsigned long c) |
| 131 | { |
| 132 | a[0]=(double)b/(double)c; |
| 133 | } |
| 134 | |
| 135 | void ddd_add(mytype a,mytype b,mytype c) |
| 136 | { |
| 137 | a[0]=b[0]+c[0]; |
| 138 | } |
| 139 | |
| 140 | void ddd_sub(mytype a,mytype b,mytype c) |
| 141 | { |
| 142 | a[0]=b[0]-c[0]; |
| 143 | } |
| 144 | |
| 145 | void ddd_mul(mytype a,mytype b,mytype c) |
| 146 | { |
| 147 | a[0]=b[0]*c[0]; |
| 148 | } |
| 149 | |
| 150 | void ddd_div(mytype a,mytype b,mytype c) |
| 151 | { |
| 152 | a[0]=b[0]/c[0]; |
| 153 | } |
| 154 | |
| 155 | void ddd_neg(mytype a,mytype b) |
| 156 | { |
| 157 | a[0]=-b[0]; |
| 158 | } |
| 159 | |
| 160 | void ddd_inv(mytype a,mytype b) |
| 161 | { |
| 162 | a[0]=1/b[0]; |
| 163 | } |
| 164 | |
| 165 | int ddd_cmp(mytype a,mytype b) |
| 166 | { |
| 167 | if (a[0]-b[0]>0) return 1; |
| 168 | else if (a[0]-b[0]>=0) return 0; |
| 169 | else return -1; |
| 170 | } |
| 171 | |
| 172 | int ddd_sgn(mytype a) |
| 173 | { |
| 174 | if (a[0]>0) return 1; |
| 175 | else if (a[0]>=0) return 0; |
| 176 | else return -1; |
| 177 | } |
| 178 | |
| 179 | double ddd_get_d(mytype a) |
| 180 | { |
| 181 | return a[0]; |
| 182 | } |
| 183 | #endif |
| 184 | |
| 185 | /* end of cddmp.h */ |