[GIT] ppl/ppl(pip): Prefer not_a_dimension() as a marker if the big parameter is not set.

Module: ppl/ppl Branch: pip Commit: 06c6a3408fb5967bb29230306b4f71f02120dbd0 URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=06c6a3408fb59...
Author: Enea Zaffanella zaffanella@cs.unipr.it Date: Tue Nov 24 12:09:20 2009 +0100
Prefer not_a_dimension() as a marker if the big parameter is not set.
---
src/PIP_Problem.cc | 18 ++++++++++-------- src/PIP_Problem.defs.hh | 11 +++++++++-- src/PIP_Problem.inlines.hh | 2 -- src/PIP_Problem.templates.hh | 2 +- src/PIP_Tree.cc | 7 ++++--- src/PIP_Tree.defs.hh | 6 ++++-- tests/PIP_Problem/pipproblem2.cc | 18 ++++++++++++++++++ 7 files changed, 46 insertions(+), 18 deletions(-)
diff --git a/src/PIP_Problem.cc b/src/PIP_Problem.cc index 6f4c01c..687f3e6 100644 --- a/src/PIP_Problem.cc +++ b/src/PIP_Problem.cc @@ -42,7 +42,7 @@ PPL::PIP_Problem::PIP_Problem(const dimension_type dim) first_pending_constraint(0), parameters(), initial_context(), - big_parameter_dimension(0) { + big_parameter_dimension(not_a_dimension()) { // Check for space dimension overflow. if (dim > max_space_dimension()) throw std::length_error("PPL::PIP_Problem::PIP_Problem(dim):\n" @@ -247,7 +247,7 @@ PPL::PIP_Problem::OK() const { return false; }
- if (big_parameter_dimension != 0 + if (big_parameter_dimension != not_a_dimension() && parameters.count(big_parameter_dimension) == 0) { #ifndef NDEBUG cerr << "The current value for the big parameter is not a parameter " @@ -323,7 +323,9 @@ PPL::PIP_Problem::ascii_dump(std::ostream& s) const { s << "\n"; }
- s << "\nbig_parameter_dimension: " << big_parameter_dimension << " \n"; + s << "\nbig_parameter_dimension: " + << big_parameter_dimension + << "\n"; }
PPL_OUTPUT_DEFINITIONS(PIP_Problem) @@ -447,7 +449,7 @@ PPL::PIP_Problem::clear() { parameters.clear(); initial_context.clear(); control_parameters_init(); - big_parameter_dimension = 0; + big_parameter_dimension = not_a_dimension(); }
void @@ -557,12 +559,12 @@ PPL::PIP_Problem::set_control_parameter(Control_Parameter_Value value) { void PPL::PIP_Problem::set_big_parameter_dimension(dimension_type x) { if (parameters.count(x) == 0) - throw std::invalid_argument("PPL::PIP_Problem::set_big_parameter_dimension" - "(x):\n" + throw std::invalid_argument("PPL::PIP_Problem::" + "set_big_parameter_dimension(x):\n" "dimension 'x' is not a parameter."); if (x < internal_space_dim) - throw std::invalid_argument("PPL::PIP_Problem::set_big_parameter_dimension" - "(x):\n" + throw std::invalid_argument("PPL::PIP_Problem::" + "set_big_parameter_dimension(x):\n" "only newly-added parameters can be" "converted into the big parameter."); big_parameter_dimension = x; diff --git a/src/PIP_Problem.defs.hh b/src/PIP_Problem.defs.hh index af6941f..e075acd 100644 --- a/src/PIP_Problem.defs.hh +++ b/src/PIP_Problem.defs.hh @@ -318,7 +318,11 @@ public: //! Sets the dimension for the big parameter void set_big_parameter_dimension(dimension_type x);
- //! Gets the dimension for the big parameter + /*! \brief + Returns the space dimension for the big parameter. + + If a big parameter was not set, returns \c not_a_dimension(). + */ dimension_type get_big_parameter_dimension() const;
private: @@ -389,7 +393,10 @@ private: Control_Parameter_Value control_parameters[CONTROL_PARAMETER_NAME_SIZE];
- //! The dimension for the big parameter, or zero if not set. + /*! \brief + The dimension for the big parameter, or \c not_a_dimension() + if not set. + */ dimension_type big_parameter_dimension; };
diff --git a/src/PIP_Problem.inlines.hh b/src/PIP_Problem.inlines.hh index cd052a6..b2f3bc3 100644 --- a/src/PIP_Problem.inlines.hh +++ b/src/PIP_Problem.inlines.hh @@ -73,14 +73,12 @@ PIP_Problem::operator=(const PIP_Problem& y) { return *this; }
-//! Returns the control parameter value for parameter name \p n. inline PIP_Problem::Control_Parameter_Value PIP_Problem::get_control_parameter(Control_Parameter_Name n) const { assert(n >= 0 && n < CONTROL_PARAMETER_NAME_SIZE); return control_parameters[n]; }
-//! Gets the dimension for the big parameter inline dimension_type PIP_Problem::get_big_parameter_dimension() const { return big_parameter_dimension; diff --git a/src/PIP_Problem.templates.hh b/src/PIP_Problem.templates.hh index 6fe4579..f5fc761 100644 --- a/src/PIP_Problem.templates.hh +++ b/src/PIP_Problem.templates.hh @@ -41,7 +41,7 @@ PIP_Problem::PIP_Problem(dimension_type dim, first_pending_constraint(0), parameters(p_vars), initial_context(), - big_parameter_dimension(0) { + big_parameter_dimension(not_a_dimension()) { // Check that integer Variables_Set does not exceed the space dimension // of the problem. if (p_vars.space_dimension() > external_space_dim) { diff --git a/src/PIP_Tree.cc b/src/PIP_Tree.cc index 1fcb98e..de77be6 100644 --- a/src/PIP_Tree.cc +++ b/src/PIP_Tree.cc @@ -230,7 +230,7 @@ PIP_Solution_Node::PIP_Solution_Node() var_row(), var_column(), special_equality_row(0), - big_dimension(0), + big_dimension(not_a_dimension()), sign(), solution(), solution_valid(false) { @@ -923,7 +923,7 @@ PIP_Solution_Node
PIP_Solution_Node::Row_Sign PIP_Solution_Node::row_sign(const Row &x, dimension_type big_dimension) { - if (big_dimension > 0) { + if (big_dimension != not_a_dimension()) { /* If a big parameter has been set and its coefficient is not zero, just return the sign of the coefficient */ const Coefficient &c = x[big_dimension]; @@ -1173,7 +1173,8 @@ PIP_Solution_Node::update_tableau(const PIP_Problem& problem, } } internal_space_dim = external_space_dim; - if (big_dimension == 0 && problem.big_parameter_dimension > 0) { + if (big_dimension == not_a_dimension() + && problem.big_parameter_dimension != not_a_dimension()) { // Compute the column number of big parameter in tableau.t matrix Variables_Set::const_iterator begin = parameters.begin(); Variables_Set::const_iterator pos diff --git a/src/PIP_Tree.defs.hh b/src/PIP_Tree.defs.hh index 3de1cb6..955c100 100644 --- a/src/PIP_Tree.defs.hh +++ b/src/PIP_Tree.defs.hh @@ -372,8 +372,10 @@ private: */ dimension_type special_equality_row;
- /*! \brief The column number in the parametric part of the simplex tableau - which corresponds to the big parameter + /*! \brief + The column number in the parametric part of the simplex tableau + which corresponds to the big parameter; \c not_a_dimension() + if not set. */ dimension_type big_dimension;
diff --git a/tests/PIP_Problem/pipproblem2.cc b/tests/PIP_Problem/pipproblem2.cc index 068e20d..a6b5b8c 100644 --- a/tests/PIP_Problem/pipproblem2.cc +++ b/tests/PIP_Problem/pipproblem2.cc @@ -92,10 +92,28 @@ test03() { return ok; }
+bool +test04() { + PIP_Problem pip(6); + Variables_Set params(Variable(3), Variable(5)); + pip.add_to_parameter_space_dimensions(params); + + bool ok = (pip.get_big_parameter_dimension() == not_a_dimension()); + + pip.set_big_parameter_dimension(3); + ok &= (pip.get_big_parameter_dimension() == 3); + + pip.set_big_parameter_dimension(5); + ok &= (pip.get_big_parameter_dimension() == 5); + + return ok; +} + } // namespace
BEGIN_MAIN DO_TEST(test01); DO_TEST(test02); DO_TEST(test03); + DO_TEST(test04); END_MAIN
participants (1)
-
Enea Zaffanella