00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "ppl_prolog_common.defs.hh"
00025 #include <exception>
00026 #include <stdexcept>
00027 #include <sstream>
00028 #include <climits>
00029 #include <typeinfo>
00030
00031 namespace Parma_Polyhedra_Library {
00032
00033 namespace Interfaces {
00034
00035 namespace Prolog {
00036
00037 #if PROLOG_TRACK_ALLOCATION || NOISY_PROLOG_TRACK_ALLOCATION
00038
00039 Allocation_Tracker::Allocation_Tracker() {
00040 }
00041
00042 Allocation_Tracker::~Allocation_Tracker() {
00043 Set::size_type n = s.size();
00044 if (n > 0)
00045 std::cerr
00046 << "Interfaces::Prolog::Allocation_Tracker: "
00047 << n << " object(s) leaked!"
00048 << std::endl;
00049 }
00050
00051 Allocation_Tracker allocation_tracker;
00052
00053 #endif // PROLOG_TRACK_ALLOCATION || NOISY_PROLOG_TRACK_ALLOCATION
00054
00055
00056
00057
00058 Prolog_atom out_of_memory_exception_atom;
00059
00060
00061 Prolog_atom a_nil;
00062
00063
00064 Prolog_atom a_dollar_VAR;
00065
00066
00067 Prolog_atom a_plus;
00068 Prolog_atom a_minus;
00069 Prolog_atom a_asterisk;
00070
00071
00072 Prolog_atom a_slash;
00073
00074
00075 Prolog_atom a_less_than;
00076 Prolog_atom a_equal_less_than;
00077 Prolog_atom a_equal;
00078 Prolog_atom a_greater_than_equal;
00079 Prolog_atom a_greater_than;
00080
00081
00082 Prolog_atom a_is_congruent_to;
00083 Prolog_atom a_modulo;
00084
00085
00086 Prolog_atom a_line;
00087 Prolog_atom a_ray;
00088 Prolog_atom a_point;
00089 Prolog_atom a_closure_point;
00090
00091
00092 Prolog_atom a_grid_line;
00093 Prolog_atom a_parameter;
00094 Prolog_atom a_grid_point;
00095
00096
00097 Prolog_atom a_divided_by;
00098
00099
00100 Prolog_atom a_is_disjoint;
00101 Prolog_atom a_strictly_intersects;
00102 Prolog_atom a_is_included;
00103 Prolog_atom a_saturates;
00104
00105
00106 Prolog_atom a_subsumes;
00107
00108
00109 Prolog_atom a_c;
00110
00111
00112 Prolog_atom a_empty;
00113
00114
00115 Prolog_atom a_universe;
00116
00117
00118 Prolog_atom a_max;
00119
00120
00121 Prolog_atom a_min;
00122
00123
00124 Prolog_atom a_bits_8;
00125 Prolog_atom a_bits_16;
00126 Prolog_atom a_bits_32;
00127 Prolog_atom a_bits_64;
00128 Prolog_atom a_bits_128;
00129
00130
00131 Prolog_atom a_unsigned;
00132 Prolog_atom a_signed_2_complement;
00133
00134
00135 Prolog_atom a_overflow_wraps;
00136 Prolog_atom a_overflow_undefined;
00137 Prolog_atom a_overflow_impossible;
00138
00139
00140 Prolog_atom a_unfeasible;
00141 Prolog_atom a_unbounded;
00142 Prolog_atom a_optimized;
00143
00144
00145 Prolog_atom a_o;
00146
00147
00148 Prolog_atom a_i;
00149
00150
00151 Prolog_atom a_minf;
00152 Prolog_atom a_pinf;
00153
00154
00155 Prolog_atom a_polynomial;
00156 Prolog_atom a_simplex;
00157 Prolog_atom a_any;
00158
00159
00160 Prolog_atom a_pricing;
00161 Prolog_atom a_pricing_steepest_edge_float;
00162 Prolog_atom a_pricing_steepest_edge_exact;
00163 Prolog_atom a_pricing_textbook;
00164
00165 Prolog_atom a_cutting_strategy;
00166 Prolog_atom a_cutting_strategy_first;
00167 Prolog_atom a_cutting_strategy_deepest;
00168 Prolog_atom a_cutting_strategy_all;
00169
00170 Prolog_atom a_pivot_row_strategy;
00171 Prolog_atom a_pivot_row_strategy_first;
00172 Prolog_atom a_pivot_row_strategy_max_column;
00173
00174
00175 Prolog_atom a_time_out;
00176
00177
00178 Prolog_atom a_out_of_memory;
00179
00180
00181 Prolog_atom a_true;
00182 Prolog_atom a_false;
00183
00184
00185 Prolog_atom a_ppl_overflow_error;
00186 Prolog_atom a_ppl_domain_error;
00187 Prolog_atom a_ppl_length_error;
00188 Prolog_atom a_ppl_invalid_argument;
00189 Prolog_atom a_ppl_logic_error;
00190 Prolog_atom a_ppl_representation_error;
00191 Prolog_atom a_expected;
00192 Prolog_atom a_found;
00193 Prolog_atom a_where;
00194
00195 const Prolog_Interface_Atom prolog_interface_atoms[] = {
00196 { &a_nil, "[]" },
00197
00198 { &a_dollar_VAR, "$VAR" },
00199
00200 { &a_plus, "+" },
00201 { &a_minus, "-" },
00202 { &a_asterisk, "*" },
00203
00204 { &a_slash, "/" },
00205
00206 { &a_equal, "=" },
00207 { &a_greater_than_equal, ">=" },
00208 { &a_equal_less_than, "=<" },
00209 { &a_greater_than, ">" },
00210 { &a_less_than, "<" },
00211
00212 { &a_is_congruent_to, "=:=" },
00213 { &a_modulo, "/" },
00214
00215 { &a_divided_by, "/" },
00216
00217 { &a_line, "line" },
00218 { &a_ray, "ray" },
00219 { &a_point, "point" },
00220 { &a_closure_point, "closure_point" },
00221
00222 { &a_grid_line, "grid_line" },
00223 { &a_parameter, "parameter" },
00224 { &a_grid_point, "grid_point" },
00225
00226 { &a_is_disjoint, "is_disjoint" },
00227 { &a_strictly_intersects, "strictly_intersects" },
00228 { &a_is_included, "is_included" },
00229 { &a_saturates, "saturates" },
00230
00231 { &a_subsumes, "subsumes" },
00232
00233 { &a_c, "c" },
00234
00235 { &a_empty, "empty" },
00236 { &a_universe, "universe" },
00237
00238 { &a_max, "max" },
00239 { &a_min, "min" },
00240
00241 { &a_bits_8, "bits_8" },
00242 { &a_bits_16, "bits_16" },
00243 { &a_bits_32, "bits_32" },
00244 { &a_bits_64, "bits_64" },
00245 { &a_bits_128, "bits_128" },
00246
00247 { &a_unsigned, "unsigned" },
00248 { &a_signed_2_complement, "signed_2_complement" },
00249
00250 { &a_overflow_wraps, "overflow_wraps" },
00251 { &a_overflow_undefined, "overflow_undefined" },
00252 { &a_overflow_impossible, "overflow_impossible" },
00253
00254 { &a_unfeasible, "unfeasible" },
00255 { &a_unbounded, "unbounded" },
00256 { &a_optimized, "optimized" },
00257
00258 { &a_o, "o" },
00259 { &a_i, "i" },
00260
00261 { &a_minf, "minf" },
00262 { &a_pinf, "pinf" },
00263
00264 { &a_polynomial, "polynomial" },
00265 { &a_simplex, "simplex" },
00266 { &a_any, "any" },
00267
00268 { &a_pricing, "pricing" },
00269 { &a_pricing_steepest_edge_float,
00270 "pricing_steepest_edge_float" },
00271 { &a_pricing_steepest_edge_exact,
00272 "pricing_steepest_edge_exact" },
00273 { &a_pricing_textbook, "pricing_textbook" },
00274
00275 { &a_cutting_strategy, "cutting_strategy" },
00276 { &a_cutting_strategy_first, "cutting_strategy_first" },
00277 { &a_cutting_strategy_deepest, "cutting_strategy_deepest" },
00278 { &a_cutting_strategy_all, "cutting_strategy_all" },
00279
00280 { &a_pivot_row_strategy, "pivot_row_strategy" },
00281 { &a_pivot_row_strategy_first, "pivot_row_strategy_first" },
00282 { &a_pivot_row_strategy_max_column,
00283 "pivot_row_strategy_max_column" },
00284
00285 { &a_time_out, "time_out" },
00286 { &a_out_of_memory, "out_of_memory" },
00287
00288 { &a_true, "true" },
00289 { &a_false, "false" },
00290
00291 { &a_ppl_invalid_argument, "ppl_invalid_argument" },
00292 { &a_ppl_overflow_error, "ppl_overflow_error" },
00293 { &a_ppl_domain_error, "ppl_domain_error" },
00294 { &a_ppl_length_error, "ppl_length_error" },
00295 { &a_ppl_invalid_argument, "ppl_invalid_argument" },
00296 { &a_ppl_logic_error, "ppl_logic_error" },
00297 { &a_ppl_representation_error, "ppl_representation_error" },
00298 { &a_expected, "expected" },
00299 { &a_found, "found" },
00300 { &a_where, "where" },
00301 { 0, 0 }
00302 };
00303
00304 Prolog_term_ref
00305 Prolog_atom_term_from_string(const char* s) {
00306 Prolog_term_ref t = Prolog_new_term_ref();
00307 Prolog_put_atom(t, Prolog_atom_from_string(s));
00308 return t;
00309 }
00310
00311 void
00312 handle_exception(const Prolog_unsigned_out_of_range& e) {
00313 Prolog_term_ref found = Prolog_new_term_ref();
00314 Prolog_construct_compound(found, a_found, e.term());
00315
00316 Prolog_term_ref max = Prolog_new_term_ref();
00317 Prolog_put_ulong(max, e.max());
00318 Prolog_construct_compound(max,
00319 Prolog_atom_from_string("unsigned_integer"
00320 "_less_or_equal"),
00321 max);
00322 Prolog_term_ref expected = Prolog_new_term_ref();
00323 Prolog_construct_compound(expected, a_expected, max);
00324
00325 Prolog_term_ref where = Prolog_new_term_ref();
00326 Prolog_construct_compound(where, a_where,
00327 Prolog_atom_term_from_string(e.where()));
00328
00329 Prolog_term_ref exception_term = Prolog_new_term_ref();
00330 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
00331 found, expected, where);
00332 Prolog_raise_exception(exception_term);
00333 }
00334
00335 void
00336 handle_exception(const not_unsigned_integer& e) {
00337 Prolog_term_ref found = Prolog_new_term_ref();
00338 Prolog_construct_compound(found, a_found, e.term());
00339
00340 Prolog_term_ref expected = Prolog_new_term_ref();
00341 Prolog_construct_compound(expected, a_expected,
00342 Prolog_atom_term_from_string("unsigned_integer"));
00343
00344 Prolog_term_ref where = Prolog_new_term_ref();
00345 Prolog_construct_compound(where, a_where,
00346 Prolog_atom_term_from_string(e.where()));
00347
00348 Prolog_term_ref exception_term = Prolog_new_term_ref();
00349 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
00350 found, expected, where);
00351 Prolog_raise_exception(exception_term);
00352 }
00353
00354 void
00355 handle_exception(const non_linear& e) {
00356 Prolog_term_ref found = Prolog_new_term_ref();
00357 Prolog_construct_compound(found, a_found, e.term());
00358
00359 Prolog_term_ref expected = Prolog_new_term_ref();
00360 Prolog_construct_compound(expected, a_expected,
00361 Prolog_atom_term_from_string
00362 ("linear_expression_or_constraint"));
00363
00364 Prolog_term_ref where = Prolog_new_term_ref();
00365 Prolog_construct_compound(where, a_where,
00366 Prolog_atom_term_from_string(e.where()));
00367
00368 Prolog_term_ref exception_term = Prolog_new_term_ref();
00369 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
00370 found, expected, where);
00371 Prolog_raise_exception(exception_term);
00372 }
00373
00374 void
00375 handle_exception(const not_a_variable& e) {
00376 Prolog_term_ref found = Prolog_new_term_ref();
00377 Prolog_construct_compound(found, a_found,
00378 e.term());
00379
00380 Prolog_term_ref expected = Prolog_new_term_ref();
00381 Prolog_construct_compound(expected, a_expected,
00382 Prolog_atom_term_from_string
00383 ("$VAR(unsigned_integer)"));
00384
00385 Prolog_term_ref where = Prolog_new_term_ref();
00386 Prolog_construct_compound(where, a_where,
00387 Prolog_atom_term_from_string(e.where()));
00388
00389 Prolog_term_ref exception_term = Prolog_new_term_ref();
00390 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
00391 found, expected, where);
00392 Prolog_raise_exception(exception_term);
00393 }
00394
00395 void
00396 handle_exception(const not_an_integer& e) {
00397 Prolog_term_ref found = Prolog_new_term_ref();
00398 Prolog_construct_compound(found, a_found, e.term());
00399
00400 Prolog_term_ref expected = Prolog_new_term_ref();
00401 Prolog_construct_compound(expected, a_expected,
00402 Prolog_atom_term_from_string("integer"));
00403
00404 Prolog_term_ref where = Prolog_new_term_ref();
00405 Prolog_construct_compound(where, a_where,
00406 Prolog_atom_term_from_string(e.where()));
00407
00408 Prolog_term_ref exception_term = Prolog_new_term_ref();
00409 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
00410 found, expected, where);
00411 Prolog_raise_exception(exception_term);
00412 }
00413
00414 void
00415 handle_exception(const ppl_handle_mismatch& e) {
00416 Prolog_term_ref found = Prolog_new_term_ref();
00417 Prolog_construct_compound(found, a_found, e.term());
00418
00419 Prolog_term_ref expected = Prolog_new_term_ref();
00420 Prolog_construct_compound(expected, a_expected,
00421 Prolog_atom_term_from_string("handle"));
00422
00423 Prolog_term_ref where = Prolog_new_term_ref();
00424 Prolog_construct_compound(where, a_where,
00425 Prolog_atom_term_from_string(e.where()));
00426
00427 Prolog_term_ref exception_term = Prolog_new_term_ref();
00428 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
00429 found, expected, where);
00430 Prolog_raise_exception(exception_term);
00431 }
00432
00433 void
00434 handle_exception(const not_an_optimization_mode& e) {
00435 Prolog_term_ref found = Prolog_new_term_ref();
00436 Prolog_construct_compound(found, a_found, e.term());
00437
00438 Prolog_term_ref expected = Prolog_new_term_ref();
00439 Prolog_put_atom(expected, a_nil);
00440 Prolog_construct_cons(expected,
00441 Prolog_atom_term_from_string("max"), expected);
00442 Prolog_construct_cons(expected,
00443 Prolog_atom_term_from_string("min"), expected);
00444 Prolog_construct_compound(expected, a_expected, expected);
00445
00446 Prolog_term_ref where = Prolog_new_term_ref();
00447 Prolog_construct_compound(where, a_where,
00448 Prolog_atom_term_from_string(e.where()));
00449 Prolog_term_ref exception_term = Prolog_new_term_ref();
00450 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
00451 found, expected, where);
00452 Prolog_raise_exception(exception_term);
00453 }
00454
00455 void
00456 handle_exception(const not_a_complexity_class& e) {
00457 Prolog_term_ref found = Prolog_new_term_ref();
00458 Prolog_construct_compound(found, a_found, e.term());
00459
00460 Prolog_term_ref expected = Prolog_new_term_ref();
00461 Prolog_put_atom(expected, a_nil);
00462 Prolog_construct_cons(expected,
00463 Prolog_atom_term_from_string("polynomial"), expected);
00464 Prolog_construct_cons(expected,
00465 Prolog_atom_term_from_string("simplex"), expected);
00466 Prolog_construct_cons(expected,
00467 Prolog_atom_term_from_string("any"), expected);
00468 Prolog_construct_compound(expected, a_expected, expected);
00469
00470 Prolog_term_ref where = Prolog_new_term_ref();
00471 Prolog_construct_compound(where, a_where,
00472 Prolog_atom_term_from_string(e.where()));
00473 Prolog_term_ref exception_term = Prolog_new_term_ref();
00474 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
00475 found, expected, where);
00476 Prolog_raise_exception(exception_term);
00477 }
00478
00479 void
00480 handle_exception(const not_a_control_parameter_name& e) {
00481 Prolog_term_ref found = Prolog_new_term_ref();
00482 Prolog_construct_compound(found, a_found, e.term());
00483
00484 Prolog_term_ref expected = Prolog_new_term_ref();
00485 Prolog_put_atom(expected, a_nil);
00486 Prolog_construct_cons(expected,
00487 Prolog_atom_term_from_string("pricing"), expected);
00488
00489 Prolog_term_ref where = Prolog_new_term_ref();
00490 Prolog_construct_compound(where, a_where,
00491 Prolog_atom_term_from_string(e.where()));
00492 Prolog_term_ref exception_term = Prolog_new_term_ref();
00493 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
00494 found, expected, where);
00495 Prolog_raise_exception(exception_term);
00496 }
00497
00498 void
00499 handle_exception(const not_a_control_parameter_value& e) {
00500 Prolog_term_ref found = Prolog_new_term_ref();
00501 Prolog_construct_compound(found, a_found, e.term());
00502
00503 Prolog_term_ref expected = Prolog_new_term_ref();
00504 Prolog_put_atom(expected, a_nil);
00505 Prolog_construct_cons(expected,
00506 Prolog_atom_term_from_string("pricing_steepest_edge_float"),
00507 expected);
00508 Prolog_construct_cons(expected,
00509 Prolog_atom_term_from_string("pricing_steepest_edge_exact"),
00510 expected);
00511 Prolog_construct_cons(expected,
00512 Prolog_atom_term_from_string("pricing_textbook"),
00513 expected);
00514
00515 Prolog_term_ref where = Prolog_new_term_ref();
00516 Prolog_construct_compound(where, a_where,
00517 Prolog_atom_term_from_string(e.where()));
00518 Prolog_term_ref exception_term = Prolog_new_term_ref();
00519 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
00520 found, expected, where);
00521 Prolog_raise_exception(exception_term);
00522 }
00523
00524 void
00525 handle_exception(const not_a_pip_problem_control_parameter_name& e) {
00526 Prolog_term_ref found = Prolog_new_term_ref();
00527 Prolog_construct_compound(found, a_found, e.term());
00528
00529 Prolog_term_ref expected = Prolog_new_term_ref();
00530 Prolog_put_atom(expected, a_nil);
00531 Prolog_construct_cons(expected,
00532 Prolog_atom_term_from_string("cutting_strategy"),
00533 expected);
00534 Prolog_construct_cons(expected,
00535 Prolog_atom_term_from_string("pivot_row_strategy"),
00536 expected);
00537
00538 Prolog_term_ref where = Prolog_new_term_ref();
00539 Prolog_construct_compound(where, a_where,
00540 Prolog_atom_term_from_string(e.where()));
00541 Prolog_term_ref exception_term = Prolog_new_term_ref();
00542 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
00543 found, expected, where);
00544 Prolog_raise_exception(exception_term);
00545 }
00546
00547 void
00548 handle_exception(const not_a_pip_problem_control_parameter_value& e) {
00549 Prolog_term_ref found = Prolog_new_term_ref();
00550 Prolog_construct_compound(found, a_found, e.term());
00551
00552 Prolog_term_ref expected = Prolog_new_term_ref();
00553 Prolog_put_atom(expected, a_nil);
00554 Prolog_construct_cons(expected,
00555 Prolog_atom_term_from_string("cutting_strategy_first"),
00556 expected);
00557 Prolog_construct_cons(expected,
00558 Prolog_atom_term_from_string("cutting_strategy_deepest"),
00559 expected);
00560 Prolog_construct_cons(expected,
00561 Prolog_atom_term_from_string("cutting_strategy_all"),
00562 expected);
00563 Prolog_construct_cons(expected,
00564 Prolog_atom_term_from_string("pivot_row_strategy_first"),
00565 expected);
00566 Prolog_construct_cons(expected,
00567 Prolog_atom_term_from_string("pivot_row_strategy_max_column"),
00568 expected);
00569 Prolog_term_ref where = Prolog_new_term_ref();
00570 Prolog_construct_compound(where, a_where,
00571 Prolog_atom_term_from_string(e.where()));
00572 Prolog_term_ref exception_term = Prolog_new_term_ref();
00573 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
00574 found, expected, where);
00575 Prolog_raise_exception(exception_term);
00576 }
00577
00578 void
00579 handle_exception(const not_universe_or_empty& e) {
00580 Prolog_term_ref found = Prolog_new_term_ref();
00581 Prolog_construct_compound(found, a_found, e.term());
00582
00583 Prolog_term_ref expected = Prolog_new_term_ref();
00584 Prolog_put_atom(expected, a_nil);
00585 Prolog_construct_cons(expected,
00586 Prolog_atom_term_from_string("universe"), expected);
00587 Prolog_construct_cons(expected,
00588 Prolog_atom_term_from_string("empty"), expected);
00589 Prolog_construct_compound(expected, a_expected, expected);
00590
00591 Prolog_term_ref where = Prolog_new_term_ref();
00592 Prolog_construct_compound(where, a_where,
00593 Prolog_atom_term_from_string(e.where()));
00594 Prolog_term_ref exception_term = Prolog_new_term_ref();
00595 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
00596 found, expected, where);
00597 Prolog_raise_exception(exception_term);
00598 }
00599
00600 void
00601 handle_exception(const not_a_boolean& e) {
00602 Prolog_term_ref found = Prolog_new_term_ref();
00603 Prolog_construct_compound(found, a_found, e.term());
00604
00605 Prolog_term_ref expected = Prolog_new_term_ref();
00606 Prolog_put_atom(expected, a_nil);
00607 Prolog_construct_cons(expected,
00608 Prolog_atom_term_from_string("true"), expected);
00609 Prolog_construct_cons(expected,
00610 Prolog_atom_term_from_string("false"), expected);
00611 Prolog_construct_compound(expected, a_expected, expected);
00612
00613 Prolog_term_ref where = Prolog_new_term_ref();
00614 Prolog_construct_compound(where, a_where,
00615 Prolog_atom_term_from_string(e.where()));
00616 Prolog_term_ref exception_term = Prolog_new_term_ref();
00617 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
00618 found, expected, where);
00619 Prolog_raise_exception(exception_term);
00620 }
00621
00622 void
00623 handle_exception(const not_a_bounded_integer_type_width& e) {
00624 Prolog_term_ref found = Prolog_new_term_ref();
00625 Prolog_construct_compound(found, a_found, e.term());
00626
00627 Prolog_term_ref expected = Prolog_new_term_ref();
00628 Prolog_put_atom(expected, a_nil);
00629 Prolog_construct_cons(expected,
00630 Prolog_atom_term_from_string("bits_8"), expected);
00631 Prolog_construct_cons(expected,
00632 Prolog_atom_term_from_string("bits_16"), expected);
00633 Prolog_construct_cons(expected,
00634 Prolog_atom_term_from_string("bits_32"), expected);
00635 Prolog_construct_cons(expected,
00636 Prolog_atom_term_from_string("bits_64"), expected);
00637 Prolog_construct_cons(expected,
00638 Prolog_atom_term_from_string("bits_128"), expected);
00639 Prolog_construct_compound(expected, a_expected, expected);
00640
00641 Prolog_term_ref where = Prolog_new_term_ref();
00642 Prolog_construct_compound(where, a_where,
00643 Prolog_atom_term_from_string(e.where()));
00644 Prolog_term_ref exception_term = Prolog_new_term_ref();
00645 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
00646 found, expected, where);
00647 Prolog_raise_exception(exception_term);
00648 }
00649
00650 void
00651 handle_exception(const not_a_bounded_integer_type_representation& e) {
00652 Prolog_term_ref found = Prolog_new_term_ref();
00653 Prolog_construct_compound(found, a_found, e.term());
00654
00655 Prolog_term_ref expected = Prolog_new_term_ref();
00656 Prolog_put_atom(expected, a_nil);
00657 Prolog_construct_cons(expected,
00658 Prolog_atom_term_from_string("unsigned"), expected);
00659 Prolog_construct_cons(expected,
00660 Prolog_atom_term_from_string("signed_2_complement"),
00661 expected);
00662 Prolog_construct_compound(expected, a_expected, expected);
00663
00664 Prolog_term_ref where = Prolog_new_term_ref();
00665 Prolog_construct_compound(where, a_where,
00666 Prolog_atom_term_from_string(e.where()));
00667 Prolog_term_ref exception_term = Prolog_new_term_ref();
00668 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
00669 found, expected, where);
00670 Prolog_raise_exception(exception_term);
00671 }
00672
00673 void
00674 handle_exception(const not_a_bounded_integer_type_overflow& e) {
00675 Prolog_term_ref found = Prolog_new_term_ref();
00676 Prolog_construct_compound(found, a_found, e.term());
00677
00678 Prolog_term_ref expected = Prolog_new_term_ref();
00679 Prolog_put_atom(expected, a_nil);
00680 Prolog_construct_cons(expected,
00681 Prolog_atom_term_from_string("overflow_wraps"),
00682 expected);
00683 Prolog_construct_cons(expected,
00684 Prolog_atom_term_from_string("overflow_undefined"),
00685 expected);
00686 Prolog_construct_cons(expected,
00687 Prolog_atom_term_from_string("overflow_impossible"),
00688 expected);
00689 Prolog_construct_compound(expected, a_expected, expected);
00690
00691 Prolog_term_ref where = Prolog_new_term_ref();
00692 Prolog_construct_compound(where, a_where,
00693 Prolog_atom_term_from_string(e.where()));
00694 Prolog_term_ref exception_term = Prolog_new_term_ref();
00695 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
00696 found, expected, where);
00697 Prolog_raise_exception(exception_term);
00698 }
00699
00700 void
00701 handle_exception(const not_a_relation& e) {
00702 Prolog_term_ref found = Prolog_new_term_ref();
00703 Prolog_construct_compound(found, a_found, e.term());
00704
00705 Prolog_term_ref expected = Prolog_new_term_ref();
00706 Prolog_put_atom(expected, a_nil);
00707 Prolog_construct_cons(expected,
00708 Prolog_atom_term_from_string("="), expected);
00709 Prolog_construct_cons(expected,
00710 Prolog_atom_term_from_string(">="), expected);
00711 Prolog_construct_cons(expected,
00712 Prolog_atom_term_from_string("=<"), expected);
00713 Prolog_construct_cons(expected,
00714 Prolog_atom_term_from_string(">"), expected);
00715 Prolog_construct_cons(expected,
00716 Prolog_atom_term_from_string("<"), expected);
00717 Prolog_construct_compound(expected, a_expected, expected);
00718
00719 Prolog_term_ref where = Prolog_new_term_ref();
00720 Prolog_construct_compound(where, a_where,
00721 Prolog_atom_term_from_string(e.where()));
00722 Prolog_term_ref exception_term = Prolog_new_term_ref();
00723 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
00724 found, expected, where);
00725 Prolog_raise_exception(exception_term);
00726 }
00727
00728 void
00729 handle_exception(const not_a_nil_terminated_list& e) {
00730 Prolog_term_ref found = Prolog_new_term_ref();
00731 Prolog_construct_compound(found, a_found, e.term());
00732
00733 Prolog_term_ref expected = Prolog_new_term_ref();
00734 Prolog_put_atom(expected, a_nil);
00735 Prolog_construct_cons(expected,
00736 Prolog_atom_term_from_string
00737 ("Prolog_list"), expected);
00738 Prolog_construct_compound(expected, a_expected, expected);
00739
00740 Prolog_term_ref where = Prolog_new_term_ref();
00741 Prolog_construct_compound(where, a_where,
00742 Prolog_atom_term_from_string(e.where()));
00743 Prolog_term_ref exception_term = Prolog_new_term_ref();
00744 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
00745 found, expected, where);
00746 Prolog_raise_exception(exception_term);
00747 }
00748
00749 void
00750 handle_exception(const PPL_integer_out_of_range& e) {
00751 Prolog_term_ref where = Prolog_new_term_ref();
00752 Prolog_construct_compound(where, a_where,
00753 Prolog_atom_term_from_string("Coefficient_to_integer_term"));
00754
00755 Prolog_term_ref exception_term = Prolog_new_term_ref();
00756 std::ostringstream s;
00757 s << e.value();
00758 std::string str = s.str();
00759 Prolog_construct_compound(exception_term, a_ppl_representation_error,
00760 Prolog_atom_term_from_string(str.c_str()),
00761 where);
00762 Prolog_raise_exception(exception_term);
00763 }
00764
00765 void
00766 handle_exception(const unknown_interface_error& e) {
00767 Prolog_term_ref et = Prolog_new_term_ref();
00768 Prolog_put_atom_chars(et, e.where());
00769 Prolog_raise_exception(et);
00770 }
00771
00772 void
00773 handle_exception(const std::overflow_error& e) {
00774 Prolog_term_ref et = Prolog_new_term_ref();
00775 Prolog_construct_compound(et, a_ppl_overflow_error,
00776 Prolog_atom_term_from_string(e.what()));
00777 Prolog_raise_exception(et);
00778 }
00779
00780 void
00781 handle_exception(const std::domain_error& e) {
00782 Prolog_term_ref et = Prolog_new_term_ref();
00783 Prolog_construct_compound(et, a_ppl_domain_error,
00784 Prolog_atom_term_from_string(e.what()));
00785 Prolog_raise_exception(et);
00786 }
00787
00788 void
00789 handle_exception(const std::length_error& e) {
00790 Prolog_term_ref et = Prolog_new_term_ref();
00791 Prolog_construct_compound(et, a_ppl_length_error,
00792 Prolog_atom_term_from_string(e.what()));
00793 Prolog_raise_exception(et);
00794 }
00795
00796 void
00797 handle_exception(const std::invalid_argument& e) {
00798 Prolog_term_ref et = Prolog_new_term_ref();
00799 Prolog_construct_compound(et, a_ppl_invalid_argument,
00800 Prolog_atom_term_from_string(e.what()));
00801 Prolog_raise_exception(et);
00802 }
00803
00804 void
00805 handle_exception(const std::logic_error& e) {
00806 Prolog_term_ref et = Prolog_new_term_ref();
00807 Prolog_construct_compound(et, a_ppl_logic_error,
00808 Prolog_atom_term_from_string(e.what()));
00809 Prolog_raise_exception(et);
00810 }
00811
00812 void
00813 handle_exception(const std::bad_alloc&) {
00814 Prolog_term_ref et = Prolog_new_term_ref();
00815 Prolog_put_atom(et, out_of_memory_exception_atom);
00816 Prolog_raise_exception(et);
00817 }
00818
00819 void
00820 handle_exception(const std::exception& e) {
00821 Prolog_term_ref et = Prolog_new_term_ref();
00822 Prolog_put_atom_chars(et, e.what());
00823 Prolog_raise_exception(et);
00824 }
00825
00826 void
00827 handle_exception() {
00828 Prolog_term_ref et = Prolog_new_term_ref();
00829 Prolog_put_atom_chars(et, "PPL bug: unknown exception raised");
00830 Prolog_raise_exception(et);
00831 }
00832
00833 #ifdef PPL_WATCHDOG_LIBRARY_ENABLED
00834
00835 Parma_Watchdog_Library::Watchdog* p_timeout_object = 0;
00836
00837 typedef
00838 Parma_Watchdog_Library::Threshold_Watcher
00839 <Parma_Polyhedra_Library::Weightwatch_Traits> Weightwatch;
00840
00841 Weightwatch* p_deterministic_timeout_object = 0;
00842
00843 void
00844 reset_timeout() {
00845 if (p_timeout_object) {
00846 delete p_timeout_object;
00847 p_timeout_object = 0;
00848 abandon_expensive_computations = 0;
00849 }
00850 }
00851
00852 void
00853 reset_deterministic_timeout() {
00854 if (p_deterministic_timeout_object) {
00855 delete p_deterministic_timeout_object;
00856 p_deterministic_timeout_object = 0;
00857 abandon_expensive_computations = 0;
00858 }
00859 }
00860 #endif // PPL_WATCHDOG_LIBRARY_ENABLED
00861
00862 Prolog_atom timeout_exception_atom;
00863
00864 void
00865 handle_exception(const timeout_exception&) {
00866 #ifdef PPL_WATCHDOG_LIBRARY_ENABLED
00867 assert(p_timeout_object);
00868 reset_timeout();
00869 #endif
00870 Prolog_term_ref et = Prolog_new_term_ref();
00871 Prolog_put_atom(et, timeout_exception_atom);
00872 Prolog_raise_exception(et);
00873 }
00874
00875 void
00876 handle_exception(const deterministic_timeout_exception&) {
00877 #ifdef PPL_WATCHDOG_LIBRARY_ENABLED
00878 assert(p_deterministic_timeout_object);
00879 reset_deterministic_timeout();
00880 #endif
00881 Prolog_term_ref et = Prolog_new_term_ref();
00882 Prolog_put_atom(et, timeout_exception_atom);
00883 Prolog_raise_exception(et);
00884 }
00885
00886 Prolog_term_ref
00887 variable_term(dimension_type varid) {
00888 Prolog_term_ref v = Prolog_new_term_ref();
00889 Prolog_put_ulong(v, varid);
00890 Prolog_term_ref t = Prolog_new_term_ref();
00891 Prolog_construct_compound(t, a_dollar_VAR, v);
00892 return t;
00893 }
00894
00895 Prolog_atom
00896 term_to_boolean(Prolog_term_ref t, const char* where) {
00897 if (Prolog_is_atom(t)) {
00898 Prolog_atom name;
00899 if (Prolog_get_atom_name(t, &name)
00900 && (name == a_true || name == a_false))
00901 return name;
00902 }
00903 throw not_a_boolean(t, where);
00904 }
00905
00906 Prolog_atom
00907 term_to_universe_or_empty(Prolog_term_ref t, const char* where) {
00908 if (Prolog_is_atom(t)) {
00909 Prolog_atom name;
00910 if (Prolog_get_atom_name(t, &name)
00911 && (name == a_universe || name == a_empty))
00912 return name;
00913 }
00914 throw not_universe_or_empty(t, where);
00915 }
00916
00917 Coefficient
00918 integer_term_to_Coefficient(Prolog_term_ref t) {
00919 PPL_DIRTY_TEMP_COEFFICIENT(n);
00920 assert(Prolog_is_integer(t));
00921 if (!Prolog_get_Coefficient(t, n))
00922 abort();
00923 return n;
00924 }
00925
00926 Prolog_term_ref
00927 Coefficient_to_integer_term(const Coefficient& n) {
00928 Prolog_term_ref t = Prolog_new_term_ref();
00929 if (!Prolog_put_Coefficient(t, n))
00930 abort();
00931 return t;
00932 }
00933
00934 bool
00935 unify_long(Prolog_term_ref t, long l) {
00936 Prolog_term_ref t_l = Prolog_new_term_ref();
00937 return Prolog_put_long(t_l, l) && Prolog_unify(t, t_l);
00938 }
00939
00940 bool
00941 unify_ulong(Prolog_term_ref t, unsigned long l) {
00942 Prolog_term_ref t_l = Prolog_new_term_ref();
00943 return Prolog_put_ulong(t_l, l) && Prolog_unify(t, t_l);
00944 }
00945
00946 Linear_Expression
00947 build_linear_expression(Prolog_term_ref t, const char* where) {
00948 if (Prolog_is_integer(t))
00949 return Linear_Expression(integer_term_to_Coefficient(t));
00950 else if (Prolog_is_compound(t)) {
00951 Prolog_atom functor;
00952 int arity;
00953 Prolog_get_compound_name_arity(t, &functor, &arity);
00954 switch (arity) {
00955 case 1:
00956 {
00957 Prolog_term_ref arg = Prolog_new_term_ref();
00958 Prolog_get_arg(1, t, arg);
00959 if (functor == a_minus)
00960
00961 return -build_linear_expression(arg, where);
00962 else if (functor == a_dollar_VAR)
00963
00964 return Variable(term_to_unsigned<dimension_type>(arg, where));
00965 }
00966 break;
00967 case 2:
00968 {
00969 Prolog_term_ref arg1 = Prolog_new_term_ref();
00970 Prolog_term_ref arg2 = Prolog_new_term_ref();
00971 Prolog_get_arg(1, t, arg1);
00972 Prolog_get_arg(2, t, arg2);
00973 if (functor == a_plus)
00974
00975 if (Prolog_is_integer(arg1))
00976 return integer_term_to_Coefficient(arg1)
00977 + build_linear_expression(arg2, where);
00978 else if (Prolog_is_integer(arg2))
00979 return build_linear_expression(arg1, where)
00980 + integer_term_to_Coefficient(arg2);
00981 else
00982 return build_linear_expression(arg1, where)
00983 + build_linear_expression(arg2, where);
00984 else if (functor == a_minus)
00985
00986 if (Prolog_is_integer(arg1))
00987 return integer_term_to_Coefficient(arg1)
00988 - build_linear_expression(arg2, where);
00989 else if (Prolog_is_integer(arg2))
00990 return build_linear_expression(arg1, where)
00991 - integer_term_to_Coefficient(arg2);
00992 else
00993 return build_linear_expression(arg1, where)
00994 - build_linear_expression(arg2, where);
00995 else if (functor == a_asterisk) {
00996
00997 if (Prolog_is_integer(arg1))
00998 return integer_term_to_Coefficient(arg1)
00999 * build_linear_expression(arg2, where);
01000 else if (Prolog_is_integer(arg2))
01001 return build_linear_expression(arg1, where)
01002 * integer_term_to_Coefficient(arg2);
01003 }
01004 }
01005 }
01006 }
01007
01008 throw non_linear(t, where);
01009 }
01010
01011 Constraint
01012 build_constraint(Prolog_term_ref t, const char* where) {
01013 if (Prolog_is_compound(t)) {
01014 Prolog_atom functor;
01015 int arity;
01016 Prolog_get_compound_name_arity(t, &functor, &arity);
01017 if (arity == 2) {
01018 Prolog_term_ref arg1 = Prolog_new_term_ref();
01019 Prolog_term_ref arg2 = Prolog_new_term_ref();
01020 Prolog_get_arg(1, t, arg1);
01021 Prolog_get_arg(2, t, arg2);
01022 if (functor == a_equal)
01023
01024 if (Prolog_is_integer(arg1))
01025 return integer_term_to_Coefficient(arg1)
01026 == build_linear_expression(arg2, where);
01027 else if (Prolog_is_integer(arg2))
01028 return build_linear_expression(arg1, where)
01029 == integer_term_to_Coefficient(arg2);
01030 else
01031 return build_linear_expression(arg1, where)
01032 == build_linear_expression(arg2, where);
01033 else if (functor == a_equal_less_than)
01034
01035 if (Prolog_is_integer(arg1))
01036 return integer_term_to_Coefficient(arg1)
01037 <= build_linear_expression(arg2, where);
01038 else if (Prolog_is_integer(arg2))
01039 return build_linear_expression(arg1, where)
01040 <= integer_term_to_Coefficient(arg2);
01041 else
01042 return build_linear_expression(arg1, where)
01043 <= build_linear_expression(arg2, where);
01044 else if (functor == a_greater_than_equal)
01045
01046 if (Prolog_is_integer(arg1))
01047 return integer_term_to_Coefficient(arg1)
01048 >= build_linear_expression(arg2, where);
01049 else if (Prolog_is_integer(arg2))
01050 return build_linear_expression(arg1, where)
01051 >= integer_term_to_Coefficient(arg2);
01052 else
01053 return build_linear_expression(arg1, where)
01054 >= build_linear_expression(arg2, where);
01055 else if (functor == a_less_than)
01056
01057 if (Prolog_is_integer(arg1))
01058 return integer_term_to_Coefficient(arg1)
01059 < build_linear_expression(arg2, where);
01060 else if (Prolog_is_integer(arg2))
01061 return build_linear_expression(arg1, where)
01062 < integer_term_to_Coefficient(arg2);
01063 else
01064 return build_linear_expression(arg1, where)
01065 < build_linear_expression(arg2, where);
01066 else if (functor == a_greater_than) {
01067
01068 if (Prolog_is_integer(arg1))
01069 return integer_term_to_Coefficient(arg1)
01070 > build_linear_expression(arg2, where);
01071 else if (Prolog_is_integer(arg2))
01072 return build_linear_expression(arg1, where)
01073 > integer_term_to_Coefficient(arg2);
01074 else
01075 return build_linear_expression(arg1, where)
01076 > build_linear_expression(arg2, where);
01077 }
01078 }
01079 }
01080
01081 throw non_linear(t, where);
01082 }
01083
01084 Congruence
01085 build_congruence(Prolog_term_ref t, const char* where) {
01086 if (Prolog_is_compound(t)) {
01087 Prolog_atom functor;
01088 int arity;
01089 Prolog_get_compound_name_arity(t, &functor, &arity);
01090 if (arity == 2) {
01091 Prolog_term_ref arg1 = Prolog_new_term_ref();
01092 Prolog_term_ref arg2 = Prolog_new_term_ref();
01093 Prolog_get_arg(1, t, arg1);
01094 Prolog_get_arg(2, t, arg2);
01095 if (functor == a_modulo) {
01096
01097 if (Prolog_is_integer(arg2)) {
01098 Prolog_atom functor1;
01099 int arity1;
01100 Prolog_get_compound_name_arity(arg1, &functor1, &arity1);
01101 if (arity1 == 2) {
01102 if (functor1 == a_is_congruent_to) {
01103
01104 Prolog_term_ref arg11 = Prolog_new_term_ref();
01105 Prolog_term_ref arg12 = Prolog_new_term_ref();
01106 Prolog_get_arg(1, arg1, arg11);
01107 Prolog_get_arg(2, arg1, arg12);
01108 if (Prolog_is_integer(arg12))
01109 return (build_linear_expression(arg11, where)
01110 %= integer_term_to_Coefficient(arg12))
01111 / integer_term_to_Coefficient(arg2);
01112 else
01113 return (build_linear_expression(arg11, where)
01114 %= build_linear_expression(arg12, where))
01115 / integer_term_to_Coefficient(arg2);
01116 }
01117 }
01118 }
01119 }
01120 else
01121 if (functor == a_is_congruent_to)
01122
01123 if (Prolog_is_integer(arg2))
01124 return build_linear_expression(arg1, where)
01125 %= integer_term_to_Coefficient(arg2);
01126 else
01127 return build_linear_expression(arg1, where)
01128 %= build_linear_expression(arg2, where);
01129 else
01130 if (functor == a_equal) {
01131
01132 if (Prolog_is_integer(arg1))
01133 return (build_linear_expression(arg2, where)
01134 %= integer_term_to_Coefficient(arg1)) / 0;
01135 else if (Prolog_is_integer(arg2))
01136 return (build_linear_expression(arg1, where)
01137 %= integer_term_to_Coefficient(arg2)) / 0;
01138 else
01139 return (build_linear_expression(arg1, where)
01140 %= build_linear_expression(arg2, where)) / 0;
01141 }
01142 }
01143 }
01144
01145 throw non_linear(t, where);
01146 }
01147
01148 Generator
01149 build_generator(Prolog_term_ref t, const char* where) {
01150 if (Prolog_is_compound(t)) {
01151 Prolog_atom functor;
01152 int arity;
01153 Prolog_get_compound_name_arity(t, &functor, &arity);
01154 if (arity == 1) {
01155 Prolog_term_ref arg = Prolog_new_term_ref();
01156 Prolog_get_arg(1, t, arg);
01157 if (functor == a_line)
01158 return Generator::line(build_linear_expression(arg, where));
01159 else if (functor == a_ray)
01160 return Generator::ray(build_linear_expression(arg, where));
01161 else if (functor == a_point)
01162 return Generator::point(build_linear_expression(arg, where));
01163 else if (functor == a_closure_point)
01164 return Generator::closure_point(build_linear_expression(arg, where));
01165 }
01166 else if (arity == 2) {
01167 Prolog_term_ref arg1 = Prolog_new_term_ref();
01168 Prolog_term_ref arg2 = Prolog_new_term_ref();
01169 Prolog_get_arg(1, t, arg1);
01170 Prolog_get_arg(2, t, arg2);
01171 if (Prolog_is_integer(arg2)) {
01172 if (functor == a_point)
01173 return Generator::point(build_linear_expression(arg1, where),
01174 integer_term_to_Coefficient(arg2));
01175 else if (functor == a_closure_point)
01176 return Generator::closure_point(build_linear_expression(arg1, where),
01177 integer_term_to_Coefficient(arg2));
01178 }
01179 }
01180 }
01181
01182 throw non_linear(t, where);
01183 }
01184
01185 Grid_Generator
01186 build_grid_generator(Prolog_term_ref t, const char* where) {
01187 if (Prolog_is_compound(t)) {
01188 Prolog_atom functor;
01189 int arity;
01190 Prolog_get_compound_name_arity(t, &functor, &arity);
01191 if (arity == 1) {
01192 Prolog_term_ref arg = Prolog_new_term_ref();
01193 Prolog_get_arg(1, t, arg);
01194 if (functor == a_grid_line)
01195 return Grid_Generator::grid_line(build_linear_expression(arg, where));
01196 else if (functor == a_parameter)
01197 return Grid_Generator::parameter(build_linear_expression(arg, where));
01198 else if (functor == a_grid_point)
01199 return Grid_Generator::grid_point(build_linear_expression(arg, where));
01200 }
01201 else if (arity == 2) {
01202 Prolog_term_ref arg1 = Prolog_new_term_ref();
01203 Prolog_term_ref arg2 = Prolog_new_term_ref();
01204 Prolog_get_arg(1, t, arg1);
01205 Prolog_get_arg(2, t, arg2);
01206 if (Prolog_is_integer(arg2)) {
01207 if (functor == a_grid_point)
01208 return Grid_Generator::grid_point(build_linear_expression(arg1,
01209 where),
01210 integer_term_to_Coefficient(arg2));
01211 else if (functor == a_parameter)
01212 return Grid_Generator::parameter(build_linear_expression(arg1,
01213 where),
01214 integer_term_to_Coefficient(arg2));
01215 }
01216 }
01217 }
01218
01219 throw non_linear(t, where);
01220 }
01221
01222 template <typename R>
01223 Prolog_term_ref
01224 get_homogeneous_expression(const R& r) {
01225 Prolog_term_ref so_far = Prolog_new_term_ref();
01226 PPL_DIRTY_TEMP_COEFFICIENT(coefficient);
01227 dimension_type varid = 0;
01228 dimension_type space_dimension = r.space_dimension();
01229 while (varid < space_dimension
01230 && (coefficient = r.coefficient(Variable(varid))) == 0)
01231 ++varid;
01232 if (varid >= space_dimension) {
01233 Prolog_put_long(so_far, 0);
01234 }
01235 else {
01236 Prolog_construct_compound(so_far, a_asterisk,
01237 Coefficient_to_integer_term(coefficient),
01238 variable_term(varid));
01239 while (true) {
01240 ++varid;
01241 while (varid < space_dimension
01242 && (coefficient = r.coefficient(Variable(varid))) == 0)
01243 ++varid;
01244 if (varid >= space_dimension)
01245 break;
01246 else {
01247 Prolog_term_ref addendum = Prolog_new_term_ref();
01248 Prolog_construct_compound(addendum, a_asterisk,
01249 Coefficient_to_integer_term(coefficient),
01250 variable_term(varid));
01251 Prolog_term_ref new_so_far = Prolog_new_term_ref();
01252 Prolog_construct_compound(new_so_far, a_plus,
01253 so_far, addendum);
01254 so_far = new_so_far;
01255 }
01256 }
01257 }
01258 return so_far;
01259 }
01260
01261 Prolog_term_ref
01262 get_linear_expression(const Linear_Expression& le) {
01263 Prolog_term_ref t_homo = get_homogeneous_expression(le);
01264 if (le.inhomogeneous_term() == 0)
01265 return t_homo;
01266 else {
01267 Prolog_term_ref t_in
01268 = Coefficient_to_integer_term(le.inhomogeneous_term());
01269 if (unify_long(t_homo, 0))
01270 return t_in;
01271 else {
01272 Prolog_term_ref t_le = Prolog_new_term_ref();
01273 Prolog_construct_compound(t_le, a_plus, t_homo, t_in);
01274 return t_le;
01275 }
01276 }
01277 }
01278
01279 Prolog_term_ref
01280 constraint_term(const Constraint& c) {
01281 Prolog_atom relation = 0;
01282 switch (c.type()) {
01283 case Constraint::EQUALITY:
01284 relation = a_equal;
01285 break;
01286 case Constraint::NONSTRICT_INEQUALITY:
01287 relation = a_greater_than_equal;
01288 break;
01289 case Constraint::STRICT_INEQUALITY:
01290 relation = a_greater_than;
01291 break;
01292 default:
01293 throw unknown_interface_error("generator_term()");
01294 }
01295 Prolog_term_ref t = Prolog_new_term_ref();
01296 Prolog_construct_compound
01297 (t,
01298 relation,
01299 get_homogeneous_expression(c),
01300 Coefficient_to_integer_term(-c.inhomogeneous_term()));
01301 return t;
01302 }
01303
01304 Prolog_term_ref
01305 congruence_term(const Congruence& cg) {
01306 Prolog_atom relation1 = a_is_congruent_to;
01307 Prolog_atom relation2 = a_modulo;
01308 Prolog_term_ref t_tmp = Prolog_new_term_ref();
01309 Prolog_term_ref t = Prolog_new_term_ref();
01310 Prolog_construct_compound
01311 (t_tmp,
01312 relation1,
01313 get_homogeneous_expression(cg),
01314 Coefficient_to_integer_term(-cg.inhomogeneous_term()));
01315 Prolog_construct_compound
01316 (t,
01317 relation2,
01318 t_tmp,
01319 Coefficient_to_integer_term(cg.modulus()));
01320 return t;
01321 }
01322
01323 Prolog_term_ref
01324 generator_term(const Generator& g) {
01325 Prolog_term_ref t = Prolog_new_term_ref();
01326 Prolog_atom constructor = 0;
01327 switch (g.type()) {
01328 case Generator::LINE:
01329 constructor = a_line;
01330 break;
01331 case Generator::RAY:
01332 constructor = a_ray;
01333 break;
01334 case Generator::POINT:
01335 {
01336 constructor = a_point;
01337 const Coefficient& divisor = g.divisor();
01338 if (divisor == 1)
01339 break;
01340 else {
01341 Prolog_construct_compound(t, constructor,
01342 get_homogeneous_expression(g),
01343 Coefficient_to_integer_term(divisor));
01344 return t;
01345 }
01346 }
01347 case Generator::CLOSURE_POINT:
01348 {
01349 constructor = a_closure_point;
01350 const Coefficient& divisor = g.divisor();
01351 if (divisor == 1)
01352 break;
01353 else {
01354 Prolog_construct_compound(t, constructor,
01355 get_homogeneous_expression(g),
01356 Coefficient_to_integer_term(divisor));
01357 return t;
01358 }
01359 }
01360 default:
01361 throw unknown_interface_error("generator_term()");
01362 }
01363 Prolog_construct_compound(t, constructor, get_homogeneous_expression(g));
01364 return t;
01365 }
01366
01367 Prolog_term_ref
01368 grid_generator_term(const Grid_Generator& g) {
01369 Prolog_term_ref t = Prolog_new_term_ref();
01370 Prolog_atom constructor = 0;
01371 switch (g.type()) {
01372 case Grid_Generator::LINE:
01373 constructor = a_grid_line;
01374 break;
01375 case Grid_Generator::PARAMETER:
01376 {
01377 constructor = a_parameter;
01378 const Coefficient& divisor = g.divisor();
01379 if (divisor == 1)
01380 break;
01381 else {
01382 Prolog_construct_compound(t, constructor,
01383 get_homogeneous_expression(g),
01384 Coefficient_to_integer_term(divisor));
01385 return t;
01386 }
01387 }
01388 case Grid_Generator::POINT:
01389 {
01390 constructor = a_grid_point;
01391 const Coefficient& divisor = g.divisor();
01392 if (divisor == 1)
01393 break;
01394 else {
01395 Prolog_construct_compound(t, constructor,
01396 get_homogeneous_expression(g),
01397 Coefficient_to_integer_term(divisor));
01398 return t;
01399 }
01400 }
01401 default:
01402 throw unknown_interface_error("grid_generator_term()");
01403 }
01404 Prolog_construct_compound(t, constructor, get_homogeneous_expression(g));
01405 return t;
01406 }
01407
01408 Prolog_term_ref
01409 artificial_parameter_term(const PIP_Tree_Node::Artificial_Parameter& art) {
01410 Prolog_term_ref t = Prolog_new_term_ref();
01411 Prolog_construct_compound(t, a_divided_by,
01412 get_linear_expression(art),
01413 Coefficient_to_integer_term(art.denominator()));
01414 return t;
01415 }
01416
01417 Variable
01418 term_to_Variable(Prolog_term_ref t, const char* where) {
01419 if (Prolog_is_compound(t)) {
01420 Prolog_atom functor;
01421 int arity;
01422 Prolog_get_compound_name_arity(t, &functor, &arity);
01423 if (functor == a_dollar_VAR && arity == 1) {
01424 Prolog_term_ref arg = Prolog_new_term_ref();
01425 Prolog_get_arg(1, t, arg);
01426 return
01427 Variable(term_to_unsigned<dimension_type>(arg, "term_to_Variable"));
01428 }
01429 }
01430 throw not_a_variable(t, where);
01431 }
01432
01433 Coefficient
01434 term_to_Coefficient(Prolog_term_ref t, const char* where) {
01435 if (Prolog_is_integer(t))
01436 return integer_term_to_Coefficient(t);
01437 else
01438 throw not_an_integer(t, where);
01439 }
01440
01441 Prolog_atom
01442 term_to_bounded_integer_type_width(Prolog_term_ref t, const char* where) {
01443 if (Prolog_is_atom(t)) {
01444 Prolog_atom name;
01445 if (Prolog_get_atom_name(t, &name)
01446 && (name == a_bits_8 || name == a_bits_16
01447 || name == a_bits_32 || name == a_bits_64
01448 || name == a_bits_128))
01449 return name;
01450 }
01451 throw not_a_bounded_integer_type_width(t, where);
01452 }
01453
01454 Prolog_atom
01455 term_to_bounded_integer_type_representation(Prolog_term_ref t,
01456 const char* where) {
01457 if (Prolog_is_atom(t)) {
01458 Prolog_atom name;
01459 if (Prolog_get_atom_name(t, &name)
01460 && (name == a_unsigned || name == a_signed_2_complement))
01461 return name;
01462 }
01463 throw not_a_bounded_integer_type_representation(t, where);
01464 }
01465
01466 Prolog_atom
01467 term_to_bounded_integer_type_overflow(Prolog_term_ref t,
01468 const char* where) {
01469 if (Prolog_is_atom(t)) {
01470 Prolog_atom name;
01471 if (Prolog_get_atom_name(t, &name)
01472 && (name == a_overflow_wraps
01473 || name == a_overflow_undefined
01474 || name == a_overflow_impossible))
01475 return name;
01476 }
01477 throw not_a_bounded_integer_type_overflow(t, where);
01478 }
01479
01480 Prolog_atom
01481 term_to_optimization_mode(Prolog_term_ref t, const char* where) {
01482 if (Prolog_is_atom(t)) {
01483 Prolog_atom name;
01484 if (Prolog_get_atom_name(t, &name)
01485 && (name == a_max || name == a_min))
01486 return name;
01487 }
01488 throw not_an_optimization_mode(t, where);
01489 }
01490
01491 Prolog_atom
01492 term_to_control_parameter_name(Prolog_term_ref t, const char* where) {
01493 if (Prolog_is_atom(t)) {
01494 Prolog_atom name;
01495 if (Prolog_get_atom_name(t, &name)
01496 && (name == a_pricing || name == a_cutting_strategy))
01497 return name;
01498 }
01499 throw not_a_control_parameter_name(t, where);
01500 }
01501
01502 Prolog_atom
01503 term_to_pip_problem_control_parameter_name(Prolog_term_ref t, const char* where) {
01504 if (Prolog_is_atom(t)) {
01505 Prolog_atom name;
01506 if (Prolog_get_atom_name(t, &name)
01507 && (name == a_cutting_strategy || name == a_pivot_row_strategy))
01508 return name;
01509 }
01510 throw not_a_pip_problem_control_parameter_name(t, where);
01511 }
01512
01513 Prolog_atom
01514 term_to_control_parameter_value(Prolog_term_ref t, const char* where) {
01515 if (Prolog_is_atom(t)) {
01516 Prolog_atom name;
01517 if (Prolog_get_atom_name(t, &name)
01518 && (name == a_pricing_steepest_edge_float
01519 || name == a_pricing_steepest_edge_exact
01520 || name == a_pricing_textbook
01521 || name == a_cutting_strategy_first
01522 || name == a_cutting_strategy_deepest))
01523 return name;
01524 }
01525 throw not_a_control_parameter_value(t, where);
01526 }
01527
01528 Prolog_atom
01529 term_to_pip_problem_control_parameter_value(Prolog_term_ref t,
01530 const char* where) {
01531 if (Prolog_is_atom(t)) {
01532 Prolog_atom name;
01533 if (Prolog_get_atom_name(t, &name)
01534 && (name == a_cutting_strategy_first
01535 || name == a_cutting_strategy_deepest
01536 || name == a_cutting_strategy_all
01537 || name == a_pivot_row_strategy_first
01538 || name == a_pivot_row_strategy_max_column))
01539 return name;
01540 }
01541 throw not_a_pip_problem_control_parameter_value(t, where);
01542 }
01543
01544 bool Prolog_interface_initialized = false;
01545
01546 void
01547 check_nil_terminating(Prolog_term_ref t, const char* where) {
01548 if (Prolog_is_atom(t)) {
01549 Prolog_atom a;
01550 Prolog_get_atom_name(t, &a);
01551 if (a == a_nil)
01552 return;
01553 }
01554 throw not_a_nil_terminated_list(t, where);
01555 }
01556
01557 inline dimension_type
01558 max_representable_dimension(dimension_type d) {
01559 return
01560 Prolog_has_unbounded_integers
01561 ? d
01562 : std::min(d, static_cast<dimension_type>(Prolog_max_integer));
01563 }
01564
01565 bool
01566 term_to_boundary(Prolog_term_ref t_b, Boundary_Kind kind,
01567 bool& finite, bool& closed,
01568 Coefficient& n, Coefficient& d) {
01569 if (!Prolog_is_compound(t_b))
01570 return false;
01571
01572 Prolog_atom functor;
01573 int arity;
01574
01575 Prolog_get_compound_name_arity(t_b, &functor, &arity);
01576
01577 if (arity != 1 || (functor != a_c && functor != a_o))
01578 return false;
01579
01580 Prolog_atom open_closed_atom = functor;
01581
01582 Prolog_term_ref t_limit = Prolog_new_term_ref();
01583 Prolog_get_arg(1, t_b, t_limit);
01584 if (Prolog_is_integer(t_limit)) {
01585
01586 finite = true;
01587 closed = (open_closed_atom == a_c);
01588 n = integer_term_to_Coefficient(t_limit);
01589 d = 1;
01590 }
01591 else if (Prolog_is_atom(t_limit)) {
01592 Prolog_atom a;
01593 Prolog_get_atom_name(t_limit, &a);
01594 Prolog_atom allowed_infinity = (kind == LOWER_BOUNDARY ? a_minf : a_pinf);
01595
01596 if (a != allowed_infinity || open_closed_atom != a_o)
01597 return false;
01598
01599 finite = false;
01600 }
01601 else if (Prolog_is_compound(t_limit)) {
01602 Prolog_get_compound_name_arity(t_limit, &functor, &arity);
01603 if (arity != 2 || functor != a_slash)
01604 return false;
01605
01606 Prolog_term_ref t_n = Prolog_new_term_ref();
01607 Prolog_term_ref t_d = Prolog_new_term_ref();
01608 Prolog_get_arg(1, t_limit, t_n);
01609 Prolog_get_arg(2, t_limit, t_d);
01610
01611 if (!Prolog_is_integer(t_n) || !Prolog_is_integer(t_d))
01612 return false;
01613 else {
01614 finite = true;
01615 closed = (open_closed_atom == a_c);
01616 n = integer_term_to_Coefficient(t_n);
01617 d = integer_term_to_Coefficient(t_d);
01618
01619 if (d <= 0)
01620 return false;
01621 }
01622 }
01623 return true;
01624 }
01625
01626 Prolog_atom
01627 term_to_relation(Prolog_term_ref t, const char* where) {
01628 if (Prolog_is_atom(t)) {
01629 Prolog_atom name;
01630 if (Prolog_get_atom_name(t, &name)
01631 && (name == a_equal
01632 || name == a_greater_than_equal
01633 || name == a_equal_less_than
01634 || name == a_greater_than
01635 || name == a_less_than))
01636 return name;
01637 }
01638 throw not_a_relation(t, where);
01639 }
01640
01641 Relation_Symbol
01642 term_to_relation_symbol(Prolog_term_ref t_r, const char* where) {
01643 Prolog_atom ra = term_to_relation(t_r, where);
01644 Relation_Symbol r;
01645 if (ra == a_less_than)
01646 r = LESS_THAN;
01647 else if (ra == a_equal_less_than)
01648 r = LESS_OR_EQUAL;
01649 else if (ra == a_equal)
01650 r = EQUAL;
01651 else if (ra == a_greater_than_equal)
01652 r = GREATER_OR_EQUAL;
01653 else {
01654 assert(ra == a_greater_than);
01655 r = GREATER_THAN;
01656 }
01657 return r;
01658 }
01659
01660 Prolog_term_ref
01661 rational_term(const Rational_Box::interval_type::boundary_type& q) {
01662 Prolog_term_ref t = Prolog_new_term_ref();
01663 PPL_DIRTY_TEMP_COEFFICIENT(numerator);
01664 PPL_DIRTY_TEMP_COEFFICIENT(denominator);
01665 numerator = q.get_num();
01666 denominator = q.get_den();
01667 if (denominator == 1)
01668 Prolog_put_Coefficient(t, numerator);
01669 else
01670 Prolog_construct_compound(t, a_slash,
01671 Coefficient_to_integer_term(numerator),
01672 Coefficient_to_integer_term(denominator));
01673 return t;
01674 }
01675
01676 Prolog_term_ref
01677 interval_term(const Rational_Box::interval_type& i) {
01678 Prolog_term_ref t = Prolog_new_term_ref();
01679 if (i.is_empty())
01680 Prolog_put_atom(t, a_empty);
01681 else {
01682
01683 const Prolog_atom& l_oc = i.lower_is_open() ? a_o : a_c;
01684 Prolog_term_ref l_b = Prolog_new_term_ref();
01685 if (i.lower_is_boundary_infinity())
01686 Prolog_put_atom(l_b, a_minf);
01687 else
01688 Prolog_put_term(l_b, rational_term(i.lower()));
01689 Prolog_term_ref l_t = Prolog_new_term_ref();
01690 Prolog_construct_compound(l_t, l_oc, l_b);
01691
01692
01693 const Prolog_atom& u_oc = i.upper_is_open() ? a_o : a_c;
01694 Prolog_term_ref u_b = Prolog_new_term_ref();
01695 if (i.upper_is_boundary_infinity())
01696 Prolog_put_atom(u_b, a_pinf);
01697 else
01698 Prolog_put_term(u_b, rational_term(i.upper()));
01699 Prolog_term_ref u_t = Prolog_new_term_ref();
01700 Prolog_construct_compound(u_t, u_oc, u_b);
01701
01702 Prolog_construct_compound(t, a_i, l_t, u_t);
01703 }
01704 return t;
01705 }
01706
01707 Prolog_atom
01708 term_to_complexity_class(Prolog_term_ref t, const char* where) {
01709 if (Prolog_is_atom(t)) {
01710 Prolog_atom name;
01711 if (Prolog_get_atom_name(t, &name)
01712 && (name == a_polynomial || name == a_simplex || name == a_any))
01713 return name;
01714 }
01715 throw not_a_complexity_class(t, where);
01716 }
01717
01718 }
01719
01720 }
01721
01722 }
01723
01724 using namespace Parma_Polyhedra_Library::Interfaces::Prolog;
01725
01726 extern "C" Prolog_foreign_return_type
01727 ppl_version_major(Prolog_term_ref t_v) {
01728 try {
01729 if (unify_ulong(t_v, version_major()))
01730 return PROLOG_SUCCESS;
01731 }
01732 CATCH_ALL;
01733 }
01734
01735 extern "C" Prolog_foreign_return_type
01736 ppl_version_minor(Prolog_term_ref t_v) {
01737 try {
01738 if (unify_ulong(t_v, version_minor()))
01739 return PROLOG_SUCCESS;
01740 }
01741 CATCH_ALL;
01742 }
01743
01744 extern "C" Prolog_foreign_return_type
01745 ppl_version_revision(Prolog_term_ref t_v) {
01746 try {
01747 if (unify_ulong(t_v, version_revision()))
01748 return PROLOG_SUCCESS;
01749 }
01750 CATCH_ALL;
01751 }
01752
01753 extern "C" Prolog_foreign_return_type
01754 ppl_version_beta(Prolog_term_ref t_v) {
01755 try {
01756 if (unify_ulong(t_v, version_beta()))
01757 return PROLOG_SUCCESS;
01758 }
01759 CATCH_ALL;
01760 }
01761
01762 extern "C" Prolog_foreign_return_type
01763 ppl_version(Prolog_term_ref t_v) {
01764 try {
01765 Prolog_term_ref tmp = Prolog_new_term_ref();
01766 Prolog_put_atom_chars(tmp, version());
01767 if (Prolog_unify(t_v, tmp))
01768 return PROLOG_SUCCESS;
01769 }
01770 CATCH_ALL;
01771 }
01772
01773 extern "C" Prolog_foreign_return_type
01774 ppl_banner(Prolog_term_ref t_b) {
01775 try {
01776 Prolog_term_ref tmp = Prolog_new_term_ref();
01777 Prolog_put_atom_chars(tmp, banner());
01778 if (Prolog_unify(t_b, tmp))
01779 return PROLOG_SUCCESS;
01780 }
01781 CATCH_ALL;
01782 }
01783
01784 extern "C" Prolog_foreign_return_type
01785 ppl_max_space_dimension(Prolog_term_ref t_msd) {
01786 try {
01787 if (unify_ulong(t_msd, max_representable_dimension(max_space_dimension())))
01788 return PROLOG_SUCCESS;
01789 }
01790 CATCH_ALL;
01791 }
01792
01793 extern "C" Prolog_foreign_return_type
01794 ppl_initialize() {
01795 try {
01796 if (Prolog_interface_initialized)
01797 return PROLOG_SUCCESS;
01798
01799 initialize();
01800 for (size_t i = 0; prolog_interface_atoms[i].p_atom != 0; ++i) {
01801 Prolog_atom a = Prolog_atom_from_string(prolog_interface_atoms[i].name);
01802 *prolog_interface_atoms[i].p_atom = a;
01803 }
01804 timeout_exception_atom = a_time_out;
01805 out_of_memory_exception_atom = a_out_of_memory;
01806 ppl_Prolog_sysdep_init();
01807 Prolog_interface_initialized = true;
01808 return PROLOG_SUCCESS;
01809 }
01810 CATCH_ALL;
01811 }
01812
01813 extern "C" Prolog_foreign_return_type
01814 ppl_finalize() {
01815 try {
01816 if (!Prolog_interface_initialized)
01817 return PROLOG_SUCCESS;
01818
01819 Prolog_interface_initialized = false;
01820
01821 finalize();
01822 #ifdef PPL_WATCHDOG_LIBRARY_ENABLED
01823
01824 reset_timeout();
01825 #endif
01826 ppl_Prolog_sysdep_deinit();
01827 return PROLOG_SUCCESS;
01828 }
01829 CATCH_ALL;
01830 }
01831
01832 extern "C" Prolog_foreign_return_type
01833 ppl_set_rounding_for_PPL() {
01834 try {
01835 set_rounding_for_PPL();
01836 return PROLOG_SUCCESS;
01837 }
01838 CATCH_ALL;
01839 }
01840
01841 extern "C" Prolog_foreign_return_type
01842 ppl_restore_pre_PPL_rounding() {
01843 try {
01844 restore_pre_PPL_rounding();
01845 return PROLOG_SUCCESS;
01846 }
01847 CATCH_ALL;
01848 }
01849
01850 extern "C" Prolog_foreign_return_type
01851 ppl_irrational_precision(Prolog_term_ref t_p) {
01852 try {
01853 if (unify_ulong(t_p, irrational_precision()))
01854 return PROLOG_SUCCESS;
01855 }
01856 CATCH_ALL;
01857 }
01858
01859 extern "C" Prolog_foreign_return_type
01860 ppl_set_irrational_precision(Prolog_term_ref t_p) {
01861 try {
01862 unsigned p
01863 = term_to_unsigned<unsigned>(t_p, "ppl_set_irrational_precision/1");
01864 set_irrational_precision(p);
01865 return PROLOG_SUCCESS;
01866 }
01867 CATCH_ALL;
01868 }
01869
01870 extern "C" Prolog_foreign_return_type
01871 ppl_set_timeout_exception_atom(Prolog_term_ref t_tea) {
01872 try {
01873 if (Prolog_is_atom(t_tea)) {
01874 Prolog_atom tea;
01875 if (Prolog_get_atom_name(t_tea, &tea)) {
01876 timeout_exception_atom = tea;
01877 return PROLOG_SUCCESS;
01878 }
01879 }
01880 Prolog_term_ref found = Prolog_new_term_ref();
01881 Prolog_construct_compound(found, a_found, t_tea);
01882
01883 Prolog_term_ref expected = Prolog_new_term_ref();
01884 Prolog_construct_compound(expected, a_expected,
01885 Prolog_atom_term_from_string("atom"));
01886
01887 Prolog_term_ref where = Prolog_new_term_ref();
01888 Prolog_construct_compound(where, a_where,
01889 Prolog_atom_term_from_string
01890 ("ppl_set_timeout_exception_atom"));
01891
01892 Prolog_term_ref exception_term = Prolog_new_term_ref();
01893 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
01894 found, expected, where);
01895 Prolog_raise_exception(exception_term);
01896 return PROLOG_FAILURE;
01897 }
01898 CATCH_ALL;
01899 }
01900
01901 extern "C" Prolog_foreign_return_type
01902 ppl_timeout_exception_atom(Prolog_term_ref t) {
01903 try {
01904 Prolog_term_ref t_tea = Prolog_new_term_ref();
01905 Prolog_put_atom(t_tea, timeout_exception_atom);
01906 return Prolog_unify(t_tea, t) ? PROLOG_SUCCESS : PROLOG_FAILURE;
01907 }
01908 CATCH_ALL;
01909 }
01910
01911 extern "C" Prolog_foreign_return_type
01912 ppl_set_timeout(Prolog_term_ref t_time) {
01913 try {
01914 #ifdef PPL_WATCHDOG_LIBRARY_ENABLED
01915
01916 reset_timeout();
01917 static timeout_exception e;
01918 unsigned hundredth_secs = term_to_unsigned<unsigned>(t_time,
01919 "ppl_set_timeout/1");
01920 p_timeout_object =
01921 new Parma_Watchdog_Library::Watchdog(hundredth_secs,
01922 abandon_expensive_computations,
01923 e);
01924 return PROLOG_SUCCESS;
01925 #else
01926 used(t_time);
01927 return PROLOG_FAILURE;
01928 #endif
01929 }
01930 CATCH_ALL;
01931 }
01932
01933 extern "C" Prolog_foreign_return_type
01934 ppl_reset_timeout() {
01935 try {
01936 #ifdef PPL_WATCHDOG_LIBRARY_ENABLED
01937 reset_timeout();
01938 return PROLOG_SUCCESS;
01939 #else
01940 return PROLOG_FAILURE;
01941 #endif
01942 }
01943 CATCH_ALL;
01944 }
01945
01946 extern "C" Prolog_foreign_return_type
01947 ppl_set_deterministic_timeout(Prolog_term_ref t_weight) {
01948 try {
01949 #ifdef PPL_WATCHDOG_LIBRARY_ENABLED
01950
01951 reset_deterministic_timeout();
01952 static deterministic_timeout_exception e;
01953 unsigned weight
01954 = term_to_unsigned<unsigned>(t_weight,
01955 "ppl_set_deterministic_timeout/1");
01956 p_deterministic_timeout_object =
01957 new Weightwatch(weight, abandon_expensive_computations, e);
01958 return PROLOG_SUCCESS;
01959 #else
01960 used(t_weight);
01961 return PROLOG_FAILURE;
01962 #endif
01963 }
01964 CATCH_ALL;
01965 }
01966
01967 extern "C" Prolog_foreign_return_type
01968 ppl_reset_deterministic_timeout() {
01969 try {
01970 #ifdef PPL_WATCHDOG_LIBRARY_ENABLED
01971 reset_deterministic_timeout();
01972 return PROLOG_SUCCESS;
01973 #else
01974 return PROLOG_FAILURE;
01975 #endif
01976 }
01977 CATCH_ALL;
01978 }
01979
01980 extern "C" Prolog_foreign_return_type
01981 ppl_Coefficient_bits(Prolog_term_ref t_bits) {
01982 try {
01983 if (unify_ulong(t_bits, PPL_COEFFICIENT_BITS))
01984 return PROLOG_SUCCESS;
01985 }
01986 CATCH_ALL;
01987 }
01988
01989 extern "C" Prolog_foreign_return_type
01990 ppl_Coefficient_is_bounded() {
01991 try {
01992 if (std::numeric_limits<Coefficient>::is_bounded)
01993 return PROLOG_SUCCESS;
01994 }
01995 CATCH_ALL;
01996 }
01997
01998 extern "C" Prolog_foreign_return_type
01999 ppl_Coefficient_min(Prolog_term_ref t_min) {
02000 try {
02001 if (std::numeric_limits<Coefficient>::is_bounded) {
02002 PPL_DIRTY_TEMP_COEFFICIENT(min);
02003 min = std::numeric_limits<Coefficient>::min();
02004 if (Prolog_has_unbounded_integers
02005 || (min >= Prolog_min_integer && min <= Prolog_min_integer))
02006 return Prolog_unify_Coefficient(t_min, min)
02007 ? PROLOG_SUCCESS : PROLOG_FAILURE;
02008 }
02009 }
02010 CATCH_ALL;
02011 }
02012
02013 extern "C" Prolog_foreign_return_type
02014 ppl_Coefficient_max(Prolog_term_ref t_max) {
02015 try {
02016 if (std::numeric_limits<Coefficient>::is_bounded) {
02017 PPL_DIRTY_TEMP_COEFFICIENT(max);
02018 max = std::numeric_limits<Coefficient>::max();
02019 if (Prolog_has_unbounded_integers
02020 || (max >= Prolog_min_integer && max <= Prolog_min_integer))
02021 return Prolog_unify_Coefficient(t_max, max)
02022 ? PROLOG_SUCCESS : PROLOG_FAILURE;
02023 }
02024 }
02025 CATCH_ALL;
02026 }
02027
02028 extern "C" Prolog_foreign_return_type
02029 ppl_new_MIP_Problem_from_space_dimension
02030 (Prolog_term_ref t_nd, Prolog_term_ref t_mip) {
02031 static const char* where = "ppl_MIP_Problem_from_space_dimension/2";
02032 try {
02033 dimension_type d = term_to_unsigned<dimension_type>(t_nd, where);
02034 MIP_Problem* mip = new MIP_Problem(d);
02035 Prolog_term_ref tmp = Prolog_new_term_ref();
02036 Prolog_put_address(tmp, mip);
02037 if (Prolog_unify(t_mip, tmp)) {
02038 PPL_REGISTER(mip);
02039 return PROLOG_SUCCESS;
02040 }
02041 else
02042 delete mip;
02043 }
02044 CATCH_ALL;
02045 }
02046
02047 extern "C" Prolog_foreign_return_type
02048 ppl_new_MIP_Problem(Prolog_term_ref t_nd,
02049 Prolog_term_ref t_clist,
02050 Prolog_term_ref t_le_expr,
02051 Prolog_term_ref t_opt,
02052 Prolog_term_ref t_mip) {
02053 static const char* where = "ppl_new_MIP_Problem/5";
02054 try {
02055 Constraint_System cs;
02056 Prolog_term_ref c = Prolog_new_term_ref();
02057 while (Prolog_is_cons(t_clist)) {
02058 Prolog_get_cons(t_clist, c, t_clist);
02059 cs.insert(build_constraint(c, where));
02060 }
02061
02062 check_nil_terminating(t_clist, where);
02063
02064 const Linear_Expression le = build_linear_expression(t_le_expr, where);
02065 Prolog_atom opt = term_to_optimization_mode(t_opt, where);
02066 Optimization_Mode mode = (opt == a_max) ? MAXIMIZATION : MINIMIZATION;
02067
02068 MIP_Problem* mip
02069 = new MIP_Problem(term_to_unsigned<dimension_type>(t_nd, where),
02070 cs, le, mode);
02071 Prolog_term_ref tmp = Prolog_new_term_ref();
02072 Prolog_put_address(tmp, mip);
02073 if (Prolog_unify(t_mip, tmp)) {
02074 PPL_REGISTER(mip);
02075 return PROLOG_SUCCESS;
02076 }
02077 else
02078 delete mip;
02079 }
02080 CATCH_ALL;
02081 }
02082
02083 extern "C" Prolog_foreign_return_type
02084 ppl_new_MIP_Problem_from_MIP_Problem(Prolog_term_ref t_mip_source,
02085 Prolog_term_ref t_mip) {
02086 static const char* where = "ppl_new_MIP_Problem_from_MIP_Problem/2";
02087 try {
02088 const MIP_Problem* mip_source
02089 = static_cast<const MIP_Problem*>
02090 (term_to_handle<MIP_Problem>(t_mip_source, where));
02091 PPL_CHECK(mip_source);
02092 MIP_Problem* mip = new MIP_Problem(*mip_source);
02093 Prolog_term_ref tmp = Prolog_new_term_ref();
02094 Prolog_put_address(tmp, mip);
02095 if (Prolog_unify(t_mip, tmp)) {
02096 PPL_REGISTER(mip);
02097 return PROLOG_SUCCESS;
02098 }
02099 else
02100 delete mip;
02101 }
02102 CATCH_ALL;
02103 }
02104
02105 extern "C" Prolog_foreign_return_type
02106 ppl_MIP_Problem_swap(Prolog_term_ref t_lhs, Prolog_term_ref t_rhs) {
02107 static const char* where = "ppl_MIP_Problem_swap/2";
02108 try {
02109 MIP_Problem* lhs = term_to_handle<MIP_Problem>(t_lhs, where);
02110 MIP_Problem* rhs = term_to_handle<MIP_Problem>(t_rhs, where);
02111 PPL_CHECK(lhs);
02112 PPL_CHECK(rhs);
02113 lhs->swap(*rhs);
02114 return PROLOG_SUCCESS;
02115 }
02116 CATCH_ALL;
02117 }
02118
02119 extern "C" Prolog_foreign_return_type
02120 ppl_delete_MIP_Problem(Prolog_term_ref t_mip) {
02121 static const char* where = "ppl_delete_MIP_Problem/1";
02122 try {
02123 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02124 PPL_UNREGISTER(mip);
02125 delete mip;
02126 return PROLOG_SUCCESS;
02127 }
02128 CATCH_ALL;
02129 }
02130
02131 extern "C" Prolog_foreign_return_type
02132 ppl_MIP_Problem_space_dimension(Prolog_term_ref t_mip, Prolog_term_ref t_sd) {
02133 static const char* where = "ppl_MIP_Problem_space_dimension/2";
02134 try {
02135 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02136 PPL_CHECK(mip);
02137 if (unify_ulong(t_sd, mip->space_dimension()))
02138 return PROLOG_SUCCESS;
02139 }
02140 CATCH_ALL;
02141 }
02142
02143 extern "C" Prolog_foreign_return_type
02144 ppl_MIP_Problem_integer_space_dimensions(Prolog_term_ref t_mip,
02145 Prolog_term_ref t_vlist) {
02146 static const char* where = "ppl_MIP_Problem_integer_space_dimensions/2";
02147 try {
02148 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02149 PPL_CHECK(mip);
02150
02151 Prolog_term_ref tail = Prolog_new_term_ref();
02152 Prolog_put_atom(tail, a_nil);
02153 const Variables_Set& i_vars = mip->integer_space_dimensions();
02154
02155 for (Variables_Set::const_iterator i = i_vars.begin(),
02156 i_end = i_vars.end(); i != i_end; ++i)
02157 Prolog_construct_cons(tail, variable_term(*i), tail);
02158
02159 if (Prolog_unify(t_vlist, tail))
02160 return PROLOG_SUCCESS;
02161 }
02162 CATCH_ALL;
02163 }
02164
02165 extern "C" Prolog_foreign_return_type
02166 ppl_MIP_Problem_constraints(Prolog_term_ref t_mip,
02167 Prolog_term_ref t_clist) {
02168 static const char* where = "ppl_MIP_Problem_constraints/2";
02169 try {
02170 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02171 PPL_CHECK(mip);
02172
02173 Prolog_term_ref tail = Prolog_new_term_ref();
02174 Prolog_put_atom(tail, a_nil);
02175 for (MIP_Problem::const_iterator i = mip->constraints_begin(),
02176 i_end = mip->constraints_end(); i != i_end; ++i)
02177 Prolog_construct_cons(tail, constraint_term(*i), tail);
02178
02179 if (Prolog_unify(t_clist, tail))
02180 return PROLOG_SUCCESS;
02181 }
02182 CATCH_ALL;
02183 }
02184
02185 extern "C" Prolog_foreign_return_type
02186 ppl_MIP_Problem_objective_function(Prolog_term_ref t_mip,
02187 Prolog_term_ref t_le_expr) {
02188 static const char* where = "ppl_MIP_Problem_objective_function/2";
02189 try {
02190 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02191 PPL_CHECK(mip);
02192
02193 const Linear_Expression& le = mip->objective_function();
02194 Prolog_term_ref t = get_linear_expression(le);
02195
02196 if (Prolog_unify(t_le_expr, t))
02197 return PROLOG_SUCCESS;
02198 }
02199 CATCH_ALL;
02200 }
02201
02202 extern "C" Prolog_foreign_return_type
02203 ppl_MIP_Problem_optimization_mode(Prolog_term_ref t_mip,
02204 Prolog_term_ref t_opt) {
02205 static const char* where = "ppl_MIP_Problem_optimization_mode/2";
02206 try {
02207 MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02208 PPL_CHECK(mip);
02209
02210 Optimization_Mode mode = mip->optimization_mode();
02211 Prolog_term_ref t = Prolog_new_term_ref();
02212 Prolog_atom a = (mode == MAXIMIZATION) ? a_max : a_min;
02213 Prolog_put_atom(t, a);
02214 if (Prolog_unify(t_opt, t))
02215 return PROLOG_SUCCESS;
02216 }
02217 CATCH_ALL;
02218 }
02219
02220 extern "C" Prolog_foreign_return_type
02221 ppl_MIP_Problem_clear(Prolog_term_ref t_mip) {
02222 static const char* where = "ppl_MIP_Problem_clear/1";
02223 try {
02224 MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02225 PPL_CHECK(mip);
02226 mip->clear();
02227 return PROLOG_SUCCESS;
02228 }
02229 CATCH_ALL;
02230 }
02231
02232 extern "C" Prolog_foreign_return_type
02233 ppl_MIP_Problem_add_space_dimensions_and_embed
02234 (Prolog_term_ref t_mip, Prolog_term_ref t_nnd) {
02235 static const char* where
02236 = "ppl_MIP_Problem_add_space_dimensions_and_embed/2";
02237 try {
02238 MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02239 PPL_CHECK(mip);
02240 dimension_type d = term_to_unsigned<dimension_type>(t_nnd, where);
02241 mip->add_space_dimensions_and_embed(d);
02242 return PROLOG_SUCCESS;
02243 }
02244 CATCH_ALL;
02245 }
02246
02247 extern "C" Prolog_foreign_return_type
02248 ppl_MIP_Problem_add_to_integer_space_dimensions(Prolog_term_ref t_mip,
02249 Prolog_term_ref t_vlist) {
02250 static const char* where
02251 = "ppl_MIP_Problem_add_to_integer_space_dimensions/2";
02252 try {
02253 MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02254 PPL_CHECK(mip);
02255 Variables_Set i_vars;
02256 Prolog_term_ref v = Prolog_new_term_ref();
02257
02258 while (Prolog_is_cons(t_vlist)) {
02259 Prolog_get_cons(t_vlist, v, t_vlist);
02260 i_vars.insert(term_to_Variable(v, where).id());
02261 }
02262
02263
02264 check_nil_terminating(t_vlist, where);
02265
02266 mip->add_to_integer_space_dimensions(i_vars);
02267 return PROLOG_SUCCESS;
02268 }
02269 CATCH_ALL;
02270 }
02271
02272 extern "C" Prolog_foreign_return_type
02273 ppl_MIP_Problem_add_constraint(Prolog_term_ref t_mip, Prolog_term_ref t_c) {
02274 static const char* where = "ppl_MIP_Problem_add_constraint/2";
02275 try {
02276 MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02277 PPL_CHECK(mip);
02278 mip->add_constraint(build_constraint(t_c, where));
02279 return PROLOG_SUCCESS;
02280 }
02281 CATCH_ALL;
02282 }
02283
02284 extern "C" Prolog_foreign_return_type
02285 ppl_MIP_Problem_add_constraints(Prolog_term_ref t_mip,
02286 Prolog_term_ref t_clist) {
02287 static const char* where = "ppl_MIP_Problem_add_constraints/2";
02288 try {
02289 MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02290 PPL_CHECK(mip);
02291 Constraint_System cs;
02292 Prolog_term_ref c = Prolog_new_term_ref();
02293
02294 while (Prolog_is_cons(t_clist)) {
02295 Prolog_get_cons(t_clist, c, t_clist);
02296 cs.insert(build_constraint(c, where));
02297 }
02298
02299
02300 check_nil_terminating(t_clist, where);
02301
02302 mip->add_constraints(cs);
02303 return PROLOG_SUCCESS;
02304 }
02305 CATCH_ALL;
02306 }
02307
02308 extern "C" Prolog_foreign_return_type
02309 ppl_MIP_Problem_set_objective_function(Prolog_term_ref t_mip,
02310 Prolog_term_ref t_le_expr) {
02311 static const char* where = "ppl_MIP_Problem_set_objective_function/2";
02312 try {
02313 MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02314 PPL_CHECK(mip);
02315 mip->set_objective_function(build_linear_expression(t_le_expr, where));
02316 return PROLOG_SUCCESS;
02317 }
02318 CATCH_ALL;
02319 }
02320
02321 extern "C" Prolog_foreign_return_type
02322 ppl_MIP_Problem_set_optimization_mode(Prolog_term_ref t_mip,
02323 Prolog_term_ref t_opt) {
02324 static const char* where = "ppl_MIP_Problem_set_optimization_mode/2";
02325 try {
02326 MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02327 PPL_CHECK(mip);
02328
02329 Prolog_atom opt = term_to_optimization_mode(t_opt, where);
02330 Optimization_Mode mode = (opt == a_max) ? MAXIMIZATION : MINIMIZATION;
02331 mip->set_optimization_mode(mode);
02332 return PROLOG_SUCCESS;
02333 }
02334 CATCH_ALL;
02335 }
02336
02337 extern "C" Prolog_foreign_return_type
02338 ppl_MIP_Problem_set_control_parameter(Prolog_term_ref t_mip,
02339 Prolog_term_ref t_cp_value) {
02340 static const char* where = "ppl_MIP_Problem_set_control_parameter/2";
02341 try {
02342 MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02343 PPL_CHECK(mip);
02344
02345 Prolog_atom cp_value = term_to_control_parameter_value(t_cp_value, where);
02346 if (cp_value == a_pricing_steepest_edge_float)
02347 mip->set_control_parameter(MIP_Problem::PRICING_STEEPEST_EDGE_FLOAT);
02348 else if (cp_value == a_pricing_steepest_edge_exact)
02349 mip->set_control_parameter(MIP_Problem::PRICING_STEEPEST_EDGE_EXACT);
02350 else if (cp_value == a_pricing_textbook)
02351 mip->set_control_parameter(MIP_Problem::PRICING_TEXTBOOK);
02352 else
02353 throw unknown_interface_error("ppl_MIP_Problem_get_control_parameter()");
02354 return PROLOG_SUCCESS;
02355 }
02356 CATCH_ALL;
02357 }
02358
02359 extern "C" Prolog_foreign_return_type
02360 ppl_MIP_Problem_get_control_parameter(Prolog_term_ref t_mip,
02361 Prolog_term_ref t_cp_name,
02362 Prolog_term_ref t_cp_value) {
02363 static const char* where = "ppl_MIP_Problem_get_control_parameter/3";
02364 try {
02365 MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02366 PPL_CHECK(mip);
02367 Prolog_atom cp_name = term_to_control_parameter_name(t_cp_name, where);
02368 MIP_Problem::Control_Parameter_Value ppl_cp_value;
02369 if (cp_name == a_pricing)
02370 ppl_cp_value = mip->get_control_parameter(MIP_Problem::PRICING);
02371 else
02372 throw unknown_interface_error("ppl_MIP_Problem_get_control_parameter()");
02373
02374 Prolog_term_ref t = Prolog_new_term_ref();
02375 Prolog_atom a;
02376 switch (ppl_cp_value) {
02377 case MIP_Problem::PRICING_STEEPEST_EDGE_FLOAT:
02378 a = a_pricing_steepest_edge_float;
02379 break;
02380 case MIP_Problem::PRICING_STEEPEST_EDGE_EXACT:
02381 a = a_pricing_steepest_edge_exact;
02382 break;
02383 case MIP_Problem::PRICING_TEXTBOOK:
02384 a = a_pricing_textbook;
02385 break;
02386 default:
02387 throw unknown_interface_error("ppl_MIP_Problem_get_control_parameter()");
02388 }
02389 Prolog_put_atom(t, a);
02390 if (Prolog_unify(t_cp_value, t))
02391 return PROLOG_SUCCESS;
02392 }
02393 CATCH_ALL;
02394 }
02395
02396 extern "C" Prolog_foreign_return_type
02397 ppl_MIP_Problem_is_satisfiable(Prolog_term_ref t_mip) {
02398 static const char* where = "ppl_MIP_Problem_is_satisfiable/1";
02399 try {
02400 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02401 PPL_CHECK(mip);
02402 if (mip->is_satisfiable())
02403 return PROLOG_SUCCESS;
02404 }
02405 CATCH_ALL;
02406 }
02407
02408 extern "C" Prolog_foreign_return_type
02409 ppl_MIP_Problem_solve(Prolog_term_ref t_mip, Prolog_term_ref t_status) {
02410 static const char* where = "ppl_MIP_Problem_solve/2";
02411 try {
02412 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02413 PPL_CHECK(mip);
02414
02415 Prolog_atom a;
02416 switch (mip->solve()) {
02417 case UNFEASIBLE_MIP_PROBLEM:
02418 a = a_unfeasible;
02419 break;
02420 case UNBOUNDED_MIP_PROBLEM:
02421 a = a_unbounded;
02422 break;
02423 case OPTIMIZED_MIP_PROBLEM:
02424 a = a_optimized;
02425 break;
02426 default:
02427 throw unknown_interface_error("ppl_MIP_Problem_solve()");
02428 }
02429 Prolog_term_ref t = Prolog_new_term_ref();
02430 Prolog_put_atom(t, a);
02431 if (Prolog_unify(t_status, t))
02432 return PROLOG_SUCCESS;
02433 }
02434 CATCH_ALL;
02435 }
02436
02437 extern "C" Prolog_foreign_return_type
02438 ppl_MIP_Problem_feasible_point(Prolog_term_ref t_mip,
02439 Prolog_term_ref t_g) {
02440 static const char* where = "ppl_MIP_Problem_feasible_point/2";
02441 try {
02442 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02443 PPL_CHECK(mip);
02444 const Generator& g = mip->feasible_point();
02445 if (Prolog_unify(t_g, generator_term(g)))
02446 return PROLOG_SUCCESS;
02447 }
02448 CATCH_ALL;
02449 }
02450
02451 extern "C" Prolog_foreign_return_type
02452 ppl_MIP_Problem_optimizing_point(Prolog_term_ref t_mip,
02453 Prolog_term_ref t_g) {
02454 static const char* where = "ppl_MIP_Problem_optimizing_point/2";
02455 try {
02456 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02457 PPL_CHECK(mip);
02458 const Generator& g = mip->optimizing_point();
02459 if (Prolog_unify(t_g, generator_term(g)))
02460 return PROLOG_SUCCESS;
02461 }
02462 CATCH_ALL;
02463 }
02464
02465 extern "C" Prolog_foreign_return_type
02466 ppl_MIP_Problem_optimal_value(Prolog_term_ref t_mip,
02467 Prolog_term_ref t_n,
02468 Prolog_term_ref t_d) {
02469 static const char* where = "ppl_MIP_Problem_optimal_value/3";
02470 try {
02471 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02472 PPL_CHECK(mip);
02473 PPL_DIRTY_TEMP_COEFFICIENT(n);
02474 PPL_DIRTY_TEMP_COEFFICIENT(d);
02475 mip->optimal_value(n, d);
02476 if (Prolog_unify_Coefficient(t_n, n)
02477 && Prolog_unify_Coefficient(t_d, d))
02478 return PROLOG_SUCCESS;
02479 }
02480 CATCH_ALL;
02481 }
02482
02483 extern "C" Prolog_foreign_return_type
02484 ppl_MIP_Problem_evaluate_objective_function(Prolog_term_ref t_mip,
02485 Prolog_term_ref t_g,
02486 Prolog_term_ref t_n,
02487 Prolog_term_ref t_d) {
02488 static const char* where = "ppl_MIP_Problem_evaluate_objective_function/4";
02489 try {
02490 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02491 PPL_CHECK(mip);
02492 PPL_DIRTY_TEMP_COEFFICIENT(n);
02493 PPL_DIRTY_TEMP_COEFFICIENT(d);
02494 mip->evaluate_objective_function(build_generator(t_g, where), n, d);
02495 if (Prolog_unify_Coefficient(t_n, n)
02496 && Prolog_unify_Coefficient(t_d, d))
02497 return PROLOG_SUCCESS;
02498 }
02499 CATCH_ALL;
02500 }
02501
02502 extern "C" Prolog_foreign_return_type
02503 ppl_MIP_Problem_OK(Prolog_term_ref t_mip) {
02504 static const char* where = "ppl_MIP_Problem_OK/1";
02505 try {
02506 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02507 PPL_CHECK(mip);
02508 if (mip->OK())
02509 return PROLOG_SUCCESS;
02510 }
02511 CATCH_ALL;
02512 }
02513
02514 extern "C" Prolog_foreign_return_type
02515 ppl_MIP_Problem_ascii_dump(Prolog_term_ref t_mip) {
02516 static const char* where = "ppl_MIP_Problem_ascii_dump/1";
02517 try {
02518 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
02519 PPL_CHECK(mip);
02520 mip->ascii_dump(std::cout);
02521 return PROLOG_SUCCESS;
02522 }
02523 CATCH_ALL;
02524 }
02525
02526 extern "C" Prolog_foreign_return_type
02527 ppl_new_PIP_Problem_from_space_dimension
02528 (Prolog_term_ref t_nd, Prolog_term_ref t_pip) {
02529 static const char* where = "ppl_PIP_Problem_from_space_dimension/2";
02530 try {
02531 dimension_type d = term_to_unsigned<dimension_type>(t_nd, where);
02532 PIP_Problem* pip = new PIP_Problem(d);
02533 Prolog_term_ref tmp = Prolog_new_term_ref();
02534 Prolog_put_address(tmp, pip);
02535 if (Prolog_unify(t_pip, tmp)) {
02536 PPL_REGISTER(pip);
02537 return PROLOG_SUCCESS;
02538 }
02539 else
02540 delete pip;
02541 }
02542 CATCH_ALL;
02543 }
02544
02545 extern "C" Prolog_foreign_return_type
02546 ppl_new_PIP_Problem(Prolog_term_ref t_dim,
02547 Prolog_term_ref t_cs,
02548 Prolog_term_ref t_params,
02549 Prolog_term_ref t_pip) {
02550 static const char* where = "ppl_new_PIP_Problem/4";
02551 try {
02552 dimension_type dim = term_to_unsigned<dimension_type>(t_dim, where);
02553 Constraint_System cs;
02554 Prolog_term_ref t_c = Prolog_new_term_ref();
02555 while (Prolog_is_cons(t_cs)) {
02556 Prolog_get_cons(t_cs, t_c, t_cs);
02557 cs.insert(build_constraint(t_c, where));
02558 }
02559
02560 check_nil_terminating(t_cs, where);
02561
02562 Variables_Set params;
02563 Prolog_term_ref t_par = Prolog_new_term_ref();
02564 while (Prolog_is_cons(t_params)) {
02565 Prolog_get_cons(t_params, t_par, t_params);
02566 params.insert(term_to_Variable(t_par, where).id());
02567 }
02568
02569 check_nil_terminating(t_params, where);
02570
02571 PIP_Problem* pip = new PIP_Problem(dim, cs.begin(), cs.end(), params);
02572 Prolog_term_ref tmp = Prolog_new_term_ref();
02573 Prolog_put_address(tmp, pip);
02574 if (Prolog_unify(t_pip, tmp)) {
02575 PPL_REGISTER(pip);
02576 return PROLOG_SUCCESS;
02577 }
02578 else
02579 delete pip;
02580 }
02581 CATCH_ALL;
02582 }
02583
02584 extern "C" Prolog_foreign_return_type
02585 ppl_new_PIP_Problem_from_PIP_Problem(Prolog_term_ref t_pip_source,
02586 Prolog_term_ref t_pip) {
02587 static const char* where = "ppl_new_PIP_Problem_from_PIP_Problem/2";
02588 try {
02589 const PIP_Problem* pip_source
02590 = static_cast<const PIP_Problem*>
02591 (term_to_handle<PIP_Problem>(t_pip_source, where));
02592 PPL_CHECK(pip_source);
02593 PIP_Problem* pip = new PIP_Problem(*pip_source);
02594 Prolog_term_ref tmp = Prolog_new_term_ref();
02595 Prolog_put_address(tmp, pip);
02596 if (Prolog_unify(t_pip, tmp)) {
02597 PPL_REGISTER(pip);
02598 return PROLOG_SUCCESS;
02599 }
02600 else
02601 delete pip;
02602 }
02603 CATCH_ALL;
02604 }
02605
02606 extern "C" Prolog_foreign_return_type
02607 ppl_PIP_Problem_swap(Prolog_term_ref t_lhs, Prolog_term_ref t_rhs) {
02608 static const char* where = "ppl_PIP_Problem_swap/2";
02609 try {
02610 PIP_Problem* lhs = term_to_handle<PIP_Problem>(t_lhs, where);
02611 PIP_Problem* rhs = term_to_handle<PIP_Problem>(t_rhs, where);
02612 PPL_CHECK(lhs);
02613 PPL_CHECK(rhs);
02614 lhs->swap(*rhs);
02615 return PROLOG_SUCCESS;
02616 }
02617 CATCH_ALL;
02618 }
02619
02620 extern "C" Prolog_foreign_return_type
02621 ppl_delete_PIP_Problem(Prolog_term_ref t_pip) {
02622 static const char* where = "ppl_delete_PIP_Problem/1";
02623 try {
02624 const PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
02625 PPL_UNREGISTER(pip);
02626 delete pip;
02627 return PROLOG_SUCCESS;
02628 }
02629 CATCH_ALL;
02630 }
02631
02632 extern "C" Prolog_foreign_return_type
02633 ppl_PIP_Problem_space_dimension(Prolog_term_ref t_pip, Prolog_term_ref t_sd) {
02634 static const char* where = "ppl_PIP_Problem_space_dimension/2";
02635 try {
02636 const PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
02637 PPL_CHECK(pip);
02638 if (unify_ulong(t_sd, pip->space_dimension()))
02639 return PROLOG_SUCCESS;
02640 }
02641 CATCH_ALL;
02642 }
02643
02644 extern "C" Prolog_foreign_return_type
02645 ppl_PIP_Problem_parameter_space_dimensions(Prolog_term_ref t_pip,
02646 Prolog_term_ref t_vlist) {
02647 static const char* where = "ppl_PIP_Problem_parameter_space_dimensions/2";
02648 try {
02649 const PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
02650 PPL_CHECK(pip);
02651
02652 Prolog_term_ref tail = Prolog_new_term_ref();
02653 Prolog_put_atom(tail, a_nil);
02654 const Variables_Set& params = pip->parameter_space_dimensions();
02655
02656 for (Variables_Set::const_iterator i = params.begin(),
02657 i_end = params.end(); i != i_end; ++i)
02658 Prolog_construct_cons(tail, variable_term(*i), tail);
02659
02660 if (Prolog_unify(t_vlist, tail))
02661 return PROLOG_SUCCESS;
02662 }
02663 CATCH_ALL;
02664 }
02665
02666 extern "C" Prolog_foreign_return_type
02667 ppl_PIP_Problem_constraints(Prolog_term_ref t_pip,
02668 Prolog_term_ref t_clist) {
02669 static const char* where = "ppl_PIP_Problem_constraints/2";
02670 try {
02671 const PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
02672 PPL_CHECK(pip);
02673
02674 Prolog_term_ref tail = Prolog_new_term_ref();
02675 Prolog_put_atom(tail, a_nil);
02676 for (PIP_Problem::const_iterator i = pip->constraints_begin(),
02677 i_end = pip->constraints_end(); i != i_end; ++i)
02678 Prolog_construct_cons(tail, constraint_term(*i), tail);
02679
02680 if (Prolog_unify(t_clist, tail))
02681 return PROLOG_SUCCESS;
02682 }
02683 CATCH_ALL;
02684 }
02685
02686 extern "C" Prolog_foreign_return_type
02687 ppl_PIP_Problem_clear(Prolog_term_ref t_pip) {
02688 static const char* where = "ppl_PIP_Problem_clear/1";
02689 try {
02690 PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
02691 PPL_CHECK(pip);
02692 pip->clear();
02693 return PROLOG_SUCCESS;
02694 }
02695 CATCH_ALL;
02696 }
02697
02698 extern "C" Prolog_foreign_return_type
02699 ppl_PIP_Problem_add_space_dimensions_and_embed
02700 (Prolog_term_ref t_pip,
02701 Prolog_term_ref t_num_vars,
02702 Prolog_term_ref t_num_params) {
02703 static const char* where
02704 = "ppl_PIP_Problem_add_space_dimensions_and_embed/3";
02705 try {
02706 PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
02707 PPL_CHECK(pip);
02708 dimension_type nv = term_to_unsigned<dimension_type>(t_num_vars, where);
02709 dimension_type np = term_to_unsigned<dimension_type>(t_num_params, where);
02710 pip->add_space_dimensions_and_embed(nv, np);
02711 return PROLOG_SUCCESS;
02712 }
02713 CATCH_ALL;
02714 }
02715
02716 extern "C" Prolog_foreign_return_type
02717 ppl_PIP_Problem_add_to_parameter_space_dimensions(Prolog_term_ref t_pip,
02718 Prolog_term_ref t_vlist) {
02719 static const char* where
02720 = "ppl_PIP_Problem_add_to_parameter_space_dimensions/2";
02721 try {
02722 PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
02723 PPL_CHECK(pip);
02724 Variables_Set params;
02725 Prolog_term_ref v = Prolog_new_term_ref();
02726
02727 while (Prolog_is_cons(t_vlist)) {
02728 Prolog_get_cons(t_vlist, v, t_vlist);
02729 params.insert(term_to_Variable(v, where).id());
02730 }
02731
02732
02733 check_nil_terminating(t_vlist, where);
02734
02735 pip->add_to_parameter_space_dimensions(params);
02736 return PROLOG_SUCCESS;
02737 }
02738 CATCH_ALL;
02739 }
02740
02741 extern "C" Prolog_foreign_return_type
02742 ppl_PIP_Problem_add_constraint(Prolog_term_ref t_pip, Prolog_term_ref t_c) {
02743 static const char* where = "ppl_PIP_Problem_add_constraint/2";
02744 try {
02745 PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
02746 PPL_CHECK(pip);
02747 pip->add_constraint(build_constraint(t_c, where));
02748 return PROLOG_SUCCESS;
02749 }
02750 CATCH_ALL;
02751 }
02752
02753 extern "C" Prolog_foreign_return_type
02754 ppl_PIP_Problem_add_constraints(Prolog_term_ref t_pip,
02755 Prolog_term_ref t_clist) {
02756 static const char* where = "ppl_PIP_Problem_add_constraints/2";
02757 try {
02758 PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
02759 PPL_CHECK(pip);
02760 Constraint_System cs;
02761 Prolog_term_ref c = Prolog_new_term_ref();
02762
02763 while (Prolog_is_cons(t_clist)) {
02764 Prolog_get_cons(t_clist, c, t_clist);
02765 cs.insert(build_constraint(c, where));
02766 }
02767
02768
02769 check_nil_terminating(t_clist, where);
02770
02771 pip->add_constraints(cs);
02772 return PROLOG_SUCCESS;
02773 }
02774 CATCH_ALL;
02775 }
02776
02777 extern "C" Prolog_foreign_return_type
02778 ppl_PIP_Problem_get_control_parameter(Prolog_term_ref t_pip,
02779 Prolog_term_ref t_cp_name,
02780 Prolog_term_ref t_cp_value) {
02781 static const char* where = "ppl_PIP_Problem_get_control_parameter/3";
02782 try {
02783 PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
02784 PPL_CHECK(pip);
02785 Prolog_atom cp_name = term_to_pip_problem_control_parameter_name(t_cp_name, where);
02786 PIP_Problem::Control_Parameter_Value ppl_cp_value;
02787 Prolog_atom a;
02788 if (cp_name == a_cutting_strategy) {
02789 ppl_cp_value
02790 = pip->get_control_parameter(PIP_Problem::CUTTING_STRATEGY);
02791 switch (ppl_cp_value) {
02792 case PIP_Problem::CUTTING_STRATEGY_FIRST:
02793 a = a_cutting_strategy_first;
02794 break;
02795 case PIP_Problem::CUTTING_STRATEGY_DEEPEST:
02796 a = a_cutting_strategy_deepest;
02797 break;
02798 case PIP_Problem::CUTTING_STRATEGY_ALL:
02799 a = a_cutting_strategy_all;
02800 break;
02801 default:
02802 throw unknown_interface_error(
02803 "ppl_PIP_Problem_get_control_parameter()");
02804 }
02805 }
02806 else if (cp_name == a_pivot_row_strategy) {
02807 ppl_cp_value
02808 = pip->get_control_parameter(PIP_Problem::PIVOT_ROW_STRATEGY);
02809 switch (ppl_cp_value) {
02810 case PIP_Problem::PIVOT_ROW_STRATEGY_FIRST:
02811 a = a_pivot_row_strategy_first;
02812 break;
02813 case PIP_Problem::PIVOT_ROW_STRATEGY_MAX_COLUMN:
02814 a = a_pivot_row_strategy_max_column;
02815 break;
02816 default:
02817 throw unknown_interface_error(
02818 "ppl_PIP_Problem_get_control_parameter()");
02819 }
02820 }
02821 else
02822 throw unknown_interface_error("ppl_PIP_Problem_get_control_parameter()");
02823
02824 Prolog_term_ref t = Prolog_new_term_ref();
02825 Prolog_put_atom(t, a);
02826 if (Prolog_unify(t_cp_value, t))
02827 return PROLOG_SUCCESS;
02828 }
02829 CATCH_ALL;
02830 }
02831
02832 extern "C" Prolog_foreign_return_type
02833 ppl_PIP_Problem_set_control_parameter(Prolog_term_ref t_pip,
02834 Prolog_term_ref t_cp_value) {
02835 static const char* where = "ppl_PIP_Problem_set_control_parameter/2";
02836 try {
02837 PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
02838 PPL_CHECK(pip);
02839
02840 Prolog_atom cp_value = term_to_pip_problem_control_parameter_value(t_cp_value, where);
02841 if (cp_value == a_cutting_strategy_first)
02842 pip->set_control_parameter(PIP_Problem::CUTTING_STRATEGY_FIRST);
02843 else if (cp_value == a_cutting_strategy_deepest)
02844 pip->set_control_parameter(PIP_Problem::CUTTING_STRATEGY_DEEPEST);
02845 else if (cp_value == a_cutting_strategy_all)
02846 pip->set_control_parameter(PIP_Problem::CUTTING_STRATEGY_ALL);
02847 else if (cp_value == a_pivot_row_strategy_first)
02848 pip->set_control_parameter(PIP_Problem::PIVOT_ROW_STRATEGY_FIRST);
02849 else if (cp_value == a_pivot_row_strategy_max_column)
02850 pip->set_control_parameter(PIP_Problem::PIVOT_ROW_STRATEGY_MAX_COLUMN);
02851 else
02852 throw unknown_interface_error("ppl_PIP_Problem_set_control_parameter()");
02853 return PROLOG_SUCCESS;
02854 }
02855 CATCH_ALL;
02856 }
02857
02858 extern "C" Prolog_foreign_return_type
02859 ppl_PIP_Problem_has_big_parameter_dimension(Prolog_term_ref t_pip,
02860 Prolog_term_ref t_d) {
02861 static const char* where = "ppl_PIP_Problem_get_big_parameter_dimension/2";
02862 try {
02863 PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
02864 PPL_CHECK(pip);
02865 dimension_type dim = pip->get_big_parameter_dimension();
02866 if (dim == not_a_dimension())
02867 return PROLOG_FAILURE;
02868 if (unify_ulong(t_d, dim))
02869 return PROLOG_SUCCESS;
02870 }
02871 CATCH_ALL;
02872 }
02873
02874 extern "C" Prolog_foreign_return_type
02875 ppl_PIP_Problem_set_big_parameter_dimension(Prolog_term_ref t_pip,
02876 Prolog_term_ref t_d) {
02877 static const char* where = "ppl_MIP_Problem_set_big_parameter_dimension/2";
02878 try {
02879 PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
02880 PPL_CHECK(pip);
02881 dimension_type d = term_to_unsigned<dimension_type>(t_d, where);
02882 pip->set_big_parameter_dimension(d);
02883 return PROLOG_SUCCESS;
02884 }
02885 CATCH_ALL;
02886 }
02887
02888 extern "C" Prolog_foreign_return_type
02889 ppl_PIP_Problem_is_satisfiable(Prolog_term_ref t_pip) {
02890 static const char* where = "ppl_PIP_Problem_is_satisfiable/1";
02891 try {
02892 const PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
02893 PPL_CHECK(pip);
02894 if (pip->is_satisfiable())
02895 return PROLOG_SUCCESS;
02896 }
02897 CATCH_ALL;
02898 }
02899
02900 extern "C" Prolog_foreign_return_type
02901 ppl_PIP_Problem_solve(Prolog_term_ref t_pip, Prolog_term_ref t_status) {
02902 static const char* where = "ppl_PIP_Problem_solve/2";
02903 try {
02904 const PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
02905 PPL_CHECK(pip);
02906
02907 Prolog_atom a;
02908 switch (pip->solve()) {
02909 case UNFEASIBLE_PIP_PROBLEM:
02910 a = a_unfeasible;
02911 break;
02912 case OPTIMIZED_PIP_PROBLEM:
02913 a = a_optimized;
02914 break;
02915 default:
02916 throw unknown_interface_error("ppl_PIP_Problem_solve()");
02917 }
02918 Prolog_term_ref t = Prolog_new_term_ref();
02919 Prolog_put_atom(t, a);
02920 if (Prolog_unify(t_status, t))
02921 return PROLOG_SUCCESS;
02922 }
02923 CATCH_ALL;
02924 }
02925
02926 extern "C" Prolog_foreign_return_type
02927 ppl_PIP_Problem_solution(Prolog_term_ref t_pip,
02928 Prolog_term_ref t_pip_tree) {
02929 static const char* where = "ppl_PIP_Problem_solution/2";
02930 try {
02931 const PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
02932 PPL_CHECK(pip);
02933 PIP_Tree_Node* sol = const_cast<PIP_Tree_Node*>(pip->solution());
02934 Prolog_term_ref t_sol = Prolog_new_term_ref();
02935 Prolog_put_address(t_sol, sol);
02936 if (Prolog_unify(t_pip_tree, t_sol)) {
02937 PPL_WEAK_REGISTER(sol);
02938 return PROLOG_SUCCESS;
02939 }
02940 }
02941 CATCH_ALL;
02942 }
02943
02944 extern "C" Prolog_foreign_return_type
02945 ppl_PIP_Problem_optimizing_solution(Prolog_term_ref t_pip,
02946 Prolog_term_ref t_pip_tree) {
02947 static const char* where = "ppl_PIP_Problem_optimizing_solution/2";
02948 try {
02949 const PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
02950 PPL_CHECK(pip);
02951 PIP_Tree_Node* sol = const_cast<PIP_Tree_Node*>(pip->optimizing_solution());
02952 Prolog_term_ref t_sol = Prolog_new_term_ref();
02953 Prolog_put_address(t_sol, sol);
02954 if (Prolog_unify(t_pip_tree, t_sol)) {
02955 PPL_WEAK_REGISTER(sol);
02956 return PROLOG_SUCCESS;
02957 }
02958 }
02959 CATCH_ALL;
02960 }
02961
02962 extern "C" Prolog_foreign_return_type
02963 ppl_PIP_Problem_OK(Prolog_term_ref t_pip) {
02964 static const char* where = "ppl_PIP_Problem_OK/1";
02965 try {
02966 const PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
02967 PPL_CHECK(pip);
02968 if (pip->OK())
02969 return PROLOG_SUCCESS;
02970 }
02971 CATCH_ALL;
02972 }
02973
02974 extern "C" Prolog_foreign_return_type
02975 ppl_PIP_Problem_ascii_dump(Prolog_term_ref t_pip) {
02976 static const char* where = "ppl_PIP_Problem_ascii_dump/1";
02977 try {
02978 const PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
02979 PPL_CHECK(pip);
02980 pip->ascii_dump(std::cout);
02981 return PROLOG_SUCCESS;
02982 }
02983 CATCH_ALL;
02984 }
02985
02986 extern "C" Prolog_foreign_return_type
02987 ppl_PIP_Tree_Node_constraints(Prolog_term_ref t_pip,
02988 Prolog_term_ref t_cs) {
02989 static const char* where = "ppl_PIP_Tree_Node_constraints/2";
02990 try {
02991 const PIP_Tree_Node* pip = term_to_handle<PIP_Tree_Node>(t_pip, where);
02992 PPL_CHECK(pip);
02993
02994 Prolog_term_ref tail = Prolog_new_term_ref();
02995 Prolog_put_atom(tail, a_nil);
02996 const Constraint_System& ppl_cs = pip->constraints();
02997 for (Constraint_System::const_iterator i = ppl_cs.begin(),
02998 ppl_cs_end = ppl_cs.end(); i != ppl_cs_end; ++i)
02999 Prolog_construct_cons(tail, constraint_term(*i), tail);
03000
03001 if (Prolog_unify(t_cs, tail)) {
03002 return PROLOG_SUCCESS;
03003 }
03004 }
03005 CATCH_ALL;
03006 }
03007
03008 extern "C" Prolog_foreign_return_type
03009 ppl_PIP_Tree_Node_is_solution(Prolog_term_ref t_pip) {
03010 static const char* where = "ppl_PIP_Tree_Node_as_solution/2";
03011 try {
03012 const PIP_Tree_Node* pip = term_to_handle<PIP_Tree_Node>(t_pip, where);
03013 PPL_CHECK(pip);
03014
03015 if (pip != 0 && pip->as_solution() != 0)
03016 return PROLOG_SUCCESS;
03017 return PROLOG_FAILURE;
03018 }
03019 CATCH_ALL;
03020 }
03021
03022 extern "C" Prolog_foreign_return_type
03023 ppl_PIP_Tree_Node_is_decision(Prolog_term_ref t_pip) {
03024 static const char* where = "ppl_PIP_Tree_Node_as_decision/2";
03025 try {
03026 const PIP_Tree_Node* pip = term_to_handle<PIP_Tree_Node>(t_pip, where);
03027 PPL_CHECK(pip);
03028
03029 if (pip != 0 && pip->as_decision() != 0)
03030 return PROLOG_SUCCESS;
03031 return PROLOG_FAILURE;
03032 }
03033 CATCH_ALL;
03034 }
03035
03036 extern "C" Prolog_foreign_return_type
03037 ppl_PIP_Tree_Node_is_bottom(Prolog_term_ref t_pip) {
03038 static const char* where = "ppl_PIP_Tree_Node_as_decision/2";
03039 try {
03040 const PIP_Tree_Node* pip = term_to_handle<PIP_Tree_Node>(t_pip, where);
03041 PPL_CHECK(pip);
03042
03043 if (pip == 0)
03044 return PROLOG_SUCCESS;
03045 return PROLOG_FAILURE;
03046 }
03047 CATCH_ALL;
03048 }
03049
03050 extern "C" Prolog_foreign_return_type
03051 ppl_PIP_Tree_Node_artificials(Prolog_term_ref t_tree_node,
03052 Prolog_term_ref t_artlist) {
03053 static const char* where = "ppl_PIP_Tree_Node_artificials/2";
03054 try {
03055 const PIP_Tree_Node* node
03056 = term_to_handle<PIP_Tree_Node>(t_tree_node, where);
03057 PPL_CHECK(node);
03058
03059 Prolog_term_ref tail = Prolog_new_term_ref();
03060 Prolog_put_atom(tail, a_nil);
03061 for (PIP_Tree_Node::Artificial_Parameter_Sequence::const_iterator
03062 i = node->art_parameter_begin(),
03063 arts_end = node->art_parameter_end(); i != arts_end; ++i)
03064 Prolog_construct_cons(tail, artificial_parameter_term(*i), tail);
03065
03066 if (Prolog_unify(t_artlist, tail))
03067 return PROLOG_SUCCESS;
03068 }
03069 CATCH_ALL;
03070 }
03071
03072 extern "C" Prolog_foreign_return_type
03073 ppl_PIP_Tree_Node_parametric_values(Prolog_term_ref t_pip,
03074 Prolog_term_ref t_var,
03075 Prolog_term_ref t_le) {
03076 static const char* where = "ppl_PIP_Solution_Node_get_parametric_values/3";
03077 try {
03078 const PIP_Solution_Node* pip
03079 = term_to_handle<PIP_Solution_Node>(t_pip, where);
03080 PPL_CHECK(pip);
03081 Variable var = term_to_Variable(t_var, where);
03082 if (Prolog_unify(t_le, get_linear_expression(pip->parametric_values(var))))
03083 return PROLOG_SUCCESS;
03084 }
03085 CATCH_ALL;
03086 }
03087
03088 extern "C" Prolog_foreign_return_type
03089 ppl_PIP_Tree_Node_true_child(Prolog_term_ref t_pip,
03090 Prolog_term_ref t_ptree) {
03091 static const char* where = "ppl_PIP_Decision_Node_get_true_child/2";
03092 try {
03093 const PIP_Decision_Node* pip
03094 = term_to_handle<PIP_Decision_Node>(t_pip, where);
03095 PPL_CHECK(pip);
03096 bool b = true;
03097 PIP_Tree_Node* ppl_ptree = const_cast<PIP_Tree_Node*>(pip->child_node(b));
03098 Prolog_term_ref t_ppl_ptree = Prolog_new_term_ref();
03099 Prolog_put_address(t_ppl_ptree, ppl_ptree);
03100 if (Prolog_unify(t_ptree, t_ppl_ptree)) {
03101 PPL_WEAK_REGISTER(ppl_ptree);
03102 return PROLOG_SUCCESS;
03103 }
03104 }
03105 CATCH_ALL;
03106 }
03107
03108 extern "C" Prolog_foreign_return_type
03109 ppl_PIP_Tree_Node_false_child(Prolog_term_ref t_pip,
03110 Prolog_term_ref t_ptree) {
03111 static const char* where = "ppl_PIP_Decision_Node_get_false_child/2";
03112 try {
03113 const PIP_Decision_Node* pip
03114 = term_to_handle<PIP_Decision_Node>(t_pip, where);
03115 PPL_CHECK(pip);
03116 bool b = false;
03117 PIP_Tree_Node* ppl_ptree = const_cast<PIP_Tree_Node*>(pip->child_node(b));
03118 Prolog_term_ref t_ppl_ptree = Prolog_new_term_ref();
03119 Prolog_put_address(t_ppl_ptree, ppl_ptree);
03120 if (Prolog_unify(t_ptree, t_ppl_ptree)) {
03121 PPL_WEAK_REGISTER(ppl_ptree);
03122 return PROLOG_SUCCESS;
03123 }
03124 }
03125 CATCH_ALL;
03126 }
03127
03128 extern "C" Prolog_foreign_return_type
03129 ppl_PIP_Tree_Node_OK(Prolog_term_ref t_pip) {
03130 static const char* where = "ppl_PIP_Tree_Node_OK/1";
03131 try {
03132 const PIP_Tree_Node* pip = term_to_handle<PIP_Tree_Node>(t_pip, where);
03133 PPL_CHECK(pip);
03134 if (pip->OK())
03135 return PROLOG_SUCCESS;
03136 }
03137 CATCH_ALL;
03138 }