[12] | 1 | /**CFile*********************************************************************** |
---|
| 2 | |
---|
| 3 | FileName [smtDebug.c] |
---|
| 4 | |
---|
| 5 | PackageName [smt] |
---|
| 6 | |
---|
| 7 | Synopsis [Routines for smt function.] |
---|
| 8 | |
---|
| 9 | Author [Hyondeuk Kim] |
---|
| 10 | |
---|
| 11 | Copyright [Copyright (c) 1995-2004, Regents of the University of Colorado |
---|
| 12 | |
---|
| 13 | All rights reserved. |
---|
| 14 | |
---|
| 15 | Redistribution and use in source and binary forms, with or without |
---|
| 16 | modification, are permitted provided that the following conditions |
---|
| 17 | are met: |
---|
| 18 | |
---|
| 19 | Redistributions of source code must retain the above copyright |
---|
| 20 | notice, this list of conditions and the following disclaimer. |
---|
| 21 | |
---|
| 22 | Redistributions in binary form must reproduce the above copyright |
---|
| 23 | notice, this list of conditions and the following disclaimer in the |
---|
| 24 | documentation and/or other materials provided with the distribution. |
---|
| 25 | |
---|
| 26 | Neither the name of the University of Colorado nor the names of its |
---|
| 27 | contributors may be used to endorse or promote products derived from |
---|
| 28 | this software without specific prior written permission. |
---|
| 29 | |
---|
| 30 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
| 31 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
| 32 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
---|
| 33 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
---|
| 34 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
---|
| 35 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
---|
| 36 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
---|
| 37 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
---|
| 38 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
| 39 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
---|
| 40 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
| 41 | POSSIBILITY OF SUCH DAMAGE.] |
---|
| 42 | |
---|
| 43 | ******************************************************************************/ |
---|
| 44 | |
---|
| 45 | #ifdef HAVE_LIBGMP |
---|
| 46 | |
---|
| 47 | #include "smt.h" |
---|
| 48 | |
---|
| 49 | void |
---|
| 50 | smt_print_atom_variable(smtManager_t * sm) |
---|
| 51 | { |
---|
| 52 | satManager_t * cm = sm->cm; |
---|
| 53 | smtAvar_t * avar; |
---|
| 54 | int value = 2; |
---|
| 55 | int i; |
---|
| 56 | |
---|
| 57 | for(i = 0; i < sm->avarArr->size; i++) { |
---|
| 58 | avar = (smtAvar_t *) sm->avarArr->space[i]; |
---|
| 59 | if (cm) value = cm->values[SATVar(avar->id)]; |
---|
| 60 | fprintf(stdout, "%d:%s:%d\n", avar->id, avar->name, value); |
---|
| 61 | } |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | void |
---|
| 65 | smt_print_atom_variable_in_array(smtManager_t * sm, satArray_t * avarArr) |
---|
| 66 | { |
---|
| 67 | satManager_t * cm = sm->cm; |
---|
| 68 | smtAvar_t * avar; |
---|
| 69 | int value = 2; |
---|
| 70 | int i; |
---|
| 71 | |
---|
| 72 | for(i = 0; i < avarArr->size; i++) { |
---|
| 73 | avar = (smtAvar_t *) avarArr->space[i]; |
---|
| 74 | if (cm) value = cm->values[SATVar(avar->id)]; |
---|
| 75 | fprintf(stdout, "%d:%s:%d\n", avar->id, avar->name, value); |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | void |
---|
| 80 | smt_print_numerical_variable(smtManager_t * sm) |
---|
| 81 | { |
---|
| 82 | smtNvar_t * nvar; |
---|
| 83 | int i; |
---|
| 84 | |
---|
| 85 | for(i = 0; i < sm->nvarArr->size; i++) { |
---|
| 86 | nvar = (smtNvar_t *) sm->nvarArr->space[i]; |
---|
| 87 | fprintf(stdout, "%d:%s\n", nvar->id, nvar->name); |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | void |
---|
| 92 | smt_print_numerical_variable_in_array( |
---|
| 93 | satArray_t * nvarArr) |
---|
| 94 | { |
---|
| 95 | smtNvar_t * nvar; |
---|
| 96 | int i; |
---|
| 97 | |
---|
| 98 | for(i = 0; i < nvarArr->size; i++) { |
---|
| 99 | nvar = (smtNvar_t *) nvarArr->space[i]; |
---|
| 100 | fprintf(stdout, "%d:%s\n", nvar->id, nvar->name); |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | void |
---|
| 105 | smt_print_nvar_with_value(smtManager_t * sm) |
---|
| 106 | { |
---|
| 107 | smtNvar_t *nvar; |
---|
| 108 | int i; |
---|
| 109 | |
---|
| 110 | for(i = 0; i < sm->nvarArr->size; i++) { |
---|
| 111 | nvar = (smtNvar_t *) sm->nvarArr->space[i]; |
---|
| 112 | if (sm->flag & IDL_MASK) |
---|
| 113 | fprintf(stdout, "%s=%d\n", nvar->name, sm->ivalues[nvar->id]); |
---|
| 114 | else if (sm->flag & RDL_MASK) |
---|
| 115 | fprintf(stdout, "%s=%g\n", nvar->name, sm->rvalues[nvar->id]); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | return; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | void |
---|
| 122 | smt_print_nvar_value_in_tableau(smtManager_t * sm) |
---|
| 123 | { |
---|
| 124 | smtNvar_t * nvar; |
---|
| 125 | double value; |
---|
| 126 | int i; |
---|
| 127 | |
---|
| 128 | for(i = 0; i < sm->tab_nvars->size; i++) { |
---|
| 129 | nvar = (smtNvar_t *) sm->tab_nvars->space[i]; |
---|
| 130 | value = sm->rvalues[nvar->id]; |
---|
| 131 | fprintf(stdout, "%s:%g\n", nvar->name, value); |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | void |
---|
| 136 | smt_check_nvar_value_with_tableau(smtManager_t * sm) |
---|
| 137 | { |
---|
| 138 | double * tab = sm->tab; |
---|
| 139 | smtNvar_t * nvar; |
---|
| 140 | double coeff, sum; |
---|
| 141 | int col, num_col, index; |
---|
| 142 | int i, j; |
---|
| 143 | |
---|
| 144 | num_col = sm->tab_nvars->size; |
---|
| 145 | |
---|
| 146 | for(i = 0; i < sm->basics->size; i++) { |
---|
| 147 | for(j = 0, sum = 0; j < sm->tab_nvars->size; j++) { |
---|
| 148 | nvar = (smtNvar_t *) sm->tab_nvars->space[j]; |
---|
| 149 | col = nvar->id; |
---|
| 150 | index = i * num_col + col; |
---|
| 151 | coeff = tab[index]; |
---|
| 152 | if (coeff <= 0 && coeff >= 0) continue; |
---|
| 153 | sum = sum + coeff * sm->rvalues[nvar->id]; |
---|
| 154 | } |
---|
| 155 | assert(sum==0); |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | void |
---|
| 160 | smt_print_nvar_bound_in_tableau(smtManager_t * sm) |
---|
| 161 | { |
---|
| 162 | smtNvar_t * nvar; |
---|
| 163 | smtBound_t * bound; |
---|
| 164 | int i; |
---|
| 165 | |
---|
| 166 | for(i = 0; i < sm->tab_nvars->size; i++) { |
---|
| 167 | nvar = (smtNvar_t *) sm->tab_nvars->space[i]; |
---|
| 168 | bound = &(sm->bounds[nvar->id]); |
---|
| 169 | fprintf(stdout, "%g <= %s <= %g\n", bound->lb, nvar->name, bound->ub); |
---|
| 170 | } |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | void |
---|
| 174 | smt_print_atom_for_slack(smtManager_t * sm) |
---|
| 175 | { |
---|
| 176 | smtAvar_t * avar; |
---|
| 177 | smtNvar_t * slack, * nvar; |
---|
| 178 | double coeff; |
---|
| 179 | int i, j; |
---|
| 180 | |
---|
| 181 | for(i = 0; i < sm->slacks->size; i++) { |
---|
| 182 | slack = (smtNvar_t *) sm->slacks->space[i]; |
---|
| 183 | avar = (smtAvar_t *) slack->avarArr->space[0]; |
---|
| 184 | fprintf(stdout, "%s:", slack->name); |
---|
| 185 | for(j = 0; j < avar->nvars->size; j++) { |
---|
| 186 | coeff = array_fetch(double, avar->coeffs, j); |
---|
| 187 | nvar = (smtNvar_t *) avar->nvars->space[j]; |
---|
| 188 | if (avar->flag & SIGNED_MASK) coeff = -coeff; |
---|
| 189 | fprintf(stdout, "%g*%s ", coeff, nvar->name); |
---|
| 190 | } |
---|
| 191 | fprintf(stdout, "\n"); |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | void |
---|
| 196 | smt_print_boolean_variable(smtManager_t * sm) |
---|
| 197 | { |
---|
| 198 | satManager_t * cm = sm->cm; |
---|
| 199 | smtBvar_t * bvar; |
---|
| 200 | int value = 2; |
---|
| 201 | int i; |
---|
| 202 | |
---|
| 203 | for(i = 0; i < sm->bvarArr->size; i++) { |
---|
| 204 | bvar = (smtBvar_t *) sm->bvarArr->space[i]; |
---|
| 205 | if (cm) value = cm->values[SATVar(bvar->id)]; |
---|
| 206 | fprintf(stdout, "%d:%s:%d\n", bvar->id, bvar->name, value); |
---|
| 207 | } |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | void |
---|
| 211 | smt_print_flet_pair(smtManager_t * sm) |
---|
| 212 | { |
---|
| 213 | smtFlet_t * flet; |
---|
| 214 | int i; |
---|
| 215 | char * fvar_str, * fml_str; |
---|
| 216 | |
---|
| 217 | for(i = 0; i < sm->fletArr->size; i++) { |
---|
| 218 | flet = (smtFlet_t *) sm->fletArr->space[i]; |
---|
| 219 | fvar_str = smt_convert_fml_to_string(flet->fvar_fml); |
---|
| 220 | fml_str = smt_convert_fml_to_string(flet->fml); |
---|
| 221 | fprintf(stdout, "%s <-> %s\n", fvar_str, fml_str); |
---|
| 222 | free(fvar_str); |
---|
| 223 | free(fml_str); |
---|
| 224 | } |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | void |
---|
| 228 | smt_print_cnf_to_smt_file(smtManager_t * sm) |
---|
| 229 | { |
---|
| 230 | FILE * fp; |
---|
| 231 | smtCls_t * cls; |
---|
| 232 | smtAvar_t * avar; |
---|
| 233 | smtBvar_t * bvar; |
---|
| 234 | smtNvar_t * nvar; |
---|
| 235 | satArray_t * clsArr = sm->clsArr; |
---|
| 236 | char * filename; |
---|
| 237 | int id, lit, i, j; |
---|
| 238 | |
---|
| 239 | if (sm->clsArr->size == 0) return; |
---|
| 240 | |
---|
| 241 | if (sm->filename) |
---|
| 242 | filename = util_strcat3(sm->filename, ".cnf.smt", ""); |
---|
| 243 | else |
---|
| 244 | return; |
---|
| 245 | |
---|
| 246 | fp = fopen(filename, "w"); |
---|
| 247 | |
---|
| 248 | fprintf(fp, "(benchmark %s\n", filename); |
---|
| 249 | fprintf(fp, ":source {\n"); |
---|
| 250 | fprintf(fp, "SMT Formula is translated by Hyondeuk Kim in CNF SMT-LIB format benchmark\n"); |
---|
| 251 | fprintf(fp, "}\n"); |
---|
| 252 | fprintf(fp, ":status unknown\n"); |
---|
| 253 | |
---|
| 254 | if (sm->flag & LIA_MASK) |
---|
| 255 | fprintf(fp, ":logic QF_LIA\n"); |
---|
| 256 | else if (sm->flag & LRA_MASK) |
---|
| 257 | fprintf(fp, ":logic QF_LRA\n"); |
---|
| 258 | else if (sm->flag & IDL_MASK) |
---|
| 259 | fprintf(fp, ":logic QF_IDL\n"); |
---|
| 260 | else if (sm->flag & RDL_MASK) |
---|
| 261 | fprintf(fp, ":logic QF_RDL\n"); |
---|
| 262 | |
---|
| 263 | for(i = 0; i < sm->bvarArr->size; i++) { |
---|
| 264 | bvar = (smtBvar_t *) sm->bvarArr->space[i]; |
---|
| 265 | fprintf(fp, " :extrapreds ((%s))\n", bvar->name); |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | for(i = 0; i < sm->nvarArr->size; i++) { |
---|
| 269 | nvar = (smtNvar_t *) sm->nvarArr->space[i]; |
---|
| 270 | if (sm->flag & LIA_MASK || sm->flag & IDL_MASK) |
---|
| 271 | fprintf(fp, " :extrafuns ((%s Int))\n", nvar->name); |
---|
| 272 | else if (sm->flag & LRA_MASK || sm->flag & RDL_MASK) |
---|
| 273 | fprintf(fp, " :extrafuns ((%s Real))\n", nvar->name); |
---|
| 274 | } |
---|
| 275 | |
---|
| 276 | fprintf(fp, ":formula\n"); |
---|
| 277 | |
---|
| 278 | fprintf(fp, "( and\n"); |
---|
| 279 | |
---|
| 280 | for(i = 0; i < clsArr->size; i++) { |
---|
| 281 | fprintf(fp, "( or "); |
---|
| 282 | cls = (smtCls_t *) clsArr->space[i]; |
---|
| 283 | for(j = 0; j < cls->litArr->size; j++) { |
---|
| 284 | lit = cls->litArr->space[j]; |
---|
| 285 | if (lit > 0) { |
---|
| 286 | id = lit; |
---|
| 287 | if (id > sm->avarArr->size) { |
---|
| 288 | bvar = (smtBvar_t *) sm->id2var->space[id]; |
---|
| 289 | fprintf(fp, "%s ", bvar->name); |
---|
| 290 | } else { |
---|
| 291 | avar = (smtAvar_t *) sm->id2var->space[id]; |
---|
| 292 | fprintf(fp, "%s ", avar->name); |
---|
| 293 | } |
---|
| 294 | } else { |
---|
| 295 | id = -lit; |
---|
| 296 | if (id > sm->avarArr->size) { |
---|
| 297 | bvar = (smtBvar_t *) sm->id2var->space[id]; |
---|
| 298 | fprintf(fp, "(not %s) ", bvar->name); |
---|
| 299 | } else { |
---|
| 300 | avar = (smtAvar_t *) sm->id2var->space[id]; |
---|
| 301 | fprintf(fp, "(not %s) ", avar->name); |
---|
| 302 | } |
---|
| 303 | } |
---|
| 304 | } |
---|
| 305 | |
---|
| 306 | fprintf(fp, " )\n"); |
---|
| 307 | } |
---|
| 308 | |
---|
| 309 | fprintf(fp, "))"); |
---|
| 310 | |
---|
| 311 | fclose(fp); |
---|
| 312 | |
---|
| 313 | free(filename); |
---|
| 314 | } |
---|
| 315 | |
---|
| 316 | void |
---|
| 317 | smt_print_cnf_to_smt_file_with_avar(smtManager_t * sm) |
---|
| 318 | { |
---|
| 319 | FILE * fp; |
---|
| 320 | smtCls_t * cls; |
---|
| 321 | smtAvar_t * avar; |
---|
| 322 | smtBvar_t * bvar; |
---|
| 323 | smtNvar_t * nvar; |
---|
| 324 | satArray_t * clsArr = sm->clsArr; |
---|
| 325 | char * filename; |
---|
| 326 | char * str_a, * str_b, * str_c, * str_d, * str_e; |
---|
| 327 | double coeff, tcoeff, constant, tconstant; |
---|
| 328 | int id, lit; |
---|
| 329 | int i, j, k; |
---|
| 330 | |
---|
| 331 | if (sm->clsArr->size == 0) return; |
---|
| 332 | |
---|
| 333 | if (sm->filename) |
---|
| 334 | filename = util_strcat3(sm->filename, ".cnf.smt", ""); |
---|
| 335 | else |
---|
| 336 | return; |
---|
| 337 | |
---|
| 338 | fp = fopen(filename, "w"); |
---|
| 339 | |
---|
| 340 | fprintf(fp, "(benchmark %s\n", filename); |
---|
| 341 | fprintf(fp, ":source {\n"); |
---|
| 342 | fprintf(fp, "SMT Formula is translated by Hyondeuk Kim in CNF SMT-LIB format benchmark\n"); |
---|
| 343 | fprintf(fp, "}\n"); |
---|
| 344 | fprintf(fp, ":status unknown\n"); |
---|
| 345 | |
---|
| 346 | if (sm->flag & LIA_MASK) |
---|
| 347 | fprintf(fp, ":logic QF_LIA\n"); |
---|
| 348 | else if (sm->flag & LRA_MASK) |
---|
| 349 | fprintf(fp, ":logic QF_LRA\n"); |
---|
| 350 | else if (sm->flag & IDL_MASK) |
---|
| 351 | fprintf(fp, ":logic QF_IDL\n"); |
---|
| 352 | else if (sm->flag & RDL_MASK) |
---|
| 353 | fprintf(fp, ":logic QF_RDL\n"); |
---|
| 354 | |
---|
| 355 | for(i = 0; i < sm->bvarArr->size; i++) { |
---|
| 356 | bvar = (smtBvar_t *) sm->bvarArr->space[i]; |
---|
| 357 | fprintf(fp, " :extrapreds ((%s))\n", bvar->name); |
---|
| 358 | } |
---|
| 359 | |
---|
| 360 | for(i = 0; i < sm->nvarArr->size; i++) { |
---|
| 361 | nvar = (smtNvar_t *) sm->nvarArr->space[i]; |
---|
| 362 | if (sm->flag & LIA_MASK || sm->flag & IDL_MASK) |
---|
| 363 | fprintf(fp, " :extrafuns ((%s Int))\n", nvar->name); |
---|
| 364 | else if (sm->flag & LRA_MASK || sm->flag & RDL_MASK) |
---|
| 365 | fprintf(fp, " :extrafuns ((%s Real))\n", nvar->name); |
---|
| 366 | } |
---|
| 367 | |
---|
| 368 | fprintf(fp, ":formula\n"); |
---|
| 369 | |
---|
| 370 | fprintf(fp, "( and\n"); |
---|
| 371 | |
---|
| 372 | str_b = (char *) malloc(sizeof(char) * 10); |
---|
| 373 | |
---|
| 374 | for(i = 0; i < clsArr->size; i++) { |
---|
| 375 | fprintf(fp, "( or "); |
---|
| 376 | cls = (smtCls_t *) clsArr->space[i]; |
---|
| 377 | for(j = 0; j < cls->litArr->size; j++) { |
---|
| 378 | lit = cls->litArr->space[j]; |
---|
| 379 | if (lit > 0) { |
---|
| 380 | id = lit; |
---|
| 381 | if (id > sm->avarArr->size) { |
---|
| 382 | bvar = (smtBvar_t *) sm->id2var->space[id]; |
---|
| 383 | fprintf(fp, "%s ", bvar->name); |
---|
| 384 | } else { |
---|
| 385 | avar = (smtAvar_t *) sm->id2var->space[id]; |
---|
| 386 | str_a = util_strsav("(<= (+ "); |
---|
| 387 | |
---|
| 388 | for(k = 0; k < avar->nvars->size; k++) { |
---|
| 389 | coeff = array_fetch(double, avar->coeffs, k); |
---|
| 390 | tcoeff = (coeff > 0) ? coeff : -coeff; |
---|
| 391 | sprintf(str_b, "%d", (int) tcoeff); |
---|
| 392 | nvar = (smtNvar_t *) avar->nvars->space[k]; |
---|
| 393 | if (coeff > 0) { |
---|
| 394 | str_c = util_strcat3("(* ", str_b, " "); |
---|
| 395 | str_d = util_strcat3(str_c, nvar->name, ") "); |
---|
| 396 | } else { |
---|
| 397 | str_c = util_strcat3("(* (~ ", str_b, ") "); |
---|
| 398 | str_d = util_strcat3(str_c, nvar->name, ") "); |
---|
| 399 | } |
---|
| 400 | str_e = str_a; |
---|
| 401 | str_a = util_strcat3(str_a, str_d, ""); |
---|
| 402 | free(str_c); |
---|
| 403 | free(str_d); |
---|
| 404 | free(str_e); |
---|
| 405 | } |
---|
| 406 | |
---|
| 407 | constant = avar->constant; |
---|
| 408 | tconstant = (constant >= 0) ? constant : -constant; |
---|
| 409 | if (constant >= 0) { |
---|
| 410 | sprintf(str_b, "%d", (int) tconstant); |
---|
| 411 | str_e = util_strsav(str_b); |
---|
| 412 | } else { |
---|
| 413 | sprintf(str_b, "%d", (int) tconstant); |
---|
| 414 | str_e = util_strcat3("(~ ", str_b, ") "); |
---|
| 415 | } |
---|
| 416 | str_c = util_strcat3(str_a, ") ", str_e); |
---|
| 417 | str_d = util_strcat3(str_c, " ) ", ""); |
---|
| 418 | fprintf(fp, "%s ", str_d); |
---|
| 419 | /* fprintf(stdout, "%s\n", str_d); */ |
---|
| 420 | free(str_a); |
---|
| 421 | free(str_c); |
---|
| 422 | free(str_d); |
---|
| 423 | free(str_e); |
---|
| 424 | } |
---|
| 425 | } else { |
---|
| 426 | id = -lit; |
---|
| 427 | if (id > sm->avarArr->size) { |
---|
| 428 | bvar = (smtBvar_t *) sm->id2var->space[id]; |
---|
| 429 | fprintf(fp, "(not %s) ", bvar->name); |
---|
| 430 | } else { |
---|
| 431 | avar = (smtAvar_t *) sm->id2var->space[id]; |
---|
| 432 | str_a = util_strsav("(<= (+ "); |
---|
| 433 | |
---|
| 434 | for(k = 0; k < avar->nvars->size; k++) { |
---|
| 435 | coeff = array_fetch(double, avar->coeffs, k); |
---|
| 436 | tcoeff = (coeff > 0) ? coeff : -coeff; |
---|
| 437 | sprintf(str_b, "%d", (int) tcoeff); |
---|
| 438 | nvar = (smtNvar_t *) avar->nvars->space[k]; |
---|
| 439 | if (coeff > 0) { |
---|
| 440 | str_c = util_strcat3("(* ", str_b, " "); |
---|
| 441 | str_d = util_strcat3(str_c, nvar->name, ") "); |
---|
| 442 | } else { |
---|
| 443 | str_c = util_strcat3("(* (~ ", str_b, ") "); |
---|
| 444 | str_d = util_strcat3(str_c, nvar->name, ") "); |
---|
| 445 | } |
---|
| 446 | str_e = str_a; |
---|
| 447 | str_a = util_strcat3(str_a, str_d, ""); |
---|
| 448 | free(str_c); |
---|
| 449 | free(str_d); |
---|
| 450 | free(str_e); |
---|
| 451 | } |
---|
| 452 | |
---|
| 453 | constant = avar->constant; |
---|
| 454 | tconstant = (constant >= 0) ? constant : -constant; |
---|
| 455 | if (constant >= 0) { |
---|
| 456 | sprintf(str_b, "%d", (int) tconstant); |
---|
| 457 | str_e = util_strsav(str_b); |
---|
| 458 | } else { |
---|
| 459 | sprintf(str_b, "%d", (int) tconstant); |
---|
| 460 | str_e = util_strcat3("(~ ", str_b, ") "); |
---|
| 461 | } |
---|
| 462 | |
---|
| 463 | str_c = util_strcat3(str_a, ") ", str_e); |
---|
| 464 | str_d = util_strcat3(str_c, " ) ", ""); |
---|
| 465 | fprintf(fp, "(not %s) ", str_d); |
---|
| 466 | free(str_a); |
---|
| 467 | free(str_c); |
---|
| 468 | free(str_d); |
---|
| 469 | free(str_e); |
---|
| 470 | } |
---|
| 471 | } |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | fprintf(fp, " )\n"); |
---|
| 475 | } |
---|
| 476 | |
---|
| 477 | fprintf(fp, "))"); |
---|
| 478 | |
---|
| 479 | fclose(fp); |
---|
| 480 | |
---|
| 481 | free(filename); |
---|
| 482 | free(str_b); |
---|
| 483 | } |
---|
| 484 | |
---|
| 485 | void |
---|
| 486 | smt_print_dimacs_to_smt_file(smtManager_t * sm) |
---|
| 487 | { |
---|
| 488 | FILE * fp; |
---|
| 489 | satManager_t * cm = sm->cm; |
---|
| 490 | satClause_t * c; |
---|
| 491 | smtAvar_t * avar; |
---|
| 492 | smtBvar_t * bvar; |
---|
| 493 | smtNvar_t * nvar; |
---|
| 494 | satArray_t * arr = cm->clauses; |
---|
| 495 | char * filename, * str_a, * str_b; |
---|
| 496 | int * vflags; |
---|
| 497 | long lit, v; |
---|
| 498 | int id, i, j, csize, value; |
---|
| 499 | |
---|
| 500 | if (arr->size == 0) return; |
---|
| 501 | |
---|
| 502 | if (sm->filename) |
---|
| 503 | filename = util_strcat3(sm->filename, ".dimacs.cnf.smt", ""); |
---|
| 504 | else |
---|
| 505 | return; |
---|
| 506 | |
---|
| 507 | vflags = (int *) malloc(sizeof(int) * sm->id2var->size); |
---|
| 508 | |
---|
| 509 | memset(vflags, 0, sizeof(int) * sm->id2var->size); |
---|
| 510 | |
---|
| 511 | for(i = 0; i < arr->size; i++) { |
---|
| 512 | c = (satClause_t *)arr->space[i]; |
---|
| 513 | csize = SATSizeClause(c); |
---|
| 514 | for(j = 0; j < csize; j++) { |
---|
| 515 | lit = c->lits[j]; |
---|
| 516 | v = lit >> 1; |
---|
| 517 | v = lit&1 ? -v : v; |
---|
| 518 | |
---|
| 519 | if (v > 0) |
---|
| 520 | id = (int) v; |
---|
| 521 | else |
---|
| 522 | id = (int) -v; |
---|
| 523 | |
---|
| 524 | vflags[id] = 1; |
---|
| 525 | } |
---|
| 526 | } |
---|
| 527 | |
---|
| 528 | fp = fopen(filename, "w"); |
---|
| 529 | |
---|
| 530 | fprintf(fp, "(benchmark %s\n", filename); |
---|
| 531 | fprintf(fp, ":source {\n"); |
---|
| 532 | fprintf(fp, "SMT Formula is translated by Hyondeuk Kim in CNF SMT-LIB format benchmark\n"); |
---|
| 533 | fprintf(fp, "}\n"); |
---|
| 534 | fprintf(fp, ":status unknown\n"); |
---|
| 535 | |
---|
| 536 | if (sm->flag & LIA_MASK) |
---|
| 537 | fprintf(fp, ":logic QF_LIA\n"); |
---|
| 538 | else if (sm->flag & LRA_MASK) |
---|
| 539 | fprintf(fp, ":logic QF_LRA\n"); |
---|
| 540 | else if (sm->flag & IDL_MASK) |
---|
| 541 | fprintf(fp, ":logic QF_IDL\n"); |
---|
| 542 | else if (sm->flag & RDL_MASK) |
---|
| 543 | fprintf(fp, ":logic QF_RDL\n"); |
---|
| 544 | |
---|
| 545 | for(i = 0; i < sm->bvarArr->size; i++) { |
---|
| 546 | bvar = (smtBvar_t *) sm->bvarArr->space[i]; |
---|
| 547 | if (vflags[bvar->id] && |
---|
| 548 | !(bvar->flag & BTRUE_MASK) && !(bvar->flag & BFALSE_MASK) ) |
---|
| 549 | fprintf(fp, " :extrapreds ((%s))\n", bvar->name); |
---|
| 550 | } |
---|
| 551 | |
---|
| 552 | for(i = 0; i < sm->nvarArr->size; i++) { |
---|
| 553 | nvar = (smtNvar_t *) sm->nvarArr->space[i]; |
---|
| 554 | if (sm->flag & LIA_MASK || sm->flag & IDL_MASK) |
---|
| 555 | fprintf(fp, " :extrafuns ((%s Int))\n", nvar->name); |
---|
| 556 | else if (sm->flag & LRA_MASK || sm->flag & RDL_MASK) |
---|
| 557 | fprintf(fp, " :extrafuns ((%s Real))\n", nvar->name); |
---|
| 558 | } |
---|
| 559 | |
---|
| 560 | fprintf(fp, ":formula\n"); |
---|
| 561 | |
---|
| 562 | fprintf(fp, "( and\n"); |
---|
| 563 | |
---|
| 564 | for(i = 0; i < arr->size; i++) { |
---|
| 565 | c = (satClause_t *)arr->space[i]; |
---|
| 566 | csize = SATSizeClause(c); |
---|
| 567 | for(j = 0, str_a = 0; j < csize; j++) { |
---|
| 568 | lit = c->lits[j]; |
---|
| 569 | v = lit >> 1; |
---|
| 570 | #if 1 |
---|
| 571 | if((cm->values[v] ^ (lit&1)) == 1) { |
---|
| 572 | if (str_a) { /* satisfied clause */ |
---|
| 573 | free(str_a); |
---|
| 574 | str_a = 0; |
---|
| 575 | } |
---|
| 576 | break; |
---|
| 577 | } /* cm->values[v] can be somehow 64, 85, ... */ |
---|
| 578 | else if (cm->values[v] == 1 || cm->values[v] == 0) { |
---|
| 579 | continue; /* unsat lit in clause : remove lit in clause */ |
---|
| 580 | } |
---|
| 581 | #endif |
---|
| 582 | v = lit&1 ? -v : v; |
---|
| 583 | |
---|
| 584 | if (v > 0) { |
---|
| 585 | id = (int) v; |
---|
| 586 | |
---|
| 587 | if (id > sm->avarArr->size) { |
---|
| 588 | bvar = (smtBvar_t *) sm->id2var->space[id]; |
---|
| 589 | str_b = str_a; |
---|
| 590 | if (str_a) |
---|
| 591 | str_a = util_strcat3(str_a, bvar->name, " "); |
---|
| 592 | else |
---|
| 593 | str_a = util_strcat3("", bvar->name, " "); |
---|
| 594 | if (str_b) free(str_b); |
---|
| 595 | } else { |
---|
| 596 | avar = (smtAvar_t *) sm->id2var->space[id]; |
---|
| 597 | str_b = str_a; |
---|
| 598 | if (str_a) |
---|
| 599 | str_a = util_strcat3(str_a, avar->name, " "); |
---|
| 600 | else |
---|
| 601 | str_a = util_strcat3("", avar->name, " "); |
---|
| 602 | if (str_b) free(str_b); |
---|
| 603 | } |
---|
| 604 | } else { |
---|
| 605 | id = (int) -v; |
---|
| 606 | |
---|
| 607 | if (id > sm->avarArr->size) { |
---|
| 608 | bvar = (smtBvar_t *) sm->id2var->space[id]; |
---|
| 609 | str_b = str_a; |
---|
| 610 | if (str_a) |
---|
| 611 | str_a = util_strcat3(str_a, "(not ", bvar->name); |
---|
| 612 | else |
---|
| 613 | str_a = util_strcat3("", "(not ", bvar->name); |
---|
| 614 | if (str_b) free(str_b); |
---|
| 615 | str_b = str_a; |
---|
| 616 | str_a = util_strcat3(str_a, ") ", ""); |
---|
| 617 | if (str_b) free(str_b); |
---|
| 618 | } else { |
---|
| 619 | avar = (smtAvar_t *) sm->id2var->space[id]; |
---|
| 620 | str_b = str_a; |
---|
| 621 | if (str_a) |
---|
| 622 | str_a = util_strcat3(str_a, "(not ", avar->name); |
---|
| 623 | else |
---|
| 624 | str_a = util_strcat3("", "(not ", avar->name); |
---|
| 625 | if (str_b) free(str_b); |
---|
| 626 | str_b = str_a; |
---|
| 627 | str_a = util_strcat3(str_a, ") ", ""); |
---|
| 628 | if (str_b) free(str_b); |
---|
| 629 | } |
---|
| 630 | } |
---|
| 631 | } |
---|
| 632 | |
---|
| 633 | if (str_a) { |
---|
| 634 | str_b = util_strcat3("( or ", str_a, " )\n"); |
---|
| 635 | fprintf(fp, "%s", str_b); |
---|
| 636 | free(str_a); |
---|
| 637 | free(str_b); |
---|
| 638 | } |
---|
| 639 | } |
---|
| 640 | |
---|
| 641 | /* require assigned predicates */ |
---|
| 642 | for(i = 0; i < sm->avarArr->size; i++) { |
---|
| 643 | avar = (smtAvar_t *) sm->avarArr->space[i]; |
---|
| 644 | id = avar->id; |
---|
| 645 | value = cm->values[id]; |
---|
| 646 | if (value == 1) |
---|
| 647 | fprintf(fp, "%s\n", avar->name); |
---|
| 648 | else if (value == 0) |
---|
| 649 | fprintf(fp, "(not %s)\n", avar->name); |
---|
| 650 | } |
---|
| 651 | #if 0 |
---|
| 652 | for(i = 0; i < sm->bvarArr->size; i++) { |
---|
| 653 | bvar = (smtBvar_t *) sm->bvarArr->space[i]; |
---|
| 654 | id = bvar->id; |
---|
| 655 | value = cm->values[id]; |
---|
| 656 | if (value == 1) |
---|
| 657 | fprintf(fp, "%s\n", bvar->name); |
---|
| 658 | else if (value == 0) |
---|
| 659 | fprintf(fp, "(not %s)\n", bvar->name); |
---|
| 660 | } |
---|
| 661 | #endif |
---|
| 662 | fprintf(fp, "))"); |
---|
| 663 | |
---|
| 664 | fclose(fp); |
---|
| 665 | |
---|
| 666 | free(filename); |
---|
| 667 | |
---|
| 668 | free(vflags); |
---|
| 669 | } |
---|
| 670 | |
---|
| 671 | void |
---|
| 672 | smt_print_cnf_to_dimcas_file(smtManager_t * sm) |
---|
| 673 | { |
---|
| 674 | FILE * fp; |
---|
| 675 | smtCls_t * cls; |
---|
| 676 | smtAvar_t * avar; |
---|
| 677 | smtBvar_t * bvar; |
---|
| 678 | satArray_t * clsArr = sm->clsArr; |
---|
| 679 | char * filename; |
---|
| 680 | int id, lit, i, j; |
---|
| 681 | |
---|
| 682 | if (sm->clsArr->size == 0) return; |
---|
| 683 | |
---|
| 684 | if (sm->filename) |
---|
| 685 | filename = util_strcat3(sm->filename, ".cnf", ""); |
---|
| 686 | else |
---|
| 687 | return; |
---|
| 688 | |
---|
| 689 | fp = fopen(filename, "w"); |
---|
| 690 | |
---|
| 691 | fprintf(fp, "p cnf %ld %ld\n", sm->id2var->size, sm->clsArr->size); |
---|
| 692 | |
---|
| 693 | for(i = 0; i < sm->bvarArr->size; i++) { |
---|
| 694 | bvar = (smtBvar_t *) sm->bvarArr->space[i]; |
---|
| 695 | fprintf(fp, "c %d:((%s))\n", bvar->id, bvar->name); |
---|
| 696 | } |
---|
| 697 | for(i = 0; i < sm->avarArr->size; i++) { |
---|
| 698 | avar = (smtAvar_t *) sm->avarArr->space[i]; |
---|
| 699 | fprintf(fp, "c %d:((%s))\n", avar->id, avar->name); |
---|
| 700 | } |
---|
| 701 | |
---|
| 702 | for(i = 0; i < clsArr->size; i++) { |
---|
| 703 | cls = (smtCls_t *) clsArr->space[i]; |
---|
| 704 | for(j = 0; j < cls->litArr->size; j++) { |
---|
| 705 | lit = cls->litArr->space[j]; |
---|
| 706 | if (lit > 0) { |
---|
| 707 | id = lit; |
---|
| 708 | if (id > sm->avarArr->size) { |
---|
| 709 | bvar = (smtBvar_t *) sm->id2var->space[id]; |
---|
| 710 | fprintf(fp, "%d ", bvar->id); |
---|
| 711 | } else { |
---|
| 712 | avar = (smtAvar_t *) sm->id2var->space[id]; |
---|
| 713 | fprintf(fp, "%d ", avar->id); |
---|
| 714 | } |
---|
| 715 | } else { |
---|
| 716 | id = -lit; |
---|
| 717 | if (id > sm->avarArr->size) { |
---|
| 718 | bvar = (smtBvar_t *) sm->id2var->space[id]; |
---|
| 719 | fprintf(fp, "%d ", -bvar->id); |
---|
| 720 | } else { |
---|
| 721 | avar = (smtAvar_t *) sm->id2var->space[id]; |
---|
| 722 | fprintf(fp, "%d ", -avar->id); |
---|
| 723 | } |
---|
| 724 | } |
---|
| 725 | } |
---|
| 726 | |
---|
| 727 | fprintf(fp, "0\n"); |
---|
| 728 | } |
---|
| 729 | |
---|
| 730 | fclose(fp); |
---|
| 731 | |
---|
| 732 | free(filename); |
---|
| 733 | } |
---|
| 734 | |
---|
| 735 | void |
---|
| 736 | smt_print_fml_to_smt_file(smtManager_t * sm, smtFml_t * fml, int index) |
---|
| 737 | { |
---|
| 738 | FILE * fp; |
---|
| 739 | smtBvar_t * bvar; |
---|
| 740 | smtNvar_t * nvar; |
---|
| 741 | satArray_t * bvarArr; |
---|
| 742 | char * filename, * num, * str; |
---|
| 743 | int i; |
---|
| 744 | |
---|
| 745 | if (sm->filename) { |
---|
| 746 | num = (char *) malloc(sizeof(char) * 10); |
---|
| 747 | memset(num, 0, sizeof(char) * 10); |
---|
| 748 | sprintf(num, ".%d", index); |
---|
| 749 | filename = util_strcat3(sm->filename, num, ".sub_fml.smt"); |
---|
| 750 | free(num); |
---|
| 751 | } else |
---|
| 752 | return; |
---|
| 753 | |
---|
| 754 | fp = fopen(filename, "w"); |
---|
| 755 | |
---|
| 756 | fprintf(fp, "(benchmark %s\n", filename); |
---|
| 757 | fprintf(fp, ":source {\n"); |
---|
| 758 | fprintf(fp, "SMT Formula is translated by Hyondeuk Kim in CNF SMT-LIB format benchmark\n"); |
---|
| 759 | fprintf(fp, "}\n"); |
---|
| 760 | fprintf(fp, ":status unknown\n"); |
---|
| 761 | |
---|
| 762 | if (sm->flag & LIA_MASK) |
---|
| 763 | fprintf(fp, ":logic QF_LIA\n"); |
---|
| 764 | else if (sm->flag & LRA_MASK) |
---|
| 765 | fprintf(fp, ":logic QF_LRA\n"); |
---|
| 766 | else if (sm->flag & IDL_MASK) |
---|
| 767 | fprintf(fp, ":logic QF_IDL\n"); |
---|
| 768 | else if (sm->flag & RDL_MASK) |
---|
| 769 | fprintf(fp, ":logic QF_RDL\n"); |
---|
| 770 | |
---|
| 771 | bvarArr = smt_gather_bvar_in_fml(sm, fml); |
---|
| 772 | |
---|
| 773 | for(i = 0; i < bvarArr->size; i++) { |
---|
| 774 | bvar = (smtBvar_t *) bvarArr->space[i]; |
---|
| 775 | fprintf(fp, " :extrapreds ((%s))\n", bvar->name); |
---|
| 776 | } |
---|
| 777 | |
---|
| 778 | for(i = 0; i < sm->nvarArr->size; i++) { |
---|
| 779 | nvar = (smtNvar_t *) sm->nvarArr->space[i]; |
---|
| 780 | if (sm->flag & LIA_MASK || sm->flag & IDL_MASK) |
---|
| 781 | fprintf(fp, " :extrafuns ((%s Int))\n", nvar->name); |
---|
| 782 | else if (sm->flag & LRA_MASK || sm->flag & RDL_MASK) |
---|
| 783 | fprintf(fp, " :extrafuns ((%s Real))\n", nvar->name); |
---|
| 784 | } |
---|
| 785 | |
---|
| 786 | fprintf(fp, ":formula\n"); |
---|
| 787 | |
---|
| 788 | str = smt_convert_fml_to_string(fml); |
---|
| 789 | |
---|
| 790 | fprintf(fp, "%s\n", str); |
---|
| 791 | |
---|
| 792 | fprintf(fp, ")"); |
---|
| 793 | |
---|
| 794 | fclose(fp); |
---|
| 795 | |
---|
| 796 | free(filename); |
---|
| 797 | free(bvarArr); |
---|
| 798 | free(str); |
---|
| 799 | |
---|
| 800 | return; |
---|
| 801 | } |
---|
| 802 | |
---|
| 803 | void |
---|
| 804 | smt_print_fml_to_file(smtManager_t * sm, smtFml_t * fml) |
---|
| 805 | { |
---|
| 806 | FILE * fp; |
---|
| 807 | smtBvar_t * bvar; |
---|
| 808 | smtNvar_t * nvar; |
---|
| 809 | satArray_t * bvarArr = 0; |
---|
| 810 | char * filename; |
---|
| 811 | int i; |
---|
| 812 | |
---|
| 813 | if (sm->filename) |
---|
| 814 | filename = util_strcat3(sm->filename, ".sub_fml.smt", ""); |
---|
| 815 | else |
---|
| 816 | return; |
---|
| 817 | |
---|
| 818 | fp = fopen(filename, "w"); |
---|
| 819 | |
---|
| 820 | fprintf(fp, "(benchmark %s\n", filename); |
---|
| 821 | fprintf(fp, ":source {\n"); |
---|
| 822 | fprintf(fp, "SMT Formula is translated by Hyondeuk Kim in CNF SMT-LIB format benchmark\n"); |
---|
| 823 | fprintf(fp, "}\n"); |
---|
| 824 | fprintf(fp, ":status unknown\n"); |
---|
| 825 | |
---|
| 826 | if (sm->flag & LIA_MASK) |
---|
| 827 | fprintf(fp, ":logic QF_LIA\n"); |
---|
| 828 | else if (sm->flag & LRA_MASK) |
---|
| 829 | fprintf(fp, ":logic QF_LRA\n"); |
---|
| 830 | else if (sm->flag & IDL_MASK) |
---|
| 831 | fprintf(fp, ":logic QF_IDL\n"); |
---|
| 832 | else if (sm->flag & RDL_MASK) |
---|
| 833 | fprintf(fp, ":logic QF_RDL\n"); |
---|
| 834 | |
---|
| 835 | for(i = 0; i < bvarArr->size; i++) { |
---|
| 836 | bvar = (smtBvar_t *) bvarArr->space[i]; |
---|
| 837 | fprintf(fp, " :extrapreds ((%s))\n", bvar->name); |
---|
| 838 | } |
---|
| 839 | |
---|
| 840 | for(i = 0; i < sm->nvarArr->size; i++) { |
---|
| 841 | nvar = (smtNvar_t *) sm->nvarArr->space[i]; |
---|
| 842 | if (sm->flag & LIA_MASK || sm->flag & IDL_MASK) |
---|
| 843 | fprintf(fp, " :extrafuns ((%s Int))\n", nvar->name); |
---|
| 844 | else if (sm->flag & LRA_MASK || sm->flag & RDL_MASK) |
---|
| 845 | fprintf(fp, " :extrafuns ((%s Real))\n", nvar->name); |
---|
| 846 | } |
---|
| 847 | |
---|
| 848 | fprintf(fp, ":formula\n"); |
---|
| 849 | |
---|
| 850 | fprintf(fp, "%s\n", smt_convert_fml_to_string(fml)); |
---|
| 851 | |
---|
| 852 | fprintf(fp, ")"); |
---|
| 853 | |
---|
| 854 | fclose(fp); |
---|
| 855 | |
---|
| 856 | free(filename); |
---|
| 857 | } |
---|
| 858 | |
---|
| 859 | void |
---|
| 860 | smt_print_aig_to_dot_file(Aig_Manager_t * bm) |
---|
| 861 | { |
---|
| 862 | FILE *fp; |
---|
| 863 | |
---|
| 864 | fp = fopen("aig.dot", "w"); |
---|
| 865 | Aig_PrintDot(fp, bm); |
---|
| 866 | |
---|
| 867 | fclose(fp); |
---|
| 868 | } |
---|
| 869 | |
---|
| 870 | void |
---|
| 871 | smt_print_lit_in_array(smtManager_t * sm, satArray_t * litArr) |
---|
| 872 | { |
---|
| 873 | satManager_t * cm = sm->cm; |
---|
| 874 | smtAvar_t * avar; |
---|
| 875 | int lit, id; |
---|
| 876 | int i; |
---|
| 877 | |
---|
| 878 | for(i = 0; i < litArr->size; i++) { |
---|
| 879 | lit = litArr->space[i]; |
---|
| 880 | id = (lit > 0) ? lit : -lit; |
---|
| 881 | avar = (smtAvar_t *) sm->id2var->space[id]; |
---|
| 882 | if (avar) { |
---|
| 883 | if (lit>0) fprintf(stdout, "%d:%s:flag:%d:level:%ld\n", |
---|
| 884 | avar->id, avar->name, avar->flag, cm->levels[id]); |
---|
| 885 | else if(lit<0) fprintf(stdout, "%d:!%s:flag:%d:level:%ld\n", |
---|
| 886 | avar->id, avar->name, avar->flag, |
---|
| 887 | cm->levels[id]); |
---|
| 888 | else fprintf(stdout, "ERROR: %d:?%s:flag:%d:level:%ld\n", |
---|
| 889 | avar->id, avar->name, avar->flag, cm->levels[id]); |
---|
| 890 | } |
---|
| 891 | } |
---|
| 892 | } |
---|
| 893 | |
---|
| 894 | void |
---|
| 895 | smt_print_lit_in_array_hor(smtManager_t * sm, satArray_t * litArr) |
---|
| 896 | { |
---|
| 897 | satManager_t * cm = sm->cm; |
---|
| 898 | smtAvar_t * avar; |
---|
| 899 | int lit, id; |
---|
| 900 | int i; |
---|
| 901 | |
---|
| 902 | for(i = 0; i < litArr->size; i++) { |
---|
| 903 | lit = litArr->space[i]; |
---|
| 904 | id = (lit > 0) ? lit : -lit; |
---|
| 905 | avar = (smtAvar_t *) sm->id2var->space[id]; |
---|
| 906 | if (avar) { |
---|
| 907 | if (lit>0) fprintf(stdout, "%d ", avar->id); |
---|
| 908 | else if(lit<0) fprintf(stdout, "%d ", avar->id); |
---|
| 909 | else fprintf(stdout, "ERROR: %d:?%s:flag:%d:level:%ld\n", |
---|
| 910 | avar->id, avar->name, avar->flag, cm->levels[id]); |
---|
| 911 | } |
---|
| 912 | } |
---|
| 913 | if (litArr->size) fprintf(stdout, "\n"); |
---|
| 914 | } |
---|
| 915 | |
---|
| 916 | void |
---|
| 917 | smt_print_sat_lit_in_array(smtManager_t * sm, satArray_t * litArr) |
---|
| 918 | { |
---|
| 919 | satManager_t * cm = sm->cm; |
---|
| 920 | smtAvar_t * avar; |
---|
| 921 | int lit, id; |
---|
| 922 | int i; |
---|
| 923 | |
---|
| 924 | for(i = 0; i < litArr->size; i++) { |
---|
| 925 | lit = litArr->space[i]; |
---|
| 926 | id = lit >> 1; |
---|
| 927 | avar = (smtAvar_t *) sm->id2var->space[id]; |
---|
| 928 | if (avar) { |
---|
| 929 | if (lit % 2 == 1) |
---|
| 930 | fprintf(stdout, "%d:%s:flag:%d:level:%ld\n", |
---|
| 931 | avar->id, avar->name, avar->flag, cm->levels[id]); |
---|
| 932 | else if(lit % 2 == 0) fprintf(stdout, "%d:!%s:flag:%d:level:%ld\n", |
---|
| 933 | avar->id, avar->name, avar->flag, |
---|
| 934 | cm->levels[id]); |
---|
| 935 | else fprintf(stdout, "ERROR: %d:?%s:flag:%d:level:%ld\n", |
---|
| 936 | avar->id, avar->name, avar->flag, cm->levels[id]); |
---|
| 937 | } |
---|
| 938 | } |
---|
| 939 | } |
---|
| 940 | |
---|
| 941 | |
---|
| 942 | void |
---|
| 943 | smt_print_idl_digraph_to_dot_file(smtGraph_t * G, char * filename) |
---|
| 944 | { |
---|
| 945 | FILE * fp; |
---|
| 946 | smtVertex_t * src, * dest; |
---|
| 947 | smtEdge_t * e; |
---|
| 948 | smtNvar_t * rnvar, * lnvar; |
---|
| 949 | int i; |
---|
| 950 | |
---|
| 951 | fp = fopen(filename, "w"); |
---|
| 952 | fprintf(fp, "digraph \"G\" {\n"); |
---|
| 953 | fprintf(fp, " rotate=90;\n"); |
---|
| 954 | fprintf(fp, " margin=0.5;\n"); |
---|
| 955 | fprintf(fp, " label=\"G\";\n"); |
---|
| 956 | fprintf(fp, " size=\"10, 7, 5\";\n"); |
---|
| 957 | |
---|
| 958 | for(i = 0; i < G->esize; i++) { |
---|
| 959 | e = &(G->eHead[i]); |
---|
| 960 | src = e->src; |
---|
| 961 | dest = e->dest; |
---|
| 962 | rnvar = (smtNvar_t *) G->nvarArr->space[src->index]; |
---|
| 963 | lnvar = (smtNvar_t *) G->nvarArr->space[dest->index]; |
---|
| 964 | |
---|
| 965 | if(G->paths[dest->index] == src) |
---|
| 966 | fprintf(fp, " \"%d.%s:%d\" -> \"%d.%s:%d\" [color = red, label=\"%g\"];\n", |
---|
| 967 | src->index, rnvar->name, G->idists[src->index], dest->index, |
---|
| 968 | lnvar->name, G->idists[dest->index], e->weight); |
---|
| 969 | else |
---|
| 970 | fprintf(fp, " \"%d.%s:%d\" -> \"%d.%s:%d\" [color = black, label=\"%g\"];\n", |
---|
| 971 | src->index, rnvar->name, G->idists[src->index], dest->index, |
---|
| 972 | lnvar->name, G->idists[dest->index], e->weight); |
---|
| 973 | } |
---|
| 974 | |
---|
| 975 | fprintf(fp, "}\n"); |
---|
| 976 | fclose(fp); |
---|
| 977 | } |
---|
| 978 | |
---|
| 979 | void |
---|
| 980 | smt_print_rdl_digraph_to_dot_file(smtGraph_t * G, char * filename) |
---|
| 981 | { |
---|
| 982 | FILE * fp; |
---|
| 983 | smtVertex_t * src, * dest; |
---|
| 984 | smtEdge_t * e; |
---|
| 985 | smtNvar_t * rnvar, * lnvar; |
---|
| 986 | int i; |
---|
| 987 | |
---|
| 988 | fp = fopen(filename, "w"); |
---|
| 989 | fprintf(fp, "digraph \"G\" {\n"); |
---|
| 990 | fprintf(fp, " rotate=90;\n"); |
---|
| 991 | fprintf(fp, " margin=0.5;\n"); |
---|
| 992 | fprintf(fp, " label=\"G\";\n"); |
---|
| 993 | fprintf(fp, " size=\"10, 7, 5\";\n"); |
---|
| 994 | |
---|
| 995 | for(i = 0; i < G->esize; i++) { |
---|
| 996 | e = &(G->eHead[i]); |
---|
| 997 | src = e->src; |
---|
| 998 | dest = e->dest; |
---|
| 999 | rnvar = (smtNvar_t *) G->nvarArr->space[src->index]; |
---|
| 1000 | lnvar = (smtNvar_t *) G->nvarArr->space[dest->index]; |
---|
| 1001 | |
---|
| 1002 | if(G->paths[dest->index] == src) |
---|
| 1003 | fprintf(fp, " \"%d.%s:%g\" -> \"%d.%s:%g\" [color = red, label=\"%g\"];\n", |
---|
| 1004 | src->index, rnvar->name, G->rdists[src->index], dest->index, |
---|
| 1005 | lnvar->name, G->rdists[dest->index], e->weight); |
---|
| 1006 | else |
---|
| 1007 | fprintf(fp, " \"%d.%s:%g\" -> \"%d.%s:%g\" [color = black, label=\"%g\"];\n", |
---|
| 1008 | src->index, rnvar->name, G->rdists[src->index], dest->index, |
---|
| 1009 | lnvar->name, G->rdists[dest->index], e->weight); |
---|
| 1010 | } |
---|
| 1011 | |
---|
| 1012 | fprintf(fp, "}\n"); |
---|
| 1013 | fclose(fp); |
---|
| 1014 | } |
---|
| 1015 | |
---|
| 1016 | void |
---|
| 1017 | smt_print_variable_to_smt_file(smtManager_t * sm, FILE * fp) |
---|
| 1018 | { |
---|
| 1019 | smtBvar_t * bvar; |
---|
| 1020 | smtNvar_t * nvar; |
---|
| 1021 | int i; |
---|
| 1022 | |
---|
| 1023 | for(i = 0; i < sm->bvarArr->size; i++) { |
---|
| 1024 | bvar = (smtBvar_t *) sm->bvarArr->space[i]; |
---|
| 1025 | if (! strcmp(bvar->name, "true") || ! strcmp(bvar->name, "false")) |
---|
| 1026 | continue; |
---|
| 1027 | fprintf(fp, ":extrapreds ((%s))\n", bvar->name); |
---|
| 1028 | } |
---|
| 1029 | |
---|
| 1030 | for(i = 0; i < sm->nvarArr->size; i++) { |
---|
| 1031 | nvar = (smtNvar_t *) sm->nvarArr->space[i]; |
---|
| 1032 | if (sm->flag & RDL_MASK) |
---|
| 1033 | fprintf(fp, ":extrafuns ((%s Real))\n", nvar->name); |
---|
| 1034 | else if (sm->flag & IDL_MASK || sm->flag & LIA_MASK) |
---|
| 1035 | fprintf(fp, ":extrafuns ((%s Int))\n", nvar->name); |
---|
| 1036 | } |
---|
| 1037 | } |
---|
| 1038 | |
---|
| 1039 | void |
---|
| 1040 | smt_print_equation_in_tableau(smtManager_t * sm) |
---|
| 1041 | { |
---|
| 1042 | double * tab = sm->tab; |
---|
| 1043 | smtNvar_t * nvar; |
---|
| 1044 | double coeff; |
---|
| 1045 | int col, num_col, index; |
---|
| 1046 | int i, j; |
---|
| 1047 | |
---|
| 1048 | num_col = sm->tab_nvars->size; |
---|
| 1049 | |
---|
| 1050 | for(i = 0; i < sm->basics->size; i++) { |
---|
| 1051 | fprintf(stdout, "row_%d:", i+1); |
---|
| 1052 | for(j = 0; j < sm->tab_nvars->size; j++) { |
---|
| 1053 | nvar = (smtNvar_t *) sm->tab_nvars->space[j]; |
---|
| 1054 | col = nvar->id; |
---|
| 1055 | index = i * num_col + col; |
---|
| 1056 | coeff = tab[index]; |
---|
| 1057 | if (coeff <= 0 && coeff >= 0) continue; |
---|
| 1058 | if (nvar->flag & BASIC_MASK) |
---|
| 1059 | fprintf(stdout, "(%g*%s)(%d) ", coeff, nvar->name, col); |
---|
| 1060 | else |
---|
| 1061 | fprintf(stdout, "%g*%s(%d) ", coeff, nvar->name, col); |
---|
| 1062 | } |
---|
| 1063 | fprintf(stdout, "\n"); |
---|
| 1064 | } |
---|
| 1065 | |
---|
| 1066 | return; |
---|
| 1067 | } |
---|
| 1068 | |
---|
| 1069 | void |
---|
| 1070 | smt_report_result(smtManager_t * sm, int is_model) |
---|
| 1071 | { |
---|
| 1072 | satManager_t * cm = sm->cm; |
---|
| 1073 | |
---|
| 1074 | if (sm->flag & IDL_MASK || sm->flag & RDL_MASK) { |
---|
| 1075 | smt_dl_report_result(sm); |
---|
| 1076 | |
---|
| 1077 | /* print solution */ |
---|
| 1078 | if (cm->status == 1 && is_model) { |
---|
| 1079 | if (sm->flag & MP_CONST_MASK) |
---|
| 1080 | smt_mp_print_solution(sm); |
---|
| 1081 | else |
---|
| 1082 | smt_print_solution(sm); |
---|
| 1083 | } |
---|
| 1084 | } |
---|
| 1085 | } |
---|
| 1086 | |
---|
| 1087 | void |
---|
| 1088 | smt_dl_report_intermediate_result(smtManager_t * sm) |
---|
| 1089 | { |
---|
| 1090 | fprintf(stdout, "rate of bellman-ford conflict : %10g/%g\n", |
---|
| 1091 | sm->stats->num_bf_conf, sm->stats->num_bf_call); |
---|
| 1092 | fprintf(stdout, "rate of simple theory propagation : %10g/%g\n", |
---|
| 1093 | sm->stats->num_simp_tprop, sm->stats->num_simp_tprop_call); |
---|
| 1094 | fprintf(stdout, "rate of theory propagation : %10g/%g\n", |
---|
| 1095 | sm->stats->num_tprop, sm->stats->num_tprop_call); |
---|
| 1096 | fprintf(stdout, "\n"); |
---|
| 1097 | |
---|
| 1098 | return; |
---|
| 1099 | } |
---|
| 1100 | |
---|
| 1101 | void |
---|
| 1102 | smt_dl_report_result(smtManager_t * sm) |
---|
| 1103 | { |
---|
| 1104 | satManager_t * cm = sm->cm; |
---|
| 1105 | |
---|
| 1106 | if (cm) { |
---|
| 1107 | if(cm->status == 0) fprintf(stdout, "unsat\n"); |
---|
| 1108 | else if(cm->status == 1) fprintf(stdout, "sat\n"); |
---|
| 1109 | else fprintf(stdout, "unknown\n"); |
---|
| 1110 | } else { |
---|
| 1111 | /*fprintf(stdout, "unknown\n");*/ |
---|
| 1112 | if (sm->obj == Aig_One) fprintf(stdout, "sat\n"); |
---|
| 1113 | else if (sm->obj == Aig_Zero) fprintf(stdout, "unsat\n"); |
---|
| 1114 | } |
---|
| 1115 | |
---|
| 1116 | fprintf(stdout, "# of clauses : %10ld\n", |
---|
| 1117 | sm->clsArr->size - (long) sm->stats->num_static_cls); |
---|
| 1118 | fprintf(stdout, "# of bool vars : %10ld\n", |
---|
| 1119 | sm->bvarArr->size + (long) sm->stats->num_inter_bvar); |
---|
| 1120 | fprintf(stdout, "# of atoms : %10ld\n", |
---|
| 1121 | sm->avarArr->size - (long) sm->stats->num_static_pred); |
---|
| 1122 | fprintf(stdout, "rate of bellman-ford conflict : %10g/%g\n", |
---|
| 1123 | sm->stats->num_bf_conf, sm->stats->num_bf_call); |
---|
| 1124 | fprintf(stdout, "rate of simple theory propagation : %10g/%g\n", |
---|
| 1125 | sm->stats->num_simp_tprop, sm->stats->num_simp_tprop_call); |
---|
| 1126 | fprintf(stdout, "rate of theory propagation : %10g/%g\n", |
---|
| 1127 | sm->stats->num_tprop, sm->stats->num_tprop_call); |
---|
| 1128 | fprintf(stdout, "total solve time : %10g\n", sm->stats->solve_time); |
---|
| 1129 | |
---|
| 1130 | /*if (cm->status == 1) |
---|
| 1131 | smt_print_solution(sm);*/ |
---|
| 1132 | |
---|
| 1133 | return; |
---|
| 1134 | } |
---|
| 1135 | |
---|
| 1136 | void |
---|
| 1137 | smt_check_result(smtManager_t * sm) |
---|
| 1138 | { |
---|
| 1139 | satManager_t * cm = sm->cm; |
---|
| 1140 | int status = 2; |
---|
| 1141 | |
---|
| 1142 | if (gvar->status == 2) return; |
---|
| 1143 | |
---|
| 1144 | if (cm) { |
---|
| 1145 | if (cm->status == 1) |
---|
| 1146 | status = 1; |
---|
| 1147 | else if (cm->status == 0) |
---|
| 1148 | status = 0; |
---|
| 1149 | else |
---|
| 1150 | status = 2; |
---|
| 1151 | } else if ( !(sm->flag & UNKNOWN_MASK) ) { |
---|
| 1152 | if (sm->flag & SAT_MASK) |
---|
| 1153 | status = 1; |
---|
| 1154 | else |
---|
| 1155 | status = 0; |
---|
| 1156 | } |
---|
| 1157 | #if 1 |
---|
| 1158 | if (status != gvar->status) { |
---|
| 1159 | fprintf(stdout,"ERROR: Wrong result\n"); |
---|
| 1160 | } else { |
---|
| 1161 | fprintf(stdout, "Right result\n"); |
---|
| 1162 | } |
---|
| 1163 | #endif |
---|
| 1164 | } |
---|
| 1165 | |
---|
| 1166 | void |
---|
| 1167 | smt_print_unknown(void) |
---|
| 1168 | { |
---|
| 1169 | fprintf(stdout, "unknown\n"); |
---|
| 1170 | } |
---|
| 1171 | |
---|
| 1172 | char * |
---|
| 1173 | smt_convert_atom_to_string(smtAvar_t * avar) |
---|
| 1174 | { |
---|
| 1175 | smtNvar_t * nvar; |
---|
| 1176 | double coeff; |
---|
| 1177 | char * str_a, * str_b, * str_c; |
---|
| 1178 | int i; |
---|
| 1179 | |
---|
| 1180 | str_a = (char *) malloc(sizeof(char) * 100); |
---|
| 1181 | |
---|
| 1182 | if ( avar->nvars->size == 1) { |
---|
| 1183 | coeff = array_fetch(double, avar->coeffs, 0); |
---|
| 1184 | nvar = (smtNvar_t *) avar->nvars->space[0]; |
---|
| 1185 | if ( coeff >= 0 ) { |
---|
| 1186 | |
---|
| 1187 | if ( avar->constant >= 0 ) |
---|
| 1188 | sprintf(str_a, "(<= (* %d %s) %d)", |
---|
| 1189 | (int) coeff, nvar->name, (int) avar->constant); |
---|
| 1190 | else |
---|
| 1191 | sprintf(str_a, "(<= (* %d %s) (~ %d))", |
---|
| 1192 | (int) coeff, nvar->name, (int) -avar->constant); |
---|
| 1193 | |
---|
| 1194 | } else { |
---|
| 1195 | |
---|
| 1196 | if ( avar->constant >= 0 ) |
---|
| 1197 | sprintf(str_a, "(<= (* (~ %d) %s) %d)", |
---|
| 1198 | (int) -coeff, nvar->name, (int) avar->constant); |
---|
| 1199 | else |
---|
| 1200 | sprintf(str_a, "(<= (* (~ %d) %s) (~ %d))", |
---|
| 1201 | (int) -coeff, nvar->name, (int) -avar->constant); |
---|
| 1202 | |
---|
| 1203 | } |
---|
| 1204 | |
---|
| 1205 | str_b = util_strsav(str_a); |
---|
| 1206 | free(str_a); |
---|
| 1207 | |
---|
| 1208 | return str_b; |
---|
| 1209 | } |
---|
| 1210 | |
---|
| 1211 | str_b = util_strsav("(<= (+ "); |
---|
| 1212 | |
---|
| 1213 | for(i = 0; i < avar->nvars->size; i++) { |
---|
| 1214 | coeff = array_fetch(double, avar->coeffs, i); |
---|
| 1215 | nvar = (smtNvar_t *) avar->nvars->space[i]; |
---|
| 1216 | if ( coeff > 0 ) |
---|
| 1217 | sprintf(str_a, "(* %d %s) ", (int) coeff, nvar->name); /* a, b, c */ |
---|
| 1218 | else |
---|
| 1219 | sprintf(str_a, "(* (~ %d) %s) ", (int) -coeff, nvar->name); /* a, b, c */ |
---|
| 1220 | |
---|
| 1221 | str_c = str_b; |
---|
| 1222 | str_b = util_strcat3(str_b, str_a, ""); |
---|
| 1223 | free(str_c); |
---|
| 1224 | } |
---|
| 1225 | |
---|
| 1226 | if ( avar->constant >= 0 ) |
---|
| 1227 | sprintf(str_a, "%d)", (int) avar->constant); |
---|
| 1228 | else |
---|
| 1229 | sprintf(str_a, "(~ %d))", (int) -avar->constant); |
---|
| 1230 | |
---|
| 1231 | |
---|
| 1232 | str_c = util_strcat3(str_b, ") ", str_a); |
---|
| 1233 | |
---|
| 1234 | |
---|
| 1235 | free(str_a); |
---|
| 1236 | free(str_b); |
---|
| 1237 | |
---|
| 1238 | return str_c; |
---|
| 1239 | } |
---|
| 1240 | |
---|
| 1241 | int |
---|
| 1242 | smt_check_solution(smtManager_t * sm) |
---|
| 1243 | { |
---|
| 1244 | smtAvar_t * avar; |
---|
| 1245 | smtNvar_t * lnvar, * rnvar; |
---|
| 1246 | double weight; |
---|
| 1247 | int id, i; |
---|
| 1248 | |
---|
| 1249 | for(i = 0; i < sm->avarArr->size; i++) { |
---|
| 1250 | avar = (smtAvar_t *) sm->avarArr->space[i]; |
---|
| 1251 | id = avar->id; |
---|
| 1252 | assert(sm->avalues[id] != 2); |
---|
| 1253 | /*if (sm->avalues[id] == 2) continue;*/ |
---|
| 1254 | |
---|
| 1255 | if (sm->avalues[id] == 1) { |
---|
| 1256 | lnvar = (smtNvar_t *) avar->nvars->space[0]; |
---|
| 1257 | rnvar = (smtNvar_t *) avar->nvars->space[1]; |
---|
| 1258 | weight = avar->constant; |
---|
| 1259 | } else { |
---|
| 1260 | lnvar = (smtNvar_t *) avar->nvars->space[1]; |
---|
| 1261 | rnvar = (smtNvar_t *) avar->nvars->space[0]; |
---|
| 1262 | weight = -avar->constant - sm->epsilon; |
---|
| 1263 | } |
---|
| 1264 | |
---|
| 1265 | if (sm->flag & IDL_MASK) { |
---|
| 1266 | if (sm->ivalues[lnvar->id-1] - sm->ivalues[rnvar->id-1] > weight) { |
---|
| 1267 | fprintf(stdout, "unknown\n"); |
---|
| 1268 | exit(0); |
---|
| 1269 | } |
---|
| 1270 | } else if (sm->flag & RDL_MASK) { |
---|
| 1271 | |
---|
| 1272 | weight = weight + sm->epsilonless; |
---|
| 1273 | |
---|
| 1274 | if (sm->rvalues[lnvar->id-1] - sm->rvalues[rnvar->id-1] > weight) { |
---|
| 1275 | fprintf(stdout, "unknown\n"); |
---|
| 1276 | exit(0); |
---|
| 1277 | } |
---|
| 1278 | } |
---|
| 1279 | } |
---|
| 1280 | |
---|
| 1281 | return 1; |
---|
| 1282 | } |
---|
| 1283 | |
---|
| 1284 | int |
---|
| 1285 | smt_mp_check_solution(smtManager_t * sm) |
---|
| 1286 | { |
---|
| 1287 | smtMp_t * mp = sm->mp; |
---|
| 1288 | mpq_t * pool = mp->pool; |
---|
| 1289 | mpq_t * tmp_a = 0, * weight = 0, * diff = 0; |
---|
| 1290 | smtAvar_t * avar; |
---|
| 1291 | smtNvar_t * lnvar, * rnvar; |
---|
| 1292 | int id, i; |
---|
| 1293 | |
---|
| 1294 | /* mp vars */ |
---|
| 1295 | tmp_a = &pool[2]; |
---|
| 1296 | diff = &pool[3]; |
---|
| 1297 | weight = &pool[4]; |
---|
| 1298 | |
---|
| 1299 | for(i = 0; i < sm->avarArr->size; i++) { |
---|
| 1300 | avar = (smtAvar_t *) sm->avarArr->space[i]; |
---|
| 1301 | id = avar->id; |
---|
| 1302 | assert(sm->avalues[id] != 2); |
---|
| 1303 | /*if (sm->avalues[id] == 2) continue;*/ |
---|
| 1304 | |
---|
| 1305 | if (sm->avalues[id] == 1) { |
---|
| 1306 | lnvar = (smtNvar_t *) avar->nvars->space[0]; |
---|
| 1307 | rnvar = (smtNvar_t *) avar->nvars->space[1]; |
---|
| 1308 | mpq_set(*weight, sm->mp->weights[avar->id]); |
---|
| 1309 | } else { |
---|
| 1310 | lnvar = (smtNvar_t *) avar->nvars->space[1]; |
---|
| 1311 | rnvar = (smtNvar_t *) avar->nvars->space[0]; |
---|
| 1312 | weight = &sm->mp->weights[avar->id]; |
---|
| 1313 | mpq_set(*weight, sm->mp->weights[avar->id]); |
---|
| 1314 | mpq_neg(*weight, *weight); |
---|
| 1315 | mpq_set_d(*tmp_a, sm->epsilon); |
---|
| 1316 | mpq_sub(*weight, *weight, *tmp_a); |
---|
| 1317 | } |
---|
| 1318 | |
---|
| 1319 | mpq_sub(*diff, sm->mp->values[lnvar->id-1], sm->mp->values[rnvar->id-1]); |
---|
| 1320 | |
---|
| 1321 | if ( mpq_cmp(*diff, *weight) > 0 ) { |
---|
| 1322 | fprintf(stdout, "unknown\n"); |
---|
| 1323 | exit(0); |
---|
| 1324 | } |
---|
| 1325 | } |
---|
| 1326 | |
---|
| 1327 | return 1; |
---|
| 1328 | } |
---|
| 1329 | |
---|
| 1330 | |
---|
| 1331 | void |
---|
| 1332 | smt_print_solution(smtManager_t * sm) |
---|
| 1333 | { |
---|
| 1334 | satManager_t * cm = sm->cm; |
---|
| 1335 | smtBvar_t * bvar; |
---|
| 1336 | smtAvar_t * avar; |
---|
| 1337 | smtNvar_t * nvar, * lnvar, * rnvar; |
---|
| 1338 | double weight; |
---|
| 1339 | long num_bvar; |
---|
| 1340 | int i; |
---|
| 1341 | |
---|
| 1342 | num_bvar = sm->bvarArr->size - sm->stats->num_inter_bvar; |
---|
| 1343 | |
---|
| 1344 | for(i = 0; i < num_bvar; i++) { |
---|
| 1345 | bvar = (smtBvar_t *) sm->bvarArr->space[i]; |
---|
| 1346 | if (cm->values[SATVar(bvar->id)] == 1) |
---|
| 1347 | fprintf(stdout, "%s = true\n", bvar->name); |
---|
| 1348 | else if (cm->values[SATVar(bvar->id)] == 0) |
---|
| 1349 | fprintf(stdout, "%s = false\n", bvar->name); |
---|
| 1350 | else |
---|
| 1351 | fprintf(stdout, "%s = unknown\n", bvar->name); |
---|
| 1352 | } |
---|
| 1353 | |
---|
| 1354 | for(i = 0; i < sm->avarArr->size; i++) { |
---|
| 1355 | avar = (smtAvar_t *) sm->avarArr->space[i]; |
---|
| 1356 | if (cm->values[SATVar(avar->id)] == 1) |
---|
| 1357 | fprintf(stdout, "%s = true\n", avar->name); |
---|
| 1358 | else if (cm->values[SATVar(avar->id)] == 0) |
---|
| 1359 | fprintf(stdout, "%s = false\n", avar->name); |
---|
| 1360 | else { |
---|
| 1361 | lnvar = (smtNvar_t *) avar->nvars->space[0]; |
---|
| 1362 | rnvar = (smtNvar_t *) avar->nvars->space[1]; |
---|
| 1363 | weight = avar->constant; |
---|
| 1364 | |
---|
| 1365 | if (sm->flag & IDL_MASK) { |
---|
| 1366 | if (sm->ivalues[lnvar->id-1] - sm->ivalues[rnvar->id-1] <= weight) |
---|
| 1367 | fprintf(stdout, "%s = true\n", avar->name); |
---|
| 1368 | else |
---|
| 1369 | fprintf(stdout, "%s = false\n", avar->name); |
---|
| 1370 | } else if (sm->flag & RDL_MASK) { |
---|
| 1371 | weight = weight + sm->epsilonless; |
---|
| 1372 | if (sm->rvalues[lnvar->id-1] - sm->rvalues[rnvar->id-1] <= weight) |
---|
| 1373 | fprintf(stdout, "%s = true\n", avar->name); |
---|
| 1374 | else |
---|
| 1375 | fprintf(stdout, "%s = false\n", avar->name); |
---|
| 1376 | } |
---|
| 1377 | } |
---|
| 1378 | } |
---|
| 1379 | |
---|
| 1380 | for(i = 0; i < sm->nvarArr->size; i++) { |
---|
| 1381 | nvar = (smtNvar_t *) sm->nvarArr->space[i]; |
---|
| 1382 | if (sm->flag & IDL_MASK) |
---|
| 1383 | fprintf(stdout, "%s = %d\n", nvar->name, sm->ivalues[nvar->id-1]); |
---|
| 1384 | else if (sm->flag & RDL_MASK) |
---|
| 1385 | fprintf(stdout, "%s = %g\n", nvar->name, sm->rvalues[nvar->id-1]); |
---|
| 1386 | } |
---|
| 1387 | |
---|
| 1388 | } |
---|
| 1389 | |
---|
| 1390 | void |
---|
| 1391 | smt_mp_print_solution(smtManager_t * sm) |
---|
| 1392 | { |
---|
| 1393 | satManager_t * cm = sm->cm; |
---|
| 1394 | smtBvar_t * bvar; |
---|
| 1395 | smtAvar_t * avar; |
---|
| 1396 | smtNvar_t * nvar; |
---|
| 1397 | long num_bvar; |
---|
| 1398 | int i; |
---|
| 1399 | |
---|
| 1400 | num_bvar = sm->bvarArr->size - sm->stats->num_inter_bvar; |
---|
| 1401 | |
---|
| 1402 | for(i = 0; i < num_bvar; i++) { |
---|
| 1403 | bvar = (smtBvar_t *) sm->bvarArr->space[i]; |
---|
| 1404 | if (cm->values[SATVar(bvar->id)] == 1) |
---|
| 1405 | fprintf(stdout, "%s = true\n", bvar->name); |
---|
| 1406 | else if (cm->values[SATVar(bvar->id)] == 0) |
---|
| 1407 | fprintf(stdout, "%s = false\n", bvar->name); |
---|
| 1408 | else |
---|
| 1409 | fprintf(stdout, "%s = unknown\n", bvar->name); |
---|
| 1410 | } |
---|
| 1411 | |
---|
| 1412 | for(i = 0; i < sm->avarArr->size; i++) { |
---|
| 1413 | avar = (smtAvar_t *) sm->avarArr->space[i]; |
---|
| 1414 | if (cm->values[SATVar(avar->id)] == 1) |
---|
| 1415 | fprintf(stdout, "%s = true\n", avar->name); |
---|
| 1416 | else if (cm->values[SATVar(avar->id)] == 0) |
---|
| 1417 | fprintf(stdout, "%s = false\n", avar->name); |
---|
| 1418 | |
---|
| 1419 | } |
---|
| 1420 | |
---|
| 1421 | for(i = 0; i < sm->nvarArr->size; i++) { |
---|
| 1422 | nvar = (smtNvar_t *) sm->nvarArr->space[i]; |
---|
| 1423 | gmp_printf("%s = %#Qd\n", nvar->name, sm->mp->values[nvar->id-1]); |
---|
| 1424 | } |
---|
| 1425 | } |
---|
| 1426 | |
---|
| 1427 | #endif |
---|