33 namespace Interfaces {
37 #if PROLOG_TRACK_ALLOCATION || NOISY_PROLOG_TRACK_ALLOCATION
39 Allocation_Tracker::Allocation_Tracker() {
42 Allocation_Tracker::~Allocation_Tracker() {
43 Set::size_type n = s.size();
46 <<
"Interfaces::Prolog::Allocation_Tracker: "
47 << n <<
" object(s) leaked!"
51 Allocation_Tracker allocation_tracker;
53 #endif // PROLOG_TRACK_ALLOCATION || NOISY_PROLOG_TRACK_ALLOCATION
58 Prolog_atom out_of_memory_exception_atom;
61 Prolog_atom a_dollar_VAR;
66 Prolog_atom a_asterisk;
72 Prolog_atom a_less_than;
73 Prolog_atom a_equal_less_than;
75 Prolog_atom a_greater_than_equal;
76 Prolog_atom a_greater_than;
79 Prolog_atom a_is_congruent_to;
86 Prolog_atom a_closure_point;
89 Prolog_atom a_grid_line;
90 Prolog_atom a_parameter;
91 Prolog_atom a_grid_point;
94 Prolog_atom a_divided_by;
97 Prolog_atom a_is_disjoint;
98 Prolog_atom a_strictly_intersects;
99 Prolog_atom a_is_included;
100 Prolog_atom a_saturates;
103 Prolog_atom a_subsumes;
112 Prolog_atom a_universe;
121 Prolog_atom a_bits_8;
122 Prolog_atom a_bits_16;
123 Prolog_atom a_bits_32;
124 Prolog_atom a_bits_64;
125 Prolog_atom a_bits_128;
128 Prolog_atom a_unsigned;
129 Prolog_atom a_signed_2_complement;
132 Prolog_atom a_overflow_wraps;
133 Prolog_atom a_overflow_undefined;
134 Prolog_atom a_overflow_impossible;
137 Prolog_atom a_unfeasible;
138 Prolog_atom a_unbounded;
139 Prolog_atom a_optimized;
152 Prolog_atom a_polynomial;
153 Prolog_atom a_simplex;
157 Prolog_atom a_pricing;
158 Prolog_atom a_pricing_steepest_edge_float;
159 Prolog_atom a_pricing_steepest_edge_exact;
160 Prolog_atom a_pricing_textbook;
162 Prolog_atom a_cutting_strategy;
163 Prolog_atom a_cutting_strategy_first;
164 Prolog_atom a_cutting_strategy_deepest;
165 Prolog_atom a_cutting_strategy_all;
167 Prolog_atom a_pivot_row_strategy;
168 Prolog_atom a_pivot_row_strategy_first;
169 Prolog_atom a_pivot_row_strategy_max_column;
172 Prolog_atom a_time_out;
175 Prolog_atom a_out_of_memory;
182 Prolog_atom a_ppl_overflow_error;
183 Prolog_atom a_ppl_domain_error;
184 Prolog_atom a_ppl_length_error;
185 Prolog_atom a_ppl_invalid_argument;
186 Prolog_atom a_ppl_logic_error;
187 Prolog_atom a_ppl_representation_error;
188 Prolog_atom a_expected;
193 { &a_dollar_VAR,
"$VAR" },
197 { &a_asterisk,
"*" },
202 { &a_greater_than_equal,
">=" },
203 { &a_equal_less_than,
"=<" },
204 { &a_greater_than,
">" },
205 { &a_less_than,
"<" },
207 { &a_is_congruent_to,
"=:=" },
210 { &a_divided_by,
"/" },
214 { &a_point,
"point" },
215 { &a_closure_point,
"closure_point" },
217 { &a_grid_line,
"grid_line" },
218 { &a_parameter,
"parameter" },
219 { &a_grid_point,
"grid_point" },
221 { &a_is_disjoint,
"is_disjoint" },
222 { &a_strictly_intersects,
"strictly_intersects" },
223 { &a_is_included,
"is_included" },
224 { &a_saturates,
"saturates" },
226 { &a_subsumes,
"subsumes" },
230 { &a_empty,
"empty" },
231 { &a_universe,
"universe" },
236 { &a_bits_8,
"bits_8" },
237 { &a_bits_16,
"bits_16" },
238 { &a_bits_32,
"bits_32" },
239 { &a_bits_64,
"bits_64" },
240 { &a_bits_128,
"bits_128" },
242 { &a_unsigned,
"unsigned" },
243 { &a_signed_2_complement,
"signed_2_complement" },
245 { &a_overflow_wraps,
"overflow_wraps" },
246 { &a_overflow_undefined,
"overflow_undefined" },
247 { &a_overflow_impossible,
"overflow_impossible" },
249 { &a_unfeasible,
"unfeasible" },
250 { &a_unbounded,
"unbounded" },
251 { &a_optimized,
"optimized" },
259 { &a_polynomial,
"polynomial" },
260 { &a_simplex,
"simplex" },
263 { &a_pricing,
"pricing" },
264 { &a_pricing_steepest_edge_float,
265 "pricing_steepest_edge_float" },
266 { &a_pricing_steepest_edge_exact,
267 "pricing_steepest_edge_exact" },
268 { &a_pricing_textbook,
"pricing_textbook" },
270 { &a_cutting_strategy,
"cutting_strategy" },
271 { &a_cutting_strategy_first,
"cutting_strategy_first" },
272 { &a_cutting_strategy_deepest,
"cutting_strategy_deepest" },
273 { &a_cutting_strategy_all,
"cutting_strategy_all" },
275 { &a_pivot_row_strategy,
"pivot_row_strategy" },
276 { &a_pivot_row_strategy_first,
"pivot_row_strategy_first" },
277 { &a_pivot_row_strategy_max_column,
278 "pivot_row_strategy_max_column" },
280 { &a_time_out,
"time_out" },
281 { &a_out_of_memory,
"out_of_memory" },
284 { &a_false,
"false" },
286 { &a_ppl_invalid_argument,
"ppl_invalid_argument" },
287 { &a_ppl_overflow_error,
"ppl_overflow_error" },
288 { &a_ppl_domain_error,
"ppl_domain_error" },
289 { &a_ppl_length_error,
"ppl_length_error" },
290 { &a_ppl_invalid_argument,
"ppl_invalid_argument" },
291 { &a_ppl_logic_error,
"ppl_logic_error" },
292 { &a_ppl_representation_error,
"ppl_representation_error" },
293 { &a_expected,
"expected" },
294 { &a_found,
"found" },
295 { &a_where,
"where" },
300 Prolog_atom_term_from_string(
const char* s) {
301 Prolog_term_ref t = Prolog_new_term_ref();
302 Prolog_put_atom(t, Prolog_atom_from_string(s));
308 Prolog_term_ref found = Prolog_new_term_ref();
309 Prolog_construct_compound(found, a_found, e.
term());
311 Prolog_term_ref max = Prolog_new_term_ref();
312 Prolog_put_ulong(max, e.
max());
313 Prolog_construct_compound(max,
314 Prolog_atom_from_string(
"unsigned_integer"
317 Prolog_term_ref expected = Prolog_new_term_ref();
318 Prolog_construct_compound(expected, a_expected, max);
320 Prolog_term_ref where = Prolog_new_term_ref();
321 Prolog_construct_compound(where, a_where,
322 Prolog_atom_term_from_string(e.
where()));
324 Prolog_term_ref exception_term = Prolog_new_term_ref();
325 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
326 found, expected, where);
327 Prolog_raise_exception(exception_term);
332 Prolog_term_ref found = Prolog_new_term_ref();
333 Prolog_construct_compound(found, a_found, e.
term());
335 Prolog_term_ref expected = Prolog_new_term_ref();
336 Prolog_construct_compound(expected, a_expected,
337 Prolog_atom_term_from_string(
"unsigned_integer"));
339 Prolog_term_ref where = Prolog_new_term_ref();
340 Prolog_construct_compound(where, a_where,
341 Prolog_atom_term_from_string(e.
where()));
343 Prolog_term_ref exception_term = Prolog_new_term_ref();
344 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
345 found, expected, where);
346 Prolog_raise_exception(exception_term);
351 Prolog_term_ref found = Prolog_new_term_ref();
352 Prolog_construct_compound(found, a_found, e.
term());
354 Prolog_term_ref expected = Prolog_new_term_ref();
355 Prolog_construct_compound(expected, a_expected,
356 Prolog_atom_term_from_string
357 (
"linear_expression_or_constraint"));
359 Prolog_term_ref where = Prolog_new_term_ref();
360 Prolog_construct_compound(where, a_where,
361 Prolog_atom_term_from_string(e.
where()));
363 Prolog_term_ref exception_term = Prolog_new_term_ref();
364 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
365 found, expected, where);
366 Prolog_raise_exception(exception_term);
371 Prolog_term_ref found = Prolog_new_term_ref();
372 Prolog_construct_compound(found, a_found,
375 Prolog_term_ref expected = Prolog_new_term_ref();
376 Prolog_construct_compound(expected, a_expected,
377 Prolog_atom_term_from_string
378 (
"$VAR(unsigned_integer)"));
380 Prolog_term_ref where = Prolog_new_term_ref();
381 Prolog_construct_compound(where, a_where,
382 Prolog_atom_term_from_string(e.
where()));
384 Prolog_term_ref exception_term = Prolog_new_term_ref();
385 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
386 found, expected, where);
387 Prolog_raise_exception(exception_term);
392 Prolog_term_ref found = Prolog_new_term_ref();
393 Prolog_construct_compound(found, a_found, e.
term());
395 Prolog_term_ref expected = Prolog_new_term_ref();
396 Prolog_construct_compound(expected, a_expected,
397 Prolog_atom_term_from_string(
"integer"));
399 Prolog_term_ref where = Prolog_new_term_ref();
400 Prolog_construct_compound(where, a_where,
401 Prolog_atom_term_from_string(e.
where()));
403 Prolog_term_ref exception_term = Prolog_new_term_ref();
404 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
405 found, expected, where);
406 Prolog_raise_exception(exception_term);
411 Prolog_term_ref found = Prolog_new_term_ref();
412 Prolog_construct_compound(found, a_found, e.
term());
414 Prolog_term_ref expected = Prolog_new_term_ref();
415 Prolog_construct_compound(expected, a_expected,
416 Prolog_atom_term_from_string(
"handle"));
418 Prolog_term_ref where = Prolog_new_term_ref();
419 Prolog_construct_compound(where, a_where,
420 Prolog_atom_term_from_string(e.
where()));
422 Prolog_term_ref exception_term = Prolog_new_term_ref();
423 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
424 found, expected, where);
425 Prolog_raise_exception(exception_term);
430 Prolog_term_ref found = Prolog_new_term_ref();
431 Prolog_construct_compound(found, a_found, e.
term());
433 Prolog_term_ref expected = Prolog_new_term_ref();
434 Prolog_put_nil(expected);
435 Prolog_construct_cons(expected,
436 Prolog_atom_term_from_string(
"max"), expected);
437 Prolog_construct_cons(expected,
438 Prolog_atom_term_from_string(
"min"), expected);
439 Prolog_construct_compound(expected, a_expected, expected);
441 Prolog_term_ref where = Prolog_new_term_ref();
442 Prolog_construct_compound(where, a_where,
443 Prolog_atom_term_from_string(e.
where()));
444 Prolog_term_ref exception_term = Prolog_new_term_ref();
445 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
446 found, expected, where);
447 Prolog_raise_exception(exception_term);
452 Prolog_term_ref found = Prolog_new_term_ref();
453 Prolog_construct_compound(found, a_found, e.
term());
455 Prolog_term_ref expected = Prolog_new_term_ref();
456 Prolog_put_nil(expected);
457 Prolog_construct_cons(expected,
458 Prolog_atom_term_from_string(
"polynomial"), expected);
459 Prolog_construct_cons(expected,
460 Prolog_atom_term_from_string(
"simplex"), expected);
461 Prolog_construct_cons(expected,
462 Prolog_atom_term_from_string(
"any"), expected);
463 Prolog_construct_compound(expected, a_expected, expected);
465 Prolog_term_ref where = Prolog_new_term_ref();
466 Prolog_construct_compound(where, a_where,
467 Prolog_atom_term_from_string(e.
where()));
468 Prolog_term_ref exception_term = Prolog_new_term_ref();
469 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
470 found, expected, where);
471 Prolog_raise_exception(exception_term);
476 Prolog_term_ref found = Prolog_new_term_ref();
477 Prolog_construct_compound(found, a_found, e.
term());
479 Prolog_term_ref expected = Prolog_new_term_ref();
480 Prolog_put_nil(expected);
481 Prolog_construct_cons(expected,
482 Prolog_atom_term_from_string(
"pricing"), expected);
484 Prolog_term_ref where = Prolog_new_term_ref();
485 Prolog_construct_compound(where, a_where,
486 Prolog_atom_term_from_string(e.
where()));
487 Prolog_term_ref exception_term = Prolog_new_term_ref();
488 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
489 found, expected, where);
490 Prolog_raise_exception(exception_term);
495 Prolog_term_ref found = Prolog_new_term_ref();
496 Prolog_construct_compound(found, a_found, e.
term());
498 Prolog_term_ref expected = Prolog_new_term_ref();
499 Prolog_put_nil(expected);
500 Prolog_construct_cons(expected,
501 Prolog_atom_term_from_string(
"pricing_steepest_edge_float"),
503 Prolog_construct_cons(expected,
504 Prolog_atom_term_from_string(
"pricing_steepest_edge_exact"),
506 Prolog_construct_cons(expected,
507 Prolog_atom_term_from_string(
"pricing_textbook"),
510 Prolog_term_ref where = Prolog_new_term_ref();
511 Prolog_construct_compound(where, a_where,
512 Prolog_atom_term_from_string(e.
where()));
513 Prolog_term_ref exception_term = Prolog_new_term_ref();
514 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
515 found, expected, where);
516 Prolog_raise_exception(exception_term);
521 Prolog_term_ref found = Prolog_new_term_ref();
522 Prolog_construct_compound(found, a_found, e.
term());
524 Prolog_term_ref expected = Prolog_new_term_ref();
525 Prolog_put_nil(expected);
526 Prolog_construct_cons(expected,
527 Prolog_atom_term_from_string(
"cutting_strategy"),
529 Prolog_construct_cons(expected,
530 Prolog_atom_term_from_string(
"pivot_row_strategy"),
533 Prolog_term_ref where = Prolog_new_term_ref();
534 Prolog_construct_compound(where, a_where,
535 Prolog_atom_term_from_string(e.
where()));
536 Prolog_term_ref exception_term = Prolog_new_term_ref();
537 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
538 found, expected, where);
539 Prolog_raise_exception(exception_term);
544 Prolog_term_ref found = Prolog_new_term_ref();
545 Prolog_construct_compound(found, a_found, e.
term());
547 Prolog_term_ref expected = Prolog_new_term_ref();
548 Prolog_put_nil(expected);
549 Prolog_construct_cons(expected,
550 Prolog_atom_term_from_string(
"cutting_strategy_first"),
552 Prolog_construct_cons(expected,
553 Prolog_atom_term_from_string(
"cutting_strategy_deepest"),
555 Prolog_construct_cons(expected,
556 Prolog_atom_term_from_string(
"cutting_strategy_all"),
558 Prolog_construct_cons(expected,
559 Prolog_atom_term_from_string(
"pivot_row_strategy_first"),
561 Prolog_construct_cons(expected,
562 Prolog_atom_term_from_string(
"pivot_row_strategy_max_column"),
564 Prolog_term_ref where = Prolog_new_term_ref();
565 Prolog_construct_compound(where, a_where,
566 Prolog_atom_term_from_string(e.
where()));
567 Prolog_term_ref exception_term = Prolog_new_term_ref();
568 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
569 found, expected, where);
570 Prolog_raise_exception(exception_term);
575 Prolog_term_ref found = Prolog_new_term_ref();
576 Prolog_construct_compound(found, a_found, e.
term());
578 Prolog_term_ref expected = Prolog_new_term_ref();
579 Prolog_put_nil(expected);
580 Prolog_construct_cons(expected,
581 Prolog_atom_term_from_string(
"universe"), expected);
582 Prolog_construct_cons(expected,
583 Prolog_atom_term_from_string(
"empty"), expected);
584 Prolog_construct_compound(expected, a_expected, expected);
586 Prolog_term_ref where = Prolog_new_term_ref();
587 Prolog_construct_compound(where, a_where,
588 Prolog_atom_term_from_string(e.
where()));
589 Prolog_term_ref exception_term = Prolog_new_term_ref();
590 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
591 found, expected, where);
592 Prolog_raise_exception(exception_term);
597 Prolog_term_ref found = Prolog_new_term_ref();
598 Prolog_construct_compound(found, a_found, e.
term());
600 Prolog_term_ref expected = Prolog_new_term_ref();
601 Prolog_put_nil(expected);
602 Prolog_construct_cons(expected,
603 Prolog_atom_term_from_string(
"true"), expected);
604 Prolog_construct_cons(expected,
605 Prolog_atom_term_from_string(
"false"), expected);
606 Prolog_construct_compound(expected, a_expected, expected);
608 Prolog_term_ref where = Prolog_new_term_ref();
609 Prolog_construct_compound(where, a_where,
610 Prolog_atom_term_from_string(e.
where()));
611 Prolog_term_ref exception_term = Prolog_new_term_ref();
612 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
613 found, expected, where);
614 Prolog_raise_exception(exception_term);
619 Prolog_term_ref found = Prolog_new_term_ref();
620 Prolog_construct_compound(found, a_found, e.
term());
622 Prolog_term_ref expected = Prolog_new_term_ref();
623 Prolog_put_nil(expected);
624 Prolog_construct_cons(expected,
625 Prolog_atom_term_from_string(
"bits_8"), expected);
626 Prolog_construct_cons(expected,
627 Prolog_atom_term_from_string(
"bits_16"), expected);
628 Prolog_construct_cons(expected,
629 Prolog_atom_term_from_string(
"bits_32"), expected);
630 Prolog_construct_cons(expected,
631 Prolog_atom_term_from_string(
"bits_64"), expected);
632 Prolog_construct_cons(expected,
633 Prolog_atom_term_from_string(
"bits_128"), expected);
634 Prolog_construct_compound(expected, a_expected, expected);
636 Prolog_term_ref where = Prolog_new_term_ref();
637 Prolog_construct_compound(where, a_where,
638 Prolog_atom_term_from_string(e.
where()));
639 Prolog_term_ref exception_term = Prolog_new_term_ref();
640 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
641 found, expected, where);
642 Prolog_raise_exception(exception_term);
647 Prolog_term_ref found = Prolog_new_term_ref();
648 Prolog_construct_compound(found, a_found, e.
term());
650 Prolog_term_ref expected = Prolog_new_term_ref();
651 Prolog_put_nil(expected);
652 Prolog_construct_cons(expected,
653 Prolog_atom_term_from_string(
"unsigned"), expected);
654 Prolog_construct_cons(expected,
655 Prolog_atom_term_from_string(
"signed_2_complement"),
657 Prolog_construct_compound(expected, a_expected, expected);
659 Prolog_term_ref where = Prolog_new_term_ref();
660 Prolog_construct_compound(where, a_where,
661 Prolog_atom_term_from_string(e.
where()));
662 Prolog_term_ref exception_term = Prolog_new_term_ref();
663 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
664 found, expected, where);
665 Prolog_raise_exception(exception_term);
670 Prolog_term_ref found = Prolog_new_term_ref();
671 Prolog_construct_compound(found, a_found, e.
term());
673 Prolog_term_ref expected = Prolog_new_term_ref();
674 Prolog_put_nil(expected);
675 Prolog_construct_cons(expected,
676 Prolog_atom_term_from_string(
"overflow_wraps"),
678 Prolog_construct_cons(expected,
679 Prolog_atom_term_from_string(
"overflow_undefined"),
681 Prolog_construct_cons(expected,
682 Prolog_atom_term_from_string(
"overflow_impossible"),
684 Prolog_construct_compound(expected, a_expected, expected);
686 Prolog_term_ref where = Prolog_new_term_ref();
687 Prolog_construct_compound(where, a_where,
688 Prolog_atom_term_from_string(e.
where()));
689 Prolog_term_ref exception_term = Prolog_new_term_ref();
690 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
691 found, expected, where);
692 Prolog_raise_exception(exception_term);
697 Prolog_term_ref found = Prolog_new_term_ref();
698 Prolog_construct_compound(found, a_found, e.
term());
700 Prolog_term_ref expected = Prolog_new_term_ref();
701 Prolog_put_nil(expected);
702 Prolog_construct_cons(expected,
703 Prolog_atom_term_from_string(
"="), expected);
704 Prolog_construct_cons(expected,
705 Prolog_atom_term_from_string(
">="), expected);
706 Prolog_construct_cons(expected,
707 Prolog_atom_term_from_string(
"=<"), expected);
708 Prolog_construct_cons(expected,
709 Prolog_atom_term_from_string(
">"), expected);
710 Prolog_construct_cons(expected,
711 Prolog_atom_term_from_string(
"<"), expected);
712 Prolog_construct_compound(expected, a_expected, expected);
714 Prolog_term_ref where = Prolog_new_term_ref();
715 Prolog_construct_compound(where, a_where,
716 Prolog_atom_term_from_string(e.
where()));
717 Prolog_term_ref exception_term = Prolog_new_term_ref();
718 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
719 found, expected, where);
720 Prolog_raise_exception(exception_term);
725 Prolog_term_ref found = Prolog_new_term_ref();
726 Prolog_construct_compound(found, a_found, e.
term());
728 Prolog_term_ref expected = Prolog_new_term_ref();
729 Prolog_put_nil(expected);
730 Prolog_construct_cons(expected,
731 Prolog_atom_term_from_string
732 (
"Prolog_list"), expected);
733 Prolog_construct_compound(expected, a_expected, expected);
735 Prolog_term_ref where = Prolog_new_term_ref();
736 Prolog_construct_compound(where, a_where,
737 Prolog_atom_term_from_string(e.
where()));
738 Prolog_term_ref exception_term = Prolog_new_term_ref();
739 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
740 found, expected, where);
741 Prolog_raise_exception(exception_term);
746 Prolog_term_ref where = Prolog_new_term_ref();
747 Prolog_construct_compound(where, a_where,
748 Prolog_atom_term_from_string(
"Coefficient_to_integer_term"));
750 Prolog_term_ref exception_term = Prolog_new_term_ref();
751 std::ostringstream s;
753 std::string str = s.str();
754 Prolog_construct_compound(exception_term, a_ppl_representation_error,
755 Prolog_atom_term_from_string(str.c_str()),
757 Prolog_raise_exception(exception_term);
762 Prolog_term_ref et = Prolog_new_term_ref();
763 Prolog_put_atom_chars(et, e.
where());
764 Prolog_raise_exception(et);
768 handle_exception(
const std::overflow_error& e) {
769 Prolog_term_ref et = Prolog_new_term_ref();
770 Prolog_construct_compound(et, a_ppl_overflow_error,
771 Prolog_atom_term_from_string(e.what()));
772 Prolog_raise_exception(et);
776 handle_exception(
const std::domain_error& e) {
777 Prolog_term_ref et = Prolog_new_term_ref();
778 Prolog_construct_compound(et, a_ppl_domain_error,
779 Prolog_atom_term_from_string(e.what()));
780 Prolog_raise_exception(et);
784 handle_exception(
const std::length_error& e) {
785 Prolog_term_ref et = Prolog_new_term_ref();
786 Prolog_construct_compound(et, a_ppl_length_error,
787 Prolog_atom_term_from_string(e.what()));
788 Prolog_raise_exception(et);
792 handle_exception(
const std::invalid_argument& e) {
793 Prolog_term_ref et = Prolog_new_term_ref();
794 Prolog_construct_compound(et, a_ppl_invalid_argument,
795 Prolog_atom_term_from_string(e.what()));
796 Prolog_raise_exception(et);
800 handle_exception(
const std::logic_error& e) {
801 Prolog_term_ref et = Prolog_new_term_ref();
802 Prolog_construct_compound(et, a_ppl_logic_error,
803 Prolog_atom_term_from_string(e.what()));
804 Prolog_raise_exception(et);
808 handle_exception(
const std::bad_alloc&) {
809 Prolog_term_ref et = Prolog_new_term_ref();
810 Prolog_put_atom(et, out_of_memory_exception_atom);
811 Prolog_raise_exception(et);
815 handle_exception(
const std::exception& e) {
816 Prolog_term_ref et = Prolog_new_term_ref();
817 Prolog_put_atom_chars(et, e.what());
818 Prolog_raise_exception(et);
823 Prolog_term_ref et = Prolog_new_term_ref();
824 Prolog_put_atom_chars(et,
"PPL bug: unknown exception raised");
825 Prolog_raise_exception(et);
834 Weightwatch* p_deterministic_timeout_object = 0;
838 if (p_timeout_object) {
839 delete p_timeout_object;
840 p_timeout_object = 0;
846 reset_deterministic_timeout() {
847 if (p_deterministic_timeout_object) {
848 delete p_deterministic_timeout_object;
849 p_deterministic_timeout_object = 0;
854 Prolog_atom timeout_exception_atom;
858 assert(p_timeout_object);
860 Prolog_term_ref et = Prolog_new_term_ref();
861 Prolog_put_atom(et, timeout_exception_atom);
862 Prolog_raise_exception(et);
867 assert(p_deterministic_timeout_object);
868 reset_deterministic_timeout();
869 Prolog_term_ref et = Prolog_new_term_ref();
870 Prolog_put_atom(et, timeout_exception_atom);
871 Prolog_raise_exception(et);
876 Prolog_term_ref v = Prolog_new_term_ref();
877 Prolog_put_ulong(v, varid);
878 Prolog_term_ref t = Prolog_new_term_ref();
879 Prolog_construct_compound(t, a_dollar_VAR, v);
884 term_to_boolean(Prolog_term_ref t,
const char* where) {
885 if (Prolog_is_atom(t)) {
887 if (Prolog_get_atom_name(t, &name)
888 && (name == a_true || name == a_false))
895 term_to_universe_or_empty(Prolog_term_ref t,
const char* where) {
896 if (Prolog_is_atom(t)) {
898 if (Prolog_get_atom_name(t, &name)
899 && (name == a_universe || name == a_empty))
906 integer_term_to_Coefficient(Prolog_term_ref t) {
908 assert(Prolog_is_integer(t));
909 if (!Prolog_get_Coefficient(t, n))
915 Coefficient_to_integer_term(
const Coefficient& n) {
916 Prolog_term_ref t = Prolog_new_term_ref();
917 if (!Prolog_put_Coefficient(t, n))
923 unify_long(Prolog_term_ref t,
long l) {
924 Prolog_term_ref t_l = Prolog_new_term_ref();
925 return Prolog_put_long(t_l, l) && Prolog_unify(t, t_l);
929 unify_ulong(Prolog_term_ref t,
unsigned long l) {
930 Prolog_term_ref t_l = Prolog_new_term_ref();
931 return Prolog_put_ulong(t_l, l) && Prolog_unify(t, t_l);
935 build_linear_expression(Prolog_term_ref t,
const char* where) {
936 if (Prolog_is_integer(t))
938 else if (Prolog_is_compound(t)) {
941 Prolog_get_compound_name_arity(t, &functor, &arity);
945 Prolog_term_ref arg = Prolog_new_term_ref();
946 Prolog_get_arg(1, t, arg);
947 if (functor == a_minus)
949 return -build_linear_expression(arg, where);
950 else if (functor == a_dollar_VAR)
952 return Variable(term_to_unsigned<dimension_type>(arg, where));
957 Prolog_term_ref arg1 = Prolog_new_term_ref();
958 Prolog_term_ref arg2 = Prolog_new_term_ref();
959 Prolog_get_arg(1, t, arg1);
960 Prolog_get_arg(2, t, arg2);
961 if (functor == a_plus)
963 if (Prolog_is_integer(arg1))
964 return integer_term_to_Coefficient(arg1)
965 + build_linear_expression(arg2, where);
966 else if (Prolog_is_integer(arg2))
967 return build_linear_expression(arg1, where)
968 + integer_term_to_Coefficient(arg2);
970 return build_linear_expression(arg1, where)
971 + build_linear_expression(arg2, where);
972 else if (functor == a_minus)
974 if (Prolog_is_integer(arg1))
975 return integer_term_to_Coefficient(arg1)
976 - build_linear_expression(arg2, where);
977 else if (Prolog_is_integer(arg2))
978 return build_linear_expression(arg1, where)
979 - integer_term_to_Coefficient(arg2);
981 return build_linear_expression(arg1, where)
982 - build_linear_expression(arg2, where);
983 else if (functor == a_asterisk) {
985 if (Prolog_is_integer(arg1))
986 return integer_term_to_Coefficient(arg1)
987 * build_linear_expression(arg2, where);
988 else if (Prolog_is_integer(arg2))
989 return build_linear_expression(arg1, where)
990 * integer_term_to_Coefficient(arg2);
1000 build_constraint(Prolog_term_ref t,
const char* where) {
1001 if (Prolog_is_compound(t)) {
1002 Prolog_atom functor;
1004 Prolog_get_compound_name_arity(t, &functor, &arity);
1006 Prolog_term_ref arg1 = Prolog_new_term_ref();
1007 Prolog_term_ref arg2 = Prolog_new_term_ref();
1008 Prolog_get_arg(1, t, arg1);
1009 Prolog_get_arg(2, t, arg2);
1010 if (functor == a_equal)
1012 if (Prolog_is_integer(arg1))
1013 return integer_term_to_Coefficient(arg1)
1014 == build_linear_expression(arg2, where);
1015 else if (Prolog_is_integer(arg2))
1016 return build_linear_expression(arg1, where)
1017 == integer_term_to_Coefficient(arg2);
1019 return build_linear_expression(arg1, where)
1020 == build_linear_expression(arg2, where);
1021 else if (functor == a_equal_less_than)
1023 if (Prolog_is_integer(arg1))
1024 return integer_term_to_Coefficient(arg1)
1025 <= build_linear_expression(arg2, where);
1026 else if (Prolog_is_integer(arg2))
1027 return build_linear_expression(arg1, where)
1028 <= integer_term_to_Coefficient(arg2);
1030 return build_linear_expression(arg1, where)
1031 <= build_linear_expression(arg2, where);
1032 else if (functor == a_greater_than_equal)
1034 if (Prolog_is_integer(arg1))
1035 return integer_term_to_Coefficient(arg1)
1036 >= build_linear_expression(arg2, where);
1037 else if (Prolog_is_integer(arg2))
1038 return build_linear_expression(arg1, where)
1039 >= integer_term_to_Coefficient(arg2);
1041 return build_linear_expression(arg1, where)
1042 >= build_linear_expression(arg2, where);
1043 else if (functor == a_less_than)
1045 if (Prolog_is_integer(arg1))
1046 return integer_term_to_Coefficient(arg1)
1047 < build_linear_expression(arg2, where);
1048 else if (Prolog_is_integer(arg2))
1049 return build_linear_expression(arg1, where)
1050 < integer_term_to_Coefficient(arg2);
1052 return build_linear_expression(arg1, where)
1053 < build_linear_expression(arg2, where);
1054 else if (functor == a_greater_than) {
1056 if (Prolog_is_integer(arg1))
1057 return integer_term_to_Coefficient(arg1)
1058 > build_linear_expression(arg2, where);
1059 else if (Prolog_is_integer(arg2))
1060 return build_linear_expression(arg1, where)
1061 > integer_term_to_Coefficient(arg2);
1063 return build_linear_expression(arg1, where)
1064 > build_linear_expression(arg2, where);
1073 build_congruence(Prolog_term_ref t,
const char* where) {
1074 if (Prolog_is_compound(t)) {
1075 Prolog_atom functor;
1077 Prolog_get_compound_name_arity(t, &functor, &arity);
1079 Prolog_term_ref arg1 = Prolog_new_term_ref();
1080 Prolog_term_ref arg2 = Prolog_new_term_ref();
1081 Prolog_get_arg(1, t, arg1);
1082 Prolog_get_arg(2, t, arg2);
1083 if (functor == a_modulo) {
1085 if (Prolog_is_integer(arg2)) {
1086 Prolog_atom functor1;
1088 Prolog_get_compound_name_arity(arg1, &functor1, &arity1);
1090 if (functor1 == a_is_congruent_to) {
1092 Prolog_term_ref arg11 = Prolog_new_term_ref();
1093 Prolog_term_ref arg12 = Prolog_new_term_ref();
1094 Prolog_get_arg(1, arg1, arg11);
1095 Prolog_get_arg(2, arg1, arg12);
1096 if (Prolog_is_integer(arg12))
1097 return (build_linear_expression(arg11, where)
1098 %= integer_term_to_Coefficient(arg12))
1099 / integer_term_to_Coefficient(arg2);
1101 return (build_linear_expression(arg11, where)
1102 %= build_linear_expression(arg12, where))
1103 / integer_term_to_Coefficient(arg2);
1109 if (functor == a_is_congruent_to)
1111 if (Prolog_is_integer(arg2))
1112 return build_linear_expression(arg1, where)
1113 %= integer_term_to_Coefficient(arg2);
1115 return build_linear_expression(arg1, where)
1116 %= build_linear_expression(arg2, where);
1118 if (functor == a_equal) {
1120 if (Prolog_is_integer(arg1))
1121 return (build_linear_expression(arg2, where)
1122 %= integer_term_to_Coefficient(arg1)) / 0;
1123 else if (Prolog_is_integer(arg2))
1124 return (build_linear_expression(arg1, where)
1125 %= integer_term_to_Coefficient(arg2)) / 0;
1127 return (build_linear_expression(arg1, where)
1128 %= build_linear_expression(arg2, where)) / 0;
1137 build_generator(Prolog_term_ref t,
const char* where) {
1138 if (Prolog_is_compound(t)) {
1139 Prolog_atom functor;
1141 Prolog_get_compound_name_arity(t, &functor, &arity);
1143 Prolog_term_ref arg = Prolog_new_term_ref();
1144 Prolog_get_arg(1, t, arg);
1145 if (functor == a_line)
1147 else if (functor == a_ray)
1149 else if (functor == a_point)
1151 else if (functor == a_closure_point)
1154 else if (arity == 2) {
1155 Prolog_term_ref arg1 = Prolog_new_term_ref();
1156 Prolog_term_ref arg2 = Prolog_new_term_ref();
1157 Prolog_get_arg(1, t, arg1);
1158 Prolog_get_arg(2, t, arg2);
1159 if (Prolog_is_integer(arg2)) {
1160 if (functor == a_point)
1162 integer_term_to_Coefficient(arg2));
1163 else if (functor == a_closure_point)
1165 integer_term_to_Coefficient(arg2));
1174 build_grid_generator(Prolog_term_ref t,
const char* where) {
1175 if (Prolog_is_compound(t)) {
1176 Prolog_atom functor;
1178 Prolog_get_compound_name_arity(t, &functor, &arity);
1180 Prolog_term_ref arg = Prolog_new_term_ref();
1181 Prolog_get_arg(1, t, arg);
1182 if (functor == a_grid_line)
1184 else if (functor == a_parameter)
1186 else if (functor == a_grid_point)
1189 else if (arity == 2) {
1190 Prolog_term_ref arg1 = Prolog_new_term_ref();
1191 Prolog_term_ref arg2 = Prolog_new_term_ref();
1192 Prolog_get_arg(1, t, arg1);
1193 Prolog_get_arg(2, t, arg2);
1194 if (Prolog_is_integer(arg2)) {
1195 if (functor == a_grid_point)
1198 integer_term_to_Coefficient(arg2));
1199 else if (functor == a_parameter)
1202 integer_term_to_Coefficient(arg2));
1210 template <
typename R>
1212 get_homogeneous_expression(
const R& r) {
1213 Prolog_term_ref so_far = Prolog_new_term_ref();
1217 while (varid < space_dimension
1218 && (coefficient = r.coefficient(
Variable(varid))) == 0)
1220 if (varid >= space_dimension) {
1221 Prolog_put_long(so_far, 0);
1224 Prolog_construct_compound(so_far, a_asterisk,
1225 Coefficient_to_integer_term(coefficient),
1226 variable_term(varid));
1229 while (varid < space_dimension
1230 && (coefficient = r.coefficient(
Variable(varid))) == 0)
1232 if (varid >= space_dimension)
1235 Prolog_term_ref addendum = Prolog_new_term_ref();
1236 Prolog_construct_compound(addendum, a_asterisk,
1237 Coefficient_to_integer_term(coefficient),
1238 variable_term(varid));
1239 Prolog_term_ref new_so_far = Prolog_new_term_ref();
1240 Prolog_construct_compound(new_so_far, a_plus,
1242 so_far = new_so_far;
1251 Prolog_term_ref t_homo = get_homogeneous_expression(le);
1255 Prolog_term_ref t_in
1257 if (unify_long(t_homo, 0))
1260 Prolog_term_ref t_le = Prolog_new_term_ref();
1261 Prolog_construct_compound(t_le, a_plus, t_homo, t_in);
1269 Prolog_atom relation = 0;
1275 relation = a_greater_than_equal;
1278 relation = a_greater_than;
1283 Prolog_term_ref t = Prolog_new_term_ref();
1284 Prolog_construct_compound
1287 get_homogeneous_expression(c),
1294 Prolog_atom relation1 = a_is_congruent_to;
1295 Prolog_atom relation2 = a_modulo;
1296 Prolog_term_ref t_tmp = Prolog_new_term_ref();
1297 Prolog_term_ref t = Prolog_new_term_ref();
1298 Prolog_construct_compound
1301 get_homogeneous_expression(cg),
1303 Prolog_construct_compound
1307 Coefficient_to_integer_term(cg.
modulus()));
1313 Prolog_term_ref t = Prolog_new_term_ref();
1314 Prolog_atom constructor = 0;
1317 constructor = a_line;
1320 constructor = a_ray;
1324 constructor = a_point;
1329 Prolog_construct_compound(t, constructor,
1330 get_homogeneous_expression(g),
1331 Coefficient_to_integer_term(divisor));
1337 constructor = a_closure_point;
1342 Prolog_construct_compound(t, constructor,
1343 get_homogeneous_expression(g),
1344 Coefficient_to_integer_term(divisor));
1351 Prolog_construct_compound(t, constructor, get_homogeneous_expression(g));
1357 Prolog_term_ref t = Prolog_new_term_ref();
1358 Prolog_atom constructor = 0;
1361 constructor = a_grid_line;
1365 constructor = a_parameter;
1370 Prolog_construct_compound(t, constructor,
1371 get_homogeneous_expression(g),
1372 Coefficient_to_integer_term(divisor));
1378 constructor = a_grid_point;
1383 Prolog_construct_compound(t, constructor,
1384 get_homogeneous_expression(g),
1385 Coefficient_to_integer_term(divisor));
1392 Prolog_construct_compound(t, constructor, get_homogeneous_expression(g));
1397 artificial_parameter_term(
const PIP_Tree_Node::Artificial_Parameter& art) {
1398 Prolog_term_ref t = Prolog_new_term_ref();
1399 Prolog_construct_compound(t, a_divided_by,
1400 get_linear_expression(art),
1401 Coefficient_to_integer_term(art.denominator()));
1406 term_to_Variable(Prolog_term_ref t,
const char* where) {
1407 if (Prolog_is_compound(t)) {
1408 Prolog_atom functor;
1410 Prolog_get_compound_name_arity(t, &functor, &arity);
1411 if (functor == a_dollar_VAR && arity == 1) {
1412 Prolog_term_ref arg = Prolog_new_term_ref();
1413 Prolog_get_arg(1, t, arg);
1415 Variable(term_to_unsigned<dimension_type>(arg,
"term_to_Variable"));
1422 term_to_Coefficient(Prolog_term_ref t,
const char* where) {
1423 if (Prolog_is_integer(t))
1424 return integer_term_to_Coefficient(t);
1430 term_to_bounded_integer_type_width(Prolog_term_ref t,
const char* where) {
1431 if (Prolog_is_atom(t)) {
1433 if (Prolog_get_atom_name(t, &name)
1434 && (name == a_bits_8 || name == a_bits_16
1435 || name == a_bits_32 || name == a_bits_64
1436 || name == a_bits_128))
1443 term_to_bounded_integer_type_representation(Prolog_term_ref t,
1444 const char* where) {
1445 if (Prolog_is_atom(t)) {
1447 if (Prolog_get_atom_name(t, &name)
1448 && (name == a_unsigned || name == a_signed_2_complement))
1455 term_to_bounded_integer_type_overflow(Prolog_term_ref t,
1456 const char* where) {
1457 if (Prolog_is_atom(t)) {
1459 if (Prolog_get_atom_name(t, &name)
1460 && (name == a_overflow_wraps
1461 || name == a_overflow_undefined
1462 || name == a_overflow_impossible))
1469 term_to_optimization_mode(Prolog_term_ref t,
const char* where) {
1470 if (Prolog_is_atom(t)) {
1472 if (Prolog_get_atom_name(t, &name)
1473 && (name == a_max || name == a_min))
1480 term_to_control_parameter_name(Prolog_term_ref t,
const char* where) {
1481 if (Prolog_is_atom(t)) {
1483 if (Prolog_get_atom_name(t, &name)
1484 && (name == a_pricing || name == a_cutting_strategy))
1491 term_to_pip_problem_control_parameter_name(Prolog_term_ref t,
const char* where) {
1492 if (Prolog_is_atom(t)) {
1494 if (Prolog_get_atom_name(t, &name)
1495 && (name == a_cutting_strategy || name == a_pivot_row_strategy))
1502 term_to_control_parameter_value(Prolog_term_ref t,
const char* where) {
1503 if (Prolog_is_atom(t)) {
1505 if (Prolog_get_atom_name(t, &name)
1506 && (name == a_pricing_steepest_edge_float
1507 || name == a_pricing_steepest_edge_exact
1508 || name == a_pricing_textbook
1509 || name == a_cutting_strategy_first
1510 || name == a_cutting_strategy_deepest))
1517 term_to_pip_problem_control_parameter_value(Prolog_term_ref t,
1518 const char* where) {
1519 if (Prolog_is_atom(t)) {
1521 if (Prolog_get_atom_name(t, &name)
1522 && (name == a_cutting_strategy_first
1523 || name == a_cutting_strategy_deepest
1524 || name == a_cutting_strategy_all
1525 || name == a_pivot_row_strategy_first
1526 || name == a_pivot_row_strategy_max_column))
1532 bool Prolog_interface_initialized =
false;
1535 check_nil_terminating(Prolog_term_ref t,
const char* where) {
1536 if (Prolog_get_nil(t))
1544 Prolog_has_unbounded_integers
1546 : std::min(d, static_cast<dimension_type>(Prolog_max_integer));
1550 term_to_boundary(Prolog_term_ref t_b, Boundary_Kind kind,
1551 bool& finite,
bool& closed,
1553 if (!Prolog_is_compound(t_b))
1556 Prolog_atom functor;
1559 Prolog_get_compound_name_arity(t_b, &functor, &arity);
1561 if (arity != 1 || (functor != a_c && functor != a_o))
1564 Prolog_atom open_closed_atom = functor;
1566 Prolog_term_ref t_limit = Prolog_new_term_ref();
1567 Prolog_get_arg(1, t_b, t_limit);
1568 if (Prolog_is_integer(t_limit)) {
1571 closed = (open_closed_atom == a_c);
1572 n = integer_term_to_Coefficient(t_limit);
1575 else if (Prolog_is_atom(t_limit)) {
1577 Prolog_get_atom_name(t_limit, &a);
1578 Prolog_atom allowed_infinity = (kind == LOWER_BOUNDARY ? a_minf : a_pinf);
1580 if (a != allowed_infinity || open_closed_atom != a_o)
1585 else if (Prolog_is_compound(t_limit)) {
1586 Prolog_get_compound_name_arity(t_limit, &functor, &arity);
1587 if (arity != 2 || functor != a_slash)
1590 Prolog_term_ref t_n = Prolog_new_term_ref();
1591 Prolog_term_ref t_d = Prolog_new_term_ref();
1592 Prolog_get_arg(1, t_limit, t_n);
1593 Prolog_get_arg(2, t_limit, t_d);
1595 if (!Prolog_is_integer(t_n) || !Prolog_is_integer(t_d))
1599 closed = (open_closed_atom == a_c);
1600 n = integer_term_to_Coefficient(t_n);
1601 d = integer_term_to_Coefficient(t_d);
1611 term_to_relation(Prolog_term_ref t,
const char* where) {
1612 if (Prolog_is_atom(t)) {
1614 if (Prolog_get_atom_name(t, &name)
1616 || name == a_greater_than_equal
1617 || name == a_equal_less_than
1618 || name == a_greater_than
1619 || name == a_less_than))
1626 term_to_relation_symbol(Prolog_term_ref t_r,
const char* where) {
1627 Prolog_atom ra = term_to_relation(t_r, where);
1629 if (ra == a_less_than)
1631 else if (ra == a_equal_less_than)
1633 else if (ra == a_equal)
1635 else if (ra == a_greater_than_equal)
1638 assert(ra == a_greater_than);
1645 rational_term(
const Rational_Box::interval_type::boundary_type& q) {
1646 Prolog_term_ref t = Prolog_new_term_ref();
1649 numerator = q.get_num();
1650 denominator = q.get_den();
1651 if (denominator == 1)
1652 Prolog_put_Coefficient(t, numerator);
1654 Prolog_construct_compound(t, a_slash,
1655 Coefficient_to_integer_term(numerator),
1656 Coefficient_to_integer_term(denominator));
1662 Prolog_term_ref t = Prolog_new_term_ref();
1664 Prolog_put_atom(t, a_empty);
1667 const Prolog_atom& l_oc = i.lower_is_open() ? a_o : a_c;
1668 Prolog_term_ref l_b = Prolog_new_term_ref();
1669 if (i.lower_is_boundary_infinity())
1670 Prolog_put_atom(l_b, a_minf);
1672 Prolog_put_term(l_b, rational_term(i.lower()));
1673 Prolog_term_ref l_t = Prolog_new_term_ref();
1674 Prolog_construct_compound(l_t, l_oc, l_b);
1677 const Prolog_atom& u_oc = i.upper_is_open() ? a_o : a_c;
1678 Prolog_term_ref u_b = Prolog_new_term_ref();
1679 if (i.upper_is_boundary_infinity())
1680 Prolog_put_atom(u_b, a_pinf);
1682 Prolog_put_term(u_b, rational_term(i.upper()));
1683 Prolog_term_ref u_t = Prolog_new_term_ref();
1684 Prolog_construct_compound(u_t, u_oc, u_b);
1686 Prolog_construct_compound(t, a_i, l_t, u_t);
1692 term_to_complexity_class(Prolog_term_ref t,
const char* where) {
1693 if (Prolog_is_atom(t)) {
1695 if (Prolog_get_atom_name(t, &name)
1696 && (name == a_polynomial || name == a_simplex || name == a_any))
1710 extern "C" Prolog_foreign_return_type
1714 return PROLOG_SUCCESS;
1719 extern "C" Prolog_foreign_return_type
1723 return PROLOG_SUCCESS;
1728 extern "C" Prolog_foreign_return_type
1732 return PROLOG_SUCCESS;
1737 extern "C" Prolog_foreign_return_type
1741 return PROLOG_SUCCESS;
1746 extern "C" Prolog_foreign_return_type
1749 Prolog_term_ref tmp = Prolog_new_term_ref();
1750 Prolog_put_atom_chars(tmp,
version());
1751 if (Prolog_unify(t_v, tmp))
1752 return PROLOG_SUCCESS;
1757 extern "C" Prolog_foreign_return_type
1760 Prolog_term_ref tmp = Prolog_new_term_ref();
1761 Prolog_put_atom_chars(tmp,
banner());
1762 if (Prolog_unify(t_b, tmp))
1763 return PROLOG_SUCCESS;
1768 extern "C" Prolog_foreign_return_type
1772 return PROLOG_SUCCESS;
1777 extern "C" Prolog_foreign_return_type
1780 if (Prolog_interface_initialized)
1781 return PROLOG_SUCCESS;
1784 for (
size_t i = 0; prolog_interface_atoms[i].
p_atom != 0; ++i) {
1785 Prolog_atom a = Prolog_atom_from_string(prolog_interface_atoms[i].name);
1786 *prolog_interface_atoms[i].
p_atom = a;
1788 timeout_exception_atom = a_time_out;
1789 out_of_memory_exception_atom = a_out_of_memory;
1790 ppl_Prolog_sysdep_init();
1791 Prolog_interface_initialized =
true;
1792 return PROLOG_SUCCESS;
1797 extern "C" Prolog_foreign_return_type
1800 if (!Prolog_interface_initialized)
1801 return PROLOG_SUCCESS;
1803 Prolog_interface_initialized =
false;
1808 ppl_Prolog_sysdep_deinit();
1809 return PROLOG_SUCCESS;
1814 extern "C" Prolog_foreign_return_type
1818 return PROLOG_SUCCESS;
1823 extern "C" Prolog_foreign_return_type
1827 return PROLOG_SUCCESS;
1832 extern "C" Prolog_foreign_return_type
1836 return PROLOG_SUCCESS;
1841 extern "C" Prolog_foreign_return_type
1845 = term_to_unsigned<unsigned>(t_p,
"ppl_set_irrational_precision/1");
1847 return PROLOG_SUCCESS;
1852 extern "C" Prolog_foreign_return_type
1855 if (Prolog_is_atom(t_tea)) {
1857 if (Prolog_get_atom_name(t_tea, &tea)) {
1858 timeout_exception_atom = tea;
1859 return PROLOG_SUCCESS;
1862 Prolog_term_ref found = Prolog_new_term_ref();
1863 Prolog_construct_compound(found, a_found, t_tea);
1865 Prolog_term_ref expected = Prolog_new_term_ref();
1866 Prolog_construct_compound(expected, a_expected,
1867 Prolog_atom_term_from_string(
"atom"));
1869 Prolog_term_ref where = Prolog_new_term_ref();
1870 Prolog_construct_compound(where, a_where,
1871 Prolog_atom_term_from_string
1872 (
"ppl_set_timeout_exception_atom"));
1874 Prolog_term_ref exception_term = Prolog_new_term_ref();
1875 Prolog_construct_compound(exception_term, a_ppl_invalid_argument,
1876 found, expected, where);
1877 Prolog_raise_exception(exception_term);
1878 return PROLOG_FAILURE;
1883 extern "C" Prolog_foreign_return_type
1886 Prolog_term_ref t_tea = Prolog_new_term_ref();
1887 Prolog_put_atom(t_tea, timeout_exception_atom);
1888 return Prolog_unify(t_tea, t) ? PROLOG_SUCCESS : PROLOG_FAILURE;
1893 extern "C" Prolog_foreign_return_type
1899 unsigned csecs = term_to_unsigned<unsigned>(t_csecs,
"ppl_set_timeout/1");
1904 return PROLOG_SUCCESS;
1909 extern "C" Prolog_foreign_return_type
1913 return PROLOG_SUCCESS;
1918 extern "C" Prolog_foreign_return_type
1920 Prolog_term_ref t_scale) {
1923 reset_deterministic_timeout();
1925 unsigned long unscaled_weight
1926 = term_to_unsigned<unsigned long>(t_unscaled_weight,
1927 "ppl_set_deterministic_timeout/2");
1929 = term_to_unsigned<unsigned>(t_scale,
"ppl_set_deterministic_timeout/2");
1931 p_deterministic_timeout_object
1932 =
new Weightwatch(Traits::compute_delta(unscaled_weight, scale),
1934 return PROLOG_SUCCESS;
1939 extern "C" Prolog_foreign_return_type
1942 reset_deterministic_timeout();
1943 return PROLOG_SUCCESS;
1948 extern "C" Prolog_foreign_return_type
1951 if (unify_ulong(t_bits, PPL_COEFFICIENT_BITS))
1952 return PROLOG_SUCCESS;
1957 extern "C" Prolog_foreign_return_type
1960 if (std::numeric_limits<Coefficient>::is_bounded)
1961 return PROLOG_SUCCESS;
1966 extern "C" Prolog_foreign_return_type
1969 if (std::numeric_limits<Coefficient>::is_bounded) {
1971 min = std::numeric_limits<Coefficient>::min();
1972 if (Prolog_has_unbounded_integers
1973 || (min >= Prolog_min_integer && min <= Prolog_min_integer))
1974 return Prolog_unify_Coefficient(t_min, min)
1975 ? PROLOG_SUCCESS : PROLOG_FAILURE;
1981 extern "C" Prolog_foreign_return_type
1984 if (std::numeric_limits<Coefficient>::is_bounded) {
1986 max = std::numeric_limits<Coefficient>::max();
1987 if (Prolog_has_unbounded_integers
1988 || (max >= Prolog_min_integer && max <= Prolog_min_integer))
1989 return Prolog_unify_Coefficient(t_max, max)
1990 ? PROLOG_SUCCESS : PROLOG_FAILURE;
1996 extern "C" Prolog_foreign_return_type
1998 (Prolog_term_ref t_nd, Prolog_term_ref t_mip) {
1999 static const char* where =
"ppl_MIP_Problem_from_space_dimension/2";
2001 dimension_type d = term_to_unsigned<dimension_type>(t_nd, where);
2003 Prolog_term_ref tmp = Prolog_new_term_ref();
2004 Prolog_put_address(tmp, mip);
2005 if (Prolog_unify(t_mip, tmp)) {
2007 return PROLOG_SUCCESS;
2015 extern "C" Prolog_foreign_return_type
2017 Prolog_term_ref t_clist,
2018 Prolog_term_ref t_le_expr,
2019 Prolog_term_ref t_opt,
2020 Prolog_term_ref t_mip) {
2021 static const char* where =
"ppl_new_MIP_Problem/5";
2024 Prolog_term_ref c = Prolog_new_term_ref();
2025 while (Prolog_is_cons(t_clist)) {
2026 Prolog_get_cons(t_clist, c, t_clist);
2027 cs.
insert(build_constraint(c, where));
2030 check_nil_terminating(t_clist, where);
2033 Prolog_atom opt = term_to_optimization_mode(t_opt, where);
2037 =
new MIP_Problem(term_to_unsigned<dimension_type>(t_nd, where),
2039 Prolog_term_ref tmp = Prolog_new_term_ref();
2040 Prolog_put_address(tmp, mip);
2041 if (Prolog_unify(t_mip, tmp)) {
2043 return PROLOG_SUCCESS;
2051 extern "C" Prolog_foreign_return_type
2053 Prolog_term_ref t_mip) {
2054 static const char* where =
"ppl_new_MIP_Problem_from_MIP_Problem/2";
2058 (term_to_handle<MIP_Problem>(t_mip_source, where));
2061 Prolog_term_ref tmp = Prolog_new_term_ref();
2062 Prolog_put_address(tmp, mip);
2063 if (Prolog_unify(t_mip, tmp)) {
2065 return PROLOG_SUCCESS;
2073 extern "C" Prolog_foreign_return_type
2075 static const char* where =
"ppl_MIP_Problem_swap/2";
2077 MIP_Problem* lhs = term_to_handle<MIP_Problem>(t_lhs, where);
2078 MIP_Problem* rhs = term_to_handle<MIP_Problem>(t_rhs, where);
2082 return PROLOG_SUCCESS;
2087 extern "C" Prolog_foreign_return_type
2089 static const char* where =
"ppl_delete_MIP_Problem/1";
2091 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2094 return PROLOG_SUCCESS;
2099 extern "C" Prolog_foreign_return_type
2101 static const char* where =
"ppl_MIP_Problem_space_dimension/2";
2103 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2106 return PROLOG_SUCCESS;
2111 extern "C" Prolog_foreign_return_type
2113 Prolog_term_ref t_vlist) {
2114 static const char* where =
"ppl_MIP_Problem_integer_space_dimensions/2";
2116 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2119 Prolog_term_ref tail = Prolog_new_term_ref();
2120 Prolog_put_nil(tail);
2123 for (Variables_Set::const_iterator i = i_vars.begin(),
2124 i_end = i_vars.end(); i != i_end; ++i)
2125 Prolog_construct_cons(tail, variable_term(*i), tail);
2127 if (Prolog_unify(t_vlist, tail))
2128 return PROLOG_SUCCESS;
2133 extern "C" Prolog_foreign_return_type
2135 Prolog_term_ref t_clist) {
2136 static const char* where =
"ppl_MIP_Problem_constraints/2";
2138 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2141 Prolog_term_ref tail = Prolog_new_term_ref();
2142 Prolog_put_nil(tail);
2145 Prolog_construct_cons(tail, constraint_term(*i), tail);
2147 if (Prolog_unify(t_clist, tail))
2148 return PROLOG_SUCCESS;
2153 extern "C" Prolog_foreign_return_type
2155 Prolog_term_ref t_le_expr) {
2156 static const char* where =
"ppl_MIP_Problem_objective_function/2";
2158 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2162 Prolog_term_ref t = get_linear_expression(le);
2164 if (Prolog_unify(t_le_expr, t))
2165 return PROLOG_SUCCESS;
2170 extern "C" Prolog_foreign_return_type
2172 Prolog_term_ref t_opt) {
2173 static const char* where =
"ppl_MIP_Problem_optimization_mode/2";
2175 MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2179 Prolog_term_ref t = Prolog_new_term_ref();
2180 Prolog_atom a = (mode ==
MAXIMIZATION) ? a_max : a_min;
2181 Prolog_put_atom(t, a);
2182 if (Prolog_unify(t_opt, t))
2183 return PROLOG_SUCCESS;
2188 extern "C" Prolog_foreign_return_type
2190 static const char* where =
"ppl_MIP_Problem_clear/1";
2192 MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2195 return PROLOG_SUCCESS;
2200 extern "C" Prolog_foreign_return_type
2202 (Prolog_term_ref t_mip, Prolog_term_ref t_nnd) {
2203 static const char* where
2204 =
"ppl_MIP_Problem_add_space_dimensions_and_embed/2";
2206 MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2208 dimension_type d = term_to_unsigned<dimension_type>(t_nnd, where);
2210 return PROLOG_SUCCESS;
2215 extern "C" Prolog_foreign_return_type
2217 Prolog_term_ref t_vlist) {
2218 static const char* where
2219 =
"ppl_MIP_Problem_add_to_integer_space_dimensions/2";
2221 MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2224 Prolog_term_ref v = Prolog_new_term_ref();
2226 while (Prolog_is_cons(t_vlist)) {
2227 Prolog_get_cons(t_vlist, v, t_vlist);
2228 i_vars.
insert(term_to_Variable(v, where).
id());
2232 check_nil_terminating(t_vlist, where);
2235 return PROLOG_SUCCESS;
2240 extern "C" Prolog_foreign_return_type
2242 static const char* where =
"ppl_MIP_Problem_add_constraint/2";
2244 MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2247 return PROLOG_SUCCESS;
2252 extern "C" Prolog_foreign_return_type
2254 Prolog_term_ref t_clist) {
2255 static const char* where =
"ppl_MIP_Problem_add_constraints/2";
2257 MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2260 Prolog_term_ref c = Prolog_new_term_ref();
2262 while (Prolog_is_cons(t_clist)) {
2263 Prolog_get_cons(t_clist, c, t_clist);
2264 cs.
insert(build_constraint(c, where));
2268 check_nil_terminating(t_clist, where);
2271 return PROLOG_SUCCESS;
2276 extern "C" Prolog_foreign_return_type
2278 Prolog_term_ref t_le_expr) {
2279 static const char* where =
"ppl_MIP_Problem_set_objective_function/2";
2281 MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2284 return PROLOG_SUCCESS;
2289 extern "C" Prolog_foreign_return_type
2291 Prolog_term_ref t_opt) {
2292 static const char* where =
"ppl_MIP_Problem_set_optimization_mode/2";
2294 MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2297 Prolog_atom opt = term_to_optimization_mode(t_opt, where);
2300 return PROLOG_SUCCESS;
2305 extern "C" Prolog_foreign_return_type
2307 Prolog_term_ref t_cp_value) {
2308 static const char* where =
"ppl_MIP_Problem_set_control_parameter/2";
2310 MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2313 Prolog_atom cp_value = term_to_control_parameter_value(t_cp_value, where);
2314 if (cp_value == a_pricing_steepest_edge_float)
2316 else if (cp_value == a_pricing_steepest_edge_exact)
2318 else if (cp_value == a_pricing_textbook)
2322 return PROLOG_SUCCESS;
2327 extern "C" Prolog_foreign_return_type
2329 Prolog_term_ref t_cp_name,
2330 Prolog_term_ref t_cp_value) {
2331 static const char* where =
"ppl_MIP_Problem_get_control_parameter/3";
2333 MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2335 Prolog_atom cp_name = term_to_control_parameter_name(t_cp_name, where);
2337 if (cp_name == a_pricing)
2342 Prolog_term_ref t = Prolog_new_term_ref();
2344 switch (ppl_cp_value) {
2346 a = a_pricing_steepest_edge_float;
2349 a = a_pricing_steepest_edge_exact;
2352 a = a_pricing_textbook;
2357 Prolog_put_atom(t, a);
2358 if (Prolog_unify(t_cp_value, t))
2359 return PROLOG_SUCCESS;
2364 extern "C" Prolog_foreign_return_type
2366 static const char* where =
"ppl_MIP_Problem_is_satisfiable/1";
2368 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2371 return PROLOG_SUCCESS;
2376 extern "C" Prolog_foreign_return_type
2378 static const char* where =
"ppl_MIP_Problem_solve/2";
2380 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2384 switch (mip->
solve()) {
2397 Prolog_term_ref t = Prolog_new_term_ref();
2398 Prolog_put_atom(t, a);
2399 if (Prolog_unify(t_status, t))
2400 return PROLOG_SUCCESS;
2405 extern "C" Prolog_foreign_return_type
2407 Prolog_term_ref t_g) {
2408 static const char* where =
"ppl_MIP_Problem_feasible_point/2";
2410 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2413 if (Prolog_unify(t_g, generator_term(g)))
2414 return PROLOG_SUCCESS;
2419 extern "C" Prolog_foreign_return_type
2421 Prolog_term_ref t_g) {
2422 static const char* where =
"ppl_MIP_Problem_optimizing_point/2";
2424 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2427 if (Prolog_unify(t_g, generator_term(g)))
2428 return PROLOG_SUCCESS;
2433 extern "C" Prolog_foreign_return_type
2435 Prolog_term_ref t_n,
2436 Prolog_term_ref t_d) {
2437 static const char* where =
"ppl_MIP_Problem_optimal_value/3";
2439 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2444 if (Prolog_unify_Coefficient(t_n, n)
2445 && Prolog_unify_Coefficient(t_d, d))
2446 return PROLOG_SUCCESS;
2451 extern "C" Prolog_foreign_return_type
2453 Prolog_term_ref t_g,
2454 Prolog_term_ref t_n,
2455 Prolog_term_ref t_d) {
2456 static const char* where =
"ppl_MIP_Problem_evaluate_objective_function/4";
2458 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2463 if (Prolog_unify_Coefficient(t_n, n)
2464 && Prolog_unify_Coefficient(t_d, d))
2465 return PROLOG_SUCCESS;
2470 extern "C" Prolog_foreign_return_type
2472 static const char* where =
"ppl_MIP_Problem_OK/1";
2474 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2477 return PROLOG_SUCCESS;
2482 extern "C" Prolog_foreign_return_type
2484 static const char* where =
"ppl_MIP_Problem_ascii_dump/1";
2486 const MIP_Problem* mip = term_to_handle<MIP_Problem>(t_mip, where);
2489 return PROLOG_SUCCESS;
2494 extern "C" Prolog_foreign_return_type
2496 (Prolog_term_ref t_nd, Prolog_term_ref t_pip) {
2497 static const char* where =
"ppl_PIP_Problem_from_space_dimension/2";
2499 dimension_type d = term_to_unsigned<dimension_type>(t_nd, where);
2501 Prolog_term_ref tmp = Prolog_new_term_ref();
2502 Prolog_put_address(tmp, pip);
2503 if (Prolog_unify(t_pip, tmp)) {
2505 return PROLOG_SUCCESS;
2513 extern "C" Prolog_foreign_return_type
2515 Prolog_term_ref t_cs,
2516 Prolog_term_ref t_params,
2517 Prolog_term_ref t_pip) {
2518 static const char* where =
"ppl_new_PIP_Problem/4";
2520 dimension_type dim = term_to_unsigned<dimension_type>(t_dim, where);
2522 Prolog_term_ref t_c = Prolog_new_term_ref();
2523 while (Prolog_is_cons(t_cs)) {
2524 Prolog_get_cons(t_cs, t_c, t_cs);
2525 cs.insert(build_constraint(t_c, where));
2528 check_nil_terminating(t_cs, where);
2531 Prolog_term_ref t_par = Prolog_new_term_ref();
2532 while (Prolog_is_cons(t_params)) {
2533 Prolog_get_cons(t_params, t_par, t_params);
2534 params.
insert(term_to_Variable(t_par, where).
id());
2537 check_nil_terminating(t_params, where);
2540 Prolog_term_ref tmp = Prolog_new_term_ref();
2541 Prolog_put_address(tmp, pip);
2542 if (Prolog_unify(t_pip, tmp)) {
2544 return PROLOG_SUCCESS;
2552 extern "C" Prolog_foreign_return_type
2554 Prolog_term_ref t_pip) {
2555 static const char* where =
"ppl_new_PIP_Problem_from_PIP_Problem/2";
2559 (term_to_handle<PIP_Problem>(t_pip_source, where));
2562 Prolog_term_ref tmp = Prolog_new_term_ref();
2563 Prolog_put_address(tmp, pip);
2564 if (Prolog_unify(t_pip, tmp)) {
2566 return PROLOG_SUCCESS;
2574 extern "C" Prolog_foreign_return_type
2576 static const char* where =
"ppl_PIP_Problem_swap/2";
2578 PIP_Problem* lhs = term_to_handle<PIP_Problem>(t_lhs, where);
2579 PIP_Problem* rhs = term_to_handle<PIP_Problem>(t_rhs, where);
2583 return PROLOG_SUCCESS;
2588 extern "C" Prolog_foreign_return_type
2590 static const char* where =
"ppl_delete_PIP_Problem/1";
2592 const PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
2595 return PROLOG_SUCCESS;
2600 extern "C" Prolog_foreign_return_type
2602 static const char* where =
"ppl_PIP_Problem_space_dimension/2";
2604 const PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
2607 return PROLOG_SUCCESS;
2612 extern "C" Prolog_foreign_return_type
2614 Prolog_term_ref t_vlist) {
2615 static const char* where =
"ppl_PIP_Problem_parameter_space_dimensions/2";
2617 const PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
2620 Prolog_term_ref tail = Prolog_new_term_ref();
2621 Prolog_put_nil(tail);
2624 for (Variables_Set::const_iterator i = params.begin(),
2625 i_end = params.end(); i != i_end; ++i)
2626 Prolog_construct_cons(tail, variable_term(*i), tail);
2628 if (Prolog_unify(t_vlist, tail))
2629 return PROLOG_SUCCESS;
2634 extern "C" Prolog_foreign_return_type
2636 Prolog_term_ref t_clist) {
2637 static const char* where =
"ppl_PIP_Problem_constraints/2";
2639 const PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
2642 Prolog_term_ref tail = Prolog_new_term_ref();
2643 Prolog_put_nil(tail);
2646 Prolog_construct_cons(tail, constraint_term(*i), tail);
2648 if (Prolog_unify(t_clist, tail))
2649 return PROLOG_SUCCESS;
2654 extern "C" Prolog_foreign_return_type
2656 static const char* where =
"ppl_PIP_Problem_clear/1";
2658 PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
2661 return PROLOG_SUCCESS;
2666 extern "C" Prolog_foreign_return_type
2668 (Prolog_term_ref t_pip,
2669 Prolog_term_ref t_num_vars,
2670 Prolog_term_ref t_num_params) {
2671 static const char* where
2672 =
"ppl_PIP_Problem_add_space_dimensions_and_embed/3";
2674 PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
2676 dimension_type nv = term_to_unsigned<dimension_type>(t_num_vars, where);
2677 dimension_type np = term_to_unsigned<dimension_type>(t_num_params, where);
2679 return PROLOG_SUCCESS;
2684 extern "C" Prolog_foreign_return_type
2686 Prolog_term_ref t_vlist) {
2687 static const char* where
2688 =
"ppl_PIP_Problem_add_to_parameter_space_dimensions/2";
2690 PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
2693 Prolog_term_ref v = Prolog_new_term_ref();
2695 while (Prolog_is_cons(t_vlist)) {
2696 Prolog_get_cons(t_vlist, v, t_vlist);
2697 params.
insert(term_to_Variable(v, where).
id());
2701 check_nil_terminating(t_vlist, where);
2704 return PROLOG_SUCCESS;
2709 extern "C" Prolog_foreign_return_type
2711 static const char* where =
"ppl_PIP_Problem_add_constraint/2";
2713 PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
2716 return PROLOG_SUCCESS;
2721 extern "C" Prolog_foreign_return_type
2723 Prolog_term_ref t_clist) {
2724 static const char* where =
"ppl_PIP_Problem_add_constraints/2";
2726 PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
2729 Prolog_term_ref c = Prolog_new_term_ref();
2731 while (Prolog_is_cons(t_clist)) {
2732 Prolog_get_cons(t_clist, c, t_clist);
2733 cs.
insert(build_constraint(c, where));
2737 check_nil_terminating(t_clist, where);
2740 return PROLOG_SUCCESS;
2745 extern "C" Prolog_foreign_return_type
2747 Prolog_term_ref t_cp_name,
2748 Prolog_term_ref t_cp_value) {
2749 static const char* where =
"ppl_PIP_Problem_get_control_parameter/3";
2751 PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
2753 Prolog_atom cp_name = term_to_pip_problem_control_parameter_name(t_cp_name, where);
2756 if (cp_name == a_cutting_strategy) {
2759 switch (ppl_cp_value) {
2761 a = a_cutting_strategy_first;
2764 a = a_cutting_strategy_deepest;
2767 a = a_cutting_strategy_all;
2771 "ppl_PIP_Problem_get_control_parameter()");
2774 else if (cp_name == a_pivot_row_strategy) {
2777 switch (ppl_cp_value) {
2779 a = a_pivot_row_strategy_first;
2782 a = a_pivot_row_strategy_max_column;
2786 "ppl_PIP_Problem_get_control_parameter()");
2792 Prolog_term_ref t = Prolog_new_term_ref();
2793 Prolog_put_atom(t, a);
2794 if (Prolog_unify(t_cp_value, t))
2795 return PROLOG_SUCCESS;
2800 extern "C" Prolog_foreign_return_type
2802 Prolog_term_ref t_cp_value) {
2803 static const char* where =
"ppl_PIP_Problem_set_control_parameter/2";
2805 PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
2808 Prolog_atom cp_value = term_to_pip_problem_control_parameter_value(t_cp_value, where);
2809 if (cp_value == a_cutting_strategy_first)
2811 else if (cp_value == a_cutting_strategy_deepest)
2813 else if (cp_value == a_cutting_strategy_all)
2815 else if (cp_value == a_pivot_row_strategy_first)
2817 else if (cp_value == a_pivot_row_strategy_max_column)
2821 return PROLOG_SUCCESS;
2826 extern "C" Prolog_foreign_return_type
2828 Prolog_term_ref t_d) {
2829 static const char* where =
"ppl_PIP_Problem_get_big_parameter_dimension/2";
2831 PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
2835 return PROLOG_FAILURE;
2836 if (unify_ulong(t_d, dim))
2837 return PROLOG_SUCCESS;
2842 extern "C" Prolog_foreign_return_type
2844 Prolog_term_ref t_d) {
2845 static const char* where =
"ppl_MIP_Problem_set_big_parameter_dimension/2";
2847 PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
2851 return PROLOG_SUCCESS;
2856 extern "C" Prolog_foreign_return_type
2858 static const char* where =
"ppl_PIP_Problem_is_satisfiable/1";
2860 const PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
2863 return PROLOG_SUCCESS;
2868 extern "C" Prolog_foreign_return_type
2870 static const char* where =
"ppl_PIP_Problem_solve/2";
2872 const PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
2876 switch (pip->
solve()) {
2886 Prolog_term_ref t = Prolog_new_term_ref();
2887 Prolog_put_atom(t, a);
2888 if (Prolog_unify(t_status, t))
2889 return PROLOG_SUCCESS;
2894 extern "C" Prolog_foreign_return_type
2896 Prolog_term_ref t_pip_tree) {
2897 static const char* where =
"ppl_PIP_Problem_solution/2";
2899 const PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
2902 Prolog_term_ref t_sol = Prolog_new_term_ref();
2903 Prolog_put_address(t_sol, sol);
2904 if (Prolog_unify(t_pip_tree, t_sol)) {
2906 return PROLOG_SUCCESS;
2912 extern "C" Prolog_foreign_return_type
2914 Prolog_term_ref t_pip_tree) {
2915 static const char* where =
"ppl_PIP_Problem_optimizing_solution/2";
2917 const PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
2920 Prolog_term_ref t_sol = Prolog_new_term_ref();
2921 Prolog_put_address(t_sol, sol);
2922 if (Prolog_unify(t_pip_tree, t_sol)) {
2924 return PROLOG_SUCCESS;
2930 extern "C" Prolog_foreign_return_type
2932 static const char* where =
"ppl_PIP_Problem_OK/1";
2934 const PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
2937 return PROLOG_SUCCESS;
2942 extern "C" Prolog_foreign_return_type
2944 static const char* where =
"ppl_PIP_Problem_ascii_dump/1";
2946 const PIP_Problem* pip = term_to_handle<PIP_Problem>(t_pip, where);
2949 return PROLOG_SUCCESS;
2954 extern "C" Prolog_foreign_return_type
2956 Prolog_term_ref t_cs) {
2957 static const char* where =
"ppl_PIP_Tree_Node_constraints/2";
2959 const PIP_Tree_Node* pip = term_to_handle<PIP_Tree_Node>(t_pip, where);
2962 Prolog_term_ref tail = Prolog_new_term_ref();
2963 Prolog_put_nil(tail);
2966 ppl_cs_end = ppl_cs.
end(); i != ppl_cs_end; ++i)
2967 Prolog_construct_cons(tail, constraint_term(*i), tail);
2969 if (Prolog_unify(t_cs, tail)) {
2970 return PROLOG_SUCCESS;
2976 extern "C" Prolog_foreign_return_type
2978 static const char* where =
"ppl_PIP_Tree_Node_as_solution/2";
2980 const PIP_Tree_Node* pip = term_to_handle<PIP_Tree_Node>(t_pip, where);
2984 return PROLOG_SUCCESS;
2985 return PROLOG_FAILURE;
2990 extern "C" Prolog_foreign_return_type
2992 static const char* where =
"ppl_PIP_Tree_Node_as_decision/2";
2994 const PIP_Tree_Node* pip = term_to_handle<PIP_Tree_Node>(t_pip, where);
2998 return PROLOG_SUCCESS;
2999 return PROLOG_FAILURE;
3004 extern "C" Prolog_foreign_return_type
3006 static const char* where =
"ppl_PIP_Tree_Node_as_decision/2";
3008 const PIP_Tree_Node* pip = term_to_handle<PIP_Tree_Node>(t_pip, where);
3012 return PROLOG_SUCCESS;
3013 return PROLOG_FAILURE;
3018 extern "C" Prolog_foreign_return_type
3020 Prolog_term_ref t_artlist) {
3021 static const char* where =
"ppl_PIP_Tree_Node_artificials/2";
3024 = term_to_handle<PIP_Tree_Node>(t_tree_node, where);
3027 Prolog_term_ref tail = Prolog_new_term_ref();
3028 Prolog_put_nil(tail);
3029 for (PIP_Tree_Node::Artificial_Parameter_Sequence::const_iterator
3032 Prolog_construct_cons(tail, artificial_parameter_term(*i), tail);
3034 if (Prolog_unify(t_artlist, tail))
3035 return PROLOG_SUCCESS;
3040 extern "C" Prolog_foreign_return_type
3042 Prolog_term_ref t_var,
3043 Prolog_term_ref t_le) {
3044 static const char* where =
"ppl_PIP_Solution_Node_get_parametric_values/3";
3047 = term_to_handle<PIP_Solution_Node>(t_pip, where);
3049 Variable var = term_to_Variable(t_var, where);
3051 return PROLOG_SUCCESS;
3056 extern "C" Prolog_foreign_return_type
3058 Prolog_term_ref t_ptree) {
3059 static const char* where =
"ppl_PIP_Decision_Node_get_true_child/2";
3062 = term_to_handle<PIP_Decision_Node>(t_pip, where);
3066 Prolog_term_ref t_ppl_ptree = Prolog_new_term_ref();
3067 Prolog_put_address(t_ppl_ptree, ppl_ptree);
3068 if (Prolog_unify(t_ptree, t_ppl_ptree)) {
3070 return PROLOG_SUCCESS;
3076 extern "C" Prolog_foreign_return_type
3078 Prolog_term_ref t_ptree) {
3079 static const char* where =
"ppl_PIP_Decision_Node_get_false_child/2";
3082 = term_to_handle<PIP_Decision_Node>(t_pip, where);
3086 Prolog_term_ref t_ppl_ptree = Prolog_new_term_ref();
3087 Prolog_put_address(t_ppl_ptree, ppl_ptree);
3088 if (Prolog_unify(t_ptree, t_ppl_ptree)) {
3090 return PROLOG_SUCCESS;
3096 extern "C" Prolog_foreign_return_type
3098 static const char* where =
"ppl_PIP_Tree_Node_OK/1";
3100 const PIP_Tree_Node* pip = term_to_handle<PIP_Tree_Node>(t_pip, where);
3103 return PROLOG_SUCCESS;
Prolog_foreign_return_type ppl_MIP_Problem_feasible_point(Prolog_term_ref t_mip, Prolog_term_ref t_g)
Artificial_Parameter_Sequence::const_iterator art_parameter_begin() const
bool is_satisfiable() const
Prolog_foreign_return_type ppl_PIP_Tree_Node_is_decision(Prolog_term_ref t_pip)
Prolog_foreign_return_type ppl_MIP_Problem_space_dimension(Prolog_term_ref t_mip, Prolog_term_ref t_sd)
Prolog_foreign_return_type ppl_Coefficient_max(Prolog_term_ref t_max)
Prolog_foreign_return_type ppl_version_revision(Prolog_term_ref t_v)
Prolog_foreign_return_type ppl_set_irrational_precision(Prolog_term_ref t_p)
dimension_type max_space_dimension()
const_iterator constraints_end() const
void set_optimization_mode(Optimization_Mode mode)
Coefficient_traits::const_reference modulus() const
void swap(CO_Tree &x, CO_Tree &y)
void add_constraint(const Constraint &c)
virtual const PIP_Decision_Node * as_decision() const =0
unsigned long max() const
Prolog_foreign_return_type ppl_PIP_Problem_ascii_dump(Prolog_term_ref t_pip)
Prolog_foreign_return_type ppl_MIP_Problem_optimizing_point(Prolog_term_ref t_mip, Prolog_term_ref t_g)
void set_control_parameter(Control_Parameter_Value value)
Prolog_foreign_return_type ppl_new_MIP_Problem_from_space_dimension(Prolog_term_ref t_nd, Prolog_term_ref t_mip)
Prolog_foreign_return_type ppl_Coefficient_min(Prolog_term_ref t_min)
void add_constraints(const Constraint_System &cs)
void add_constraints(const Constraint_System &cs)
Prolog_foreign_return_type ppl_MIP_Problem_clear(Prolog_term_ref t_mip)
Coefficient_traits::const_reference inhomogeneous_term() const
#define PPL_DIRTY_TEMP_COEFFICIENT(id)
const_iterator constraints_end() const
Prolog_foreign_return_type ppl_PIP_Tree_Node_is_bottom(Prolog_term_ref t_pip)
const Linear_Expression & parametric_values(Variable var) const
Prolog_foreign_return_type ppl_version(Prolog_term_ref t_v)
dimension_type not_a_dimension()
static Generator ray(const Linear_Expression &e, Representation r=default_representation)
Prolog_foreign_return_type ppl_MIP_Problem_ascii_dump(Prolog_term_ref t_mip)
Prolog_foreign_return_type ppl_new_PIP_Problem(Prolog_term_ref t_dim, Prolog_term_ref t_cs, Prolog_term_ref t_params, Prolog_term_ref t_pip)
void insert(const Constraint &c)
Prolog_foreign_return_type ppl_version_minor(Prolog_term_ref t_v)
Constraint_Sequence::const_iterator const_iterator
dimension_type space_dimension() const
Prolog_foreign_return_type ppl_MIP_Problem_set_control_parameter(Prolog_term_ref t_mip, Prolog_term_ref t_cp_value)
Prolog_foreign_return_type ppl_MIP_Problem_swap(Prolog_term_ref t_lhs, Prolog_term_ref t_rhs)
void set_big_parameter_dimension(dimension_type big_dim)
Prolog_foreign_return_type ppl_initialize()
Prolog_foreign_return_type ppl_new_MIP_Problem(Prolog_term_ref t_nd, Prolog_term_ref t_clist, Prolog_term_ref t_le_expr, Prolog_term_ref t_opt, Prolog_term_ref t_mip)
Prolog_foreign_return_type ppl_MIP_Problem_set_objective_function(Prolog_term_ref t_mip, Prolog_term_ref t_le_expr)
void evaluate_objective_function(const Generator &evaluating_point, Coefficient &numer, Coefficient &denom) const
Prolog_foreign_return_type ppl_Coefficient_bits(Prolog_term_ref t_bits)
Prolog_foreign_return_type ppl_PIP_Problem_space_dimension(Prolog_term_ref t_pip, Prolog_term_ref t_sd)
Coefficient_traits::const_reference inhomogeneous_term() const
void add_constraint(const Constraint &c)
const_iterator begin() const
Prolog_foreign_return_type ppl_MIP_Problem_optimal_value(Prolog_term_ref t_mip, Prolog_term_ref t_n, Prolog_term_ref t_d)
Prolog_foreign_return_type ppl_PIP_Problem_clear(Prolog_term_ref t_pip)
static Generator closure_point(const Linear_Expression &e=Linear_Expression::zero(), Coefficient_traits::const_reference d=Coefficient_one(), Representation r=default_representation)
Prolog_foreign_return_type ppl_PIP_Problem_solve(Prolog_term_ref t_pip, Prolog_term_ref t_status)
Prolog_foreign_return_type ppl_version_major(Prolog_term_ref t_v)
const Parma_Polyhedra_Library::Coefficient value() const
Prolog_foreign_return_type ppl_MIP_Problem_constraints(Prolog_term_ref t_mip, Prolog_term_ref t_clist)
void set_irrational_precision(const unsigned p)
Artificial_Parameter_Sequence::const_iterator art_parameter_end() const
const Variables_Set & integer_space_dimensions() const
const Linear_Expression & objective_function() const
const Generator & optimizing_point() const
Prolog_foreign_return_type ppl_MIP_Problem_objective_function(Prolog_term_ref t_mip, Prolog_term_ref t_le_expr)
static Generator line(const Linear_Expression &e, Representation r=default_representation)
void set_rounding_for_PPL()
Control_Parameter_Value get_control_parameter(Control_Parameter_Name name) const
Prolog_foreign_return_type ppl_new_PIP_Problem_from_PIP_Problem(Prolog_term_ref t_pip_source, Prolog_term_ref t_pip)
Prolog_foreign_return_type ppl_MIP_Problem_is_satisfiable(Prolog_term_ref t_mip)
Prolog_foreign_return_type ppl_PIP_Tree_Node_parametric_values(Prolog_term_ref t_pip, Prolog_term_ref t_var, Prolog_term_ref t_le)
Prolog_foreign_return_type ppl_PIP_Problem_has_big_parameter_dimension(Prolog_term_ref t_pip, Prolog_term_ref t_d)
const_iterator constraints_begin() const
static Grid_Generator parameter(const Linear_Expression &e=Linear_Expression::zero(), Coefficient_traits::const_reference d=Coefficient_one(), Representation r=default_representation)
Prolog_foreign_return_type ppl_PIP_Problem_swap(Prolog_term_ref t_lhs, Prolog_term_ref t_rhs)
const Variables_Set & parameter_space_dimensions() const
Coefficient_traits::const_reference divisor() const
Prolog_foreign_return_type ppl_PIP_Problem_solution(Prolog_term_ref t_pip, Prolog_term_ref t_pip_tree)
virtual bool OK() const =0
Optimization_Mode optimization_mode() const
Prolog_foreign_return_type ppl_set_deterministic_timeout(Prolog_term_ref t_unscaled_weight, Prolog_term_ref t_scale)
Prolog_foreign_return_type ppl_PIP_Tree_Node_OK(Prolog_term_ref t_pip)
Prolog_foreign_return_type ppl_MIP_Problem_optimization_mode(Prolog_term_ref t_mip, Prolog_term_ref t_opt)
const_iterator end() const
void optimal_value(Coefficient &numer, Coefficient &denom) const
const Constraint_System & constraints() const
Prolog_foreign_return_type ppl_MIP_Problem_add_to_integer_space_dimensions(Prolog_term_ref t_mip, Prolog_term_ref t_vlist)
Prolog_foreign_return_type ppl_Coefficient_is_bounded()
Prolog_foreign_return_type ppl_MIP_Problem_OK(Prolog_term_ref t_mip)
PIVOT_ROW_STRATEGY_MAX_COLUMN
virtual Prolog_term_ref term() const
Prolog_foreign_return_type ppl_MIP_Problem_set_optimization_mode(Prolog_term_ref t_mip, Prolog_term_ref t_opt)
Prolog_foreign_return_type ppl_MIP_Problem_add_constraints(Prolog_term_ref t_mip, Prolog_term_ref t_clist)
Prolog_foreign_return_type ppl_banner(Prolog_term_ref t_b)
bool is_satisfiable() const
Prolog_foreign_return_type ppl_MIP_Problem_integer_space_dimensions(Prolog_term_ref t_mip, Prolog_term_ref t_vlist)
PPL_COEFFICIENT_TYPE Coefficient
Prolog_foreign_return_type ppl_MIP_Problem_get_control_parameter(Prolog_term_ref t_mip, Prolog_term_ref t_cp_name, Prolog_term_ref t_cp_value)
Prolog_foreign_return_type ppl_PIP_Tree_Node_false_child(Prolog_term_ref t_pip, Prolog_term_ref t_ptree)
Prolog_foreign_return_type ppl_PIP_Problem_add_constraints(Prolog_term_ref t_pip, Prolog_term_ref t_clist)
virtual const PIP_Solution_Node * as_solution() const =0
const PIP_Tree_Node * child_node(bool b) const
Prolog_foreign_return_type ppl_timeout_exception_atom(Prolog_term_ref t)
Prolog_foreign_return_type ppl_reset_deterministic_timeout()
Prolog_foreign_return_type ppl_PIP_Problem_OK(Prolog_term_ref t_pip)
Prolog_foreign_return_type ppl_irrational_precision(Prolog_term_ref t_p)
static Generator point(const Linear_Expression &e=Linear_Expression::zero(), Coefficient_traits::const_reference d=Coefficient_one(), Representation r=default_representation)
Prolog_foreign_return_type ppl_delete_MIP_Problem(Prolog_term_ref t_mip)
Prolog_foreign_return_type ppl_PIP_Problem_add_constraint(Prolog_term_ref t_pip, Prolog_term_ref t_c)
Prolog_foreign_return_type ppl_restore_pre_PPL_rounding()
Prolog_foreign_return_type ppl_MIP_Problem_add_space_dimensions_and_embed(Prolog_term_ref t_mip, Prolog_term_ref t_nnd)
Prolog_foreign_return_type ppl_PIP_Problem_add_space_dimensions_and_embed(Prolog_term_ref t_pip, Prolog_term_ref t_num_vars, Prolog_term_ref t_num_params)
virtual const char * where() const
static Grid_Generator grid_point(const Linear_Expression &e=Linear_Expression::zero(), Coefficient_traits::const_reference d=Coefficient_one(), Representation r=default_representation)
unsigned version_revision()
PIP_Problem_Status solve() const
const Generator & feasible_point() const
Prolog_foreign_return_type ppl_finalize()
Prolog_foreign_return_type ppl_new_PIP_Problem_from_space_dimension(Prolog_term_ref t_nd, Prolog_term_ref t_pip)
static Grid_Generator grid_line(const Linear_Expression &e, Representation r=default_representation)
Prolog_foreign_return_type ppl_PIP_Problem_add_to_parameter_space_dimensions(Prolog_term_ref t_pip, Prolog_term_ref t_vlist)
Prolog_foreign_return_type ppl_PIP_Tree_Node_is_solution(Prolog_term_ref t_pip)
unsigned irrational_precision()
PIP_Tree solution() const
const char * where() const
Prolog_foreign_return_type ppl_PIP_Tree_Node_constraints(Prolog_term_ref t_pip, Prolog_term_ref t_cs)
Prolog_foreign_return_type ppl_PIP_Problem_get_control_parameter(Prolog_term_ref t_pip, Prolog_term_ref t_cp_name, Prolog_term_ref t_cp_value)
void set_objective_function(const Linear_Expression &obj)
MIP_Problem_Status solve() const
Prolog_foreign_return_type ppl_version_beta(Prolog_term_ref t_v)
Prolog_foreign_return_type ppl_PIP_Tree_Node_artificials(Prolog_term_ref t_tree_node, Prolog_term_ref t_artlist)
#define PPL_WEAK_REGISTER(x)
Prolog_foreign_return_type ppl_MIP_Problem_evaluate_objective_function(Prolog_term_ref t_mip, Prolog_term_ref t_g, Prolog_term_ref t_n, Prolog_term_ref t_d)
PRICING_STEEPEST_EDGE_FLOAT
Coefficient_traits::const_reference divisor() const
Prolog_foreign_return_type ppl_PIP_Problem_set_big_parameter_dimension(Prolog_term_ref t_pip, Prolog_term_ref t_d)
Prolog_foreign_return_type ppl_set_timeout_exception_atom(Prolog_term_ref t_tea)
#define PPL_UNREGISTER(x)
PRICING_STEEPEST_EDGE_EXACT
void set_control_parameter(Control_Parameter_Value value)
dimension_type get_big_parameter_dimension() const
Coefficient_traits::const_reference inhomogeneous_term() const
Prolog_foreign_return_type ppl_set_rounding_for_PPL()
Prolog_foreign_return_type ppl_PIP_Problem_parameter_space_dimensions(Prolog_term_ref t_pip, Prolog_term_ref t_vlist)
Prolog_foreign_return_type ppl_delete_PIP_Problem(Prolog_term_ref t_pip)
void add_to_parameter_space_dimensions(const Variables_Set &p_vars)
void add_space_dimensions_and_embed(dimension_type m)
const Throwable *volatile abandon_expensive_computations
const_iterator constraints_begin() const
Prolog_foreign_return_type ppl_PIP_Problem_set_control_parameter(Prolog_term_ref t_pip, Prolog_term_ref t_cp_value)
Control_Parameter_Value get_control_parameter(Control_Parameter_Name name) const
void add_space_dimensions_and_embed(dimension_type m_vars, dimension_type m_params)
Prolog_foreign_return_type ppl_MIP_Problem_add_constraint(Prolog_term_ref t_mip, Prolog_term_ref t_c)
Prolog_foreign_return_type ppl_MIP_Problem_solve(Prolog_term_ref t_mip, Prolog_term_ref t_status)
Prolog_foreign_return_type ppl_PIP_Problem_optimizing_solution(Prolog_term_ref t_pip, Prolog_term_ref t_pip_tree)
PIP_Tree optimizing_solution() const
Prolog_foreign_return_type ppl_PIP_Tree_Node_true_child(Prolog_term_ref t_pip, Prolog_term_ref t_ptree)
Prolog_foreign_return_type ppl_max_space_dimension(Prolog_term_ref t_msd)
Prolog_foreign_return_type ppl_reset_timeout()
Prolog_foreign_return_type ppl_new_MIP_Problem_from_MIP_Problem(Prolog_term_ref t_mip_source, Prolog_term_ref t_mip)
Prolog_foreign_return_type ppl_set_timeout(Prolog_term_ref t_csecs)
Prolog_foreign_return_type ppl_PIP_Problem_constraints(Prolog_term_ref t_pip, Prolog_term_ref t_clist)
void restore_pre_PPL_rounding()
Prolog_foreign_return_type ppl_PIP_Problem_is_satisfiable(Prolog_term_ref t_pip)
void add_to_integer_space_dimensions(const Variables_Set &i_vars)
dimension_type space_dimension() const