[GIT] ppl/ppl(master): Simplified Prolog interface for PIP_Tree_Node.

Module: ppl/ppl Branch: master Commit: 97c151b721fbfa9963d9b873355b163181f0d07b URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=97c151b721fbf...
Author: Patricia Hill p.m.hill@leeds.ac.uk Date: Thu Apr 8 12:06:01 2010 +0100
Simplified Prolog interface for PIP_Tree_Node.
---
...erface_generator_prolog_procedure_generators.m4 | 11 +++-- interfaces/Prolog/ppl_prolog_common.cc | 46 ++++++++++---------- interfaces/Prolog/ppl_prolog_common.defs.hh | 23 +++++----- interfaces/Prolog/tests/pl_check.pl | 34 +++++++------- 4 files changed, 58 insertions(+), 56 deletions(-)
diff --git a/interfaces/Prolog/ppl_interface_generator_prolog_procedure_generators.m4 b/interfaces/Prolog/ppl_interface_generator_prolog_procedure_generators.m4 index 1d80e1c..cfd158b 100644 --- a/interfaces/Prolog/ppl_interface_generator_prolog_procedure_generators.m4 +++ b/interfaces/Prolog/ppl_interface_generator_prolog_procedure_generators.m4 @@ -107,13 +107,14 @@ ppl_PIP_Problem_optimizing_solution/2, ppl_PIP_Problem_OK/1, ppl_PIP_Problem_ascii_dump/1, ppl_PIP_Tree_Node_constraints/2, -ppl_PIP_Tree_Node_as_solution/2, -ppl_PIP_Tree_Node_as_decision/2, +ppl_PIP_Tree_Node_is_solution/1, +ppl_PIP_Tree_Node_is_decision/1, +ppl_PIP_Tree_Node_is_bottom/1, ppl_PIP_Tree_Node_artificials/2, ppl_PIP_Tree_Node_OK/1, -ppl_PIP_Solution_Node_get_parametric_values/3, -ppl_PIP_Decision_Node_get_true_child/2, -ppl_PIP_Decision_Node_get_false_child/2`'dnl +ppl_PIP_Tree_Node_parametric_values/3, +ppl_PIP_Tree_Node_true_child/2, +ppl_PIP_Tree_Node_false_child/2`'dnl ')
m4_define(`m4_procedure_list', diff --git a/interfaces/Prolog/ppl_prolog_common.cc b/interfaces/Prolog/ppl_prolog_common.cc index fbb985d..cf55e9a 100644 --- a/interfaces/Prolog/ppl_prolog_common.cc +++ b/interfaces/Prolog/ppl_prolog_common.cc @@ -2996,43 +2996,43 @@ ppl_PIP_Tree_Node_constraints(Prolog_term_ref t_pip, }
extern "C" Prolog_foreign_return_type -ppl_PIP_Tree_Node_as_solution(Prolog_term_ref t_pip, - Prolog_term_ref t_sol) { +ppl_PIP_Tree_Node_is_solution(Prolog_term_ref t_pip) { static const char* where = "ppl_PIP_Tree_Node_as_solution/2"; try { const PIP_Tree_Node* pip = term_to_handle<PIP_Tree_Node>(t_pip, where); PPL_CHECK(pip);
- PIP_Solution_Node* sol = const_cast<PIP_Solution_Node*>(pip->as_solution()); - if (sol == 0) - return PROLOG_FAILURE; - Prolog_term_ref t_ppl_sol = Prolog_new_term_ref(); - Prolog_put_address(t_ppl_sol, sol); - if (Prolog_unify(t_sol, t_ppl_sol)) { - PPL_WEAK_REGISTER(sol); + if (pip != 0 && pip->as_solution() != 0) return PROLOG_SUCCESS; - } + return PROLOG_FAILURE; } CATCH_ALL; }
extern "C" Prolog_foreign_return_type -ppl_PIP_Tree_Node_as_decision(Prolog_term_ref t_pip, - Prolog_term_ref t_dec) { +ppl_PIP_Tree_Node_is_decision(Prolog_term_ref t_pip) { static const char* where = "ppl_PIP_Tree_Node_as_decision/2"; try { const PIP_Tree_Node* pip = term_to_handle<PIP_Tree_Node>(t_pip, where); PPL_CHECK(pip);
- PIP_Decision_Node* dec = const_cast<PIP_Decision_Node*>(pip->as_decision()); - if (dec == 0) - return PROLOG_FAILURE; - Prolog_term_ref t_ppl_dec = Prolog_new_term_ref(); - Prolog_put_address(t_ppl_dec, dec); - if (Prolog_unify(t_dec, t_ppl_dec)) { - PPL_WEAK_REGISTER(dec); + if (pip != 0 && pip->as_decision() != 0) return PROLOG_SUCCESS; - } + return PROLOG_FAILURE; + } + CATCH_ALL; +} + +extern "C" Prolog_foreign_return_type +ppl_PIP_Tree_Node_is_bottom(Prolog_term_ref t_pip) { + static const char* where = "ppl_PIP_Tree_Node_as_decision/2"; + try { + const PIP_Tree_Node* pip = term_to_handle<PIP_Tree_Node>(t_pip, where); + PPL_CHECK(pip); + + if (pip == 0) + return PROLOG_SUCCESS; + return PROLOG_FAILURE; } CATCH_ALL; } @@ -3060,7 +3060,7 @@ ppl_PIP_Tree_Node_artificials(Prolog_term_ref t_tree_node, }
extern "C" Prolog_foreign_return_type -ppl_PIP_Solution_Node_get_parametric_values(Prolog_term_ref t_pip, +ppl_PIP_Tree_Node_parametric_values(Prolog_term_ref t_pip, Prolog_term_ref t_var, Prolog_term_ref t_le) { static const char* where = "ppl_PIP_Solution_Node_get_parametric_values/3"; @@ -3076,7 +3076,7 @@ ppl_PIP_Solution_Node_get_parametric_values(Prolog_term_ref t_pip, }
extern "C" Prolog_foreign_return_type -ppl_PIP_Decision_Node_get_true_child(Prolog_term_ref t_pip, +ppl_PIP_Tree_Node_true_child(Prolog_term_ref t_pip, Prolog_term_ref t_ptree) { static const char* where = "ppl_PIP_Decision_Node_get_true_child/2"; try { @@ -3096,7 +3096,7 @@ ppl_PIP_Decision_Node_get_true_child(Prolog_term_ref t_pip, }
extern "C" Prolog_foreign_return_type -ppl_PIP_Decision_Node_get_false_child(Prolog_term_ref t_pip, +ppl_PIP_Tree_Node_false_child(Prolog_term_ref t_pip, Prolog_term_ref t_ptree) { static const char* where = "ppl_PIP_Decision_Node_get_false_child/2"; try { diff --git a/interfaces/Prolog/ppl_prolog_common.defs.hh b/interfaces/Prolog/ppl_prolog_common.defs.hh index 337b9fc..53a9b63 100644 --- a/interfaces/Prolog/ppl_prolog_common.defs.hh +++ b/interfaces/Prolog/ppl_prolog_common.defs.hh @@ -1046,12 +1046,13 @@ ppl_PIP_Tree_Node_constraints(Prolog_term_ref t_tree_node, Prolog_term_ref t_clist);
extern "C" Prolog_foreign_return_type -ppl_PIP_Tree_Node_as_solution(Prolog_term_ref t_tree_node, - Prolog_term_ref t_sol_node); +ppl_PIP_Tree_Node_is_solution(Prolog_term_ref t_tree_node);
extern "C" Prolog_foreign_return_type -ppl_PIP_Tree_Node_as_decision(Prolog_term_ref t_tree_node, - Prolog_term_ref t_dec_node); +ppl_PIP_Tree_Node_is_decision(Prolog_term_ref t_tree_node); + +extern "C" Prolog_foreign_return_type +ppl_PIP_Tree_Node_is_bottom(Prolog_term_ref t_tree_node);
extern "C" Prolog_foreign_return_type ppl_PIP_Tree_Node_artificials(Prolog_term_ref t_tree_node, @@ -1061,17 +1062,17 @@ extern "C" Prolog_foreign_return_type ppl_PIP_Tree_Node_OK(Prolog_term_ref t_pip_tree);
extern "C" Prolog_foreign_return_type -ppl_PIP_Solution_Node_get_parametric_values(Prolog_term_ref t_pip_sol, - Prolog_term_ref t_var, - Prolog_term_ref t_pvalue_list); +ppl_PIP_Tree_Node_parametric_values(Prolog_term_ref t_pip_sol, + Prolog_term_ref t_var, + Prolog_term_ref t_pvalue_list);
extern "C" Prolog_foreign_return_type -ppl_PIP_Decision_Node_get_true_child(Prolog_term_ref t_pip_dec, - Prolog_term_ref t_pip_tree); +ppl_PIP_Tree_Node_true_child(Prolog_term_ref t_pip_dec, + Prolog_term_ref t_pip_tree);
extern "C" Prolog_foreign_return_type -ppl_PIP_Decision_Node_get_false_child(Prolog_term_ref t_pip_dec, - Prolog_term_ref t_pip_tree); +ppl_PIP_Tree_Node_false_child(Prolog_term_ref t_pip_dec, + Prolog_term_ref t_pip_tree);
using namespace Parma_Polyhedra_Library; using namespace Parma_Polyhedra_Library::Interfaces::Prolog; diff --git a/interfaces/Prolog/tests/pl_check.pl b/interfaces/Prolog/tests/pl_check.pl index e70d85a..83d3e48 100644 --- a/interfaces/Prolog/tests/pl_check.pl +++ b/interfaces/Prolog/tests/pl_check.pl @@ -2464,29 +2464,29 @@ pip_solution :- make_vars(4, [I, J, M, N]), clean_ppl_new_PIP_Problem( 4, [3*J >= -2*I + 8, J =< 4*I - 4, J =< M, I =< N], [M,N], PIP), - ppl_PIP_Problem_solution(PIP, Tree_Node), - ppl_PIP_Tree_Node_artificials(Tree_Node, Artificials), + ppl_PIP_Problem_solution(PIP, Node), + ppl_PIP_Tree_Node_artificials(Node, Artificials), Artificials = [], - + ppl_PIP_Tree_Node_as_solution(Tree_Node, _Sol), - ppl_PIP_Tree_Node_constraints(Tree_Node, _CS), - ppl_PIP_Tree_Node_as_decision(Tree_Node, Dec), - ppl_PIP_Tree_Node_constraints(Dec, _CS1), - ppl_PIP_Decision_Node_get_true_child(Dec, TChild), - ppl_PIP_Decision_Node_get_false_child(Dec, _FChild), - ppl_PIP_Tree_Node_as_decision(TChild, TChild_Dec), - ppl_PIP_Decision_Node_get_true_child(TChild_Dec, TTChild), - + ppl_PIP_Tree_Node_as_decision(TTChild, _TTChild_Dec), - ppl_PIP_Tree_Node_as_solution(TTChild, TTChild_Sol), - ppl_PIP_Solution_Node_get_parametric_values(TTChild_Sol, I, _TPV), - ppl_PIP_Decision_Node_get_false_child(TChild_Dec, FTChild), + + ppl_PIP_Tree_Node_is_solution(Node), + ppl_PIP_Tree_Node_constraints(Node, _CS), + ppl_PIP_Tree_Node_is_decision(Node), + ppl_PIP_Tree_Node_constraints(Node, _CS1), + ppl_PIP_Tree_Node_true_child(Node, TChild), + ppl_PIP_Tree_Node_false_child(Node, _FChild), + ppl_PIP_Tree_Node_is_decision(TChild), + ppl_PIP_Tree_Node_true_child(TChild, TTChild), + + ppl_PIP_Tree_Node_is_decision(TTChild), + ppl_PIP_Tree_Node_is_solution(TTChild), + ppl_PIP_Tree_Node_parametric_values(TTChild, I, _TPV), + ppl_PIP_Tree_Node_false_child(TChild, FTChild), ppl_PIP_Tree_Node_artificials(FTChild, FTChild_Artificials), FTChild_Artificials = [Art_LinExpr/Art_Den], compare_lin_expressions(Art_LinExpr, M), Art_Den = 2, - ppl_PIP_Tree_Node_as_solution(FTChild, FTChild_Sol), - ppl_PIP_Solution_Node_get_parametric_values(FTChild_Sol, I, _FPV), + ppl_PIP_Tree_Node_is_solution(FTChild), + ppl_PIP_Tree_Node_parametric_values(FTChild, I, _FPV), ppl_PIP_Problem_OK(PIP), - ppl_PIP_Tree_Node_OK(Tree_Node), + ppl_PIP_Tree_Node_OK(Node), !, ppl_delete_PIP_Problem(PIP).
participants (1)
-
Patricia Hill