
Module: ppl/ppl Branch: pip Commit: 4002ecca8f7a3b0400289e1998f3bb3b068a2c9a URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=4002ecca8f7a3...
Author: Patricia Hill p.m.hill@leeds.ac.uk Date: Fri Oct 9 23:25:07 2009 +0100
More functions for the C interface to the PIP Tree class - in particular, corresponding to the PIP_Solution_Node and PIP_Decision_Node C++ methods.
Various small bugs fixed in the PIP_Problem C interface code.
---
interfaces/C/ppl_c_header.h | 91 ++++++++++++++++++++------- interfaces/C/ppl_c_implementation_common.cc | 59 +++++++++++++++++ 2 files changed, 127 insertions(+), 23 deletions(-)
diff --git a/interfaces/C/ppl_c_header.h b/interfaces/C/ppl_c_header.h index 142431c..8d48fbe 100644 --- a/interfaces/C/ppl_c_header.h +++ b/interfaces/C/ppl_c_header.h @@ -2768,7 +2768,7 @@ int ppl_PIP_Problem_solve PPL_PROTO((ppl_const_PIP_Problem_t pip));
/*! \relates ppl_PIP_Problem_tag \brief - Returns a feasible solution for \p *this, if it exists. + Writes to \p pip_tree a solution for \p pip, if it exists.
\param pip The PIP problem; @@ -2784,7 +2784,7 @@ ppl_PPL_Problem_solution PPL_PROTO((ppl_const_PIP_Problem_t pip, ppl_const_PIP_Tree_Node_t* pip_tree));
/*! \relates ppl_PIP_Problem_tag \brief - Returns an optimizing solution for \p *this, if it exists. + Writes to \p pip_tree an optimizing solution for \p pip, if it exists.
\param pip The PIP problem; @@ -2793,7 +2793,7 @@ ppl_PPL_Problem_solution PPL_PROTO((ppl_const_PIP_Problem_t pip, The PIP tree;
\exception std::domain_error - Thrown if \p *this doesn't not have an optimizing point, i.e., + Thrown if \p pip does not not have an optimizing point, i.e., if the PIP problem is unbounded or not satisfiable. */ int @@ -2803,25 +2803,9 @@ PPL_PROTO((ppl_const_PIP_Problem_t pip,
/*@}*/ /* Computing the Solution of the PIP_Problem */
-/*! \brief \name Querying/Setting Control Parameters */ -/*@{*/ - -/*! \relates ppl_PIP_Problem_tag \brief - Returns the value of control parameter \p name in problem \p pip. -*/ -int -ppl_PIP_Problem_get_control_parameter -PPL_PROTO((ppl_const_PIP_Problem_t pip, int name)); - -/*! \relates ppl_PIP_Problem_tag \brief - Sets control parameter \p value in problem \p pip. -*/ -int -ppl_PIP_Problem_set_control_parameter -PPL_PROTO((ppl_PIP_Problem_t pip, int value)); - /*! \relates ppl_PIP_Problem_tag \brief - Returns \p this if \p *this is a solution node, 0 otherwise. + Writes to \p dpip_tree the solution node if \p spip_tree is + a solution node, and 0 otherwise. */ int ppl_PIP_Tree_Node_as_solution @@ -2829,7 +2813,8 @@ PPL_PROTO((ppl_const_PIP_Tree_Node_t spip_tree, ppl_const_PIP_Solution_Node_t* dpip_tree));
/*! \relates ppl_PIP_Problem_tag \brief - Returns \p this if \p *this is a decision node, 0 otherwise. + Writes to \p dpip_tree the decision node if \p spip_tree + is a decision node, and 0 otherwise. */ int ppl_PIP_Tree_Node_as_decision @@ -2837,7 +2822,8 @@ PPL_PROTO((ppl_const_PIP_Tree_Node_t spip_tree, ppl_const_PIP_Decision_Node_t* dpip_tree));
/*! \relates ppl_PIP_Problem_tag \brief - Returns the value of control parameter \p name in problem \p pip. + Writes to \p pcs the local system of parameter constraints + at the pip tree node \p pip_tree. */ int ppl_PIP_Tree_Node_get_constraints @@ -2899,6 +2885,61 @@ PPL_PROTO((ppl_const_PIP_Tree_Node_t pip_tree, ppl_dimension_type inserted));
/*! \relates ppl_PIP_Problem_tag \brief + Builds a trivial PIP problem of dimension \p d and writes an + handle to it at address \p pmip. +*/ +int +ppl_new_PIP_Solution_Node PPL_PROTO((ppl_PIP_Solution_Node_t* ppip_sol)); + +/*! \relates ppl_PIP_Problem_tag \brief + Invalidates the handle \p pip_sol: this makes sure the corresponding + resources will eventually be released. +*/ +int +ppl_delete_PIP_Solution_Node PPL_PROTO((ppl_const_PIP_Solution_Node_t pip_sol)); + +/*! \relates ppl_PIP_Problem_tag \brief + Writes to \p le a parametric expression of the values of variable \p v. + + The returned linear expression only involves parameters. + + \param v + the variable which is queried about + + \param pars + a \c std::set of indices of the parameters in the constraints + + \exception std::invalid_argument + Thrown if \p v is dimension-incompatible with \p *this + or if \p v is a parameter. +*/ +int +ppl_PIP_Solution_Node_get_parametric_values +PPL_PROTO((ppl_const_PIP_Solution_Node_t pip_sol, + ppl_dimension_type v, + ppl_dimension_type pars[], + size_t n, + ppl_Linear_Expression_t le)); + + +/*! \relates ppl_PIP_Problem_tag \brief + Invalidates the handle \p pip_dec: this makes sure the corresponding + resources will eventually be released. +*/ +int +ppl_delete_PIP_Decision_Node PPL_PROTO((ppl_const_PIP_Decision_Node_t pip_dec)); + +/*! \relates ppl_PIP_Problem_tag \brief + Writes to \p pip_tree a const pointer to the \p b (true or false) branch + of \p pip_dec. +*/ +int +ppl_PIP_Decision_Node_get_child_node +PPL_PROTO((ppl_const_PIP_Decision_Node_t pip_dec, + int b, + ppl_const_PIP_Tree_Node_t* pip_tree)); + +/*! \relates ppl_PIP_Problem_tag \brief Creates a new artificial parameter corresponding to the constant 0 in a zero-dimensional space; writes a handle for the new artificial parameter at address \p pap. @@ -2942,6 +2983,10 @@ PPL_DECLARE_AND_DOCUMENT_IO_FUNCTIONS(PIP_Problem)
PPL_DECLARE_AND_DOCUMENT_IO_FUNCTIONS(PIP_Tree_Node)
+PPL_DECLARE_AND_DOCUMENT_IO_FUNCTIONS(PIP_Solution_Node) + +PPL_DECLARE_AND_DOCUMENT_IO_FUNCTIONS(PIP_Decision_Node) + PPL_DECLARE_AND_DOCUMENT_IO_FUNCTIONS(Artificial_Parameter)
#include "ppl_c_domains.h" diff --git a/interfaces/C/ppl_c_implementation_common.cc b/interfaces/C/ppl_c_implementation_common.cc index 9ff417c..e1201b8 100644 --- a/interfaces/C/ppl_c_implementation_common.cc +++ b/interfaces/C/ppl_c_implementation_common.cc @@ -2321,6 +2321,65 @@ ppl_PIP_Tree_Node_insert_artificials(ppl_const_PIP_Tree_Node_t pip_tree, CATCH_ALL
int +ppl_new_PIP_Solution_Node(ppl_PIP_Solution_Node_t* ppip_sol) try { + *ppip_sol = to_nonconst(new PIP_Solution_Node()); + return 0; +} +CATCH_ALL + +int +ppl_delete_PIP_Solution_Node(ppl_const_PIP_Solution_Node_t pip_sol) try { + delete to_const(pip_sol); + return 0; +} +CATCH_ALL + +int +ppl_PIP_Solution_Node_get_parametric_values + (ppl_const_PIP_Solution_Node_t pip_sol, + ppl_dimension_type v, + ppl_dimension_type pars[], + size_t n, + ppl_const_Linear_Expression_t* le) try { + const PIP_Solution_Node& spip_sol = *to_const(pip_sol); + Variables_Set vars; + for (ppl_dimension_type i = n; i-- > 0; ) + vars.insert(pars[i]); + const Linear_Expression& lle = spip_sol.parametric_values(Variable(v),vars); + *le = to_const(&lle); + return 0; +} +CATCH_ALL + +int +ppl_PIP_Solution_Node_OK(ppl_const_PIP_Solution_Node_t pip_sol) try { + return to_const(pip_sol)->OK() ? 1 : 0; +} +CATCH_ALL + +int +ppl_delete_PIP_Decision_Node(ppl_const_PIP_Decision_Node_t pip_dec) try { + delete to_const(pip_dec); + return 0; +} +CATCH_ALL + +int +ppl_PIP_Decision_Node_OK(ppl_const_PIP_Decision_Node_t pip_dec) try { + return to_const(pip_dec)->OK() ? 1 : 0; +} +CATCH_ALL + +int +ppl_PIP_Decision_Node_get_child_node(ppl_const_PIP_Decision_Node_t pip_dec, + int b, + ppl_const_PIP_Tree_Node_t* pip_tree) try { + *pip_tree = to_const(to_const(pip_dec)->child_node(b)); + return 0; +} +CATCH_ALL + +int ppl_new_Artificial_Parameter(ppl_Artificial_Parameter_t* pap) try { *pap = to_nonconst(new Artificial_Parameter()); return 0;