00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "ppl_ocaml_common.defs.hh"
00025
00026 namespace Parma_Polyhedra_Library {
00027
00028 namespace Interfaces {
00029
00030 namespace OCaml {
00031
00032 #ifdef PPL_WATCHDOG_LIBRARY_ENABLED
00033
00034 Parma_Watchdog_Library::Watchdog* p_timeout_object = 0;
00035
00036 typedef
00037 Parma_Watchdog_Library::Threshold_Watcher
00038 <Parma_Polyhedra_Library::Weightwatch_Traits> Weightwatch;
00039
00040 Weightwatch* p_deterministic_timeout_object = 0;
00041
00042 #endif // PPL_WATCHDOG_LIBRARY_ENABLED
00043
00044 void
00045 reset_timeout() {
00046 #ifdef PPL_WATCHDOG_LIBRARY_ENABLED
00047 if (p_timeout_object) {
00048 delete p_timeout_object;
00049 p_timeout_object = 0;
00050 abandon_expensive_computations = 0;
00051 }
00052 #endif // PPL_WATCHDOG_LIBRARY_ENABLED
00053 }
00054
00055 void
00056 reset_deterministic_timeout() {
00057 #ifdef PPL_WATCHDOG_LIBRARY_ENABLED
00058 if (p_deterministic_timeout_object) {
00059 delete p_deterministic_timeout_object;
00060 p_deterministic_timeout_object = 0;
00061 abandon_expensive_computations = 0;
00062 }
00063 #endif // PPL_WATCHDOG_LIBRARY_ENABLED
00064 }
00065
00066 namespace {
00067
00068 inline mpz_ptr
00069 mpz_ptr_val(value val) {
00070 return static_cast<mpz_ptr>(Data_custom_val(val));
00071 }
00072
00073 inline mpz_class&
00074 mpz_class_val(value val) {
00075 return reinterpret_cast<mpz_class&>(*mpz_ptr_val(val));
00076 }
00077
00078
00079 extern "C" struct custom_operations _mlgmp_custom_z;
00080
00081 inline value
00082 unregistered_value_p_zero_mpz(void) {
00083 value zero_mpz = caml_alloc_custom(&_mlgmp_custom_z, sizeof(mpz_t), 0, 1);
00084 mpz_init(mpz_ptr_val(zero_mpz));
00085 return zero_mpz;
00086 }
00087
00088 }
00089
00090 value
00091 build_ocaml_coefficient(const Coefficient& ppl_coeff) {
00092 CAMLparam0();
00093 CAMLlocal1(ml_coeff);
00094 ml_coeff = unregistered_value_p_zero_mpz();
00095 assign_r(mpz_class_val(ml_coeff), ppl_coeff, ROUND_NOT_NEEDED);
00096 CAMLreturn(ml_coeff);
00097 }
00098
00099 Coefficient
00100 build_ppl_Coefficient(value coeff) {
00101 mpz_class z(mpz_ptr_val(coeff));
00102 return Coefficient(z);
00103 }
00104
00105 Linear_Expression
00106 build_ppl_Linear_Expression(value e) {
00107 switch (Tag_val(e)) {
00108 case 0:
00109
00110 return build_ppl_Variable(Field(e, 0));
00111 case 1: {
00112
00113 mpz_class z(mpz_ptr_val(Field(e, 0)));
00114 return Linear_Expression(Coefficient(z));
00115 }
00116 case 2:
00117
00118 return build_ppl_Linear_Expression(Field(e, 0));
00119 case 3:
00120
00121 return -build_ppl_Linear_Expression(Field(e, 0));
00122 case 4:
00123
00124 return build_ppl_Linear_Expression(Field(e, 0))
00125 + build_ppl_Linear_Expression(Field(e, 1));
00126 case 5:
00127
00128 return build_ppl_Linear_Expression(Field(e, 0))
00129 - build_ppl_Linear_Expression(Field(e, 1));
00130 case 6: {
00131
00132 mpz_class z(mpz_ptr_val(Field(e, 0)));
00133 return Coefficient(z) * build_ppl_Linear_Expression(Field(e, 1));
00134 }
00135 default:
00136 throw std::invalid_argument("PPL OCaml interface invalid_argument\n:"
00137 "error building PPL::Linear_Expression");
00138 }
00139 }
00140
00141 Relation_Symbol
00142 build_ppl_relsym(value caml_relsym) {
00143 assert(Is_long(caml_relsym));
00144 switch (Int_val(caml_relsym)) {
00145 case 0:
00146 return LESS_THAN;
00147 case 1:
00148 return LESS_OR_EQUAL;
00149 case 2:
00150 return EQUAL;
00151 case 3:
00152 return GREATER_OR_EQUAL;
00153 case 4:
00154 return GREATER_THAN;
00155 default:
00156
00157 throw std::runtime_error("PPL OCaml interface internal error\n:"
00158 "build_ppl_relsym(rel)");
00159 }
00160 }
00161
00162 Bounded_Integer_Type_Width
00163 build_ppl_bounded_integer_type_width(value caml_width) {
00164 assert(Is_long(caml_width));
00165 switch (Int_val(caml_width)) {
00166 case 0:
00167 return BITS_8;
00168 case 1:
00169 return BITS_16;
00170 case 2:
00171 return BITS_32;
00172 case 3:
00173 return BITS_64;
00174 case 4:
00175 return BITS_128;
00176 default:
00177
00178 throw std::runtime_error("PPL OCaml interface internal error\n:"
00179 "build_ppl_bounded_integer_type_width(width)");
00180 }
00181 }
00182
00183 Bounded_Integer_Type_Representation
00184 build_ppl_bounded_integer_type_representation(value caml_rep) {
00185 assert(Is_long(caml_rep));
00186 switch (Int_val(caml_rep)) {
00187 case 0:
00188 return UNSIGNED;
00189 case 1:
00190 return SIGNED_2_COMPLEMENT;
00191 default:
00192
00193 throw std::runtime_error("PPL OCaml interface internal error\n:"
00194 "build_ppl_bounded_integer_type_representation(rep)");
00195 }
00196 }
00197
00198 Bounded_Integer_Type_Overflow
00199 build_ppl_bounded_integer_type_overflow(value caml_oflow) {
00200 assert(Is_long(caml_oflow));
00201 switch (Int_val(caml_oflow)) {
00202 case 0:
00203 return OVERFLOW_WRAPS;
00204 case 1:
00205 return OVERFLOW_UNDEFINED;
00206 case 2:
00207 return OVERFLOW_IMPOSSIBLE;
00208 default:
00209
00210 throw std::runtime_error("PPL OCaml interface internal error\n:"
00211 "build_ppl_bounded_integer_type_overflow(oflow)");
00212 }
00213 }
00214
00215 Optimization_Mode
00216 build_ppl_opt_mode(value caml_opt_mode) {
00217 assert(Is_long(caml_opt_mode));
00218 switch (Int_val(caml_opt_mode)) {
00219 case 0:
00220 return MINIMIZATION;
00221 case 1:
00222 return MAXIMIZATION;
00223 default:
00224
00225 throw std::runtime_error("PPL OCaml interface internal error\n:"
00226 "build_ppl_opt_mode(opt)");
00227 }
00228 }
00229
00230 Degenerate_Element
00231 build_ppl_Degenerate_Element(value de) {
00232 assert(Is_long(de));
00233 switch (Int_val(de)) {
00234 case 0:
00235 return UNIVERSE;
00236 case 1:
00237 return EMPTY;
00238 default:
00239
00240 throw std::runtime_error("PPL OCaml interface internal error:\n"
00241 "build_ppl_Degenerate_Element(de)");
00242 }
00243 }
00244
00245 Complexity_Class
00246 build_ppl_Complexity_Class(value cc) {
00247 assert(Is_long(cc));
00248 switch (Int_val(cc)) {
00249 case 0:
00250 return POLYNOMIAL_COMPLEXITY;
00251 case 1:
00252 return SIMPLEX_COMPLEXITY;
00253 case 2:
00254 return ANY_COMPLEXITY;
00255 default:
00256
00257 throw std::runtime_error("PPL OCaml interface internal error:\n"
00258 "build_ppl_Complexity_Class(cc)");
00259 }
00260 }
00261
00262 MIP_Problem::Control_Parameter_Name
00263 build_ppl_control_parameter_name(value caml_cp_name) {
00264 assert(Is_long(caml_cp_name));
00265 switch (Int_val(caml_cp_name)) {
00266 case 0:
00267 return MIP_Problem::PRICING;
00268 default:
00269
00270 throw std::runtime_error("PPL OCaml interface internal error:\n"
00271 "build_ppl_control_parameter_name(cpn)");
00272 }
00273 }
00274
00275 MIP_Problem::Control_Parameter_Value
00276 build_ppl_control_parameter_value(value caml_cp_value) {
00277 assert(Is_long(caml_cp_value));
00278 switch (Int_val(caml_cp_value)) {
00279 case 0:
00280 return MIP_Problem::PRICING_STEEPEST_EDGE_FLOAT;
00281 case 1:
00282 return MIP_Problem::PRICING_STEEPEST_EDGE_EXACT;
00283 case 2:
00284 return MIP_Problem::PRICING_TEXTBOOK;
00285 default:
00286
00287 throw std::runtime_error("PPL OCaml interface internal error:\n"
00288 "build_ppl_control_parameter_value(cpv)");
00289 }
00290 }
00291
00292 PIP_Problem::Control_Parameter_Name
00293 build_ppl_pip_problem_control_parameter_name(value caml_cp_name) {
00294 assert(Is_long(caml_cp_name));
00295 switch (Int_val(caml_cp_name)) {
00296 case 0:
00297 return PIP_Problem::CUTTING_STRATEGY;
00298 case 1:
00299 return PIP_Problem::PIVOT_ROW_STRATEGY;
00300 default:
00301
00302 throw std::runtime_error("PPL OCaml interface internal error:\n"
00303 "build_ppl_pip_problem_"
00304 "control_parameter_name(cpn)");
00305 }
00306 }
00307
00308 PIP_Problem::Control_Parameter_Value
00309 build_ppl_pip_problem_control_parameter_value(value caml_cp_value) {
00310 assert(Is_long(caml_cp_value));
00311 switch (Int_val(caml_cp_value)) {
00312 case 0:
00313 return PIP_Problem::CUTTING_STRATEGY_FIRST;
00314 case 1:
00315 return PIP_Problem::CUTTING_STRATEGY_DEEPEST;
00316 case 2:
00317 return PIP_Problem::CUTTING_STRATEGY_ALL;
00318 case 3:
00319 return PIP_Problem::PIVOT_ROW_STRATEGY_FIRST;
00320 case 4:
00321 return PIP_Problem::PIVOT_ROW_STRATEGY_MAX_COLUMN;
00322 default:
00323
00324 throw std::runtime_error("PPL OCaml interface internal error:\n"
00325 "build_ppl_pip_problem_"
00326 "control_parameter_value(cpv)");
00327 }
00328 }
00329
00330 Variables_Set
00331 build_ppl_Variables_Set(value caml_vset) {
00332 Variables_Set ppl_vset;
00333 while (caml_vset != Val_emptylist) {
00334 ppl_vset.insert(value_to_ppl_dimension(Field(caml_vset, 0)));
00335 caml_vset = Field(caml_vset, 1);
00336 }
00337 return ppl_vset;
00338 }
00339
00340 Constraint
00341 build_ppl_Constraint(value c) {
00342 value e1 = Field(c, 0);
00343 value e2 = Field(c, 1);
00344 switch (Tag_val(c)) {
00345 case 0:
00346
00347 return build_ppl_Linear_Expression(e1) < build_ppl_Linear_Expression(e2);
00348 case 1:
00349
00350 return build_ppl_Linear_Expression(e1) <= build_ppl_Linear_Expression(e2);
00351 case 2:
00352
00353 return build_ppl_Linear_Expression(e1) == build_ppl_Linear_Expression(e2);
00354 case 3:
00355
00356 return build_ppl_Linear_Expression(e1) > build_ppl_Linear_Expression(e2);
00357 case 4:
00358
00359 return build_ppl_Linear_Expression(e1) >= build_ppl_Linear_Expression(e2);
00360 default:
00361 throw std::invalid_argument("PPL OCaml interface invalid argument:\n"
00362 "error building PPL::Constraint");
00363 }
00364 }
00365
00366
00367 template <typename R>
00368 CAMLprim value
00369 get_inhomogeneous_term(const R& r) {
00370 CAMLparam0();
00371 CAMLlocal1(coeff_term);
00372 PPL_DIRTY_TEMP_COEFFICIENT(coeff);
00373 neg_assign(coeff, r.inhomogeneous_term());
00374 coeff_term = caml_alloc(1,1);
00375 Store_field(coeff_term, 0, build_ocaml_coefficient(coeff));
00376 CAMLreturn(coeff_term);
00377 }
00378
00379
00380
00381 template <typename R>
00382 CAMLprim value
00383 get_linear_expression(const R& r) {
00384 CAMLparam0();
00385 CAMLlocal2(zero_term, zero_mpz);
00386 CAMLlocal5(sum, term1, ml_le_var1, term2, ml_le_var2);
00387 dimension_type space_dimension = r.space_dimension();
00388 dimension_type varid = 0;
00389 PPL_DIRTY_TEMP_COEFFICIENT(coeff);
00390 while (varid < space_dimension
00391 && (coeff = r.coefficient(Variable(varid))) == 0)
00392 ++varid;
00393 if (varid >= space_dimension) {
00394 zero_mpz = unregistered_value_p_zero_mpz();
00395 zero_term = caml_alloc(1,1);
00396 Store_field(zero_term, 0, zero_mpz);
00397 CAMLreturn(zero_term);
00398 }
00399 else {
00400 ml_le_var1 = caml_alloc(1,0);
00401 Store_field(ml_le_var1, 0, ppl_dimension_to_value(varid));
00402 term1 = caml_alloc(2,6);
00403 PPL_DIRTY_TEMP_COEFFICIENT(ppl_coeff);
00404 ppl_coeff = r.coefficient(Variable(varid));
00405 Store_field(term1, 0, build_ocaml_coefficient(ppl_coeff));
00406 Store_field(term1, 1, ml_le_var1);
00407 while (true) {
00408 ++varid;
00409 while (varid < space_dimension
00410 && (coeff = r.coefficient(Variable(varid))) == 0)
00411 ++varid;
00412 if (varid >= space_dimension)
00413 CAMLreturn(term1);
00414 else {
00415 ml_le_var2 = caml_alloc(1,0);
00416 Store_field(ml_le_var2, 0, ppl_dimension_to_value(varid));
00417 term2 = caml_alloc(2,6);
00418 ppl_coeff = r.coefficient(Variable(varid));
00419 Store_field(term2, 0, build_ocaml_coefficient(ppl_coeff));
00420 Store_field(term2, 1, ml_le_var2);
00421 sum = caml_alloc(2,4);
00422 Store_field(sum, 0, term1);
00423 Store_field(sum, 1, term2);
00424 term1 = sum;
00425 }
00426 }
00427 }
00428 }
00429
00430 value
00431 build_ocaml_generator(const Generator& ppl_generator) {
00432 CAMLparam0();
00433 CAMLlocal1(caml_generator);
00434 switch (ppl_generator.type()) {
00435 case Generator::LINE: {
00436
00437
00438 caml_generator = caml_alloc(1,0);
00439 Store_field(caml_generator, 0, get_linear_expression(ppl_generator));
00440 CAMLreturn(caml_generator);
00441 }
00442 case Generator::RAY: {
00443 caml_generator = caml_alloc(1,1);
00444 Store_field(caml_generator, 0, get_linear_expression(ppl_generator));
00445 CAMLreturn(caml_generator);
00446 }
00447 case Generator::POINT: {
00448
00449
00450 caml_generator = caml_alloc(2,2);
00451 Store_field(caml_generator, 0, get_linear_expression(ppl_generator));
00452 const Coefficient& divisor = ppl_generator.divisor();
00453 Store_field(caml_generator, 1, build_ocaml_coefficient(divisor));
00454 CAMLreturn(caml_generator);
00455 }
00456 case Generator::CLOSURE_POINT: {
00457 caml_generator = caml_alloc(2,3);
00458 Store_field(caml_generator, 0, get_linear_expression(ppl_generator));
00459 const Coefficient& divisor = ppl_generator.divisor();
00460 Store_field(caml_generator, 1, build_ocaml_coefficient(divisor));
00461 CAMLreturn(caml_generator);
00462 }
00463 default:
00464 throw std::runtime_error("PPL OCaml interface internal error:\n"
00465 "build_ocaml_generator(g)");
00466 }
00467 }
00468
00469 value
00470 build_ocaml_grid_generator(const Grid_Generator& ppl_grid_generator) {
00471 CAMLparam0();
00472 CAMLlocal1(caml_generator);
00473 switch (ppl_grid_generator.type()) {
00474 case Grid_Generator::LINE: {
00475
00476
00477 caml_generator = caml_alloc(1,0);
00478 Store_field(caml_generator, 0, get_linear_expression(ppl_grid_generator));
00479 CAMLreturn(caml_generator);
00480 }
00481 case Grid_Generator::PARAMETER: {
00482 caml_generator = caml_alloc(2,1);
00483 Store_field(caml_generator, 0, get_linear_expression(ppl_grid_generator));
00484 const Coefficient& divisor = ppl_grid_generator.divisor();
00485 Store_field(caml_generator, 1, build_ocaml_coefficient(divisor));
00486 CAMLreturn(caml_generator);
00487 }
00488 case Grid_Generator::POINT: {
00489
00490
00491 caml_generator = caml_alloc(2,2);
00492 Store_field(caml_generator, 0, get_linear_expression(ppl_grid_generator));
00493 const Coefficient& divisor = ppl_grid_generator.divisor();
00494 Store_field(caml_generator, 1, build_ocaml_coefficient(divisor));
00495 CAMLreturn(caml_generator);
00496 }
00497 default:
00498 throw std::runtime_error("PPL OCaml interface internal error:\n"
00499 "build_ocaml_grid_generator(g)");
00500 }
00501 }
00502
00503 value
00504 build_ocaml_constraint(const Constraint& ppl_constraint) {
00505 CAMLparam0();
00506 CAMLlocal1(caml_constraint);
00507 switch (ppl_constraint.type()) {
00508 case Constraint::EQUALITY: {
00509 caml_constraint = caml_alloc(2,2);
00510 Store_field(caml_constraint, 0, get_linear_expression(ppl_constraint));
00511 Store_field(caml_constraint, 1, get_inhomogeneous_term(ppl_constraint));
00512 CAMLreturn(caml_constraint);
00513 }
00514 case Constraint::STRICT_INEQUALITY: {
00515 caml_constraint = caml_alloc(2,3);
00516 Store_field(caml_constraint, 0, get_linear_expression(ppl_constraint));
00517 Store_field(caml_constraint, 1, get_inhomogeneous_term(ppl_constraint));
00518 CAMLreturn(caml_constraint);
00519 }
00520 case Constraint::NONSTRICT_INEQUALITY: {
00521 caml_constraint = caml_alloc(2,4);
00522 Store_field(caml_constraint, 0, get_linear_expression(ppl_constraint));
00523 Store_field(caml_constraint, 1, get_inhomogeneous_term(ppl_constraint));
00524 CAMLreturn(caml_constraint);
00525 }
00526 default:
00527 throw std::runtime_error("PPL OCaml interface internal error:\n"
00528 "build_ocaml_constraint(c)");
00529 }
00530 }
00531
00532 value
00533 build_ocaml_congruence(const Congruence& ppl_congruence) {
00534 CAMLparam0();
00535 CAMLlocal1(caml_congruence);
00536 caml_congruence = caml_alloc(3,0);
00537 Store_field(caml_congruence, 0, get_linear_expression(ppl_congruence));
00538 Store_field(caml_congruence, 1, get_inhomogeneous_term(ppl_congruence));
00539 const Coefficient& modulus = ppl_congruence.modulus();
00540 Store_field(caml_congruence, 2, build_ocaml_coefficient(modulus));
00541 CAMLreturn(caml_congruence);
00542 }
00543
00544 value
00545 build_ocaml_congruence_system(const Congruence_System& ppl_cgs) {
00546 CAMLparam0();
00547 CAMLlocal2(result, new_tail);
00548 result = Val_emptylist;
00549 for (Congruence_System::const_iterator v_begin = ppl_cgs.begin(),
00550 v_end = ppl_cgs.end(); v_begin != v_end; ++v_begin) {
00551 new_tail = caml_alloc_tuple(2);
00552 Store_field(new_tail, 0, build_ocaml_congruence(*v_begin));
00553 Store_field(new_tail, 1, result);
00554 result = new_tail;
00555 }
00556 CAMLreturn(result);
00557 }
00558
00559 value
00560 build_ocaml_constraint_system(const Constraint_System& ppl_cs) {
00561 CAMLparam0();
00562 CAMLlocal2(result, new_tail);
00563 result = Val_emptylist;
00564 for (Constraint_System::const_iterator v_begin = ppl_cs.begin(),
00565 v_end = ppl_cs.end(); v_begin != v_end; ++v_begin) {
00566 new_tail = caml_alloc_tuple(2);
00567 Store_field(new_tail, 0, build_ocaml_constraint(*v_begin));
00568 Store_field(new_tail, 1, result);
00569 result = new_tail;
00570 }
00571 CAMLreturn(result);
00572 }
00573
00574 value
00575 build_ocaml_generator_system(const Generator_System& ppl_gs) {
00576 CAMLparam0();
00577 CAMLlocal2(result, new_tail);
00578 result = Val_emptylist;
00579 for (Generator_System::const_iterator v_begin = ppl_gs.begin(),
00580 v_end = ppl_gs.end(); v_begin != v_end; ++v_begin) {
00581 new_tail = caml_alloc_tuple(2);
00582 Store_field(new_tail, 0, build_ocaml_generator(*v_begin));
00583 Store_field(new_tail, 1, result);
00584 result = new_tail;
00585 }
00586 CAMLreturn(result);
00587 }
00588
00589 value
00590 build_ocaml_grid_generator_system(const Grid_Generator_System& ppl_ggs) {
00591 CAMLparam0();
00592 CAMLlocal2(result, new_tail);
00593 result = Val_emptylist;
00594 for (Grid_Generator_System::const_iterator v_begin = ppl_ggs.begin(),
00595 v_end = ppl_ggs.end(); v_begin != v_end; ++v_begin) {
00596 new_tail = caml_alloc_tuple(2);
00597 Store_field(new_tail, 0, build_ocaml_grid_generator(*v_begin));
00598 Store_field(new_tail, 1, result);
00599 result = new_tail;
00600 }
00601 CAMLreturn(result);
00602 }
00603
00604 value
00605 build_ocaml_poly_con_relation(Poly_Con_Relation& r) {
00606 CAMLparam0();
00607 CAMLlocal2(result, cons);
00608 result = Val_emptylist;
00609 while (r != Poly_Con_Relation::nothing()) {
00610 if (r.implies(Poly_Con_Relation::is_disjoint())) {
00611 cons = caml_alloc_tuple(2);
00612 Store_field(cons, 0, Val_int(0));
00613 Store_field(cons, 1, result);
00614 result = cons;
00615 r = r - Poly_Con_Relation::is_disjoint();
00616 }
00617 else if (r.implies(Poly_Con_Relation::strictly_intersects())) {
00618 cons = caml_alloc_tuple(2);
00619 Store_field(cons, 0, Val_int(1));
00620 Store_field(cons, 1, result);
00621 result = cons;
00622 r = r - Poly_Con_Relation::strictly_intersects();
00623 }
00624 else if (r.implies(Poly_Con_Relation::is_included())) {
00625 cons = caml_alloc_tuple(2);
00626 Store_field(cons, 0, Val_int(2));
00627 Store_field(cons, 1, result);
00628 result = cons;
00629 r = r - Poly_Con_Relation::is_included();
00630 }
00631 else if (r.implies(Poly_Con_Relation::saturates())) {
00632 cons = caml_alloc_tuple(2);
00633 Store_field(cons, 0, Val_int(3));
00634 Store_field(cons, 1, result);
00635 result = cons;
00636 r = r - Poly_Con_Relation::saturates();
00637 }
00638 }
00639 CAMLreturn(result);
00640 }
00641
00642 value
00643 build_ocaml_poly_gen_relation(Poly_Gen_Relation& r) {
00644 CAMLparam0();
00645 CAMLlocal2(result, cons);
00646 result = Val_emptylist;
00647 while (r != Poly_Gen_Relation::nothing()) {
00648 if (r.implies(Poly_Gen_Relation::subsumes())) {
00649 cons = caml_alloc_tuple(2);
00650 Store_field(cons, 0, Val_int(0));
00651 Store_field(cons, 1, result);
00652 result = cons;
00653 r = r - Poly_Gen_Relation::subsumes();
00654 }
00655 }
00656 CAMLreturn(result);
00657 }
00658
00659 Congruence
00660 build_ppl_Congruence(value c) {
00661 value e1 = Field(c, 0);
00662 value e2 = Field(c, 1);
00663 mpz_class z(mpz_ptr_val(Field(c, 2)));
00664 Linear_Expression lhs = build_ppl_Linear_Expression(e1);
00665 Linear_Expression rhs = build_ppl_Linear_Expression(e2);
00666 return (lhs %= rhs) / z;
00667 }
00668
00669 Generator
00670 build_ppl_Generator(value g) {
00671 switch (Tag_val(g)) {
00672 case 0:
00673
00674 return Generator::line(build_ppl_Linear_Expression(Field(g, 0)));
00675 case 1:
00676
00677 return Generator::ray(build_ppl_Linear_Expression(Field(g, 0)));
00678 case 2: {
00679
00680 mpz_class z(mpz_ptr_val(Field(g, 1)));
00681 return Generator::point(build_ppl_Linear_Expression(Field(g, 0)),
00682 Coefficient(z));
00683 }
00684 case 3: {
00685
00686 mpz_class z(mpz_ptr_val(Field(g, 1)));
00687 return Generator::closure_point(build_ppl_Linear_Expression(Field(g, 0)),
00688 Coefficient(z));
00689 }
00690 default:
00691 throw std::invalid_argument("PPL OCaml interface invalid argument:\n"
00692 "error building PPL::Generator");
00693 }
00694 }
00695
00696 Grid_Generator
00697 build_ppl_Grid_Generator(value gg) {
00698 switch (Tag_val(gg)) {
00699 case 0:
00700
00701 return grid_line(build_ppl_Linear_Expression(Field(gg, 0)));
00702 case 1: {
00703
00704 mpz_class z(mpz_ptr_val(Field(gg, 1)));
00705 return parameter(build_ppl_Linear_Expression(Field(gg, 0)),
00706 Coefficient(z));
00707 }
00708 case 2: {
00709
00710 mpz_class z(mpz_ptr_val(Field(gg, 1)));
00711 return grid_point(build_ppl_Linear_Expression(Field(gg, 0)),
00712 Coefficient(z));
00713 }
00714 default:
00715
00716 throw std::invalid_argument("PPL OCaml interface invalid argument:\n"
00717 "error building PPL::Grid_Generator");
00718 }
00719 }
00720
00721 Constraint_System
00722 build_ppl_Constraint_System(value cl) {
00723 Constraint_System cs;
00724 while (cl != Val_emptylist) {
00725 cs.insert(build_ppl_Constraint(Field(cl, 0)));
00726 cl = Field(cl, 1);
00727 }
00728 return cs;
00729 }
00730
00731 Generator_System
00732 build_ppl_Generator_System(value gl) {
00733 Generator_System gs;
00734 while (gl != Val_emptylist) {
00735 gs.insert(build_ppl_Generator(Field(gl, 0)));
00736 gl = Field(gl, 1);
00737 }
00738 return gs;
00739 }
00740
00741 Congruence_System
00742 build_ppl_Congruence_System(value cgl) {
00743 Congruence_System cgs;
00744 while (cgl != Val_emptylist) {
00745 cgs.insert(build_ppl_Congruence(Field(cgl, 0)));
00746 cgl = Field(cgl, 1);
00747 }
00748 return cgs;
00749 }
00750
00751 Grid_Generator_System
00752 build_ppl_Grid_Generator_System(value caml_ggs) {
00753 Grid_Generator_System ggs;
00754 while (caml_ggs != Val_emptylist) {
00755 ggs.insert(build_ppl_Grid_Generator(Field(caml_ggs, 0)));
00756 caml_ggs = Field(caml_ggs, 1);
00757 }
00758 return ggs;
00759 }
00760
00762 inline MIP_Problem*&
00763 p_MIP_Problem_val(value v) {
00764 return *reinterpret_cast<MIP_Problem**>(Data_custom_val(v));
00765 }
00766
00767 void
00768 custom_MIP_Problem_finalize(value v) {
00769 delete p_MIP_Problem_val(v);
00770 }
00771
00772 static struct custom_operations MIP_Problem_custom_operations = {
00773 "it.unipr.cs.ppl" "." PPL_VERSION "." "MIP_Problem",
00774 custom_MIP_Problem_finalize,
00775 custom_compare_default,
00776 custom_hash_default,
00777 custom_serialize_default,
00778 custom_deserialize_default
00779 };
00780
00781 inline value
00782 unregistered_value_p_MIP_Problem(const MIP_Problem& ph) {
00783 value v = caml_alloc_custom(&MIP_Problem_custom_operations,
00784 sizeof(MIP_Problem*), 0, 1);
00785 p_MIP_Problem_val(v) = const_cast<MIP_Problem*>(&ph);
00786 return v;
00787 }
00788
00790 inline PIP_Problem*&
00791 p_PIP_Problem_val(value v) {
00792 return *reinterpret_cast<PIP_Problem**>(Data_custom_val(v));
00793 }
00794
00795 void
00796 custom_PIP_Problem_finalize(value v) {
00797 delete p_PIP_Problem_val(v);
00798 }
00799
00800 static struct custom_operations PIP_Problem_custom_operations = {
00801 "it.unipr.cs.ppl" "." PPL_VERSION "." "PIP_Problem",
00802 custom_PIP_Problem_finalize,
00803 custom_compare_default,
00804 custom_hash_default,
00805 custom_serialize_default,
00806 custom_deserialize_default
00807 };
00808
00809 inline value
00810 unregistered_value_p_PIP_Problem(const PIP_Problem& ph) {
00811 value v = caml_alloc_custom(&PIP_Problem_custom_operations,
00812 sizeof(PIP_Problem*), 0, 1);
00813 p_PIP_Problem_val(v) = const_cast<PIP_Problem*>(&ph);
00814 return v;
00815 }
00816
00817
00818
00819
00820
00821
00822 static struct custom_operations PIP_Tree_Node_custom_operations = {
00823 "it.unipr.cs.ppl" "." PPL_VERSION "." "PIP_Tree_Node",
00824 custom_finalize_default,
00825 custom_compare_default,
00826 custom_hash_default,
00827 custom_serialize_default,
00828 custom_deserialize_default
00829 };
00830
00832 inline const PIP_Tree_Node*&
00833 p_PIP_Tree_Node_val(value v) {
00834 return *reinterpret_cast<const PIP_Tree_Node**>(Data_custom_val(v));
00835 }
00836
00837 inline value
00838 unregistered_value_p_PIP_Tree_Node(const PIP_Tree_Node* pip_tree) {
00839 value v = caml_alloc_custom(&PIP_Tree_Node_custom_operations,
00840 sizeof(PIP_Tree_Node*), 0, 1);
00841 p_PIP_Tree_Node_val(v) = pip_tree;
00842 return v;
00843 }
00844
00845 inline const PIP_Tree_Node*
00846 ppl_PIP_Tree_Node_get_child(const PIP_Tree_Node* parent, bool branch) {
00847 if (parent == 0)
00848 throw std::invalid_argument("ppl_PIP_Tree_Node_get_child(node):\n"
00849 "node is bottom.");
00850 if (const PIP_Decision_Node* ppl_dec = parent->as_decision())
00851 return ppl_dec->child_node(branch);
00852 else
00853 throw std::invalid_argument("ppl_PIP_Tree_Node_get_child(node):\n"
00854 "node is not a decision node (solution).");
00855 }
00856
00857 }
00858
00859 }
00860
00861 }
00862
00863 using namespace Parma_Polyhedra_Library;
00864 using namespace Parma_Polyhedra_Library::Interfaces::OCaml;
00865
00866 extern "C"
00867 CAMLprim value
00868 ppl_new_MIP_Problem_from_space_dimension(value d) try {
00869 CAMLparam1(d);
00870 dimension_type dd = value_to_ppl_dimension(d);
00871 MIP_Problem& ppl_mip = *new MIP_Problem(dd);
00872 CAMLreturn(unregistered_value_p_MIP_Problem(ppl_mip));
00873 }
00874 CATCH_ALL
00875
00876 extern "C"
00877 CAMLprim value
00878 ppl_new_MIP_Problem(value d, value caml_cs, value caml_cost,
00879 value caml_opt_mode) try {
00880 CAMLparam4(d, caml_cs, caml_cost, caml_opt_mode);
00881 dimension_type dd = value_to_ppl_dimension(d);
00882 Constraint_System ppl_cs = build_ppl_Constraint_System(caml_cs);
00883 Linear_Expression ppl_cost = build_ppl_Linear_Expression(caml_cost);
00884 Optimization_Mode ppl_opt_mode = build_ppl_opt_mode(caml_opt_mode);
00885 MIP_Problem& ppl_mip = *new MIP_Problem(dd, ppl_cs, ppl_cost, ppl_opt_mode);
00886 CAMLreturn(unregistered_value_p_MIP_Problem(ppl_mip));
00887 }
00888 CATCH_ALL
00889
00890
00891 extern "C"
00892 CAMLprim value
00893 ppl_MIP_Problem_space_dimension(value ph) try {
00894 CAMLparam1(ph);
00895 const MIP_Problem& pph = *p_MIP_Problem_val(ph);
00896 dimension_type d = pph.space_dimension();
00897 CAMLreturn(ppl_dimension_to_value(d));
00898 }
00899 CATCH_ALL
00900
00901 extern "C"
00902 CAMLprim value
00903 ppl_MIP_Problem_integer_space_dimensions(value caml_mip) try {
00904 CAMLparam1(caml_mip);
00905 CAMLlocal2(result, new_tail);
00906 MIP_Problem& ppl_mip = *p_MIP_Problem_val(caml_mip);
00907 const Variables_Set& ppl_ivars = ppl_mip.integer_space_dimensions();
00908 result = Val_emptylist;
00909 for (Variables_Set::const_reverse_iterator i = ppl_ivars.rbegin(),
00910 i_end = ppl_ivars.rend(); i != i_end; ++i) {
00911 new_tail = caml_alloc_tuple(2);
00912 Store_field(new_tail, 0, ppl_dimension_to_value(*i));
00913 Store_field(new_tail, 1, result);
00914 result = new_tail;
00915 }
00916 CAMLreturn(result);
00917 }
00918 CATCH_ALL
00919
00920 extern "C"
00921 CAMLprim value
00922 ppl_MIP_Problem_constraints(value caml_mip) try {
00923 CAMLparam1(caml_mip);
00924 const MIP_Problem& ppl_mip = *p_MIP_Problem_val(caml_mip);
00925 Constraint_System cs;
00926 for (MIP_Problem::const_iterator cs_it = ppl_mip.constraints_begin(),
00927 cs_end = ppl_mip.constraints_end(); cs_it != cs_end; ++cs_it) {
00928 cs.insert(*cs_it);
00929 }
00930 CAMLreturn(build_ocaml_constraint_system(cs));
00931 }
00932 CATCH_ALL
00933
00934 extern "C"
00935 CAMLprim value
00936 ppl_MIP_Problem_add_space_dimensions_and_embed(value caml_mip, value dim) try {
00937 CAMLparam2(caml_mip, dim);
00938 dimension_type ppl_dim = value_to_ppl_dimension(dim);
00939 MIP_Problem& ppl_mip = *p_MIP_Problem_val(caml_mip);
00940 ppl_mip.add_space_dimensions_and_embed(ppl_dim);
00941 CAMLreturn(Val_unit);
00942 }
00943 CATCH_ALL
00944
00945 extern "C"
00946 CAMLprim value
00947 ppl_MIP_Problem_add_to_integer_space_dimensions(value caml_mip,
00948 value caml_ivars) try {
00949 CAMLparam2(caml_mip, caml_ivars);
00950 MIP_Problem& ppl_mip = *p_MIP_Problem_val(caml_mip);
00951 ppl_mip.add_to_integer_space_dimensions(build_ppl_Variables_Set(caml_ivars));
00952 CAMLreturn(Val_unit);
00953 }
00954 CATCH_ALL
00955
00956 extern "C"
00957 CAMLprim value
00958 ppl_MIP_Problem_add_constraint(value caml_mip,
00959 value caml_constraint) try {
00960 CAMLparam2(caml_mip, caml_constraint);
00961 MIP_Problem& ppl_mip = *p_MIP_Problem_val(caml_mip);
00962 ppl_mip.add_constraint(build_ppl_Constraint(caml_constraint));
00963 CAMLreturn(Val_unit);
00964 }
00965 CATCH_ALL
00966
00967 extern "C"
00968 CAMLprim value
00969 ppl_MIP_Problem_add_constraints(value caml_mip,
00970 value caml_constraints) try {
00971 CAMLparam2(caml_mip, caml_constraints);
00972 MIP_Problem& ppl_mip = *p_MIP_Problem_val(caml_mip);
00973 ppl_mip.add_constraints(build_ppl_Constraint_System(caml_constraints));
00974 CAMLreturn(Val_unit);
00975 }
00976 CATCH_ALL
00977
00978 extern "C"
00979 CAMLprim value
00980 ppl_MIP_Problem_set_objective_function(value caml_mip,
00981 value caml_cost) try {
00982 CAMLparam2(caml_mip, caml_cost);
00983 MIP_Problem& ppl_mip = *p_MIP_Problem_val(caml_mip);
00984 ppl_mip.set_objective_function(build_ppl_Linear_Expression(caml_cost));
00985 CAMLreturn(Val_unit);
00986 }
00987 CATCH_ALL
00988
00989 extern "C"
00990 CAMLprim value
00991 ppl_MIP_Problem_is_satisfiable(value caml_mip) try {
00992 CAMLparam1(caml_mip);
00993 MIP_Problem& ppl_mip = *p_MIP_Problem_val(caml_mip);
00994 CAMLreturn(ppl_mip.is_satisfiable());
00995 }
00996 CATCH_ALL
00997
00998 extern "C"
00999 CAMLprim value
01000 ppl_MIP_Problem_solve(value caml_mip) try {
01001 CAMLparam1(caml_mip);
01002 MIP_Problem& ppl_mip = *p_MIP_Problem_val(caml_mip);
01003 MIP_Problem_Status mip_status = ppl_mip.solve();
01004 switch (mip_status) {
01005 case UNFEASIBLE_MIP_PROBLEM:
01006 CAMLreturn(Val_int(0));
01007 case UNBOUNDED_MIP_PROBLEM:
01008 CAMLreturn(Val_int(1));
01009 case OPTIMIZED_MIP_PROBLEM:
01010 CAMLreturn(Val_int(2));
01011 default:
01012 ;
01013 }
01014
01015 throw std::runtime_error("PPL OCaml interface internal error");
01016 }
01017 CATCH_ALL
01018
01019 extern "C"
01020 CAMLprim value
01021 ppl_MIP_Problem_optimization_mode(value caml_mip) try {
01022 CAMLparam1(caml_mip);
01023 MIP_Problem& ppl_mip = *p_MIP_Problem_val(caml_mip);
01024 Optimization_Mode opt_mode = ppl_mip.optimization_mode();
01025 switch (opt_mode) {
01026 case MINIMIZATION:
01027 CAMLreturn(Val_int(0));
01028 case MAXIMIZATION:
01029 CAMLreturn(Val_int(1));
01030 default:
01031 ;
01032 }
01033
01034 throw std::runtime_error("PPL OCaml interface internal error");
01035 }
01036 CATCH_ALL
01037
01038 extern "C"
01039 CAMLprim value
01040 ppl_MIP_Problem_set_control_parameter(value caml_mip,
01041 value caml_cp_value) try {
01042 CAMLparam2(caml_mip, caml_cp_value);
01043 MIP_Problem& ppl_mip = *p_MIP_Problem_val(caml_mip);
01044 MIP_Problem::Control_Parameter_Value ppl_cp_value
01045 = build_ppl_control_parameter_value(caml_cp_value);
01046 ppl_mip.set_control_parameter(ppl_cp_value);
01047 CAMLreturn(Val_unit);
01048 }
01049 CATCH_ALL
01050
01051 extern "C"
01052 CAMLprim value
01053 ppl_MIP_Problem_get_control_parameter(value caml_mip,
01054 value caml_cp_name) try {
01055 CAMLparam2(caml_mip, caml_cp_name);
01056 MIP_Problem& ppl_mip = *p_MIP_Problem_val(caml_mip);
01057 MIP_Problem::Control_Parameter_Name ppl_cp_name
01058 = build_ppl_control_parameter_name(caml_cp_name);
01059 MIP_Problem::Control_Parameter_Value ppl_cp_value
01060 = ppl_mip.get_control_parameter(ppl_cp_name);
01061 switch (ppl_cp_value) {
01062 case MIP_Problem::PRICING_STEEPEST_EDGE_FLOAT:
01063 CAMLreturn(Val_int(0));
01064 case MIP_Problem::PRICING_STEEPEST_EDGE_EXACT:
01065 CAMLreturn(Val_int(1));
01066 case MIP_Problem::PRICING_TEXTBOOK:
01067 CAMLreturn(Val_int(2));
01068 default:
01069 ;
01070 }
01071
01072 throw std::runtime_error("PPL OCaml interface internal error");
01073 }
01074 CATCH_ALL
01075
01076 extern "C"
01077 CAMLprim value
01078 ppl_MIP_Problem_feasible_point(value caml_mip) try {
01079 CAMLparam1(caml_mip);
01080 MIP_Problem& ppl_mip = *p_MIP_Problem_val(caml_mip);
01081 CAMLreturn(build_ocaml_generator(ppl_mip.feasible_point()));
01082 }
01083 CATCH_ALL
01084
01085 extern "C"
01086 CAMLprim value
01087 ppl_MIP_Problem_optimizing_point(value caml_mip) try {
01088 CAMLparam1(caml_mip);
01089 MIP_Problem& ppl_mip = *p_MIP_Problem_val(caml_mip);
01090 CAMLreturn(build_ocaml_generator(ppl_mip.optimizing_point()));
01091 }
01092 CATCH_ALL
01093
01094 extern "C"
01095 CAMLprim value
01096 ppl_MIP_Problem_optimal_value(value caml_mip) try {
01097 CAMLparam1(caml_mip);
01098 CAMLlocal1(caml_return_value);
01099 MIP_Problem& ppl_mip = *p_MIP_Problem_val(caml_mip);
01100 PPL_DIRTY_TEMP_COEFFICIENT(num);
01101 PPL_DIRTY_TEMP_COEFFICIENT(den);
01102 ppl_mip.optimal_value(num, den);
01103 caml_return_value = caml_alloc(2,0);
01104 Store_field(caml_return_value, 0, build_ocaml_coefficient(num));
01105 Store_field(caml_return_value, 1, build_ocaml_coefficient(den));
01106 CAMLreturn(caml_return_value);
01107 }
01108 CATCH_ALL
01109
01110 extern "C"
01111 CAMLprim value
01112 ppl_MIP_Problem_evaluate_objective_function(value caml_mip,
01113 value caml_generator) try {
01114 CAMLparam2(caml_mip, caml_generator);
01115 CAMLlocal1(caml_return_value);
01116 Generator g = build_ppl_Generator(caml_generator);
01117 MIP_Problem& ppl_mip = *p_MIP_Problem_val(caml_mip);
01118 PPL_DIRTY_TEMP_COEFFICIENT(num);
01119 PPL_DIRTY_TEMP_COEFFICIENT(den);
01120 ppl_mip.evaluate_objective_function(g, num, den);
01121 caml_return_value = caml_alloc(2,0);
01122 Store_field(caml_return_value, 0, build_ocaml_coefficient(num));
01123 Store_field(caml_return_value, 1, build_ocaml_coefficient(den));
01124 CAMLreturn(caml_return_value);
01125 }
01126 CATCH_ALL
01127
01128 extern "C"
01129 CAMLprim value
01130 ppl_MIP_Problem_OK(value caml_mip) try {
01131 CAMLparam1(caml_mip);
01132 MIP_Problem& ppl_mip = *p_MIP_Problem_val(caml_mip);
01133 CAMLreturn(ppl_mip.OK());
01134 }
01135 CATCH_ALL
01136
01137 extern "C"
01138 CAMLprim value
01139 ppl_MIP_Problem_objective_function(value caml_mip) try {
01140 CAMLparam1(caml_mip);
01141 CAMLlocal4(homogeneous_term, inhomogeneous_term, sum, coeff);
01142 const MIP_Problem& ppl_mip = *p_MIP_Problem_val(caml_mip);
01143 const Linear_Expression& ppl_obj_func = ppl_mip.objective_function();
01144 homogeneous_term = get_linear_expression(ppl_obj_func);
01145 inhomogeneous_term
01146 = build_ocaml_coefficient(ppl_obj_func.inhomogeneous_term());
01147 coeff = caml_alloc(1,1);
01148 Store_field(coeff, 0, inhomogeneous_term);
01149 sum = caml_alloc(2,4);
01150 Store_field(sum, 0, homogeneous_term);
01151 Store_field(sum, 1, coeff);
01152 CAMLreturn(sum);
01153 }
01154 CATCH_ALL
01155
01156 extern "C"
01157 CAMLprim value
01158 ppl_MIP_Problem_clear(value caml_mip) try {
01159 CAMLparam1(caml_mip);
01160 MIP_Problem& ppl_mip = *p_MIP_Problem_val(caml_mip);
01161 ppl_mip.clear();
01162 CAMLreturn(Val_unit);
01163 }
01164 CATCH_ALL
01165
01166 extern "C"
01167 CAMLprim value
01168 ppl_MIP_Problem_set_optimization_mode(value caml_mip, value caml_opt_mode) try{
01169 CAMLparam2(caml_mip, caml_opt_mode);
01170 Optimization_Mode ppl_opt_mode= build_ppl_opt_mode(caml_opt_mode);
01171 MIP_Problem& ppl_mip = *p_MIP_Problem_val(caml_mip);
01172 ppl_mip.set_optimization_mode(ppl_opt_mode);
01173 CAMLreturn(Val_unit);
01174 }
01175 CATCH_ALL
01176
01177 extern "C"
01178 CAMLprim value
01179 ppl_MIP_Problem_swap(value caml_mip1, value caml_mip2) try{
01180 CAMLparam2(caml_mip1, caml_mip2);
01181 MIP_Problem& ppl_mip1 = *p_MIP_Problem_val(caml_mip1);
01182 MIP_Problem& ppl_mip2 = *p_MIP_Problem_val(caml_mip2);
01183 ppl_mip1.swap(ppl_mip2);
01184 CAMLreturn(Val_unit);
01185 }
01186 CATCH_ALL
01187
01188 extern "C"
01189 CAMLprim value
01190 ppl_MIP_Problem_ascii_dump(value caml_mip) try {
01191 CAMLparam1(caml_mip);
01192 MIP_Problem& mip = *p_MIP_Problem_val(caml_mip);
01193 std::ostringstream s;
01194 mip.ascii_dump(s);
01195 CAMLreturn(caml_copy_string(s.str().c_str()));
01196 }
01197 CATCH_ALL
01198
01199 extern "C"
01200 CAMLprim value
01201 ppl_new_PIP_Problem_from_space_dimension(value d) try {
01202 CAMLparam1(d);
01203 dimension_type dd = value_to_ppl_dimension(d);
01204 PIP_Problem& ppl_pip = *new PIP_Problem(dd);
01205 CAMLreturn(unregistered_value_p_PIP_Problem(ppl_pip));
01206 }
01207 CATCH_ALL
01208
01209 extern "C"
01210 CAMLprim value
01211 ppl_new_PIP_Problem(value d, value caml_cs, value caml_vset) try {
01212 CAMLparam3(d, caml_cs, caml_vset);
01213 dimension_type dd = value_to_ppl_dimension(d);
01214 Constraint_System ppl_cs = build_ppl_Constraint_System(caml_cs);
01215 Variables_Set ppl_vset;
01216 if (Int_val(caml_vset) == 0)
01217 CAMLreturn(Val_unit);
01218 while (true) {
01219 ppl_vset.insert(Int_val(Field(caml_vset, 0)));
01220 if (Int_val(Field(caml_vset, 1)) == 0)
01221 break;
01222 caml_vset = Field(caml_vset, 1);
01223 }
01224 PIP_Problem& ppl_pip = *new PIP_Problem(dd, ppl_cs.begin(), ppl_cs.end(),
01225 ppl_vset);
01226 CAMLreturn(unregistered_value_p_PIP_Problem(ppl_pip));
01227 }
01228 CATCH_ALL
01229
01230
01231 extern "C"
01232 CAMLprim value
01233 ppl_PIP_Problem_space_dimension(value pip) try {
01234 CAMLparam1(pip);
01235 const PIP_Problem& ppip = *p_PIP_Problem_val(pip);
01236 dimension_type d = ppip.space_dimension();
01237 CAMLreturn(ppl_dimension_to_value(d));
01238 }
01239 CATCH_ALL
01240
01241 extern "C"
01242 CAMLprim value
01243 ppl_PIP_Problem_parameter_space_dimensions(value caml_pip) try {
01244 CAMLparam1(caml_pip);
01245 CAMLlocal2(result, new_tail);
01246 PIP_Problem& ppl_pip = *p_PIP_Problem_val(caml_pip);
01247 const Variables_Set& ppl_ivars = ppl_pip.parameter_space_dimensions();
01248 result = Val_emptylist;
01249 for (Variables_Set::const_reverse_iterator i = ppl_ivars.rbegin(),
01250 i_end = ppl_ivars.rend(); i != i_end; ++i) {
01251 new_tail = caml_alloc_tuple(2);
01252 Store_field(new_tail, 0, ppl_dimension_to_value(*i));
01253 Store_field(new_tail, 1, result);
01254 result = new_tail;
01255 }
01256 CAMLreturn(result);
01257 }
01258 CATCH_ALL
01259
01260 extern "C"
01261 CAMLprim value
01262 ppl_PIP_Problem_constraints(value caml_pip) try {
01263 CAMLparam1(caml_pip);
01264 const PIP_Problem& ppl_pip = *p_PIP_Problem_val(caml_pip);
01265 Constraint_System cs;
01266 for (PIP_Problem::const_iterator cs_it = ppl_pip.constraints_begin(),
01267 cs_end = ppl_pip.constraints_end(); cs_it != cs_end; ++cs_it) {
01268 cs.insert(*cs_it);
01269 }
01270 CAMLreturn(build_ocaml_constraint_system(cs));
01271 }
01272 CATCH_ALL
01273
01274 extern "C"
01275 CAMLprim value
01276 ppl_PIP_Problem_add_space_dimensions_and_embed(value caml_pip,
01277 value vdim, value pdim) try {
01278 CAMLparam3(caml_pip, vdim, pdim);
01279 dimension_type ppl_vdim = value_to_ppl_dimension(vdim);
01280 dimension_type ppl_pdim = value_to_ppl_dimension(pdim);
01281 PIP_Problem& ppl_pip = *p_PIP_Problem_val(caml_pip);
01282 ppl_pip.add_space_dimensions_and_embed(ppl_vdim, ppl_pdim);
01283 CAMLreturn(Val_unit);
01284 }
01285 CATCH_ALL
01286
01287 extern "C"
01288 CAMLprim value
01289 ppl_PIP_Problem_add_to_parameter_space_dimensions(value caml_pip,
01290 value caml_ivars) try {
01291 CAMLparam2(caml_pip, caml_ivars);
01292 PIP_Problem& ppl_pip = *p_PIP_Problem_val(caml_pip);
01293 ppl_pip.add_to_parameter_space_dimensions
01294 (build_ppl_Variables_Set(caml_ivars));
01295 CAMLreturn(Val_unit);
01296 }
01297 CATCH_ALL
01298
01299 extern "C"
01300 CAMLprim value
01301 ppl_PIP_Problem_add_constraint(value caml_pip,
01302 value caml_constraint) try {
01303 CAMLparam2(caml_pip, caml_constraint);
01304 PIP_Problem& ppl_pip = *p_PIP_Problem_val(caml_pip);
01305 ppl_pip.add_constraint(build_ppl_Constraint(caml_constraint));
01306 CAMLreturn(Val_unit);
01307 }
01308 CATCH_ALL
01309
01310 extern "C"
01311 CAMLprim value
01312 ppl_PIP_Problem_add_constraints(value caml_pip,
01313 value caml_constraints) try {
01314 CAMLparam2(caml_pip, caml_constraints);
01315 PIP_Problem& ppl_pip = *p_PIP_Problem_val(caml_pip);
01316 ppl_pip.add_constraints(build_ppl_Constraint_System(caml_constraints));
01317 CAMLreturn(Val_unit);
01318 }
01319 CATCH_ALL
01320
01321 extern "C"
01322 CAMLprim value
01323 ppl_PIP_Problem_set_big_parameter_dimension(value caml_pip,
01324 value caml_dim) try {
01325 CAMLparam2(caml_pip, caml_dim);
01326 dimension_type ppl_dim = value_to_ppl_dimension(caml_dim);
01327 PIP_Problem& ppl_pip = *p_PIP_Problem_val(caml_pip);
01328 ppl_pip.set_big_parameter_dimension(ppl_dim);
01329 CAMLreturn(Val_unit);
01330 }
01331 CATCH_ALL
01332
01333 extern "C"
01334 CAMLprim value
01335 ppl_PIP_Problem_get_big_parameter_dimension(value caml_pip) try {
01336 CAMLparam1(caml_pip);
01337 PIP_Problem& ppl_pip = *p_PIP_Problem_val(caml_pip);
01338 dimension_type d = ppl_pip.get_big_parameter_dimension();
01339 if (d == not_a_dimension())
01340 throw std::invalid_argument("ppl_PIP_Problem_get_big_parameter_dimension"
01341 "(pip):\n"
01342 "big parameter dimension has not been set.");
01343 CAMLreturn(ppl_dimension_to_value(d));
01344 }
01345 CATCH_ALL
01346
01347 extern "C"
01348 CAMLprim value
01349 ppl_PIP_Problem_has_big_parameter_dimension(value caml_pip) try {
01350 CAMLparam1(caml_pip);
01351 PIP_Problem& ppl_pip = *p_PIP_Problem_val(caml_pip);
01352 dimension_type d = ppl_pip.get_big_parameter_dimension();
01353 CAMLreturn(Val_bool(d != not_a_dimension()));
01354 }
01355 CATCH_ALL
01356
01357 extern "C"
01358 CAMLprim value
01359 ppl_PIP_Problem_is_satisfiable(value caml_pip) try {
01360 CAMLparam1(caml_pip);
01361 PIP_Problem& ppl_pip = *p_PIP_Problem_val(caml_pip);
01362 CAMLreturn(ppl_pip.is_satisfiable());
01363 }
01364 CATCH_ALL
01365
01366 extern "C"
01367 CAMLprim value
01368 ppl_PIP_Problem_solve(value caml_pip) try {
01369 CAMLparam1(caml_pip);
01370 PIP_Problem& ppl_pip = *p_PIP_Problem_val(caml_pip);
01371 PIP_Problem_Status pip_status = ppl_pip.solve();
01372 switch (pip_status) {
01373 case UNFEASIBLE_PIP_PROBLEM:
01374 CAMLreturn(Val_int(0));
01375 case OPTIMIZED_PIP_PROBLEM:
01376 CAMLreturn(Val_int(1));
01377 default:
01378 ;
01379 }
01380
01381 throw std::runtime_error("PPL OCaml interface internal error");
01382 }
01383 CATCH_ALL
01384
01385 extern "C"
01386 CAMLprim value
01387 ppl_PIP_Problem_set_control_parameter(value caml_pip,
01388 value caml_cp_value) try {
01389 CAMLparam2(caml_pip, caml_cp_value);
01390 PIP_Problem& ppl_pip = *p_PIP_Problem_val(caml_pip);
01391 PIP_Problem::Control_Parameter_Value ppl_cp_value
01392 = build_ppl_pip_problem_control_parameter_value(caml_cp_value);
01393 ppl_pip.set_control_parameter(ppl_cp_value);
01394 CAMLreturn(Val_unit);
01395 }
01396 CATCH_ALL
01397
01398 extern "C"
01399 CAMLprim value
01400 ppl_PIP_Problem_get_control_parameter(value caml_pip,
01401 value caml_cp_name) try {
01402 CAMLparam2(caml_pip, caml_cp_name);
01403 PIP_Problem& ppl_pip = *p_PIP_Problem_val(caml_pip);
01404 PIP_Problem::Control_Parameter_Name ppl_cp_name
01405 = build_ppl_pip_problem_control_parameter_name(caml_cp_name);
01406 PIP_Problem::Control_Parameter_Value ppl_cp_value
01407 = ppl_pip.get_control_parameter(ppl_cp_name);
01408 switch (ppl_cp_value) {
01409 case PIP_Problem::CUTTING_STRATEGY_FIRST:
01410 CAMLreturn(Val_int(0));
01411 case PIP_Problem::CUTTING_STRATEGY_DEEPEST:
01412 CAMLreturn(Val_int(1));
01413 case PIP_Problem::CUTTING_STRATEGY_ALL:
01414 CAMLreturn(Val_int(2));
01415 case PIP_Problem::PIVOT_ROW_STRATEGY_FIRST:
01416 CAMLreturn(Val_int(3));
01417 case PIP_Problem::PIVOT_ROW_STRATEGY_MAX_COLUMN:
01418 CAMLreturn(Val_int(4));
01419 default:
01420 ;
01421 }
01422
01423 throw std::runtime_error("PPL OCaml interface internal error");
01424 }
01425 CATCH_ALL
01426
01427 extern "C"
01428 CAMLprim value
01429 ppl_PIP_Problem_solution(value caml_pip) try {
01430 CAMLparam1(caml_pip);
01431 PIP_Problem& ppl_pip = *p_PIP_Problem_val(caml_pip);
01432 const PIP_Tree_Node* ppl_node = ppl_pip.solution();
01433 CAMLreturn(unregistered_value_p_PIP_Tree_Node(ppl_node));
01434 }
01435 CATCH_ALL
01436
01437 extern "C"
01438 CAMLprim value
01439 ppl_PIP_Problem_optimizing_solution(value caml_pip) try {
01440 CAMLparam1(caml_pip);
01441 PIP_Problem& ppl_pip = *p_PIP_Problem_val(caml_pip);
01442 const PIP_Tree_Node* ppl_node = ppl_pip.optimizing_solution();
01443 CAMLreturn(unregistered_value_p_PIP_Tree_Node(ppl_node));
01444 }
01445 CATCH_ALL
01446
01447 extern "C"
01448 CAMLprim value
01449 ppl_PIP_Problem_OK(value caml_pip) try {
01450 CAMLparam1(caml_pip);
01451 PIP_Problem& ppl_pip = *p_PIP_Problem_val(caml_pip);
01452 CAMLreturn(Val_bool(ppl_pip.OK()));
01453 }
01454 CATCH_ALL
01455
01456 extern "C"
01457 CAMLprim value
01458 ppl_PIP_Problem_clear(value caml_pip) try {
01459 CAMLparam1(caml_pip);
01460 PIP_Problem& ppl_pip = *p_PIP_Problem_val(caml_pip);
01461 ppl_pip.clear();
01462 CAMLreturn(Val_unit);
01463 }
01464 CATCH_ALL
01465
01466 extern "C"
01467 CAMLprim value
01468 ppl_PIP_Problem_swap(value caml_pip1, value caml_pip2) try{
01469 CAMLparam2(caml_pip1, caml_pip2);
01470 PIP_Problem& ppl_pip1 = *p_PIP_Problem_val(caml_pip1);
01471 PIP_Problem& ppl_pip2 = *p_PIP_Problem_val(caml_pip2);
01472 ppl_pip1.swap(ppl_pip2);
01473 CAMLreturn(Val_unit);
01474 }
01475 CATCH_ALL
01476
01477 extern "C"
01478 CAMLprim value
01479 ppl_PIP_Problem_ascii_dump(value caml_pip) try {
01480 CAMLparam1(caml_pip);
01481 PIP_Problem& pip = *p_PIP_Problem_val(caml_pip);
01482 std::ostringstream s;
01483 pip.ascii_dump(s);
01484 CAMLreturn(caml_copy_string(s.str().c_str()));
01485 }
01486 CATCH_ALL
01487
01488 value
01489 build_ocaml_artificial_parameter(const PIP_Tree_Node::Artificial_Parameter&
01490 ppl_artificial_parameter) {
01491 CAMLparam0();
01492 CAMLlocal1(caml_artificial_parameter);
01493 caml_artificial_parameter = caml_alloc(2,0);
01494 Store_field(caml_artificial_parameter, 0,
01495 get_linear_expression(ppl_artificial_parameter));
01496 const Coefficient& denominator = ppl_artificial_parameter.denominator();
01497 Store_field(caml_artificial_parameter, 1,
01498 build_ocaml_coefficient(denominator));
01499 CAMLreturn(caml_artificial_parameter);
01500 }
01501
01502 extern "C"
01503 CAMLprim value
01504 ppl_PIP_Tree_Node_constraints(value caml_node) try {
01505 CAMLparam1(caml_node);
01506 const PIP_Tree_Node* ppl_node = p_PIP_Tree_Node_val(caml_node);
01507 if (ppl_node == 0)
01508 throw std::invalid_argument("ppl_PIP_Tree_Node_constraints(node):\n"
01509 "node is bottom.");
01510 const Constraint_System& ppl_cs = ppl_node->constraints();
01511 CAMLreturn(build_ocaml_constraint_system(ppl_cs));
01512 }
01513 CATCH_ALL
01514
01515 extern "C"
01516 CAMLprim value
01517 ppl_PIP_Tree_Node_is_bottom(value caml_node) try {
01518 CAMLparam1(caml_node);
01519 const PIP_Tree_Node* ppl_node = p_PIP_Tree_Node_val(caml_node);
01520 CAMLreturn(Val_bool(ppl_node == 0));
01521 }
01522 CATCH_ALL
01523
01524 extern "C"
01525 CAMLprim value
01526 ppl_PIP_Tree_Node_is_solution(value caml_node) try {
01527 CAMLparam1(caml_node);
01528 const PIP_Tree_Node* ppl_node = p_PIP_Tree_Node_val(caml_node);
01529 CAMLreturn(Val_bool(ppl_node != 0
01530 && ppl_node->as_solution() != 0));
01531 }
01532 CATCH_ALL
01533
01534 extern "C"
01535 CAMLprim value
01536 ppl_PIP_Tree_Node_is_decision(value caml_node) try {
01537 CAMLparam1(caml_node);
01538 const PIP_Tree_Node* ppl_node = p_PIP_Tree_Node_val(caml_node);
01539 CAMLreturn(Val_bool(ppl_node != 0
01540 && ppl_node->as_decision() != 0));
01541 }
01542 CATCH_ALL
01543
01544 extern "C"
01545 CAMLprim value
01546 ppl_PIP_Tree_Node_artificials(value caml_node) try {
01547 CAMLparam1(caml_node);
01548 CAMLlocal2(result, new_tail);
01549 const PIP_Tree_Node* ppl_node = p_PIP_Tree_Node_val(caml_node);
01550 if (ppl_node == 0)
01551 throw std::invalid_argument("ppl_PIP_Tree_Node_artificials(node):\n"
01552 "node is bottom.");
01553 for (PIP_Tree_Node::Artificial_Parameter_Sequence::const_iterator
01554 v_begin = ppl_node->art_parameter_begin(),
01555 v_end = ppl_node->art_parameter_end(); v_begin != v_end; ++v_begin) {
01556 new_tail = caml_alloc_tuple(2);
01557 Store_field(new_tail, 0, build_ocaml_artificial_parameter(*v_begin));
01558 Store_field(new_tail, 1, result);
01559 result = new_tail;
01560 }
01561 CAMLreturn(result);
01562 }
01563 CATCH_ALL
01564
01565 extern "C"
01566 CAMLprim value
01567 ppl_PIP_Tree_Node_OK(value caml_node) try {
01568 CAMLparam1(caml_node);
01569 const PIP_Tree_Node* ppl_node = p_PIP_Tree_Node_val(caml_node);
01570 if (ppl_node == 0)
01571 throw std::invalid_argument("ppl_PIP_Tree_Node_OK(node):\n"
01572 "node is bottom.");
01573 CAMLreturn(Val_bool(ppl_node->OK()));
01574 }
01575 CATCH_ALL
01576
01577 extern "C"
01578 CAMLprim value
01579 ppl_PIP_Tree_Node_ascii_dump(value caml_node) try {
01580 CAMLparam1(caml_node);
01581 const PIP_Tree_Node* ppl_node = p_PIP_Tree_Node_val(caml_node);
01582 if (ppl_node == 0)
01583 throw std::invalid_argument("ppl_PIP_Tree_Node_ascii_dump(node):\n"
01584 "node is bottom.");
01585 std::ostringstream s;
01586 ppl_node->ascii_dump(s);
01587 CAMLreturn(caml_copy_string(s.str().c_str()));
01588 }
01589 CATCH_ALL
01590
01591 extern "C"
01592 CAMLprim value
01593 ppl_PIP_Tree_Node_parametric_values(value caml_node,
01594 value caml_dim) try {
01595 CAMLparam2(caml_node, caml_dim);
01596 const PIP_Tree_Node* ppl_node = p_PIP_Tree_Node_val(caml_node);
01597 if (ppl_node == 0)
01598 throw std::invalid_argument("ppl_PIP_Tree_Node_get_parametric_values"
01599 "(node, dim):\n"
01600 "node is not a solution node (bottom).");
01601 const PIP_Solution_Node* ppl_sol = ppl_node->as_solution();
01602 if (ppl_sol == 0)
01603 throw std::invalid_argument("ppl_PIP_Tree_Node_get_parametric_values"
01604 "(node, dim):\n"
01605 "node is not a solution node (decision).");
01606 Variable var(Int_val(caml_dim));
01607 const Linear_Expression& ppl_le = ppl_sol->parametric_values(var);
01608 CAMLreturn(get_linear_expression(ppl_le));
01609 }
01610 CATCH_ALL
01611
01612 extern "C"
01613 CAMLprim value
01614 ppl_PIP_Tree_Node_true_child(value caml_node) try {
01615 CAMLparam1(caml_node);
01616 const PIP_Tree_Node* ppl_node = p_PIP_Tree_Node_val(caml_node);
01617 const PIP_Tree_Node* child = ppl_PIP_Tree_Node_get_child(ppl_node, true);
01618 CAMLreturn(unregistered_value_p_PIP_Tree_Node(child));
01619 }
01620 CATCH_ALL
01621
01622 extern "C"
01623 CAMLprim value
01624 ppl_PIP_Tree_Node_false_child(value caml_node) try {
01625 CAMLparam1(caml_node);
01626 const PIP_Tree_Node* ppl_node = p_PIP_Tree_Node_val(caml_node);
01627 const PIP_Tree_Node* child = ppl_PIP_Tree_Node_get_child(ppl_node, false);
01628 CAMLreturn(unregistered_value_p_PIP_Tree_Node(child));
01629 }
01630 CATCH_ALL
01631
01632 extern "C"
01633 CAMLprim value
01634 ppl_version_major(value unit) try {
01635 CAMLparam1(unit);
01636 CAMLreturn(Val_long(version_major()));
01637 }
01638 CATCH_ALL
01639
01640 extern "C"
01641 CAMLprim value
01642 ppl_version_minor(value unit) try {
01643 CAMLparam1(unit);
01644 CAMLreturn(Val_long(version_minor()));
01645 }
01646 CATCH_ALL
01647
01648 extern "C"
01649 CAMLprim value
01650 ppl_version_revision(value unit) try {
01651 CAMLparam1(unit);
01652 CAMLreturn(Val_long(version_revision()));
01653 }
01654 CATCH_ALL
01655
01656 extern "C"
01657 CAMLprim value
01658 ppl_version_beta(value unit) try {
01659 CAMLparam1(unit);
01660 CAMLreturn(Val_long(version_beta()));
01661 }
01662 CATCH_ALL
01663
01664 extern "C"
01665 CAMLprim value
01666 ppl_version(value unit) try {
01667 CAMLparam1(unit);
01668 CAMLreturn(caml_copy_string(version()));
01669 }
01670 CATCH_ALL
01671
01672 extern "C"
01673 CAMLprim value
01674 ppl_banner(value unit) try {
01675 CAMLparam1(unit);
01676 CAMLreturn(caml_copy_string(banner()));
01677 }
01678 CATCH_ALL
01679
01680 extern "C"
01681 CAMLprim value
01682 ppl_io_wrap_string(value src,
01683 value indent_depth,
01684 value preferred_first_line_length,
01685 value preferred_line_length) try {
01686 CAMLparam4(src, indent_depth, preferred_first_line_length,
01687 preferred_line_length);
01688 unsigned cpp_indent_depth
01689 = value_to_unsigned<unsigned>(indent_depth);
01690 unsigned cpp_preferred_first_line_length
01691 = value_to_unsigned<unsigned>(preferred_first_line_length);
01692 unsigned cpp_preferred_line_length
01693 = value_to_unsigned<unsigned>(preferred_line_length);
01694 using IO_Operators::wrap_string;
01695 CAMLreturn(caml_copy_string(wrap_string(String_val(src),
01696 cpp_indent_depth,
01697 cpp_preferred_first_line_length,
01698 cpp_preferred_line_length
01699 ).c_str()));
01700 }
01701 CATCH_ALL
01702
01703 extern "C"
01704 CAMLprim value
01705 ppl_Coefficient_bits(value unit) try {
01706 CAMLparam1(unit);
01707 CAMLreturn(Val_long(PPL_COEFFICIENT_BITS));
01708 }
01709 CATCH_ALL
01710
01711 extern "C"
01712 CAMLprim value
01713 ppl_Coefficient_is_bounded(value unit) try {
01714 CAMLparam1(unit);
01715 CAMLreturn(std::numeric_limits<Coefficient>::is_bounded
01716 ? Val_true : Val_false);
01717 }
01718 CATCH_ALL
01719
01720 extern "C"
01721 CAMLprim value
01722 ppl_Coefficient_min(value unit) try {
01723 CAMLparam1(unit);
01724 if (std::numeric_limits<Coefficient>::is_bounded) {
01725 const Coefficient& min = std::numeric_limits<Coefficient>::min();
01726 CAMLreturn(build_ocaml_coefficient(min));
01727 }
01728 else
01729 CAMLreturn(Val_unit);
01730 }
01731 CATCH_ALL
01732
01733 extern "C"
01734 CAMLprim value
01735 ppl_Coefficient_max(value unit) try {
01736 CAMLparam1(unit);
01737 if (std::numeric_limits<Coefficient>::is_bounded) {
01738 const Coefficient& max = std::numeric_limits<Coefficient>::max();
01739 CAMLreturn(build_ocaml_coefficient(max));
01740 }
01741 else
01742 CAMLreturn(Val_unit);
01743 }
01744 CATCH_ALL
01745
01746 extern "C"
01747 CAMLprim value
01748 ppl_max_space_dimension(value unit) try {
01749 CAMLparam1(unit);
01750 dimension_type d = max_space_dimension();
01751 CAMLreturn(ppl_dimension_to_value(d));
01752 }
01753 CATCH_ALL
01754
01755 extern "C"
01756 CAMLprim value
01757 ppl_Linear_Expression_is_zero(value ocaml_le) try {
01758 CAMLparam1(ocaml_le);
01759 CAMLreturn(build_ppl_Linear_Expression(ocaml_le).is_zero()
01760 ? Val_true : Val_false);
01761 }
01762 CATCH_ALL
01763
01764 extern "C"
01765 CAMLprim value
01766 ppl_Linear_Expression_all_homogeneous_terms_are_zero(value ocaml_le) try {
01767 CAMLparam1(ocaml_le);
01768 CAMLreturn(build_ppl_Linear_Expression(ocaml_le).
01769 all_homogeneous_terms_are_zero()
01770 ? Val_true : Val_false);
01771 }
01772 CATCH_ALL
01773
01774 extern "C"
01775 CAMLprim value
01776 ppl_set_rounding_for_PPL(value unit) try {
01777 CAMLparam1(unit);
01778 set_rounding_for_PPL();
01779 CAMLreturn(Val_unit);
01780 }
01781 CATCH_ALL
01782
01783 extern "C"
01784 CAMLprim value
01785 ppl_restore_pre_PPL_rounding(value unit) try {
01786 CAMLparam1(unit);
01787 restore_pre_PPL_rounding();
01788 CAMLreturn(Val_unit);
01789 }
01790 CATCH_ALL
01791
01792 extern "C"
01793 CAMLprim value
01794 ppl_irrational_precision(value unit) try {
01795 CAMLparam1(unit);
01796 CAMLreturn(Val_long(irrational_precision()));
01797 }
01798 CATCH_ALL
01799
01800 extern "C"
01801 CAMLprim value
01802 ppl_set_irrational_precision(value p) try {
01803 CAMLparam1(p);
01804 unsigned cxx_p = value_to_unsigned<unsigned>(p);
01805 set_irrational_precision(cxx_p);
01806 CAMLreturn(Val_unit);
01807 }
01808 CATCH_ALL
01809
01810 extern "C"
01811 CAMLprim value
01812 ppl_set_timeout(value time) try {
01813 CAMLparam1(time);
01814 #ifndef PPL_WATCHDOG_LIBRARY_ENABLED
01815 const char* what = "PPL OCaml interface usage error:\n"
01816 "ppl_set_timeout: the PPL Watchdog library is not enabled.";
01817 throw std::runtime_error(what);
01818 #else
01819
01820 reset_timeout();
01821 unsigned cpp_time = value_to_unsigned<unsigned>(time);
01822 static timeout_exception e;
01823 using Parma_Watchdog_Library::Watchdog;
01824 p_timeout_object = new Watchdog(cpp_time, abandon_expensive_computations, e);
01825 CAMLreturn(Val_unit);
01826 #endif // PPL_WATCHDOG_LIBRARY_ENABLED
01827 }
01828 CATCH_ALL
01829
01830 extern "C"
01831 CAMLprim value
01832 ppl_reset_timeout(value unit) try {
01833 CAMLparam1(unit);
01834 #ifndef PPL_WATCHDOG_LIBRARY_ENABLED
01835 throw std::runtime_error("PPL OCaml interface error:\n"
01836 "the PPL Watchdog library is not enabled.");
01837 #else
01838 reset_timeout();
01839 CAMLreturn(Val_unit);
01840 #endif // PPL_WATCHDOG_LIBRARY_ENABLED
01841 }
01842 CATCH_ALL
01843
01844 extern "C"
01845 CAMLprim value
01846 ppl_set_deterministic_timeout(value weight) try {
01847 CAMLparam1(weight);
01848 #ifndef PPL_WATCHDOG_LIBRARY_ENABLED
01849 const char* what = "PPL OCaml interface usage error:\n"
01850 "ppl_set_deterministic_timeout: the PPL Watchdog library is not enabled.";
01851 throw std::runtime_error(what);
01852 #else
01853
01854 reset_deterministic_timeout();
01855 unsigned cpp_weight = value_to_unsigned<unsigned>(weight);
01856 static deterministic_timeout_exception e;
01857 p_deterministic_timeout_object
01858 = new Weightwatch(cpp_weight, abandon_expensive_computations, e);
01859 CAMLreturn(Val_unit);
01860 #endif // PPL_WATCHDOG_LIBRARY_ENABLED
01861 }
01862 CATCH_ALL
01863
01864 extern "C"
01865 CAMLprim value
01866 ppl_reset_deterministic_timeout(value unit) try {
01867 CAMLparam1(unit);
01868 #ifndef PPL_WATCHDOG_LIBRARY_ENABLED
01869 throw std::runtime_error("PPL OCaml interface error:\n"
01870 "the PPL Watchdog library is not enabled.");
01871 #else
01872 reset_deterministic_timeout();
01873 CAMLreturn(Val_unit);
01874 #endif // PPL_WATCHDOG_LIBRARY_ENABLED
01875 }
01876 CATCH_ALL