00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "ppl.hh"
00024 #include "ppl_c.h"
00025 #include <stdexcept>
00026 #include <limits>
00027 #include <sstream>
00028 #include <cstdio>
00029 #include <cerrno>
00030 #include <climits>
00031
00032 using namespace Parma_Polyhedra_Library;
00033
00035 mpz_class&
00036 reinterpret_mpz_class(mpz_t n) {
00037 return reinterpret_cast<mpz_class&>(*n);
00038 }
00039
00040 #define DECLARE_CONVERSIONS(Type) \
00041 inline const Type* \
00042 to_const(ppl_const_ ## Type ## _t x) { \
00043 return reinterpret_cast<const Type*>(x); \
00044 } \
00045 \
00046 inline Type* \
00047 to_nonconst(ppl_ ## Type ## _t x) { \
00048 return reinterpret_cast<Type*>(x); \
00049 } \
00050 \
00051 inline ppl_const_ ## Type ## _t \
00052 to_const(const Type* x) { \
00053 return reinterpret_cast<ppl_const_ ## Type ## _t>(x); \
00054 } \
00055 \
00056 inline ppl_ ## Type ## _t \
00057 to_nonconst(Type* x) { \
00058 return reinterpret_cast<ppl_ ## Type ## _t>(x); \
00059 }
00060
00061 namespace {
00062
00063 extern "C" typedef void
00064 (*error_handler_type)(enum ppl_enum_error_code code, const char* description);
00065
00066 error_handler_type user_error_handler = 0;
00067
00068 void
00069 notify_error(enum ppl_enum_error_code code, const char* description) {
00070 if (user_error_handler != 0)
00071 user_error_handler(code, description);
00072 }
00073
00074 }
00075
00076 int
00077 ppl_set_error_handler(error_handler_type h) {
00078 user_error_handler = h;
00079 return 0;
00080 }
00081
00082 #define CATCH_STD_EXCEPTION(exception, code) \
00083 catch (const std::exception& e) { \
00084 notify_error(code, e.what()); \
00085 return code; \
00086 }
00087
00088 #define CATCH_ALL \
00089 CATCH_STD_EXCEPTION(bad_alloc, PPL_ERROR_OUT_OF_MEMORY) \
00090 CATCH_STD_EXCEPTION(invalid_argument, PPL_ERROR_INVALID_ARGUMENT) \
00091 CATCH_STD_EXCEPTION(domain_error, PPL_ERROR_DOMAIN_ERROR) \
00092 CATCH_STD_EXCEPTION(length_error, PPL_ERROR_LENGTH_ERROR) \
00093 CATCH_STD_EXCEPTION(overflow_error, PPL_ARITHMETIC_OVERFLOW) \
00094 CATCH_STD_EXCEPTION(runtime_error, PPL_ERROR_INTERNAL_ERROR) \
00095 CATCH_STD_EXCEPTION(exception, PPL_ERROR_UNKNOWN_STANDARD_EXCEPTION) \
00096 catch (...) { \
00097 notify_error(PPL_ERROR_UNEXPECTED_ERROR, \
00098 "completely unexpected error: a bug in the PPL"); \
00099 return PPL_ERROR_UNEXPECTED_ERROR; \
00100 }
00101
00102 unsigned int PPL_POLY_CON_RELATION_IS_DISJOINT;
00103 unsigned int PPL_POLY_CON_RELATION_STRICTLY_INTERSECTS;
00104 unsigned int PPL_POLY_CON_RELATION_IS_INCLUDED;
00105 unsigned int PPL_POLY_CON_RELATION_SATURATES;
00106
00107 unsigned int PPL_POLY_GEN_RELATION_SUBSUMES;
00108
00109 unsigned int PPL_COMPLEXITY_CLASS_POLYNOMIAL;
00110 unsigned int PPL_COMPLEXITY_CLASS_SIMPLEX;
00111 unsigned int PPL_COMPLEXITY_CLASS_ANY;
00112
00113 int PPL_LP_PROBLEM_STATUS_UNFEASIBLE;
00114 int PPL_LP_PROBLEM_STATUS_UNBOUNDED;
00115 int PPL_LP_PROBLEM_STATUS_OPTIMIZED;
00116
00117 int PPL_LP_PROBLEM_MINIMIZATION;
00118 int PPL_LP_PROBLEM_MAXIMIZATION;
00119
00120 namespace {
00121
00122
00123 Init* init_object_ptr = 0;
00124
00125 }
00126
00127
00128
00129 namespace {
00130
00131 extern "C" const char*
00132 c_variable_default_output_function(ppl_dimension_type var) {
00133 #if SIZEOF_SIZE_T == SIZEOF_UNSIGNED
00134 # define FORMAT "%u"
00135 # define CONVERSION (unsigned)
00136 #elif SIZEOF_SIZE_T == SIZEOF_UNSIGNED_LONG
00137 # define FORMAT "%lu"
00138 # define CONVERSION (unsigned long)
00139 #elif SIZEOF_SIZE_T == SIZEOF_UNSIGNED_LONG_LONG
00140 # define FORMAT "%llu"
00141 # define CONVERSION (unsigned long long)
00142 #else
00143 # error "Unsupported definition for `size_t'."
00144 #endif
00145
00146
00147
00148 #if defined(ULLONG_MAX) && ULLONG_MAX > 18446744073709551615ULL
00149 # error "Please enlarge the buffer in the following line."
00150 #endif
00151 static char buffer[20];
00152 buffer[0] = static_cast<char>('A' + var % 26);
00153 if (ppl_dimension_type i = var / 26) {
00154 int r = sprintf(buffer+1, FORMAT, CONVERSION i);
00155 if (r < 0)
00156 return 0;
00157 else if (r >= 19) {
00158 errno = ERANGE;
00159 return 0;
00160 }
00161 }
00162 else
00163 buffer[1] = '\0';
00164 return buffer;
00165 }
00166
00167
00168 ppl_io_variable_output_function_type* c_variable_output_function;
00169
00170 void
00171 cxx_Variable_output_function(std::ostream& s, const Variable& v) {
00172 const char* b = c_variable_output_function(v.id());
00173 if (b == 0)
00174
00175
00176 return;
00177 s << b;
00178 }
00179
00180 extern "C" typedef const char*
00181 c_variable_output_function_type(ppl_dimension_type var);
00182
00183
00184 Variable::output_function_type* saved_cxx_Variable_output_function;
00185
00186 }
00187
00188
00189 int
00190 ppl_initialize(void) try {
00191 if (init_object_ptr != 0)
00192
00193 return PPL_ERROR_INVALID_ARGUMENT;
00194
00195 init_object_ptr = new Init();
00196
00197 PPL_POLY_CON_RELATION_IS_DISJOINT
00198 = Poly_Con_Relation::is_disjoint().get_flags();
00199 PPL_POLY_CON_RELATION_STRICTLY_INTERSECTS
00200 = Poly_Con_Relation::strictly_intersects().get_flags();
00201 PPL_POLY_CON_RELATION_IS_INCLUDED
00202 = Poly_Con_Relation::is_included().get_flags();
00203 PPL_POLY_CON_RELATION_SATURATES
00204 = Poly_Con_Relation::saturates().get_flags();
00205
00206 PPL_POLY_GEN_RELATION_SUBSUMES
00207 = Poly_Gen_Relation::subsumes().get_flags();
00208
00209 PPL_COMPLEXITY_CLASS_POLYNOMIAL = POLYNOMIAL_COMPLEXITY;
00210 PPL_COMPLEXITY_CLASS_SIMPLEX = SIMPLEX_COMPLEXITY;
00211 PPL_COMPLEXITY_CLASS_ANY = ANY_COMPLEXITY;
00212
00213 PPL_LP_PROBLEM_STATUS_UNFEASIBLE = UNFEASIBLE_LP_PROBLEM;
00214 PPL_LP_PROBLEM_STATUS_UNBOUNDED = UNBOUNDED_LP_PROBLEM;
00215 PPL_LP_PROBLEM_STATUS_OPTIMIZED = OPTIMIZED_LP_PROBLEM;
00216
00217 PPL_LP_PROBLEM_MINIMIZATION = MINIMIZATION;
00218 PPL_LP_PROBLEM_MAXIMIZATION = MAXIMIZATION;
00219
00220 c_variable_output_function = c_variable_default_output_function;
00221 saved_cxx_Variable_output_function = Variable::get_output_function();
00222 Variable::set_output_function(cxx_Variable_output_function);
00223
00224 return 0;
00225 }
00226 CATCH_ALL
00227
00228 int
00229 ppl_finalize(void) try {
00230 if (init_object_ptr == 0)
00231
00232 return PPL_ERROR_INVALID_ARGUMENT;
00233
00234 delete init_object_ptr;
00235 init_object_ptr = 0;
00236
00237 Variable::set_output_function(saved_cxx_Variable_output_function);
00238
00239 return 0;
00240 }
00241 CATCH_ALL
00242
00243 int
00244 ppl_version_major(void) try {
00245 return version_major();
00246 }
00247 CATCH_ALL
00248
00249 int
00250 ppl_version_minor(void) try {
00251 return version_minor();
00252 }
00253 CATCH_ALL
00254
00255 int
00256 ppl_version_revision(void) try {
00257 return version_revision();
00258 }
00259 CATCH_ALL
00260
00261 int
00262 ppl_version_beta(void) try {
00263 return version_beta();
00264 }
00265 CATCH_ALL
00266
00267 int
00268 ppl_version(const char** p) try {
00269
00270
00271
00272 *p = Parma_Polyhedra_Library::version();
00273 return 0;
00274 }
00275 CATCH_ALL
00276
00277 int
00278 ppl_banner(const char** p) try {
00279 *p = banner();
00280 return 0;
00281 }
00282 CATCH_ALL
00283
00284 int
00285 ppl_max_space_dimension(ppl_dimension_type* m) try {
00286 *m = max_space_dimension();
00287 return 0;
00288 }
00289 CATCH_ALL
00290
00291 int
00292 ppl_not_a_dimension(ppl_dimension_type* m) try {
00293 *m = not_a_dimension();
00294 return 0;
00295 }
00296 CATCH_ALL
00297
00298 DECLARE_CONVERSIONS(Coefficient)
00299
00300 DECLARE_CONVERSIONS(Linear_Expression)
00301
00302 DECLARE_CONVERSIONS(Constraint)
00303
00304 DECLARE_CONVERSIONS(Constraint_System)
00305
00306 typedef Constraint_System::const_iterator Constraint_System_const_iterator;
00307 DECLARE_CONVERSIONS(Constraint_System_const_iterator)
00308
00309 DECLARE_CONVERSIONS(Generator)
00310
00311 DECLARE_CONVERSIONS(Generator_System)
00312
00313 typedef Generator_System::const_iterator Generator_System_const_iterator;
00314 DECLARE_CONVERSIONS(Generator_System_const_iterator)
00315
00316 DECLARE_CONVERSIONS(Polyhedron)
00317
00318 DECLARE_CONVERSIONS(LP_Problem)
00319
00320
00321 int
00322 ppl_new_Coefficient(ppl_Coefficient_t* pc) try {
00323 *pc = to_nonconst(new Coefficient(0));
00324 return 0;
00325 }
00326 CATCH_ALL
00327
00328 int
00329 ppl_new_Coefficient_from_mpz_t(ppl_Coefficient_t* pc, mpz_t z) try {
00330 *pc = to_nonconst(new Coefficient(reinterpret_mpz_class(z)));
00331 return 0;
00332 }
00333 CATCH_ALL
00334
00335 int
00336 ppl_new_Coefficient_from_Coefficient(ppl_Coefficient_t* pc,
00337 ppl_const_Coefficient_t c) try {
00338 const Coefficient& cc = *to_const(c);
00339 *pc = to_nonconst(new Coefficient(cc));
00340 return 0;
00341 }
00342 CATCH_ALL
00343
00344 int
00345 ppl_Coefficient_to_mpz_t(ppl_const_Coefficient_t c, mpz_t z) try {
00346 assign_r(reinterpret_mpz_class(z), *to_const(c), ROUND_NOT_NEEDED);
00347 return 0;
00348 }
00349 CATCH_ALL
00350
00351 int
00352 ppl_delete_Coefficient(ppl_const_Coefficient_t c) try {
00353 delete to_const(c);
00354 return 0;
00355 }
00356 CATCH_ALL
00357
00358 int
00359 ppl_assign_Coefficient_from_mpz_t(ppl_Coefficient_t dst, mpz_t z) try {
00360 Coefficient& ddst = *to_nonconst(dst);
00361 ddst = reinterpret_mpz_class(z);
00362 return 0;
00363 }
00364 CATCH_ALL
00365
00366 int
00367 ppl_assign_Coefficient_from_Coefficient(ppl_Coefficient_t dst,
00368 ppl_const_Coefficient_t src) try {
00369 const Coefficient& ssrc = *to_const(src);
00370 Coefficient& ddst = *to_nonconst(dst);
00371 ddst = ssrc;
00372 return 0;
00373 }
00374 CATCH_ALL
00375
00376 int
00377 ppl_Coefficient_OK(ppl_const_Coefficient_t ) try {
00378 return 1;
00379 }
00380 CATCH_ALL
00381
00382 int
00383 ppl_Coefficient_is_bounded(void) try {
00384 return std::numeric_limits<Coefficient>::is_bounded ? 1 : 0;
00385 }
00386 CATCH_ALL
00387
00388 int
00389 ppl_Coefficient_min(mpz_t min) try {
00390 if (std::numeric_limits<Coefficient>::is_bounded) {
00391 assign_r(reinterpret_mpz_class(min),
00392 std::numeric_limits<Coefficient>::min(),
00393 ROUND_NOT_NEEDED);
00394 return 1;
00395 }
00396 else
00397 return 0;
00398 }
00399 CATCH_ALL
00400
00401 int
00402 ppl_Coefficient_max(mpz_t max) try {
00403 if (std::numeric_limits<Coefficient>::is_bounded) {
00404 assign_r(reinterpret_mpz_class(max),
00405 std::numeric_limits<Coefficient>::max(),
00406 ROUND_NOT_NEEDED);
00407 return 1;
00408 }
00409 else
00410 return 0;
00411 }
00412 CATCH_ALL
00413
00414 int
00415 ppl_new_Linear_Expression(ppl_Linear_Expression_t* ple) try {
00416 *ple = to_nonconst(new Linear_Expression());
00417 return 0;
00418 }
00419 CATCH_ALL
00420
00421 int
00422 ppl_new_Linear_Expression_with_dimension(ppl_Linear_Expression_t* ple,
00423 ppl_dimension_type d) try {
00424 *ple = to_nonconst(d == 0
00425 ? new Linear_Expression(0)
00426 : new Linear_Expression(0*Variable(d-1)));
00427 return 0;
00428 }
00429 CATCH_ALL
00430
00431 int
00432 ppl_new_Linear_Expression_from_Linear_Expression
00433 (ppl_Linear_Expression_t* ple, ppl_const_Linear_Expression_t le) try {
00434 const Linear_Expression& lle = *to_const(le);
00435 *ple = to_nonconst(new Linear_Expression(lle));
00436 return 0;
00437 }
00438 CATCH_ALL
00439
00440 int
00441 ppl_delete_Linear_Expression(ppl_const_Linear_Expression_t le) try {
00442 delete to_const(le);
00443 return 0;
00444 }
00445 CATCH_ALL
00446
00447 int
00448 ppl_assign_Linear_Expression_from_Linear_Expression
00449 (ppl_Linear_Expression_t dst, ppl_const_Linear_Expression_t src) try {
00450 const Linear_Expression& ssrc = *to_const(src);
00451 Linear_Expression& ddst = *to_nonconst(dst);
00452 ddst = ssrc;
00453 return 0;
00454 }
00455 CATCH_ALL
00456
00457 int
00458 ppl_Linear_Expression_add_to_coefficient(ppl_Linear_Expression_t le,
00459 ppl_dimension_type var,
00460 ppl_const_Coefficient_t n) try {
00461 Linear_Expression& lle = *to_nonconst(le);
00462 const Coefficient& nn = *to_const(n);
00463 lle += nn * Variable(var);
00464 return 0;
00465 }
00466 CATCH_ALL
00467
00468 int
00469 ppl_Linear_Expression_add_to_inhomogeneous(ppl_Linear_Expression_t le,
00470 ppl_const_Coefficient_t n) try {
00471 Linear_Expression& lle = *to_nonconst(le);
00472 const Coefficient& nn = *to_const(n);
00473 lle += nn;
00474 return 0;
00475 }
00476 CATCH_ALL
00477
00478 int
00479 ppl_add_Linear_Expression_to_Linear_Expression
00480 (ppl_Linear_Expression_t dst, ppl_const_Linear_Expression_t src) try {
00481 Linear_Expression& ddst = *to_nonconst(dst);
00482 const Linear_Expression& ssrc = *to_const(src);
00483 ddst += ssrc;
00484 return 0;
00485 }
00486 CATCH_ALL
00487
00488 int
00489 ppl_subtract_Linear_Expression_from_Linear_Expression
00490 (ppl_Linear_Expression_t dst, ppl_const_Linear_Expression_t src) try {
00491 Linear_Expression& ddst = *to_nonconst(dst);
00492 const Linear_Expression& ssrc = *to_const(src);
00493 ddst -= ssrc;
00494 return 0;
00495 }
00496 CATCH_ALL
00497
00498 int
00499 ppl_multiply_Linear_Expression_by_Coefficient(ppl_Linear_Expression_t le,
00500 ppl_const_Coefficient_t n) try {
00501 Linear_Expression& lle = *to_nonconst(le);
00502 const Coefficient& nn = *to_const(n);
00503 lle *= nn;
00504 return 0;
00505 }
00506 CATCH_ALL
00507
00508 int
00509 ppl_Linear_Expression_space_dimension(ppl_const_Linear_Expression_t le,
00510 ppl_dimension_type* m) try {
00511 *m = to_const(le)->space_dimension();
00512 return 0;
00513 }
00514 CATCH_ALL
00515
00516 int
00517 ppl_Linear_Expression_coefficient(ppl_const_Linear_Expression_t le,
00518 ppl_dimension_type var,
00519 ppl_Coefficient_t n) try {
00520 const Linear_Expression& lle = *to_const(le);
00521 Coefficient& nn = *to_nonconst(n);
00522 nn = lle.coefficient(Variable(var));
00523 return 0;
00524 }
00525 CATCH_ALL
00526
00527 int
00528 ppl_Linear_Expression_inhomogeneous_term(ppl_const_Linear_Expression_t le,
00529 ppl_Coefficient_t n) try {
00530 const Linear_Expression& lle = *to_const(le);
00531 Coefficient& nn = *to_nonconst(n);
00532 nn = lle.inhomogeneous_term();
00533 return 0;
00534 }
00535 CATCH_ALL
00536
00537 int
00538 ppl_Linear_Expression_OK(ppl_const_Linear_Expression_t ) try {
00539 return 1;
00540 }
00541 CATCH_ALL
00542
00543
00544 int
00545 ppl_new_Constraint(ppl_Constraint_t* pc,
00546 ppl_const_Linear_Expression_t le,
00547 enum ppl_enum_Constraint_Type t) try {
00548 Constraint* ppc;
00549 const Linear_Expression& lle = *to_const(le);
00550 switch (t) {
00551 case PPL_CONSTRAINT_TYPE_EQUAL:
00552 ppc = new Constraint(lle == 0);
00553 break;
00554 case PPL_CONSTRAINT_TYPE_GREATER_THAN_OR_EQUAL:
00555 ppc = new Constraint(lle >= 0);
00556 break;
00557 case PPL_CONSTRAINT_TYPE_GREATER_THAN:
00558 ppc = new Constraint(lle > 0);
00559 break;
00560 case PPL_CONSTRAINT_TYPE_LESS_THAN_OR_EQUAL:
00561 ppc = new Constraint(lle <= 0);
00562 break;
00563 case PPL_CONSTRAINT_TYPE_LESS_THAN:
00564 ppc = new Constraint(lle < 0);
00565 break;
00566 default:
00567 throw std::invalid_argument("ppl_new_Constraint(pc, le, t): "
00568 "t invalid");
00569 }
00570 *pc = to_nonconst(ppc);
00571 return 0;
00572 }
00573 CATCH_ALL
00574
00575 int
00576 ppl_new_Constraint_zero_dim_false(ppl_Constraint_t* pc) try {
00577 *pc = to_nonconst(new Constraint(Constraint::zero_dim_false()));
00578 return 0;
00579 }
00580 CATCH_ALL
00581
00582 int
00583 ppl_new_Constraint_zero_dim_positivity(ppl_Constraint_t* pc) try {
00584 *pc = to_nonconst(new Constraint(Constraint::zero_dim_positivity()));
00585 return 0;
00586 }
00587 CATCH_ALL
00588
00589 int
00590 ppl_new_Constraint_from_Constraint(ppl_Constraint_t* pc,
00591 ppl_const_Constraint_t c) try {
00592 const Constraint& cc = *to_const(c);
00593 *pc = to_nonconst(new Constraint(cc));
00594 return 0;
00595 }
00596 CATCH_ALL
00597
00598 int
00599 ppl_delete_Constraint(ppl_const_Constraint_t le) try {
00600 delete to_const(le);
00601 return 0;
00602 }
00603 CATCH_ALL
00604
00605 int
00606 ppl_assign_Constraint_from_Constraint(ppl_Constraint_t dst,
00607 ppl_const_Constraint_t src) try {
00608 const Constraint& ssrc = *to_const(src);
00609 Constraint& ddst = *to_nonconst(dst);
00610 ddst = ssrc;
00611 return 0;
00612 }
00613 CATCH_ALL
00614
00615 int
00616 ppl_Constraint_space_dimension(ppl_const_Constraint_t c,
00617 ppl_dimension_type* m) try {
00618 *m = to_const(c)->space_dimension();
00619 return 0;
00620 }
00621 CATCH_ALL
00622
00623 int
00624 ppl_Constraint_type(ppl_const_Constraint_t c) try {
00625 switch (to_const(c)->type()) {
00626 case Constraint::EQUALITY:
00627 return PPL_CONSTRAINT_TYPE_EQUAL;
00628 case Constraint::NONSTRICT_INEQUALITY:
00629 return PPL_CONSTRAINT_TYPE_GREATER_THAN_OR_EQUAL;
00630 case Constraint::STRICT_INEQUALITY:
00631 return PPL_CONSTRAINT_TYPE_GREATER_THAN;
00632 default:
00633 throw std::runtime_error("ppl_Constraint_type()");
00634 }
00635 }
00636 CATCH_ALL
00637
00638 int
00639 ppl_Constraint_coefficient(ppl_const_Constraint_t c,
00640 ppl_dimension_type var,
00641 ppl_Coefficient_t n) try {
00642 const Constraint& cc = *to_const(c);
00643 Coefficient& nn = *to_nonconst(n);
00644 nn = cc.coefficient(Variable(var));
00645 return 0;
00646 }
00647 CATCH_ALL
00648
00649 int
00650 ppl_Constraint_inhomogeneous_term(ppl_const_Constraint_t c,
00651 ppl_Coefficient_t n) try {
00652 const Constraint& cc = *to_const(c);
00653 Coefficient& nn = *to_nonconst(n);
00654 nn = cc.inhomogeneous_term();
00655 return 0;
00656 }
00657 CATCH_ALL
00658
00659 int
00660 ppl_Constraint_OK(ppl_const_Constraint_t ) try {
00661 return 1;
00662 }
00663 CATCH_ALL
00664
00665 int
00666 ppl_new_Linear_Expression_from_Constraint(ppl_Linear_Expression_t* ple,
00667 ppl_const_Constraint_t c) try {
00668 const Constraint& cc = *to_const(c);
00669 *ple = to_nonconst(new Linear_Expression(cc));
00670 return 0;
00671 }
00672 CATCH_ALL
00673
00674
00675 int
00676 ppl_new_Constraint_System(ppl_Constraint_System_t* pcs) try {
00677 *pcs = to_nonconst(new Constraint_System());
00678 return 0;
00679 }
00680 CATCH_ALL
00681
00682 int
00683 ppl_new_Constraint_System_zero_dim_empty(ppl_Constraint_System_t* pcs) try {
00684 *pcs = to_nonconst(new
00685 Constraint_System(Constraint_System::zero_dim_empty()));
00686 return 0;
00687 }
00688 CATCH_ALL
00689
00690
00691 int
00692 ppl_new_Constraint_System_from_Constraint(ppl_Constraint_System_t* pcs,
00693 ppl_const_Constraint_t c) try {
00694 const Constraint& cc = *to_const(c);
00695 *pcs = to_nonconst(new Constraint_System(cc));
00696 return 0;
00697 }
00698 CATCH_ALL
00699
00700 int
00701 ppl_new_Constraint_System_from_Constraint_System
00702 (ppl_Constraint_System_t* pcs, ppl_const_Constraint_System_t cs) try {
00703 const Constraint_System& ccs = *to_const(cs);
00704 *pcs = to_nonconst(new Constraint_System(ccs));
00705 return 0;
00706 }
00707 CATCH_ALL
00708
00709 int
00710 ppl_delete_Constraint_System(ppl_const_Constraint_System_t cs) try {
00711 delete to_const(cs);
00712 return 0;
00713 }
00714 CATCH_ALL
00715
00716 int
00717 ppl_assign_Constraint_System_from_Constraint_System
00718 (ppl_Constraint_System_t dst, ppl_const_Constraint_System_t src) try {
00719 const Constraint_System& ssrc = *to_const(src);
00720 Constraint_System& ddst = *to_nonconst(dst);
00721 ddst = ssrc;
00722 return 0;
00723 }
00724 CATCH_ALL
00725
00726 int
00727 ppl_Constraint_System_space_dimension(ppl_const_Constraint_System_t cs,
00728 ppl_dimension_type* m) try {
00729 *m = to_const(cs)->space_dimension();
00730 return 0;
00731 }
00732 CATCH_ALL
00733
00734 int
00735 ppl_Constraint_System_has_strict_inequalities
00736 (ppl_const_Constraint_System_t cs) try {
00737 const Constraint_System& ccs = *to_const(cs);
00738 return ccs.has_strict_inequalities() ? 1 : 0;
00739 }
00740 CATCH_ALL
00741
00742 int
00743 ppl_Constraint_System_clear(ppl_Constraint_System_t cs) try {
00744 to_nonconst(cs)->clear();
00745 return 0;
00746 }
00747 CATCH_ALL
00748
00749 int
00750 ppl_Constraint_System_insert_Constraint(ppl_Constraint_System_t cs,
00751 ppl_const_Constraint_t c) try {
00752 const Constraint& cc = *to_const(c);
00753 Constraint_System& ccs = *to_nonconst(cs);
00754 ccs.insert(cc);
00755 return 0;
00756 }
00757 CATCH_ALL
00758
00759 int
00760 ppl_Constraint_System_OK(ppl_const_Constraint_System_t cs) try {
00761 return to_const(cs)->OK() ? 1 : 0;
00762 }
00763 CATCH_ALL
00764
00765
00766 int
00767 ppl_new_Constraint_System_const_iterator
00768 (ppl_Constraint_System_const_iterator_t* pcit) try {
00769 *pcit = to_nonconst(new Constraint_System::const_iterator());
00770 return 0;
00771 }
00772 CATCH_ALL
00773
00774 int
00775 ppl_new_Constraint_System_const_iterator_from_Constraint_System_const_iterator
00776 (ppl_Constraint_System_const_iterator_t* pcit,
00777 ppl_const_Constraint_System_const_iterator_t cit) try {
00778 *pcit = to_nonconst(new Constraint_System::const_iterator(*to_const(cit)));
00779 return 0;
00780 }
00781 CATCH_ALL
00782
00783 int
00784 ppl_delete_Constraint_System_const_iterator
00785 (ppl_const_Constraint_System_const_iterator_t cit)
00786 try {
00787 delete to_const(cit);
00788 return 0;
00789 }
00790 CATCH_ALL
00791
00792 int
00793 ppl_assign_Constraint_System_const_iterator_from_Constraint_System_const_iterator
00794 (ppl_Constraint_System_const_iterator_t dst,
00795 ppl_const_Constraint_System_const_iterator_t src) try {
00796 const Constraint_System::const_iterator& ssrc = *to_const(src);
00797 Constraint_System::const_iterator& ddst = *to_nonconst(dst);
00798 ddst = ssrc;
00799 return 0;
00800 }
00801 CATCH_ALL
00802
00803 int
00804 ppl_Constraint_System_begin(ppl_const_Constraint_System_t cs,
00805 ppl_Constraint_System_const_iterator_t cit) try {
00806 const Constraint_System& ccs = *to_const(cs);
00807 Constraint_System::const_iterator& ccit = *to_nonconst(cit);
00808 ccit = ccs.begin();
00809 return 0;
00810 }
00811 CATCH_ALL
00812
00813 int
00814 ppl_Constraint_System_end(ppl_const_Constraint_System_t cs,
00815 ppl_Constraint_System_const_iterator_t cit) try {
00816 const Constraint_System& ccs = *to_const(cs);
00817 Constraint_System::const_iterator& ccit = *to_nonconst(cit);
00818 ccit = ccs.end();
00819 return 0;
00820 }
00821 CATCH_ALL
00822
00823 int
00824 ppl_Constraint_System_const_iterator_dereference
00825 (ppl_const_Constraint_System_const_iterator_t cit,
00826 ppl_const_Constraint_t* pc) try {
00827 const Constraint_System::const_iterator& ccit = *to_const(cit);
00828 const Constraint& c = *ccit;
00829 *pc = to_const(&c);
00830 return 0;
00831 }
00832 CATCH_ALL
00833
00834 int
00835 ppl_Constraint_System_const_iterator_increment
00836 (ppl_Constraint_System_const_iterator_t cit) try {
00837 Constraint_System::const_iterator& ccit = *to_nonconst(cit);
00838 ++ccit;
00839 return 0;
00840 }
00841 CATCH_ALL
00842
00843 int
00844 ppl_Constraint_System_const_iterator_equal_test
00845 (ppl_const_Constraint_System_const_iterator_t x,
00846 ppl_const_Constraint_System_const_iterator_t y) try {
00847 const Constraint_System::const_iterator& xx = *to_const(x);
00848 const Constraint_System::const_iterator& yy = *to_const(y);
00849 return (xx == yy) ? 1 : 0;
00850 }
00851 CATCH_ALL
00852
00853
00854 int
00855 ppl_new_Generator(ppl_Generator_t* pg,
00856 ppl_const_Linear_Expression_t le,
00857 enum ppl_enum_Generator_Type t,
00858 ppl_const_Coefficient_t d) try {
00859 Generator* ppg;
00860 const Linear_Expression& lle = *to_const(le);
00861 const Coefficient& dd = *to_const(d);
00862 switch (t) {
00863 case PPL_GENERATOR_TYPE_POINT:
00864 ppg = new Generator(Generator::point(lle, dd));
00865 break;
00866 case PPL_GENERATOR_TYPE_CLOSURE_POINT:
00867 ppg = new Generator(Generator::closure_point(lle, dd));
00868 break;
00869 case PPL_GENERATOR_TYPE_RAY:
00870 ppg = new Generator(Generator::ray(lle));
00871 break;
00872 case PPL_GENERATOR_TYPE_LINE:
00873 ppg = new Generator(Generator::line(lle));
00874 break;
00875 default:
00876 throw std::invalid_argument("ppl_new_Generator(pg, le, t, d): "
00877 "t invalid");
00878 }
00879 *pg = to_nonconst(ppg);
00880 return 0;
00881 }
00882 CATCH_ALL
00883
00884 int
00885 ppl_new_Generator_zero_dim_point(ppl_Generator_t* pg) try {
00886 *pg = to_nonconst(new Generator(Generator::zero_dim_point()));
00887 return 0;
00888 }
00889 CATCH_ALL
00890
00891 int
00892 ppl_new_Generator_zero_dim_closure_point(ppl_Generator_t* pg) try {
00893 *pg = to_nonconst(new Generator(Generator::zero_dim_closure_point()));
00894 return 0;
00895 }
00896 CATCH_ALL
00897
00898 int
00899 ppl_new_Generator_from_Generator(ppl_Generator_t* pg,
00900 ppl_const_Generator_t g) try {
00901 const Generator& gg = *to_const(g);
00902 *pg = to_nonconst(new Generator(gg));
00903 return 0;
00904 }
00905 CATCH_ALL
00906
00907 int
00908 ppl_delete_Generator(ppl_const_Generator_t le) try {
00909 delete to_const(le);
00910 return 0;
00911 }
00912 CATCH_ALL
00913
00914 int
00915 ppl_assign_Generator_from_Generator(ppl_Generator_t dst,
00916 ppl_const_Generator_t src) try {
00917 const Generator& ssrc = *to_const(src);
00918 Generator& ddst = *to_nonconst(dst);
00919 ddst = ssrc;
00920 return 0;
00921 }
00922 CATCH_ALL
00923
00924 int
00925 ppl_Generator_space_dimension(ppl_const_Generator_t g,
00926 ppl_dimension_type* m) try {
00927 *m = to_const(g)->space_dimension();
00928 return 0;
00929 }
00930 CATCH_ALL
00931
00932 int
00933 ppl_Generator_type(ppl_const_Generator_t g) try {
00934 switch (to_const(g)->type()) {
00935 case Generator::LINE:
00936 return PPL_GENERATOR_TYPE_LINE;
00937 case Generator::RAY:
00938 return PPL_GENERATOR_TYPE_RAY;
00939 case Generator::POINT:
00940 return PPL_GENERATOR_TYPE_POINT;
00941 case Generator::CLOSURE_POINT:
00942 return PPL_GENERATOR_TYPE_CLOSURE_POINT;
00943 default:
00944 throw std::runtime_error("ppl_Generator_type()");
00945 }
00946 }
00947 CATCH_ALL
00948
00949 int
00950 ppl_Generator_coefficient(ppl_const_Generator_t g,
00951 ppl_dimension_type var,
00952 ppl_Coefficient_t n) try {
00953 const Generator& gg = *to_const(g);
00954 Coefficient& nn = *to_nonconst(n);
00955 nn = gg.coefficient(Variable(var));
00956 return 0;
00957 }
00958 CATCH_ALL
00959
00960 int
00961 ppl_Generator_divisor(ppl_const_Generator_t g,
00962 ppl_Coefficient_t n) try {
00963 const Generator& gg = *to_const(g);
00964 Coefficient& nn = *to_nonconst(n);
00965 nn = gg.divisor();
00966 return 0;
00967 }
00968 CATCH_ALL
00969
00970 int
00971 ppl_Generator_OK(ppl_const_Generator_t ) try {
00972 return 1;
00973 }
00974 CATCH_ALL
00975
00976 int
00977 ppl_new_Linear_Expression_from_Generator(ppl_Linear_Expression_t* ple,
00978 ppl_const_Generator_t g) try {
00979 const Generator& gg = *to_const(g);
00980 *ple = to_nonconst(new Linear_Expression(gg));
00981 return 0;
00982 }
00983 CATCH_ALL
00984
00985
00986 int
00987 ppl_new_Generator_System(ppl_Generator_System_t* pgs) try {
00988 *pgs = to_nonconst(new Generator_System());
00989 return 0;
00990 }
00991 CATCH_ALL
00992
00993 int
00994 ppl_new_Generator_System_zero_dim_univ(ppl_Generator_System_t* pgs) try {
00995 *pgs = to_nonconst(new Generator_System(Generator_System::zero_dim_univ()));
00996 return 0;
00997 }
00998 CATCH_ALL
00999
01000 int
01001 ppl_new_Generator_System_from_Generator(ppl_Generator_System_t* pgs,
01002 ppl_const_Generator_t g) try {
01003 const Generator& gg = *to_const(g);
01004 *pgs = to_nonconst(new Generator_System(gg));
01005 return 0;
01006 }
01007 CATCH_ALL
01008
01009 int
01010 ppl_new_Generator_System_from_Generator_System
01011 (ppl_Generator_System_t* pgs, ppl_const_Generator_System_t gs) try {
01012 const Generator_System& ggs = *to_const(gs);
01013 *pgs = to_nonconst(new Generator_System(ggs));
01014 return 0;
01015 }
01016 CATCH_ALL
01017
01018 int
01019 ppl_delete_Generator_System(ppl_const_Generator_System_t gs) try {
01020 delete to_const(gs);
01021 return 0;
01022 }
01023 CATCH_ALL
01024
01025 int
01026 ppl_assign_Generator_System_from_Generator_System
01027 (ppl_Generator_System_t dst, ppl_const_Generator_System_t src) try {
01028 const Generator_System& ssrc = *to_const(src);
01029 Generator_System& ddst = *to_nonconst(dst);
01030 ddst = ssrc;
01031 return 0;
01032 }
01033 CATCH_ALL
01034
01035 int
01036 ppl_Generator_System_space_dimension(ppl_const_Generator_System_t gs,
01037 ppl_dimension_type* m) try {
01038 *m = to_const(gs)->space_dimension();
01039 return 0;
01040 }
01041 CATCH_ALL
01042
01043 int
01044 ppl_Generator_System_clear(ppl_Generator_System_t gs) try {
01045 to_nonconst(gs)->clear();
01046 return 0;
01047 }
01048 CATCH_ALL
01049
01050 int
01051 ppl_Generator_System_insert_Generator(ppl_Generator_System_t gs,
01052 ppl_const_Generator_t g) try {
01053 const Generator& gg = *to_const(g);
01054 Generator_System& ggs = *to_nonconst(gs);
01055 ggs.insert(gg);
01056 return 0;
01057 }
01058 CATCH_ALL
01059
01060 int
01061 ppl_Generator_System_OK(ppl_const_Generator_System_t gs) try {
01062 return to_const(gs)->OK() ? 1 : 0;
01063 }
01064 CATCH_ALL
01065
01066
01067 int
01068 ppl_new_Generator_System_const_iterator
01069 (ppl_Generator_System_const_iterator_t* pgit) try {
01070 *pgit = to_nonconst(new Generator_System::const_iterator());
01071 return 0;
01072 }
01073 CATCH_ALL
01074
01075 int
01076 ppl_new_Generator_System_const_iterator_from_Generator_System_const_iterator
01077 (ppl_Generator_System_const_iterator_t* pgit,
01078 ppl_const_Generator_System_const_iterator_t git) try {
01079 *pgit = to_nonconst(new Generator_System::const_iterator(*to_const(git)));
01080 return 0;
01081 }
01082 CATCH_ALL
01083
01084 int
01085 ppl_delete_Generator_System_const_iterator
01086 (ppl_const_Generator_System_const_iterator_t git) try {
01087 delete to_const(git);
01088 return 0;
01089 }
01090 CATCH_ALL
01091
01092 int
01093 ppl_assign_Generator_System_const_iterator_from_Generator_System_const_iterator
01094 (ppl_Generator_System_const_iterator_t dst,
01095 ppl_const_Generator_System_const_iterator_t src) try {
01096 const Generator_System::const_iterator& ssrc = *to_const(src);
01097 Generator_System::const_iterator& ddst = *to_nonconst(dst);
01098 ddst = ssrc;
01099 return 0;
01100 }
01101 CATCH_ALL
01102
01103 int
01104 ppl_Generator_System_begin(ppl_const_Generator_System_t gs,
01105 ppl_Generator_System_const_iterator_t git) try {
01106 const Generator_System& ggs = *to_const(gs);
01107 Generator_System::const_iterator& ggit = *to_nonconst(git);
01108 ggit = ggs.begin();
01109 return 0;
01110 }
01111 CATCH_ALL
01112
01113 int
01114 ppl_Generator_System_end(ppl_const_Generator_System_t gs,
01115 ppl_Generator_System_const_iterator_t git) try {
01116 const Generator_System& ggs = *to_const(gs);
01117 Generator_System::const_iterator& ggit = *to_nonconst(git);
01118 ggit = ggs.end();
01119 return 0;
01120 }
01121 CATCH_ALL
01122
01123 int
01124 ppl_Generator_System_const_iterator_dereference
01125 (ppl_const_Generator_System_const_iterator_t git,
01126 ppl_const_Generator_t* pg) try {
01127 const Generator_System::const_iterator& ggit = *to_const(git);
01128 const Generator& c = *ggit;
01129 *pg = to_const(&c);
01130 return 0;
01131 }
01132 CATCH_ALL
01133
01134 int
01135 ppl_Generator_System_const_iterator_increment
01136 (ppl_Generator_System_const_iterator_t git) try {
01137 Generator_System::const_iterator& ggit = *to_nonconst(git);
01138 ++ggit;
01139 return 0;
01140 }
01141 CATCH_ALL
01142
01143 int
01144 ppl_Generator_System_const_iterator_equal_test
01145 (ppl_const_Generator_System_const_iterator_t x,
01146 ppl_const_Generator_System_const_iterator_t y) try {
01147 const Generator_System::const_iterator& xx = *to_const(x);
01148 const Generator_System::const_iterator& yy = *to_const(y);
01149 return (xx == yy) ? 1 : 0;
01150 }
01151 CATCH_ALL
01152
01153
01154 int
01155 ppl_new_C_Polyhedron_from_dimension(ppl_Polyhedron_t* pph,
01156 ppl_dimension_type d) try {
01157 *pph = to_nonconst(new C_Polyhedron(d, UNIVERSE));
01158 return 0;
01159 }
01160 CATCH_ALL
01161
01162 int
01163 ppl_new_NNC_Polyhedron_from_dimension(ppl_Polyhedron_t* pph,
01164 ppl_dimension_type d) try {
01165 *pph = to_nonconst(new NNC_Polyhedron(d, UNIVERSE));
01166 return 0;
01167 }
01168 CATCH_ALL
01169
01170 int
01171 ppl_new_C_Polyhedron_empty_from_dimension(ppl_Polyhedron_t* pph,
01172 ppl_dimension_type d) try {
01173 *pph = to_nonconst(new C_Polyhedron(d, EMPTY));
01174 return 0;
01175 }
01176 CATCH_ALL
01177
01178 int
01179 ppl_new_NNC_Polyhedron_empty_from_dimension(ppl_Polyhedron_t* pph,
01180 ppl_dimension_type d) try {
01181 *pph = to_nonconst(new NNC_Polyhedron(d, EMPTY));
01182 return 0;
01183 }
01184 CATCH_ALL
01185
01186 int
01187 ppl_new_C_Polyhedron_from_C_Polyhedron(ppl_Polyhedron_t* pph,
01188 ppl_const_Polyhedron_t ph) try {
01189 const C_Polyhedron& phh = *static_cast<const C_Polyhedron*>(to_const(ph));
01190 *pph = to_nonconst(new C_Polyhedron(phh));
01191 return 0;
01192 }
01193 CATCH_ALL
01194
01195 int
01196 ppl_new_C_Polyhedron_from_NNC_Polyhedron(ppl_Polyhedron_t* pph,
01197 ppl_const_Polyhedron_t ph) try {
01198 const NNC_Polyhedron& phh
01199 = *static_cast<const NNC_Polyhedron*>(to_const(ph));
01200 *pph = to_nonconst(new C_Polyhedron(phh));
01201 return 0;
01202 }
01203 CATCH_ALL
01204
01205 int
01206 ppl_new_NNC_Polyhedron_from_C_Polyhedron(ppl_Polyhedron_t* pph,
01207 ppl_const_Polyhedron_t ph) try {
01208 const C_Polyhedron& phh = *static_cast<const C_Polyhedron*>(to_const(ph));
01209 *pph = to_nonconst(new NNC_Polyhedron(phh));
01210 return 0;
01211 }
01212 CATCH_ALL
01213
01214 int
01215 ppl_new_NNC_Polyhedron_from_NNC_Polyhedron(ppl_Polyhedron_t* pph,
01216 ppl_const_Polyhedron_t ph) try {
01217 const NNC_Polyhedron& phh
01218 = *static_cast<const NNC_Polyhedron*>(to_const(ph));
01219 *pph = to_nonconst(new NNC_Polyhedron(phh));
01220 return 0;
01221 }
01222 CATCH_ALL
01223
01224 int
01225 ppl_new_C_Polyhedron_from_Constraint_System
01226 (ppl_Polyhedron_t* pph, ppl_const_Constraint_System_t cs) try {
01227 const Constraint_System& ccs = *to_const(cs);
01228 *pph = to_nonconst(new C_Polyhedron(ccs));
01229 return 0;
01230 }
01231 CATCH_ALL
01232
01233 int
01234 ppl_new_C_Polyhedron_recycle_Constraint_System
01235 (ppl_Polyhedron_t* pph, ppl_Constraint_System_t cs) try {
01236 Constraint_System& ccs = *to_nonconst(cs);
01237 *pph = to_nonconst(new C_Polyhedron(ccs));
01238 return 0;
01239 }
01240 CATCH_ALL
01241
01242 int
01243 ppl_new_NNC_Polyhedron_from_Constraint_System
01244 (ppl_Polyhedron_t* pph, ppl_const_Constraint_System_t cs) try {
01245 const Constraint_System& ccs = *to_const(cs);
01246 *pph = to_nonconst(new NNC_Polyhedron(ccs));
01247 return 0;
01248 }
01249 CATCH_ALL
01250
01251 int
01252 ppl_new_NNC_Polyhedron_recycle_Constraint_System
01253 (ppl_Polyhedron_t* pph, ppl_Constraint_System_t cs) try {
01254 Constraint_System& ccs = *to_nonconst(cs);
01255 *pph = to_nonconst(new NNC_Polyhedron(ccs));
01256 return 0;
01257 }
01258 CATCH_ALL
01259
01260 int
01261 ppl_new_C_Polyhedron_from_Generator_System
01262 (ppl_Polyhedron_t* pph, ppl_const_Generator_System_t gs) try {
01263 const Generator_System& ggs = *to_const(gs);
01264 *pph = to_nonconst(new C_Polyhedron(ggs));
01265 return 0;
01266 }
01267 CATCH_ALL
01268
01269 int
01270 ppl_new_C_Polyhedron_recycle_Generator_System(ppl_Polyhedron_t* pph,
01271 ppl_Generator_System_t gs) try {
01272 Generator_System& ggs = *to_nonconst(gs);
01273 *pph = to_nonconst(new C_Polyhedron(ggs));
01274 return 0;
01275 }
01276 CATCH_ALL
01277
01278 int
01279 ppl_new_NNC_Polyhedron_from_Generator_System
01280 (ppl_Polyhedron_t* pph, ppl_const_Generator_System_t gs) try {
01281 const Generator_System& ggs = *to_const(gs);
01282 *pph = to_nonconst(new C_Polyhedron(ggs));
01283 return 0;
01284 }
01285 CATCH_ALL
01286
01287 int
01288 ppl_new_NNC_Polyhedron_recycle_Generator_System
01289 (ppl_Polyhedron_t* pph, ppl_Generator_System_t gs) try {
01290 Generator_System& ggs = *to_nonconst(gs);
01291 *pph = to_nonconst(new C_Polyhedron(ggs));
01292 return 0;
01293 }
01294 CATCH_ALL
01295
01296 namespace {
01297
01298 class C_Build_Box {
01299 private:
01300 ppl_dimension_type (*s_d)(void);
01301 int (*i_e)(void);
01302 int (*g_l_b)(ppl_dimension_type k, int closed,
01303 ppl_Coefficient_t n,
01304 ppl_Coefficient_t d);
01305 int (*g_u_b)(ppl_dimension_type k, int closed,
01306 ppl_Coefficient_t n,
01307 ppl_Coefficient_t d);
01308
01309 public:
01310 C_Build_Box(ppl_dimension_type (*sd)(void),
01311 int (*ie)(void),
01312 int (*glb)(ppl_dimension_type k, int closed,
01313 ppl_Coefficient_t n,
01314 ppl_Coefficient_t d),
01315 int (*gub)(ppl_dimension_type k, int closed,
01316 ppl_Coefficient_t n,
01317 ppl_Coefficient_t d))
01318 : s_d(sd), i_e(ie), g_l_b(glb), g_u_b(gub) {
01319 }
01320
01321 ppl_dimension_type space_dimension() const {
01322 return s_d();
01323 }
01324
01325 bool is_empty(void) const {
01326 return i_e() != 0;
01327 }
01328
01329 bool get_lower_bound(ppl_dimension_type k, bool closed,
01330 Coefficient& n, Coefficient& d) const {
01331 return g_l_b(k, closed, to_nonconst(&n), to_nonconst(&d)) != 0;
01332 }
01333
01334 bool get_upper_bound(ppl_dimension_type k, bool closed,
01335 Coefficient& n, Coefficient& d) const {
01336 return g_u_b(k, closed, to_nonconst(&n), to_nonconst(&d)) != 0;
01337 }
01338 };
01339
01340 }
01341
01342 int
01343 ppl_new_C_Polyhedron_from_bounding_box
01344 (ppl_Polyhedron_t* pph,
01345 ppl_dimension_type (*space_dimension)(void),
01346 int (*is_empty)(void),
01347 int (*get_lower_bound)(ppl_dimension_type k, int closed,
01348 ppl_Coefficient_t n,
01349 ppl_Coefficient_t d),
01350 int (*get_upper_bound)(ppl_dimension_type k, int closed,
01351 ppl_Coefficient_t n,
01352 ppl_Coefficient_t d)) try {
01353 C_Build_Box cbbox(space_dimension, is_empty,
01354 get_lower_bound, get_upper_bound);
01355 *pph = to_nonconst(new C_Polyhedron(cbbox, From_Bounding_Box()));
01356 return 0;
01357 }
01358 CATCH_ALL
01359
01360 int
01361 ppl_new_NNC_Polyhedron_from_bounding_box
01362 (ppl_Polyhedron_t* pph,
01363 ppl_dimension_type (*space_dimension)(void),
01364 int (*is_empty)(void),
01365 int (*get_lower_bound)(ppl_dimension_type k, int closed,
01366 ppl_Coefficient_t n,
01367 ppl_Coefficient_t d),
01368 int (*get_upper_bound)(ppl_dimension_type k, int closed,
01369 ppl_Coefficient_t n,
01370 ppl_Coefficient_t d)) try {
01371 C_Build_Box cbbox(space_dimension, is_empty,
01372 get_lower_bound, get_upper_bound);
01373 *pph = to_nonconst(new NNC_Polyhedron(cbbox, From_Bounding_Box()));
01374 return 0;
01375 }
01376 CATCH_ALL
01377
01378 int
01379 ppl_delete_Polyhedron(ppl_const_Polyhedron_t ph) try {
01380 delete to_const(ph);
01381 return 0;
01382 }
01383 CATCH_ALL
01384
01385 int
01386 ppl_assign_C_Polyhedron_from_C_Polyhedron(ppl_Polyhedron_t dst,
01387 ppl_const_Polyhedron_t src) try {
01388 const C_Polyhedron& ssrc
01389 = *static_cast<const C_Polyhedron*>(to_const(src));
01390 C_Polyhedron& ddst = *static_cast<C_Polyhedron*>(to_nonconst(dst));
01391 ddst = ssrc;
01392 return 0;
01393 }
01394 CATCH_ALL
01395
01396 int
01397 ppl_assign_NNC_Polyhedron_from_NNC_Polyhedron(ppl_Polyhedron_t dst,
01398 ppl_const_Polyhedron_t src) try {
01399 const NNC_Polyhedron& ssrc
01400 = *static_cast<const NNC_Polyhedron*>(to_const(src));
01401 NNC_Polyhedron& ddst = *static_cast<NNC_Polyhedron*>(to_nonconst(dst));
01402 ddst = ssrc;
01403 return 0;
01404 }
01405 CATCH_ALL
01406
01407 int
01408 ppl_Polyhedron_space_dimension(ppl_const_Polyhedron_t ph,
01409 ppl_dimension_type* m) try {
01410 *m = to_const(ph)->space_dimension();
01411 return 0;
01412 }
01413 CATCH_ALL
01414
01415 int
01416 ppl_Polyhedron_affine_dimension(ppl_const_Polyhedron_t ph,
01417 ppl_dimension_type* m) try {
01418 *m = to_const(ph)->affine_dimension();
01419 return 0;
01420 }
01421 CATCH_ALL
01422
01423 int
01424 ppl_Polyhedron_intersection_assign(ppl_Polyhedron_t x,
01425 ppl_const_Polyhedron_t y) try {
01426 Polyhedron& xx = *to_nonconst(x);
01427 const Polyhedron& yy = *to_const(y);
01428 xx.intersection_assign(yy);
01429 return 0;
01430 }
01431 CATCH_ALL
01432
01433 int
01434 ppl_Polyhedron_intersection_assign_and_minimize(ppl_Polyhedron_t x,
01435 ppl_const_Polyhedron_t y) try {
01436 Polyhedron& xx = *to_nonconst(x);
01437 const Polyhedron& yy = *to_const(y);
01438 return xx.intersection_assign_and_minimize(yy) ? 1 : 0;
01439 }
01440 CATCH_ALL
01441
01442 int
01443 ppl_Polyhedron_concatenate_assign(ppl_Polyhedron_t x,
01444 ppl_const_Polyhedron_t y) try {
01445 Polyhedron& xx = *to_nonconst(x);
01446 const Polyhedron& yy = *to_const(y);
01447 xx.concatenate_assign(yy);
01448 return 0;
01449 }
01450 CATCH_ALL
01451
01452 int
01453 ppl_Polyhedron_poly_hull_assign(ppl_Polyhedron_t x,
01454 ppl_const_Polyhedron_t y) try {
01455 Polyhedron& xx = *to_nonconst(x);
01456 const Polyhedron& yy = *to_const(y);
01457 xx.poly_hull_assign(yy);
01458 return 0;
01459 }
01460 CATCH_ALL
01461
01462 int
01463 ppl_Polyhedron_poly_hull_assign_and_minimize(ppl_Polyhedron_t x,
01464 ppl_const_Polyhedron_t y) try {
01465 Polyhedron& xx = *to_nonconst(x);
01466 const Polyhedron& yy = *to_const(y);
01467 return xx.poly_hull_assign_and_minimize(yy) ? 1 : 0;
01468 }
01469 CATCH_ALL
01470
01471 int
01472 ppl_Polyhedron_poly_difference_assign(ppl_Polyhedron_t x,
01473 ppl_const_Polyhedron_t y) try {
01474 Polyhedron& xx = *to_nonconst(x);
01475 const Polyhedron& yy = *to_const(y);
01476 xx.poly_difference_assign(yy);
01477 return 0;
01478 }
01479 CATCH_ALL
01480
01481 int
01482 ppl_Polyhedron_BHRZ03_widening_assign_with_tokens(ppl_Polyhedron_t x,
01483 ppl_const_Polyhedron_t y,
01484 unsigned* tp) try {
01485 Polyhedron& xx = *to_nonconst(x);
01486 const Polyhedron& yy = *to_const(y);
01487 xx.BHRZ03_widening_assign(yy, tp);
01488 return 0;
01489 }
01490 CATCH_ALL
01491
01492 int
01493 ppl_Polyhedron_BHRZ03_widening_assign(ppl_Polyhedron_t x,
01494 ppl_const_Polyhedron_t y) try {
01495 return ppl_Polyhedron_BHRZ03_widening_assign_with_tokens(x, y, 0);
01496 }
01497 CATCH_ALL
01498
01499 int
01500 ppl_Polyhedron_limited_BHRZ03_extrapolation_assign_with_tokens
01501 (ppl_Polyhedron_t x,
01502 ppl_const_Polyhedron_t y,
01503 ppl_const_Constraint_System_t cs,
01504 unsigned* tp) try {
01505 Polyhedron& xx = *to_nonconst(x);
01506 const Polyhedron& yy = *to_const(y);
01507 const Constraint_System& ccs = *to_const(cs);
01508 xx.limited_BHRZ03_extrapolation_assign(yy, ccs, tp);
01509 return 0;
01510 }
01511 CATCH_ALL
01512
01513 int
01514 ppl_Polyhedron_limited_BHRZ03_extrapolation_assign
01515 (ppl_Polyhedron_t x,
01516 ppl_const_Polyhedron_t y,
01517 ppl_const_Constraint_System_t cs) try {
01518 return ppl_Polyhedron_limited_BHRZ03_extrapolation_assign_with_tokens(x, y,
01519 cs, 0);
01520 }
01521 CATCH_ALL
01522
01523 int
01524 ppl_Polyhedron_bounded_BHRZ03_extrapolation_assign_with_tokens
01525 (ppl_Polyhedron_t x,
01526 ppl_const_Polyhedron_t y,
01527 ppl_const_Constraint_System_t cs,
01528 unsigned* tp) try {
01529 Polyhedron& xx = *to_nonconst(x);
01530 const Polyhedron& yy = *to_const(y);
01531 const Constraint_System& ccs = *to_const(cs);
01532 xx.bounded_BHRZ03_extrapolation_assign(yy, ccs, tp);
01533 return 0;
01534 }
01535 CATCH_ALL
01536
01537 int
01538 ppl_Polyhedron_bounded_BHRZ03_extrapolation_assign
01539 (ppl_Polyhedron_t x,
01540 ppl_const_Polyhedron_t y,
01541 ppl_const_Constraint_System_t cs) try {
01542 return ppl_Polyhedron_bounded_BHRZ03_extrapolation_assign_with_tokens(x, y,
01543 cs, 0);
01544 }
01545 CATCH_ALL
01546
01547 int
01548 ppl_Polyhedron_H79_widening_assign_with_tokens(ppl_Polyhedron_t x,
01549 ppl_const_Polyhedron_t y,
01550 unsigned* tp) try {
01551 Polyhedron& xx = *to_nonconst(x);
01552 const Polyhedron& yy = *to_const(y);
01553 xx.H79_widening_assign(yy, tp);
01554 return 0;
01555 }
01556 CATCH_ALL
01557
01558 int
01559 ppl_Polyhedron_H79_widening_assign(ppl_Polyhedron_t x,
01560 ppl_const_Polyhedron_t y) try {
01561 return ppl_Polyhedron_H79_widening_assign_with_tokens(x, y, 0);
01562 }
01563 CATCH_ALL
01564
01565 int
01566 ppl_Polyhedron_limited_H79_extrapolation_assign_with_tokens
01567 (ppl_Polyhedron_t x,
01568 ppl_const_Polyhedron_t y,
01569 ppl_const_Constraint_System_t cs,
01570 unsigned* tp) try {
01571 Polyhedron& xx = *to_nonconst(x);
01572 const Polyhedron& yy = *to_const(y);
01573 const Constraint_System& ccs = *to_const(cs);
01574 xx.limited_H79_extrapolation_assign(yy, ccs, tp);
01575 return 0;
01576 }
01577 CATCH_ALL
01578
01579 int
01580 ppl_Polyhedron_limited_H79_extrapolation_assign
01581 (ppl_Polyhedron_t x,
01582 ppl_const_Polyhedron_t y,
01583 ppl_const_Constraint_System_t cs) try {
01584 return ppl_Polyhedron_limited_H79_extrapolation_assign_with_tokens(x, y,
01585 cs, 0);
01586 }
01587 CATCH_ALL
01588
01589 int
01590 ppl_Polyhedron_bounded_H79_extrapolation_assign_with_tokens
01591 (ppl_Polyhedron_t x,
01592 ppl_const_Polyhedron_t y,
01593 ppl_const_Constraint_System_t cs,
01594 unsigned* tp) try {
01595 Polyhedron& xx = *to_nonconst(x);
01596 const Polyhedron& yy = *to_const(y);
01597 const Constraint_System& ccs = *to_const(cs);
01598 xx.bounded_H79_extrapolation_assign(yy, ccs, tp);
01599 return 0;
01600 }
01601 CATCH_ALL
01602
01603 int
01604 ppl_Polyhedron_bounded_H79_extrapolation_assign
01605 (ppl_Polyhedron_t x,
01606 ppl_const_Polyhedron_t y,
01607 ppl_const_Constraint_System_t cs) try {
01608 return ppl_Polyhedron_bounded_H79_extrapolation_assign_with_tokens(x, y,
01609 cs, 0);
01610 }
01611 CATCH_ALL
01612
01613 int
01614 ppl_Polyhedron_time_elapse_assign(ppl_Polyhedron_t x,
01615 ppl_const_Polyhedron_t y) try {
01616 Polyhedron& xx = *to_nonconst(x);
01617 const Polyhedron& yy = *to_const(y);
01618 xx.time_elapse_assign(yy);
01619 return 0;
01620 }
01621 CATCH_ALL
01622
01623 int
01624 ppl_Polyhedron_constraints(ppl_const_Polyhedron_t ph,
01625 ppl_const_Constraint_System_t* pcs) try {
01626 const Polyhedron& pph = *to_const(ph);
01627 const Constraint_System& cs = pph.constraints();
01628 *pcs = to_const(&cs);
01629 return 0;
01630 }
01631 CATCH_ALL
01632
01633 int
01634 ppl_Polyhedron_minimized_constraints(ppl_const_Polyhedron_t ph,
01635 ppl_const_Constraint_System_t* pcs) try {
01636 const Polyhedron& pph = *to_const(ph);
01637 const Constraint_System& cs = pph.minimized_constraints();
01638 *pcs = to_const(&cs);
01639 return 0;
01640 }
01641 CATCH_ALL
01642
01643 int
01644 ppl_Polyhedron_generators(ppl_const_Polyhedron_t ph,
01645 ppl_const_Generator_System_t* pgs) try {
01646 const Polyhedron& pph = *to_const(ph);
01647 const Generator_System& gs = pph.generators();
01648 *pgs = to_const(&gs);
01649 return 0;
01650 }
01651 CATCH_ALL
01652
01653 int
01654 ppl_Polyhedron_minimized_generators(ppl_const_Polyhedron_t ph,
01655 ppl_const_Generator_System_t* pgs) try {
01656 const Polyhedron& pph = *to_const(ph);
01657 const Generator_System& gs = pph.minimized_generators();
01658 *pgs = to_const(&gs);
01659 return 0;
01660 }
01661 CATCH_ALL
01662
01663 int
01664 ppl_Polyhedron_add_constraint(ppl_Polyhedron_t ph,
01665 ppl_const_Constraint_t c) try {
01666 Polyhedron& pph = *to_nonconst(ph);
01667 const Constraint& cc = *to_const(c);
01668 pph.add_constraint(cc);
01669 return 0;
01670 }
01671 CATCH_ALL
01672
01673 int
01674 ppl_Polyhedron_add_constraint_and_minimize(ppl_Polyhedron_t ph,
01675 ppl_const_Constraint_t c) try {
01676 Polyhedron& pph = *to_nonconst(ph);
01677 const Constraint& cc = *to_const(c);
01678 pph.add_constraint_and_minimize(cc);
01679 return 0;
01680 }
01681 CATCH_ALL
01682
01683 int
01684 ppl_Polyhedron_add_generator(ppl_Polyhedron_t ph,
01685 ppl_const_Generator_t g) try {
01686 Polyhedron& pph = *to_nonconst(ph);
01687 const Generator& gg = *to_const(g);
01688 pph.add_generator(gg);
01689 return 0;
01690 }
01691 CATCH_ALL
01692
01693 int
01694 ppl_Polyhedron_add_generator_and_minimize(ppl_Polyhedron_t ph,
01695 ppl_const_Generator_t g) try {
01696 Polyhedron& pph = *to_nonconst(ph);
01697 const Generator& gg = *to_const(g);
01698 pph.add_generator_and_minimize(gg);
01699 return 0;
01700 }
01701 CATCH_ALL
01702
01703 int
01704 ppl_Polyhedron_add_constraints(ppl_Polyhedron_t ph,
01705 ppl_const_Constraint_System_t cs) try {
01706 Polyhedron& pph = *to_nonconst(ph);
01707 const Constraint_System& ccs = *to_const(cs);
01708 pph.add_constraints(ccs);
01709 return 0;
01710 }
01711 CATCH_ALL
01712
01713 int
01714 ppl_Polyhedron_add_constraints_and_minimize
01715 (ppl_Polyhedron_t ph, ppl_const_Constraint_System_t cs) try {
01716 Polyhedron& pph = *to_nonconst(ph);
01717 const Constraint_System& ccs = *to_const(cs);
01718 return pph.add_constraints_and_minimize(ccs) ? 1 : 0;
01719 }
01720 CATCH_ALL
01721
01722 int
01723 ppl_Polyhedron_add_generators(ppl_Polyhedron_t ph,
01724 ppl_const_Generator_System_t gs) try {
01725 Polyhedron& pph = *to_nonconst(ph);
01726 const Generator_System& ggs = *to_const(gs);
01727 pph.add_generators(ggs);
01728 return 0;
01729 }
01730 CATCH_ALL
01731
01732 int
01733 ppl_Polyhedron_add_generators_and_minimize
01734 (ppl_Polyhedron_t ph, ppl_const_Generator_System_t gs) try {
01735 Polyhedron& pph = *to_nonconst(ph);
01736 const Generator_System& ggs = *to_const(gs);
01737 return pph.add_generators_and_minimize(ggs) ? 1 : 0;
01738 }
01739 CATCH_ALL
01740
01741 int
01742 ppl_Polyhedron_add_recycled_constraints(ppl_Polyhedron_t ph,
01743 ppl_Constraint_System_t cs) try {
01744 Polyhedron& pph = *to_nonconst(ph);
01745 Constraint_System& ccs = *to_nonconst(cs);
01746 pph.add_recycled_constraints(ccs);
01747 return 0;
01748 }
01749 CATCH_ALL
01750
01751 int
01752 ppl_Polyhedron_add_recycled_constraints_and_minimize
01753 (ppl_Polyhedron_t ph, ppl_Constraint_System_t cs) try {
01754 Polyhedron& pph = *to_nonconst(ph);
01755 Constraint_System& ccs = *to_nonconst(cs);
01756 return pph.add_recycled_constraints_and_minimize(ccs) ? 1 : 0;
01757 }
01758 CATCH_ALL
01759
01760 int
01761 ppl_Polyhedron_add_recycled_generators(ppl_Polyhedron_t ph,
01762 ppl_Generator_System_t gs) try {
01763 Polyhedron& pph = *to_nonconst(ph);
01764 Generator_System& ggs = *to_nonconst(gs);
01765 pph.add_recycled_generators(ggs);
01766 return 0;
01767 }
01768 CATCH_ALL
01769
01770 int
01771 ppl_Polyhedron_add_recycled_generators_and_minimize(ppl_Polyhedron_t ph,
01772 ppl_Generator_System_t gs)
01773 try {
01774 Polyhedron& pph = *to_nonconst(ph);
01775 Generator_System& ggs = *to_nonconst(gs);
01776 return pph.add_recycled_generators_and_minimize(ggs) ? 1 : 0;
01777 }
01778 CATCH_ALL
01779
01780 int
01781 ppl_Polyhedron_add_space_dimensions_and_embed(ppl_Polyhedron_t ph,
01782 ppl_dimension_type d) try {
01783 Polyhedron& pph = *to_nonconst(ph);
01784 pph.add_space_dimensions_and_embed(d);
01785 return 0;
01786 }
01787 CATCH_ALL
01788
01789 int
01790 ppl_Polyhedron_add_space_dimensions_and_project(ppl_Polyhedron_t ph,
01791 ppl_dimension_type d) try {
01792 Polyhedron& pph = *to_nonconst(ph);
01793 pph.add_space_dimensions_and_project(d);
01794 return 0;
01795 }
01796 CATCH_ALL
01797
01798 int
01799 ppl_Polyhedron_remove_space_dimensions(ppl_Polyhedron_t ph,
01800 ppl_dimension_type ds[],
01801 size_t n) try {
01802 Polyhedron& pph = *to_nonconst(ph);
01803 Variables_Set to_be_removed;
01804 for (ppl_dimension_type i = n; i-- > 0; )
01805 to_be_removed.insert(Variable(ds[i]));
01806 pph.remove_space_dimensions(to_be_removed);
01807 return 0;
01808 }
01809 CATCH_ALL
01810
01811 int
01812 ppl_Polyhedron_remove_higher_space_dimensions(ppl_Polyhedron_t ph,
01813 ppl_dimension_type d) try {
01814 Polyhedron& pph = *to_nonconst(ph);
01815 pph.remove_higher_space_dimensions(d);
01816 return 0;
01817 }
01818 CATCH_ALL
01819
01820 namespace {
01821
01822 class PIFunc {
01823 private:
01825 dimension_type* vec;
01826
01828 size_t vec_size;
01829
01831 mutable dimension_type max_in_codomain_;
01832
01835 mutable int empty;
01836
01837 public:
01838 PIFunc(dimension_type* v, size_t n)
01839 : vec(v), vec_size(n), max_in_codomain_(not_a_dimension()), empty(-1) {
01840 }
01841
01842 bool has_empty_codomain() const {
01843 if (empty < 0) {
01844 empty = 1;
01845 for (size_t i = vec_size; i-- > 0; )
01846 if (vec[i] != not_a_dimension()) {
01847 empty = 0;
01848 break;
01849 }
01850 }
01851 return empty;
01852 }
01853
01854 dimension_type max_in_codomain() const {
01855 if (max_in_codomain_ == not_a_dimension()) {
01856 for (size_t i = vec_size; i-- > 0; ) {
01857 dimension_type vec_i = vec[i];
01858 if (vec_i != not_a_dimension()
01859 && (max_in_codomain_ == not_a_dimension()
01860 || vec_i > max_in_codomain_))
01861 max_in_codomain_ = vec_i;
01862 }
01863 }
01864 return max_in_codomain_;
01865 }
01866
01867 bool maps(dimension_type i, dimension_type& j) const {
01868 if (i >= vec_size)
01869 return false;
01870 dimension_type vec_i = vec[i];
01871 if (vec_i == not_a_dimension())
01872 return false;
01873 j = vec_i;
01874 return true;
01875 }
01876 };
01877
01878 }
01879
01880 int
01881 ppl_Polyhedron_map_space_dimensions(ppl_Polyhedron_t ph,
01882 ppl_dimension_type maps[],
01883 size_t n) try {
01884 Polyhedron& pph = *to_nonconst(ph);
01885 PIFunc pifunc(maps, n);
01886 pph.map_space_dimensions(pifunc);
01887 return 0;
01888 }
01889 CATCH_ALL
01890
01891 int
01892 ppl_Polyhedron_expand_space_dimension(ppl_Polyhedron_t ph,
01893 ppl_dimension_type d,
01894 ppl_dimension_type m) try {
01895 Polyhedron& pph = *to_nonconst(ph);
01896 pph.expand_space_dimension(Variable(d), m);
01897 return 0;
01898 }
01899 CATCH_ALL
01900
01901 int
01902 ppl_Polyhedron_fold_space_dimensions(ppl_Polyhedron_t ph,
01903 ppl_dimension_type ds[],
01904 size_t n,
01905 ppl_dimension_type d) try {
01906 Polyhedron& pph = *to_nonconst(ph);
01907 Variables_Set to_be_folded;
01908 for (ppl_dimension_type i = n; i-- > 0; )
01909 to_be_folded.insert(Variable(ds[i]));
01910 pph.fold_space_dimensions(to_be_folded, Variable(d));
01911 return 0;
01912 }
01913 CATCH_ALL
01914
01915 int
01916 ppl_Polyhedron_affine_image(ppl_Polyhedron_t ph,
01917 ppl_dimension_type var,
01918 ppl_const_Linear_Expression_t le,
01919 ppl_const_Coefficient_t d) try {
01920 Polyhedron& pph = *to_nonconst(ph);
01921 const Linear_Expression& lle = *to_const(le);
01922 const Coefficient& dd = *to_const(d);
01923 pph.affine_image(Variable(var), lle, dd);
01924 return 0;
01925 }
01926 CATCH_ALL
01927
01928 int
01929 ppl_Polyhedron_affine_preimage(ppl_Polyhedron_t ph,
01930 ppl_dimension_type var,
01931 ppl_const_Linear_Expression_t le,
01932 ppl_const_Coefficient_t d) try {
01933 Polyhedron& pph = *to_nonconst(ph);
01934 const Linear_Expression& lle = *to_const(le);
01935 const Coefficient& dd = *to_const(d);
01936 pph.affine_preimage(Variable(var), lle, dd);
01937 return 0;
01938 }
01939 CATCH_ALL
01940
01941 int
01942 ppl_Polyhedron_bounded_affine_image(ppl_Polyhedron_t ph,
01943 ppl_dimension_type var,
01944 ppl_const_Linear_Expression_t lb,
01945 ppl_const_Linear_Expression_t ub,
01946 ppl_const_Coefficient_t d) try {
01947 Polyhedron& pph = *to_nonconst(ph);
01948 const Linear_Expression& llb = *to_const(lb);
01949 const Linear_Expression& uub = *to_const(ub);
01950 const Coefficient& dd = *to_const(d);
01951 pph.bounded_affine_image(Variable(var), llb, uub, dd);
01952 return 0;
01953 }
01954 CATCH_ALL
01955
01956 int
01957 ppl_Polyhedron_bounded_affine_preimage(ppl_Polyhedron_t ph,
01958 ppl_dimension_type var,
01959 ppl_const_Linear_Expression_t lb,
01960 ppl_const_Linear_Expression_t ub,
01961 ppl_const_Coefficient_t d) try {
01962 Polyhedron& pph = *to_nonconst(ph);
01963 const Linear_Expression& llb = *to_const(lb);
01964 const Linear_Expression& uub = *to_const(ub);
01965 const Coefficient& dd = *to_const(d);
01966 pph.bounded_affine_preimage(Variable(var), llb, uub, dd);
01967 return 0;
01968 }
01969 CATCH_ALL
01970
01971 namespace {
01972
01973 inline Relation_Symbol
01974 relation_symbol(enum ppl_enum_Constraint_Type t) {
01975 switch (t) {
01976 case PPL_CONSTRAINT_TYPE_LESS_THAN:
01977 return LESS_THAN;
01978 case PPL_CONSTRAINT_TYPE_LESS_THAN_OR_EQUAL:
01979 return LESS_THAN_OR_EQUAL;
01980 case PPL_CONSTRAINT_TYPE_EQUAL:
01981 return EQUAL;
01982 case PPL_CONSTRAINT_TYPE_GREATER_THAN_OR_EQUAL:
01983 return GREATER_THAN_OR_EQUAL;
01984 case PPL_CONSTRAINT_TYPE_GREATER_THAN:
01985 return GREATER_THAN;
01986 default:
01987 return static_cast<Relation_Symbol>(t);
01988 }
01989 }
01990
01991 }
01992
01993 int
01994 ppl_Polyhedron_generalized_affine_image(ppl_Polyhedron_t ph,
01995 ppl_dimension_type var,
01996 enum ppl_enum_Constraint_Type relsym,
01997 ppl_const_Linear_Expression_t le,
01998 ppl_const_Coefficient_t d) try {
01999 Polyhedron& pph = *to_nonconst(ph);
02000 const Linear_Expression& lle = *to_const(le);
02001 const Coefficient& dd = *to_const(d);
02002 pph.generalized_affine_image(Variable(var), relation_symbol(relsym), lle,
02003 dd);
02004 return 0;
02005 }
02006 CATCH_ALL
02007
02008 int
02009 ppl_Polyhedron_generalized_affine_preimage
02010 (ppl_Polyhedron_t ph,
02011 ppl_dimension_type var,
02012 enum ppl_enum_Constraint_Type relsym,
02013 ppl_const_Linear_Expression_t le,
02014 ppl_const_Coefficient_t d) try {
02015 Polyhedron& pph = *to_nonconst(ph);
02016 const Linear_Expression& lle = *to_const(le);
02017 const Coefficient& dd = *to_const(d);
02018 pph.generalized_affine_preimage(Variable(var), relation_symbol(relsym), lle,
02019 dd);
02020 return 0;
02021 }
02022 CATCH_ALL
02023
02024 int
02025 ppl_Polyhedron_generalized_affine_image_lhs_rhs
02026 (ppl_Polyhedron_t ph,
02027 ppl_const_Linear_Expression_t lhs,
02028 enum ppl_enum_Constraint_Type relsym,
02029 ppl_const_Linear_Expression_t rhs) try {
02030 Polyhedron& pph = *to_nonconst(ph);
02031 const Linear_Expression& llhs = *to_const(lhs);
02032 const Linear_Expression& rrhs = *to_const(rhs);
02033 pph.generalized_affine_image(llhs, relation_symbol(relsym), rrhs);
02034 return 0;
02035 }
02036 CATCH_ALL
02037
02038 int
02039 ppl_Polyhedron_generalized_affine_preimage_lhs_rhs
02040 (ppl_Polyhedron_t ph,
02041 ppl_const_Linear_Expression_t lhs,
02042 enum ppl_enum_Constraint_Type relsym,
02043 ppl_const_Linear_Expression_t rhs) try {
02044 Polyhedron& pph = *to_nonconst(ph);
02045 const Linear_Expression& llhs = *to_const(lhs);
02046 const Linear_Expression& rrhs = *to_const(rhs);
02047 pph.generalized_affine_preimage(llhs, relation_symbol(relsym), rrhs);
02048 return 0;
02049 }
02050 CATCH_ALL
02051
02052
02053 namespace {
02054
02055 class C_Shrink_Box {
02056 private:
02057 void (*s_e)(void);
02058 void (*r_l_b)(ppl_dimension_type k, int closed,
02059 ppl_const_Coefficient_t n,
02060 ppl_const_Coefficient_t d);
02061 void (*l_u_b)(ppl_dimension_type k, int closed,
02062 ppl_const_Coefficient_t n,
02063 ppl_const_Coefficient_t d);
02064
02065 public:
02066 C_Shrink_Box(void (*se)(void),
02067 void (*rlb)(ppl_dimension_type k, int closed,
02068 ppl_const_Coefficient_t n,
02069 ppl_const_Coefficient_t d),
02070 void (*lub)(ppl_dimension_type k, int closed,
02071 ppl_const_Coefficient_t n,
02072 ppl_const_Coefficient_t d))
02073 : s_e(se), r_l_b(rlb), l_u_b(lub) {
02074 }
02075
02076 void set_empty() {
02077 s_e();
02078 }
02079
02080 void raise_lower_bound(ppl_dimension_type k, bool closed,
02081 const Coefficient& n, const Coefficient& d) {
02082 r_l_b(k, closed, to_const(&n), to_const(&d));
02083 }
02084
02085 void lower_upper_bound(ppl_dimension_type k, bool closed,
02086 const Coefficient& n, const Coefficient& d) {
02087 l_u_b(k, closed, to_const(&n), to_const(&d));
02088 }
02089 };
02090
02091 }
02092
02093 int
02094 ppl_Polyhedron_shrink_bounding_box
02095 (ppl_const_Polyhedron_t ph,
02096 unsigned int complexity,
02097 void (*set_empty)(void),
02098 void (*raise_lower_bound)(ppl_dimension_type k, int closed,
02099 ppl_const_Coefficient_t n,
02100 ppl_const_Coefficient_t d),
02101 void (*lower_upper_bound)(ppl_dimension_type k, int closed,
02102 ppl_const_Coefficient_t n,
02103 ppl_const_Coefficient_t d)) try {
02104 if (complexity != POLYNOMIAL_COMPLEXITY
02105 && complexity != SIMPLEX_COMPLEXITY
02106 && complexity != ANY_COMPLEXITY)
02107 return PPL_ERROR_INVALID_ARGUMENT;
02108
02109 const Polyhedron& pph = *to_const(ph);
02110 C_Shrink_Box csbox(set_empty, raise_lower_bound, lower_upper_bound);
02111 pph.shrink_bounding_box(csbox, Complexity_Class(complexity));
02112 return 0;
02113 }
02114 CATCH_ALL
02115
02116 int
02117 ppl_Polyhedron_relation_with_Constraint(ppl_const_Polyhedron_t ph,
02118 ppl_const_Constraint_t c) try {
02119 const Polyhedron& pph = *to_const(ph);
02120 const Constraint& cc = *to_const(c);
02121 return pph.relation_with(cc).get_flags();
02122 }
02123 CATCH_ALL
02124
02125 int
02126 ppl_Polyhedron_relation_with_Generator(ppl_const_Polyhedron_t ph,
02127 ppl_const_Generator_t g) try {
02128 const Polyhedron& pph = *to_const(ph);
02129 const Generator& gg = *to_const(g);
02130 return pph.relation_with(gg).get_flags();
02131 }
02132 CATCH_ALL
02133
02134 int
02135 ppl_Polyhedron_is_empty(ppl_const_Polyhedron_t ph) try {
02136 const Polyhedron& pph = *to_const(ph);
02137 return pph.is_empty() ? 1 : 0;
02138 }
02139 CATCH_ALL
02140
02141 int
02142 ppl_Polyhedron_is_universe(ppl_const_Polyhedron_t ph) try {
02143 const Polyhedron& pph = *to_const(ph);
02144 return pph.is_universe() ? 1 : 0;
02145 }
02146 CATCH_ALL
02147
02148 int
02149 ppl_Polyhedron_is_bounded(ppl_const_Polyhedron_t ph) try {
02150 const Polyhedron& pph = *to_const(ph);
02151 return pph.is_bounded() ? 1 : 0;
02152 }
02153 CATCH_ALL
02154
02155 int
02156 ppl_Polyhedron_bounds_from_above(ppl_const_Polyhedron_t ph,
02157 ppl_const_Linear_Expression_t le) try {
02158 const Polyhedron& pph = *to_const(ph);
02159 const Linear_Expression& lle = *to_const(le);
02160 return pph.bounds_from_above(lle) ? 1 : 0;
02161 }
02162 CATCH_ALL
02163
02164 int
02165 ppl_Polyhedron_bounds_from_below(ppl_const_Polyhedron_t ph,
02166 ppl_const_Linear_Expression_t le) try {
02167 const Polyhedron& pph = *to_const(ph);
02168 const Linear_Expression& lle = *to_const(le);
02169 return pph.bounds_from_below(lle) ? 1 : 0;
02170 }
02171 CATCH_ALL
02172
02173 int
02174 ppl_Polyhedron_maximize(ppl_const_Polyhedron_t ph,
02175 ppl_const_Linear_Expression_t le,
02176 ppl_Coefficient_t sup_n,
02177 ppl_Coefficient_t sup_d,
02178 int* pmaximum,
02179 ppl_Generator_t point) try {
02180 const Polyhedron& pph = *to_const(ph);
02181 const Linear_Expression& lle = *to_const(le);
02182 Coefficient& ssup_n = *to_nonconst(sup_n);
02183 Coefficient& ssup_d = *to_nonconst(sup_d);
02184 Generator& ppoint = *to_nonconst(point);
02185 bool maximum;
02186 bool ok = pph.maximize(lle, ssup_n, ssup_d, maximum, ppoint);
02187 if (ok)
02188 *pmaximum = maximum ? 1 : 0;
02189 return ok ? 1 : 0;
02190 }
02191 CATCH_ALL
02192
02193 int
02194 ppl_Polyhedron_minimize(ppl_const_Polyhedron_t ph,
02195 ppl_const_Linear_Expression_t le,
02196 ppl_Coefficient_t inf_n,
02197 ppl_Coefficient_t inf_d,
02198 int* pminimum,
02199 ppl_Generator_t point) try {
02200 const Polyhedron& pph = *to_const(ph);
02201 const Linear_Expression& lle = *to_const(le);
02202 Coefficient& iinf_n = *to_nonconst(inf_n);
02203 Coefficient& iinf_d = *to_nonconst(inf_d);
02204 Generator& ppoint = *to_nonconst(point);
02205 bool minimum;
02206 bool ok = pph.minimize(lle, iinf_n, iinf_d, minimum, ppoint);
02207 if (ok)
02208 *pminimum = minimum ? 1 : 0;
02209 return ok ? 1 : 0;
02210 }
02211 CATCH_ALL
02212
02213 int
02214 ppl_Polyhedron_is_topologically_closed(ppl_const_Polyhedron_t ph) try {
02215 const Polyhedron& pph = *to_const(ph);
02216 return pph.is_topologically_closed() ? 1 : 0;
02217 }
02218 CATCH_ALL
02219
02220 int
02221 ppl_Polyhedron_topological_closure_assign(ppl_Polyhedron_t ph) try {
02222 Polyhedron& pph = *to_nonconst(ph);
02223 pph.topological_closure_assign();
02224 return 0;
02225 }
02226 CATCH_ALL
02227
02228 int
02229 ppl_Polyhedron_contains_Polyhedron(ppl_const_Polyhedron_t x,
02230 ppl_const_Polyhedron_t y) try {
02231 const Polyhedron& xx = *to_const(x);
02232 const Polyhedron& yy = *to_const(y);
02233 return xx.contains(yy) ? 1 : 0;
02234 }
02235 CATCH_ALL
02236
02237 int
02238 ppl_Polyhedron_strictly_contains_Polyhedron(ppl_const_Polyhedron_t x,
02239 ppl_const_Polyhedron_t y) try {
02240 const Polyhedron& xx = *to_const(x);
02241 const Polyhedron& yy = *to_const(y);
02242 return xx.strictly_contains(yy) ? 1 : 0;
02243 }
02244 CATCH_ALL
02245
02246 int
02247 ppl_Polyhedron_is_disjoint_from_Polyhedron(ppl_const_Polyhedron_t x,
02248 ppl_const_Polyhedron_t y) try {
02249 const Polyhedron& xx = *to_const(x);
02250 const Polyhedron& yy = *to_const(y);
02251 return xx.is_disjoint_from(yy) ? 1 : 0;
02252 }
02253 CATCH_ALL
02254
02255 int
02256 ppl_Polyhedron_equals_Polyhedron(ppl_const_Polyhedron_t x,
02257 ppl_const_Polyhedron_t y) try {
02258 const Polyhedron& xx = *to_const(x);
02259 const Polyhedron& yy = *to_const(y);
02260 return (xx == yy) ? 1 : 0;
02261 }
02262 CATCH_ALL
02263
02264 int
02265 ppl_Polyhedron_OK(ppl_const_Polyhedron_t ph) try {
02266 return to_const(ph)->OK() ? 1 : 0;
02267 }
02268 CATCH_ALL
02269
02270 int
02271 ppl_new_LP_Problem_trivial(ppl_LP_Problem_t* plp) try {
02272 *plp = to_nonconst(new LP_Problem());
02273 return 0;
02274 }
02275 CATCH_ALL
02276
02277 int
02278 ppl_new_LP_Problem(ppl_LP_Problem_t* plp, ppl_const_Constraint_System_t cs,
02279 ppl_const_Linear_Expression_t le, int m) try {
02280 const Constraint_System& ccs = *to_const(cs);
02281 const Linear_Expression& lle = *to_const(le);
02282 Optimization_Mode mm = (m == PPL_LP_PROBLEM_MINIMIZATION)
02283 ? MINIMIZATION : MAXIMIZATION;
02284 *plp = to_nonconst(new LP_Problem(ccs, lle, mm));
02285 return 0;
02286 }
02287 CATCH_ALL
02288
02289 int
02290 ppl_new_LP_Problem_from_LP_Problem(ppl_LP_Problem_t* plp,
02291 ppl_const_LP_Problem_t lp) try {
02292 const LP_Problem& llp = *to_const(lp);
02293 *plp = to_nonconst(new LP_Problem(llp));
02294 return 0;
02295 }
02296 CATCH_ALL
02297
02298 int
02299 ppl_delete_LP_Problem(ppl_const_LP_Problem_t lp) try {
02300 delete to_const(lp);
02301 return 0;
02302 }
02303 CATCH_ALL
02304
02305 int
02306 ppl_assign_LP_Problem_from_LP_Problem(ppl_LP_Problem_t dst,
02307 ppl_const_LP_Problem_t src) try {
02308 const LP_Problem& ssrc = *to_const(src);
02309 LP_Problem& ddst = *to_nonconst(dst);
02310 ddst = ssrc;
02311 return 0;
02312 }
02313 CATCH_ALL
02314
02315 int
02316 ppl_LP_Problem_space_dimension(ppl_const_LP_Problem_t lp,
02317 ppl_dimension_type* m) try {
02318 *m = to_const(lp)->space_dimension();
02319 return 0;
02320 }
02321 CATCH_ALL
02322
02323 int
02324 ppl_LP_Problem_constraints(ppl_const_LP_Problem_t lp,
02325 ppl_const_Constraint_System_t* pcs) try {
02326 const Constraint_System& cs = to_const(lp)->constraints();
02327 *pcs = to_const(&cs);
02328 return 0;
02329 }
02330 CATCH_ALL
02331
02332 int
02333 ppl_LP_Problem_objective_function(ppl_const_LP_Problem_t lp,
02334 ppl_const_Linear_Expression_t* ple) try {
02335 const Linear_Expression& le = to_const(lp)->objective_function();
02336 *ple = to_const(&le);
02337 return 0;
02338 }
02339 CATCH_ALL
02340
02341 int
02342 ppl_LP_Problem_optimization_mode(ppl_const_LP_Problem_t lp) try {
02343 return to_const(lp)->optimization_mode();
02344 }
02345 CATCH_ALL
02346
02347 int
02348 ppl_LP_Problem_clear(ppl_LP_Problem_t lp) try {
02349 to_nonconst(lp)->clear();
02350 return 0;
02351 }
02352 CATCH_ALL
02353
02354 int
02355 ppl_LP_Problem_add_constraint(ppl_LP_Problem_t lp,
02356 ppl_const_Constraint_t c) try {
02357 const Constraint& cc = *to_const(c);
02358 LP_Problem& llp = *to_nonconst(lp);
02359 llp.add_constraint(cc);
02360 return 0;
02361 }
02362 CATCH_ALL
02363
02364 int
02365 ppl_LP_Problem_add_constraints(ppl_LP_Problem_t lp,
02366 ppl_const_Constraint_System_t cs) try {
02367 const Constraint_System& ccs = *to_const(cs);
02368 LP_Problem& llp = *to_nonconst(lp);
02369 llp.add_constraints(ccs);
02370 return 0;
02371 }
02372 CATCH_ALL
02373
02374 int
02375 ppl_LP_Problem_set_objective_function(ppl_LP_Problem_t lp,
02376 ppl_const_Linear_Expression_t le) try {
02377 const Linear_Expression& lle = *to_const(le);
02378 LP_Problem& llp = *to_nonconst(lp);
02379 llp.set_objective_function(lle);
02380 return 0;
02381 }
02382 CATCH_ALL
02383
02384 int
02385 ppl_LP_Problem_set_optimization_mode(ppl_LP_Problem_t lp, int mode) try {
02386 LP_Problem& llp = *to_nonconst(lp);
02387 Optimization_Mode m = (mode == PPL_LP_PROBLEM_MINIMIZATION)
02388 ? MINIMIZATION : MAXIMIZATION;
02389 llp.set_optimization_mode(m);
02390 return 0;
02391 }
02392 CATCH_ALL
02393
02394 int
02395 ppl_LP_Problem_is_satisfiable(ppl_const_LP_Problem_t lp) try {
02396 return to_const(lp)->is_satisfiable() ? 1 : 0;
02397 }
02398 CATCH_ALL
02399
02400 int
02401 ppl_LP_Problem_solve(ppl_const_LP_Problem_t lp) try {
02402 return to_const(lp)->solve();
02403 }
02404 CATCH_ALL
02405
02406 int
02407 ppl_LP_Problem_evaluate_objective_function(ppl_const_LP_Problem_t lp,
02408 ppl_const_Generator_t g,
02409 ppl_Coefficient_t num,
02410 ppl_Coefficient_t den) try {
02411 const LP_Problem& llp = *to_const(lp);
02412 const Generator& gg = *to_const(g);
02413 Coefficient& nnum = *to_nonconst(num);
02414 Coefficient& dden = *to_nonconst(den);
02415 llp.evaluate_objective_function(gg, nnum, dden);
02416 return 0;
02417 }
02418 CATCH_ALL
02419
02420 int
02421 ppl_LP_Problem_feasible_point(ppl_const_LP_Problem_t lp,
02422 ppl_const_Generator_t* pg) try {
02423 const Generator& g = to_const(lp)->feasible_point();
02424 *pg = to_const(&g);
02425 return 0;
02426 }
02427 CATCH_ALL
02428
02429 int
02430 ppl_LP_Problem_optimizing_point(ppl_const_LP_Problem_t lp,
02431 ppl_const_Generator_t* pg) try {
02432 const Generator& g = to_const(lp)->optimizing_point();
02433 *pg = to_const(&g);
02434 return 0;
02435 }
02436 CATCH_ALL
02437
02438 int
02439 ppl_LP_Problem_optimal_value(ppl_const_LP_Problem_t lp,
02440 ppl_Coefficient_t num,
02441 ppl_Coefficient_t den) try {
02442 Coefficient& nnum = *to_nonconst(num);
02443 Coefficient& dden = *to_nonconst(den);
02444 to_const(lp)->optimal_value(nnum, dden);
02445 return 0;
02446 }
02447 CATCH_ALL
02448
02449 int
02450 ppl_LP_Problem_OK(ppl_const_LP_Problem_t lp) try {
02451 return to_const(lp)->OK() ? 1 : 0;
02452 }
02453 CATCH_ALL
02454
02455 int
02456 ppl_io_print_variable(ppl_dimension_type var) try {
02457 const char* b = c_variable_output_function(var);
02458 if (b == 0 || puts(b) < 0)
02459 return PPL_STDIO_ERROR;
02460 return 0;
02461 }
02462 CATCH_ALL
02463
02464 int
02465 ppl_io_fprint_variable(FILE* stream, ppl_dimension_type var) try {
02466 const char* b = c_variable_output_function(var);
02467 if (b == 0 || fputs(b, stream) < 0)
02468 return PPL_STDIO_ERROR;
02469 return 0;
02470 }
02471 CATCH_ALL
02472
02473 #define DEFINE_PRINT_FUNCTIONS(Type) \
02474 int \
02475 ppl_io_print_ ## Type(ppl_const_ ## Type ## _t x) try { \
02476 using namespace IO_Operators; \
02477 std::ostringstream s; \
02478 s << *to_const(x); \
02479 if (puts(s.str().c_str()) < 0) \
02480 return PPL_STDIO_ERROR; \
02481 return 0; \
02482 } \
02483 CATCH_ALL \
02484 \
02485 int \
02486 ppl_io_fprint_ ## Type(FILE* stream, ppl_const_ ## Type ## _t x) try { \
02487 using namespace IO_Operators; \
02488 std::ostringstream s; \
02489 s << *to_const(x); \
02490 if (fputs(s.str().c_str(), stream) < 0) \
02491 return PPL_STDIO_ERROR; \
02492 return 0; \
02493 } \
02494 CATCH_ALL
02495
02496 DEFINE_PRINT_FUNCTIONS(Coefficient)
02497
02498 DEFINE_PRINT_FUNCTIONS(Linear_Expression)
02499
02500 DEFINE_PRINT_FUNCTIONS(Constraint)
02501
02502 DEFINE_PRINT_FUNCTIONS(Constraint_System)
02503
02504 DEFINE_PRINT_FUNCTIONS(Generator)
02505
02506 DEFINE_PRINT_FUNCTIONS(Generator_System)
02507
02508 DEFINE_PRINT_FUNCTIONS(Polyhedron)
02509
02510 int
02511 ppl_io_set_variable_output_function(ppl_io_variable_output_function_type* p)
02512 try {
02513 c_variable_output_function = p;
02514 return 0;
02515 }
02516 CATCH_ALL
02517
02518 int
02519 ppl_io_get_variable_output_function(ppl_io_variable_output_function_type** pp)
02520 try {
02521 *pp = c_variable_output_function;
02522 return 0;
02523 }
02524 CATCH_ALL